unwrap-npm-cmd 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/resolve-npm-cmd.js +16 -13
- package/lib/utils.js +2 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function unwrapExe(exe, options) {
|
|
|
43
43
|
return [quote(process.execPath), quote(jsFile)].join(" ");
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
module.exports = function(cmd, options = { path: process.env.PATH }) {
|
|
46
|
+
module.exports = function (cmd, options = { path: process.env.PATH }) {
|
|
47
47
|
/* istanbul ignore next */
|
|
48
48
|
if (process.platform !== "win32") {
|
|
49
49
|
return cmd;
|
package/lib/resolve-npm-cmd.js
CHANGED
|
@@ -4,7 +4,8 @@ const Fs = require("fs");
|
|
|
4
4
|
const which = require("which");
|
|
5
5
|
const Path = require("path");
|
|
6
6
|
|
|
7
|
-
const { quote } = require("./utils");
|
|
7
|
+
const { quote, unquote } = require("./utils");
|
|
8
|
+
const nodeJsVer = parseInt(process.versions.node.split(".")[0]);
|
|
8
9
|
|
|
9
10
|
module.exports = function resolveNpmCmd(exe, options) {
|
|
10
11
|
// look for the windows CMD batch npm generates for JS
|
|
@@ -18,33 +19,35 @@ module.exports = function resolveNpmCmd(exe, options) {
|
|
|
18
19
|
const script = Fs.readFileSync(resolvedExe)
|
|
19
20
|
.toString()
|
|
20
21
|
.split("\n")
|
|
21
|
-
.map(x => x.trim());
|
|
22
|
+
.map((x) => x.trim());
|
|
22
23
|
|
|
23
24
|
const binName = Path.basename(resolvedExe).toLowerCase();
|
|
24
25
|
const resolvedDir = Path.dirname(resolvedExe);
|
|
25
26
|
// handle npm
|
|
26
27
|
let nodeCmd;
|
|
27
28
|
if (binName === "npm.cmd") {
|
|
28
|
-
nodeCmd = script.find(l => l.startsWith(`SET "NPM_CLI_JS=`)).replace(/NPM_CLI_JS=/, "");
|
|
29
|
+
nodeCmd = script.find((l) => l.startsWith(`SET "NPM_CLI_JS=`)).replace(/NPM_CLI_JS=/, "");
|
|
29
30
|
} else if (binName === "npx.cmd") {
|
|
30
|
-
nodeCmd = script.find(l => l.startsWith(`SET "NPX_CLI_JS=`)).replace(/NPX_CLI_JS=/, "");
|
|
31
|
+
nodeCmd = script.find((l) => l.startsWith(`SET "NPX_CLI_JS=`)).replace(/NPX_CLI_JS=/, "");
|
|
31
32
|
} else {
|
|
32
33
|
nodeCmd =
|
|
33
|
-
script.find(l => l.startsWith(`"%~dp0\\node.exe"`)) ||
|
|
34
|
-
script.find(l => l.startsWith(`"%_prog%"`));
|
|
34
|
+
script.find((l) => l.startsWith(`"%~dp0\\node.exe"`)) ||
|
|
35
|
+
script.find((l) => l.startsWith(`"%_prog%"`));
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
if (!nodeCmd) {
|
|
38
39
|
return quote(resolvedExe);
|
|
39
40
|
}
|
|
40
41
|
// update JS script from batch file
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
const a = nodeCmd.split(" ").filter((x) => x)[1];
|
|
43
|
+
const b = a.replace(`%~dp0`, resolvedDir).replace(`%dp0%`, resolvedDir);
|
|
44
|
+
let jsFile;
|
|
45
|
+
if (nodeJsVer < 18) {
|
|
46
|
+
jsFile = Path.normalize(b);
|
|
47
|
+
} else {
|
|
48
|
+
// starting with version 18, the behavior changed when there're escaping quotes
|
|
49
|
+
jsFile = quote(Path.normalize(unquote(b)));
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
return { jsFile };
|
|
50
53
|
};
|
package/lib/utils.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const Path = require("path");
|
|
4
4
|
|
|
5
|
-
const unquote = x =>
|
|
6
|
-
const quote = x => (!x.startsWith(`"`) ? `"${x}"` : x);
|
|
5
|
+
const unquote = (x) => x.trim().replace(/^['"]+|['"]+$/g, "");
|
|
6
|
+
const quote = (x) => (!x.startsWith(`"`) ? `"${x}"` : x);
|
|
7
7
|
const relative = (x, cwd) => {
|
|
8
8
|
const r = Path.relative(cwd || process.cwd(), unquote(x));
|
|
9
9
|
return r.startsWith(".") ? r : `.\\${r}`;
|