diff options
author | Gar <gar+gh@danger.computer> | 2022-08-10 19:34:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 19:34:24 +0300 |
commit | daaf4619c85ecf62346770735cfa8e2ddecbef8b (patch) | |
tree | b565e27bc860abfe49a6de404e72d226d81ca5fd /test | |
parent | a4808fbd5601df10f6bdf20029cdbf1f06966c98 (diff) |
fix: ignore global prefix if --prefix is used (#5291)
When `--prefix` is used, both the local and global prefix values are set
to be identical. This is functionally broken because their directory
structures are inherently different (for instance, in posix the tree is
in `lib/node_modules` in the global prefix).
This commit makes npm exec ignore the global folders if it detects both
local and global prefix are identical.
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/commands/exec.js | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/test/lib/commands/exec.js b/test/lib/commands/exec.js index 6e4c3e224..f2bccf9e0 100644 --- a/test/lib/commands/exec.js +++ b/test/lib/commands/exec.js @@ -28,6 +28,7 @@ t.test('registry package', async t => { const { npm } = await loadMockNpm(t, { config: { + audit: false, yes: true, }, prefixDir: { @@ -43,7 +44,46 @@ t.test('registry package', async t => { }) await registry.package({ - times: 2, + manifest, + tarballs: { + '1.0.0': path.join(npm.prefix, 'npm-exec-test'), + } }) + + await npm.exec('exec', ['@npmcli/npx-test']) + const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success')) + t.ok(exists.isFile(), 'bin ran, creating file') +}) + +t.test('--prefix', async t => { + const registry = new MockRegistry({ + tap: t, + registry: 'https://registry.npmjs.org/', + }) + + const manifest = registry.manifest({ name: '@npmcli/npx-test' }) + manifest.versions['1.0.0'].bin = { 'npx-test': 'index.js' } + + const { npm } = await loadMockNpm(t, { + config: { + audit: false, + yes: true, + }, + prefixDir: { + 'npm-exec-test': { + 'package.json': JSON.stringify(manifest), + 'index.js': `#!/usr/bin/env node + require('fs').writeFileSync('npm-exec-test-success', '')`, + }, + }, + globals: ({ prefix }) => ({ + 'process.cwd': () => prefix, + }), + }) + + // This is what `--prefix` does + npm.globalPrefix = npm.localPrefix + + await registry.package({ manifest, tarballs: { '1.0.0': path.join(npm.prefix, 'npm-exec-test'), @@ -65,6 +105,7 @@ t.test('workspaces', async t => { const { npm } = await loadMockNpm(t, { config: { + audit: false, yes: true, workspace: ['workspace-a'], }, |