From 6b54599ca7c123ebeef0bfc151b4b66ab5ae7870 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:59:34 -0700 Subject: [PATCH] Get publish script working on Windows/node 20 Part of #5135 --- bin/publish.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/publish.js b/bin/publish.js index 1f47a82bb2..7587b475e6 100644 --- a/bin/publish.js +++ b/bin/publish.js @@ -9,7 +9,9 @@ const os = require('os'); const path = require('path'); // Setup auth -fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`); +if (process.env['NPM_AUTH_TOKEN']) { + fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`); +} const isDryRun = process.argv.includes('--dry'); if (isDryRun) { @@ -118,7 +120,11 @@ function asArray(value) { } function getPublishedVersions(packageJson, version, tag) { - const versionsProcess = cp.spawnSync(os.platform === 'win32' ? 'npm.cmd' : 'npm', ['view', packageJson.name, 'versions', '--json']); + const versionsProcess = cp.spawnSync( + os.platform === 'win32' ? 'npm.cmd' : 'npm', + ['view', packageJson.name, 'versions', '--json'], + { shell: true } + ); if (versionsProcess.stdout.length === 0 && versionsProcess.stderr) { const err = versionsProcess.stderr.toString(); if (err.indexOf('404 Not Found - GET https://registry.npmjs.org/@xterm') > 0) {