diff --git a/lib/install.js b/lib/install.js index 3580cdd003..8c0daba988 100644 --- a/lib/install.js +++ b/lib/install.js @@ -385,7 +385,8 @@ async function install (gyp, argv) { log.verbose('tmpdir == cwd', 'automatically will remove dev files after to save disk space') gyp.todo.push({ name: 'remove', args: argv }) } - return gyp.commands.install([noretry].concat(argv)) + // The version to install is read from argv[0], so the sentinel goes on the end. + return gyp.commands.install(argv.concat([noretry])) } } diff --git a/test/test-install.js b/test/test-install.js index 8aecf78e11..2ffe13c09a 100644 --- a/test/test-install.js +++ b/test/test-install.js @@ -53,6 +53,43 @@ describe('install', function () { } }) + it('EACCES retry keeps the requested version', async () => { + const argvs = [] + const mockInstall = requireInject('../lib/install', { + 'graceful-fs': { + promises: { + stat (_) { + const err = new Error() + err.code = 'EACCES' + throw err + } + } + } + }) + const Gyp = { + devDir: __dirname, + opts: { + ensure: true + }, + commands: { + install: (...args) => { + argvs.push(args[0]) + return mockInstall(Gyp, ...args) + }, + remove: async () => {} + } + } + + try { + await Gyp.commands.install(['99.0.0']) + } catch (e) { + // the install itself cannot succeed here, only the argv it retries with matters + } + + assert.equal(argvs.length, 2) + assert.equal(argvs[1][0], '99.0.0') + }) + describe('parallel', function () { let prog