From 2d683fbbccb90b3d80b64137610a1c70359cb122 Mon Sep 17 00:00:00 2001 From: Masashi Katsumata Date: Thu, 12 Nov 2026 04:52:58 -0800 Subject: [PATCH] Read the package version under npm 12 as well npm 12 prints 'npm pkg get version' as plain text (' ') and, with --json, as {"": {"version": ""}}. The workflow parsed the npm 11 shape {"": ""} without --json, so the preview step failed with 'Unexpected token @' after the switch to npm 12 and nothing was published. Pass --json and accept both shapes, failing loudly if neither matches. --- .github/workflows/npm-publish.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 84eff79..390fcac 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -119,12 +119,19 @@ jobs: echo "::group::${package}" # Skip previewing when the local version is already on the registry. - local_version="$(npm pkg get version --workspace "${package}" | node -e ' + local_version="$(npm pkg get version --workspace "${package}" --json | node -e ' let input = ""; process.stdin.on("data", chunk => input += chunk); process.stdin.on("end", () => { + // npm 11 prints {"": ""}; npm 12 needs --json and + // prints {"": {"version": ""}}. Accept both. const parsed = JSON.parse(input); - const version = typeof parsed === "string" ? parsed : Object.values(parsed)[0]; + let version = typeof parsed === "string" ? parsed : Object.values(parsed)[0]; + if (version && typeof version === "object") version = version.version; + if (typeof version !== "string" || !version) { + console.error(`Could not read the version from: ${input}`); + process.exit(1); + } process.stdout.write(version); }); ')" @@ -164,12 +171,19 @@ jobs: echo "::group::${package}" # Skip publishing when the local version is already on the registry. - local_version="$(npm pkg get version --workspace "${package}" | node -e ' + local_version="$(npm pkg get version --workspace "${package}" --json | node -e ' let input = ""; process.stdin.on("data", chunk => input += chunk); process.stdin.on("end", () => { + // npm 11 prints {"": ""}; npm 12 needs --json and + // prints {"": {"version": ""}}. Accept both. const parsed = JSON.parse(input); - const version = typeof parsed === "string" ? parsed : Object.values(parsed)[0]; + let version = typeof parsed === "string" ? parsed : Object.values(parsed)[0]; + if (version && typeof version === "object") version = version.version; + if (typeof version !== "string" || !version) { + console.error(`Could not read the version from: ${input}`); + process.exit(1); + } process.stdout.write(version); }); ')"