Skip to content

Commit 7f541e8

Browse files
authored
fix: make pack and exec work with git hash refs (#7815)
Passing arborist constructor to pacote.manifest call because internally when fetching git deps DirFetcher requires Arborist constructor from GitFetcher https://github.com/npm/pacote/blob/main/CHANGELOG.md#1400-pre3-2022-09-28 - [x] Trying to add some tests Fixes: #6723
1 parent 852dd8b commit 7f541e8

File tree

7 files changed

+42
-3
lines changed

7 files changed

+42
-3
lines changed

lib/commands/pack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class Pack extends BaseCommand {
2929
const unicode = this.npm.config.get('unicode')
3030
const json = this.npm.config.get('json')
3131

32+
const Arborist = require('@npmcli/arborist')
3233
// Get the manifests and filenames first so we can bail early on manifest
3334
// errors before making any tarballs
3435
const manifests = []
3536
for (const arg of args) {
3637
const spec = npa(arg)
37-
const manifest = await pacote.manifest(spec, this.npm.flatOptions)
38+
const manifest = await pacote.manifest(spec, { ...this.npm.flatOptions, Arborist })
3839
if (!manifest._id) {
3940
throw new Error('Invalid package, must have name and version')
4041
}

test/fixtures/git-test.tgz

268 Bytes
Binary file not shown.

test/lib/commands/exec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,27 @@ t.test('npx --no-install @npmcli/npx-test', async t => {
254254
)
255255
}
256256
})
257+
258+
t.test('packs from git spec', async t => {
259+
const spec = 'test/test#111111aaaaaaaabbbbbbbbccccccdddddddeeeee'
260+
const pkgPath = path.resolve(__dirname, '../../fixtures/git-test.tgz')
261+
262+
const srv = MockRegistry.tnock(t, 'https://codeload.github.com')
263+
srv.get('/test/test/tar.gz/111111aaaaaaaabbbbbbbbccccccdddddddeeeee')
264+
.times(2)
265+
.reply(200, await fs.readFile(pkgPath))
266+
267+
const { npm } = await loadMockNpm(t, {
268+
config: {
269+
audit: false,
270+
yes: true,
271+
},
272+
})
273+
try {
274+
await npm.exec('exec', [spec])
275+
const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success'))
276+
t.ok(exists.isFile(), 'bin ran, creating file')
277+
} catch (err) {
278+
t.fail(err, "shouldn't throw")
279+
}
280+
})

workspaces/libnpmexec/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const manifests = new Map()
2424

2525
const getManifest = async (spec, flatOptions) => {
2626
if (!manifests.has(spec.raw)) {
27-
const manifest = await pacote.manifest(spec, { ...flatOptions, preferOnline: true })
27+
const manifest = await pacote.manifest(spec, { ...flatOptions, preferOnline: true, Arborist })
2828
manifests.set(spec.raw, manifest)
2929
}
3030
return manifests.get(spec.raw)

workspaces/libnpmpack/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function pack (spec = 'file:.', opts = {}) {
1212
// gets spec
1313
spec = npa(spec)
1414

15-
const manifest = await pacote.manifest(spec, opts)
15+
const manifest = await pacote.manifest(spec, { ...opts, Arborist })
1616

1717
const stdio = opts.foregroundScripts ? 'inherit' : 'pipe'
1818

245 Bytes
Binary file not shown.

workspaces/libnpmpack/test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const spawk = tspawk(t)
77

88
const fs = require('node:fs')
99
const path = require('node:path')
10+
const { resolve } = require('node:path')
1011
const pack = require('../lib/index.js')
1112
const tnock = require('./fixtures/tnock.js')
1213

@@ -133,6 +134,19 @@ t.test('packs from registry spec', async t => {
133134
t.ok(tarball)
134135
})
135136

137+
t.test('packs from git spec', async t => {
138+
const spec = 'test/test#111111aaaaaaaabbbbbbbbccccccdddddddeeeee'
139+
const pkgPath = resolve(__dirname, 'fixtures/git-test.tgz')
140+
141+
const srv = tnock(t, 'https://codeload.github.com')
142+
srv.get('/test/test/tar.gz/111111aaaaaaaabbbbbbbbccccccdddddddeeeee')
143+
.times(2)
144+
.reply(200, fs.readFileSync(pkgPath))
145+
146+
const tarball = await pack(spec, { ...OPTS })
147+
t.ok(tarball)
148+
})
149+
136150
t.test('runs scripts in foreground when foregroundScripts === true', async t => {
137151
const testDir = t.testdir({
138152
'package.json': JSON.stringify({

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy