Skip to content

Commit 2c4c1da

Browse files
authored
chore: remove zx in setup script (#2756)
chore: remove zx in setup script
1 parent 3e87b29 commit 2c4c1da

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"bump": "changeset version",
3030
"changeset": "changeset",
3131
"prepare": "is-ci || husky install",
32-
"pnpm:devPreinstall": "is-ci || node ./scripts/meta/doctor.mjs",
32+
"pnpm:devPreinstall": "is-ci || node ./scripts/doctor.mjs",
3333
"test:example": "pnpm --filter \"example-*\" build",
3434
"test:unit": "pnpm --filter \"@rspack/*\" test",
3535
"test:e2e": "pnpm --filter \"@rspack-e2e/*\" test"

scripts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ node ./scripts/xxxx.js
1010

1111
## Guidance
1212

13+
Scripts in `meta` folder are self-contained and shouldn't rely on denpendencis outside the `meta` folder(especially modules in `node_modules`). Built-in modules of `node` are ok to use.
14+
1315
### Writing scripts with zx
1416

1517
[zx](https://github.com/google/zx) is a wonderful tool for Writing scripts using JavaScript.
File renamed without changes.

scripts/meta/setup.mjs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
// Setup everything before pnpm install
2-
import "zx/globals";
2+
import { spawnSync } from "child_process";
33
import * as path from "path";
44

5-
// Make sure developers are at the workspace root
5+
/**
6+
*
7+
* @param {string} context
8+
* @param {(...args: any[]) => any} fn
9+
*/
10+
function runInContext(context, fn) {
11+
console.log(`⏺️ Running \`${context}\``);
12+
const status = fn();
13+
console.log(`⏹️ Finish \`${context}\` with ${status}`);
14+
}
615

716
try {
17+
// Make sure developers are at the workspace root
818
const { default: rootPkgJson } = await import(
919
path.join(process.cwd(), "package.json"),
1020
{
@@ -25,4 +35,13 @@ try {
2535
throw err;
2636
}
2737

28-
await $`corepack enable`;
38+
runInContext(
39+
"corepack enable",
40+
() =>
41+
spawnSync("corepack", ["enable"], {
42+
cwd: process.cwd(),
43+
env: process.env,
44+
stdio: "inherit",
45+
encoding: "utf-8"
46+
}).status
47+
);

0 commit comments

Comments
 (0)