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

fix: pass the scope option to pacote for auth purposes #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function pack (spec = 'file:.', opts = {}) {
// packs tarball
const tarball = await pacote.tarball(manifest._resolved, {
...opts,
scope: spec.scope, // this is necessary to correctly identify auth later
integrity: manifest._integrity
})

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/tnock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const nock = require('nock')
nock.disableNetConnect()

module.exports = tnock
function tnock (t, host) {
Expand Down
43 changes: 42 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ const pack = require('../index.js')
const tnock = require('./fixtures/tnock.js')

const OPTS = {
registry: 'https://mock.reg/'
registry: 'https://mock.reg/',
'@private:registry': 'https://private.reg',
'//private.reg/:_authToken': '123456'
}

const REG = OPTS.registry
const PRIVATEREG = OPTS['@private:registry']

t.test('packs from local directory', async t => {
const testDir = t.testdir({
Expand Down Expand Up @@ -89,3 +92,41 @@ t.test('packs from registry spec', async t => {
const tarball = await pack(spec, { ...OPTS })
t.ok(tarball)
})

t.test('packs from registry spec, using a private registry', async t => {
const spec = '@private/my-cool-pkg'
const packument = {
_id: '@private/my-cool-pkg',
name: '@private/my-cool-pkg',
description: 'some stuff',
'dist-tags': {
latest: '1.0.0'
},
versions: {
'1.0.0': {
_id: '@private/my-cool-pkg@1.0.0',
_nodeVersion: process.versions.node,
name: '@private/my-cool-pkg',
version: '1.0.0',
description: 'some stuff',
dist: {
shasum: 'some-shasum',
integrity: '123',
tarball: 'https://private.reg/download/@private/my-cool-pkg/-/my-cool-pkg-1.0.0.tgz'
}
}
}
}

console.error(PRIVATEREG)
const srv = tnock(t, PRIVATEREG)
srv.matchHeader('authorization', 'Bearer 123456')
.get('/@private%2fmy-cool-pkg').reply(200, packument)

// this one has a real slash after the scope because it's the tarball value from above
srv.matchHeader('authorization', 'Bearer 123456')
.get('/download/@private/my-cool-pkg/-/my-cool-pkg-1.0.0.tgz').reply(200, '')

const tarball = await pack(spec, { ...OPTS })
t.ok(tarball)
})