-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(install): very strict global npm engines
This will do an engines check when installing npm globally and fail if the new npm is known not to work in the current node version. It will not work for older npm versions because they don't have an engines field (it wasn't added till [email protected]). It will at least prevent npm@7 from being installed in node@8. PR-URL: #3731 Credit: @wraithgar Close: #3731 Reviewed-by: @nlf
- Loading branch information
Showing
4 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,146 @@ t.test('should install globally using Arborist', (t) => { | |
}) | ||
}) | ||
|
||
t.test('npm i -g npm engines check success', (t) => { | ||
const Install = t.mock('../../lib/install.js', { | ||
'../../lib/utils/reify-finish.js': async () => {}, | ||
'@npmcli/arborist': function () { | ||
this.reify = () => {} | ||
}, | ||
pacote: { | ||
manifest: () => { | ||
return { | ||
version: '100.100.100', | ||
engines: { | ||
node: '>1', | ||
}, | ||
} | ||
}, | ||
}, | ||
}) | ||
const npm = mockNpm({ | ||
globalDir: 'path/to/node_modules/', | ||
config: { | ||
global: true, | ||
}, | ||
}) | ||
const install = new Install(npm) | ||
install.exec(['npm'], er => { | ||
if (er) | ||
throw er | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('npm i -g npm engines check failure', (t) => { | ||
const Install = t.mock('../../lib/install.js', { | ||
pacote: { | ||
manifest: () => { | ||
return { | ||
_id: '[email protected]', | ||
version: '100.100.100', | ||
engines: { | ||
node: '>1000', | ||
}, | ||
} | ||
}, | ||
}, | ||
}) | ||
const npm = mockNpm({ | ||
globalDir: 'path/to/node_modules/', | ||
config: { | ||
global: true, | ||
}, | ||
}) | ||
const install = new Install(npm) | ||
install.exec(['npm'], er => { | ||
t.match(er, { | ||
message: 'Unsupported engine', | ||
pkgid: '[email protected]', | ||
current: { | ||
node: process.version, | ||
npm: '100.100.100', | ||
}, | ||
required: { | ||
node: '>1000', | ||
}, | ||
code: 'EBADENGINE', | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('npm i -g npm engines check failure forced override', (t) => { | ||
const Install = t.mock('../../lib/install.js', { | ||
'../../lib/utils/reify-finish.js': async () => {}, | ||
'@npmcli/arborist': function () { | ||
this.reify = () => {} | ||
}, | ||
pacote: { | ||
manifest: () => { | ||
return { | ||
_id: '[email protected]', | ||
version: '100.100.100', | ||
engines: { | ||
node: '>1000', | ||
}, | ||
} | ||
}, | ||
}, | ||
}) | ||
const npm = mockNpm({ | ||
globalDir: 'path/to/node_modules/', | ||
config: { | ||
force: true, | ||
global: true, | ||
}, | ||
}) | ||
const install = new Install(npm) | ||
install.exec(['npm'], er => { | ||
if (er) | ||
throw er | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('npm i -g npm@version engines check failure', (t) => { | ||
const Install = t.mock('../../lib/install.js', { | ||
pacote: { | ||
manifest: () => { | ||
return { | ||
_id: '[email protected]', | ||
version: '100.100.100', | ||
engines: { | ||
node: '>1000', | ||
}, | ||
} | ||
}, | ||
}, | ||
}) | ||
const npm = mockNpm({ | ||
globalDir: 'path/to/node_modules/', | ||
config: { | ||
global: true, | ||
}, | ||
}) | ||
const install = new Install(npm) | ||
install.exec(['npm@100'], er => { | ||
t.match(er, { | ||
message: 'Unsupported engine', | ||
pkgid: '[email protected]', | ||
current: { | ||
node: process.version, | ||
npm: '100.100.100', | ||
}, | ||
required: { | ||
node: '>1000', | ||
}, | ||
code: 'EBADENGINE', | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.test('completion to folder', async t => { | ||
const Install = t.mock('../../lib/install.js', { | ||
'../../lib/utils/reify-finish.js': async () => {}, | ||
|