@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
@@ -468,18 +468,14 @@ function getRawParserOptions(parser, type) {
468
468
  }
469
469
  function getRawJavascriptParserOptions(parser) {
470
470
  return {
471
- dynamicImportMode: parser.dynamicImportMode ?? "lazy",
472
- dynamicImportPreload: parser.dynamicImportPreload?.toString() ?? "false",
473
- dynamicImportPrefetch: parser.dynamicImportPrefetch?.toString() ?? "false",
474
- dynamicImportFetchPriority: parser.dynamicImportFetchPriority?.toString(),
475
- importMeta: parser.importMeta ?? true,
476
- url: parser.url === false
477
- ? "false"
478
- : parser.url === "relative"
479
- ? parser.url
480
- : "true",
481
- exprContextCritical: parser.exprContextCritical ?? true,
482
- wrappedContextCritical: parser.wrappedContextCritical ?? false,
471
+ dynamicImportMode: parser.dynamicImportMode,
472
+ dynamicImportPreload: parser.dynamicImportPreload?.toString(),
473
+ dynamicImportPrefetch: parser.dynamicImportPrefetch?.toString(),
474
+ dynamicImportFetchPriority: parser.dynamicImportFetchPriority,
475
+ importMeta: parser.importMeta,
476
+ url: parser.url?.toString(),
477
+ exprContextCritical: parser.exprContextCritical,
478
+ wrappedContextCritical: parser.wrappedContextCritical,
483
479
  exportsPresence: parser.exportsPresence === false ? "false" : parser.exportsPresence,
484
480
  importExportsPresence: parser.importExportsPresence === false
485
481
  ? "false"
@@ -487,12 +483,12 @@ function getRawJavascriptParserOptions(parser) {
487
483
  reexportExportsPresence: parser.reexportExportsPresence === false
488
484
  ? "false"
489
485
  : parser.reexportExportsPresence,
490
- strictExportPresence: parser.strictExportPresence ?? false,
486
+ strictExportPresence: parser.strictExportPresence,
491
487
  worker: typeof parser.worker === "boolean"
492
488
  ? parser.worker
493
489
  ? ["..."]
494
490
  : []
495
- : parser.worker ?? ["..."],
491
+ : parser.worker,
496
492
  overrideStrict: parser.overrideStrict
497
493
  };
498
494
  }
@@ -639,19 +635,35 @@ function getRawSnapshotOptions(_snapshot) {
639
635
  return {};
640
636
  }
641
637
  function getRawExperiments(experiments) {
642
- const { topLevelAwait, layers, rspackFuture } = experiments;
643
- (0, node_assert_1.default)(!(0, util_1.isNil)(topLevelAwait) && !(0, util_1.isNil)(rspackFuture) && !(0, util_1.isNil)(layers));
638
+ const { topLevelAwait, layers, incremental, rspackFuture } = experiments;
639
+ (0, node_assert_1.default)(!(0, util_1.isNil)(topLevelAwait) &&
640
+ !(0, util_1.isNil)(rspackFuture) &&
641
+ !(0, util_1.isNil)(layers) &&
642
+ !(0, util_1.isNil)(incremental));
644
643
  return {
645
644
  layers,
646
645
  topLevelAwait,
646
+ incremental: getRawIncremental(incremental),
647
647
  rspackFuture: getRawRspackFutureOptions(rspackFuture)
648
648
  };
649
649
  }
650
- function getRawRspackFutureOptions(future) {
650
+ function getRawIncremental(incremental) {
651
+ if (incremental === false) {
652
+ return undefined;
653
+ }
651
654
  return {
652
- newIncremental: future.newIncremental
655
+ make: incremental.make,
656
+ emitAssets: incremental.emitAssets,
657
+ inferAsyncModules: incremental.inferAsyncModules,
658
+ providedExports: incremental.providedExports,
659
+ moduleHashes: incremental.moduleHashes,
660
+ moduleCodegen: incremental.moduleCodegen,
661
+ moduleRuntimeRequirements: incremental.moduleRuntimeRequirements
653
662
  };
654
663
  }
664
+ function getRawRspackFutureOptions(future) {
665
+ return {};
666
+ }
655
667
  function getRawNode(node) {
656
668
  if (node === false) {
657
669
  return undefined;
@@ -28,14 +28,45 @@ export interface SourceMap {
28
28
  export interface AdditionalData {
29
29
  [index: string]: any;
30
30
  }
31
+ export type LoaderContextCallback = (err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
32
+ export type ErrorWithDetails = Error & {
33
+ details?: string;
34
+ };
35
+ export type ResolveCallback = (err: null | ErrorWithDetails, res?: string | false, req?: ResolveRequest) => void;
36
+ export interface DiagnosticLocation {
37
+ /** Text for highlighting the location */
38
+ text?: string;
39
+ /** 1-based line */
40
+ line: number;
41
+ /** 0-based column in bytes */
42
+ column: number;
43
+ /** Length in bytes */
44
+ length: number;
45
+ }
46
+ export interface Diagnostic {
47
+ message: string;
48
+ help?: string;
49
+ sourceCode?: string;
50
+ /**
51
+ * Location to the source code.
52
+ *
53
+ * If `sourceCode` is not provided, location will be omitted.
54
+ */
55
+ location?: DiagnosticLocation;
56
+ file?: string;
57
+ severity: "error" | "warning";
58
+ }
59
+ interface LoaderExperiments {
60
+ emitDiagnostic(diagnostic: Diagnostic): void;
61
+ }
31
62
  export interface LoaderContext<OptionsType = {}> {
32
63
  version: 2;
33
64
  resource: string;
34
65
  resourcePath: string;
35
66
  resourceQuery: string;
36
67
  resourceFragment: string;
37
- async(): (err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
38
- callback(err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData): void;
68
+ async(): LoaderContextCallback;
69
+ callback: LoaderContextCallback;
39
70
  cacheable(cacheable?: boolean): void;
40
71
  sourceMap: boolean;
41
72
  rootContext: string;
@@ -72,7 +103,7 @@ export interface LoaderContext<OptionsType = {}> {
72
103
  */
73
104
  getOptions(schema?: any): OptionsType;
74
105
  resolve(context: string, request: string, callback: (arg0: null | Error, arg1?: string | false, arg2?: ResolveRequest) => void): void;
75
- getResolve(options: Resolve): (context: any, request: any, callback: any) => Promise<any>;
106
+ getResolve(options: Resolve): ((context: string, request: string, callback: ResolveCallback) => void) | ((context: string, request: string) => Promise<string | false | undefined>);
76
107
  getLogger(name: string): Logger;
77
108
  emitError(error: Error): void;
78
109
  emitWarning(warning: Error): void;
@@ -92,6 +123,11 @@ export interface LoaderContext<OptionsType = {}> {
92
123
  baseUri?: string;
93
124
  }, callback: (err?: Error, res?: any) => void): void;
94
125
  fs: any;
126
+ /**
127
+ * This is an experimental API and maybe subject to change.
128
+ * @experimental
129
+ */
130
+ experiments: LoaderExperiments;
95
131
  utils: {
96
132
  absolutify: (context: string, request: string) => string;
97
133
  contextify: (context: string, request: string) => string;
@@ -119,3 +155,4 @@ export type LoaderDefinition<OptionsType = {}, ContextAdditions = {}> = LoaderDe
119
155
  export declare function createRawModuleRuleUses(uses: RuleSetUseItem | RuleSetUseItem[], path: string, options: ComposeJsUseOptions): RawModuleRuleUse[];
120
156
  export declare function isUseSourceMap(devtool: RawOptions["devtool"]): boolean;
121
157
  export declare function isUseSimpleSourceMap(devtool: RawOptions["devtool"]): boolean;
158
+ export {};
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.resolve = exports.load = void 0;
16
16
  const node_path_1 = __importDefault(require("node:path"));
17
- const browserslist_1 = __importDefault(require("../../compiled/browserslist"));
18
17
  // [[C:]/path/to/config][:env]
19
18
  const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
20
19
  /**
@@ -30,7 +29,8 @@ const parse = (input, context) => {
30
29
  const [, configPath, env] = inputRx.exec(input) || [];
31
30
  return { configPath, env };
32
31
  }
33
- const config = browserslist_1.default.findConfig(context);
32
+ const browserslist = require("../../compiled/browserslist");
33
+ const config = browserslist.findConfig(context);
34
34
  if (config && Object.keys(config).includes(input)) {
35
35
  return { env: input };
36
36
  }
@@ -42,6 +42,7 @@ const parse = (input, context) => {
42
42
  * @returns selected browsers
43
43
  */
44
44
  const load = (input, context) => {
45
+ const browserslist = require("../../compiled/browserslist");
45
46
  const { configPath, env, query } = parse(input, context);
46
47
  // if a query is specified, then use it, else
47
48
  // if a path to a config is specified then load it, else
@@ -49,14 +50,14 @@ const load = (input, context) => {
49
50
  const config = query
50
51
  ? query
51
52
  : configPath
52
- ? browserslist_1.default.loadConfig({
53
+ ? browserslist.loadConfig({
53
54
  config: configPath,
54
55
  env
55
56
  })
56
- : browserslist_1.default.loadConfig({ path: context, env });
57
+ : browserslist.loadConfig({ path: context, env });
57
58
  if (!config)
58
59
  return;
59
- return (0, browserslist_1.default)(config);
60
+ return browserslist(config);
60
61
  };
61
62
  exports.load = load;
62
63
  /**
@@ -133,12 +133,20 @@ const applyExperimentsDefaults = (experiments) => {
133
133
  D(experiments, "css", experiments.futureDefaults ? true : undefined);
134
134
  D(experiments, "layers", false);
135
135
  D(experiments, "topLevelAwait", true);
136
+ // IGNORE(experiments.incremental): Rspack specific configuration for incremental
137
+ D(experiments, "incremental", {});
138
+ if (typeof experiments.incremental === "object") {
139
+ D(experiments.incremental, "make", true);
140
+ D(experiments.incremental, "emitAssets", true);
141
+ D(experiments.incremental, "inferAsyncModules", false);
142
+ D(experiments.incremental, "providedExports", false);
143
+ D(experiments.incremental, "moduleHashes", false);
144
+ D(experiments.incremental, "moduleCodegen", false);
145
+ D(experiments.incremental, "moduleRuntimeRequirements", false);
146
+ }
136
147
  // IGNORE(experiments.rspackFuture): Rspack specific configuration
137
148
  D(experiments, "rspackFuture", {});
138
149
  // rspackFuture.bundlerInfo default value is applied after applyDefaults
139
- if (typeof experiments.rspackFuture === "object") {
140
- D(experiments.rspackFuture, "newIncremental", false);
141
- }
142
150
  };
143
151
  const applybundlerInfoDefaults = (rspackFuture, library) => {
144
152
  if (typeof rspackFuture === "object") {
@@ -159,12 +167,8 @@ const applyJavascriptParserOptionsDefaults = (parserOptions) => {
159
167
  D(parserOptions, "url", true);
160
168
  D(parserOptions, "exprContextCritical", true);
161
169
  D(parserOptions, "wrappedContextCritical", false);
162
- D(parserOptions, "exportsPresence", undefined);
163
- D(parserOptions, "importExportsPresence", undefined);
164
- D(parserOptions, "reexportExportsPresence", undefined);
165
170
  D(parserOptions, "strictExportPresence", false);
166
171
  D(parserOptions, "worker", ["..."]);
167
- D(parserOptions, "overrideStrict", undefined);
168
172
  D(parserOptions, "importMeta", true);
169
173
  };
170
174
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type { Compilation } from "../Compilation";
11
- import type { AssetModuleFilename, AsyncChunks, Bail, BaseUri, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, ImportMetaName, InfrastructureLogging, Layer, LazyCompilationOptions, LibraryOptions, Loader, Mode, Name, NoParseOption, Node, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
11
+ import type { AssetModuleFilename, AsyncChunks, Bail, BaseUri, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, ImportMetaName, Incremental, InfrastructureLogging, Layer, LazyCompilationOptions, LibraryOptions, Loader, Mode, Name, NoParseOption, Node, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
13
  export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
14
  export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
@@ -90,6 +90,7 @@ export interface ExperimentsNormalized {
90
90
  topLevelAwait?: boolean;
91
91
  css?: boolean;
92
92
  layers?: boolean;
93
+ incremental?: false | Incremental;
93
94
  futureDefaults?: boolean;
94
95
  rspackFuture?: RspackFutureOptions;
95
96
  }
@@ -194,7 +194,8 @@ const getNormalizedRspackOptions = (config) => {
194
194
  plugins: nestedArray(config.plugins, p => [...p]),
195
195
  experiments: nestedConfig(config.experiments, experiments => ({
196
196
  ...experiments,
197
- lazyCompilation: optionalNestedConfig(experiments.lazyCompilation, options => (options === true ? {} : options))
197
+ lazyCompilation: optionalNestedConfig(experiments.lazyCompilation, options => (options === true ? {} : options)),
198
+ incremental: optionalNestedConfig(experiments.incremental, options => options === true ? {} : options)
198
199
  })),
199
200
  watch: config.watch,
200
201
  watchOptions: cloneObject(config.watchOptions),