Skip to content

Commit

Permalink
fix(app-service): fix db import error while building;
Browse files Browse the repository at this point in the history
init.ts should not import db globally, because init.ts would be referenced in build time;
  • Loading branch information
maslow committed May 5, 2022
1 parent 0c83449 commit 070114e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/app-service/src/support/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Constants } from '../constants'
import { execSync } from 'child_process'
import Config from '../config'
import { logger } from './logger'
import { DatabaseAgent } from '../db'


/**
Expand Down Expand Up @@ -59,9 +58,11 @@ interface AppConfigItem {
* @returns
*/
export async function getExtraPackages() {
const { DatabaseAgent } = require('../db') // init.ts should not import db globally, because init.ts would be referenced in build time

await DatabaseAgent.accessor.ready
const db = DatabaseAgent.db
const doc = await db.collection<AppConfigItem>(Constants.config_collection)
const doc: AppConfigItem = await db.collection(Constants.config_collection)
.findOne({ key: 'packages' })

return doc?.value ?? []
Expand Down Expand Up @@ -109,6 +110,8 @@ export function moduleExists(mod: string) {
* @returns
*/
export async function ensureCollectionIndexes(): Promise<any> {
const { DatabaseAgent } = require('../db') // init.ts should not import db globally, because init.ts would be referenced in build time

const db = DatabaseAgent.db
await db.collection(Constants.function_log_collection)
.createIndexes([
Expand Down

0 comments on commit 070114e

Please sign in to comment.