An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): a crashed run's release install is recognized by the Node it ran on, whatever its name (#8520)
Christopher Chedeau45f77d085e2a
diff --git a/.changeset/cli-release-install-node-name.md b/.changeset/cli-release-install-node-name.mdnew file mode 100644index 0000000000..da8748331d--- /dev/null+++ b/.changeset/cli-release-install-node-name.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] A run that takes over a crashed run's release-cache lock now also recognizes the npm install that run left behind by its original command line, as npm shows it before renaming its process, when Node's own file is not named `node`, such as `nodejs` or `node-linux-x64`.++@vjeuxdiff --git a/packages/cli/foundation/release/cache.mjs b/packages/cli/foundation/release/cache.mjsindex a871103726..bbdd2198e1 100644--- a/packages/cli/foundation/release/cache.mjs+++ b/packages/cli/foundation/release/cache.mjs@@ -823,15 +823,24 @@ function processFactsOf(pid, procRoot) {/*** Whether a process's arguments are this CLI's install of `version`, as- * runNpm starts it: the program (`argv[0]`) is npm, or node running npm's+ * runNpm starts it: the program (`argv[0]`) is npm, or a Node running npm's* entry file `npm-cli.js` (`argv[1]`), each exactly by name, and the arguments- * include `install` and `@astryxdesign/cli@<version>`. A program that only has- * `npm` somewhere in its name or arguments is not.+ * include `install` and `@astryxdesign/cli@<version>`. A Node is one named+ * `node` (with a version, such as `node22`), or one with the same file name+ * as the Node runNpm starts npm with (`node`, by default this one), however+ * it is named, such as `nodejs` or `node-linux-x64`. A program that only+ * has `npm` somewhere in its name or arguments is not.* @param {string[]} argv* @param {string} version+ * @param {{node?: string}} [options] `node`: the Node runNpm starts npm with+ * (npmCommand's `execPath`; default: this one)* @returns {boolean}*/-export function isReleaseInstall(argv, version) {+export function isReleaseInstall(+ argv,+ version,+ {node = process.execPath} = {},+) {const name = (/** @type {string | undefined} */ arg) =>(arg ?? '').split(/[\\/]/u)@@ -839,9 +848,8 @@ export function isReleaseInstall(argv, version) {?.replace(/\.(?:exe|cmd)$/iu, '').toLowerCase() ?? '';const program = name(argv[0]);- const npm =- program === 'npm' ||- (/^node(?:[-.\d]*)$/u.test(program) && name(argv[1]) === 'npm-cli.js');+ const isNode = /^node(?:[-.\d]*)$/u.test(program) || program === name(node);+ const npm = program === 'npm' || (isNode && name(argv[1]) === 'npm-cli.js');return (npm &&argv.includes('install') &&diff --git a/packages/cli/foundation/release/cache.test.mjs b/packages/cli/foundation/release/cache.test.mjsindex 6818e84409..9221e5f6fa 100644--- a/packages/cli/foundation/release/cache.test.mjs+++ b/packages/cli/foundation/release/cache.test.mjs@@ -280,6 +280,32 @@ describe.skipIf(process.platform === 'win32')(expect(isReleaseInstall(['C:\\npm\\npm.cmd', ...INSTALL], '9.9.9')).toBe(true,);+ // The Node runNpm starts npm with, whatever its file is named, as a+ // distribution or a toolchain names it.+ for (const node of [+ '/opt/toolchain/bin/node-linux-x64',+ '/usr/bin/nodejs',+ 'C:\\tools\\node-win-x64.exe',+ ]) {+ expect(+ isReleaseInstall(+ [node, '/x/npm/bin/npm-cli.js', ...INSTALL],+ '9.9.9',+ {+ node,+ },+ ),+ node,+ ).toBe(true);+ }+ // Another program running npm-cli.js is not a Node by name.+ expect(+ isReleaseInstall(+ ['/usr/local/bin/nodemon', '/x/npm/bin/npm-cli.js', ...INSTALL],+ '9.9.9',+ {node: '/usr/bin/node'},+ ),+ ).toBe(false);for (const argv of [['/opt/my-npm-tool', ...INSTALL],['python3', '-c', 'sleep', '/home/me/notes/npm-debug.log', ...INSTALL],