From fa38057fb619b619a01188240929356c8f27bcfd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Sep 2023 15:46:39 +0200 Subject: [PATCH 1/4] Keep structure building test dist --- packages/backend-core/scripts/build.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/backend-core/scripts/build.js b/packages/backend-core/scripts/build.js index bd00cbc7ff..dd1992855a 100644 --- a/packages/backend-core/scripts/build.js +++ b/packages/backend-core/scripts/build.js @@ -1,6 +1,19 @@ #!/usr/bin/node const coreBuild = require("../../../scripts/build") +const { exec } = require("child_process") coreBuild("./src/plugin/index.ts", "./dist/plugins.js") coreBuild("./src/index.ts", "./dist/index.js") -coreBuild("./tests/index.ts", "./dist/tests.js") + +const child = exec( + `esbuild ./tests/*.[tj]s ./tests/**/*.[tj]s --outdir=./dist/tests` +) +child.stdout.on("data", data => { + console.log(`stdout: ${data}`) +}) +child.stderr.on("data", data => { + console.error(`stderr: ${data}`) +}) +child.on("close", code => { + console.log(`esbuild process exited with code ${code}`) +}) From d3f4cde372694ba837b8cf7c465f2cbe2d08e13a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Sep 2023 15:47:15 +0200 Subject: [PATCH 2/4] Update test entry point --- packages/backend-core/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index 1d6aa5b9fd..970a4aab8d 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -6,7 +6,7 @@ "types": "dist/src/index.d.ts", "exports": { ".": "./dist/index.js", - "./tests": "./dist/tests.js", + "./tests": "./dist/tests/index.js", "./*": "./dist/*.js" }, "author": "Budibase", From 7ff6714ff888a93fb92e469f64eb9f5ed783befb Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Sep 2023 16:19:15 +0200 Subject: [PATCH 3/4] Use esbuild js --- packages/backend-core/scripts/build.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/backend-core/scripts/build.js b/packages/backend-core/scripts/build.js index dd1992855a..ff8211b04a 100644 --- a/packages/backend-core/scripts/build.js +++ b/packages/backend-core/scripts/build.js @@ -1,19 +1,18 @@ #!/usr/bin/node const coreBuild = require("../../../scripts/build") -const { exec } = require("child_process") coreBuild("./src/plugin/index.ts", "./dist/plugins.js") coreBuild("./src/index.ts", "./dist/index.js") -const child = exec( - `esbuild ./tests/*.[tj]s ./tests/**/*.[tj]s --outdir=./dist/tests` -) -child.stdout.on("data", data => { - console.log(`stdout: ${data}`) -}) -child.stderr.on("data", data => { - console.error(`stderr: ${data}`) -}) -child.on("close", code => { - console.log(`esbuild process exited with code ${code}`) -}) +const esbuild = require("esbuild") +const glob = require("glob") + +const inputFiles = glob.sync("./tests/**/*.[tj]s", { nodir: true }) +const outputDir = "./dist/tests" + +esbuild + .build({ + entryPoints: inputFiles, + outdir: outputDir, + }) + .catch(() => process.exit(1)) From 5a4d032b0d26b6875237f7086fc7e7dd7697b13f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Sep 2023 16:44:02 +0200 Subject: [PATCH 4/4] Build dist/tests --- packages/backend-core/scripts/build.js | 21 +++++++++-------- scripts/build.js | 31 +++++++++++++------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/backend-core/scripts/build.js b/packages/backend-core/scripts/build.js index ff8211b04a..8a15d09708 100644 --- a/packages/backend-core/scripts/build.js +++ b/packages/backend-core/scripts/build.js @@ -1,18 +1,21 @@ #!/usr/bin/node + const coreBuild = require("../../../scripts/build") coreBuild("./src/plugin/index.ts", "./dist/plugins.js") coreBuild("./src/index.ts", "./dist/index.js") -const esbuild = require("esbuild") const glob = require("glob") +const inputFiles = [ + ...glob.sync("./src/**/*.[tj]s", { nodir: true }), + ...glob.sync("./tests/**/*.[tj]s", { nodir: true }), +] -const inputFiles = glob.sync("./tests/**/*.[tj]s", { nodir: true }) -const outputDir = "./dist/tests" - -esbuild - .build({ - entryPoints: inputFiles, - outdir: outputDir, +const path = require("path") +for (const file of inputFiles) { + coreBuild(file, `./${path.join("dist", file.replace(/\.ts$/, ".js"))}`, { + skipMeta: true, + bundle: false, + forcedFormat: "cjs", }) - .catch(() => process.exit(1)) +} diff --git a/scripts/build.js b/scripts/build.js index 0175388051..8356f2e035 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -15,7 +15,7 @@ const { nodeExternalsPlugin } = require("esbuild-node-externals") var argv = require("minimist")(process.argv.slice(2)) -function runBuild(entry, outfile) { +function runBuild(entry, outfile, opts = { skipMeta: false, bundle: true }) { const isDev = process.env.NODE_ENV !== "production" const tsconfig = argv["p"] || `tsconfig.build.json` const tsconfigPathPluginContent = JSON.parse( @@ -36,12 +36,16 @@ function runBuild(entry, outfile) { ] } + const metafile = !opts.skipMeta + const { bundle } = opts + const sharedConfig = { entryPoints: [entry], - bundle: true, + bundle, minify: !isDev, sourcemap: isDev, tsconfig, + format: opts?.forcedFormat, plugins: [ TsconfigPathsPlugin({ tsconfig: tsconfigPathPluginContent }), nodeExternalsPlugin(), @@ -50,15 +54,10 @@ function runBuild(entry, outfile) { loader: { ".svelte": "copy", }, - metafile: true, - external: [ - "deasync", - "mock-aws-s3", - "nock", - "pino", - "koa-pino-logger", - "bull", - ], + metafile, + external: bundle + ? ["deasync", "mock-aws-s3", "nock", "pino", "koa-pino-logger", "bull"] + : undefined, } build({ @@ -77,10 +76,12 @@ function runBuild(entry, outfile) { ) }) - fs.writeFileSync( - `dist/${path.basename(outfile)}.meta.json`, - JSON.stringify(result.metafile) - ) + if (metafile) { + fs.writeFileSync( + `dist/${path.basename(outfile)}.meta.json`, + JSON.stringify(result.metafile) + ) + } }) }