Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class Install extends ArboristWorkspaceCmd {
args = ['.']
}

// throw usage error if trying to install empty package
// name to global space, e.g: `npm i -g ""`
if (where === globalTop && !args.every(Boolean)) {
throw this.usageError()
}

const opts = {
...this.npm.flatOptions,
auditLevel: null,
Expand Down
17 changes: 17 additions & 0 deletions test/lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ t.test('should install globally using Arborist', async t => {
t.strictSame(SCRIPTS, [], 'no scripts when installing globally')
})

t.test('should not install invalid global package name', async t => {
const { npm } = await loadMockNpm(t, {
'@npmcli/run-script': () => {},
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/arborist': function (args) {
throw new Error('should not reify')
},
})
npm.config.set('global', true)
npm.globalPrefix = path.resolve(t.testdir({}))
await t.rejects(
npm.exec('install', ['']),
/Usage:/,
'should not install invalid package name'
)
})

t.test('npm i -g npm engines check success', async t => {
const { npm } = await loadMockNpm(t, {
'../../lib/utils/reify-finish.js': async () => {},
Expand Down