Skip to content

ci: generate js and definitions from ts and place in original location #1007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file required to override .gitignore when publishing to npm
website/
plugins/
experimental/
cypress/
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
35 changes: 35 additions & 0 deletions scripts/build-for-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
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"

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
11 changes: 11 additions & 0 deletions scripts/undo-build.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -47,15 +47,15 @@ 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));
app.use('/', router);
return app;
};

const start = async () => {
export const start = async () => {
const app = await createApp();
await proxyPreparations();
http.createServer(options as any, app).listen(proxyHttpPort, () => {
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"moduleResolution": "Node",
"strict": true,
"noEmit": true,
"declaration": true,
"skipLibCheck": true,
"isolatedModules": true,
"module": "CommonJS",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
"include": ["src"]
"include": ["."],
"exclude": ["experimental/**", "plugins/**"]
}
15 changes: 15 additions & 0 deletions tsconfig.publish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "./dist"
},
"exclude": [
"experimental/**",
"plugins/**",
"./dist/**",
"./src/ui",
"./src/**/*.jsx",
"./src/context.js"
]
}
Loading