@rspack/browser 2.1.0-rc.0 → 2.1.0

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';
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 './binding';
2
3
  import type Watchpack from 'watchpack';
3
4
  import type { FileSystemInfoEntry, InputFileSystem, Watcher, WatchFileSystem } from './util/fs';
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 '@swc/types';
1
+ import type { Config, EnvConfig, EsParserConfig, JscConfig, ModuleConfig, ParserConfig, TransformConfig, TsParserConfig } from '@swc/types';
2
2
  import type { CollectTypeScriptInfoOptions } from './collectTypeScriptInfo';
3
3
  import type { PluginImportOptions } from './pluginImport';
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
@@ -56134,6 +56134,7 @@ const compareIds = (a, b)=>{
56134
56134
  if (a > b) return 1;
56135
56135
  return 0;
56136
56136
  };
56137
+ const compareNumbers = compareIds;
56137
56138
  const compareSelectCache = new TwoKeyWeakMap();
56138
56139
  const compareSelect = (getter, comparator)=>{
56139
56140
  const cacheEntry = compareSelectCache.get(getter, comparator);
@@ -56151,12 +56152,6 @@ const compareSelect = (getter, comparator)=>{
56151
56152
  compareSelectCache.set(getter, comparator, result);
56152
56153
  return result;
56153
56154
  };
56154
- const compareNumbers = (a, b)=>{
56155
- if (typeof a !== typeof b) return typeof a < typeof b ? -1 : 1;
56156
- if (a < b) return -1;
56157
- if (a > b) return 1;
56158
- return 0;
56159
- };
56160
56155
  const smartGrouping = (items, groupConfigs)=>{
56161
56156
  const itemsWithGroups = new Set();
56162
56157
  const allGroups = new Map();
@@ -58267,10 +58262,10 @@ const toObject = (input)=>{
58267
58262
  function serializeObject(map) {
58268
58263
  if (isNil(map)) return;
58269
58264
  if ('string' == typeof map) {
58270
- if (map) return toBuffer(map);
58265
+ if (map) return util_Buffer.from(map);
58271
58266
  return;
58272
58267
  }
58273
- return toBuffer(JSON.stringify(map));
58268
+ return util_Buffer.from(JSON.stringify(map));
58274
58269
  }
58275
58270
  function util_indent(str, prefix) {
58276
58271
  const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
@@ -58757,11 +58752,11 @@ function getRawCache(cache) {
58757
58752
  };
58758
58753
  return {
58759
58754
  ...cache,
58755
+ maxAge: toRawStorageLimit('cache.maxAge', cache.maxAge),
58756
+ maxVersions: toRawStorageLimit('cache.maxVersions', cache.maxVersions),
58760
58757
  storage: {
58761
58758
  ...cache.storage,
58762
- directory: cache.storage.directory,
58763
- maxAge: toRawStorageLimit('cache.storage.maxAge', cache.storage.maxAge),
58764
- maxGenerations: toRawStorageLimit('cache.storage.maxGenerations', cache.storage.maxGenerations)
58759
+ directory: cache.storage.directory
58765
58760
  },
58766
58761
  snapshot: {
58767
58762
  immutablePaths: cache.snapshot.immutablePaths,
@@ -59490,7 +59485,7 @@ const HtmlRspackPluginImpl = base_create(external_rspack_wasi_browser_js_Builtin
59490
59485
  ...value
59491
59486
  };
59492
59487
  }
59493
- const scriptLoading = c.scriptLoading ?? 'defer';
59488
+ const scriptLoading = c.scriptLoading ?? (this.options.output.module ? 'module' : 'defer');
59494
59489
  const configInject = c.inject ?? true;
59495
59490
  const inject = true === configInject ? 'blocking' === scriptLoading ? 'body' : 'head' : false === configInject ? 'false' : configInject;
59496
59491
  const base = 'string' == typeof c.base ? {
@@ -60955,7 +60950,9 @@ async function runLoaders(compiler, context) {
60955
60950
  case JsLoaderState.Normal:
60956
60951
  {
60957
60952
  let content = context.content;
60958
- let sourceMap = JsSourceMap.__from_binding(context.sourceMap);
60953
+ const rawSourceMap = context.sourceMap;
60954
+ let sourceMap;
60955
+ let sourceMapParsed = false;
60959
60956
  let additionalData = context.additionalData;
60960
60957
  while(loaderContext.loaderIndex >= 0){
60961
60958
  const currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
@@ -60969,6 +60966,10 @@ async function runLoaders(compiler, context) {
60969
60966
  const fn = currentLoaderObject.normal;
60970
60967
  if (!parallelism || !fn) currentLoaderObject.normalExecuted = true;
60971
60968
  if (!fn) continue;
60969
+ if (!sourceMapParsed) {
60970
+ sourceMap = JsSourceMap.__from_binding(rawSourceMap);
60971
+ sourceMapParsed = true;
60972
+ }
60972
60973
  [content, sourceMap, additionalData] = await isomorphoicRun(fn, [
60973
60974
  content,
60974
60975
  sourceMap,
@@ -60976,7 +60977,7 @@ async function runLoaders(compiler, context) {
60976
60977
  ]);
60977
60978
  }
60978
60979
  context.content = isNil(content) ? null : toBuffer(content);
60979
- context.sourceMap = JsSourceMap.__to_binding(sourceMap);
60980
+ context.sourceMap = sourceMapParsed ? JsSourceMap.__to_binding(sourceMap) : rawSourceMap;
60980
60981
  context.additionalData = additionalData || void 0;
60981
60982
  context.__internal__utf8Hint = 'string' == typeof content;
60982
60983
  break;
@@ -63096,6 +63097,8 @@ const applyCacheDefaults = (cache, { context, name, mode, compilerIndex })=>{
63096
63097
  break;
63097
63098
  case 'persistent':
63098
63099
  D(cache, 'version', '');
63100
+ D(cache, 'maxAge', DEFAULT_FILESYSTEM_CACHE_MAX_AGE_SECONDS);
63101
+ D(cache, 'maxVersions', 3);
63099
63102
  F(cache, 'buildDependencies', ()=>[]);
63100
63103
  F(cache.snapshot, 'immutablePaths', ()=>[]);
63101
63104
  F(cache.snapshot, 'unmanagedPaths', ()=>[]);
@@ -63103,8 +63106,6 @@ const applyCacheDefaults = (cache, { context, name, mode, compilerIndex })=>{
63103
63106
  /[\\/]node_modules[\\/][^.]/
63104
63107
  ]);
63105
63108
  D(cache.storage, 'type', 'filesystem');
63106
- D(cache.storage, 'maxAge', DEFAULT_FILESYSTEM_CACHE_MAX_AGE_SECONDS);
63107
- D(cache.storage, 'maxGenerations', 3);
63108
63109
  F(cache.storage, 'directory', ()=>{
63109
63110
  const modeName = mode || 'production';
63110
63111
  const compilerName = name ? `${name}-${modeName}` : modeName;
@@ -63609,7 +63610,7 @@ const applyOutputDefaults = (options, { context, targetProperties: tp, isAffecte
63609
63610
  });
63610
63611
  D(output, 'bundlerInfo', {});
63611
63612
  if ('object' == typeof output.bundlerInfo) {
63612
- D(output.bundlerInfo, 'version', "2.1.0-rc.0");
63613
+ D(output.bundlerInfo, 'version', "2.1.0");
63613
63614
  D(output.bundlerInfo, 'bundler', 'rspack');
63614
63615
  D(output.bundlerInfo, 'force', false);
63615
63616
  }
@@ -64041,6 +64042,8 @@ const getNormalizedRspackOptions = (config)=>({
64041
64042
  return {
64042
64043
  type: 'persistent',
64043
64044
  version: cache.version,
64045
+ maxAge: cache.maxAge,
64046
+ maxVersions: cache.maxVersions,
64044
64047
  portable: cache.portable,
64045
64048
  readonly: cache.readonly,
64046
64049
  buildDependencies: nestedArray(cache.buildDependencies, (deps)=>deps.map((d)=>path_browserify_default().resolve(context, d))),
@@ -64057,9 +64060,7 @@ const getNormalizedRspackOptions = (config)=>({
64057
64060
  })),
64058
64061
  storage: nestedConfig(cache.storage, (storage)=>({
64059
64062
  type: storage.type,
64060
- directory: optionalNestedConfig(storage.directory, (d)=>path_browserify_default().resolve(context, d)),
64061
- maxAge: storage.maxAge,
64062
- maxGenerations: storage.maxGenerations
64063
+ directory: optionalNestedConfig(storage.directory, (d)=>path_browserify_default().resolve(context, d))
64063
64064
  }))
64064
64065
  };
64065
64066
  }
@@ -65317,7 +65318,7 @@ class MultiStats {
65317
65318
  return obj;
65318
65319
  });
65319
65320
  if (childOptions.version) {
65320
- obj.rspackVersion = "2.1.0-rc.0";
65321
+ obj.rspackVersion = "2.1.0";
65321
65322
  obj.version = "5.75.0";
65322
65323
  }
65323
65324
  if (childOptions.hash) obj.hash = obj.children.map((j)=>j.hash).join('');
@@ -65883,17 +65884,36 @@ const createConsoleLogger = ({ level = 'info', debug = false, console: console1
65883
65884
  };
65884
65885
  return logger;
65885
65886
  };
65887
+ const events_0 = __webpack_require__("80381");
65886
65888
  const toJsWatcherIgnored = (ignored)=>{
65887
65889
  if (Array.isArray(ignored) || 'string' == typeof ignored || ignored instanceof RegExp) return ignored;
65888
65890
  if ('function' == typeof ignored) throw new Error("NativeWatcher does not support using a function for the 'ignored' option");
65889
65891
  };
65892
+ class NativeWatcherShim extends events_0.EventEmitter {
65893
+ #trigger;
65894
+ constructor(trigger){
65895
+ super();
65896
+ this.#trigger = trigger;
65897
+ }
65898
+ _onChange(item, _mtime, file, _type) {
65899
+ this.#trigger('change', file ?? item);
65900
+ }
65901
+ _onRemove(item, file, _type) {
65902
+ this.#trigger('remove', file ?? item);
65903
+ }
65904
+ }
65890
65905
  class NativeWatchFileSystem {
65891
65906
  #inner;
65892
65907
  #isFirstWatch = true;
65893
65908
  #inputFileSystem;
65909
+ #events = new events_0.EventEmitter();
65910
+ #watcher;
65894
65911
  constructor(inputFileSystem){
65895
65912
  this.#inputFileSystem = inputFileSystem;
65896
65913
  }
65914
+ get watcher() {
65915
+ return this.#watcher;
65916
+ }
65897
65917
  watch(files, directories, missing, startTime, options, callback, callbackUndelayed) {
65898
65918
  if ((!files.added || 'function' != typeof files.added[Symbol.iterator]) && (!files.removed || 'function' != typeof files.removed[Symbol.iterator])) throw new Error("Invalid arguments: 'files'");
65899
65919
  if ((!directories.added || 'function' != typeof directories.added[Symbol.iterator]) && (!directories.removed || 'function' != typeof directories.removed[Symbol.iterator])) throw new Error("Invalid arguments: 'directories'");
@@ -65901,6 +65921,8 @@ class NativeWatchFileSystem {
65901
65921
  if ('object' != typeof options) throw new Error("Invalid arguments: 'options'");
65902
65922
  if ('function' != typeof callbackUndelayed && callbackUndelayed) throw new Error("Invalid arguments: 'callbackUndelayed'");
65903
65923
  const nativeWatcher = this.getNativeWatcher(options);
65924
+ const watcher = new NativeWatcherShim((kind, path)=>this.#inner?.triggerEvent(kind, path));
65925
+ this.#watcher = watcher;
65904
65926
  nativeWatcher.watch(this.formatWatchDependencies(files), this.formatWatchDependencies(directories), this.formatWatchDependencies(missing), BigInt(startTime), (err, result)=>{
65905
65927
  if (err) return void callback(err, new Map(), new Map(), new Set(), new Set());
65906
65928
  nativeWatcher.pause();
@@ -65911,9 +65933,21 @@ class NativeWatchFileSystem {
65911
65933
  for (const item of changedFiles)fs.purge?.(item);
65912
65934
  for (const item of removedFiles)fs.purge?.(item);
65913
65935
  }
65914
- callback(err, new Map(), new Map(), new Set(changedFiles), new Set(removedFiles));
65915
- }, (fileName)=>{
65916
- callbackUndelayed(fileName, Date.now());
65936
+ const changes = new Set(changedFiles);
65937
+ const removals = new Set(removedFiles);
65938
+ this.#events.emit('aggregated', changes, removals);
65939
+ watcher.emit('aggregated', changes, removals);
65940
+ callback(err, new Map(), new Map(), changes, removals);
65941
+ }, (event)=>{
65942
+ if ('change' === event.kind) {
65943
+ const mtime = Date.now();
65944
+ callbackUndelayed(event.path, mtime);
65945
+ this.#events.emit('change', event.path, mtime);
65946
+ watcher.emit('change', event.path, mtime);
65947
+ } else {
65948
+ this.#events.emit('remove', event.path);
65949
+ watcher.emit('remove', event.path);
65950
+ }
65917
65951
  });
65918
65952
  this.#isFirstWatch = false;
65919
65953
  return {
@@ -65952,6 +65986,26 @@ class NativeWatchFileSystem {
65952
65986
  triggerEvent(kind, path) {
65953
65987
  this.#inner?.triggerEvent(kind, path);
65954
65988
  }
65989
+ on(event, listener) {
65990
+ this.#events.on(event, listener);
65991
+ return this;
65992
+ }
65993
+ once(event, listener) {
65994
+ this.#events.once(event, listener);
65995
+ return this;
65996
+ }
65997
+ emit(event, arg1, arg2) {
65998
+ if ('aggregated' === event) {
65999
+ const changes = arg1;
66000
+ const removals = arg2;
66001
+ const notified = this.#events.emit('aggregated', changes, removals);
66002
+ const shimNotified = this.#watcher?.emit('aggregated', changes, removals) ?? false;
66003
+ return notified || shimNotified;
66004
+ }
66005
+ if (!this.#inner) return false;
66006
+ this.#inner.triggerEvent(event, arg1);
66007
+ return true;
66008
+ }
65955
66009
  formatWatchDependencies(dependencies) {
65956
66010
  if (this.#isFirstWatch) return [
65957
66011
  Array.from(dependencies),
@@ -65967,6 +66021,7 @@ class NodeWatchFileSystem {
65967
66021
  inputFileSystem;
65968
66022
  watcherOptions;
65969
66023
  watcher;
66024
+ #events = new events_0.EventEmitter();
65970
66025
  constructor(inputFileSystem){
65971
66026
  this.inputFileSystem = inputFileSystem;
65972
66027
  this.watcherOptions = {
@@ -65985,6 +66040,15 @@ class NodeWatchFileSystem {
65985
66040
  const Watchpack = __webpack_require__(71823);
65986
66041
  this.watcher = new Watchpack(options);
65987
66042
  if (callbackUndelayed) this.watcher?.once('change', callbackUndelayed);
66043
+ this.watcher?.on('change', (filename, mtime)=>{
66044
+ this.#events.emit('change', filename, mtime);
66045
+ });
66046
+ this.watcher?.on('remove', (filename)=>{
66047
+ this.#events.emit('remove', filename);
66048
+ });
66049
+ this.watcher?.on('aggregated', (changes, removals)=>{
66050
+ this.#events.emit('aggregated', changes, removals);
66051
+ });
65988
66052
  const fetchTimeInfo = ()=>{
65989
66053
  const fileTimeInfoEntries = new Map();
65990
66054
  const contextTimeInfoEntries = new Map();
@@ -66057,6 +66121,22 @@ class NodeWatchFileSystem {
66057
66121
  }
66058
66122
  };
66059
66123
  }
66124
+ on(event, listener) {
66125
+ this.#events.on(event, listener);
66126
+ return this;
66127
+ }
66128
+ once(event, listener) {
66129
+ this.#events.once(event, listener);
66130
+ return this;
66131
+ }
66132
+ emit(event, arg1, arg2) {
66133
+ if ('aggregated' === event) return this.#events.emit('aggregated', arg1, arg2);
66134
+ if (!this.watcher) return false;
66135
+ const filename = arg1;
66136
+ if ('change' === event) this.watcher._onChange(filename, arg2 ?? Date.now(), filename, 'change');
66137
+ else this.watcher._onRemove(filename, filename, 'rename');
66138
+ return true;
66139
+ }
66060
66140
  }
66061
66141
  const arraySum = (array)=>{
66062
66142
  let sum = 0;
@@ -67023,7 +67103,7 @@ const SIMPLE_EXTRACTORS = {
67023
67103
  },
67024
67104
  version: (object)=>{
67025
67105
  object.version = "5.75.0";
67026
- object.rspackVersion = "2.1.0-rc.0";
67106
+ object.rspackVersion = "2.1.0";
67027
67107
  },
67028
67108
  env: (object, _compilation, _context, { _env })=>{
67029
67109
  object.env = _env;
@@ -71983,7 +72063,7 @@ function transformSync(source, options) {
71983
72063
  const _options = JSON.stringify(options || {});
71984
72064
  return rspack_wasi_browser.transformSync(source, _options);
71985
72065
  }
71986
- const exports_rspackVersion = "2.1.0-rc.0";
72066
+ const exports_rspackVersion = "2.1.0";
71987
72067
  const exports_version = "5.75.0";
71988
72068
  const exports_WebpackError = Error;
71989
72069
  const exports_config = {
@@ -72082,7 +72162,7 @@ const exports_experiments = {
72082
72162
  const src_fn = Object.assign(rspack_rspack, exports_namespaceObject);
72083
72163
  src_fn.rspack = src_fn;
72084
72164
  src_fn.webpack = src_fn;
72085
- const src_rspack_0 = src_fn;
72165
+ const src_rspack = src_fn;
72086
72166
  class BrowserHttpImportEsmPlugin {
72087
72167
  options;
72088
72168
  constructor(options){
@@ -72252,4 +72332,4 @@ const builtinMemFs = {
72252
72332
  volume: fs_0.volume,
72253
72333
  memfs: fs_0.memfs
72254
72334
  };
72255
- export { AsyncDependenciesBlock, BannerPlugin, BrowserHttpImportEsmPlugin, BrowserRequirePlugin, 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_ModuleGraphConnection as ModuleGraphConnection, MultiCompiler, MultiStats, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, ProgressPlugin, ProvidePlugin, RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply, RuntimeModule, RuntimePlugin, SourceMapDevToolPlugin, Stats, SubresourceIntegrityPlugin, SwcJsMinimizerRspackPlugin, Template, ValidationError, builtinMemFs, container, electron, exports_WebpackError as WebpackError, exports_config as config, exports_experiments as experiments, exports_library as library, exports_node as node, exports_rspackVersion as rspackVersion, exports_version as version, exports_wasm as wasm, ids, 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, webpack_sources_lib as sources, webworker };
72335
+ export { AsyncDependenciesBlock, BannerPlugin, BrowserHttpImportEsmPlugin, BrowserRequirePlugin, 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_ModuleGraphConnection as ModuleGraphConnection, MultiCompiler, MultiStats, NoEmitOnErrorsPlugin, NormalModule, NormalModuleReplacementPlugin, ProgressPlugin, ProvidePlugin, RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply, RuntimeModule, RuntimePlugin, SourceMapDevToolPlugin, Stats, SubresourceIntegrityPlugin, SwcJsMinimizerRspackPlugin, Template, ValidationError, builtinMemFs, container, electron, exports_WebpackError as WebpackError, exports_config as config, exports_experiments as experiments, exports_library as library, exports_node as node, exports_rspackVersion as rspackVersion, exports_version as version, exports_wasm as wasm, ids, javascript, lazyCompilationMiddleware, lib_EntryOptionPlugin as EntryOptionPlugin, optimize, sharing, src_rspack as "module.exports", src_rspack as rspack, statsFactoryUtils_StatsErrorCode as StatsErrorCode, util, web, webpack_sources_lib as sources, 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';
14
14
  * @returns result
15
15
  */
16
16
  export declare const mergeEtags: (first: Etag, second: Etag) => Etag;
17
- export default mergeEtags;
@@ -464,7 +464,7 @@ export declare class ModuleGraphConnection {
464
464
 
465
465
  export declare class NativeWatcher {
466
466
  constructor(options: NativeWatcherOptions)
467
- watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], startTime: bigint, callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (path: string) => void): void
467
+ watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], startTime: bigint, callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (event: NativeWatchUndelayedEvent) => void): void
468
468
  triggerEvent(kind: 'change' | 'remove' | 'create', path: string): void
469
469
  /**
470
470
  * # Safety
@@ -1797,6 +1797,16 @@ export interface NativeWatcherOptions {
1797
1797
  ignored?: string | string[] | RegExp
1798
1798
  }
1799
1799
 
1800
+ /**
1801
+ * A single, undelayed file system event delivered to the `callbackUndelayed`
1802
+ * callback. Passed as one object so napi-rs delivers it as a single JS
1803
+ * argument unambiguously (a tuple would arrive as an array).
1804
+ */
1805
+ export interface NativeWatchUndelayedEvent {
1806
+ kind: string
1807
+ path: string
1808
+ }
1809
+
1800
1810
  export interface NodeFsStats {
1801
1811
  isFile: boolean
1802
1812
  isDirectory: boolean
@@ -1916,6 +1926,8 @@ export interface RawCacheOptionsMemory {
1916
1926
  export interface RawCacheOptionsPersistent {
1917
1927
  buildDependencies?: Array<string>
1918
1928
  version?: string
1929
+ maxAge: number
1930
+ maxVersions: number
1919
1931
  snapshot?: RawSnapshotOptions
1920
1932
  storage?: RawStorageOptions
1921
1933
  portable?: boolean
@@ -3086,8 +3098,6 @@ export interface RawStatsOptions {
3086
3098
  export interface RawStorageOptions {
3087
3099
  type: "filesystem"
3088
3100
  directory: string
3089
- maxAge: number
3090
- maxGenerations: number
3091
3101
  }
3092
3102
 
3093
3103
  export interface RawSubresourceIntegrityPluginOptions {
@@ -11,10 +11,20 @@ import type Watchpack from 'watchpack';
11
11
  import type { FileSystemInfoEntry, InputFileSystem, Watcher, WatchFileSystem } from '../util/fs';
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 {};
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;
Binary file
@@ -2,7 +2,6 @@ import type { Compiler } from '../Compiler';
2
2
  import type { LibraryOptions, Plugins } from '../config';
3
3
  import { type ModuleFederationManifestPluginOptions } from '../container/ModuleFederationManifestPlugin';
4
4
  import type { Shared, SharedConfig } from './SharePlugin';
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/browser",
3
- "version": "2.1.0-rc.0",
3
+ "version": "2.1.0",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "Rspack for running in the browser. This is still in early stage and may not follow the semver.",