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
7 changes: 6 additions & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ class Publish extends BaseCommand {
await this.#publish(args)
}

async execWorkspaces () {
async execWorkspaces (args) {
const useWorkspaces = args.length === 0 || args.includes('.')
if (!useWorkspaces) {
log.warn('Ignoring workspaces for specified package(s)')
return this.exec(args)
}
await this.setWorkspaces()

for (const [name, workspace] of this.workspaces.entries()) {
Expand Down
4 changes: 4 additions & 0 deletions tap-snapshots/test/lib/commands/publish.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ exports[`test/lib/commands/publish.js TAP workspaces all workspaces - some marke
+ workspace-a@1.2.3-a
`

exports[`test/lib/commands/publish.js TAP workspaces differet package spec > publish different package spec 1`] = `
+ pkg@1.2.3
`

exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in json 1`] = `
{
"workspace-a": {
Expand Down
42 changes: 42 additions & 0 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,48 @@ t.test('workspaces', t => {
await npm.exec('publish', [])
t.matchSnapshot(joinedOutput(), 'all workspaces in json')
})

t.test('differet package spec', async t => {
const testDir = {
'package.json': JSON.stringify(
{
...pkgJson,
workspaces: ['workspace-a'],
}, null, 2),
'workspace-a': {
'package.json': JSON.stringify({
name: 'workspace-a',
version: '1.2.3-a',
}),
},
'dir/pkg': {
'package.json': JSON.stringify({
name: 'pkg',
version: '1.2.3',
}),
},
}

const { npm, joinedOutput } = await loadMockNpm(t, {
config: {
...auth,
},
prefixDir: testDir,
chdir: ({ prefix }) => path.resolve(prefix, './workspace-a'),
})
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
authorization: token,
})
registry.nock
.put('/pkg', body => {
return t.match(body, { name: 'pkg' })
}).reply(200, {})
await npm.exec('publish', ['../dir/pkg'])
t.matchSnapshot(joinedOutput(), 'publish different package spec')
})

t.end()
})

Expand Down