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); }); ')"