Skip to content

Commit

Permalink
chore: remove zx in setup script (#2756)
Browse files Browse the repository at this point in the history
chore: remove zx in setup script
  • Loading branch information
hyf0 authored Apr 14, 2023
1 parent 3e87b29 commit 2c4c1da
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"bump": "changeset version",
"changeset": "changeset",
"prepare": "is-ci || husky install",
"pnpm:devPreinstall": "is-ci || node ./scripts/meta/doctor.mjs",
"pnpm:devPreinstall": "is-ci || node ./scripts/doctor.mjs",
"test:example": "pnpm --filter \"example-*\" build",
"test:unit": "pnpm --filter \"@rspack/*\" test",
"test:e2e": "pnpm --filter \"@rspack-e2e/*\" test"
Expand Down
2 changes: 2 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ node ./scripts/xxxx.js

## Guidance

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.

### Writing scripts with zx

[zx](https://github.com/google/zx) is a wonderful tool for Writing scripts using JavaScript.
Expand Down
File renamed without changes.
25 changes: 22 additions & 3 deletions scripts/meta/setup.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// Setup everything before pnpm install
import "zx/globals";
import { spawnSync } from "child_process";
import * as path from "path";

// Make sure developers are at the workspace root
/**
*
* @param {string} context
* @param {(...args: any[]) => any} fn
*/
function runInContext(context, fn) {
console.log(`⏺️ Running \`${context}\``);
const status = fn();
console.log(`⏹️ Finish \`${context}\` with ${status}`);
}

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

await $`corepack enable`;
runInContext(
"corepack enable",
() =>
spawnSync("corepack", ["enable"], {
cwd: process.cwd(),
env: process.env,
stdio: "inherit",
encoding: "utf-8"
}).status
);

0 comments on commit 2c4c1da

Please sign in to comment.