From f733d293dad5516714dafbf599a3435f5943ece5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 13 Feb 2024 23:44:24 +0100 Subject: [PATCH] Simplify loading --- packages/server/src/environment.ts | 1 - packages/server/src/jsRunner/bundles/index.ts | 33 +++---------------- scripts/build.js | 6 +--- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index b6654d0a14..8e6866d5e4 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -98,7 +98,6 @@ 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 ce19c15e09..9e2960807a 100644 --- a/packages/server/src/jsRunner/bundles/index.ts +++ b/packages/server/src/jsRunner/bundles/index.ts @@ -7,6 +7,10 @@ export const enum BundleType { BSON = "bson", } +const bundleSourceFile: Record = { + [BundleType.HELPERS]: "./index-helpers.ivm.bundle.js", + [BundleType.BSON]: "./bson.ivm.bundle.js", +} const bundleSourceCode: Partial> = {} export function loadBundle(type: BundleType) { @@ -15,34 +19,7 @@ export function loadBundle(type: BundleType) { return sourceCode } - if (!environment.isBundled) { - let filePath - switch (type) { - case BundleType.HELPERS: - filePath = "./index-helpers.ivm.bundle.js" - break - case BundleType.BSON: - filePath = "./bson.ivm.bundle.js" - break - default: - throw utils.unreachable(type) - } - - sourceCode = fs.readFileSync(require.resolve(filePath), "utf-8") - } else { - // If we are running from a built version, esbuild is configured to inject .ivm.bundle.js files as text - switch (type) { - case BundleType.HELPERS: - sourceCode = require("./index-helpers.ivm.bundle.js") - break - case BundleType.BSON: - sourceCode = require("./bson.ivm.bundle.js") - break - default: - throw utils.unreachable(type) - } - } + sourceCode = fs.readFileSync(require.resolve(bundleSourceFile[type]), "utf-8") bundleSourceCode[type] = sourceCode - return sourceCode } diff --git a/scripts/build.js b/scripts/build.js index 73f07152a9..0c0c8f1548 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -49,7 +49,6 @@ function runBuild(entry, outfile) { preserveSymlinks: true, loader: { ".svelte": "copy", - ".ivm.bundle.js": "text", }, metafile: true, external: [ @@ -63,9 +62,6 @@ function runBuild(entry, outfile) { "graphql/*", "bson", ], - define: { - "process.env.BUNDLED": '"true"', - }, } build({ @@ -73,7 +69,7 @@ function runBuild(entry, outfile) { platform: "node", outfile, }).then(result => { - glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => { + glob(`${process.cwd()}/src/**/*.{hbs,ivm.bundle.js}`, {}, (err, files) => { for (const file of files) { fs.copyFileSync(file, `${process.cwd()}/dist/${path.basename(file)}`) }