1
0
Fork 0
mirror of synced 2024-09-28 07:11:40 +12:00

Simplify loading

This commit is contained in:
Adria Navarro 2024-02-13 23:44:24 +01:00
parent 2d2d88f988
commit f733d293da
3 changed files with 6 additions and 34 deletions

View file

@ -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

View file

@ -7,6 +7,10 @@ export const enum BundleType {
BSON = "bson",
}
const bundleSourceFile: Record<BundleType, string> = {
[BundleType.HELPERS]: "./index-helpers.ivm.bundle.js",
[BundleType.BSON]: "./bson.ivm.bundle.js",
}
const bundleSourceCode: Partial<Record<BundleType, string>> = {}
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
}

View file

@ -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)}`)
}