Skip to content

Commit

Permalink
fix: bundle the cli with the correct version
Browse files Browse the repository at this point in the history
Currently the executables are built before semantic-release and thus they have the old version in
the package.json. Instead of using it, a version is provided as an argument to the build script.
  • Loading branch information
anacierdem committed Sep 28, 2024
1 parent b0894e9 commit 4b8bb23
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions globals.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const { readProjectInfo, writeProjectInfo } = require('./modules/project-info');
* @typedef {NoUnion<Exclude<Parameters<import('./modules/parameters').Actions[import('./modules/project-info').ActionsNoProject]['fn']>[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) => {
Expand Down
2 changes: 0 additions & 2 deletions modules/actions/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference path="../../globals.d.ts" />

const fs = require('fs/promises');
const _fs = require('fs');
const path = require('path');
Expand Down
12 changes: 10 additions & 2 deletions modules/actions/version.js
Original file line number Diff line number Diff line change
@@ -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} */ ({
Expand Down
5 changes: 5 additions & 0 deletions pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
],
Expand Down

0 comments on commit 4b8bb23

Please sign in to comment.