Skip to content

Commit

Permalink
fix(pkg): properly output in workspace mode (#6977)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Nov 13, 2023
1 parent 6ab06d7 commit 12e13ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/commands/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ class Pkg extends BaseCommand {
}
}

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

Expand Down
37 changes: 37 additions & 0 deletions test/lib/commands/pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,43 @@ t.test('workspaces', async t => {
)
})

t.test('single workspace', async t => {
const { pkg, OUTPUT } = await mockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'root',
version: '1.0.0',
workspaces: [
'packages/*',
],
}),
packages: {
a: {
'package.json': JSON.stringify({
name: 'a',
version: '1.0.0',
}),
},
b: {
'package.json': JSON.stringify({
name: 'b',
version: '1.2.3',
}),
},
},
},
config: { workspace: ['packages/a'] },
})

await pkg('get', 'name', 'version')

t.strictSame(
JSON.parse(OUTPUT()),
{ a: { name: 'a', version: '1.0.0' } },
'should only return info for one workspace'
)
})

t.test('fix', async t => {
const { pkg, readPackageJson } = await mockNpm(t, {
prefixDir: {
Expand Down

0 comments on commit 12e13ee

Please sign in to comment.