File tree Expand file tree Collapse file tree 7 files changed +35
-9
lines changed Expand file tree Collapse file tree 7 files changed +35
-9
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ if [ $? -ne 0 ]; then
42
42
no_node_dir
43
43
fi
44
44
NPM_CLI_JS=" $CLI_BASEDIR /node_modules/npm/bin/npm-cli.js"
45
- NPM_PREFIX=` " $NODE_EXE " " $NPM_CLI_JS " prefix -g`
45
+ NPM_PREFIX_JS=" $CLI_BASEDIR /node_modules/npm/bin/npm-prefix.js"
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
1
+ #!/usr/bin/env node
2
+ // This is a single-use bin to help windows discover the proper prefix for npm without having to load all of npm first
3
+ // It does not accept argv params
4
+
5
+ const path = require ( 'path' )
6
+ const Config = require ( '@npmcli/config' )
7
+ const { definitions, flatten, shorthands } = require ( '@npmcli/config/lib/definitions' )
8
+ const config = new Config ( {
9
+ npmPath : path . dirname ( __dirname ) ,
10
+ // argv is explicitly not looked at since prefix is not something that can be changed via argv
11
+ argv : [ ] ,
12
+ definitions,
13
+ flatten,
14
+ shorthands,
15
+ excludeNpmCwd : false ,
16
+ } )
17
+
18
+ config . load ( ) . then ( ( ) => {
19
+ console . log ( config . globalPrefix )
20
+ } ) . catch ( err => {
21
+ console . trace ( err )
22
+ process . exit ( 1 )
23
+ } )
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ IF NOT EXIST "%NODE_EXE%" (
9
9
)
10
10
11
11
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 (
12
+ SET " NPM_PREFIX_JS = %~dp0 \node_modules\npm\bin\npm-prefix.js"
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 @@ -18,7 +18,8 @@ if ($nodebin -eq $null) {
18
18
$nodedir = $ (New-Object - ComObject Scripting.FileSystemObject).GetFile(" $nodebin " ).ParentFolder.Path
19
19
20
20
$npmclijs = " $nodedir /node_modules/npm/bin/npm-cli.js"
21
- $npmprefix = (& $nodeexe $npmclijs prefix - g)
21
+ $npmprefixjs = " $nodedir /node_modules/npm/bin/npm-prefix.js"
22
+ $npmprefix = (& $nodeexe $npmprefixjs )
22
23
if ($LASTEXITCODE -ne 0 ) {
23
24
Write-Host " Could not determine Node.js install directory"
24
25
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
You can’t perform that action at this time.
0 commit comments