Skip to content

Commit 10db3ca

Browse files
authoredNov 13, 2023
fix(pkg): properly output in workspace mode (#6990)
1 parent 6ab06d7 commit 10db3ca

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed
 

‎lib/commands/pkg.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ class Pkg extends BaseCommand {
8282
}
8383
}
8484

85-
// only outputs if not running with workspaces config,
86-
// in case you're retrieving info for workspaces the pkgWorkspaces
87-
// will handle the output to make sure it get keyed by ws name
88-
if (!this.npm.config.get('workspaces')) {
85+
// only outputs if not running with workspaces config
86+
// execWorkspaces will handle the output otherwise
87+
if (!this.workspaces) {
8988
this.npm.output(JSON.stringify(result, null, 2))
9089
}
9190

‎test/lib/commands/pkg.js

+37
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,43 @@ t.test('workspaces', async t => {
618618
)
619619
})
620620

621+
t.test('single workspace', async t => {
622+
const { pkg, OUTPUT } = await mockNpm(t, {
623+
prefixDir: {
624+
'package.json': JSON.stringify({
625+
name: 'root',
626+
version: '1.0.0',
627+
workspaces: [
628+
'packages/*',
629+
],
630+
}),
631+
packages: {
632+
a: {
633+
'package.json': JSON.stringify({
634+
name: 'a',
635+
version: '1.0.0',
636+
}),
637+
},
638+
b: {
639+
'package.json': JSON.stringify({
640+
name: 'b',
641+
version: '1.2.3',
642+
}),
643+
},
644+
},
645+
},
646+
config: { workspace: ['packages/a'] },
647+
})
648+
649+
await pkg('get', 'name', 'version')
650+
651+
t.strictSame(
652+
JSON.parse(OUTPUT()),
653+
{ a: { name: 'a', version: '1.0.0' } },
654+
'should only return info for one workspace'
655+
)
656+
})
657+
621658
t.test('fix', async t => {
622659
const { pkg, readPackageJson } = await mockNpm(t, {
623660
prefixDir: {

0 commit comments

Comments
 (0)
Please sign in to comment.