@rsbuild/core 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ let importer;
2
+ import { Module } from "node:module";
3
+ import { fileURLToPath } from "node:url";
4
+ import { MessageChannel } from "node:worker_threads";
5
+ let instanceId = Math.random().toString(36).slice(2), relativeImportRE = /^\.{1,2}(?:\/|\\)/;
6
+ function escapeRegExp(value) {
7
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8
+ }
9
+ function buildQueryName() {
10
+ return `fresh-import-${instanceId}`;
11
+ }
12
+ function buildQueryRE(queryName) {
13
+ return RegExp(`(?:\\?|&)${escapeRegExp(queryName)}=(\\d+),([^&]+)(?:&|$)`);
14
+ }
15
+ function formatTrackingQuery(queryName, id, context) {
16
+ return `?${queryName}=${id},${context}`;
17
+ }
18
+ function trackResolved(specifier, context, result, queryName, queryRE, onDependency) {
19
+ let isRelativeImport = relativeImportRE.test(specifier);
20
+ if ("builtin" === result.format || !isRelativeImport || !context.parentURL || queryRE.test(result.url) || !result.url.startsWith("file:")) return result;
21
+ let m = queryRE.exec(context.parentURL);
22
+ if (m) {
23
+ let [, id, contextFile] = m;
24
+ onDependency(contextFile, result.url), result.url = result.url.replace(/(\?)|$/, (_n, n1)=>`?${queryName}=${id},${contextFile}${"?" === n1 ? "&" : ""}`);
25
+ }
26
+ return result;
27
+ }
28
+ let nextId$1 = 0;
29
+ function createOffThreadImporter() {
30
+ let queryName = buildQueryName(), { port1, port2 } = new MessageChannel();
31
+ return Module.register('data:text/javascript,Math.random().toString(36).slice(2);%0Aconst relativeImportRE = /^\\.{1,2}(%3F:\\/|\\\\)/;%0Afunction escapeRegExp(value) {%0A%09return value.replace(/[.*+%3F^${}()|[\\]\\\\]/g, "\\\\$&");%0A}%0A/**%0A* Build the regex that matches the tracking query `%3F<name>=<id>,<context>`%0A* (or the `&<name>=...` form).%0A*/%0Afunction buildQueryRE(queryName) {%0A%09return new RegExp(`(%3F:\\\\%3F|&)${escapeRegExp(queryName)}=(\\\\d+),([^&]+)(%3F:&|$)`);%0A}%0A/**%0A* Shared body of the resolve hook for both the on-thread and off-thread%0A* importers. Given an already-resolved `result`, decides whether it is a tracked%0A* relative file dependency; if so, reports it via `onDependency` and tags the%0A* URL so the query propagates to its own dependencies.%0A*%0A* The sync/async difference between the two hooks lives entirely in the caller%0A* (which awaits `nextResolve` or not); this function performs no I/O. `result`%0A* is mutated in place and returned.%0A*/%0Afunction trackResolved(specifier, context, result, queryName, queryRE, onDependency) {%0A%09const isRelativeImport = relativeImportRE.test(specifier);%0A%09if (result.format === "builtin" || !isRelativeImport) return result;%0A%09if (!context.parentURL || queryRE.test(result.url) || !result.url.startsWith("file:")) return result;%0A%09const m = queryRE.exec(context.parentURL);%0A%09if (m) {%0A%09%09const [, id, contextFile] = m;%0A%09%09onDependency(contextFile, result.url);%0A%09%09result.url = result.url.replace(/(\\%3F)|$/, (_n, n1) => `%3F${queryName}=${id},${contextFile}${n1 === "%3F" %3F "&" : ""}`);%0A%09}%0A%09return result;%0A}%0A//%23endregion%0A//%23region src/off-thread/loader.ts%0Alet port;%0Alet queryName;%0Alet queryRE;%0Aconst initialize = async (data) => {%0A%09port = data.port;%0A%09queryName = data.queryName;%0A%09queryRE = buildQueryRE(queryName);%0A};%0Aconst resolve = async (specifier, context, nextResolve) => {%0A%09return trackResolved(specifier, context, await nextResolve(specifier, context), queryName, queryRE, (ctx, url) => {%0A%09%09port.postMessage({%0A%09%09%09context: ctx,%0A%09%09%09url%0A%09%09});%0A%09});%0A};%0A//%23endregion%0Aexport { initialize, resolve };%0A', {
32
+ data: {
33
+ port: port2,
34
+ queryName
35
+ },
36
+ transferList: [
37
+ port2
38
+ ]
39
+ }), port1.unref(), {
40
+ async collect (specifier) {
41
+ let id = nextId$1++, depsList = new Set(), onMessage = (e)=>{
42
+ e.context === specifier && depsList.add(e.url);
43
+ };
44
+ port1.on("message", onMessage), port1.unref();
45
+ try {
46
+ let result = await import(specifier + formatTrackingQuery(queryName, id, specifier));
47
+ return await new Promise((resolve)=>setImmediate(resolve)), {
48
+ result,
49
+ dependencies: [
50
+ ...depsList
51
+ ].filter((url)=>url.startsWith("file:")).map((url)=>fileURLToPath(url))
52
+ };
53
+ } finally{
54
+ port1.off("message", onMessage);
55
+ }
56
+ }
57
+ };
58
+ }
59
+ let nextId = 0;
60
+ function createOnThreadImporter() {
61
+ let registry = new Map(), queryName = buildQueryName(), queryRE = buildQueryRE(queryName);
62
+ return Module.registerHooks({
63
+ resolve: (specifier, context, nextResolve)=>trackResolved(specifier, context, nextResolve(specifier, context), queryName, queryRE, (ctx, url)=>{
64
+ registry.get(ctx)?.add(url);
65
+ })
66
+ }), {
67
+ async collect (specifier) {
68
+ let id = nextId++, depsList = new Set();
69
+ registry.set(specifier, depsList);
70
+ try {
71
+ return {
72
+ result: await import(specifier + formatTrackingQuery(queryName, id, specifier)),
73
+ dependencies: [
74
+ ...depsList
75
+ ].filter((url)=>url.startsWith("file:")).map((url)=>fileURLToPath(url))
76
+ };
77
+ } finally{
78
+ registry.delete(specifier);
79
+ }
80
+ }
81
+ };
82
+ }
83
+ function createImporter() {
84
+ return Module.registerHooks ? createOnThreadImporter() : Module.register ? createOffThreadImporter() : void 0;
85
+ }
86
+ let initialized = !1;
87
+ function freshImport(specifier) {
88
+ return initialized || (importer = createImporter(), initialized = !0), importer?.collect(specifier);
89
+ }
90
+ export { freshImport };
@@ -1,7 +1,7 @@
1
1
  import { __webpack_require__ } from "./1~rslib-runtime.js";
2
2
  import "./756.js";
3
3
  __webpack_require__.add({
4
- "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/helpers.js" (__unused_rspack_module, exports, __webpack_require__) {
4
+ "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/helpers.js" (__unused_rspack_module, exports, __webpack_require__) {
5
5
  exports.transformFiles = exports.reduceChunk = exports.reduceAssets = exports.generateManifest = void 0;
6
6
  let node_path_1 = __webpack_require__("node:path?435f");
7
7
  exports.generateManifest = (compilation, files, { generate, seed = {} })=>generate ? generate(seed, files, Array.from(compilation.entrypoints.entries()).reduce((e, [name, entrypoint])=>Object.assign(e, {
@@ -61,9 +61,9 @@ __webpack_require__.add({
61
61
  'sort'
62
62
  ].filter((fname)=>!!options[fname]).reduce((prev, fname)=>prev[fname](options[fname]), files).map(standardizeFilePaths);
63
63
  },
64
- "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/hooks.js" (__unused_rspack_module, exports, __webpack_require__) {
64
+ "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/hooks.js" (__unused_rspack_module, exports, __webpack_require__) {
65
65
  exports.getCompilerHooks = exports.emitHook = exports.beforeRunHook = void 0;
66
- let node_fs_1 = __webpack_require__("node:fs?9592"), node_path_1 = __webpack_require__("node:path?435f"), lite_tapable_1 = __webpack_require__("../../node_modules/.pnpm/@rspack+lite-tapable@1.1.0/node_modules/@rspack/lite-tapable/dist/index.cjs"), helpers_1 = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/helpers.js"), compilerHookMap = new WeakMap(), getCompilerHooks = (compiler)=>{
66
+ let node_fs_1 = __webpack_require__("node:fs?9592"), node_path_1 = __webpack_require__("node:path?435f"), lite_tapable_1 = __webpack_require__("../../node_modules/.pnpm/@rspack+lite-tapable@1.1.0/node_modules/@rspack/lite-tapable/dist/index.cjs"), helpers_1 = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/helpers.js"), compilerHookMap = new WeakMap(), getCompilerHooks = (compiler)=>{
67
67
  let hooks = compilerHookMap.get(compiler);
68
68
  return void 0 === hooks && (hooks = {
69
69
  afterEmit: new lite_tapable_1.SyncWaterfallHook([
@@ -112,9 +112,9 @@ __webpack_require__.add({
112
112
  getCompilerHooks(compiler).afterEmit.call(manifest);
113
113
  };
114
114
  },
115
- "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/index.js" (__unused_rspack_module, exports, __webpack_require__) {
115
+ "../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/index.js" (__unused_rspack_module, exports, __webpack_require__) {
116
116
  exports.RspackManifestPlugin = void 0;
117
- let node_path_1 = __webpack_require__("node:path?435f"), hooks_1 = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/hooks.js"), emitCountMap = new Map(), defaults = {
117
+ let node_path_1 = __webpack_require__("node:path?435f"), hooks_1 = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/hooks.js"), emitCountMap = new Map(), defaults = {
118
118
  assetHookStage: 1 / 0,
119
119
  basePath: '',
120
120
  fileName: 'manifest.json',
@@ -684,5 +684,5 @@ __webpack_require__.add({
684
684
  });
685
685
  }
686
686
  });
687
- var RspackManifestPlugin = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.1/node_modules/rspack-manifest-plugin/dist/index.js").RspackManifestPlugin;
687
+ var RspackManifestPlugin = __webpack_require__("../../node_modules/.pnpm/rspack-manifest-plugin@5.2.2_@rspack+core@2.1.2/node_modules/rspack-manifest-plugin/dist/index.js").RspackManifestPlugin;
688
688
  export { RspackManifestPlugin };
@@ -2,6 +2,8 @@ import type { ConfigLoader } from '../loadConfig';
2
2
  import type { LogLevel, RsbuildMode } from '../types';
3
3
  export type CommonOptions = {
4
4
  base?: string;
5
+ distPath?: string;
6
+ sourceMap?: boolean;
5
7
  root?: string;
6
8
  mode?: RsbuildMode;
7
9
  config?: string;
@@ -12,6 +14,7 @@ export type CommonOptions = {
12
14
  open?: boolean | string;
13
15
  host?: true | string;
14
16
  port?: number;
17
+ strictPort?: boolean;
15
18
  environment?: string[];
16
19
  logLevel?: LogLevel;
17
20
  };
@@ -25,4 +28,4 @@ export type InspectOptions = CommonOptions & {
25
28
  };
26
29
  export type DevOptions = CommonOptions;
27
30
  export type PreviewOptions = CommonOptions;
28
- export declare function setupCommands(): void;
31
+ export declare function setupCommands(argv: string[]): void;
@@ -1 +1,7 @@
1
- export declare function runCLI(): void;
1
+ export type RunCLIOptions = {
2
+ /**
3
+ * The command-line arguments to parse, matching the shape of Node.js `process.argv`
4
+ * @default process.argv
5
+ */ argv?: string[];
6
+ };
7
+ export declare function runCLI({ argv }?: RunCLIOptions): void;
@@ -1,7 +1,8 @@
1
1
  import type { RsbuildInstance } from '../types';
2
2
  import type { CommonOptions } from './commands';
3
- export declare function init({ cliOptions, isRestart, isBuildWatch }: {
4
- cliOptions?: CommonOptions;
3
+ export type CommandName = 'dev' | 'build' | 'preview' | 'inspect';
4
+ export declare const initCliAction: (command: CommandName, options: CommonOptions) => void;
5
+ export declare function init({ isRestart, isBuildWatch }?: {
5
6
  isRestart?: boolean;
6
7
  isBuildWatch?: boolean;
7
8
  }): Promise<RsbuildInstance | undefined>;
@@ -24,12 +24,15 @@ export declare const CHAIN_ID: {
24
24
  /** JS oneOf rules */ readonly JS_MAIN: 'js';
25
25
  readonly JS_WORKER: 'js-worker';
26
26
  readonly JS_RAW: 'js-raw';
27
+ readonly JS_TEXT: 'js-text';
27
28
  /** CSS oneOf rules */ readonly CSS_MAIN: 'css';
28
29
  readonly CSS_RAW: 'css-raw';
30
+ readonly CSS_TEXT: 'css-text';
29
31
  readonly CSS_URL: 'css-url';
30
32
  readonly CSS_INLINE: 'css-inline';
31
33
  /** SVG oneOf rules */ readonly SVG: 'svg';
32
34
  readonly SVG_RAW: 'svg-asset-raw';
35
+ readonly SVG_TEXT: 'svg-asset-text';
33
36
  readonly SVG_URL: 'svg-asset-url';
34
37
  readonly SVG_ASSET: 'svg-asset';
35
38
  readonly SVG_REACT: 'svg-react';
@@ -3,9 +3,9 @@
3
3
  * the public API of @rsbuild/core.
4
4
  */ import type * as Rspack from '@rspack/core';
5
5
  import { rspack } from '@rspack/core';
6
- export { runCLI } from './cli';
6
+ export { type RunCLIOptions, runCLI } from './cli';
7
7
  export { createRsbuild } from './createRsbuild';
8
- export { type ConfigParams, defineConfig, type LoadConfigOptions, type LoadConfigResult, loadConfig } from './loadConfig';
8
+ export { type ConfigParams, defineConfig, type LoadConfigOptions, type LoadConfigResult, type RsbuildConfigAsyncFn, type RsbuildConfigDefinition, type RsbuildConfigSyncFn, loadConfig } from './loadConfig';
9
9
  // Core methods
10
10
  export { type LoadEnvOptions, type LoadEnvResult, loadEnv } from './loadEnv';
11
11
  // Rsbuild version
@@ -7,7 +7,7 @@ export type ConfigParams = {
7
7
  };
8
8
  export type RsbuildConfigAsyncFn = (env: ConfigParams) => Promise<RsbuildConfig>;
9
9
  export type RsbuildConfigSyncFn = (env: ConfigParams) => RsbuildConfig;
10
- export type RsbuildConfigExport = RsbuildConfig | RsbuildConfigSyncFn | RsbuildConfigAsyncFn;
10
+ export type RsbuildConfigDefinition = RsbuildConfig | RsbuildConfigSyncFn | RsbuildConfigAsyncFn;
11
11
  export type LoadConfigOptions = {
12
12
  /**
13
13
  * The root path to resolve the config file.
@@ -18,6 +18,10 @@ export type LoadConfigOptions = {
18
18
  * If `path` is not provided, the function will search for the config file in the `cwd`.
19
19
  */ path?: string;
20
20
  /**
21
+ * Config file names to search in `cwd` when `path` is not provided.
22
+ * The list replaces the default `rsbuild.config.*` lookup order.
23
+ */ configFileNames?: string[];
24
+ /**
21
25
  * A custom meta object to be passed into the config function of `defineConfig`.
22
26
  */ meta?: Record<string, unknown>;
23
27
  /**
@@ -31,6 +35,10 @@ export type LoadConfigOptions = {
31
35
  * - 'native': Use native Node.js loader, requires TypeScript support in Node.js >= 22.6
32
36
  * @default 'auto'
33
37
  */ loader?: ConfigLoader;
38
+ /**
39
+ * The command passed to the config function.
40
+ * @default process.argv[2]
41
+ */ command?: string;
34
42
  };
35
43
  export type LoadConfigResult = {
36
44
  /**
@@ -40,6 +48,10 @@ export type LoadConfigResult = {
40
48
  * The path to the loaded configuration file.
41
49
  * Return `null` if the configuration file is not found.
42
50
  */ filePath: string | null;
51
+ /**
52
+ * Absolute file paths of statically imported (relative) dependencies of the
53
+ * config file.
54
+ */ dependencies: string[];
43
55
  };
44
56
  /**
45
57
  * This function helps you to autocomplete configuration types.
@@ -47,6 +59,6 @@ export type LoadConfigResult = {
47
59
  */ export declare function defineConfig(config: RsbuildConfig): RsbuildConfig;
48
60
  export declare function defineConfig(config: RsbuildConfigSyncFn): RsbuildConfigSyncFn;
49
61
  export declare function defineConfig(config: RsbuildConfigAsyncFn): RsbuildConfigAsyncFn;
50
- export declare function defineConfig(config: RsbuildConfigExport): RsbuildConfigExport;
62
+ export declare function defineConfig(config: RsbuildConfigDefinition): RsbuildConfigDefinition;
51
63
  export type ConfigLoader = 'auto' | 'jiti' | 'native';
52
- export declare function loadConfig({ cwd, path, envMode, meta, loader }?: LoadConfigOptions): Promise<LoadConfigResult>;
64
+ export declare function loadConfig({ cwd, path, configFileNames, envMode, meta, loader, command }?: LoadConfigOptions): Promise<LoadConfigResult>;
@@ -3,5 +3,5 @@
3
3
  * license at https://github.com/facebook/create-react-app/blob/master/LICENSE
4
4
  */ import type { InternalContext, PrintFileSizeAsset, RsbuildPlugin } from '../types';
5
5
  /** Normalize file path by removing hash for comparison across builds */ export declare function normalizeFilePath(filePath: string): string;
6
- /** Exclude source map and license files by default */ export declare const excludeAsset: (asset: PrintFileSizeAsset) => boolean;
6
+ /** Exclude source map, license, and type declaration files by default */ export declare const excludeAsset: (asset: PrintFileSizeAsset) => boolean;
7
7
  export declare const pluginFileSize: (context: InternalContext) => RsbuildPlugin;
@@ -516,7 +516,7 @@ export type PrintFileSizeOptions = {
516
516
  /**
517
517
  * A filter function to exclude static assets from the total size or detailed size.
518
518
  * If both `include` and `exclude` are set, `exclude` will take precedence.
519
- * @default (asset) => /\.(?:map|LICENSE\.txt)$/.test(asset.name)
519
+ * @default (asset) => /\.(?:map|LICENSE\.txt|d\.(?:ts|mts|cts))$/.test(asset.name)
520
520
  */ exclude?: (asset: PrintFileSizeAsset) => boolean;
521
521
  /**
522
522
  * Controls whether file size differences are displayed relative to the previous build.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.rs",
6
6
  "bugs": {
@@ -40,13 +40,13 @@
40
40
  "registry": "https://registry.npmjs.org/"
41
41
  },
42
42
  "dependencies": {
43
- "@rspack/core": "~2.1.1",
43
+ "@rspack/core": "~2.1.2",
44
44
  "@swc/helpers": "^0.5.23"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@jridgewell/remapping": "^2.3.5",
48
48
  "@jridgewell/trace-mapping": "^0.3.31",
49
- "@rslib/core": "0.23.0",
49
+ "@rslib/core": "0.23.1",
50
50
  "@types/cors": "^2.8.19",
51
51
  "@types/node": "^24.13.2",
52
52
  "@types/on-finished": "2.3.5",
@@ -61,6 +61,7 @@
61
61
  "css-loader": "7.1.4",
62
62
  "deepmerge": "^4.3.1",
63
63
  "dotenv-expand": "^13.0.0",
64
+ "fresh-import": "^0.2.1",
64
65
  "html-rspack-plugin": "6.1.9",
65
66
  "http-proxy-middleware": "4.1.1",
66
67
  "jiti": "^2.7.0",
File without changes
File without changes