+48
-19
lines changedFilter options
+48
-19
lines changed Original file line number Diff line number Diff line change
@@ -41,8 +41,9 @@ if [ $? -ne 0 ]; then
41
41
fi
42
42
no_node_dir
43
43
fi
44
+
NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
44
45
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
45
-
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
46
+
NPM_PREFIX=`"$NODE_EXE" "$NPM_PREFIX_JS"`
46
47
if [ $? -ne 0 ]; then
47
48
no_node_dir
48
49
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
1
+
#!/usr/bin/env node
2
+
// This is a single-use bin to help windows discover the proper prefix for npm
3
+
// without having to load all of npm first
4
+
// It does not accept argv params
5
+
6
+
const path = require('path')
7
+
const Config = require('@npmcli/config')
8
+
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')
9
+
const config = new Config({
10
+
npmPath: path.dirname(__dirname),
11
+
// argv is explicitly not looked at since prefix is not something that can be changed via argv
12
+
argv: [],
13
+
definitions,
14
+
flatten,
15
+
shorthands,
16
+
excludeNpmCwd: false,
17
+
})
18
+
19
+
async function main () {
20
+
try {
21
+
await config.load()
22
+
// eslint-disable-next-line no-console
23
+
console.log(config.globalPrefix)
24
+
} catch (err) {
25
+
// eslint-disable-next-line no-console
26
+
console.error(err)
27
+
process.exit(1)
28
+
}
29
+
}
30
+
main()
Original file line number Diff line number Diff line change
@@ -8,8 +8,9 @@ IF NOT EXIST "%NODE_EXE%" (
8
8
SET "NODE_EXE=node"
9
9
)
10
10
11
+
SET "NPM_PREFIX_JS=%~dp0\node_modules\npm\bin\npm-prefix.js"
11
12
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
12
-
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
13
+
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_PREFIX_JS%"') DO (
13
14
SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
14
15
)
15
16
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ if ($nodebin -eq $null) {
17
17
}
18
18
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
19
19
20
-
$npmclijs="$nodedir/node_modules/npm/bin/npm-cli.js"
21
-
$npmprefix=(& $nodeexe $npmclijs prefix -g)
20
+
$npmprefixjs="$nodedir/node_modules/npm/bin/npm-prefix.js"
21
+
$npmprefix=(& $nodeexe $npmprefixjs)
22
22
if ($LASTEXITCODE -ne 0) {
23
23
Write-Host "Could not determine Node.js install directory"
24
24
exit 1
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@ if [ $? -ne 0 ]; then
41
41
fi
42
42
no_node_dir
43
43
fi
44
-
NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
44
+
NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
45
45
NPX_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npx-cli.js"
46
-
NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
46
+
NPM_PREFIX=`"$NODE_EXE" "$NPM_PREFIX_JS"`
47
47
if [ $? -ne 0 ]; then
48
48
no_node_dir
49
49
fi
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ IF NOT EXIST "%NODE_EXE%" (
8
8
SET "NODE_EXE=node"
9
9
)
10
10
11
-
SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
11
+
SET "NPM_PREFIX_JS=%~dp0\node_modules\npm\bin\npm-prefix.js"
12
12
SET "NPX_CLI_JS=%~dp0\node_modules\npm\bin\npx-cli.js"
13
-
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
13
+
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_PREFIX_JS%"') DO (
14
14
SET "NPM_PREFIX_NPX_CLI_JS=%%F\node_modules\npm\bin\npx-cli.js"
15
15
)
16
16
IF EXIST "%NPM_PREFIX_NPX_CLI_JS%" (
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ if ($nodebin -eq $null) {
17
17
}
18
18
$nodedir = $(New-Object -ComObject Scripting.FileSystemObject).GetFile("$nodebin").ParentFolder.Path
19
19
20
-
$npmclijs="$nodedir/node_modules/npm/bin/npm-cli.js"
21
-
$npmprefix=(& $nodeexe $npmclijs prefix -g)
20
+
$npmprefixjs="$nodedir/node_modules/npm/bin/npm-prefix.js"
21
+
$npmprefix=(& $nodeexe $npmprefixjs)
22
22
if ($LASTEXITCODE -ne 0) {
23
23
Write-Host "Could not determine Node.js install directory"
24
24
exit 1
Original file line number Diff line number Diff line change
@@ -44,23 +44,21 @@ t.test('shim contents', t => {
44
44
45
45
t.test('bash', t => {
46
46
const { diff, letters } = diffFiles(SHIMS.npm, SHIMS.npx)
47
-
t.match(diff[0].split('\n').reverse().join(''), /^NPX_CLI_JS=/, 'has NPX_CLI')
48
-
t.equal(diff.length, 1)
47
+
t.strictSame(diff, [])
49
48
t.strictSame([...letters], ['M', 'X'], 'all other changes are m->x')
50
49
t.end()
51
50
})
52
51
53
52
t.test('cmd', t => {
54
53
const { diff, letters } = diffFiles(SHIMS['npm.cmd'], SHIMS['npx.cmd'])
55
-
t.match(diff[0], /^SET "NPX_CLI_JS=/, 'has NPX_CLI')
56
-
t.equal(diff.length, 1)
54
+
t.strictSame(diff, [])
57
55
t.strictSame([...letters], ['M', 'X'], 'all other changes are m->x')
58
56
t.end()
59
57
})
60
58
61
59
t.test('pwsh', t => {
62
60
const { diff, letters } = diffFiles(SHIMS['npm.ps1'], SHIMS['npx.ps1'])
63
-
t.equal(diff.length, 0)
61
+
t.strictSame(diff, [])
64
62
t.strictSame([...letters], ['M', 'X'], 'all other changes are m->x')
65
63
t.end()
66
64
})
@@ -96,13 +94,12 @@ t.test('run shims', t => {
96
94
node_modules: {
97
95
npm: {
98
96
bin: {
99
-
'npx-cli.js': `throw new Error('this should not be called')`,
100
-
'npm-cli.js': `
101
-
const assert = require('assert')
97
+
'npm-prefix.js': `
102
98
const { resolve } = require('path')
103
-
assert.equal(process.argv.slice(2).join(' '), 'prefix -g')
104
99
console.log(resolve(__dirname, '../../../global-prefix'))
105
100
`,
101
+
'npx-cli.js': `throw new Error('local npx should not be called')`,
102
+
'npm-cli.js': `throw new Error('local npm should not be called')`,
106
103
},
107
104
},
108
105
},
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4