@rspack/core 0.7.6-canary-1a0d77d-20240627143904 → 1.0.0-alpha.1

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 (87) hide show
  1. package/README.md +2 -2
  2. package/compiled/enhanced-resolve/index.js +11 -11
  3. package/compiled/webpack-sources/index.d.ts +130 -0
  4. package/compiled/webpack-sources/index.js +3520 -0
  5. package/compiled/webpack-sources/license +21 -0
  6. package/compiled/webpack-sources/package.json +1 -0
  7. package/dist/Chunk.d.ts +19 -14
  8. package/dist/Chunk.js +22 -17
  9. package/dist/ChunkGraph.d.ts +1 -1
  10. package/dist/ChunkGraph.js +5 -5
  11. package/dist/ChunkGroup.d.ts +17 -7
  12. package/dist/ChunkGroup.js +12 -2
  13. package/dist/Compilation.d.ts +31 -33
  14. package/dist/Compilation.js +33 -53
  15. package/dist/Compiler.d.ts +26 -28
  16. package/dist/Compiler.js +74 -26
  17. package/dist/ContextModuleFactory.d.ts +1 -1
  18. package/dist/ContextModuleFactory.js +1 -1
  19. package/dist/Entrypoint.d.ts +1 -1
  20. package/dist/Entrypoint.js +2 -2
  21. package/dist/Module.d.ts +12 -7
  22. package/dist/Module.js +1 -0
  23. package/dist/MultiCompiler.d.ts +11 -11
  24. package/dist/MultiCompiler.js +30 -13
  25. package/dist/NormalModule.d.ts +7 -4
  26. package/dist/NormalModule.js +27 -11
  27. package/dist/NormalModuleFactory.d.ts +3 -1
  28. package/dist/NormalModuleFactory.js +3 -23
  29. package/dist/ResolverFactory.d.ts +3 -3
  30. package/dist/ResolverFactory.js +1 -1
  31. package/dist/RspackError.d.ts +8 -0
  32. package/dist/RspackError.js +21 -0
  33. package/dist/Stats.d.ts +4 -2
  34. package/dist/Stats.js +6 -0
  35. package/dist/Template.d.ts +1 -1
  36. package/dist/Template.js +2 -2
  37. package/dist/Watching.d.ts +1 -1
  38. package/dist/builtin-loader/swc/index.d.ts +0 -4
  39. package/dist/builtin-loader/swc/index.js +1 -5
  40. package/dist/builtin-loader/swc/preact.d.ts +3 -4
  41. package/dist/builtin-loader/swc/types.d.ts +2 -17
  42. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -0
  43. package/dist/builtin-plugin/BundlerInfoRspackPlugin.js +1 -0
  44. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/JavascriptModulesPlugin.js +1 -1
  46. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +1 -1
  47. package/dist/builtin-plugin/SplitChunksPlugin.js +11 -2
  48. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +0 -28
  49. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +20 -69
  50. package/dist/builtin-plugin/css-extract/index.d.ts +2 -2
  51. package/dist/config/adapter.js +30 -16
  52. package/dist/config/adapterRuleUse.js +0 -11
  53. package/dist/config/defaults.js +22 -30
  54. package/dist/config/normalization.js +13 -5
  55. package/dist/config/zod.d.ts +753 -205
  56. package/dist/config/zod.js +27 -13
  57. package/dist/container/ModuleFederationPlugin.js +1 -1
  58. package/dist/container/default.runtime.js +1 -170
  59. package/dist/exports.d.ts +9 -2
  60. package/dist/exports.js +11 -6
  61. package/dist/lib/Cache.d.ts +3 -3
  62. package/dist/lib/Cache.js +1 -1
  63. package/dist/loader-runner/index.js +37 -12
  64. package/dist/rspack.d.ts +1 -1
  65. package/dist/rspackOptionsApply.js +3 -0
  66. package/dist/stats/DefaultStatsFactoryPlugin.js +35 -11
  67. package/dist/stats/DefaultStatsPrinterPlugin.js +2 -2
  68. package/dist/stats/StatsFactory.d.ts +2 -2
  69. package/dist/stats/StatsFactory.js +12 -12
  70. package/dist/stats/StatsPrinter.d.ts +1 -1
  71. package/dist/stats/StatsPrinter.js +8 -8
  72. package/dist/stats/statsFactoryUtils.d.ts +13 -4
  73. package/dist/util/SplitChunkSize.d.ts +5 -0
  74. package/dist/util/SplitChunkSize.js +18 -0
  75. package/dist/util/index.d.ts +2 -2
  76. package/dist/util/index.js +4 -3
  77. package/dist/util/memoize.js +5 -1
  78. package/dist/util/source.d.ts +1 -1
  79. package/dist/util/source.js +1 -1
  80. package/package.json +14 -9
  81. package/dist/builtin-loader/swc/emotion.d.ts +0 -17
  82. package/dist/builtin-loader/swc/emotion.js +0 -22
  83. package/dist/builtin-loader/swc/relay.d.ts +0 -5
  84. package/dist/builtin-loader/swc/relay.js +0 -48
  85. package/dist/container/default.runtime.d.ts +0 -2
  86. package/dist/lite-tapable/index.d.ts +0 -146
  87. package/dist/lite-tapable/index.js +0 -752
@@ -24,13 +24,13 @@ declare class ResolverFactory {
24
24
  declare namespace ResolverFactory {
25
25
  export { ResolveOptions, Resolver, WebpackResolveOptions, ResolvePluginInstance, ResolveOptionsWithDependencyType, WithOptions, ResolverWithOptions, ResolverCache };
26
26
  }
27
- import { HookMap } from "tapable";
28
- import { SyncWaterfallHook } from "tapable";
27
+ import { HookMap } from "@rspack/lite-tapable";
28
+ import { SyncWaterfallHook } from "@rspack/lite-tapable";
29
29
  type ResolveOptionsWithDependencyType = WebpackResolveOptions & {
30
30
  dependencyType?: string;
31
31
  resolveToContext?: boolean;
32
32
  };
33
- import { SyncHook } from "tapable";
33
+ import { SyncHook } from "@rspack/lite-tapable";
34
34
  type Resolver = import("../compiled/enhanced-resolve").Resolver;
35
35
  type ResolveOptions = import("../compiled/enhanced-resolve").ResolveOptions;
36
36
  type ResolverCache = {
@@ -9,7 +9,7 @@
9
9
  */
10
10
  "use strict";
11
11
  const Factory = require("../compiled/enhanced-resolve").ResolverFactory;
12
- const { HookMap, SyncHook, SyncWaterfallHook } = require("tapable");
12
+ const { HookMap, SyncHook, SyncWaterfallHook } = require("@rspack/lite-tapable");
13
13
  const { cachedCleverMerge, removeOperations, resolveByProperty } = require("./util/cleverMerge");
14
14
  /** @typedef {import("../compiled/enhanced-resolve").ResolveOptions} ResolveOptions */
15
15
  /** @typedef {import("../compiled/enhanced-resolve").Resolver} Resolver */
@@ -0,0 +1,8 @@
1
+ import * as binding from "@rspack/binding";
2
+ export type RspackError = binding.JsRspackError;
3
+ export declare class JsDiagnostic {
4
+ static __to_binding(error: Error | RspackError, severity: binding.JsRspackSeverity): binding.JsDiagnostic;
5
+ }
6
+ export declare class NonErrorEmittedError extends Error {
7
+ constructor(error: Error);
8
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NonErrorEmittedError = exports.JsDiagnostic = void 0;
4
+ const util_1 = require("./util");
5
+ class JsDiagnostic {
6
+ static __to_binding(error, severity) {
7
+ return {
8
+ error: (0, util_1.concatErrorMsgAndStack)(error),
9
+ severity
10
+ };
11
+ }
12
+ }
13
+ exports.JsDiagnostic = JsDiagnostic;
14
+ class NonErrorEmittedError extends Error {
15
+ constructor(error) {
16
+ super();
17
+ this.name = "NonErrorEmittedError";
18
+ this.message = "(Emitted value instead of an instance of Error) " + error;
19
+ }
20
+ }
21
+ exports.NonErrorEmittedError = NonErrorEmittedError;
package/dist/Stats.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Compilation } from ".";
1
+ import { Compilation } from "./Compilation";
2
2
  import { StatsOptions, StatsValue } from "./config";
3
3
  import type { StatsCompilation } from "./stats/statsFactoryUtils";
4
4
  export type { StatsAsset, StatsChunk, StatsCompilation, StatsError, StatsModule, StatsWarnings } from "./stats/statsFactoryUtils";
@@ -6,7 +6,9 @@ export declare class Stats {
6
6
  #private;
7
7
  compilation: Compilation;
8
8
  constructor(compilation: Compilation);
9
- get hash(): string | null;
9
+ get hash(): Readonly<string | null>;
10
+ get startTime(): number | undefined;
11
+ get endTime(): number | undefined;
10
12
  hasErrors(): boolean;
11
13
  hasWarnings(): boolean;
12
14
  toJson(opts?: StatsValue, forToString?: boolean): StatsCompilation;
package/dist/Stats.js CHANGED
@@ -25,6 +25,12 @@ class Stats {
25
25
  get hash() {
26
26
  return this.compilation.hash;
27
27
  }
28
+ get startTime() {
29
+ return this.compilation.startTime;
30
+ }
31
+ get endTime() {
32
+ return this.compilation.endTime;
33
+ }
28
34
  hasErrors() {
29
35
  return __classPrivateFieldGet(this, _Stats_inner, "f").getErrors().length > 0;
30
36
  }
@@ -137,7 +137,7 @@ declare namespace Template {
137
137
  }
138
138
  type ChunkRenderContext = any;
139
139
  type Module = any;
140
- type Source = import("webpack-sources").Source;
140
+ type Source = import("../compiled/webpack-sources").Source;
141
141
  type RuntimeModule = any;
142
142
  type RenderContext = any;
143
143
  type CodeGenerationResults = any;
package/dist/Template.js CHANGED
@@ -3,10 +3,10 @@
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
5
  "use strict";
6
- const { ConcatSource, PrefixSource } = require("webpack-sources");
6
+ const { ConcatSource, PrefixSource } = require("../compiled/webpack-sources");
7
7
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
8
8
  const RuntimeGlobals = require("./RuntimeGlobals");
9
- /** @typedef {import("webpack-sources").Source} Source */
9
+ /** @typedef {import("../compiled/webpack-sources").Source} Source */
10
10
  // /** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
11
11
  /** @typedef {any} OutputOptions */
12
12
  // /** @typedef {import("./Chunk")} Chunk */
@@ -1,4 +1,4 @@
1
- import { Callback } from "tapable";
1
+ import { Callback } from "@rspack/lite-tapable";
2
2
  import type { Compiler } from ".";
3
3
  import { Stats } from ".";
4
4
  import { WatchOptions } from "./config";
@@ -1,11 +1,7 @@
1
- export type { EmotionOptions } from "./emotion";
2
- export { resolveEmotion } from "./emotion";
3
1
  export { resolvePluginImport } from "./pluginImport";
4
2
  export type { PluginImportOptions } from "./pluginImport";
5
3
  export type { ReactOptions } from "./react";
6
4
  export { resolveReact } from "./react";
7
5
  export { resolvePreact } from "./preact";
8
6
  export type { PreactOptions } from "./preact";
9
- export type { RelayOptions } from "./relay";
10
- export { resolveRelay } from "./relay";
11
7
  export type { SwcLoaderEnvConfig, SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, SwcLoaderOptions, SwcLoaderParserConfig, SwcLoaderTransformConfig, SwcLoaderTsParserConfig } from "./types";
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveRelay = exports.resolvePreact = exports.resolveReact = exports.resolvePluginImport = exports.resolveEmotion = void 0;
4
- var emotion_1 = require("./emotion");
5
- Object.defineProperty(exports, "resolveEmotion", { enumerable: true, get: function () { return emotion_1.resolveEmotion; } });
3
+ exports.resolvePreact = exports.resolveReact = exports.resolvePluginImport = void 0;
6
4
  var pluginImport_1 = require("./pluginImport");
7
5
  Object.defineProperty(exports, "resolvePluginImport", { enumerable: true, get: function () { return pluginImport_1.resolvePluginImport; } });
8
6
  var react_1 = require("./react");
9
7
  Object.defineProperty(exports, "resolveReact", { enumerable: true, get: function () { return react_1.resolveReact; } });
10
8
  var preact_1 = require("./preact");
11
9
  Object.defineProperty(exports, "resolvePreact", { enumerable: true, get: function () { return preact_1.resolvePreact; } });
12
- var relay_1 = require("./relay");
13
- Object.defineProperty(exports, "resolveRelay", { enumerable: true, get: function () { return relay_1.resolveRelay; } });
@@ -1,7 +1,6 @@
1
1
  type RawPreactOptions = {
2
2
  library?: string;
3
3
  };
4
- type PreactOptions = RawPreactOptions | boolean | undefined;
5
- declare function resolvePreact(preact: PreactOptions): RawPreactOptions | undefined;
6
- export { resolvePreact };
7
- export type { PreactOptions };
4
+ export type PreactOptions = RawPreactOptions | boolean | undefined;
5
+ export declare function resolvePreact(preact: PreactOptions): RawPreactOptions | undefined;
6
+ export {};
@@ -2,22 +2,9 @@
2
2
  * Some types are modified from https://github.com/swc-project/swc/blob/16a38851/packages/types/index.ts#L647
3
3
  * license at https://github.com/swc-project/swc/blob/main/LICENSE
4
4
  */
5
- import type { EmotionOptions } from "./emotion";
6
5
  import type { PluginImportOptions } from "./pluginImport";
6
+ import type { PreactOptions } from "./preact";
7
7
  import type { ReactOptions } from "./react";
8
- import type { RelayOptions } from "./relay";
9
- export type StyledComponentsOptions = {
10
- displayName?: boolean;
11
- ssr?: boolean;
12
- fileName?: boolean;
13
- meaninglessFileNames?: string[];
14
- namespace?: string;
15
- topLevelImportPaths?: string[];
16
- transpileTemplateLiterals?: boolean;
17
- minify?: boolean;
18
- pure?: boolean;
19
- cssProps?: boolean;
20
- };
21
8
  export type JscTarget = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "esnext";
22
9
  export type SwcLoaderParserConfig = SwcLoaderTsParserConfig | SwcLoaderEsParserConfig;
23
10
  export interface SwcLoaderTsParserConfig {
@@ -454,9 +441,7 @@ export type SwcLoaderOptions = {
454
441
  * @experimental
455
442
  */
456
443
  rspackExperiments?: {
457
- relay?: RelayOptions;
458
- emotion?: EmotionOptions;
459
444
  import?: PluginImportOptions;
460
- styledComponents?: StyledComponentsOptions;
445
+ preact?: PreactOptions;
461
446
  };
462
447
  };
@@ -1,6 +1,7 @@
1
1
  import { BuiltinPluginName, RawBundlerInfoPluginOptions } from "@rspack/binding";
2
2
  export type BundleInfoOptions = {
3
3
  version?: string;
4
+ bundler?: string;
4
5
  force?: boolean | string[];
5
6
  };
6
7
  export declare const BundlerInfoRspackPlugin: {
@@ -6,6 +6,7 @@ const base_1 = require("./base");
6
6
  exports.BundlerInfoRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.BundlerInfoRspackPlugin, (options) => {
7
7
  return {
8
8
  version: options.version || "unknown",
9
+ bundler: options.bundler || "rspack",
9
10
  force: options.force ?? true
10
11
  };
11
12
  });
@@ -1,6 +1,6 @@
1
1
  import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding";
2
+ import * as liteTapable from "@rspack/lite-tapable";
2
3
  import { Compilation } from "../Compilation";
3
- import * as liteTapable from "../lite-tapable";
4
4
  import { RspackBuiltinPlugin } from "./base";
5
5
  import Hash = require("../util/hash");
6
6
  import { Chunk } from "../Chunk";
@@ -25,8 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.JavascriptModulesPlugin = void 0;
27
27
  const binding_1 = require("@rspack/binding");
28
+ const liteTapable = __importStar(require("@rspack/lite-tapable"));
28
29
  const Compilation_1 = require("../Compilation");
29
- const liteTapable = __importStar(require("../lite-tapable"));
30
30
  const base_1 = require("./base");
31
31
  const compilationHooksMap = new WeakMap();
32
32
  class JavascriptModulesPlugin extends base_1.RspackBuiltinPlugin {
@@ -5,7 +5,7 @@ const binding_1 = require("@rspack/binding");
5
5
  const base_1 = require("./base");
6
6
  exports.LightningCssMinimizerRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.LightningCssMinimizerRspackPlugin, (options) => {
7
7
  return {
8
- errorRecovery: options?.errorRecovery ?? false,
8
+ errorRecovery: options?.errorRecovery ?? true,
9
9
  unusedSymbols: options?.unusedSymbols ?? [],
10
10
  removeUnusedLocalIdents: options?.removeUnusedLocalIdents ?? true,
11
11
  browserslist: options?.browserslist ?? ["defaults"]
@@ -8,6 +8,7 @@ const assert_1 = __importDefault(require("assert"));
8
8
  const binding_1 = require("@rspack/binding");
9
9
  const Chunk_1 = require("../Chunk");
10
10
  const Module_1 = require("../Module");
11
+ const SplitChunkSize_1 = require("../util/SplitChunkSize");
11
12
  const base_1 = require("./base");
12
13
  class SplitChunksPlugin extends base_1.RspackBuiltinPlugin {
13
14
  constructor(options) {
@@ -65,7 +66,7 @@ function toRawSplitChunksOptions(sc, compiler) {
65
66
  return chunks;
66
67
  }
67
68
  }
68
- const { name, chunks, defaultSizeTypes, cacheGroups = {}, fallbackCacheGroup, ...passThrough } = sc;
69
+ const { name, chunks, defaultSizeTypes, cacheGroups = {}, fallbackCacheGroup, minSize, maxSize, maxAsyncSize, maxInitialSize, ...passThrough } = sc;
69
70
  return {
70
71
  name: getName(name),
71
72
  chunks: getChunks(chunks),
@@ -74,12 +75,16 @@ function toRawSplitChunksOptions(sc, compiler) {
74
75
  .filter(([_key, group]) => group !== false)
75
76
  .map(([key, group]) => {
76
77
  group = group;
77
- const { test, name, chunks, ...passThrough } = group;
78
+ const { test, name, chunks, minSize, maxSize, maxAsyncSize, maxInitialSize, ...passThrough } = group;
78
79
  const rawGroup = {
79
80
  key,
80
81
  test: getTest(test),
81
82
  name: getName(name),
82
83
  chunks: getChunks(chunks),
84
+ minSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(minSize),
85
+ maxSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxSize),
86
+ maxAsyncSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxAsyncSize),
87
+ maxInitialSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxInitialSize),
83
88
  ...passThrough
84
89
  };
85
90
  return rawGroup;
@@ -88,6 +93,10 @@ function toRawSplitChunksOptions(sc, compiler) {
88
93
  chunks: getChunks(chunks),
89
94
  ...fallbackCacheGroup
90
95
  },
96
+ minSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(minSize),
97
+ maxSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxSize),
98
+ maxAsyncSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxAsyncSize),
99
+ maxInitialSize: SplitChunkSize_1.JsSplitChunkSizes.__to_binding(maxInitialSize),
91
100
  ...passThrough
92
101
  };
93
102
  }
@@ -9,34 +9,6 @@ type ExtractCommentsObject = {
9
9
  };
10
10
  type ExtractCommentsOptions = ExtractCommentsCondition | ExtractCommentsObject;
11
11
  export type SwcJsMinimizerRspackPluginOptions = {
12
- /**
13
- * @deprecated Deprecated, move to `compress.passes`
14
- */
15
- passes?: number;
16
- /**
17
- * @deprecated Deprecated, move to `compress.drop_console`
18
- */
19
- dropConsole?: boolean;
20
- /**
21
- * @deprecated Deprecated, move to `compress.pure_funcs`
22
- */
23
- pureFuncs?: Array<string>;
24
- /**
25
- * @deprecated Deprecated, move to `mangle.keep_classnames`
26
- */
27
- keepClassNames?: boolean;
28
- /**
29
- * @deprecated Deprecated, move to `mangle.keep_fnames`
30
- */
31
- keepFnNames?: boolean;
32
- /**
33
- * @deprecated Deprecated, move to `format.comments`
34
- */
35
- comments?: false | "all" | "some";
36
- /**
37
- * @deprecated Deprecated, move to `format.ascii_only`
38
- */
39
- asciiOnly?: boolean;
40
12
  extractComments?: ExtractCommentsOptions | undefined;
41
13
  compress?: TerserCompressOptions | boolean;
42
14
  mangle?: TerserMangleOptions | boolean;
@@ -3,72 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SwcJsMinimizerRspackPlugin = void 0;
4
4
  const binding_1 = require("@rspack/binding");
5
5
  const base_1 = require("./base");
6
- function getRawCompressOptions(options) {
7
- function _inner() {
8
- const _default = {
9
- passes: options?.passes ?? 1,
10
- pure_funcs: options?.pureFuncs ?? [],
11
- drop_console: options?.dropConsole ?? false
12
- };
13
- if (options?.compress === true) {
14
- return _default;
15
- }
16
- if (options?.compress === false) {
17
- return false;
18
- }
19
- if (options?.compress && typeof options.compress === "object") {
20
- return {
21
- // TODO: deprecate default merging in 0.4
22
- ..._default,
23
- ...options.compress
24
- };
25
- }
26
- return _default;
27
- }
28
- let inner = _inner();
29
- return typeof inner === "boolean" ? inner : JSON.stringify(inner);
30
- }
31
- function getRawMangleOptions(options) {
32
- function _inner() {
33
- const _default = {
34
- keep_classnames: options?.keepClassNames ?? false,
35
- keep_fnames: options?.keepFnNames ?? false
36
- };
37
- if (options?.mangle === true) {
38
- return _default;
39
- }
40
- if (options?.mangle === false) {
41
- return false;
42
- }
43
- if (options?.mangle && typeof options.mangle === "object") {
44
- return {
45
- // TODO: deprecate default merging in 0.4
46
- ..._default,
47
- ...options.mangle
48
- };
49
- }
50
- return _default;
51
- }
52
- let inner = _inner();
53
- return typeof inner === "boolean" ? inner : JSON.stringify(inner);
54
- }
55
- function getRawFormatOptions(options) {
56
- function _inner() {
57
- const _default = {
58
- comments: options?.comments ? options?.comments : false,
59
- asciiOnly: options?.asciiOnly ?? false
60
- };
61
- if (options?.format && typeof options.format === "object") {
62
- // TODO: deprecate default merging in 0.4
63
- return {
64
- ..._default,
65
- ...options.format
66
- };
67
- }
68
- return _default;
69
- }
70
- return JSON.stringify(_inner());
71
- }
72
6
  function isObject(value) {
73
7
  const type = typeof value;
74
8
  return value != null && (type === "object" || type === "function");
@@ -121,11 +55,28 @@ function getRawExtractCommentsOptions(extractComments) {
121
55
  }
122
56
  }
123
57
  exports.SwcJsMinimizerRspackPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.SwcJsMinimizerRspackPlugin, (options) => {
58
+ let compress = options?.compress ?? true;
59
+ let mangle = options?.mangle ?? true;
60
+ let format = {
61
+ comments: false,
62
+ ...options?.format
63
+ };
64
+ if (compress && typeof compress === "object") {
65
+ compress = {
66
+ passes: 1,
67
+ ...compress
68
+ };
69
+ }
70
+ else if (compress) {
71
+ compress = {
72
+ passes: 1
73
+ };
74
+ }
124
75
  return {
125
76
  extractComments: getRawExtractCommentsOptions(options?.extractComments),
126
- compress: getRawCompressOptions(options),
127
- mangle: getRawMangleOptions(options),
128
- format: getRawFormatOptions(options),
77
+ compress,
78
+ mangle,
79
+ format,
129
80
  module: options?.module,
130
81
  test: options?.test,
131
82
  include: options?.include,
@@ -3,8 +3,8 @@ import { Compiler } from "../..";
3
3
  export * from "./loader";
4
4
  export type { CssExtractRspackLoaderOptions } from "./loader";
5
5
  export interface CssExtractRspackPluginOptions {
6
- filename?: string;
7
- chunkFilename?: string;
6
+ filename?: RawCssExtractPluginOption["filename"];
7
+ chunkFilename?: RawCssExtractPluginOption["chunkFilename"];
8
8
  ignoreOrder?: boolean;
9
9
  insert?: string | ((linkTag: HTMLLinkElement) => void);
10
10
  attributes?: Record<string, string>;
@@ -85,21 +85,24 @@ function getRawResolveByDependency(byDependency) {
85
85
  return byDependency;
86
86
  return Object.fromEntries(Object.entries(byDependency).map(([k, v]) => [k, getRawResolve(v)]));
87
87
  }
88
+ function getRawTsConfig(tsConfig) {
89
+ (0, assert_1.default)(typeof tsConfig !== "string", "should resolve string tsConfig in normalization");
90
+ if (tsConfig === undefined)
91
+ return tsConfig;
92
+ const { configFile, references } = tsConfig;
93
+ return {
94
+ configFile,
95
+ referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled",
96
+ references: references == "auto" ? undefined : references
97
+ };
98
+ }
88
99
  function getRawResolve(resolve) {
89
- let references = resolve.tsConfig?.references;
90
- let tsconfigConfigFile = resolve.tsConfigPath ?? resolve.tsConfig?.configFile;
91
100
  return {
92
101
  ...resolve,
93
102
  alias: getRawAlias(resolve.alias),
94
103
  fallback: getRawAlias(resolve.fallback),
95
104
  extensionAlias: getRawExtensionAlias(resolve.extensionAlias),
96
- tsconfig: tsconfigConfigFile
97
- ? {
98
- configFile: tsconfigConfigFile,
99
- referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled",
100
- references: references == "auto" ? undefined : references
101
- }
102
- : undefined,
105
+ tsconfig: getRawTsConfig(resolve.tsConfig),
103
106
  byDependency: getRawResolveByDependency(resolve.byDependency)
104
107
  };
105
108
  }
@@ -211,7 +214,7 @@ function getRawModule(module, options) {
211
214
  { rules: module.defaultRules },
212
215
  { rules: module.rules }
213
216
  ];
214
- const rules = ruleSet.map((rule, index) => getRawModuleRule(rule, `ruleSet[${index}]`, options));
217
+ const rules = ruleSet.map((rule, index) => getRawModuleRule(rule, `ruleSet[${index}]`, options, "javascript/auto"));
215
218
  return {
216
219
  rules,
217
220
  parser: getRawParserOptionsByModuleType(module.parser),
@@ -245,7 +248,7 @@ function tryMatch(payload, condition) {
245
248
  }
246
249
  return false;
247
250
  }
248
- const getRawModuleRule = (rule, path, options) => {
251
+ const getRawModuleRule = (rule, path, options, upperType) => {
249
252
  // Rule.loader is a shortcut to Rule.use: [ { loader } ].
250
253
  // See: https://webpack.js.org/configuration/module/#ruleloader
251
254
  if (rule.loader) {
@@ -297,17 +300,17 @@ const getRawModuleRule = (rule, path, options) => {
297
300
  : (0, adapterRuleUse_1.createRawModuleRuleUses)(rule.use ?? [], `${path}.use`, options),
298
301
  type: rule.type,
299
302
  parser: rule.parser
300
- ? getRawParserOptions(rule.parser, rule.type ?? "javascript/auto")
303
+ ? getRawParserOptions(rule.parser, rule.type ?? upperType)
301
304
  : undefined,
302
305
  generator: rule.generator
303
- ? getRawGeneratorOptions(rule.generator, rule.type ?? "javascript/auto")
306
+ ? getRawGeneratorOptions(rule.generator, rule.type ?? upperType)
304
307
  : undefined,
305
308
  resolve: rule.resolve ? getRawResolve(rule.resolve) : undefined,
306
309
  oneOf: rule.oneOf
307
- ? rule.oneOf.map((rule, index) => getRawModuleRule(rule, `${path}.oneOf[${index}]`, options))
310
+ ? rule.oneOf.map((rule, index) => getRawModuleRule(rule, `${path}.oneOf[${index}]`, options, rule.type ?? upperType))
308
311
  : undefined,
309
312
  rules: rule.rules
310
- ? rule.rules.map((rule, index) => getRawModuleRule(rule, `${path}.rules[${index}]`, options))
313
+ ? rule.rules.map((rule, index) => getRawModuleRule(rule, `${path}.rules[${index}]`, options, rule.type ?? upperType))
311
314
  : undefined,
312
315
  enforce: rule.enforce
313
316
  };
@@ -450,6 +453,7 @@ function getRawJavascriptParserOptions(parser) {
450
453
  dynamicImportMode: parser.dynamicImportMode ?? "lazy",
451
454
  dynamicImportPreload: parser.dynamicImportPreload?.toString() ?? "false",
452
455
  dynamicImportPrefetch: parser.dynamicImportPrefetch?.toString() ?? "false",
456
+ dynamicImportFetchPriority: parser.dynamicImportFetchPriority?.toString(),
453
457
  url: parser.url === false
454
458
  ? "false"
455
459
  : parser.url === "relative"
@@ -464,9 +468,19 @@ function getRawJavascriptParserOptions(parser) {
464
468
  reexportExportsPresence: parser.reexportExportsPresence === false
465
469
  ? "false"
466
470
  : parser.reexportExportsPresence,
467
- strictExportPresence: parser.strictExportPresence ?? false
471
+ strictExportPresence: parser.strictExportPresence ?? false,
472
+ worker: getRawJavascriptParserOptionsWorker(parser.worker)
468
473
  };
469
474
  }
475
+ function getRawJavascriptParserOptionsWorker(worker) {
476
+ const DEFAULT_SYNTAX = [
477
+ "Worker",
478
+ "SharedWorker",
479
+ "navigator.serviceWorker.register()",
480
+ "Worker from worker_threads"
481
+ ];
482
+ return (worker === false ? [] : Array.isArray(worker) ? worker : ["..."]).flatMap(item => (item === "..." ? DEFAULT_SYNTAX : item));
483
+ }
470
484
  function getRawAssetParserOptions(parser) {
471
485
  return {
472
486
  dataUrlCondition: parser.dataUrlCondition
@@ -16,20 +16,9 @@ exports.createRawModuleRuleUses = createRawModuleRuleUses;
16
16
  const getSwcLoaderOptions = (o, options) => {
17
17
  if (o && typeof o === "object" && o.rspackExperiments) {
18
18
  let expr = o.rspackExperiments;
19
- const contextPath = options.context;
20
- const production = options.mode === "production" || !options.mode;
21
- if (expr.emotion) {
22
- expr.emotion = (0, builtin_loader_1.resolveEmotion)(expr.emotion, production);
23
- }
24
- if (expr.relay) {
25
- expr.relay = (0, builtin_loader_1.resolveRelay)(expr.relay, contextPath);
26
- }
27
19
  if (expr.import || expr.pluginImport) {
28
20
  expr.import = (0, builtin_loader_1.resolvePluginImport)(expr.import || expr.pluginImport);
29
21
  }
30
- if (expr.react) {
31
- expr.react = (0, builtin_loader_1.resolveReact)(expr.react);
32
- }
33
22
  if (expr.preact) {
34
23
  expr.preact = (0, builtin_loader_1.resolvePreact)(expr.preact);
35
24
  }