diff --git a/lib/commands/pack.js b/lib/commands/pack.js index 79e7f49f819ec..6a1bb53acb8aa 100644 --- a/lib/commands/pack.js +++ b/lib/commands/pack.js @@ -29,12 +29,13 @@ class Pack extends BaseCommand { const unicode = this.npm.config.get('unicode') const json = this.npm.config.get('json') + const Arborist = require('@npmcli/arborist') // Get the manifests and filenames first so we can bail early on manifest // errors before making any tarballs const manifests = [] for (const arg of args) { const spec = npa(arg) - const manifest = await pacote.manifest(spec, this.npm.flatOptions) + const manifest = await pacote.manifest(spec, { ...this.npm.flatOptions, Arborist }) if (!manifest._id) { throw new Error('Invalid package, must have name and version') } diff --git a/test/fixtures/git-test.tgz b/test/fixtures/git-test.tgz new file mode 100644 index 0000000000000..c06592708c2a0 Binary files /dev/null and b/test/fixtures/git-test.tgz differ diff --git a/test/lib/commands/exec.js b/test/lib/commands/exec.js index c2977a2f577cb..db2a8641708d3 100644 --- a/test/lib/commands/exec.js +++ b/test/lib/commands/exec.js @@ -254,3 +254,27 @@ t.test('npx --no-install @npmcli/npx-test', async t => { ) } }) + +t.test('packs from git spec', async t => { + const spec = 'test/test#111111aaaaaaaabbbbbbbbccccccdddddddeeeee' + const pkgPath = path.resolve(__dirname, '../../fixtures/git-test.tgz') + + const srv = MockRegistry.tnock(t, 'https://codeload.github.com') + srv.get('/test/test/tar.gz/111111aaaaaaaabbbbbbbbccccccdddddddeeeee') + .times(2) + .reply(200, await fs.readFile(pkgPath)) + + const { npm } = await loadMockNpm(t, { + config: { + audit: false, + yes: true, + }, + }) + try { + await npm.exec('exec', [spec]) + const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success')) + t.ok(exists.isFile(), 'bin ran, creating file') + } catch (err) { + t.fail(err, "shouldn't throw") + } +}) diff --git a/workspaces/libnpmexec/lib/index.js b/workspaces/libnpmexec/lib/index.js index 8344471696e25..78633a8cadb3c 100644 --- a/workspaces/libnpmexec/lib/index.js +++ b/workspaces/libnpmexec/lib/index.js @@ -24,7 +24,7 @@ const manifests = new Map() const getManifest = async (spec, flatOptions) => { if (!manifests.has(spec.raw)) { - const manifest = await pacote.manifest(spec, { ...flatOptions, preferOnline: true }) + const manifest = await pacote.manifest(spec, { ...flatOptions, preferOnline: true, Arborist }) manifests.set(spec.raw, manifest) } return manifests.get(spec.raw) diff --git a/workspaces/libnpmpack/lib/index.js b/workspaces/libnpmpack/lib/index.js index b026ad1a935c7..bd3e0c7bd7232 100644 --- a/workspaces/libnpmpack/lib/index.js +++ b/workspaces/libnpmpack/lib/index.js @@ -12,7 +12,7 @@ async function pack (spec = 'file:.', opts = {}) { // gets spec spec = npa(spec) - const manifest = await pacote.manifest(spec, opts) + const manifest = await pacote.manifest(spec, { ...opts, Arborist }) const stdio = opts.foregroundScripts ? 'inherit' : 'pipe' diff --git a/workspaces/libnpmpack/test/fixtures/git-test.tgz b/workspaces/libnpmpack/test/fixtures/git-test.tgz new file mode 100644 index 0000000000000..cc2b701d7df30 Binary files /dev/null and b/workspaces/libnpmpack/test/fixtures/git-test.tgz differ diff --git a/workspaces/libnpmpack/test/index.js b/workspaces/libnpmpack/test/index.js index f5eb647e4153b..62d5af1a80d2c 100644 --- a/workspaces/libnpmpack/test/index.js +++ b/workspaces/libnpmpack/test/index.js @@ -7,6 +7,7 @@ const spawk = tspawk(t) const fs = require('node:fs') const path = require('node:path') +const { resolve } = require('node:path') const pack = require('../lib/index.js') const tnock = require('./fixtures/tnock.js') @@ -133,6 +134,19 @@ t.test('packs from registry spec', async t => { t.ok(tarball) }) +t.test('packs from git spec', async t => { + const spec = 'test/test#111111aaaaaaaabbbbbbbbccccccdddddddeeeee' + const pkgPath = resolve(__dirname, 'fixtures/git-test.tgz') + + const srv = tnock(t, 'https://codeload.github.com') + srv.get('/test/test/tar.gz/111111aaaaaaaabbbbbbbbccccccdddddddeeeee') + .times(2) + .reply(200, fs.readFileSync(pkgPath)) + + const tarball = await pack(spec, { ...OPTS }) + t.ok(tarball) +}) + t.test('runs scripts in foreground when foregroundScripts === true', async t => { const testDir = t.testdir({ 'package.json': JSON.stringify({