Skip to content
Open
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
5 changes: 2 additions & 3 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ class Publish extends BaseCommand {
prefix: this.npm.localPrefix,
workspaces: this.workspacePaths,
})
const pkgContents = await getContents(manifest, tarballData)
const logPkg = () => logTar(pkgContents, { unicode, json, key: pkgContents.name })

// The purpose of re-reading the manifest is in case it changed, so that we send the latest and greatest thing to the registry note that publishConfig might have changed as well!
manifest = await this.#getManifest(spec, opts, true)
// re-check the authoritative manifest in case a lifecycle script introduced packageExtensions
this.#assertNoPackageExtensions(manifest)
const pkgContents = await getContents(manifest, tarballData)
const logPkg = () => logTar(pkgContents, { unicode, json, key: pkgContents.name })
const force = this.npm.config.get('force')
const isDefaultTag = this.npm.config.isDefault('tag') && !manifest.publishConfig?.tag

Expand Down
22 changes: 22 additions & 0 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ t.test('re-loads publishConfig.registry if added during script process', async t
t.matchSnapshot(joinedOutput(), 'new package version')
})

t.test('reports the version bumped by prepublishOnly', async t => {
const { npm, joinedOutput, registry } = await loadNpmWithRegistry(t, {
config: { ...auth, 'foreground-scripts': false },
prefixDir: {
'package.json': JSON.stringify({
...pkgJson,
scripts: { prepublishOnly: 'node bump.js' },
}, null, 2),
'bump.js': [
"const fs = require('fs')",
"const p = JSON.parse(fs.readFileSync('package.json'))",
"p.version = '1.0.1'",
"fs.writeFileSync('package.json', JSON.stringify(p))",
].join('\n'),
},
authorization: token,
})
registry.publish(pkg, { packageJson: { ...pkgJson, version: '1.0.1' } })
await npm.exec('publish', [])
t.match(joinedOutput(), `+ ${pkg}@1.0.1`)
})

t.test('prioritize CLI flags over publishConfig', async t => {
const initPackageJson = {
...pkgJson,
Expand Down