|
1 | 1 | const { resolve } = require('node:path')
|
2 | 2 | const t = require('tap')
|
3 | 3 | const { setup, createPkg, merge } = require('./fixtures/setup.js')
|
| 4 | +const crypto = require('node:crypto') |
4 | 5 |
|
5 | 6 | t.test('run from registry - no local packages', async t => {
|
6 | 7 | const { fixtures, package } = createPkg({ versions: ['2.0.0'] })
|
@@ -245,3 +246,54 @@ t.test('run from registry - non existant global path', async t => {
|
245 | 246 | value: 'packages-2.0.0',
|
246 | 247 | })
|
247 | 248 | })
|
| 249 | + |
| 250 | +t.test('npx tree triggers manifest fetch when local version does satisfy range using real npx cache inventory', async t => { |
| 251 | + // The local installation is version 1.0.0, which does NOT satisfy the spec ^2.0.0. |
| 252 | + const pkgData = createPkg({ |
| 253 | + localVersion: '1.0.0', |
| 254 | + versions: ['1.0.0', '2.0.0', '2.0.1'], |
| 255 | + name: '@npmcli/create-index', |
| 256 | + }) |
| 257 | + const { fixtures, package: pkg } = pkgData |
| 258 | + |
| 259 | + const hash = crypto.createHash('sha512') |
| 260 | + .update('@npmcli/create-index@^2.0.0') |
| 261 | + .digest('hex') |
| 262 | + .slice(0, 16) |
| 263 | + |
| 264 | + const npxCacheFixture = { |
| 265 | + [hash]: { |
| 266 | + 'package.json': { |
| 267 | + name: '@npmcli/create-index', |
| 268 | + version: '2.0.0', |
| 269 | + }, |
| 270 | + }, |
| 271 | + } |
| 272 | + |
| 273 | + const { exec: execFn, path, registry, readOutput, binLinks } = setup(t, { |
| 274 | + pkg: [pkg], |
| 275 | + testdir: { |
| 276 | + ...fixtures, |
| 277 | + npxCache: npxCacheFixture, |
| 278 | + }, |
| 279 | + }) |
| 280 | + |
| 281 | + // Set up the registry package so that a manifest fetch returns version 2.0.1. |
| 282 | + await pkg({ |
| 283 | + registry, |
| 284 | + path, |
| 285 | + tarballs: ['2.0.1'], |
| 286 | + }) |
| 287 | + await binLinks() |
| 288 | + |
| 289 | + // Execute in NPX mode with the spec ^2.0.0. |
| 290 | + // The local tree (version 1.0.0) does not satisfy ^2.0.0, so the system will find the cached package (version 2.0.0) in npxCache and then update from the registry to 2.0.1. |
| 291 | + await execFn({ |
| 292 | + args: ['create-index'], |
| 293 | + packages: ['@npmcli/create-index@^2.0.0'], |
| 294 | + }) |
| 295 | + |
| 296 | + t.match(await readOutput('@npmcli-create-index'), { |
| 297 | + value: 'packages-2.0.1', |
| 298 | + }) |
| 299 | +}) |
0 commit comments