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
1 change: 1 addition & 0 deletions lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Pack extends BaseCommand {
const spec = npa(arg)
const manifest = await pacote.manifest(spec, {
...this.npm.flatOptions,
...(spec.type === 'directory' && { allowDirectory: 'all' }),
Arborist,
preferOnline: true,
_isRoot: true,
Expand Down
19 changes: 19 additions & 0 deletions test/lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ t.test('dry run', async t => {
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
})

for (const allowDirectory of ['none', 'root']) {
t.test(`dry run with allow-directory=${allowDirectory}`, async t => {
const { npm, outputs } = await loadMockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'test-package',
version: '1.0.0',
}),
},
config: {
'allow-directory': allowDirectory,
'dry-run': true,
},
})
await npm.exec('pack', [])
t.strictSame(outputs, ['test-package-1.0.0.tgz'])
})
}

t.test('foreground-scripts defaults to true', async t => {
const { npm, outputs, logs } = await loadMockNpm(t, {
prefixDir: {
Expand Down
19 changes: 19 additions & 0 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ t.test('dry-run', async t => {
t.matchSnapshot(logs.notice)
})

for (const allowDirectory of ['none', 'root']) {
t.test(`dry-run with allow-directory=${allowDirectory}`, async t => {
const { joinedOutput, npm, registry } = await loadNpmWithRegistry(t, {
config: {
'allow-directory': allowDirectory,
'dry-run': true,
...auth,
},
prefixDir: {
'package.json': JSON.stringify(pkgJson, null, 2),
},
authorization: token,
})
registry.publish(pkg, { noPut: true })
await npm.exec('publish', [])
t.equal(joinedOutput(), `+ ${pkg}@1.0.0`)
})
}

t.test('foreground-scripts defaults to true', async t => {
const { outputs, npm, logs, registry } = await loadNpmWithRegistry(t, {
config: {
Expand Down
5 changes: 5 additions & 0 deletions workspaces/libnpmpack/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ async function pack (spec = 'file:.', opts = {}) {
// gets spec
spec = npa(spec)

// An explicit directory is the package being packed, not a dependency fetch.
if (spec.type === 'directory') {
opts = { ...opts, allowDirectory: 'all' }
}

const manifest = await pacote.manifest(spec, { ...opts, Arborist, _isRoot: true })

if (spec.type === 'directory') {
Expand Down
14 changes: 14 additions & 0 deletions workspaces/libnpmpack/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ t.test('packs from local directory', async t => {
})
})

for (const allowDirectory of ['none', 'root']) {
t.test(`packs an explicit local directory with allow-directory=${allowDirectory}`, async t => {
const testDir = t.testdir({
'package.json': JSON.stringify({
name: 'my-cool-pkg',
version: '1.0.0',
}, null, 2),
})

const tarball = await pack(testDir, { allowDirectory })
t.ok(tarball)
})
}

t.test('flattens path separators in name so tarball stays in packDestination', async t => {
const testDir = t.testdir({
src: {
Expand Down