From 792283d8b5c796138788a548190b61ed4f8bf09e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 6 Feb 2024 10:18:58 +0100 Subject: [PATCH] Add readme --- packages/server/package.json | 2 +- packages/server/src/jsRunner/bundles/README.md | 15 +++++++++++++++ ....bundle.js.txt => index-helpers.ivm.bundle.js} | 0 packages/server/src/jsRunner/index.ts | 2 +- scripts/build.js | 4 ++-- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 packages/server/src/jsRunner/bundles/README.md rename packages/server/src/jsRunner/bundles/{index-helpers.ivm.bundle.js.txt => index-helpers.ivm.bundle.js} (100%) diff --git a/packages/server/package.json b/packages/server/package.json index ebfa66aeca..5591fe080f 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -13,7 +13,7 @@ "build": "node ./scripts/build.js", "postbuild": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client && copyfiles -f ../../yarn.lock ./dist/", "check:types": "tsc -p tsconfig.json --noEmit --paths null", - "build:isolated-vm-lib:string-templates": "esbuild --minify --bundle src/jsRunner/bundles/index-helpers.ts --outfile=src/jsRunner/bundles/index-helpers.ivm.bundle.js.txt --platform=node --format=esm --external:handlebars", + "build:isolated-vm-lib:string-templates": "esbuild --minify --bundle src/jsRunner/bundles/index-helpers.ts --outfile=src/jsRunner/bundles/index-helpers.ivm.bundle.js --platform=node --format=esm --external:handlebars", "build:isolated-vm-libs": "yarn build:isolated-vm-lib:string-templates", "build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput", "debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js", diff --git a/packages/server/src/jsRunner/bundles/README.md b/packages/server/src/jsRunner/bundles/README.md new file mode 100644 index 0000000000..fac8ebe14a --- /dev/null +++ b/packages/server/src/jsRunner/bundles/README.md @@ -0,0 +1,15 @@ +# Bundles for isolated-vm + +[Isolated-vm](https://github.com/laverdet/isolated-vm) requires for us to have some libraries, such as string-templates helpers, built in a single file without external dependencies. These libraries are pretty much static. To avoid building this in every dev command, in every test command and in every pipeline, these libraries are already compiled and commited into the repo. + +## How are they consumed? + +These libaries are compiled with a special extension: .ivm.bundle.js. This extension is configured in [esbuild](/scripts/build.js) in order to not be bundled as javascript, and to be treated as a `string` instead. This will allow us to read it's context on runtime and inject it to `isolated-vm`. + +## How to update it? + +These libraries are pretty much static, but they might require some updates from time to time when something changes on the source code. In order to do this, we just need to run the following command and commit the updated bundles: + +``` +yarn build:isolated-vm-libs +``` diff --git a/packages/server/src/jsRunner/bundles/index-helpers.ivm.bundle.js.txt b/packages/server/src/jsRunner/bundles/index-helpers.ivm.bundle.js similarity index 100% rename from packages/server/src/jsRunner/bundles/index-helpers.ivm.bundle.js.txt rename to packages/server/src/jsRunner/bundles/index-helpers.ivm.bundle.js diff --git a/packages/server/src/jsRunner/index.ts b/packages/server/src/jsRunner/index.ts index e5d95cf200..f0ebac2ec4 100644 --- a/packages/server/src/jsRunner/index.ts +++ b/packages/server/src/jsRunner/index.ts @@ -7,7 +7,7 @@ import url from "url" import crypto from "crypto" import querystring from "querystring" -const helpersSource = require("./bundles/index-helpers.ivm.bundle.js.txt") +const helpersSource = require("./bundles/index-helpers.ivm.bundle.js") class ExecutionTimeoutError extends Error { constructor(message: string) { diff --git a/scripts/build.js b/scripts/build.js index 599585c731..ad31381684 100755 --- a/scripts/build.js +++ b/scripts/build.js @@ -49,7 +49,7 @@ function runBuild(entry, outfile) { preserveSymlinks: true, loader: { ".svelte": "copy", - ".ivm.bundle.js.txt": "text", + ".ivm.bundle.js": "text", }, metafile: true, external: [ @@ -61,7 +61,7 @@ function runBuild(entry, outfile) { "bcrypt", "bcryptjs", "graphql/*", - "bson" + "bson", ], }