@@ -28,6 +28,46 @@ const { t, tf } = require('./i18n');
2828
2929const execFileAsync = promisify ( execFile ) ;
3030
31+ function stripWrappingQuotes ( value ) {
32+ return String ( value || '' ) . trim ( ) . replace ( / ^ " ( .* ) " $ / , '$1' ) ;
33+ }
34+
35+ function resolveNpmInvocation ( options = { } ) {
36+ const platform = options . platform || process . platform ;
37+ const env = options . env || process . env ;
38+ const execPath = options . execPath || process . execPath ;
39+ const fileExists = options . fileExists || fs . existsSync ;
40+ const npmExecPath = stripWrappingQuotes ( env . npm_execpath ) ;
41+
42+ if ( npmExecPath && / \. j s $ / i. test ( npmExecPath ) && fileExists ( npmExecPath ) ) {
43+ return {
44+ command : execPath ,
45+ prefixArgs : [ npmExecPath ] ,
46+ execOptions : { } ,
47+ } ;
48+ }
49+
50+ return {
51+ command : platform === 'win32' ? 'npm.cmd' : 'npm' ,
52+ prefixArgs : [ ] ,
53+ execOptions : platform === 'win32' ? { shell : true } : { } ,
54+ } ;
55+ }
56+
57+ async function runNpm ( args , options = { } ) {
58+ const invocation = resolveNpmInvocation ( ) ;
59+
60+ return execFileAsync (
61+ invocation . command ,
62+ [ ...invocation . prefixArgs , ...args ] ,
63+ {
64+ ...options ,
65+ ...invocation . execOptions ,
66+ windowsHide : true ,
67+ } ,
68+ ) ;
69+ }
70+
3171/**
3272 * Gold color for Pro branding.
3373 * Falls back gracefully if chalk hex is unavailable.
@@ -749,10 +789,8 @@ async function extractProArtifactToTemp(artifactPath, tempRoot) {
749789 dependencies : { } ,
750790 } ) ;
751791
752- const npmBin = process . platform === 'win32' ? 'npm.cmd' : 'npm' ;
753792 try {
754- await execFileAsync (
755- npmBin ,
793+ await runNpm (
756794 [ 'install' , artifactPath , '--ignore-scripts' , '--no-audit' , '--no-fund' , '--no-save' , '--silent' ] ,
757795 {
758796 cwd : installRoot ,
@@ -776,10 +814,8 @@ async function extractProArtifactToTemp(artifactPath, tempRoot) {
776814async function installProArtifactIntoTarget ( artifactPath , targetDir ) {
777815 await fs . ensureDir ( targetDir ) ;
778816
779- const npmBin = process . platform === 'win32' ? 'npm.cmd' : 'npm' ;
780817 try {
781- await execFileAsync (
782- npmBin ,
818+ await runNpm (
783819 [
784820 'install' ,
785821 artifactPath ,
@@ -2163,6 +2199,7 @@ module.exports = {
21632199 generateMachineId,
21642200 persistLicenseCache,
21652201 resolveLicenseServerUrl,
2202+ resolveNpmInvocation,
21662203 ensureKeyValidationParity,
21672204 acquireProArtifactSourceDir,
21682205 downloadArtifactFile,
0 commit comments