Visitar URL original
fix(pack): honor min-release-age-exclude (#9811) · npm/cli@3529ca2 · GitHub
Skip to content

Commit 3529ca2

Browse files
github-actions[bot]martinrrmCopilot
authored
fix(pack): honor min-release-age-exclude (#9811)
Backport of #9760 to `release/v11`. Co-authored-by: martin <martin.ruiz.mares@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: dec204b6-ad66-45a5-8228-831e306f6ba6
1 parent 67f12ae commit 3529ca2

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

‎lib/commands/pack.js‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ const pacote = require('pacote')
22
const libpack = require('libnpmpack')
33
const npa = require('npm-package-arg')
44
const { log, output } = require('proc-log')
5+
const {
6+
isReleaseAgeExcluded,
7+
trustedSpecName,
8+
} = require('@npmcli/arborist/lib/release-age-exclude.js')
59
const { getContents, logTar } = require('../utils/tar.js')
610
const BaseCommand = require('../base-cmd.js')
711

@@ -35,23 +39,27 @@ class Pack extends BaseCommand {
3539
const manifests = []
3640
for (const arg of args) {
3741
const spec = npa(arg)
42+
const options = isReleaseAgeExcluded(
43+
trustedSpecName(spec),
44+
this.npm.flatOptions.minReleaseAgeExclude
45+
) ? { ...this.npm.flatOptions, before: null } : this.npm.flatOptions
3846
const manifest = await pacote.manifest(spec, {
39-
...this.npm.flatOptions,
47+
...options,
4048
Arborist,
4149
preferOnline: true,
4250
_isRoot: true,
4351
})
4452
if (!manifest._id) {
4553
throw new Error('Invalid package, must have name and version')
4654
}
47-
manifests.push({ arg, manifest })
55+
manifests.push({ arg, manifest, options })
4856
}
4957

5058
// Load tarball names up for printing afterward to isolate from the noise generated during packing
5159
const tarballs = []
52-
for (const { arg, manifest } of manifests) {
60+
for (const { arg, manifest, options } of manifests) {
5361
const tarballData = await libpack(arg, {
54-
...this.npm.flatOptions,
62+
...options,
5563
foregroundScripts: this.npm.config.isDefault('foreground-scripts')
5664
? true
5765
: this.npm.config.get('foreground-scripts'),

‎test/lib/commands/pack.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const t = require('tap')
22
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
33
const { cleanZlib } = require('../../fixtures/clean-snapshot')
4+
const MockRegistry = require('@npmcli/mock-registry')
45
const path = require('node:path')
56
const fs = require('node:fs')
67

@@ -167,6 +168,61 @@ t.test('foreground-scripts can still be set to false', async t => {
167168
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
168169
})
169170

171+
t.test('min-release-age-exclude applies to registry packages', async t => {
172+
const name = '@myscope/some-package'
173+
const version = '1.2.3'
174+
const { npm, outputs } = await loadMockNpm(t, {
175+
prefixDir: {
176+
package: {
177+
'package.json': JSON.stringify({ name, version }),
178+
},
179+
},
180+
config: {
181+
'min-release-age': 7,
182+
'min-release-age-exclude': ['@myscope/*'],
183+
},
184+
})
185+
const registry = new MockRegistry({
186+
tap: t,
187+
registry: npm.config.get('registry'),
188+
})
189+
const manifest = registry.manifest({ name, versions: [version] })
190+
await registry.package({
191+
manifest,
192+
times: 2,
193+
tarballs: { [version]: path.join(npm.prefix, 'package') },
194+
})
195+
196+
await npm.exec('pack', [`${name}@${version}`])
197+
198+
const filename = 'myscope-some-package-1.2.3.tgz'
199+
t.strictSame(outputs, [filename])
200+
t.ok(fs.statSync(path.resolve(npm.prefix, filename)))
201+
})
202+
203+
t.test('excluded alias name does not bypass min-release-age for its target', async t => {
204+
const target = 'other-package'
205+
const version = '1.2.3'
206+
const { npm } = await loadMockNpm(t, {
207+
config: {
208+
'min-release-age': 7,
209+
'min-release-age-exclude': ['@myscope/*'],
210+
},
211+
})
212+
const registry = new MockRegistry({
213+
tap: t,
214+
registry: npm.config.get('registry'),
215+
})
216+
await registry.package({
217+
manifest: registry.manifest({ name: target, versions: [version] }),
218+
})
219+
220+
await t.rejects(
221+
npm.exec('pack', [`@myscope/alias@npm:${target}@${version}`]),
222+
{ code: 'ETARGET' }
223+
)
224+
})
225+
170226
t.test('invalid packument', async t => {
171227
const { npm, outputs } = await loadMockNpm(t, {
172228
prefixDir: {

0 commit comments

Comments
 (0)