@rspack/core 2.1.0-rc.0 → 2.1.1

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.
package/dist/Module.d.ts CHANGED
@@ -5,7 +5,6 @@ import './BuildInfo.js';
5
5
  export type ResourceDataWithData = ResourceData & {
6
6
  data?: Record<string, any>;
7
7
  };
8
- export type CreateData = binding.JsCreateData;
9
8
  export type ContextInfo = binding.ContextInfo;
10
9
  export type ResolveData = binding.JsResolveData;
11
10
  export declare class ContextModuleFactoryBeforeResolveData {
@@ -1,9 +1,28 @@
1
+ import { EventEmitter } from 'node:events';
1
2
  import binding from '@rspack/binding';
2
3
  import type Watchpack from '../compiled/watchpack/index.js';
3
4
  import type { FileSystemInfoEntry, InputFileSystem, Watcher, WatchFileSystem } from './util/fs.js';
5
+ /**
6
+ * Minimal watchpack-compatible shim exposed as `NativeWatchFileSystem.watcher`.
7
+ *
8
+ * It proxies the watchpack-private surface that `ts-checker-rspack-plugin` and
9
+ * `fork-ts-checker-webpack-plugin` rely on — `on`/`once` for `change`/`remove`,
10
+ * plus `_onChange`/`_onRemove` to inject events — onto the native watcher, so
11
+ * those plugins keep working under `experiments.nativeWatcher` unmodified.
12
+ *
13
+ * APIs that iterate `fileWatchers`/`directoryWatchers` are intentionally not
14
+ * supported; plugins needing those should use `WatchFileSystem.emit` instead.
15
+ */
16
+ declare class NativeWatcherShim extends EventEmitter {
17
+ #private;
18
+ constructor(trigger: (kind: 'change' | 'remove', path: string) => void);
19
+ _onChange(item: string, _mtime?: number, file?: string, _type?: string): void;
20
+ _onRemove(item: string, file?: string, _type?: string): void;
21
+ }
4
22
  export default class NativeWatchFileSystem implements WatchFileSystem {
5
23
  #private;
6
24
  constructor(inputFileSystem: InputFileSystem);
25
+ get watcher(): NativeWatcherShim | undefined;
7
26
  watch(files: Iterable<string> & {
8
27
  added?: Iterable<string>;
9
28
  removed?: Iterable<string>;
@@ -16,8 +35,18 @@ export default class NativeWatchFileSystem implements WatchFileSystem {
16
35
  }, startTime: number, options: Watchpack.WatchOptions, callback: (error: Error | null, fileTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, contextTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, changedFiles: Set<string>, removedFiles: Set<string>) => void, callbackUndelayed: (fileName: string, changeTime: number) => void): Watcher;
17
36
  getNativeWatcher(options: Watchpack.WatchOptions): binding.NativeWatcher;
18
37
  triggerEvent(kind: 'change' | 'remove' | 'create', path: string): void;
38
+ on(event: 'change', listener: (filename: string, mtime: number) => void): this;
39
+ on(event: 'remove', listener: (filename: string) => void): this;
40
+ on(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
41
+ once(event: 'change', listener: (filename: string, mtime: number) => void): this;
42
+ once(event: 'remove', listener: (filename: string) => void): this;
43
+ once(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
44
+ emit(event: 'change', filename: string, mtime: number): boolean;
45
+ emit(event: 'remove', filename: string): boolean;
46
+ emit(event: 'aggregated', changes: Set<string>, removals: Set<string>): boolean;
19
47
  formatWatchDependencies(dependencies: Iterable<string> & {
20
48
  added?: Iterable<string>;
21
49
  removed?: Iterable<string>;
22
50
  }): [string[], string[]];
23
51
  }
52
+ export {};
@@ -345,7 +345,6 @@ declare enum RuntimeGlobals {
345
345
  makeDeferredNamespaceObjectSymbol = 76
346
346
  }
347
347
  export declare const isReservedRuntimeGlobal: (r: string, compilerRuntimeGlobals: Record<string, string>) => boolean;
348
- export declare function renderModulePrefix(_compilerOptions: RspackOptionsNormalized): string;
349
348
  export declare enum RuntimeVariable {
350
349
  Require = 0,
351
350
  Context = 1,
@@ -1,4 +1,4 @@
1
- import type { Config, EnvConfig, EsParserConfig, JscConfig, ModuleConfig, ParserConfig, TerserEcmaVersion, TransformConfig, TsParserConfig } from '../../../compiled/@swc/types/index.js';
1
+ import type { Config, EnvConfig, EsParserConfig, JscConfig, ModuleConfig, ParserConfig, TransformConfig, TsParserConfig } from '../../../compiled/@swc/types/index.js';
2
2
  import type { CollectTypeScriptInfoOptions } from './collectTypeScriptInfo.js';
3
3
  import type { PluginImportOptions } from './pluginImport.js';
4
4
  export type SwcLoaderEnvConfig = EnvConfig;
@@ -57,62 +57,4 @@ export interface ReactServerComponentsOptions {
57
57
  */
58
58
  disableClientApiChecks?: boolean;
59
59
  }
60
- export interface TerserCompressOptions {
61
- arguments?: boolean;
62
- arrows?: boolean;
63
- booleans?: boolean;
64
- booleans_as_integers?: boolean;
65
- collapse_vars?: boolean;
66
- comparisons?: boolean;
67
- computed_props?: boolean;
68
- conditionals?: boolean;
69
- dead_code?: boolean;
70
- defaults?: boolean;
71
- directives?: boolean;
72
- drop_console?: boolean;
73
- drop_debugger?: boolean;
74
- ecma?: TerserEcmaVersion;
75
- evaluate?: boolean;
76
- expression?: boolean;
77
- global_defs?: any;
78
- hoist_funs?: boolean;
79
- hoist_props?: boolean;
80
- hoist_vars?: boolean;
81
- ie8?: boolean;
82
- if_return?: boolean;
83
- inline?: 0 | 1 | 2 | 3;
84
- join_vars?: boolean;
85
- keep_classnames?: boolean;
86
- keep_fargs?: boolean;
87
- keep_fnames?: boolean;
88
- keep_infinity?: boolean;
89
- loops?: boolean;
90
- negate_iife?: boolean;
91
- passes?: number;
92
- properties?: boolean;
93
- pure_getters?: any;
94
- pure_funcs?: string[];
95
- reduce_funcs?: boolean;
96
- reduce_vars?: boolean;
97
- sequences?: any;
98
- side_effects?: boolean;
99
- switches?: boolean;
100
- top_retain?: any;
101
- toplevel?: any;
102
- typeofs?: boolean;
103
- unsafe?: boolean;
104
- unsafe_passes?: boolean;
105
- unsafe_arrows?: boolean;
106
- unsafe_comps?: boolean;
107
- unsafe_function?: boolean;
108
- unsafe_math?: boolean;
109
- unsafe_symbols?: boolean;
110
- unsafe_methods?: boolean;
111
- unsafe_proto?: boolean;
112
- unsafe_regexp?: boolean;
113
- unsafe_undefined?: boolean;
114
- unused?: boolean;
115
- const_to_let?: boolean;
116
- module?: boolean;
117
- }
118
60
  export {};
@@ -182,7 +182,7 @@ export interface TerserCompressOptions {
182
182
  unsafe_passes?: boolean;
183
183
  unsafe_arrows?: boolean;
184
184
  unsafe_comps?: boolean;
185
- unsafe_function?: boolean;
185
+ unsafe_Function?: boolean;
186
186
  unsafe_math?: boolean;
187
187
  unsafe_symbols?: boolean;
188
188
  unsafe_methods?: boolean;
@@ -40,7 +40,7 @@ export type HtmlRspackPluginOptions = {
40
40
  * Modern browsers support non-blocking JavaScript loading ([`defer` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#defer)) to improve the page startup performance.
41
41
  *
42
42
  * Setting this option to `'module'` adds attribute `type="module"` to the `script`. This also implies `defer` attribute on the `script`, since modules are automatically deferred.
43
- * @default "defer"
43
+ * @default "module" when `output.module` is enabled, otherwise "defer"
44
44
  * */
45
45
  scriptLoading?: 'blocking' | 'defer' | 'module' | 'systemjs-module';
46
46
  /** Allows you to add only some chunks. */
@@ -83,6 +83,8 @@ export type CacheNormalized = false | {
83
83
  type: 'persistent';
84
84
  buildDependencies: string[];
85
85
  version?: string;
86
+ maxAge?: number;
87
+ maxVersions?: number;
86
88
  snapshot: {
87
89
  immutablePaths?: (string | RegExp)[];
88
90
  unmanagedPaths?: (string | RegExp)[];
@@ -91,8 +93,6 @@ export type CacheNormalized = false | {
91
93
  storage: {
92
94
  type: 'filesystem';
93
95
  directory?: string;
94
- maxAge?: number;
95
- maxGenerations?: number;
96
96
  };
97
97
  portable?: boolean;
98
98
  readonly?: boolean;
@@ -1378,19 +1378,6 @@ export type CacheStorageOptions = {
1378
1378
  * @default 'node_modules/.cache/rspack/<name>-<mode>-<compilerIndex>'
1379
1379
  */
1380
1380
  directory?: string;
1381
- /**
1382
- * Maximum age of unused filesystem cache in seconds. Must be an integer
1383
- * between 1 and 4294967295, or Infinity to disable age-based cleanup.
1384
- * @default 7 * 24 * 60 * 60
1385
- */
1386
- maxAge?: number;
1387
- /**
1388
- * Maximum number of filesystem cache generations to retain in the cache
1389
- * directory. Must be an integer between 1 and 4294967295, or Infinity to
1390
- * disable generation-based cleanup.
1391
- * @default 3
1392
- */
1393
- maxGenerations?: number;
1394
1381
  };
1395
1382
  /**
1396
1383
  * Persistent cache options.
@@ -1410,6 +1397,19 @@ export type PersistentCacheOptions = {
1410
1397
  * @default ""
1411
1398
  */
1412
1399
  version?: string;
1400
+ /**
1401
+ * Maximum age of unused filesystem cache in seconds. Must be an integer
1402
+ * between 1 and 4294967295, or Infinity to disable age-based cleanup.
1403
+ * @default 7 * 24 * 60 * 60
1404
+ */
1405
+ maxAge?: number;
1406
+ /**
1407
+ * Maximum number of filesystem cache versions to retain in the cache
1408
+ * directory. Must be an integer between 1 and 4294967295, or Infinity to
1409
+ * disable version-based cleanup.
1410
+ * @default 3
1411
+ */
1412
+ maxVersions?: number;
1413
1413
  /**
1414
1414
  * Snapshot options for determining which files have been modified.
1415
1415
  */
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@ import { createRequire, createRequire as __rspack_createRequire } from "node:mod
4
4
  import node_path, { isAbsolute, join, relative, resolve as external_node_path_resolve, sep } from "node:path";
5
5
  import node_fs, { readFileSync } from "node:fs";
6
6
  import node_querystring from "node:querystring";
7
- import { __webpack_require__ } from "./612.js";
7
+ import { EventEmitter } from "node:events";
8
+ import { __webpack_require__ } from "./rslib-runtime-index.js";
8
9
  let __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
9
10
  import * as __rspack_external_node_util_1b29d436 from "node:util";
10
11
  __webpack_require__.add({
@@ -1218,7 +1219,7 @@ let concatComparatorsCache = new TwoKeyWeakMap(), concatComparators = (...comps)
1218
1219
  return null != aValue ? null != bValue ? comparator(aValue, bValue) : -1 : +(null != bValue);
1219
1220
  };
1220
1221
  return compareSelectCache.set(getter, comparator, result), result;
1221
- }, compareNumbers = (a, b)=>typeof a != typeof b ? typeof a < typeof b ? -1 : 1 : a < b ? -1 : +(a > b);
1222
+ };
1222
1223
  class StatsFactory {
1223
1224
  hooks;
1224
1225
  _caches;
@@ -2845,7 +2846,7 @@ let toBuffer = (bufLike)=>{
2845
2846
  throw Error('Buffer, Uint8Array or string expected');
2846
2847
  };
2847
2848
  function serializeObject(map) {
2848
- if (!isNil(map)) return 'string' == typeof map ? map ? toBuffer(map) : void 0 : toBuffer(JSON.stringify(map));
2849
+ if (!isNil(map)) return 'string' == typeof map ? map ? Buffer.from(map) : void 0 : Buffer.from(JSON.stringify(map));
2849
2850
  }
2850
2851
  function stringifyLoaderObject(o) {
2851
2852
  return o.path + o.query + o.fragment;
@@ -3683,7 +3684,7 @@ let compilationOptionsMap = new WeakMap(), hooks_compilationHooksMap = new WeakM
3683
3684
  ...value
3684
3685
  };
3685
3686
  }
3686
- let scriptLoading = c.scriptLoading ?? 'defer', configInject = c.inject ?? !0, base = 'string' == typeof c.base ? {
3687
+ let scriptLoading = c.scriptLoading ?? (this.options.output.module ? 'module' : 'defer'), configInject = c.inject ?? !0, base = 'string' == typeof c.base ? {
3687
3688
  href: c.base
3688
3689
  } : c.base, chunksSortMode = c.chunksSortMode ?? 'auto', compilation = null;
3689
3690
  function generateRenderData(data) {
@@ -4920,7 +4921,7 @@ async function runLoaders(compiler, context) {
4920
4921
  break;
4921
4922
  case binding_namespaceObject.JsLoaderState.Normal:
4922
4923
  {
4923
- let content = context.content, sourceMap = JsSourceMap.__from_binding(context.sourceMap), additionalData = context.additionalData;
4924
+ let sourceMap, content = context.content, rawSourceMap = context.sourceMap, sourceMapParsed = !1, additionalData = context.additionalData;
4924
4925
  for(; loaderContext.loaderIndex >= 0;){
4925
4926
  let currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex], parallelism = enableParallelism(currentLoaderObject);
4926
4927
  if (currentLoaderObject.shouldYield()) break;
@@ -4930,13 +4931,13 @@ async function runLoaders(compiler, context) {
4930
4931
  }
4931
4932
  await utils_loadLoader(currentLoaderObject, compiler);
4932
4933
  let fn = currentLoaderObject.normal;
4933
- parallelism && fn || (currentLoaderObject.normalExecuted = !0), fn && ([content, sourceMap, additionalData] = await isomorphoicRun(fn, [
4934
+ parallelism && fn || (currentLoaderObject.normalExecuted = !0), fn && (sourceMapParsed || (sourceMap = JsSourceMap.__from_binding(rawSourceMap), sourceMapParsed = !0), [content, sourceMap, additionalData] = await isomorphoicRun(fn, [
4934
4935
  content,
4935
4936
  sourceMap,
4936
4937
  additionalData
4937
4938
  ]));
4938
4939
  }
4939
- context.content = isNil(content) ? null : toBuffer(content), context.sourceMap = JsSourceMap.__to_binding(sourceMap), context.additionalData = additionalData || void 0, context.__internal__utf8Hint = 'string' == typeof content;
4940
+ context.content = isNil(content) ? null : toBuffer(content), context.sourceMap = sourceMapParsed ? JsSourceMap.__to_binding(sourceMap) : rawSourceMap, context.additionalData = additionalData || void 0, context.__internal__utf8Hint = 'string' == typeof content;
4940
4941
  break;
4941
4942
  }
4942
4943
  default:
@@ -6712,9 +6713,9 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6712
6713
  case 'memory':
6713
6714
  break;
6714
6715
  case 'persistent':
6715
- D(cache, 'version', ''), F(cache, 'buildDependencies', ()=>[]), F(cache.snapshot, 'immutablePaths', ()=>[]), F(cache.snapshot, 'unmanagedPaths', ()=>[]), F(cache.snapshot, 'managedPaths', ()=>[
6716
+ D(cache, 'version', ''), D(cache, 'maxAge', 604800), D(cache, 'maxVersions', 3), F(cache, 'buildDependencies', ()=>[]), F(cache.snapshot, 'immutablePaths', ()=>[]), F(cache.snapshot, 'unmanagedPaths', ()=>[]), F(cache.snapshot, 'managedPaths', ()=>[
6716
6717
  /[\\/]node_modules[\\/][^.]/
6717
- ]), D(cache.storage, 'type', 'filesystem'), D(cache.storage, 'maxAge', 604800), D(cache.storage, 'maxGenerations', 3), F(cache.storage, 'directory', ()=>{
6718
+ ]), D(cache.storage, 'type', 'filesystem'), F(cache.storage, 'directory', ()=>{
6718
6719
  let modeName = mode || 'production', compilerName = name ? `${name}-${modeName}` : modeName, cacheName = compilerIndex ? `${compilerName}-${compilerIndex}` : compilerName;
6719
6720
  return node_path.resolve(context, 'node_modules/.cache/rspack', cacheName);
6720
6721
  }), D(cache, 'portable', !1), D(cache, 'readonly', !1);
@@ -7031,7 +7032,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7031
7032
  return output.wasmLoading && enabledWasmLoadingTypes.add(output.wasmLoading), output.workerWasmLoading && enabledWasmLoadingTypes.add(output.workerWasmLoading), forEachEntry((desc)=>{
7032
7033
  desc.wasmLoading && enabledWasmLoadingTypes.add(desc.wasmLoading);
7033
7034
  }), Array.from(enabledWasmLoadingTypes);
7034
- }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.1.0-rc.0"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
7035
+ }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.1.1"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
7035
7036
  }, applyExternalsPresetsDefaults = (externalsPresets, { targetProperties, buildHttp, outputModule })=>{
7036
7037
  let isUniversal = (key)=>!!(outputModule && targetProperties && null === targetProperties[key]);
7037
7038
  D(externalsPresets, 'web', !buildHttp && targetProperties && (targetProperties.web || isUniversal('node'))), D(externalsPresets, 'node', targetProperties && (targetProperties.node || isUniversal('node'))), D(externalsPresets, 'electron', targetProperties && targetProperties.electron || isUniversal('electron')), D(externalsPresets, 'electronMain', targetProperties && !!targetProperties.electron && (targetProperties.electronMain || isUniversal('electronMain'))), D(externalsPresets, 'electronPreload', targetProperties && !!targetProperties.electron && (targetProperties.electronPreload || isUniversal('electronPreload'))), D(externalsPresets, 'electronRenderer', targetProperties && !!targetProperties.electron && (targetProperties.electronRenderer || isUniversal('electronRenderer'))), D(externalsPresets, 'nwjs', targetProperties && (targetProperties.nwjs || isUniversal('nwjs')));
@@ -7350,6 +7351,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7350
7351
  return {
7351
7352
  type: 'persistent',
7352
7353
  version: cache.version,
7354
+ maxAge: cache.maxAge,
7355
+ maxVersions: cache.maxVersions,
7353
7356
  portable: cache.portable,
7354
7357
  readonly: cache.readonly,
7355
7358
  buildDependencies: nestedArray(cache.buildDependencies, (deps)=>deps.map((d)=>node_path.resolve(context, d))),
@@ -7366,9 +7369,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7366
7369
  })),
7367
7370
  storage: nestedConfig(cache.storage, (storage)=>({
7368
7371
  type: storage.type,
7369
- directory: optionalNestedConfig(storage.directory, (d)=>node_path.resolve(context, d)),
7370
- maxAge: storage.maxAge,
7371
- maxGenerations: storage.maxGenerations
7372
+ directory: optionalNestedConfig(storage.directory, (d)=>node_path.resolve(context, d))
7372
7373
  }))
7373
7374
  };
7374
7375
  }
@@ -8329,7 +8330,7 @@ class MultiStats {
8329
8330
  obj.children = this.stats.map((stat, idx)=>{
8330
8331
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
8331
8332
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
8332
- }), childOptions.version && (obj.rspackVersion = "2.1.0-rc.0", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8333
+ }), childOptions.version && (obj.rspackVersion = "2.1.1", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8333
8334
  let mapError = (j, obj)=>({
8334
8335
  ...obj,
8335
8336
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -8659,21 +8660,38 @@ let filterToFunction = (item)=>{
8659
8660
  true: 2,
8660
8661
  verbose: 1
8661
8662
  };
8663
+ class NativeWatcherShim extends EventEmitter {
8664
+ #trigger;
8665
+ constructor(trigger){
8666
+ super(), this.#trigger = trigger;
8667
+ }
8668
+ _onChange(item, _mtime, file, _type) {
8669
+ this.#trigger('change', file ?? item);
8670
+ }
8671
+ _onRemove(item, file, _type) {
8672
+ this.#trigger('remove', file ?? item);
8673
+ }
8674
+ }
8662
8675
  class NativeWatchFileSystem {
8663
8676
  #inner;
8664
8677
  #isFirstWatch = !0;
8665
8678
  #inputFileSystem;
8679
+ #events = new EventEmitter();
8680
+ #watcher;
8666
8681
  constructor(inputFileSystem){
8667
8682
  this.#inputFileSystem = inputFileSystem;
8668
8683
  }
8684
+ get watcher() {
8685
+ return this.#watcher;
8686
+ }
8669
8687
  watch(files, directories, missing, startTime, options, callback, callbackUndelayed) {
8670
8688
  if ((!files.added || 'function' != typeof files.added[Symbol.iterator]) && (!files.removed || 'function' != typeof files.removed[Symbol.iterator])) throw Error("Invalid arguments: 'files'");
8671
8689
  if ((!directories.added || 'function' != typeof directories.added[Symbol.iterator]) && (!directories.removed || 'function' != typeof directories.removed[Symbol.iterator])) throw Error("Invalid arguments: 'directories'");
8672
8690
  if ('function' != typeof callback) throw Error("Invalid arguments: 'callback'");
8673
8691
  if ('object' != typeof options) throw Error("Invalid arguments: 'options'");
8674
8692
  if ('function' != typeof callbackUndelayed && callbackUndelayed) throw Error("Invalid arguments: 'callbackUndelayed'");
8675
- let nativeWatcher = this.getNativeWatcher(options);
8676
- return nativeWatcher.watch(this.formatWatchDependencies(files), this.formatWatchDependencies(directories), this.formatWatchDependencies(missing), BigInt(startTime), (err, result)=>{
8693
+ let nativeWatcher = this.getNativeWatcher(options), watcher = new NativeWatcherShim((kind, path)=>this.#inner?.triggerEvent(kind, path));
8694
+ return this.#watcher = watcher, nativeWatcher.watch(this.formatWatchDependencies(files), this.formatWatchDependencies(directories), this.formatWatchDependencies(missing), BigInt(startTime), (err, result)=>{
8677
8695
  if (err) return void callback(err, new Map(), new Map(), new Set(), new Set());
8678
8696
  nativeWatcher.pause();
8679
8697
  let changedFiles = result.changedFiles, removedFiles = result.removedFiles;
@@ -8682,9 +8700,13 @@ class NativeWatchFileSystem {
8682
8700
  for (let item of changedFiles)fs.purge?.(item);
8683
8701
  for (let item of removedFiles)fs.purge?.(item);
8684
8702
  }
8685
- callback(err, new Map(), new Map(), new Set(changedFiles), new Set(removedFiles));
8686
- }, (fileName)=>{
8687
- callbackUndelayed(fileName, Date.now());
8703
+ let changes = new Set(changedFiles), removals = new Set(removedFiles);
8704
+ this.#events.emit('aggregated', changes, removals), watcher.emit('aggregated', changes, removals), callback(err, new Map(), new Map(), changes, removals);
8705
+ }, (event)=>{
8706
+ if ('change' === event.kind) {
8707
+ let mtime = Date.now();
8708
+ callbackUndelayed(event.path, mtime), this.#events.emit('change', event.path, mtime), watcher.emit('change', event.path, mtime);
8709
+ } else this.#events.emit('remove', event.path), watcher.emit('remove', event.path);
8688
8710
  }), this.#isFirstWatch = !1, {
8689
8711
  close: ()=>{
8690
8712
  nativeWatcher.close().then(()=>{
@@ -8720,6 +8742,19 @@ class NativeWatchFileSystem {
8720
8742
  triggerEvent(kind, path) {
8721
8743
  this.#inner?.triggerEvent(kind, path);
8722
8744
  }
8745
+ on(event, listener) {
8746
+ return this.#events.on(event, listener), this;
8747
+ }
8748
+ once(event, listener) {
8749
+ return this.#events.once(event, listener), this;
8750
+ }
8751
+ emit(event, arg1, arg2) {
8752
+ if ('aggregated' === event) {
8753
+ let notified = this.#events.emit('aggregated', arg1, arg2), shimNotified = this.#watcher?.emit('aggregated', arg1, arg2) ?? !1;
8754
+ return notified || shimNotified;
8755
+ }
8756
+ return !!this.#inner && (this.#inner.triggerEvent(event, arg1), !0);
8757
+ }
8723
8758
  formatWatchDependencies(dependencies) {
8724
8759
  return this.#isFirstWatch ? [
8725
8760
  Array.from(dependencies),
@@ -8735,6 +8770,7 @@ class NodeWatchFileSystem {
8735
8770
  inputFileSystem;
8736
8771
  watcherOptions;
8737
8772
  watcher;
8773
+ #events = new EventEmitter();
8738
8774
  constructor(inputFileSystem){
8739
8775
  this.inputFileSystem = inputFileSystem, this.watcherOptions = {
8740
8776
  aggregateTimeout: 0
@@ -8749,7 +8785,13 @@ class NodeWatchFileSystem {
8749
8785
  if ('object' != typeof options) throw Error("Invalid arguments: 'options'");
8750
8786
  if ('function' != typeof callbackUndelayed && callbackUndelayed) throw Error("Invalid arguments: 'callbackUndelayed'");
8751
8787
  let oldWatcher = this.watcher, Watchpack = NodeWatchFileSystem_require('../compiled/watchpack/index.js');
8752
- this.watcher = new Watchpack(options), callbackUndelayed && this.watcher?.once('change', callbackUndelayed);
8788
+ this.watcher = new Watchpack(options), callbackUndelayed && this.watcher?.once('change', callbackUndelayed), this.watcher?.on('change', (filename, mtime)=>{
8789
+ this.#events.emit('change', filename, mtime);
8790
+ }), this.watcher?.on('remove', (filename)=>{
8791
+ this.#events.emit('remove', filename);
8792
+ }), this.watcher?.on('aggregated', (changes, removals)=>{
8793
+ this.#events.emit('aggregated', changes, removals);
8794
+ });
8753
8795
  let fetchTimeInfo = ()=>{
8754
8796
  let fileTimeInfoEntries = new Map(), contextTimeInfoEntries = new Map();
8755
8797
  return this.watcher?.collectTimeInfoEntries(fileTimeInfoEntries, contextTimeInfoEntries), {
@@ -8812,6 +8854,15 @@ class NodeWatchFileSystem {
8812
8854
  }
8813
8855
  };
8814
8856
  }
8857
+ on(event, listener) {
8858
+ return this.#events.on(event, listener), this;
8859
+ }
8860
+ once(event, listener) {
8861
+ return this.#events.once(event, listener), this;
8862
+ }
8863
+ emit(event, arg1, arg2) {
8864
+ return 'aggregated' === event ? this.#events.emit('aggregated', arg1, arg2) : !!this.watcher && ('change' === event ? this.watcher._onChange(arg1, arg2 ?? Date.now(), arg1, 'change') : this.watcher._onRemove(arg1, arg1, 'rename'), !0);
8865
+ }
8815
8866
  }
8816
8867
  let arraySum = (array)=>{
8817
8868
  let sum = 0;
@@ -9451,7 +9502,7 @@ let iterateConfig = (config, options, fn)=>{
9451
9502
  'asset.related': ASSET_SORTERS
9452
9503
  }, MODULES_SORTER = {
9453
9504
  _: (comparators)=>{
9454
- comparators.push(compareSelect((m)=>m.commonAttributes.depth, compareNumbers), compareSelect((m)=>m.commonAttributes.preOrderIndex, compareNumbers), compareSelect((m)=>m.commonAttributes.moduleDescriptor?.identifier, compareIds));
9505
+ comparators.push(compareSelect((m)=>m.commonAttributes.depth, compareIds), compareSelect((m)=>m.commonAttributes.preOrderIndex, compareIds), compareSelect((m)=>m.commonAttributes.moduleDescriptor?.identifier, compareIds));
9455
9506
  }
9456
9507
  }, SORTERS = {
9457
9508
  'compilation.chunks': {
@@ -9603,7 +9654,7 @@ let iterateConfig = (config, options, fn)=>{
9603
9654
  object.hash = context.getStatsCompilation(compilation).hash;
9604
9655
  },
9605
9656
  version: (object)=>{
9606
- object.version = "5.75.0", object.rspackVersion = "2.1.0-rc.0";
9657
+ object.version = "5.75.0", object.rspackVersion = "2.1.1";
9607
9658
  },
9608
9659
  env: (object, _compilation, _context, { _env })=>{
9609
9660
  object.env = _env;
@@ -11264,7 +11315,7 @@ class TraceHookPlugin {
11264
11315
  });
11265
11316
  }
11266
11317
  }
11267
- let CORE_VERSION = "2.1.0-rc.0", VFILES_BY_COMPILER = new WeakMap();
11318
+ let CORE_VERSION = "2.1.1", VFILES_BY_COMPILER = new WeakMap();
11268
11319
  class VirtualModulesPlugin {
11269
11320
  #staticModules;
11270
11321
  #compiler;
@@ -11929,11 +11980,11 @@ Help:
11929
11980
  };
11930
11981
  return {
11931
11982
  ...cache,
11983
+ maxAge: toRawStorageLimit('cache.maxAge', cache.maxAge),
11984
+ maxVersions: toRawStorageLimit('cache.maxVersions', cache.maxVersions),
11932
11985
  storage: {
11933
11986
  ...cache.storage,
11934
- directory: cache.storage.directory,
11935
- maxAge: toRawStorageLimit('cache.storage.maxAge', cache.storage.maxAge),
11936
- maxGenerations: toRawStorageLimit('cache.storage.maxGenerations', cache.storage.maxGenerations)
11987
+ directory: cache.storage.directory
11937
11988
  },
11938
11989
  snapshot: {
11939
11990
  immutablePaths: cache.snapshot.immutablePaths,
@@ -13685,7 +13736,7 @@ async function transform(source, options) {
13685
13736
  let _options = JSON.stringify(options || {});
13686
13737
  return binding_default().transform(source, _options);
13687
13738
  }
13688
- let exports_rspackVersion = "2.1.0-rc.0", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13739
+ let exports_rspackVersion = "2.1.1", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13689
13740
  getNormalizedRspackOptions: getNormalizedRspackOptions,
13690
13741
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
13691
13742
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -13931,7 +13982,7 @@ let exports_rspackVersion = "2.1.0-rc.0", exports_version = "5.75.0", exports_We
13931
13982
  }
13932
13983
  }, src_fn = Object.assign(rspack_rspack, exports_namespaceObject);
13933
13984
  src_fn.rspack = src_fn, src_fn.webpack = src_fn;
13934
- let src_rspack_0 = src_fn;
13985
+ let src_rspack = src_fn;
13935
13986
  var AsyncDependenciesBlock = binding_namespaceObject.AsyncDependenciesBlock, ConcatenatedModule = binding_namespaceObject.ConcatenatedModule, ContextModule = binding_namespaceObject.ContextModule, Dependency = binding_namespaceObject.Dependency, EntryDependency = binding_namespaceObject.EntryDependency, ExternalModule = binding_namespaceObject.ExternalModule, Module = binding_namespaceObject.Module, NormalModule = binding_namespaceObject.NormalModule;
13936
- export default src_rspack_0;
13937
- export { AsyncDependenciesBlock, BannerPlugin, CaseSensitivePlugin, CircularCheckRspackPlugin, CircularDependencyRspackPlugin, Compilation, Compiler, ConcatenatedModule, ContextModule, ContextReplacementPlugin, CopyRspackPlugin, CssExtractRspackPlugin, DefaultRuntimeGlobals as RuntimeGlobals, DefinePlugin, Dependency, DllPlugin, DllReferencePlugin, DynamicEntryPlugin, EntryDependency, EntryPlugin, EnvironmentPlugin, EvalDevToolModulePlugin, EvalSourceMapDevToolPlugin, ExternalModule, ExternalsPlugin, HotModuleReplacementPlugin, HtmlRspackPlugin, IgnorePlugin, LightningCssMinimizerRspackPlugin, LoaderOptionsPlugin, LoaderTargetPlugin, Module, ModuleFilenameHelpers_namespaceObject as ModuleFilenameHelpers, ModuleGraphConnection, MultiCompiler, MultiStats, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, ProgressPlugin, ProvidePlugin, RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply, RuntimeModule, RuntimePlugin, SourceMapDevToolPlugin, Stats, SubresourceIntegrityPlugin, SwcJsMinimizerRspackPlugin, Template, ValidationError, container, electron, exports_WebpackError as WebpackError, exports_config as config, exports_experiments as experiments, exports_ids as ids, exports_library as library, exports_node as node, exports_rspackVersion as rspackVersion, exports_version as version, exports_wasm as wasm, index_js_namespaceObject as sources, javascript, lazyCompilationMiddleware, lib_EntryOptionPlugin as EntryOptionPlugin, optimize, sharing, src_rspack_0 as "module.exports", src_rspack_0 as rspack, statsFactoryUtils_StatsErrorCode as StatsErrorCode, util, web, webworker };
13987
+ export default src_rspack;
13988
+ export { AsyncDependenciesBlock, BannerPlugin, CaseSensitivePlugin, CircularCheckRspackPlugin, CircularDependencyRspackPlugin, Compilation, Compiler, ConcatenatedModule, ContextModule, ContextReplacementPlugin, CopyRspackPlugin, CssExtractRspackPlugin, DefaultRuntimeGlobals as RuntimeGlobals, DefinePlugin, Dependency, DllPlugin, DllReferencePlugin, DynamicEntryPlugin, EntryDependency, EntryPlugin, EnvironmentPlugin, EvalDevToolModulePlugin, EvalSourceMapDevToolPlugin, ExternalModule, ExternalsPlugin, HotModuleReplacementPlugin, HtmlRspackPlugin, IgnorePlugin, LightningCssMinimizerRspackPlugin, LoaderOptionsPlugin, LoaderTargetPlugin, Module, ModuleFilenameHelpers_namespaceObject as ModuleFilenameHelpers, ModuleGraphConnection, MultiCompiler, MultiStats, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, ProgressPlugin, ProvidePlugin, RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply, RuntimeModule, RuntimePlugin, SourceMapDevToolPlugin, Stats, SubresourceIntegrityPlugin, SwcJsMinimizerRspackPlugin, Template, ValidationError, container, electron, exports_WebpackError as WebpackError, exports_config as config, exports_experiments as experiments, exports_ids as ids, exports_library as library, exports_node as node, exports_rspackVersion as rspackVersion, exports_version as version, exports_wasm as wasm, index_js_namespaceObject as sources, javascript, lazyCompilationMiddleware, lib_EntryOptionPlugin as EntryOptionPlugin, optimize, sharing, src_rspack as "module.exports", src_rspack as rspack, statsFactoryUtils_StatsErrorCode as StatsErrorCode, util, web, webworker };
@@ -19,7 +19,6 @@ export declare class HookWebpackError extends WebpackError {
19
19
  */
20
20
  constructor(error: Error, hook: string);
21
21
  }
22
- export default HookWebpackError;
23
22
  /**
24
23
  * @param error an error
25
24
  * @param hook name of the hook
@@ -32,4 +32,4 @@ declare class LazyHashedEtag {
32
32
  * @returns etag
33
33
  */
34
34
  export declare const getter: (obj: HashableObject, hashFunction?: string | HashConstructor) => LazyHashedEtag;
35
- export default getter;
35
+ export {};
@@ -14,4 +14,3 @@ import type { Etag } from '../Cache.js';
14
14
  * @returns result
15
15
  */
16
16
  export declare const mergeEtags: (first: Etag, second: Etag) => Etag;
17
- export default mergeEtags;
@@ -11,10 +11,20 @@ import type Watchpack from '../../compiled/watchpack/index.js';
11
11
  import type { FileSystemInfoEntry, InputFileSystem, Watcher, WatchFileSystem } from '../util/fs.js';
12
12
  type WatchpackInstance = InstanceType<typeof Watchpack>;
13
13
  export default class NodeWatchFileSystem implements WatchFileSystem {
14
+ #private;
14
15
  inputFileSystem: InputFileSystem;
15
16
  watcherOptions: Watchpack.WatchOptions;
16
17
  watcher?: WatchpackInstance;
17
18
  constructor(inputFileSystem: InputFileSystem);
18
19
  watch(files: Iterable<string>, directories: Iterable<string>, missing: Iterable<string>, startTime: number, options: Watchpack.WatchOptions, callback: (error: Error | null, fileTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, contextTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, changedFiles: Set<string>, removedFiles: Set<string>) => void, callbackUndelayed: (fileName: string, changeTime: number) => void): Watcher;
20
+ on(event: 'change', listener: (filename: string, mtime: number) => void): this;
21
+ on(event: 'remove', listener: (filename: string) => void): this;
22
+ on(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
23
+ once(event: 'change', listener: (filename: string, mtime: number) => void): this;
24
+ once(event: 'remove', listener: (filename: string) => void): this;
25
+ once(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
26
+ emit(event: 'change', filename: string, mtime: number): boolean;
27
+ emit(event: 'remove', filename: string): boolean;
28
+ emit(event: 'aggregated', changes: Set<string>, removals: Set<string>): boolean;
19
29
  }
20
30
  export {};
@@ -0,0 +1,22 @@
1
+ var __webpack_require__ = {};
2
+ __webpack_require__.n = (module)=>{
3
+ var getter = module && module.__esModule ? ()=>module.default : ()=>module;
4
+ return __webpack_require__.d(getter, {
5
+ a: getter
6
+ }), getter;
7
+ }, __webpack_require__.d = (exports, getters, values)=>{
8
+ var define = (defs, kind)=>{
9
+ for(var key in defs)__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
10
+ enumerable: !0,
11
+ [kind]: defs[key]
12
+ });
13
+ };
14
+ define(getters, "get"), define(values, "value");
15
+ }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports)=>{
16
+ "u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ }), Object.defineProperty(exports, '__esModule', {
19
+ value: !0
20
+ });
21
+ };
22
+ export { __webpack_require__ };
package/dist/rspack.d.ts CHANGED
@@ -22,4 +22,3 @@ declare function rspack(options: MultiRspackOptions, callback?: Callback<Error,
22
22
  declare function rspack(options: RspackOptions, callback?: Callback<Error, Stats>): null | Compiler;
23
23
  declare function rspack(options: MultiRspackOptions | RspackOptions, callback?: Callback<Error, MultiStats | Stats>): null | MultiCompiler | Compiler;
24
24
  export { createCompiler, createMultiCompiler, MultiStats, rspack, Stats };
25
- export default rspack;
@@ -2,7 +2,6 @@ import type { Compiler } from '../Compiler.js';
2
2
  import type { LibraryOptions, Plugins } from '../config/index.js';
3
3
  import { type ModuleFederationManifestPluginOptions } from '../container/ModuleFederationManifestPlugin.js';
4
4
  import type { Shared, SharedConfig } from './SharePlugin.js';
5
- export type MakeRequired<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
6
5
  export interface IndependentSharePluginOptions {
7
6
  name: string;
8
7
  shared: Shared;
@@ -126,11 +126,6 @@ export type KnownStatsModule = {
126
126
  filteredModules?: number;
127
127
  source?: string | Buffer;
128
128
  };
129
- export type KnownStatsProfile = {
130
- total: number;
131
- resolving: number;
132
- building: number;
133
- };
134
129
  export type StatsModule = KnownStatsModule & Record<string, any>;
135
130
  export type KnownStatsModuleIssuer = {
136
131
  identifier?: string;
@@ -334,5 +329,4 @@ export declare const errorsSpaceLimit: (errors: StatsError[], max: number) => {
334
329
  errors: StatsError[];
335
330
  filtered: number;
336
331
  };
337
- export declare const warningFromStatsWarning: (warning: binding.JsStatsError) => Error;
338
332
  export {};
@@ -11,6 +11,6 @@ export type Comparator = <T>(arg0: T, arg1: T) => -1 | 0 | 1;
11
11
  type Selector<A, B> = (input: A) => B;
12
12
  export declare const concatComparators: (...comps: Comparator[]) => Comparator;
13
13
  export declare const compareIds: <T = string | number>(a: T, b: T) => -1 | 0 | 1;
14
- export declare const compareSelect: <T, R>(getter: Selector<T, R>, comparator: Comparator) => Comparator;
15
14
  export declare const compareNumbers: (a: number, b: number) => -1 | 0 | 1;
15
+ export declare const compareSelect: <T, R>(getter: Selector<T, R>, comparator: Comparator) => Comparator;
16
16
  export {};
@@ -1,6 +1,3 @@
1
- export type FakeHook<T> = T & {
2
- _fakeHook: true;
3
- };
4
1
  export declare function createFakeCompilationDependencies(getDeps: () => string[], addDeps: (deps: string[]) => void): {
5
2
  [Symbol.iterator](): Generator<string, void, unknown>;
6
3
  has: (dep: string) => boolean;
package/dist/util/fs.d.ts CHANGED
@@ -113,7 +113,6 @@ export type JsonObject = {
113
113
  } & {
114
114
  [Key in string]?: JsonValue | undefined;
115
115
  };
116
- export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
117
116
  export type StringCallback = (err: NodeJS.ErrnoException | null, data?: string) => void;
118
117
  export type BufferCallback = (err: NodeJS.ErrnoException | null, data?: Buffer) => void;
119
118
  export type StringOrBufferCallback = (err: NodeJS.ErrnoException | null, data?: string | Buffer) => void;
@@ -124,7 +123,6 @@ export type ReaddirDirentCallback = (err: NodeJS.ErrnoException | null, files?:
124
123
  export type StatsCallback = (err: NodeJS.ErrnoException | null, stats?: IStats) => void;
125
124
  export type BigIntStatsCallback = (err: NodeJS.ErrnoException | null, stats?: IBigIntStats) => void;
126
125
  export type StatsOrBigIntStatsCallback = (err: NodeJS.ErrnoException | null, stats?: IStats | IBigIntStats) => void;
127
- export type NumberCallback = (err: NodeJS.ErrnoException | null, data?: number) => void;
128
126
  export type ReadJsonCallback = (err: NodeJS.ErrnoException | Error | null, data?: JsonObject) => void;
129
127
  export type PathLike = string | Buffer | URL;
130
128
  export type PathOrFileDescriptor = PathLike | number;
@@ -320,12 +318,6 @@ export type InputFileSystem = {
320
318
  dirname?: (path: string) => string;
321
319
  };
322
320
  export type IntermediateFileSystem = InputFileSystem & OutputFileSystem & IntermediateFileSystemExtras;
323
- export type WriteStreamOptions = {
324
- flags?: string;
325
- encoding?: 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'utf-16le' | 'ucs2' | 'ucs-2' | 'latin1' | 'binary' | 'base64' | 'base64url' | 'hex';
326
- fd?: any;
327
- mode?: number;
328
- };
329
321
  export type MakeDirectoryOptions = {
330
322
  recursive?: boolean;
331
323
  mode?: string | number;
@@ -371,5 +363,14 @@ export interface WatchFileSystem {
371
363
  added?: Iterable<String>;
372
364
  removed?: Iterable<String>;
373
365
  }, startTime: number, options: WatchOptions, callback: (error: Error | null, fileTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, contextTimeInfoEntries: Map<string, FileSystemInfoEntry | 'ignore'>, changedFiles: Set<string>, removedFiles: Set<string>) => void, callbackUndelayed: (fileName: string, changeTime: number) => void): Watcher;
366
+ on?(event: 'change', listener: (filename: string, mtime: number) => void): this;
367
+ on?(event: 'remove', listener: (filename: string) => void): this;
368
+ on?(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
369
+ once?(event: 'change', listener: (filename: string, mtime: number) => void): this;
370
+ once?(event: 'remove', listener: (filename: string) => void): this;
371
+ once?(event: 'aggregated', listener: (changes: Set<string>, removals: Set<string>) => void): this;
372
+ emit?(event: 'change', filename: string, mtime: number): boolean;
373
+ emit?(event: 'remove', filename: string): boolean;
374
+ emit?(event: 'aggregated', changes: Set<string>, removals: Set<string>): boolean;
374
375
  }
375
376
  export {};
package/dist/worker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  let createMd4, createXxhash64, url;
2
- import { __webpack_require__ } from "./612.js";
2
+ import { __webpack_require__ } from "./rslib-runtime-worker.js";
3
3
  import node_fs from "node:fs";
4
4
  import node_querystring from "node:querystring";
5
5
  import { inspect, promisify } from "node:util";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "2.1.0-rc.0",
3
+ "version": "2.1.1",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "Fast Rust-based bundler for the web with a modernized webpack API",
@@ -58,7 +58,7 @@
58
58
  "webpack-sources": "3.5.0"
59
59
  },
60
60
  "dependencies": {
61
- "@rspack/binding": "2.1.0-rc.0"
61
+ "@rspack/binding": "2.1.1"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "@module-federation/runtime-tools": "^0.24.1 || ^2.0.0",
File without changes