Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
feat(publish): add support for publishConfig on manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 31, 2018
1 parent ce17c3c commit 161723b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function publish (manifest, tarball, opts) {
}
const spec = npa.resolve(manifest.name, manifest.version)
// NOTE: spec is used to pick the appropriate registry/auth combo.
opts = opts.concat({ spec })
opts = opts.concat(manifest.publishConfig, { spec })
const reg = npmFetch.pickRegistry(spec, opts)
const auth = npmAuth(reg, opts)
const pubManifest = patchedManifest(spec, auth, manifest, opts)
Expand Down
62 changes: 62 additions & 0 deletions test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,65 @@ test('publish includes access', t => {
})
})
})

test('publishConfig on manifest', t => {
const manifest = {
name: 'libnpmpublish',
version: '1.0.0',
description: 'some stuff',
publishConfig: {
registry: REG
}
}
return mockTar({
'package.json': JSON.stringify(manifest),
'index.js': 'console.log("hello world")'
}).then(tarData => {
const shasum = crypto.createHash('sha1').update(tarData).digest('hex')
const integrity = ssri.fromData(tarData, { algorithms: ['sha512'] })
const packument = {
name: 'libnpmpublish',
description: 'some stuff',
readme: '',
_id: 'libnpmpublish',
'dist-tags': {
latest: '1.0.0'
},
versions: {
'1.0.0': {
_id: 'libnpmpublish@1.0.0',
_nodeVersion: process.versions.node,
name: 'libnpmpublish',
version: '1.0.0',
description: 'some stuff',
dist: {
shasum,
integrity: integrity.toString(),
tarball: `http://mock.reg/libnpmpublish/-/libnpmpublish-1.0.0.tgz`
},
publishConfig: {
registry: REG
}
}
},
_attachments: {
'libnpmpublish-1.0.0.tgz': {
'content_type': 'application/octet-stream',
data: tarData.toString('base64'),
length: tarData.length
}
}
}
const srv = tnock(t, REG)
srv.put('/libnpmpublish', body => {
t.deepEqual(body, packument, 'posted packument matches expectations')
return true
}, {
authorization: 'Bearer deadbeef'
}).reply(201, {})

return publish(manifest, tarData, { token: 'deadbeef' }).then(ret => {
t.ok(ret, 'publish succeeded')
})
})
})

0 comments on commit 161723b

Please sign in to comment.