@rspack/core 0.6.3 → 0.6.4

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.
@@ -67,6 +67,7 @@ const applyRspackOptionsDefaults = (options) => {
67
67
  (Array.isArray(target) &&
68
68
  target.some(target => target.startsWith("browserslist"))),
69
69
  outputModule: options.experiments.outputModule,
70
+ development,
70
71
  entry: options.entry,
71
72
  futureDefaults
72
73
  });
@@ -88,6 +89,7 @@ const applyRspackOptionsDefaults = (options) => {
88
89
  css: options.experiments.css
89
90
  });
90
91
  options.resolve = (0, cleverMerge_1.cleverMerge)(getResolveDefaults({
92
+ context: options.context,
91
93
  targetProperties,
92
94
  mode: options.mode,
93
95
  css: options.experiments.css
@@ -125,15 +127,33 @@ const applyExperimentsDefaults = (experiments, { cache }) => {
125
127
  }
126
128
  };
127
129
  const applySnapshotDefaults = (snapshot, { production }) => {
128
- F(snapshot, "module", () => production
129
- ? { timestamp: true, hash: true }
130
- : { timestamp: true, hash: false });
131
- F(snapshot, "resolve", () => production
132
- ? { timestamp: true, hash: true }
133
- : { timestamp: true, hash: false });
130
+ if (typeof snapshot.module === "object") {
131
+ D(snapshot.module, "timestamp", false);
132
+ D(snapshot.module, "hash", false);
133
+ }
134
+ else {
135
+ F(snapshot, "module", () => production
136
+ ? { timestamp: true, hash: true }
137
+ : { timestamp: true, hash: false });
138
+ }
139
+ if (typeof snapshot.resolve === "object") {
140
+ D(snapshot.resolve, "timestamp", false);
141
+ D(snapshot.resolve, "hash", false);
142
+ }
143
+ else {
144
+ F(snapshot, "resolve", () => production
145
+ ? { timestamp: true, hash: true }
146
+ : { timestamp: true, hash: false });
147
+ }
134
148
  };
135
- const applyJavascriptParserOptionsDefaults = (parserOptions) => {
136
- D(parserOptions, "dynamicImportMode", "lazy");
149
+ const applyJavascriptParserOptionsDefaults = (parserOptions, fallback) => {
150
+ var _a, _b, _c, _d, _e, _f;
151
+ D(parserOptions, "dynamicImportMode", (_a = fallback === null || fallback === void 0 ? void 0 : fallback.dynamicImportMode) !== null && _a !== void 0 ? _a : "lazy");
152
+ D(parserOptions, "dynamicImportPrefetch", (_b = fallback === null || fallback === void 0 ? void 0 : fallback.dynamicImportPrefetch) !== null && _b !== void 0 ? _b : false);
153
+ D(parserOptions, "dynamicImportPreload", (_c = fallback === null || fallback === void 0 ? void 0 : fallback.dynamicImportPreload) !== null && _c !== void 0 ? _c : false);
154
+ D(parserOptions, "url", (_d = fallback === null || fallback === void 0 ? void 0 : fallback.url) !== null && _d !== void 0 ? _d : true);
155
+ D(parserOptions, "exprContextCritical", (_e = fallback === null || fallback === void 0 ? void 0 : fallback.exprContextCritical) !== null && _e !== void 0 ? _e : true);
156
+ D(parserOptions, "wrappedContextCritical", (_f = fallback === null || fallback === void 0 ? void 0 : fallback.wrappedContextCritical) !== null && _f !== void 0 ? _f : false);
137
157
  };
138
158
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
139
159
  (0, assertNotNil_1.assertNotNill)(module.parser);
@@ -147,6 +167,15 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }
147
167
  F(module.parser, "javascript", () => ({}));
148
168
  (0, assertNotNil_1.assertNotNill)(module.parser.javascript);
149
169
  applyJavascriptParserOptionsDefaults(module.parser.javascript);
170
+ F(module.parser, "javascript/auto", () => ({}));
171
+ (0, assertNotNil_1.assertNotNill)(module.parser["javascript/auto"]);
172
+ applyJavascriptParserOptionsDefaults(module.parser["javascript/auto"], module.parser.javascript);
173
+ F(module.parser, "javascript/dynamic", () => ({}));
174
+ (0, assertNotNil_1.assertNotNill)(module.parser["javascript/dynamic"]);
175
+ applyJavascriptParserOptionsDefaults(module.parser["javascript/dynamic"], module.parser.javascript);
176
+ F(module.parser, "javascript/esm", () => ({}));
177
+ (0, assertNotNil_1.assertNotNill)(module.parser["javascript/esm"]);
178
+ applyJavascriptParserOptionsDefaults(module.parser["javascript/esm"], module.parser.javascript);
150
179
  if (css) {
151
180
  F(module.parser, "css", () => ({}));
152
181
  (0, assertNotNil_1.assertNotNill)(module.parser.css);
@@ -287,7 +316,7 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }
287
316
  return rules;
288
317
  });
289
318
  };
290
- const applyOutputDefaults = (output, { context, outputModule, targetProperties: tp, isAffectedByBrowserslist, entry, futureDefaults }) => {
319
+ const applyOutputDefaults = (output, { context, outputModule, targetProperties: tp, isAffectedByBrowserslist, development, entry, futureDefaults }) => {
291
320
  const getLibraryName = (library) => {
292
321
  const libraryName = typeof library === "object" &&
293
322
  library &&
@@ -371,6 +400,7 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
371
400
  D(output, "assetModuleFilename", "[hash][ext][query]");
372
401
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
373
402
  F(output, "path", () => path_1.default.join(process.cwd(), "dist"));
403
+ F(output, "pathinfo", () => development);
374
404
  D(output, "publicPath", tp && (tp.document || tp.importScripts) ? "auto" : "");
375
405
  D(output, "hashFunction", futureDefaults ? "xxhash64" : "md4");
376
406
  D(output, "hashDigest", "hex");
@@ -502,6 +532,9 @@ const applyOutputDefaults = (output, { context, outputModule, targetProperties:
502
532
  F(trustedTypes, "policyName", () => output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack");
503
533
  }
504
534
  const forEachEntry = (fn) => {
535
+ if (typeof entry === "function") {
536
+ return;
537
+ }
505
538
  for (const name of Object.keys(entry)) {
506
539
  fn(entry[name]);
507
540
  }
@@ -660,7 +693,7 @@ const getResolveLoaderDefaults = () => {
660
693
  };
661
694
  // The values are aligned with webpack
662
695
  // https://github.com/webpack/webpack/blob/b9fb99c63ca433b24233e0bbc9ce336b47872c08/lib/config/defaults.js#L1431
663
- const getResolveDefaults = ({ targetProperties, mode, css }) => {
696
+ const getResolveDefaults = ({ context, targetProperties, mode, css }) => {
664
697
  const conditions = ["webpack"];
665
698
  conditions.push(mode === "development" ? "development" : "production");
666
699
  if (targetProperties) {
@@ -701,6 +734,7 @@ const getResolveDefaults = ({ targetProperties, mode, css }) => {
701
734
  extensions: [],
702
735
  aliasFields: [],
703
736
  exportsFields: ["exports"],
737
+ roots: [context],
704
738
  mainFields: ["main"],
705
739
  byDependency: {
706
740
  wasm: esmDeps(),
@@ -10,7 +10,8 @@
10
10
  import type { Compilation } from "../Compilation";
11
11
  import type { Context, Dependencies, Node, DevTool, Externals, ExternalsPresets, ExternalsType, InfrastructureLogging, LibraryOptions, Mode, Name, Resolve, Target, SnapshotOptions, CacheOptions, StatsValue, Optimization, Plugins, Watch, WatchOptions, DevServer, Profile, Bail, Builtins, EntryRuntime, ChunkLoading, PublicPath, EntryFilename, Path, Clean, Filename, ChunkFilename, CrossOriginLoading, CssFilename, CssChunkFilename, HotUpdateMainFilename, HotUpdateChunkFilename, AssetModuleFilename, UniqueName, ChunkLoadingGlobal, EnabledLibraryTypes, OutputModule, StrictModuleErrorHandling, GlobalObject, ImportFunctionName, Iife, WasmLoading, EnabledWasmLoadingTypes, WebassemblyModuleFilename, TrustedTypes, SourceMapFilename, HashDigest, HashDigestLength, HashFunction, HashSalt, WorkerPublicPath, RuleSetRules, ParserOptionsByModuleType, GeneratorOptionsByModuleType, RspackFutureOptions, HotUpdateGlobal, ScriptType, NoParseOption, DevtoolNamespace, DevtoolModuleFilenameTemplate, DevtoolFallbackModuleFilenameTemplate, RspackOptions } from "./zod";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
- export type EntryNormalized = EntryStaticNormalized;
13
+ export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
+ export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
14
15
  export interface EntryStaticNormalized {
15
16
  [k: string]: EntryDescriptionNormalized;
16
17
  }
@@ -27,6 +28,7 @@ export interface EntryDescriptionNormalized {
27
28
  }
28
29
  export interface OutputNormalized {
29
30
  path?: Path;
31
+ pathinfo?: boolean | "verbose";
30
32
  clean?: Clean;
31
33
  publicPath?: PublicPath;
32
34
  filename?: Filename;
@@ -87,7 +89,9 @@ export interface ExperimentsNormalized {
87
89
  }
88
90
  export type IgnoreWarningsNormalized = ((warning: Error, compilation: Compilation) => boolean)[];
89
91
  export type OptimizationRuntimeChunkNormalized = false | {
90
- name: (...args: any[]) => string | undefined;
92
+ name: string | ((entrypoint: {
93
+ name: string;
94
+ }) => string);
91
95
  };
92
96
  export interface RspackOptionsNormalized {
93
97
  name?: Name;
@@ -30,7 +30,9 @@ const getNormalizedRspackOptions = (config) => {
30
30
  mode: config.mode,
31
31
  entry: config.entry === undefined
32
32
  ? { main: {} }
33
- : getNormalizedEntryStatic(typeof config.entry === "function" ? config.entry() : config.entry),
33
+ : typeof config.entry === "function"
34
+ ? (fn => () => Promise.resolve().then(fn).then(getNormalizedEntryStatic))(config.entry)
35
+ : getNormalizedEntryStatic(config.entry),
34
36
  output: nestedConfig(config.output, output => {
35
37
  var _a;
36
38
  const { library } = output;
@@ -47,6 +49,7 @@ const getNormalizedRspackOptions = (config) => {
47
49
  : undefined;
48
50
  return {
49
51
  path: output.path,
52
+ pathinfo: output.pathinfo,
50
53
  publicPath: output.publicPath,
51
54
  filename: output.filename,
52
55
  clean: output.clean,
@@ -254,19 +257,20 @@ const getNormalizedOptimizationRuntimeChunk = (runtimeChunk) => {
254
257
  return false;
255
258
  if (runtimeChunk === "single") {
256
259
  return {
257
- name: () => "runtime"
260
+ name: "single"
258
261
  };
259
262
  }
260
263
  if (runtimeChunk === true || runtimeChunk === "multiple") {
261
264
  return {
262
- name: (entrypoint) => `runtime~${entrypoint.name}`
265
+ name: "multiple"
263
266
  };
264
267
  }
265
- const { name } = runtimeChunk;
266
- const opts = {
267
- name: typeof name === "function" ? name : () => name
268
- };
269
- return opts;
268
+ if (runtimeChunk.name) {
269
+ const opts = {
270
+ name: runtimeChunk.name
271
+ };
272
+ return opts;
273
+ }
270
274
  };
271
275
  const nestedConfig = (value, fn) => value === undefined ? fn({}) : fn(value);
272
276
  const optionalNestedConfig = (value, fn) => (value === undefined ? undefined : fn(value));