Skip to content

Commit 8d5fadf

Browse files
committed
fixed npm8
1 parent 41f7abc commit 8d5fadf

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

packages/yonpx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.15.0",
2+
"version": "0.15.1",
33
"name": "yonpx",
44
"repository": {
55
"type": "git",

packages/yonpx/src/__tests__/Test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ const { init, getNpxCmd, getPkgName, npxPath } = require("../init");
44

55
describe("Test yonpx", () => {
66
it("test getNpxCmd", () => {
7-
/*your test code*/
87
const actual = getNpxCmd(["", "", "reshow"]);
9-
expect(actual.p).to.deep.equal(["yo@latest", "generator-reshow@latest"]);
8+
if (actual.p) {
9+
expect(actual.p).to.deep.equal(["yo@latest", "generator-reshow@latest"]);
10+
} else {
11+
expect(actual[5]).to.equal("yo reshow ");
12+
}
1013
});
1114
});
1215

packages/yonpx/src/init.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ const npxPath = () => {
1010
if (!FS.existsSync(libnpx)) {
1111
libnpx = getPath([path]);
1212
}
13+
if (!FS.existsSync(libnpx)) {
14+
libnpx = getPath(["../lib", "node_modules/npm/lib/cli.js"]);
15+
}
1316
return { libnpx, npmCli: getPath(["npm"]) };
1417
};
1518
const { libnpx, npmCli } = npxPath();
16-
const npx = createRequire(libnpx)("libnpx");
19+
20+
const npx8 = (cmd) => {
21+
const npmcli = require(libnpx);
22+
process.argv[1] = libnpx;
23+
process.argv.splice(2, 0, "exec");
24+
for (let i = 0, j = cmd.length; i < j; i++) {
25+
process.argv[i + 3] = cmd[i];
26+
}
27+
npmcli(process);
28+
};
29+
30+
const npx =
31+
libnpx.substr(-6) === "cli.js" ? npx8 : createRequire(libnpx)("libnpx");
1732

1833
const pkgPrefix = "generator-";
1934
const isOrgReg = /^@[^/]+\//;
@@ -32,26 +47,26 @@ const getNpxCmd = (argv) => {
3247
return false;
3348
}
3449

35-
const parsed = npx.parseArgs(
36-
[
37-
"-p",
38-
"yo",
39-
"-p",
40-
getPkgName(generatorPkg),
41-
"-c",
42-
`yo ${generatorName} ${otherArgv.join(" ")}`,
43-
],
44-
npmCli
45-
);
46-
return parsed;
50+
let cmd = [
51+
"--package",
52+
"yo",
53+
"--package",
54+
getPkgName(generatorPkg),
55+
"--call",
56+
`yo ${generatorName} ${otherArgv.join(" ")}`,
57+
];
58+
if (npx.parseArgs != null) {
59+
cmd = npx.parseArgs(cmd, npmCli);
60+
}
61+
62+
return cmd;
4763
};
4864

4965
const init = async () => {
5066
const argv = process.argv;
5167
const cmdOptions = getNpxCmd(argv);
5268
if (cmdOptions) {
5369
await npx(cmdOptions);
54-
process.exit(0);
5570
} else {
5671
console.error("Generator not found.", argv);
5772
process.exit(1);

packages/yonpx/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,10 +3177,10 @@ require-relative@^0.8.7:
31773177
resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de"
31783178
integrity sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4=
31793179

3180-
reshow-unit@*:
3181-
version "0.0.5"
3182-
resolved "https://registry.yarnpkg.com/reshow-unit/-/reshow-unit-0.0.5.tgz#a3fa410f7ab266492edf6afb3dbd5130d66ced68"
3183-
integrity sha512-TMnfSJwbDKzq4SAZXh5oNzDLu1we4rT/ZOf2iXa69PdKZPqO0aVBq+jJr23Zh/itZbagEt+YKro7tQHNSxZqsg==
3180+
reshow-unit@^0.15.0:
3181+
version "0.15.0"
3182+
resolved "https://registry.yarnpkg.com/reshow-unit/-/reshow-unit-0.15.0.tgz#2ed3edb586066c59119f09e1430b63a415c044af"
3183+
integrity sha512-wvxGZLUCsTXpLbX95YYwbN/xxufj2M/ongbyQxbPnUoR0SyNmjK02+MbdEetWCrwQelQ46KqM5stG6Ky1ZHeEw==
31843184
dependencies:
31853185
chai "*"
31863186
enzyme "*"

0 commit comments

Comments
 (0)