+24
-1
lines changedFilter options
+24
-1
lines changed Original file line number Diff line number Diff line change
@@ -26,7 +26,11 @@ class RunScript extends BaseCommand {
26
26
static async completion (opts, npm) {
27
27
const argv = opts.conf.argv.remain
28
28
if (argv.length === 2) {
29
-
const { content: { scripts = {} } } = await pkgJson.normalize(npm.localPrefix)
29
+
const workspacePrefixes = npm.config.get('workspace', 'default')
30
+
const localPrefix = workspacePrefixes.length
31
+
? workspacePrefixes[0]
32
+
: npm.localPrefix
33
+
const { content: { scripts = {} } } = await pkgJson.normalize(localPrefix)
30
34
.catch(() => ({ content: {} }))
31
35
if (opts.isFish) {
32
36
return Object.keys(scripts).map(s => `${s}\t${scripts[s].slice(0, 30)}`)
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ const { resolve } = require('node:path')
3
3
const realRunScript = require('@npmcli/run-script')
4
4
const mockNpm = require('../../fixtures/mock-npm')
5
5
const { cleanCwd } = require('../../fixtures/clean-snapshot')
6
+
const path = require('node:path')
6
7
7
8
const mockRs = async (t, { windows = false, runScript, ...opts } = {}) => {
8
9
let RUN_SCRIPTS = []
@@ -511,6 +512,7 @@ t.test('workspaces', async t => {
511
512
prefixDir,
512
513
workspaces = true,
513
514
exec = [],
515
+
chdir = ({ prefix }) => prefix,
514
516
...config
515
517
} = {}) => {
516
518
const mock = await mockRs(t, {
@@ -574,6 +576,7 @@ t.test('workspaces', async t => {
574
576
...Array.isArray(workspaces) ? { workspace: workspaces } : { workspaces },
575
577
...config,
576
578
},
579
+
chdir,
577
580
runScript,
578
581
})
579
582
if (exec) {
@@ -582,6 +585,22 @@ t.test('workspaces', async t => {
582
585
return mock
583
586
}
584
587
588
+
t.test('completion', async t => {
589
+
t.test('in root dir', async t => {
590
+
const { runScript } = await mockWorkspaces(t)
591
+
const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run'] } } })
592
+
t.strictSame(res, [])
593
+
})
594
+
595
+
t.test('in workspace dir', async t => {
596
+
const { runScript } = await mockWorkspaces(t, {
597
+
chdir: ({ prefix }) => path.join(prefix, 'packages/c'),
598
+
})
599
+
const res = await runScript.completion({ conf: { argv: { remain: ['npm', 'run'] } } })
600
+
t.strictSame(res, ['test', 'posttest', 'lorem'])
601
+
})
602
+
})
603
+
585
604
t.test('list all scripts', async t => {
586
605
const { joinedOutput } = await mockWorkspaces(t)
587
606
t.matchSnapshot(joinedOutput())
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4