From 6872fd06d4257264cf435d3c03e73e70005cfa7e Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Tue, 26 Apr 2022 13:36:23 -0500 Subject: [PATCH] Pre-typescript compile releases - build the release in-place in out/dist - run the `tsc` compiler on the code so everything is pre-transpiled --- app.js | 2 +- etc/scripts/build-dist.sh | 46 +++++++++++++++++++++++++-------------- tsconfig.backend.json | 10 +++++---- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index 94c1900e5..51c9dbe84 100755 --- a/app.js +++ b/app.js @@ -119,7 +119,7 @@ if (opts.tmpDir) { process.env.winTmp = path.join('/mnt', driveLetter, directoryPath); } -const distPath = utils.resolvePathFromAppRoot('out', 'dist'); +const distPath = utils.resolvePathFromAppRoot('.'); const gitReleaseName = (() => { // Use the canned git_hash if provided diff --git a/etc/scripts/build-dist.sh b/etc/scripts/build-dist.sh index 6932bf456..7098e785a 100755 --- a/etc/scripts/build-dist.sh +++ b/etc/scripts/build-dist.sh @@ -2,10 +2,11 @@ set -euo pipefail -cd "$( +ROOT="$( cd -- "$(dirname "$0")/../.." >/dev/null 2>&1 pwd -P )" +cd "$ROOT" RELEASE_FILE_NAME=${GITHUB_RUN_NUMBER} RELEASE_NAME=gh-${RELEASE_FILE_NAME} @@ -14,34 +15,47 @@ HASH=$(git rev-parse HEAD) # Clear the output rm -rf out/dist mkdir -p out/dist -echo "${HASH}" >out/dist/git_hash -echo "${RELEASE_NAME}" >out/dist/release_build +cd out/dist + +echo "${HASH}" >git_hash +echo "${RELEASE_NAME}" >release_build + +cp -R "${ROOT}"/etc \ + "${ROOT}"/examples \ + "${ROOT}"/static \ + "${ROOT}"/views \ + "${ROOT}"/types \ + "${ROOT}"/package*.json \ + . +rm -rf "${ROOT}"/lib/storage/data # Create any autogenerated files. -python3 ./etc/scripts/util/changelog.py -python3 ./etc/scripts/util/politic.py - +python3 "${ROOT}/etc/scripts/util/changelog.py" +python3 "${ROOT}/etc/scripts/util/politic.py" # Set up and build and webpack everything -rm -rf node_modules +cd "${ROOT}" npm install --no-audit npm run webpack +npm run ts-compile -# Now install only the production dependencies +# Now install only the production dependencies in our output directory +cd out/dist rm -rf node_modules -npm install --no-audit --production +npm install --no-audit --ignore-scripts --production +rm -rf node_modules/.cache/ node_modules/monaco-editor/ # Output some magic for GH to set the branch name and release name echo "::set-output name=branch::${GITHUB_REF#refs/heads/}" echo "::set-output name=release_name::${RELEASE_NAME}" # Run to make sure we haven't just made something that won't work -node -r esm -r ts-node/register ./app.js --version --dist +node -r esm ./app.js --version --dist -rm -rf out/dist-bin -mkdir -p out/dist-bin +rm -rf "${ROOT}/out/dist-bin" +mkdir -p "${ROOT}/out/dist-bin" export XZ_OPT="-1 -T 0" -tar -Jcf "out/dist-bin/${RELEASE_FILE_NAME}.tar.xz" -T gh-dist-files.txt -tar -Jcf "out/dist-bin/${RELEASE_FILE_NAME}.static.tar.xz" --transform="s,^out/dist/static/,," out/dist/static/* -echo "${HASH}" >"out/dist-bin/${RELEASE_FILE_NAME}.txt" -du -ch out/**/* +tar -Jcf "${ROOT}/out/dist-bin/${RELEASE_FILE_NAME}.tar.xz" --exclude static . +tar -Jcf "${ROOT}/out/dist-bin/${RELEASE_FILE_NAME}.static.tar.xz" --transform="s,^static/,," static/* +echo "${HASH}" >"${RELEASE_FILE_NAME}.txt" +du -ch ./* diff --git a/tsconfig.backend.json b/tsconfig.backend.json index 2149bbf9f..d4faa7743 100644 --- a/tsconfig.backend.json +++ b/tsconfig.backend.json @@ -1,17 +1,19 @@ { "extends": "./tsconfig.base.json", - "include": ["lib/**/*"], - "exclude": ["static/**/*"], + "files": ["app.js"], + "include": ["**/*.js", "**/*.ts"], + "exclude": ["out", "etc", "examples", "static", "**/*.d.ts"], "compilerOptions": { /* Module resolution */ "target": "esnext", "module": "esnext", "moduleResolution": "node", /* Code generation */ - "outDir": "./out/app", + "outDir": "./out/dist", "typeRoots": ["./typings", "./node_modules/@types"], /* Other options */ "strict": true, - "noImplicitAny": false + "noImplicitAny": false, + "allowJs": true } }