diff --git a/.github/workflows/bench-history.yaml b/.github/workflows/bench-history.yaml index 39c16f408f14..22893b578707 100644 --- a/.github/workflows/bench-history.yaml +++ b/.github/workflows/bench-history.yaml @@ -34,7 +34,7 @@ jobs: run: | corepack enable pnpm i - ./x build cli:release + pnpm -w build:cli:release export ROOT_DIR=$(pwd) && cd benchcases/react-refresh && pnpm dev - name: Store benchmark result diff --git a/.github/workflows/release-canary.yml b/.github/workflows/release-canary.yml index a1535e525287..6b043c9d4f65 100644 --- a/.github/workflows/release-canary.yml +++ b/.github/workflows/release-canary.yml @@ -42,7 +42,7 @@ jobs: - name: Build run: | set -e - USE_ZIG=1 ./x build cli:release:all + USE_ZIG=1 pnpm -w build:cli:release:all - name: Release uses: modern-js-dev/actions@v2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26f1813e8bb0..4d440cac8a77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -157,5 +157,5 @@ To make releasing easier, Rspack use github action to automate creating versioni 1. Install `go install github.com/go-delve/delve/cmd/dlv@latest` 2. Install vscode extension [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) and [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) -3. build `@rspack/cli` and napi binding by run `./x build cli:debug` +3. build `@rspack/cli` and napi binding by run `pnpm -w build:cli:debug` 4. In Vscode's `Run and Debug` tab, select `debug-rspack` to start debugging the initial launch of `@rspack/cli`, This task is configured in `.vscode/launch.json`, which launch node debugger and rust debugger together. so you can debug both rust and nodejs code. diff --git a/Makefile b/Makefile deleted file mode 100644 index 43f2c8e212c1..000000000000 --- a/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -# github/three: -# mkdir -p github -# git clone --depth 1 --branch r108 https://github.com/mrdoob/three.js.git github/three -copy/three: - - mkdir -p benchcases/three/src - echo > benchcases/three/src/entry.js - for i in 1 2 3 4 5 6 7 8 9 10; do test -d "benchcases/three/src/copy$$i" || cp -r examples/.three/src "benchcases/three/src/copy$$i"; done - for i in 1 2 3 4 5 6 7 8 9 10; do echo "import * as copy$$i from './copy$$i/Three.js'; export {copy$$i}" >> benchcases/three/src/entry.js; done - echo "module.exports = {mode: 'development',entry: {index: {import: ['./src/entry.js']}}};" > benchcases/three/test.config.js - echo "module.exports = {mode: 'development',entry: {index: ['./benchcases/three/src/entry.js']},devtool: 'eval',cache: {type: 'filesystem'}}" > benchcases/three/webpack.config.js - -flamegraph: - samply record ./target/release/bench - -bench_three: | copy/three - @cargo build -p bench --release - @echo "rspack" - @hyperfine --warmup 3 \ - -n rspack './target/release/bench' \ - -n esbuild './node_modules/esbuild/bin/esbuild --bundle --global-name=THREE benchcases/three/src/entry.js --outfile=benchcases/three/esbuild/entry.esbuild.js --timing' \ - -n webpack './node_modules/webpack-cli/bin/cli.js -c ./benchcases/three/webpack.config.js' - - -esbuild_trace: - ./node_modules/esbuild/bin/esbuild --bundle benchcases/three/src/entry.js --outfile=/dev/null --trace=esbuild.trace - go tool trace esbuild.trace - -esbuild_cpuprofile: - ./node_modules/esbuild/bin/esbuild --bundle benchcases/three/src/entry.js --outfile=/dev/null --cpuprofile=esbuild.cpuprofile - go tool pprof -http=:1234 esbuild.cpuprofile - -rspack_trace: - TRACE=TRACE cargo run -F tracing -F hmr --release --bin bench - - -sync_bnpm: - @bnpm sync @rspack/core - @bnpm sync @rspack/dev-server - @bnpm sync @rspack/dev-client - @bnpm sync @rspack/dev-middleware - @bnpm sync @rspack/plugin-less - @bnpm sync @rspack/plugin-postcss - @bnpm sync @rspack/cli - @bnpm sync @rspack/binding - @bnpm sync @rspack/binding-darwin-arm64 - @bnpm sync @rspack/binding-darwin-x64 - @bnpm sync @rspack/binding-linux-x64-gnu - @bnpm sync create-rspack -snapshot_ci: - @./x build cli:release:all - @pnpm version:snapshot - @pnpm release:snapshot -release: - @./x build cli:release:all - @pnpm bump - @pnpm release - @make sync_bnpm -release-snapshot: - @make snapshot_ci - @make sync_bnpm \ No newline at end of file diff --git a/package.json b/package.json index d800f76fa5c1..6ef236624540 100644 --- a/package.json +++ b/package.json @@ -7,20 +7,17 @@ "scripts": { "dev": "pnpm --filter @rspack/cli run dev", "clean": "pnpm --filter @rspack/cli run clean", - "init": "./x i", - "setup": "./x i && ./x build binding", - "build:js": "./x build js", - "build:cli:debug": "./x build cli:debug", - "build:cli:release": "./x build cli:release", - "build:cli:release:all": "./x build cli:release:all", - "build:webpack": "./x build webpack", - "test:js": "./x test js", - "format:rs": "./x format rs", - "format:js": "./x format js", - "format-ci:toml": "./x format toml", + "build:js": "pnpm --filter \"@rspack/*\" build", + "build:cli:debug": "pnpm --filter @rspack/binding build:debug && pnpm --filter \"@rspack/*\" build", + "build:cli:release": "pnpm --filter @rspack/binding build:release && pnpm --filter \"@rspack/*\" build", + "build:cli:release:all": "pnpm --filter @rspack/binding build:release:all && pnpm --filter \"@rspack/*\" build", + "test:js": "pnpm -r run test", + "format:rs": "pnpm --filter @rspack/core... build", + "format:js": "npx prettier \"packages/**/*.{ts,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" --check --write", + "format-ci:toml": "npx @taplo/cli format --check '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", "format:toml": "npx @taplo/cli format '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", - "lint:js": "./x lint js", - "lint:rs": "./x lint rs", + "lint:js": "npx prettier \"packages/**/*.{ts,js}\" --check", + "lint:rs": "node ./scripts/check_rust_dependency.js", "build:binding:debug": "pnpm --filter @rspack/binding run build:debug", "build:binding:release": "pnpm --filter @rspack/binding run build:release", "version:snapshot": "changeset version --snapshot", diff --git a/scripts/check_rust_dependency.js b/scripts/check_rust_dependency.js index 8f09392d6bfe..259eeea0e36b 100644 --- a/scripts/check_rust_dependency.js +++ b/scripts/check_rust_dependency.js @@ -1,4 +1,15 @@ // @ts-nocheck + +// The code checks for multiple version dependencies in Rust crates. +// It reads the Cargo.toml files of all crates in a specified directory and extracts the dependencies. +// It then uses the cargo tree command to get a list of all dependencies and their versions and +// checks if any of the dependencies have multiple versions. +// If a crate has multiple version dependencies, an error message is pushed to an array. Finally, +// if there are any error messages, they are logged to the console along with a command to run for more information. + +// This is a best effort checking. It's possible that some dependencies may be missed, especially if +// they are not listed in the Cargo.toml file or if they are not direct dependencies of the crate. + const path = require("path"); const fs = require("fs"); const child_process = require("child_process"); diff --git a/scripts/cmd.js b/scripts/cmd.js deleted file mode 100644 index 5ee0ebbc3ace..000000000000 --- a/scripts/cmd.js +++ /dev/null @@ -1,262 +0,0 @@ -// @ts-nocheck -const cp = require("child_process"); -const log = require("./log"); -const { Command } = require("commander"); - -const COMMANDER_VERSION = "2.20.3"; - -function checkCommandVersion() { - const pkgInfo = require(require.resolve("commander/package.json")); - if (pkgInfo.version !== COMMANDER_VERSION) { - log.error( - `expected the version of Commander is 2.20.3, yours is ${pkgInfo.version}` - ); - process.exit(1); - } -} - -function createCLI() { - checkCommandVersion(); - - const cli = new Command(); - - cli.description("cli to control project").version("0.1.0"); - - cli - .command("install") - .alias("i") - .description("install node dependencies") - .action(() => { - const COMMAND = "pnpm i"; - log.info(`start install deps by '${COMMAND}'`); - cp.execSync(COMMAND, { - stdio: "inherit" - }); - log.info("finish install deps"); - }); - cli - .command("test") - .option("rust", "run all rust test") - .option("example", "test arco pro in rust side") - .option("js", "test all js packages") - .action(args => { - let command; - switch (args) { - case "rust": - command = "cargo test --all -- --nocapture"; - break; - case "js": - command = "pnpm -r run test"; - break; - case "example": - command = "cargo run --example arco_pro"; - break; - default: - log.error("invalid args, see `./x test -h` to get more information"); - process.exit(1); - } - if (!command) { - return; - } - log.info(`start test by '${command}'`); - cp.execSync(command, { - stdio: "inherit" - }); - log.info("test finished"); - }); - cli - .command("dev") - .description("run dev for ") - .option("js", "dev for all js package") - .action(args => { - let command; - switch (args) { - case "js": - command = `pnpm -parallel --filter "@rspack/*" dev`; - break; - default: - log.error(`invalid args, see "./x dev -h" to get more information`); - process.exit(1); - } - cp.execSync(command, { - stdio: "inherit" - }); - }); - cli - .command("build") - .option("binding", "build binding between rust and js") - .option("cli", "build @rspack/core which located in js side") - .option("bundle", "build example directory in rust side") - .option("webpack", "build webpack-example directory") - .option("js", "build all js library") - .option("examples", "build all rspack examples") - .action(args => { - let command; - switch (args) { - case "js": - command = `pnpm --filter "@rspack/*" build`; - break; - case "binding": - command = "pnpm --filter @rspack/binding build:debug"; - break; - case "cli": - command = `pnpm --filter @rspack/binding build:debug && pnpm --filter "@rspack/*" build`; - break; - case "cli:release": // only build local release binary, for benchmark - command = `pnpm --filter @rspack/binding build:release && pnpm --filter "@rspack/*" build`; - break; - case "cli:release:all": // build for all cross platform, for release - command = `pnpm --filter @rspack/binding build:release:all && pnpm --filter "@rspack/*" build`; - break; - case "cli:debug": // only build local debug release, for local debug - command = `pnpm --filter @rspack/binding build:debug && pnpm --filter "@rspack/*" build`; - break; - case "bundle": - command = "cargo run --package rspack --example bundle"; - break; - case "examples": - command = 'pnpm --filter "example-*" build'; - break; - default: - log.error("invalid args, see `./x build -h` to get more information"); - process.exit(1); - } - if (!command) { - return; - } - log.info(`start build by '${command}'`); - cp.execSync(command, { - stdio: "inherit" - }); - log.info("build finished"); - }); - - cli - .command("format") - .option("rs", "format rust code") - .option("js", "format js code") - .option("toml", "format toml code") - .action(args => { - let command; - switch (args) { - case "js": - command = - 'npx prettier "packages/**/*.{ts,js}" "crates/rspack_plugin_runtime/**/*.{ts,js}" --check --write'; - break; - case "rs": - command = "pnpm --filter @rspack/core... build"; - break; - case "toml": - command = - "npx @taplo/cli format --check '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'"; - break; - default: - log.error( - "invalid args, see `./x format -h` to get more information" - ); - process.exit(1); - } - if (!command) { - return; - } - log.info(`start format by '${command}'`); - cp.execSync(command, { - stdio: "inherit" - }); - log.info("format finished"); - }); - - cli - .command("lint") - .option("js", "lint js code") - .option("rs", "lint rust code") - .action(args => { - let commands = []; - switch (args) { - case "js": - commands = ['npx prettier "packages/**/*.{ts,js}" --check']; - break; - case "rs": - commands = [ - "cargo clippy --all -- --deny warnings", - "node ./scripts/check_rust_dependency.js" - ]; - break; - default: - log.error( - "invalid args, see `./x format -h` to get more information" - ); - process.exit(1); - } - commands.forEach(command => { - cp.execSync(command, { - stdio: "inherit" - }); - }); - log.info("lint finished"); - }); - cli - .command("clean") - .option("all", "clean all") - .option("dist", "clean build artifacts") - .option("npm", "clean node_modules") - .action(args => { - let commands = []; - let clean_npm = `rimraf node_modules && rimraf packages/**/node_modules`; - let clean_rust = `cargo clean`; - let clean_dist = `rimraf packages/**/{lib,dist}`; - log.info("start clean"); - switch (args) { - case "all": - commands = [clean_npm, clean_rust, clean_dist]; - break; - case "npm": - commands = [clean_npm]; - break; - case "dist": - commands = [clean_dist]; - } - commands.forEach(command => { - cp.execSync(command, { - stdio: "inherit" - }); - }); - log.info("finish clean"); - }); - - cli - .command("script") - .option( - "update_swc_version", - "update all swc sub packages to the correct version" - ) - .action(args => { - let commands = []; - switch (args) { - case "update_swc_version": - commands = ["node ./scripts/update_swc_version.js"]; - break; - default: - log.error( - "invalid args, see `./x format -h` to get more information" - ); - process.exit(1); - } - commands.forEach(command => { - cp.execSync(command, { - stdio: "inherit" - }); - }); - log.info("run script finished"); - }); - cli - .command("pkg-version") - .option("show package version for release note") - .action(args => { - const { version } = require("../packages/rspack-cli/package.json"); - console.log(version); - }); - return cli; -} - -module.exports = { createCLI }; diff --git a/x b/x deleted file mode 100755 index c68b26dbd93f..000000000000 --- a/x +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env node -const { createCLI } = require("./scripts/cmd.js"); - -/// use `./x --help` to get more information. -void (function () { - const cli = createCLI(); - cli.parse(process.argv); -})();