Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg): properly output in workspace mode #6977

Merged
merged 1 commit into from
Nov 13, 2023
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
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 @@ -662,6 +662,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