Skip to content

Commit

Permalink
fix: consolidate registryConfig application logic
Browse files Browse the repository at this point in the history
It should happen whenever we read a manifest anyways.

Tests were also rewritten to be real.
  • Loading branch information
wraithgar authored and lukekarrys committed Apr 19, 2022
1 parent 4a46a27 commit ced0acf
Show file tree
Hide file tree
Showing 4 changed files with 715 additions and 886 deletions.
31 changes: 15 additions & 16 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ class Publish extends BaseCommand {
const spec = npa(args[0])
let manifest = await this.getManifest(spec, opts)

if (manifest.publishConfig) {
flatten(manifest.publishConfig, opts)
}

// only run scripts for directory type publishes
if (spec.type === 'directory' && !ignoreScripts) {
await runScript({
Expand All @@ -92,12 +88,8 @@ class Publish extends BaseCommand {
// 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)
if (manifest.publishConfig) {
flatten(manifest.publishConfig, opts)
}

// note that logTar calls log.notice(), so if we ARE in silent mode,
// this will do nothing, but we still want it in the debuglog if it fails.
// JSON already has the package contents
if (!json) {
logTar(pkgContents, { unicode })
}
Expand Down Expand Up @@ -197,15 +189,22 @@ class Publish extends BaseCommand {

// if it's a directory, read it from the file system
// otherwise, get the full metadata from whatever it is
getManifest (spec, opts) {
// XXX can't pacote read the manifest from a directory?
async getManifest (spec, opts) {
let manifest
if (spec.type === 'directory') {
return readJson(`${spec.fetchSpec}/package.json`)
manifest = await readJson(`${spec.fetchSpec}/package.json`)
} else {
manifest = await pacote.manifest(spec, {
...opts,
fullmetadata: true,
fullReadJson: true,
})
}
if (manifest.publishConfig) {
flatten(manifest.publishConfig, opts)
}
return pacote.manifest(spec, {
...opts,
fullMetadata: true,
fullReadJson: true,
})
return manifest
}
}
module.exports = Publish
Loading

0 comments on commit ced0acf

Please sign in to comment.