Skip to content

fix(npx): always save true when installing to npx cache #8154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
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 workspaces/libnpmexec/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ const exec = async (opts) => {
}
await npxArb.reify({
...flatOptions,
save: true,
add,
})
}
Expand Down
31 changes: 31 additions & 0 deletions workspaces/libnpmexec/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { resolve } = require('node:path')
const t = require('tap')
const { setup, createPkg, merge } = require('./fixtures/setup.js')
const crypto = require('node:crypto')
const { existsSync } = require('node:fs')

t.test('run from registry - no local packages', async t => {
const { fixtures, package } = createPkg({ versions: ['2.0.0'] })
Expand Down Expand Up @@ -297,3 +298,33 @@ t.test('npx tree triggers manifest fetch when local version does satisfy range u
value: 'packages-2.0.1',
})
})

t.test('override save to true when installing to npx cache', async t => {
const { fixtures, package } = createPkg({ versions: ['2.0.0'] })

const hash = crypto.createHash('sha512')
.update('@npmcli/create-index')
.digest('hex')
.slice(0, 16)

const { exec, path, registry, readOutput } = setup(t, {
testdir: merge(fixtures, {
global: {},
}),
})

await package({ registry, path })

await exec({
args: ['@npmcli/create-index'],
globalPath: resolve(path, 'global'),
save: false,
})

const packageJsonPath = resolve(path, 'npxCache', hash, 'package.json')
t.ok(existsSync(packageJsonPath), 'package.json should exist at npmCache')

t.match(await readOutput('@npmcli-create-index'), {
Copy link
Member

@wraithgar wraithgar Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test should be the existence of the package.json file. I believe thanks to @owlstronaut there is code in the libnpmexec tests that let you calculate the cache directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added assertion to test existence of package.json file. 👍

value: 'packages-2.0.0',
})
})