diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index 8e6866d5e4..b6654d0a14 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -98,6 +98,7 @@ const environment = { JS_RUNNER_MEMORY_LIMIT: parseIntSafe(process.env.JS_RUNNER_MEMORY_LIMIT) || 64, LOG_JS_ERRORS: process.env.LOG_JS_ERRORS, + isBundled: process.env.BUNDLED, } // clean up any environment variable edge cases diff --git a/packages/server/src/jsRunner/bundles/index.ts b/packages/server/src/jsRunner/bundles/index.ts index 37e677ef46..e4b50c5e8d 100644 --- a/packages/server/src/jsRunner/bundles/index.ts +++ b/packages/server/src/jsRunner/bundles/index.ts @@ -8,20 +8,21 @@ export const enum BundleType { } const bundleSourceCode = { - [BundleType.HELPERS]: "../bundles/index-helpers.ivm.bundle.js", - [BundleType.BSON]: "../bundles/bson.ivm.bundle.js", + [BundleType.HELPERS]: "./index-helpers.ivm.bundle.js", + [BundleType.BSON]: "./bson.ivm.bundle.js", } export function loadBundle(type: BundleType) { - if (environment.isJest()) { + if (!environment.isBundled) { return fs.readFileSync(require.resolve(bundleSourceCode[type]), "utf-8") } + // If we are running from a built version, esbuild is configured to inject .ivm.bundle.js files as text switch (type) { case BundleType.HELPERS: - return require("../bundles/index-helpers.ivm.bundle.js") + return require("./index-helpers.ivm.bundle.js") case BundleType.BSON: - return require("../bundles/bson.ivm.bundle.js") + return require("./bson.ivm.bundle.js") default: utils.unreachable(type) } diff --git a/scripts/build.js b/scripts/build.js index ad31381684..73f07152a9 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -63,6 +63,9 @@ function runBuild(entry, outfile) { "graphql/*", "bson", ], + define: { + "process.env.BUNDLED": '"true"', + }, } build({