Skip to content

Commit

Permalink
chore: use zx to replace xtask (#2840)
Browse files Browse the repository at this point in the history
* chore: use `zx` to replace xtask

* Fix script

* Fix
  • Loading branch information
hyf0 committed Apr 20, 2023
1 parent dcc1545 commit b4426ce
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 219 deletions.
3 changes: 1 addition & 2 deletions .cargo/config.toml
Expand Up @@ -5,8 +5,7 @@ CARGO_WORKSPACE_DIR = { value = "", relative = true }
[alias]
lint = "clippy --workspace --all-targets -- --deny warnings"
# AKA `test-update`, handy cargo rst update without install `cargo-rst` binary
tu = "run -p cargo-rst -- update"
xtask = "run --package xtask --"
tu = "run -p cargo-rst -- update"
[target.'cfg(all())']
rustflags = [
"-Dclippy::unwrap_in_result", # https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
Expand Down
12 changes: 10 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -1,25 +1,32 @@
# About code owners

# https://help.github.com/en/articles/about-code-owners

# Default to project owner
* @hardfist

- @hardfist

# Ignore lock files

Cargo.lock
pnpm-lock.yaml

# Infra

/benchcases @IWANABETHATGUY
/xtask @IWANABETHATGUY
/.github/workflows @IWANABETHATGUY @h-a-n-a
/scripts @Boshen @hyf0

# Examples

/examples @hardfist

# Webpack Tests

/webpack-test @IWANABETHATGUY

# Crates in alphabetical order

/crates/bench @IWANABETHATGUY
/crates/cargo-rst @JSerFeng
/crates/loader_runner @h-a-n-a
Expand Down Expand Up @@ -64,6 +71,7 @@ pnpm-lock.yaml
/crates/rspack_util @hyf0

# Packages in alphabetical order

/packages/create-rspack @hardfist
/packages/postcss-loader @ahabhgk
/packages/rspack @hardfist
Expand Down
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -2,7 +2,7 @@
exclude = [
"crates/node_binding",
] # Avoid including node binding, since feature unification will cause an linking issue. See: https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
members = ["crates/*", "xtask"]
members = ["crates/*"]

[profile.dev]
debug = 2
Expand Down
9 changes: 0 additions & 9 deletions benchcases/css-heavy/test.config.json

This file was deleted.

34 changes: 0 additions & 34 deletions benchcases/lodash-with-simple-css/test.config.json

This file was deleted.

17 changes: 11 additions & 6 deletions crates/rspack/benches/main.rs
Expand Up @@ -28,12 +28,14 @@ fn criterion_benchmark(c: &mut Criterion) {
let sh = Shell::new().expect("TODO:");
println!("{:?}", sh.current_dir());
sh.change_dir(PathBuf::from(env!("CARGO_WORKSPACE_DIR")));
cmd!(sh, "cargo xtask copy_three").run().expect("TODO:");
cmd!(sh, "node ./scripts/bench/make-threejs10x.js")
.run()
.expect("TODO:");
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("TODO:");
generate_bench!(ten_copy_of_threejs, "three", group, rt);
generate_bench!(ten_copy_of_threejs, "threejs10x", group, rt);
group.finish();

// High cost benchmark
Expand All @@ -43,14 +45,17 @@ fn criterion_benchmark(c: &mut Criterion) {
let sh = Shell::new().expect("TODO:");
println!("{:?}", sh.current_dir());
sh.change_dir(PathBuf::from(env!("CARGO_WORKSPACE_DIR")));
cmd!(sh, "cargo xtask three_production_config")
.run()
.expect("TODO:");
cmd!(
sh,
"node ./scripts/bench/make-threejs10x-production-config.js"
)
.run()
.expect("TODO:");
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("TODO:");
generate_bench!(ten_copy_of_threejs_production, "three", group, rt);
generate_bench!(ten_copy_of_threejs_production, "threejs10x", group, rt);
group.finish()
}

Expand Down
26 changes: 26 additions & 0 deletions scripts/bench/make-threejs10x-production-config.js
@@ -0,0 +1,26 @@
import "zx/globals";

await import("../meta/check_is_workspace_root.js");

const testConfig = `
{
"devtool": "source-map",
"builtins": {
"minifyOptions": {
"passes": 1,
"dropConsole": true,
"pureFuncs": []
}
},
"optimization": {
"moduleIds": "deterministic"
},
"entry": {
"index": {
"import": ["./src/entry.js"]
}
}
}
`;

fs.writeFile("./benchcases/threejs10x/test.config.json", testConfig);
48 changes: 48 additions & 0 deletions scripts/bench/make-threejs10x.js
@@ -0,0 +1,48 @@
import "zx/globals";

await import("../meta/check_is_workspace_root.js");

fs.ensureDir("./benchcases/threejs10x/src");

for (const i in Array(10).fill(null)) {
await $`cp -r ./benchcases/.three/src ./benchcases/threejs10x/src/copy${i}`;
}

const entryCode = Array(10)
.fill(null)
.map((_, i) => i)
.map(
i => `import * as copy${i} from './copy${i}/Three.js'\nexport { copy${i} }`
)
.join("\n");

fs.writeFile("./benchcases/threejs10x/src/entry.js", entryCode);

// Create test.config.json

const testConfig = `
{
"entry": {
"index": {
"import": ["./src/entry.js"]
}
}
}
`;

fs.writeFile("./benchcases/threejs10x/test.config.json", testConfig);

// Create webpack.config.js

const webpackConfig = `
module.exports = {
mode: 'development',
entry: {
index: ['./benchcases/three/src/entry.js']
},
devtool: 'eval',
cache: {type: 'filesystem'}
}
`;

fs.writeFile("./benchcases/threejs10x/webpack.config.js", webpackConfig);
25 changes: 25 additions & 0 deletions scripts/meta/check_is_workspace_root.js
@@ -0,0 +1,25 @@
import * as path from "path";

try {
// Make sure developers are at the workspace root
const { default: rootPkgJson } = await import(
path.join(process.cwd(), "package.json"),
{
assert: {
type: "json"
}
}
);
if (rootPkgJson.name != "monorepo") {
throw new Error(`Unexpected cwd ${process.cwd()}`);
}
} catch (oldErr) {
const err = new Error(
`Make sure you are in workspace root to run this script`
);
// @ts-expect-error
err.cause = oldErr;
throw err;
}

export {};
23 changes: 1 addition & 22 deletions scripts/meta/setup.js
@@ -1,6 +1,5 @@
// Setup everything before pnpm install
import { spawnSync } from "child_process";
import * as path from "path";

/**
*
Expand All @@ -13,27 +12,7 @@ function runInContext(context, 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"),
{
assert: {
type: "json"
}
}
);
if (rootPkgJson.name != "monorepo") {
throw new Error(`Unexpected cwd ${process.cwd()}`);
}
} catch (oldErr) {
const err = new Error(
`Make sure you are in workspace root to run this script`
);
// @ts-expect-error
err.cause = oldErr;
throw err;
}
await import("./check_is_workspace_root");

runInContext(
"corepack enable",
Expand Down
4 changes: 3 additions & 1 deletion scripts/package.json
Expand Up @@ -3,11 +3,13 @@
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {},
"keywords": [],
"author": "",
"license": "MIT",
"private": true,
"scripts": {
"typecheck": "pnpm tsc --noEmit"
},
"dependencies": {
"@changesets/read": "0.5.9",
"@iarna/toml": "2.2.5",
Expand Down
8 changes: 4 additions & 4 deletions scripts/tsconfig.json
Expand Up @@ -3,7 +3,7 @@
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
"incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
Expand Down Expand Up @@ -32,7 +32,7 @@
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
"types": [] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
Expand All @@ -55,7 +55,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
"noEmit": true /* Disable emitting files from a compilation. */,
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down Expand Up @@ -91,7 +91,7 @@
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
Expand Down
9 changes: 0 additions & 9 deletions xtask/Cargo.toml

This file was deleted.

0 comments on commit b4426ce

Please sign in to comment.