@rspack/core 2.0.0 → 2.0.2

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,53 @@
1
+ export function batch(fn: () => void): void;
2
+ export function getNumberOfWatchers(): number;
3
+ export function watch(filePath: string): Watcher;
4
+ export type FSWatcher = import("fs").FSWatcher;
5
+ export type EventType = import("./index").EventType;
6
+ export type WatcherSet = Set<Watcher>;
7
+ export type WatcherEvents = {
8
+ /**
9
+ * change event
10
+ */
11
+ change: (eventType: EventType, filename?: string) => void;
12
+ /**
13
+ * error event
14
+ */
15
+ error: (err: unknown) => void;
16
+ };
17
+ /**
18
+ * @typedef {object} WatcherEvents
19
+ * @property {(eventType: EventType, filename?: string) => void} change change event
20
+ * @property {(err: unknown) => void} error error event
21
+ */
22
+ /**
23
+ * @extends {EventEmitter<{ [K in keyof WatcherEvents]: Parameters<WatcherEvents[K]> }>}
24
+ */
25
+ export class Watcher extends EventEmitter<{
26
+ /**
27
+ * change event
28
+ */
29
+ change: [
30
+ eventType: import("./index").EventType,
31
+ filename?: string | undefined,
32
+ ];
33
+ /**
34
+ * error event
35
+ */
36
+ error: [err: unknown];
37
+ }> {
38
+ constructor();
39
+ close(): void;
40
+ }
41
+ /**
42
+ * @param {FSWatcher} watcher watcher
43
+ * @param {string} filePath a file path
44
+ * @param {(type: "rename" | "change", filename: string) => void} handleChangeEvent function to handle change
45
+ * @returns {(type: "rename" | "change", filename: string) => void} handler of change event
46
+ */
47
+ export function createHandleChangeEvent(
48
+ watcher: FSWatcher,
49
+ filePath: string,
50
+ handleChangeEvent: (type: "rename" | "change", filename: string) => void,
51
+ ): (type: "rename" | "change", filename: string) => void;
52
+ export const watcherLimit: number;
53
+ import { EventEmitter } from "events";
@@ -0,0 +1,2 @@
1
+ declare const _exports: typeof import("./index");
2
+ export = _exports;
@@ -45,7 +45,7 @@ export interface Asset {
45
45
  info: AssetInfo;
46
46
  }
47
47
  export type ChunkPathData = {
48
- id?: string;
48
+ id?: string | number;
49
49
  name?: string;
50
50
  hash?: string;
51
51
  contentHash?: Record<string, string>;
@@ -56,7 +56,7 @@ export type PathData = {
56
56
  contentHash?: string;
57
57
  runtime?: string;
58
58
  url?: string;
59
- id?: string;
59
+ id?: string | number;
60
60
  chunk?: Chunk | ChunkPathData;
61
61
  contentHashType?: string;
62
62
  };
@@ -29,7 +29,7 @@ export interface RscManifestPerEntry {
29
29
  export type RscManifest = Record<string, RscManifestPerEntry>;
30
30
  export type RscServerPluginOptions = {
31
31
  coordinator: Coordinator;
32
- onServerComponentChanges?: () => Promise<void>;
32
+ onServerComponentChanges?: () => void | Promise<void>;
33
33
  onManifest?: (manifest: RscManifest) => void | Promise<void>;
34
34
  };
35
35
  export declare class RscServerPlugin extends RspackBuiltinPlugin {
@@ -1,13 +1,13 @@
1
- import { RscClientPlugin, type RscClientPluginOptions } from './RscClientPlugin.js';
2
- import { RscServerPlugin } from './RscServerPlugin.js';
1
+ import { RscClientPlugin } from './RscClientPlugin.js';
2
+ import { RscServerPlugin, type RscServerPluginOptions } from './RscServerPlugin.js';
3
3
  declare class ServerPlugin extends RscServerPlugin {
4
- constructor(options?: Omit<RscClientPluginOptions, 'coordinator'>);
4
+ constructor(options?: Omit<RscServerPluginOptions, 'coordinator'>);
5
5
  }
6
6
  declare class ClientPlugin extends RscClientPlugin {
7
7
  }
8
8
  export declare const rsc: {
9
9
  createPlugins: () => {
10
- ServerPlugin: new (options?: Omit<RscClientPluginOptions, "coordinator">) => ServerPlugin;
10
+ ServerPlugin: new (options?: Omit<RscServerPluginOptions, "coordinator">) => ServerPlugin;
11
11
  ClientPlugin: new () => ClientPlugin;
12
12
  };
13
13
  Layers: {
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
34
34
  value: !0
35
35
  });
36
36
  }, __webpack_require__.add({
37
- "../../node_modules/.pnpm/enhanced-resolve@5.20.1/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js" (module, __unused_rspack_exports, __webpack_require__) {
37
+ "../../node_modules/.pnpm/enhanced-resolve@5.21.0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js" (module, __unused_rspack_exports, __webpack_require__) {
38
38
  let { nextTick } = __webpack_require__("process"), dirname = (path)=>{
39
39
  let idx = path.length - 1;
40
40
  for(; idx >= 0;){
@@ -76,7 +76,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
76
76
  constructor(duration, provider, syncProvider, providerContext){
77
77
  this._duration = duration, this._provider = provider, this._syncProvider = syncProvider, this._providerContext = providerContext, this._activeAsyncOperations = new Map(), this._data = new Map(), this._levels = [];
78
78
  for(let i = 0; i < 10; i++)this._levels.push(new Set());
79
- for(let i = 5000; i < duration; i += 500)this._levels.push(new Set());
79
+ if (duration !== 1 / 0) for(let i = 5000; i < duration; i += 500)this._levels.push(new Set());
80
80
  this._currentLevel = 0, this._tickInterval = Math.floor(duration / this._levels.length), this._mode = 0, this._timeout = void 0, this._nextDecay = void 0, this.provide = provider ? this.provide.bind(this) : null, this.provideSync = syncProvider ? this.provideSync.bind(this) : null;
81
81
  }
82
82
  provide(path, options, callback) {
@@ -176,7 +176,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
176
176
  if (this._runDecays(), 0 === this._mode) return;
177
177
  timeout = Math.max(0, this._nextDecay - Date.now());
178
178
  }
179
- this._mode = 2;
179
+ if (this._mode = 2, this._duration === 1 / 0) return;
180
180
  let ref = setTimeout(()=>{
181
181
  this._mode = 1, this._runDecays();
182
182
  }, timeout);
@@ -1671,7 +1671,7 @@ Object.defineProperty(binding_namespaceObject.Chunk.prototype, 'files', {
1671
1671
  let chunkHashMap = {}, chunkContentHashMap = {}, chunkNameMap = {};
1672
1672
  for (let chunk of this.getAllAsyncChunks()){
1673
1673
  let id = chunk.id;
1674
- if (!id) continue;
1674
+ if (void 0 === id) continue;
1675
1675
  let chunkHash = realHash ? chunk.hash : chunk.renderedHash;
1676
1676
  for (let key of (chunkHash && (chunkHashMap[id] = chunkHash), Object.keys(chunk.contentHash)))chunkContentHashMap[key] || (chunkContentHashMap[key] = {}), chunkContentHashMap[key][id] = chunk.contentHash[key];
1677
1677
  chunk.name && (chunkNameMap[id] = chunk.name);
@@ -1809,7 +1809,7 @@ function createDiagnosticArray(adm) {
1809
1809
  return copy.sort(compareFn), adm.spliceWithArray(0, adm.length, copy), this;
1810
1810
  },
1811
1811
  at: (index)=>adm.get(index),
1812
- concat: (...items)=>([].includes, adm.values().concat(...items)),
1812
+ concat: (...items)=>adm.values().concat(...items),
1813
1813
  flat: ()=>adm.values(),
1814
1814
  every: (predicate, thisArg)=>adm.values().every(predicate, thisArg),
1815
1815
  filter: (predicate, thisArg)=>adm.values().filter(predicate, thisArg),
@@ -1848,6 +1848,20 @@ function _to_property_key(arg) {
1848
1848
  function _type_of(obj) {
1849
1849
  return obj && "u" > typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj;
1850
1850
  }
1851
+ function normalizePathData(data = {}) {
1852
+ let pathData = {
1853
+ filename: data.filename,
1854
+ hash: data.hash,
1855
+ contentHash: data.contentHash,
1856
+ runtime: data.runtime,
1857
+ url: data.url
1858
+ };
1859
+ return void 0 !== data.id && (pathData.id = String(data.id)), data.chunk && (pathData.chunk = {
1860
+ id: void 0 !== data.chunk.id ? String(data.chunk.id) : void 0,
1861
+ name: data.chunk.name,
1862
+ hash: data.chunk.hash
1863
+ }), pathData;
1864
+ }
1851
1865
  let checkCompilation = (compilation)=>{
1852
1866
  if (!(compilation instanceof Compilation)) throw TypeError('The \'compilation\' argument must be an instance of Compilation. This usually occurs when multiple versions of "@rspack/core" are used, or when the code in "@rspack/core" is executed multiple times.');
1853
1867
  };
@@ -2159,27 +2173,19 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2159
2173
  this.#warnings || (this.#warnings = createDiagnosticArray(this.#inner.warnings)), this.#warnings.splice(0, this.#warnings.length, ...warnings);
2160
2174
  }
2161
2175
  getPath(filename, data = {}) {
2162
- let pathData = {
2163
- ...data
2164
- };
2176
+ let pathData = normalizePathData(data);
2165
2177
  return data.contentHashType && data.chunk?.contentHash && (pathData.contentHash = data.chunk.contentHash[data.contentHashType]), this.#inner.getPath(filename, pathData);
2166
2178
  }
2167
2179
  getPathWithInfo(filename, data = {}) {
2168
- let pathData = {
2169
- ...data
2170
- };
2180
+ let pathData = normalizePathData(data);
2171
2181
  return data.contentHashType && data.chunk?.contentHash && (pathData.contentHash = data.chunk.contentHash[data.contentHashType]), this.#inner.getPathWithInfo(filename, pathData);
2172
2182
  }
2173
2183
  getAssetPath(filename, data = {}) {
2174
- let pathData = {
2175
- ...data
2176
- };
2184
+ let pathData = normalizePathData(data);
2177
2185
  return data.contentHashType && data.chunk?.contentHash && (pathData.contentHash = data.chunk.contentHash[data.contentHashType]), this.#inner.getAssetPath(filename, pathData);
2178
2186
  }
2179
2187
  getAssetPathWithInfo(filename, data = {}) {
2180
- let pathData = {
2181
- ...data
2182
- };
2188
+ let pathData = normalizePathData(data);
2183
2189
  return data.contentHashType && data.chunk?.contentHash && (pathData.contentHash = data.chunk.contentHash[data.contentHashType]), this.#inner.getAssetPathWithInfo(filename, pathData);
2184
2190
  }
2185
2191
  getLogger(name) {
@@ -6865,7 +6871,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6865
6871
  return output.wasmLoading && enabledWasmLoadingTypes.add(output.wasmLoading), output.workerWasmLoading && enabledWasmLoadingTypes.add(output.workerWasmLoading), forEachEntry((desc)=>{
6866
6872
  desc.wasmLoading && enabledWasmLoadingTypes.add(desc.wasmLoading);
6867
6873
  }), Array.from(enabledWasmLoadingTypes);
6868
- }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.0"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
6874
+ }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.2"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
6869
6875
  }, applyExternalsPresetsDefaults = (externalsPresets, { targetProperties, buildHttp, outputModule })=>{
6870
6876
  let isUniversal = (key)=>!!(outputModule && targetProperties && null === targetProperties[key]);
6871
6877
  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')));
@@ -8119,7 +8125,7 @@ class MultiStats {
8119
8125
  obj.children = this.stats.map((stat, idx)=>{
8120
8126
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
8121
8127
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
8122
- }), childOptions.version && (obj.rspackVersion = "2.0.0", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8128
+ }), childOptions.version && (obj.rspackVersion = "2.0.2", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8123
8129
  let mapError = (j, obj)=>({
8124
8130
  ...obj,
8125
8131
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -8628,7 +8634,7 @@ let arraySum = (array)=>{
8628
8634
  let str = `${a}`, length = lengths[i];
8629
8635
  return str.length === length ? str : length > 5 ? `...${str.slice(-length + 3)}` : length > 0 ? str.slice(-length) : '';
8630
8636
  });
8631
- }, CachedInputFileSystem = __webpack_require__("../../node_modules/.pnpm/enhanced-resolve@5.20.1/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js");
8637
+ }, CachedInputFileSystem = __webpack_require__("../../node_modules/.pnpm/enhanced-resolve@5.21.0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js");
8632
8638
  var CachedInputFileSystem_default = __webpack_require__.n(CachedInputFileSystem);
8633
8639
  class NodeEnvironmentPlugin {
8634
8640
  options;
@@ -9246,7 +9252,7 @@ let iterateConfig = (config, options, fn)=>{
9246
9252
  }, SORTERS = {
9247
9253
  'compilation.chunks': {
9248
9254
  _: (comparators)=>{
9249
- comparators.push(compareSelect((c)=>c.id, compareIds));
9255
+ comparators.push(compareSelect((c)=>void 0 === c.id ? void 0 : String(c.id), compareIds));
9250
9256
  }
9251
9257
  },
9252
9258
  'compilation.modules': MODULES_SORTER,
@@ -9342,7 +9348,10 @@ let iterateConfig = (config, options, fn)=>{
9342
9348
  ]) : 'error' === logging ? getLogTypesBitFlag([
9343
9349
  LogType.error
9344
9350
  ]) : getLogTypesBitFlag([]), object.logging = {};
9345
- let compilationLogging = compilation.logging;
9351
+ let compilationLogging = new Map();
9352
+ for (let [origin, logEntries] of compilation.logging)compilationLogging.set(origin, [
9353
+ ...logEntries
9354
+ ]);
9346
9355
  for (let { name, ...rest } of context.getInner(compilation).getLogging(acceptedTypes)){
9347
9356
  let value = compilationLogging.get(name), entry = {
9348
9357
  type: rest.type,
@@ -9390,7 +9399,7 @@ let iterateConfig = (config, options, fn)=>{
9390
9399
  object.hash = context.getStatsCompilation(compilation).hash;
9391
9400
  },
9392
9401
  version: (object)=>{
9393
- object.version = "5.75.0", object.rspackVersion = "2.0.0";
9402
+ object.version = "5.75.0", object.rspackVersion = "2.0.2";
9394
9403
  },
9395
9404
  env: (object, _compilation, _context, { _env })=>{
9396
9405
  object.env = _env;
@@ -11048,7 +11057,7 @@ class TraceHookPlugin {
11048
11057
  });
11049
11058
  }
11050
11059
  }
11051
- let CORE_VERSION = "2.0.0", VFILES_BY_COMPILER = new WeakMap();
11060
+ let CORE_VERSION = "2.0.2", VFILES_BY_COMPILER = new WeakMap();
11052
11061
  class VirtualModulesPlugin {
11053
11062
  #staticModules;
11054
11063
  #compiler;
@@ -13351,7 +13360,7 @@ async function transform(source, options) {
13351
13360
  let _options = JSON.stringify(options || {});
13352
13361
  return binding_default().transform(source, _options);
13353
13362
  }
13354
- let exports_rspackVersion = "2.0.0", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13363
+ let exports_rspackVersion = "2.0.2", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13355
13364
  getNormalizedRspackOptions: getNormalizedRspackOptions,
13356
13365
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
13357
13366
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -77,9 +77,9 @@ export type KnownStatsAsset = {
77
77
  related?: StatsAsset[];
78
78
  chunkNames?: (string | number)[];
79
79
  chunkIdHints?: (string | number)[];
80
- chunks?: (string | null | undefined)[];
80
+ chunks?: (string | number | null | undefined)[];
81
81
  auxiliaryChunkNames?: (string | number)[];
82
- auxiliaryChunks?: (string | null | undefined)[];
82
+ auxiliaryChunks?: (string | number | null | undefined)[];
83
83
  auxiliaryChunkIdHints?: (string | number)[];
84
84
  filteredRelated?: number;
85
85
  isOverSizeLimit?: boolean;
@@ -108,7 +108,7 @@ export type KnownStatsModule = {
108
108
  orphan?: boolean;
109
109
  id?: string | number | null;
110
110
  issuerId?: string | number | null;
111
- chunks?: string[];
111
+ chunks?: (string | number)[];
112
112
  assets?: string[];
113
113
  dependent?: boolean;
114
114
  issuer?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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",
@@ -40,26 +40,25 @@
40
40
  "@ast-grep/napi": "^0.42.1",
41
41
  "@napi-rs/wasm-runtime": "1.1.4",
42
42
  "@rsbuild/plugin-node-polyfill": "^1.4.4",
43
- "@rslib/core": "0.21.2",
43
+ "@rslib/core": "0.21.3",
44
44
  "@rspack/lite-tapable": "1.1.0",
45
45
  "@swc/types": "0.1.26",
46
46
  "@types/node": "^20.19.39",
47
- "@types/watchpack": "^2.4.5",
48
47
  "browserslist-load-config": "^1.0.1",
49
48
  "browserslist-to-es-version": "^1.4.1",
50
49
  "connect-next": "^4.0.1",
51
- "enhanced-resolve": "5.20.1",
52
- "http-proxy-middleware": "^3.0.5",
53
- "memfs": "4.53.0",
50
+ "enhanced-resolve": "5.21.0",
51
+ "http-proxy-middleware": "^4.0.0-beta.6",
52
+ "memfs": "4.57.2",
54
53
  "open": "^11.0.0",
55
54
  "prebundle": "^1.6.4",
56
55
  "tinypool": "^2.1.0",
57
56
  "typescript": "^6.0.3",
58
- "watchpack": "2.4.4",
57
+ "watchpack": "2.5.1",
59
58
  "webpack-sources": "3.3.4"
60
59
  },
61
60
  "dependencies": {
62
- "@rspack/binding": "2.0.0"
61
+ "@rspack/binding": "2.0.2"
63
62
  },
64
63
  "peerDependencies": {
65
64
  "@module-federation/runtime-tools": "^0.24.1 || ^2.0.0",