@rspack/core 1.0.5 → 1.0.7

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.
Files changed (41) hide show
  1. package/dist/Chunk.d.ts +5 -0
  2. package/dist/Chunk.js +28 -0
  3. package/dist/Compilation.d.ts +15 -7
  4. package/dist/Compilation.js +25 -8
  5. package/dist/Compiler.js +9 -21
  6. package/dist/Module.d.ts +20 -8
  7. package/dist/Module.js +66 -7
  8. package/dist/Resolver.d.ts +2 -4
  9. package/dist/RspackError.d.ts +2 -2
  10. package/dist/RspackError.js +3 -3
  11. package/dist/RuntimeModule.d.ts +32 -0
  12. package/dist/RuntimeModule.js +58 -0
  13. package/dist/builtin-plugin/ContextReplacementPlugin.d.ts +10 -0
  14. package/dist/builtin-plugin/ContextReplacementPlugin.js +43 -0
  15. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  16. package/dist/builtin-plugin/ProgressPlugin.js +10 -8
  17. package/dist/builtin-plugin/index.d.ts +1 -0
  18. package/dist/builtin-plugin/index.js +1 -0
  19. package/dist/config/adapter.js +30 -18
  20. package/dist/config/adapterRuleUse.d.ts +40 -3
  21. package/dist/config/browserslistTargetHandler.js +6 -5
  22. package/dist/config/defaults.js +11 -7
  23. package/dist/config/normalization.d.ts +2 -1
  24. package/dist/config/normalization.js +2 -1
  25. package/dist/config/zod.d.ts +146 -31
  26. package/dist/config/zod.js +11 -2
  27. package/dist/exports.d.ts +2 -0
  28. package/dist/exports.js +6 -2
  29. package/dist/loader-runner/index.js +30 -28
  30. package/dist/node/NodeEnvironmentPlugin.js +1 -1
  31. package/dist/stats/DefaultStatsFactoryPlugin.js +18 -29
  32. package/dist/stats/DefaultStatsPrinterPlugin.js +3 -5
  33. package/dist/stats/StatsFactory.d.ts +1 -1
  34. package/dist/stats/StatsFactory.js +1 -4
  35. package/dist/stats/statsFactoryUtils.d.ts +7 -3
  36. package/dist/stats/statsFactoryUtils.js +5 -6
  37. package/dist/util/comparators.d.ts +2 -2
  38. package/dist/util/smartGrouping.d.ts +4 -4
  39. package/dist/util/source.d.ts +1 -12
  40. package/dist/util/source.js +19 -43
  41. package/package.json +2 -2
@@ -181,17 +181,16 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
181
181
  let isDone = false;
182
182
  let isError = false; // internal error
183
183
  let reportedError = false;
184
- // @ts-expect-error loader-runner leverages `arguments` to achieve the same functionality.
185
184
  context.async = function async() {
186
185
  if (isDone) {
187
186
  if (reportedError)
188
- return; // ignore
187
+ return undefined; // ignore
189
188
  throw new Error("async(): The callback was already called.");
190
189
  }
191
190
  isSync = false;
192
191
  return innerCallback;
193
192
  };
194
- const innerCallback = (context.callback = (err, ...args) => {
193
+ const innerCallback = (err, ...args) => {
195
194
  if (isDone) {
196
195
  if (reportedError)
197
196
  return; // ignore
@@ -200,14 +199,14 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
200
199
  isDone = true;
201
200
  isSync = false;
202
201
  try {
203
- // @ts-expect-error
204
202
  callback(err, args);
205
203
  }
206
204
  catch (e) {
207
205
  isError = true;
208
206
  throw e;
209
207
  }
210
- });
208
+ };
209
+ context.callback = innerCallback;
211
210
  try {
212
211
  const result = (function LOADER_EXECUTION() {
213
212
  return fn.apply(context, args);
@@ -215,8 +214,7 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
215
214
  if (isSync) {
216
215
  isDone = true;
217
216
  if (result === undefined) {
218
- // @ts-expect-error
219
- callback();
217
+ callback(null, []);
220
218
  return;
221
219
  }
222
220
  if (result &&
@@ -250,8 +248,7 @@ const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, co
250
248
  }
251
249
  isDone = true;
252
250
  reportedError = true;
253
- // @ts-expect-error
254
- callback(e);
251
+ callback(e, []);
255
252
  }
256
253
  });
257
254
  function dirname(path) {
@@ -485,23 +482,22 @@ async function runLoaders(compiler, context) {
485
482
  loaderContext.resolve = function resolve(context, request, callback) {
486
483
  resolver.resolve({}, context, request, getResolveContext(), callback);
487
484
  };
488
- // @ts-expect-error TODO
489
485
  loaderContext.getResolve = function getResolve(options) {
490
486
  const child = options ? resolver.withOptions(options) : resolver;
491
487
  return (context, request, callback) => {
492
488
  if (callback) {
493
489
  child.resolve({}, context, request, getResolveContext(), callback);
490
+ return;
494
491
  }
495
- else {
496
- return new Promise((resolve, reject) => {
497
- child.resolve({}, context, request, getResolveContext(), (err, result) => {
498
- if (err)
499
- reject(err);
500
- else
501
- resolve(result);
502
- });
492
+ // TODO: (type) our native resolver return value is "string | false" but webpack type is "string"
493
+ return new Promise((resolve, reject) => {
494
+ child.resolve({}, context, request, getResolveContext(), (err, result) => {
495
+ if (err)
496
+ reject(err);
497
+ else
498
+ resolve(result);
503
499
  });
504
- }
500
+ });
505
501
  };
506
502
  };
507
503
  loaderContext.getLogger = function getLogger(name) {
@@ -517,7 +513,7 @@ async function runLoaders(compiler, context) {
517
513
  error.message = `${error.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
518
514
  error = (0, util_1.concatErrorMsgAndStack)(error);
519
515
  error.moduleIdentifier = this._module.identifier();
520
- compiler._lastCompilation.__internal__pushDiagnostic({
516
+ compiler._lastCompilation.__internal__pushRspackDiagnostic({
521
517
  error,
522
518
  severity: binding_1.JsRspackSeverity.Error
523
519
  });
@@ -531,13 +527,13 @@ async function runLoaders(compiler, context) {
531
527
  warning.message = `${warning.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
532
528
  warning = (0, util_1.concatErrorMsgAndStack)(warning);
533
529
  warning.moduleIdentifier = this._module.identifier();
534
- compiler._lastCompilation.__internal__pushDiagnostic({
530
+ compiler._lastCompilation.__internal__pushRspackDiagnostic({
535
531
  error: warning,
536
532
  severity: binding_1.JsRspackSeverity.Warn
537
533
  });
538
534
  };
539
535
  loaderContext.emitFile = function emitFile(name, content, sourceMap, assetInfo) {
540
- let source;
536
+ let source = undefined;
541
537
  if (sourceMap) {
542
538
  if (typeof sourceMap === "string" &&
543
539
  (loaderContext.sourceMap ||
@@ -556,14 +552,20 @@ async function runLoaders(compiler, context) {
556
552
  // @ts-expect-error webpack-sources type declaration is wrong
557
553
  content);
558
554
  }
559
- // @ts-expect-error
560
- compiler._lastCompilation.__internal__emit_asset_from_loader(name,
561
- // @ts-expect-error
562
- source,
563
- // @ts-expect-error
564
- assetInfo, context._moduleIdentifier);
555
+ compiler._lastCompilation.__internal__emit_asset_from_loader(name, source, assetInfo, context._moduleIdentifier);
565
556
  };
566
557
  loaderContext.fs = compiler.inputFileSystem;
558
+ loaderContext.experiments = {
559
+ emitDiagnostic: (diagnostic) => {
560
+ const d = Object.assign({}, diagnostic, {
561
+ message: diagnostic.severity === "warning"
562
+ ? `ModuleWarning: ${diagnostic.message}`
563
+ : `ModuleError: ${diagnostic.message}`,
564
+ moduleIdentifier: context._module.moduleIdentifier
565
+ });
566
+ compiler._lastCompilation.__internal__pushDiagnostic((0, binding_1.formatDiagnostic)(d));
567
+ }
568
+ };
567
569
  const getAbsolutify = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindCache(compiler.root));
568
570
  const getAbsolutifyInContext = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindContextCache(contextDirectory, compiler.root));
569
571
  const getContextify = (0, memoize_1.memoize)(() => identifier_1.contextify.bindCache(compiler.root));
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  * Copyright (c) JS Foundation and other contributors
13
13
  * https://github.com/webpack/webpack/blob/main/LICENSE
14
14
  */
15
- // @ts-expect-error
15
+ // @ts-expect-error we directly import from enhanced-resolve inner js file to improve performance
16
16
  const CachedInputFileSystem_1 = __importDefault(require("../../compiled/enhanced-resolve/CachedInputFileSystem"));
17
17
  const graceful_fs_1 = __importDefault(require("../../compiled/graceful-fs"));
18
18
  const createConsoleLogger_1 = require("../logging/createConsoleLogger");
@@ -66,7 +66,7 @@ const MERGER = {
66
66
  "compilation.namedChunkGroups": statsFactoryUtils_1.mergeToObject
67
67
  };
68
68
  const ASSETS_GROUPERS = {
69
- _: (groupConfigs, context, options) => {
69
+ _: (groupConfigs, _context, options) => {
70
70
  const groupByFlag = (name, exclude) => {
71
71
  groupConfigs.push({
72
72
  getKeys: (asset) => {
@@ -78,7 +78,6 @@ const ASSETS_GROUPERS = {
78
78
  force: exclude
79
79
  };
80
80
  },
81
- // @ts-expect-error
82
81
  createGroup: (key, children, assets) => {
83
82
  return exclude
84
83
  ? {
@@ -130,7 +129,6 @@ const ASSETS_GROUPERS = {
130
129
  }
131
130
  return keys;
132
131
  },
133
- // @ts-expect-error
134
132
  createGroup: (key, children) => {
135
133
  return {
136
134
  type: groupAssetsByPath ? "assets by path" : "assets by extension",
@@ -148,7 +146,6 @@ const ASSETS_GROUPERS = {
148
146
  getKeys: asset => {
149
147
  return asset.info?.[name] ? ["1"] : undefined;
150
148
  },
151
- // @ts-expect-error
152
149
  createGroup: (key, children) => {
153
150
  return {
154
151
  type: "assets by info",
@@ -171,7 +168,6 @@ const ASSETS_GROUPERS = {
171
168
  getKeys: asset => {
172
169
  return asset[name];
173
170
  },
174
- // @ts-expect-error
175
171
  createGroup: (key, children) => {
176
172
  return {
177
173
  type: "assets by chunk",
@@ -187,7 +183,7 @@ const ASSETS_GROUPERS = {
187
183
  groupByNames("chunkIdHints");
188
184
  groupByNames("auxiliaryChunkIdHints");
189
185
  },
190
- excludeAssets: (groupConfigs, context, { excludeAssets }) => {
186
+ excludeAssets: (groupConfigs, _context, { excludeAssets }) => {
191
187
  groupConfigs.push({
192
188
  getKeys: asset => {
193
189
  const ident = asset.name;
@@ -199,8 +195,7 @@ const ASSETS_GROUPERS = {
199
195
  groupChildren: false,
200
196
  force: true
201
197
  }),
202
- // @ts-expect-error
203
- createGroup: (key, children, assets) => ({
198
+ createGroup: (_key, children, assets) => ({
204
199
  type: "hidden assets",
205
200
  filteredChildren: assets.length,
206
201
  ...(0, statsFactoryUtils_1.assetGroup)(children)
@@ -209,7 +204,7 @@ const ASSETS_GROUPERS = {
209
204
  }
210
205
  };
211
206
  const MODULES_GROUPERS = (type) => ({
212
- _: (groupConfigs, context, options) => {
207
+ _: (groupConfigs, _context, options) => {
213
208
  const groupByFlag = (name, type, exclude) => {
214
209
  groupConfigs.push({
215
210
  getKeys: module => {
@@ -221,7 +216,6 @@ const MODULES_GROUPERS = (type) => ({
221
216
  force: exclude
222
217
  };
223
218
  },
224
- // @ts-expect-error
225
219
  createGroup: (key, children, modules) => {
226
220
  return {
227
221
  type,
@@ -273,7 +267,6 @@ const MODULES_GROUPERS = (type) => ({
273
267
  force: exclude
274
268
  };
275
269
  },
276
- // @ts-expect-error
277
270
  createGroup: (key, children, modules) => {
278
271
  const exclude = key === "runtime" && !options.runtimeModules;
279
272
  return {
@@ -316,8 +309,7 @@ const MODULES_GROUPERS = (type) => ({
316
309
  }
317
310
  return keys;
318
311
  },
319
- // @ts-expect-error
320
- createGroup: (key, children, modules) => {
312
+ createGroup: (key, children, _modules) => {
321
313
  const isDataUrl = key.startsWith("data:");
322
314
  return {
323
315
  type: isDataUrl
@@ -333,7 +325,7 @@ const MODULES_GROUPERS = (type) => ({
333
325
  });
334
326
  }
335
327
  },
336
- excludeModules: (groupConfigs, context, { excludeModules }) => {
328
+ excludeModules: (groupConfigs, _context, { excludeModules }) => {
337
329
  groupConfigs.push({
338
330
  getKeys: module => {
339
331
  const name = module.name;
@@ -347,8 +339,7 @@ const MODULES_GROUPERS = (type) => ({
347
339
  groupChildren: false,
348
340
  force: true
349
341
  }),
350
- // @ts-expect-error
351
- createGroup: (key, children, modules) => ({
342
+ createGroup: (_key, children, _modules) => ({
352
343
  type: "hidden modules",
353
344
  filteredChildren: children.length,
354
345
  ...(0, statsFactoryUtils_1.moduleGroup)(children)
@@ -374,22 +365,22 @@ const ASSET_SORTERS = {
374
365
  };
375
366
  const RESULT_SORTERS = {
376
367
  "compilation.chunks": {
377
- chunksSort: (comparators, context, { chunksSort }) => {
368
+ chunksSort: (comparators, _context, { chunksSort }) => {
378
369
  comparators.push((0, statsFactoryUtils_1.sortByField)(chunksSort));
379
370
  }
380
371
  },
381
372
  "compilation.modules": {
382
- modulesSort: (comparators, context, { modulesSort }) => {
373
+ modulesSort: (comparators, _context, { modulesSort }) => {
383
374
  comparators.push((0, statsFactoryUtils_1.sortByField)(modulesSort));
384
375
  }
385
376
  },
386
377
  "chunk.modules": {
387
- chunkModulesSort: (comparators, context, { chunkModulesSort }) => {
378
+ chunkModulesSort: (comparators, _context, { chunkModulesSort }) => {
388
379
  comparators.push((0, statsFactoryUtils_1.sortByField)(chunkModulesSort));
389
380
  }
390
381
  },
391
382
  "module.modules": {
392
- nestedModulesSort: (comparators, context, { nestedModulesSort }) => {
383
+ nestedModulesSort: (comparators, _context, { nestedModulesSort }) => {
393
384
  comparators.push((0, statsFactoryUtils_1.sortByField)(nestedModulesSort));
394
385
  }
395
386
  },
@@ -840,7 +831,7 @@ const SIMPLE_EXTRACTORS = {
840
831
  object.auxiliaryChunkIdHints =
841
832
  asset.auxiliaryChunkIdHints.filter(Boolean);
842
833
  },
843
- relatedAssets: (object, asset, context, options, factory) => {
834
+ relatedAssets: (object, asset, context, _options, factory) => {
844
835
  const { type } = context;
845
836
  object.related = factory.create(`${type.slice(0, -8)}.related`, asset.related, context);
846
837
  object.filteredRelated = asset.related
@@ -900,7 +891,7 @@ const SIMPLE_EXTRACTORS = {
900
891
  }
901
892
  },
902
893
  module$visible: {
903
- _: (object, module, context, options, factory) => {
894
+ _: (object, module, context, _options, factory) => {
904
895
  const { type } = context;
905
896
  const { commonAttributes } = module;
906
897
  if (commonAttributes.moduleDescriptor) {
@@ -1008,7 +999,7 @@ const SIMPLE_EXTRACTORS = {
1008
999
  }
1009
1000
  },
1010
1001
  moduleIssuer: {
1011
- _: (object, module, context, options, factory) => {
1002
+ _: (object, module, _context, _options, _factory) => {
1012
1003
  if (module.moduleDescriptor) {
1013
1004
  object.identifier = module.moduleDescriptor.identifier;
1014
1005
  object.name = module.moduleDescriptor.name;
@@ -1077,13 +1068,13 @@ const SIMPLE_EXTRACTORS = {
1077
1068
  object.modules = limited.children;
1078
1069
  object.filteredModules = limited.filteredChildren;
1079
1070
  },
1080
- chunkOrigins: (object, chunk, context, options, factory) => {
1071
+ chunkOrigins: (object, chunk, context, _options, factory) => {
1081
1072
  const { type } = context;
1082
1073
  object.origins = factory.create(`${type}.origins`, chunk.origins, context);
1083
1074
  }
1084
1075
  },
1085
1076
  chunkOrigin: {
1086
- _: (object, origin, context) => {
1077
+ _: (object, origin, _context) => {
1087
1078
  const { moduleDescriptor, loc, request } = origin;
1088
1079
  const statsChunkOrigin = {
1089
1080
  module: moduleDescriptor ? moduleDescriptor.identifier : "",
@@ -1101,7 +1092,7 @@ const SIMPLE_EXTRACTORS = {
1101
1092
  error: EXTRACT_ERROR,
1102
1093
  warning: EXTRACT_ERROR,
1103
1094
  moduleTraceItem: {
1104
- _: (object, { origin, module }, context, { requestShortener }, factory) => {
1095
+ _: (object, { origin, module }, _context, { requestShortener }, _factory) => {
1105
1096
  if (origin.moduleDescriptor) {
1106
1097
  object.originIdentifier = origin.moduleDescriptor.identifier;
1107
1098
  object.originName = origin.moduleDescriptor.name;
@@ -1134,9 +1125,7 @@ const FILTER_RESULTS = {
1134
1125
  class DefaultStatsFactoryPlugin {
1135
1126
  apply(compiler) {
1136
1127
  compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
1137
- compilation.hooks.statsFactory.tap("DefaultStatsFactoryPlugin",
1138
- // @ts-expect-error
1139
- (stats, options, context) => {
1128
+ compilation.hooks.statsFactory.tap("DefaultStatsFactoryPlugin", (stats, options) => {
1140
1129
  (0, statsFactoryUtils_1.iterateConfig)(SIMPLE_EXTRACTORS, options, (hookFor, fn) => {
1141
1130
  stats.hooks.extract
1142
1131
  .for(hookFor)
@@ -1002,8 +1002,8 @@ class DefaultStatsPrinterPlugin {
1002
1002
  start = options.colors[color];
1003
1003
  }
1004
1004
  else {
1005
- // @ts-expect-error
1006
- start = AVAILABLE_COLORS[color];
1005
+ start =
1006
+ AVAILABLE_COLORS[color];
1007
1007
  }
1008
1008
  }
1009
1009
  if (start) {
@@ -1026,9 +1026,7 @@ class DefaultStatsPrinterPlugin {
1026
1026
  for (const key of Object.keys(SIMPLE_PRINTERS)) {
1027
1027
  stats.hooks.print
1028
1028
  .for(key)
1029
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1030
- // @ts-expect-error
1031
- SIMPLE_PRINTERS[key](obj, ctx, stats));
1029
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) => SIMPLE_PRINTERS[key](obj, ctx, stats));
1032
1030
  }
1033
1031
  for (const key of Object.keys(PREFERRED_ORDERS)) {
1034
1032
  const preferredOrder = PREFERRED_ORDERS[key];
@@ -25,7 +25,7 @@ type Hooks = Readonly<{
25
25
  extract: HookMap<SyncBailHook<[Object, any, StatsFactoryContext], undefined>>;
26
26
  filter: HookMap<SyncBailHook<[any, StatsFactoryContext, number, number], undefined>>;
27
27
  filterSorted: HookMap<SyncBailHook<[any, StatsFactoryContext, number, number], undefined>>;
28
- groupResults: HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], undefined>>;
28
+ groupResults: HookMap<SyncBailHook<[GroupConfig<any>[], StatsFactoryContext], undefined>>;
29
29
  filterResults: HookMap<SyncBailHook<[any, StatsFactoryContext, number, number], undefined>>;
30
30
  sort: HookMap<SyncBailHook<[
31
31
  ((arg1: any, arg2: any) => number)[],
@@ -15,10 +15,7 @@ class StatsFactory {
15
15
  filter: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
16
16
  sort: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["comparators", "context"])),
17
17
  filterSorted: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
18
- groupResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
19
- "groupConfigs",
20
- "context"
21
- ])),
18
+ groupResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["groupConfigs", "context"])),
22
19
  sortResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["comparators", "context"])),
23
20
  filterResults: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook(["item", "context", "index", "unfilteredIndex"])),
24
21
  merge: new lite_tapable_1.HookMap(() => new lite_tapable_1.SyncBailHook([
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type * as binding from "@rspack/binding";
3
3
  import type { JsOriginRecord } from "@rspack/binding";
4
- import type { Compilation, NormalizedStatsOptions } from "../Compilation";
4
+ import type { Compilation } from "../Compilation";
5
+ import type { StatsOptions } from "../config";
5
6
  import { type Comparator } from "../util/comparators";
6
7
  import type { StatsFactory, StatsFactoryContext } from "./StatsFactory";
7
8
  export type KnownStatsChunkGroup = {
@@ -258,7 +259,7 @@ export type SimpleExtractors = {
258
259
  };
259
260
  export declare const uniqueArray: <T, I>(items: Iterable<T>, selector: (arg: T) => Iterable<I>) => I[];
260
261
  export declare const uniqueOrderedArray: <T, I>(items: Iterable<T>, selector: (arg: T) => Iterable<I>, comparator: Comparator) => I[];
261
- export declare const iterateConfig: (config: Record<string, Record<string, Function>>, options: NormalizedStatsOptions, fn: (a1: string, a2: Function) => void) => void;
262
+ export declare const iterateConfig: (config: Record<string, Record<string, Function>>, options: StatsOptions, fn: (a1: string, a2: Function) => void) => void;
262
263
  type Child = {
263
264
  children?: ItemChildren;
264
265
  filteredChildren?: number;
@@ -275,7 +276,10 @@ export declare const sortByField: (field: string) => (a1: Object, a2: Object) =>
275
276
  export declare const assetGroup: (children: StatsAsset[]) => {
276
277
  size: number;
277
278
  };
278
- export declare const moduleGroup: (children: KnownStatsModule[]) => {
279
+ export declare const moduleGroup: (children: {
280
+ size: number;
281
+ sizes: Record<string, number>;
282
+ }[]) => {
279
283
  size: number;
280
284
  sizes: Record<string, number>;
281
285
  };
@@ -22,7 +22,9 @@ const iterateConfig = (config, options, fn) => {
22
22
  for (const option of Object.keys(subConfig)) {
23
23
  if (option !== "_") {
24
24
  if (option.startsWith("!")) {
25
- if (options[option.slice(1)])
25
+ if (
26
+ // string cannot be used as key, so use "as"
27
+ options[option.slice(1)])
26
28
  continue;
27
29
  }
28
30
  else {
@@ -157,7 +159,6 @@ const spaceLimited = (itemsAndGroups, max, filteredChildrenLineReserved = false)
157
159
  }
158
160
  for (let i = 0; i < groups.length; i++) {
159
161
  if (groupSizes[i] === maxGroupSize) {
160
- // @ts-expect-error
161
162
  const group = groups[i];
162
163
  // run this algorithm recursively and limit the size of the children to
163
164
  // current size - oversize / number of groups
@@ -226,13 +227,11 @@ const sortOrderRegular = (field) => {
226
227
  };
227
228
  const sortByField = (field) => {
228
229
  if (!field) {
229
- const noSort = (a, b) => 0;
230
+ const noSort = (_a, _b) => 0;
230
231
  return noSort;
231
232
  }
232
233
  const fieldKey = normalizeFieldKey(field);
233
- let sortFn = (0, comparators_1.compareSelect)((m) => m[fieldKey],
234
- // @ts-expect-error
235
- comparators_1.compareIds);
234
+ let sortFn = (0, comparators_1.compareSelect)((m) => m[fieldKey], comparators_1.compareIds);
236
235
  // if a field is prefixed with a "!" the sort is reversed!
237
236
  const sortIsRegular = sortOrderRegular(field);
238
237
  if (!sortIsRegular) {
@@ -12,9 +12,9 @@ import type { ChunkGroup } from "../ChunkGroup";
12
12
  export type Comparator = <T>(arg0: T, arg1: T) => -1 | 0 | 1;
13
13
  type Selector<A, B> = (input: A) => B;
14
14
  export declare const concatComparators: (...comps: Array<Comparator>) => Comparator;
15
- export declare const compareIds: (a: string | number, b: string | number) => -1 | 0 | 1;
15
+ export declare const compareIds: <T = string | number>(a: T, b: T) => -1 | 0 | 1;
16
16
  export declare const compareChunksById: (a: Chunk, b: Chunk) => -1 | 0 | 1;
17
17
  export declare const compareChunkGroupsByIndex: (a: ChunkGroup, b: ChunkGroup) => -1 | 0 | 1;
18
18
  export declare const compareSelect: <T, R>(getter: Selector<T, R>, comparator: Comparator) => Comparator;
19
- export declare const compareNumbers: (a: number, b: number) => 1 | 0 | -1;
19
+ export declare const compareNumbers: (a: number, b: number) => 0 | 1 | -1;
20
20
  export {};
@@ -12,10 +12,10 @@ type GroupOptions = {
12
12
  force?: boolean | undefined;
13
13
  targetGroupCount?: number | undefined;
14
14
  };
15
- export type GroupConfig = {
15
+ export type GroupConfig<T, R = T> = {
16
16
  getKeys: (arg0: any) => string[] | undefined;
17
- createGroup: <T, R>(arg0: string, arg1: (T | R)[], arg2: T[]) => R;
18
- getOptions?: (<T>(arg0: string, arg1: T[]) => GroupOptions) | undefined;
17
+ createGroup: (key: string, arg1: (T | R)[], arg2: T[]) => R;
18
+ getOptions?: ((key: string, arg1: T[]) => GroupOptions) | undefined;
19
19
  };
20
- export declare const smartGrouping: <T, R>(items: T[], groupConfigs: GroupConfig[]) => (T | R)[];
20
+ export declare const smartGrouping: <T, R>(items: T[], groupConfigs: GroupConfig<T, R>[]) => (T | R)[];
21
21
  export {};
@@ -1,18 +1,7 @@
1
- /// <reference types="node" />
2
1
  import type { JsCompatSource } from "@rspack/binding";
3
2
  import { Source } from "../../compiled/webpack-sources";
4
3
  declare class JsSource extends Source {
5
4
  static __from_binding(source: JsCompatSource): Source;
6
- static __to_binding(source: Source): {
7
- source: Buffer;
8
- isRaw: boolean;
9
- isBuffer: boolean;
10
- map?: undefined;
11
- } | {
12
- source: Buffer;
13
- map: Buffer;
14
- isRaw: boolean;
15
- isBuffer: boolean;
16
- };
5
+ static __to_binding(source: Source): JsCompatSource;
17
6
  }
18
7
  export { JsSource };
@@ -2,65 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsSource = void 0;
4
4
  const webpack_sources_1 = require("../../compiled/webpack-sources");
5
- const index_1 = require("./index");
6
5
  class JsSource extends webpack_sources_1.Source {
7
6
  static __from_binding(source) {
8
- if (source.isRaw) {
9
- return new webpack_sources_1.RawSource(
10
- // @ts-expect-error: webpack-sources can accept buffer as source, see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12
11
- source.isBuffer ? source.source : source.source.toString("utf-8"));
7
+ if (source.source instanceof Buffer) {
8
+ // @ts-expect-error: webpack-sources can accept buffer as source,
9
+ // see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12
10
+ return new webpack_sources_1.RawSource(source.source);
12
11
  }
13
12
  if (!source.map) {
14
- return new webpack_sources_1.RawSource(source.source.toString("utf-8"));
13
+ return new webpack_sources_1.RawSource(source.source);
15
14
  }
16
- return new webpack_sources_1.CompatSource({
17
- source() {
18
- return source.source.toString("utf-8");
19
- },
20
- buffer() {
21
- return source.source;
22
- },
23
- map(_) {
24
- if (source.map) {
25
- return JSON.parse(source.map.toString("utf-8"));
26
- }
27
- return null;
28
- }
29
- });
15
+ return new webpack_sources_1.SourceMapSource(source.source, "inmemory://from rust",
16
+ // @ts-expect-error: SourceMapSource can accept string as source map,
17
+ // see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/SourceMapSource.js#L30
18
+ source.map);
30
19
  }
31
20
  static __to_binding(source) {
32
- const sourceSource = source.source();
33
- const isBuffer = Buffer.isBuffer(sourceSource);
34
21
  if (source instanceof webpack_sources_1.RawSource) {
22
+ // @ts-expect-error: The 'isBuffer' method exists on 'RawSource' in 'webpack-sources',
23
+ if (source.isBuffer()) {
24
+ return {
25
+ source: source.buffer()
26
+ };
27
+ }
35
28
  return {
36
- source: source.buffer(),
37
- isRaw: true,
38
- isBuffer
29
+ source: source.source()
39
30
  };
40
31
  }
41
- const buffer = source.buffer?.() ??
42
- (isBuffer
43
- ? sourceSource
44
- : sourceSource instanceof ArrayBuffer
45
- ? arrayBufferToBuffer(sourceSource)
46
- : Buffer.from(sourceSource));
47
32
  const map = JSON.stringify(source.map?.({
48
33
  columns: true
49
34
  }));
35
+ const code = source.source();
50
36
  return {
51
- source: buffer,
52
- map: (0, index_1.isNil)(map) ? map : Buffer.from(map),
53
- isRaw: false,
54
- isBuffer
37
+ source: typeof code === "string" ? code : Buffer.from(code).toString("utf-8"),
38
+ map
55
39
  };
56
40
  }
57
41
  }
58
42
  exports.JsSource = JsSource;
59
- function arrayBufferToBuffer(ab) {
60
- const buf = Buffer.alloc(ab.byteLength);
61
- const view = new Uint8Array(ab);
62
- for (let i = 0; i < buf.length; ++i) {
63
- buf[i] = view[i];
64
- }
65
- return buf;
66
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "The fast Rust-based web bundler with webpack-compatible API",
@@ -60,7 +60,7 @@
60
60
  "@module-federation/runtime-tools": "0.5.1",
61
61
  "@rspack/lite-tapable": "1.0.0",
62
62
  "caniuse-lite": "^1.0.30001616",
63
- "@rspack/binding": "1.0.5"
63
+ "@rspack/binding": "1.0.7"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@swc/helpers": ">=0.5.1"