diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d9e89d..31d9687 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,8 +65,12 @@ jobs: - name: Install run: npm ci + - name: Get next version + id: next_release + run: npx semantic-release --dry-run --no-ci + - name: Build - run: npm run pack + run: npm run pack ${{ steps.next_release.outputs.version }} - name: Upload build artifacts uses: actions/upload-artifact@v4 diff --git a/globals.d.ts b/globals.d.ts deleted file mode 100644 index 0876fd6..0000000 --- a/globals.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export {}; - -declare global {} diff --git a/index.js b/index.js index 802d9b2..07fd673 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,11 @@ const { readProjectInfo, writeProjectInfo } = require('./modules/project-info'); * @typedef {NoUnion[0], undefined>>} EitherCLIOrLibdragonInfo */ +// This is overridden when building for SEA. When running from local or NPM, +// the package.json version is used by the version action. esbuild will give +// a warning for this assignment, but it works as expected. +globalThis.VERSION = ""; + parseParameters(process.argv) .then(readProjectInfo) .then((info) => { diff --git a/modules/actions/init.js b/modules/actions/init.js index 9a1ce8e..d5e09a0 100644 --- a/modules/actions/init.js +++ b/modules/actions/init.js @@ -1,5 +1,3 @@ -/// - const fs = require('fs/promises'); const _fs = require('fs'); const path = require('path'); diff --git a/modules/actions/version.js b/modules/actions/version.js index 339ee88..c1b8572 100644 --- a/modules/actions/version.js +++ b/modules/actions/version.js @@ -1,8 +1,16 @@ -const { version } = require('../../package.json'); +const sea = require('node:sea'); + const { log } = require('../helpers'); const printVersion = async () => { - log(`libdragon-cli v${version}`); + // Version is set during build time. If it is not set, it is set to the + // package.json version. This is done to avoid bundling the package.json + // (which would be out of date) with the built one. + if (!globalThis.VERSION) { + const { version } = require('../../package.json'); + globalThis.VERSION = version; + } + log(`libdragon-cli v${globalThis.VERSION} ${sea.isSea() ? '(sea)' : ''}`); }; module.exports = /** @type {const} */ ({ diff --git a/pack.mjs b/pack.mjs index 1398a08..f25244c 100644 --- a/pack.mjs +++ b/pack.mjs @@ -39,6 +39,11 @@ await esbuild.build({ '.c': 'text', '.mk': 'text', }, + define: { + ...(process.argv[2] && { + 'globalThis.VERSION': JSON.stringify(process.argv[2]), + }), + }, }); await $`node --experimental-sea-config sea-config.json`; diff --git a/package.json b/package.json index a08c1c2..c94813e 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ [ "@semantic-release/exec", { + "verifyReleaseCmd": "powershell.exe echo \"${nextRelease.version} \" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append", "prepareCmd": "npm run bundle ${nextRelease.version}" } ],