Skip to content
Draft
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
11 changes: 0 additions & 11 deletions lib/npm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { resolve, dirname, join } = require('node:path')
const Config = require('@npmcli/config')
const which = require('which')
const fs = require('node:fs/promises')
const { definitions, flatten, nerfDarts, shorthands } = require('@npmcli/config/lib/definitions')
const usage = require('./utils/npm-usage.js')
Expand Down Expand Up @@ -87,16 +86,6 @@ class Npm {
}

async #load () {
await time.start('npm:load:whichnode', async () => {
// TODO should we throw here?
const node = await which(process.argv[0]).catch(() => {})
if (node && node.toUpperCase() !== process.execPath.toUpperCase()) {
log.verbose('node symlink', node)
process.execPath = node
this.config.execPath = node
}
})

await time.start('npm:load:configload', () => this.config.load())

// npm --versions
Expand Down
2 changes: 0 additions & 2 deletions tap-snapshots/test/lib/cli/exit-handler.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
'use strict'
exports[`test/lib/cli/exit-handler.js TAP handles unknown error with logs and debug file > debug file contents 1`] = `
XX timing npm:load:whichnode Completed in {TIME}ms
XX silly config load:file:{CWD}/npmrc
XX silly config load:file:{CWD}/prefix/.npmrc
XX silly config load:file:{CWD}/home/.npmrc
Expand Down Expand Up @@ -36,7 +35,6 @@ XX error A complete log of this run can be found in: {CWD}/cache/_logs/{DATE}-de
`

exports[`test/lib/cli/exit-handler.js TAP handles unknown error with logs and debug file > logs 1`] = `
timing npm:load:whichnode Completed in {TIME}ms
silly config load:file:{CWD}/npmrc
silly config load:file:{CWD}/prefix/.npmrc
silly config load:file:{CWD}/home/.npmrc
Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/lib/commands/install.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ verbose stack Error: The developer of this package has specified the following t
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:244:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:310:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:209:9)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:299:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:198:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
error EBADDEVENGINES Invalid devEngines.runtime
Expand Down Expand Up @@ -200,8 +200,8 @@ verbose stack Error: The developer of this package has specified the following t
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:244:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:310:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:209:9)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:299:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:198:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
error EBADDEVENGINES Invalid devEngines.runtime
Expand All @@ -226,8 +226,8 @@ verbose stack Error: The developer of this package has specified the following t
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:244:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:310:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:209:9)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:299:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:198:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
error EBADDEVENGINES Invalid devEngines.runtime
Expand Down
69 changes: 1 addition & 68 deletions test/lib/npm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const t = require('tap')
const { resolve, dirname, join } = require('node:path')
const { resolve, join } = require('node:path')
const fs = require('node:fs/promises')
const { time } = require('proc-log')
const { load: loadMockNpm } = require('../fixtures/mock-npm.js')
Expand Down Expand Up @@ -88,73 +88,6 @@ t.test('npm.load', async t => {
])
})

await t.test('node is a symlink', async t => {
const node = process.platform === 'win32' ? 'node.exe' : 'node'
const { Npm, npm, logs, outputs, prefix } = await loadMockNpm(t, {
prefixDir: {
bin: t.fixture('symlink', dirname(process.execPath)),
},
config: {
timing: true,
usage: '',
scope: 'foo',
},
argv: [
'token',
'revoke',
'blergggg',
],
globals: (dirs) => ({
'process.env.PATH': resolve(dirs.prefix, 'bin'),
'process.argv': [
node,
process.argv[1],
],
}),
})

t.equal(npm.config.get('scope'), '@foo', 'added the @ sign to scope')

t.match([
...logs.timing.filter((p) => p.startsWith('npm:load:whichnode')),
...logs.verbose,
...logs.timing.filter((p) => p.startsWith('npm:load')),
], [
/npm:load:whichnode Completed in [0-9.]+ms/,
`node symlink ${resolve(prefix, 'bin', node)}`,
/title npm token revoke blergggg/,
/argv "token" "revoke" "blergggg".*"--usage" "--scope" "foo"/,
/logfile logs-max:\d+ dir:.*/,
/logfile .*-debug-0.log/,
/npm:load:.* Completed in [0-9.]+ms/,
])
t.equal(process.execPath, resolve(prefix, 'bin', node))

outputs.length = 0
logs.length = 0
await npm.exec('ll', [])

t.equal(npm.command, 'll', 'command set to first npm command')
t.equal(npm.flatOptions.npmCommand, 'll', 'npmCommand flatOption set')

const ll = Npm.cmd('ll')
t.same(outputs, [ll.describeUsage], 'print usage')
npm.config.set('usage', false)

outputs.length = 0
logs.length = 0
await npm.exec('get', ['scope', 'usage'])

t.strictSame([npm.command, npm.flatOptions.npmCommand], ['ll', 'll'],
'does not change npm.command when another command is called')

t.match(logs, [
/timing config:load:flatten Completed in [0-9.]+ms/,
/timing command:config Completed in [0-9.]+ms/,
])
t.same(outputs, ['scope=@foo\nusage=false'])
})

await t.test('--no-workspaces with --workspace', async t => {
const { npm } = await loadMockNpm(t, {
prefixDir: {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/config/lib/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const setEnvs = (config) => {
// this doesn't have a full definition so we manually export it here
env.npm_config_npm_version = cliConf['npm-version'] || 'unknown'
env.npm_execpath = config.npmBin
env.NODE = env.npm_node_execpath = config.execPath
env.npm_node_execpath = config.execPath
}

module.exports = setEnvs
5 changes: 0 additions & 5 deletions workspaces/config/test/set-envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { execPath } = process
const cwd = process.cwd()
const globalPrefix = join(cwd, 'global')
const localPrefix = join(cwd, 'local')
const NODE = execPath

const npmPath = '{path}'
const npmBin = join(npmPath, 'bin/npm-cli.js')
Expand All @@ -24,7 +23,6 @@ t.test('set envs that are not defaults and not already in env', t => {
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
NODE,
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
Expand Down Expand Up @@ -79,7 +77,6 @@ t.test('set envs that are not defaults and not already in env, array style', t =
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
NODE,
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
Expand Down Expand Up @@ -131,7 +128,6 @@ t.test('set envs that are not defaults and not already in env, boolean edition',
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
NODE,
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
Expand Down Expand Up @@ -210,7 +206,6 @@ t.test('dont set configs marked as envExport:false', t => {
const envConf = Object.create(defaults)
const cliConf = Object.create(envConf)
const extras = {
NODE,
INIT_CWD: cwd,
EDITOR: 'vim',
HOME: undefined,
Expand Down
Loading