From 405aadde4485f31ba744d76044dbecf392dfeebf Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Wed, 14 May 2025 12:28:59 +0100 Subject: [PATCH 1/4] chore: dont publish experimental or cypress --- .npmignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.npmignore b/.npmignore index 27087e67d..286c7a75f 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,5 @@ # This file required to override .gitignore when publishing to npm website/ plugins/ +experimental/ +cypress/ From c730f972c69641f531602dc3d83b379c9e77262e Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Wed, 14 May 2025 12:31:11 +0100 Subject: [PATCH 2/4] ci: generate js and definitions from ts and place in original location --- package.json | 7 +++++-- scripts/build-for-publish.sh | 26 ++++++++++++++++++++++++++ scripts/undo-build.sh | 11 +++++++++++ src/proxy/index.ts | 6 +++--- tsconfig.json | 4 +++- tsconfig.publish.json | 15 +++++++++++++++ 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 scripts/build-for-publish.sh create mode 100755 scripts/undo-build.sh create mode 100644 tsconfig.publish.json diff --git a/package.json b/package.json index 2db0042be..d44634451 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,11 @@ "clientinstall": "npm install --prefix client", "server": "tsx index.ts", "start": "concurrently \"npm run server\" \"npm run client\"", - "build": "vite build", - "build-ts": "tsc", + "build": "npm run build-ui && npm run build-lib", + "build-ui": "vite build", + "build-lib": "./scripts/build-for-publish.sh", + "restore-lib": "./scripts/undo-build.sh", + "check-types": "tsc", "test": "NODE_ENV=test ts-mocha './test/*.js' --exit", "test-coverage": "nyc npm run test", "test-coverage-ci": "nyc --reporter=lcovonly --reporter=text npm run test", diff --git a/scripts/build-for-publish.sh b/scripts/build-for-publish.sh new file mode 100755 index 000000000..d326e69b8 --- /dev/null +++ b/scripts/build-for-publish.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euxo pipefail + +# This script allows for emitting js and definitions from the typescript into +# the same import locations as the original files. +# When we adjust how we import the library we can move to a "dist" folder and +# explicit "exports". + +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd "$REPO_ROOT" + +rm -rf dist || true +tsc --project tsconfig.publish.json +# replace tsx with node for the new index.js +sed -ie '1s/tsx/node/' dist/index.js +# ensure it's executable +chmod +x dist/index.js +# move the ts source +mv src src-old +# move the built source +mv dist/src dist/index.js dist/index.d.ts . +# copy back unchanged ui code +# could probably drop this as the ui code shouldn't really be imported from +# the main package but keep for compat until split out. +mv src-old/ui src/ui +rm -rf src-old index.ts dist diff --git a/scripts/undo-build.sh b/scripts/undo-build.sh new file mode 100755 index 000000000..998123e09 --- /dev/null +++ b/scripts/undo-build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euxo pipefail + +# Undo what was done by build-for-publish.sh in the event this was ran locally + +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd "$REPO_ROOT" + +rm -rf dist index.js index.d.ts || true +git checkout src index.ts +git clean -f src diff --git a/src/proxy/index.ts b/src/proxy/index.ts index 04fce52d7..0a49d0a6f 100644 --- a/src/proxy/index.ts +++ b/src/proxy/index.ts @@ -27,7 +27,7 @@ const options = { cert: getTLSEnabled() ? fs.readFileSync(getTLSCertPemPath()) : undefined, }; -const proxyPreparations = async () => { +export const proxyPreparations = async () => { const plugins = getPlugins(); const pluginLoader = new PluginLoader(plugins); await pluginLoader.load(); @@ -47,7 +47,7 @@ const proxyPreparations = async () => { }; // just keep this async incase it needs async stuff in the future -const createApp = async () => { +export const createApp = async () => { const app = express(); // Setup the proxy middleware app.use(bodyParser.raw(options)); @@ -55,7 +55,7 @@ const createApp = async () => { return app; }; -const start = async () => { +export const start = async () => { const app = await createApp(); await proxyPreparations(); http.createServer(options as any, app).listen(proxyHttpPort, () => { diff --git a/tsconfig.json b/tsconfig.json index 805153d01..a389ca8c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "moduleResolution": "Node", "strict": true, "noEmit": true, + "declaration": true, "skipLibCheck": true, "isolatedModules": true, "module": "CommonJS", @@ -15,5 +16,6 @@ "allowSyntheticDefaultImports": true, "resolveJsonModule": true }, - "include": ["src"] + "include": ["."], + "exclude": ["experimental/**", "plugins/**"] } diff --git a/tsconfig.publish.json b/tsconfig.publish.json new file mode 100644 index 000000000..ef9be14f7 --- /dev/null +++ b/tsconfig.publish.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "./dist" + }, + "exclude": [ + "experimental/**", + "plugins/**", + "./dist/**", + "./src/ui", + "./src/**/*.jsx", + "./src/context.js" + ] +} From cd1b431ee1b65b8ecc1de8d24b6c33bb74e02260 Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Wed, 14 May 2025 15:44:25 +0100 Subject: [PATCH 3/4] ci: add guardrails and add to publish --- .github/workflows/npm.yml | 2 ++ scripts/build-for-publish.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index 7e592f77b..274019886 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -22,6 +22,8 @@ jobs: registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm run build + env: + IS_PUBLISHING: 'YES' - run: npm publish --access=public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/scripts/build-for-publish.sh b/scripts/build-for-publish.sh index d326e69b8..1c9ac4130 100755 --- a/scripts/build-for-publish.sh +++ b/scripts/build-for-publish.sh @@ -1,11 +1,20 @@ #!/usr/bin/env bash -set -euxo pipefail +set -euo pipefail # This script allows for emitting js and definitions from the typescript into # the same import locations as the original files. # When we adjust how we import the library we can move to a "dist" folder and # explicit "exports". +if [ "${IS_PUBLISHING:-}" != "YES" ]; then + echo "This script is intended to prepare the directory for publishing" + echo "and replaces files. If you only want to build the UI run \`npm run build-ui\`." + echo "Otherwise set IS_PUBLISHING to \"YES\"" + exit 1 +fi + +set -x + REPO_ROOT="$(git rev-parse --show-toplevel)" cd "$REPO_ROOT" From 8810a636704683f83c7b65b3ef694b5f4b3a9097 Mon Sep 17 00:00:00 2001 From: Jack Kelly Date: Wed, 14 May 2025 16:01:57 +0100 Subject: [PATCH 4/4] ci: correctly build frontend in ci --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33c5fd418..972fd7e1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,8 +60,8 @@ jobs: # if: ${{ steps.test.outputs.exit_code }} != 0 # run: exit ${{ steps.test.outputs.exit_code }} - - name: Build application - run: npm run build + - name: Build frontend + run: npm run build-ui - name: Save build folder uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4