Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 5 additions & 61 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# Temp files
.cache
.temp

# TypeScript cache
*.tsbuildinfo

Expand All @@ -77,15 +81,6 @@ web_modules/
# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -102,50 +97,14 @@ web_modules/
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt

# Dist files
dist
compiled
webpack-dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

Expand All @@ -163,7 +122,6 @@ webpack-dist
# os
.DS_Store


# Do not ignore this for binding test
# crates/node_binding/binding.d.ts

Expand All @@ -174,20 +132,12 @@ tests/e2e/temp
packages/*/tests/js
tests/rspack-test/js


# Benchmark
/github/

# profile
profile.json

# esbuild trace
esbuild.trace

# esbuild cpuprofile
esbuild.cpuprofile


# this node_modules is used for tree-shaking snapshot
!tests/rspack-test/treeShakingCases/node_modules

Expand All @@ -210,12 +160,6 @@ npm/**/*.node
!npm/win32-ia32-msvc
!npm/win32-x64-msvc/

# Precompiled config schema
packages/rspack/src/config/schema.check.js

## Angular Incremental Build Cache
**/.angular/

smoke-example
diff_output

Expand All @@ -235,7 +179,7 @@ diff_output
trace.json
*.pftrace

# Rsapck bench
# Rspack bench
.bench

# Claude
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl From<&str> for HashFunction {
"xxhash64" => HashFunction::Xxhash64,
"md4" => HashFunction::MD4,
"sha256" => HashFunction::SHA256,
_ => unimplemented!("{}", value),
_ => panic!(
"Unsupported hash function: '{}'. Expected one of: xxhash64, md4, sha256",
value
),
}
}
}
Expand All @@ -35,7 +38,7 @@ impl From<&str> for HashDigest {
fn from(value: &str) -> Self {
match value {
"hex" => HashDigest::Hex,
_ => unimplemented!(),
_ => panic!("Unsupported hash digest: '{}'. Expected: hex", value),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/rspack-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export class RspackCLI {
rspackCommand: Command,
callback?: (e: Error | null, res?: Stats | MultiStats) => void
) {
process.env.RSPACK_CONFIG_VALIDATE ??= "loose";

let { config, pathMap } = await this.loadConfig(options);
config = await this.buildConfig(config, pathMap, options, rspackCommand);

Expand Down
4 changes: 1 addition & 3 deletions packages/rspack-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ async function runBuild(cli: RspackCLI, options: BuildOptions): Promise<void> {
item.options ? item.options.stats : undefined
)
}
: compiler.options
? compiler.options.stats
: undefined;
: compiler.options?.stats;

if (options.json && createJsonStringifyStream) {
const handleWriteError = (error: Error) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6294,6 +6294,7 @@ declare namespace rspackExports {
NormalModuleFactory,
RspackError,
RspackSeverity,
ValidationError,
RuntimeGlobals,
RuntimeModule,
StatsAsset,
Expand All @@ -6309,7 +6310,6 @@ declare namespace rspackExports {
Watching,
sources,
config,
ValidationError,
util,
BannerPluginArgument,
DefinePluginOptions,
Expand Down
12 changes: 8 additions & 4 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"api-extractor": "api-extractor run --verbose",
"api-extractor:ci": "api-extractor run --verbose || diff temp/core.api.md etc/core.api.md"
},
"files": ["dist", "hot", "compiled", "module.d.ts"],
"files": [
"dist",
"hot",
"compiled",
"module.d.ts"
],
"engines": {
"node": ">=18.12.0"
},
Expand All @@ -45,6 +50,7 @@
"@rsbuild/plugin-node-polyfill": "^1.4.2",
"@rslib/core": "0.15.1",
"@swc/types": "0.1.25",
"@types/node": "^20.19.21",
"@types/watchpack": "^2.4.4",
"browserslist-load-config": "^1.0.1",
"enhanced-resolve": "5.18.3",
Expand All @@ -55,9 +61,7 @@
"tsx": "^4.20.6",
"typescript": "^5.9.3",
"watchpack": "^2.4.4",
"webpack-sources": "3.3.3",
"zod": "^4.1.12",
"zod-validation-error": "^4.0.2"
"webpack-sources": "3.3.3"
},
"dependencies": {
"@module-federation/runtime-tools": "0.20.0",
Expand Down
41 changes: 1 addition & 40 deletions packages/rspack/rslib.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -63,45 +63,6 @@ const commonLibConfig: LibConfig = {
}
};

/**
* The `zod` dependency is bundled by Rslib. Since Rspack's public APIs
* do not depend on `zod` types, we add `@ts-ignore` to prevent type errors
* when users set `skipLibCheck: false` in their tsconfig.json file.
*/
const fixZodTypePlugin: rsbuild.RsbuildPlugin = {
name: "fix-zod-type",
setup(api) {
api.onAfterBuild(async () => {
const schemaDir = path.join(api.context.distPath, "schema");

if (!fs.existsSync(schemaDir)) {
throw new Error(`Schema directory not found: ${schemaDir}`);
}

const files = await fs.promises.readdir(schemaDir);
const dtsFiles = files.filter(file => file.endsWith(".d.ts"));

for (const file of dtsFiles) {
const filePath = path.join(schemaDir, file);
const content = await fs.promises.readFile(filePath, "utf-8");
const newContent = content
.replace(
`import * as z from "zod";`,
`// @ts-ignore\nimport * as z from "zod";`
)
.replace(
`import type { z } from "zod";`,
`// @ts-ignore\nimport type { z } from "zod";`
);

if (content !== newContent) {
await fs.promises.writeFile(filePath, newContent);
}
}
});
}
};

const mfRuntimePlugin: rsbuild.RsbuildPlugin = {
name: "mf-runtime",
setup(api) {
Expand Down Expand Up @@ -169,7 +130,7 @@ const codmodPlugin: rsbuild.RsbuildPlugin = {
};

export default defineConfig({
plugins: [fixZodTypePlugin, mfRuntimePlugin, codmodPlugin],
plugins: [mfRuntimePlugin, codmodPlugin],
lib: [
merge(commonLibConfig, {
dts: {
Expand Down
34 changes: 1 addition & 33 deletions packages/rspack/scripts/check-documentation-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { basename, dirname, extname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { ApiItemKind, ApiModel } from "@microsoft/api-extractor-model";

// import { ZodObject, ZodOptional, ZodUnion } from "zod";
// import { rspackOptions } from "../src/config/zod.ts";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down Expand Up @@ -157,7 +154,7 @@ type Section = {
/**
* The process of checking the documentation coverage of Rspack configuration
*
* 1. Retrieve and traverse all implemented Rspack configurations through zod declaration.
* 1. Retrieve and traverse all implemented Rspack configurations.
* 2. Traverse the configurations and determine whether they match the any level titles of the Markdown files under the config directory of the document site:
* 1. If so, pass.
* 2. If not, judge whether the introduction of the configuration exists in the body of the parent configuration:
Expand All @@ -167,35 +164,6 @@ type Section = {
function checkConfigsDocumentationCoverage() {
const CONFIG_DOCS_DIR = resolve(__dirname, "../../../website/docs/en/config");

// function getImplementedConfigs() {
// const implementedConfigs: string[] = [];
// function visit(zod, path = "") {
// if (zod instanceof ZodObject) {
// for (const [key, schema] of Object.entries(zod.shape)) {
// const next = (() => {
// if (key.includes("/")) {
// return `${path}["${key}"]`;
// }
// if (path) {
// return `${path}.${key}`;
// }
// return key;
// })();
// implementedConfigs.push(next);
// visit(schema, next);
// }
// } else if (zod instanceof ZodOptional) {
// visit(zod.unwrap(), path);
// } else if (zod instanceof ZodUnion) {
// for (const schema of zod.options) {
// visit(schema, path);
// }
// }
// }
// visit(rspackOptions);
// return implementedConfigs;
// }

function parseConfigDocuments() {
function parseMarkdownContent(content) {
const sections: Section[] = [];
Expand Down
44 changes: 30 additions & 14 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,12 @@ class Compiler {
return callback(null, this.#instance);
}

const options = this.options;
const { options } = this;
const rawOptions = getRawOptions(options, this);
rawOptions.__references = Object.fromEntries(
this.#ruleSet.builtinReferences.entries()
);

rawOptions.__virtual_files =
VirtualModulesPlugin.__internal__take_virtual_files(this);

Expand All @@ -867,20 +868,35 @@ class Compiler {
? ThreadsafeInputNodeFS.__to_binding(this.inputFileSystem)
: undefined;

this.#instance = new instanceBinding.JsCompiler(
this.compilerPath,
rawOptions,
this.#builtinPlugins,
this.#registers,
ThreadsafeOutputNodeFS.__to_binding(this.outputFileSystem!),
this.intermediateFileSystem
? ThreadsafeIntermediateNodeFS.__to_binding(this.intermediateFileSystem)
: undefined,
inputFileSystem,
ResolverFactory.__to_binding(this.resolverFactory)
);
try {
this.#instance = new instanceBinding.JsCompiler(
this.compilerPath,
rawOptions,
this.#builtinPlugins,
this.#registers,
ThreadsafeOutputNodeFS.__to_binding(this.outputFileSystem!),
this.intermediateFileSystem
? ThreadsafeIntermediateNodeFS.__to_binding(
this.intermediateFileSystem
)
: undefined,
inputFileSystem,
ResolverFactory.__to_binding(this.resolverFactory)
);

callback(null, this.#instance);
callback(null, this.#instance);
} catch (err) {
if (err instanceof Error) {
// hide unnecessary stack trace
delete err.stack;
}
callback(
new Error(
"Failed to create Rspack compiler instance, check the Rspack configuration.",
{ cause: err }
)
);
}
}

#createHooksRegisters(): binding.RegisterJsTaps {
Expand Down
Loading
Loading