From d7f7ad5b5f92aeb2a3ebb0bc7813598681fe8c7c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 3 May 2023 12:38:23 +0100 Subject: [PATCH] Build shared-core --- package.json | 1 + packages/shared-core/package.json | 2 +- packages/shared-core/tsconfig-base.build.json | 5 ++++- packages/shared-core/tsconfig-cjs.build.json | 1 - packages/shared-core/tsconfig.build.json | 1 - scripts/build.js | 15 +++++++++++---- yarn.lock | 14 +++++++++++--- 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 3f3d0a5c6a..532b037168 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "kill-port": "^1.6.1", "lerna": "^6.6.1", "madge": "^6.0.0", + "minimist": "^1.2.8", "prettier": "^2.3.1", "prettier-plugin-svelte": "^2.3.0", "rimraf": "^3.0.2", diff --git a/packages/shared-core/package.json b/packages/shared-core/package.json index e29fea93af..a27163b0bc 100644 --- a/packages/shared-core/package.json +++ b/packages/shared-core/package.json @@ -15,7 +15,7 @@ "license": "GPL-3.0", "scripts": { "prebuild": "rimraf dist/", - "build": "tsc -p tsconfig.build.json && tsc -p tsconfig-cjs.build.json", + "build": "node ../../scripts/build.js -p tsconfig.build.json --outdir dist/mjs/src && node ../../scripts/build.js -p tsconfig-cjs.build.json --outdir dist/cjs/src", "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", "dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\"" }, diff --git a/packages/shared-core/tsconfig-base.build.json b/packages/shared-core/tsconfig-base.build.json index 6930e3cb99..31dc1afc10 100644 --- a/packages/shared-core/tsconfig-base.build.json +++ b/packages/shared-core/tsconfig-base.build.json @@ -12,7 +12,10 @@ "declaration": true, "types": ["node"], "outDir": "dist", - "skipLibCheck": true + "skipLibCheck": true, + "paths": { + "@budibase/types": ["../types/src"] + } }, "include": ["**/*.js", "**/*.ts"], "exclude": [ diff --git a/packages/shared-core/tsconfig-cjs.build.json b/packages/shared-core/tsconfig-cjs.build.json index 45e81e575c..fc736056c8 100644 --- a/packages/shared-core/tsconfig-cjs.build.json +++ b/packages/shared-core/tsconfig-cjs.build.json @@ -2,7 +2,6 @@ "extends": "./tsconfig-base.build.json", "compilerOptions": { "module": "commonjs", - "outDir": "dist/cjs/src", "target": "es2015" } } diff --git a/packages/shared-core/tsconfig.build.json b/packages/shared-core/tsconfig.build.json index 2a00a44dfe..19bcef552d 100644 --- a/packages/shared-core/tsconfig.build.json +++ b/packages/shared-core/tsconfig.build.json @@ -2,7 +2,6 @@ "extends": "./tsconfig-base.build.json", "compilerOptions": { "module": "esnext", - "outDir": "dist/mjs/src", "target": "esnext" } } diff --git a/scripts/build.js b/scripts/build.js index 0e813ab3f8..a17c19803b 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -11,12 +11,16 @@ const sveltePlugin = require("esbuild-svelte") const { default: NodeResolve } = require("@esbuild-plugins/node-resolve") +var argv = require("minimist")(process.argv.slice(2)) + function runBuild(entry, outfile) { + const isDev = process.env.NODE_ENV !== "production" + const sharedConfig = { entryPoints: [entry], bundle: true, - minify: true, - tsconfig: `tsconfig.build.json`, + minify: !isDev, + tsconfig: argv["p"] || `tsconfig.build.json`, plugins: [ sveltePlugin(), NodeResolve({ @@ -33,12 +37,15 @@ function runBuild(entry, outfile) { ], target: "node14", preserveSymlinks: true, + external: isDev ? ["@budibase/client"] : [], } + const outdir = argv["outdir"] build({ ...sharedConfig, platform: "node", - outfile, + outdir, + outfile: outdir ? undefined : outfile, }).then(() => { glob(`${process.cwd()}/src/**/*.hbs`, {}, (err, files) => { for (const file of files) { @@ -54,7 +61,7 @@ function runBuild(entry, outfile) { } if (require.main === module) { - const entry = process.argv[2] || "./src/index.ts" + const entry = argv["e"] || "./src/index.ts" const outfile = `dist/${entry.split("/").pop().replace(".ts", ".js")}` runBuild(entry, outfile) } else { diff --git a/yarn.lock b/yarn.lock index 8e2ad58618..1f930b4ce1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17538,7 +17538,7 @@ minimist-options@4.1.0: is-plain-obj "^1.1.0" kind-of "^6.0.3" -minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.3, minimist@^1.2.7: +minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.3, minimist@^1.2.7, minimist@^1.2.8: version "1.2.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== @@ -24972,7 +24972,7 @@ vlq@^0.2.2: resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow== -vm2@3.9.17, vm2@^3.9.15: +vm2@3.9.17: version "3.9.17" resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.17.tgz#251b165ff8a0e034942b5181057305e39570aeab" integrity sha512-AqwtCnZ/ERcX+AVj9vUsphY56YANXxRuqMb7GsDtAr0m0PcQX3u0Aj3KWiXM0YAHy7i6JEeHrwOnwXbGYgRpAw== @@ -24980,7 +24980,15 @@ vm2@3.9.17, vm2@^3.9.15: acorn "^8.7.0" acorn-walk "^8.2.0" -vm2@^3.9.4, vm2@^3.9.8: +vm2@^3.9.15: + version "3.9.16" + resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.16.tgz#0fbc2a265f7bf8b837cea6f4a908f88a3f93b8e6" + integrity sha512-3T9LscojNTxdOyG+e8gFeyBXkMlOBYDoF6dqZbj+MPVHi9x10UfiTAJIobuchRCp3QvC+inybTbMJIUrLsig0w== + dependencies: + acorn "^8.7.0" + acorn-walk "^8.2.0" + +vm2@^3.9.8: version "3.9.14" resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.14.tgz#964042b474cf1e6e4f475a39144773cdb9deb734" integrity sha512-HgvPHYHeQy8+QhzlFryvSteA4uQLBCOub02mgqdR+0bN/akRZ48TGB1v0aCv7ksyc0HXx16AZtMHKS38alc6TA==