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

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 (64) hide show
  1. package/README.md +2 -2
  2. package/compiled/webpack-sources/index.d.ts +130 -0
  3. package/compiled/webpack-sources/index.js +3520 -0
  4. package/compiled/webpack-sources/license +21 -0
  5. package/compiled/webpack-sources/package.json +1 -0
  6. package/dist/Chunk.d.ts +19 -14
  7. package/dist/Chunk.js +22 -17
  8. package/dist/ChunkGraph.d.ts +1 -1
  9. package/dist/ChunkGraph.js +5 -5
  10. package/dist/ChunkGroup.d.ts +17 -7
  11. package/dist/ChunkGroup.js +12 -2
  12. package/dist/Compilation.d.ts +19 -23
  13. package/dist/Compilation.js +20 -43
  14. package/dist/Compiler.d.ts +1 -1
  15. package/dist/Compiler.js +32 -2
  16. package/dist/Entrypoint.d.ts +1 -1
  17. package/dist/Entrypoint.js +2 -2
  18. package/dist/Module.d.ts +12 -7
  19. package/dist/Module.js +1 -0
  20. package/dist/NormalModule.d.ts +0 -1
  21. package/dist/NormalModule.js +0 -7
  22. package/dist/NormalModuleFactory.d.ts +1 -0
  23. package/dist/NormalModuleFactory.js +1 -22
  24. package/dist/RspackError.d.ts +8 -0
  25. package/dist/RspackError.js +21 -0
  26. package/dist/Stats.d.ts +2 -2
  27. package/dist/Template.d.ts +1 -1
  28. package/dist/Template.js +2 -2
  29. package/dist/builtin-loader/swc/index.d.ts +0 -4
  30. package/dist/builtin-loader/swc/index.js +1 -5
  31. package/dist/builtin-loader/swc/preact.d.ts +3 -4
  32. package/dist/builtin-loader/swc/types.d.ts +2 -17
  33. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -0
  34. package/dist/builtin-plugin/BundlerInfoRspackPlugin.js +1 -0
  35. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +0 -28
  36. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +20 -69
  37. package/dist/builtin-plugin/css-extract/index.d.ts +2 -2
  38. package/dist/config/adapter.js +23 -10
  39. package/dist/config/adapterRuleUse.js +0 -11
  40. package/dist/config/defaults.js +22 -30
  41. package/dist/config/normalization.js +13 -5
  42. package/dist/config/zod.d.ts +168 -43
  43. package/dist/config/zod.js +23 -11
  44. package/dist/container/ModuleFederationPlugin.js +1 -1
  45. package/dist/container/default.runtime.js +1 -170
  46. package/dist/exports.d.ts +1 -1
  47. package/dist/exports.js +1 -1
  48. package/dist/lite-tapable/index.js +2 -2
  49. package/dist/loader-runner/index.js +28 -7
  50. package/dist/rspackOptionsApply.js +3 -0
  51. package/dist/stats/DefaultStatsFactoryPlugin.js +35 -11
  52. package/dist/stats/DefaultStatsPrinterPlugin.js +2 -2
  53. package/dist/stats/statsFactoryUtils.d.ts +13 -4
  54. package/dist/util/index.d.ts +2 -2
  55. package/dist/util/index.js +4 -3
  56. package/dist/util/memoize.js +5 -1
  57. package/dist/util/source.d.ts +1 -1
  58. package/dist/util/source.js +1 -1
  59. package/package.json +12 -7
  60. package/dist/builtin-loader/swc/emotion.d.ts +0 -17
  61. package/dist/builtin-loader/swc/emotion.js +0 -22
  62. package/dist/builtin-loader/swc/relay.d.ts +0 -5
  63. package/dist/builtin-loader/swc/relay.js +0 -48
  64. package/dist/container/default.runtime.d.ts +0 -2
package/dist/Compiler.js CHANGED
@@ -652,16 +652,27 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
652
652
  __classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
653
653
  }),
654
654
  registerCompilationFinishModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationFinishModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.finishModules, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
655
- registerCompilationOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
656
- registerCompilationAfterOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterOptimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
655
+ registerCompilationOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeModules, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules.values())),
656
+ registerCompilationAfterOptimizeModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterOptimizeModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterOptimizeModules, queried => () => {
657
+ queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").modules.values());
658
+ }),
657
659
  registerCompilationOptimizeTreeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeTree, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeTree, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").chunks, __classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
658
660
  registerCompilationOptimizeChunkModulesTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationOptimizeChunkModules, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.optimizeChunkModules, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").chunks, __classPrivateFieldGet(this, _Compiler_compilation, "f").modules)),
661
+ registerCompilationChunkHashTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkHash, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.chunkHash, queried => (chunk) => {
662
+ const hash = (0, createHash_1.createHash)(this.options.output.hashFunction);
663
+ queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), hash);
664
+ const digestResult = hash.digest(this.options.output.hashDigest);
665
+ return Buffer.from(digestResult);
666
+ }),
659
667
  registerCompilationChunkAssetTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkAsset, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.chunkAsset, queried => ({ chunk, filename }) => queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), filename)),
660
668
  registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.processAssets, queried => async () => await queried.promise(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
661
669
  registerCompilationAfterProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterProcessAssets, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterProcessAssets, queried => () => queried.call(__classPrivateFieldGet(this, _Compiler_compilation, "f").assets)),
662
670
  registerCompilationAfterSealTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterSeal, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.afterSeal, queried => async () => await queried.promise()),
663
671
  registerNormalModuleFactoryBeforeResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryBeforeResolve, () => __classPrivateFieldGet(this, _Compiler_compilationParams, "f").normalModuleFactory.hooks.beforeResolve, queried => async (resolveData) => {
664
672
  const normalizedResolveData = {
673
+ contextInfo: {
674
+ issuer: resolveData.issuer
675
+ },
665
676
  request: resolveData.request,
666
677
  context: resolveData.context,
667
678
  fileDependencies: [],
@@ -673,6 +684,22 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
673
684
  resolveData.context = normalizedResolveData.context;
674
685
  return [ret, resolveData];
675
686
  }),
687
+ registerNormalModuleFactoryFactorizeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryFactorize, () => __classPrivateFieldGet(this, _Compiler_compilationParams, "f").normalModuleFactory.hooks.factorize, queried => async (resolveData) => {
688
+ const normalizedResolveData = {
689
+ contextInfo: {
690
+ issuer: resolveData.issuer
691
+ },
692
+ request: resolveData.request,
693
+ context: resolveData.context,
694
+ fileDependencies: [],
695
+ missingDependencies: [],
696
+ contextDependencies: []
697
+ };
698
+ await queried.promise(normalizedResolveData);
699
+ resolveData.request = normalizedResolveData.request;
700
+ resolveData.context = normalizedResolveData.context;
701
+ return resolveData;
702
+ }),
676
703
  registerNormalModuleFactoryResolveForSchemeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookMapRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryResolveForScheme, () => __classPrivateFieldGet(this, _Compiler_compilationParams, "f").normalModuleFactory.hooks.resolveForScheme, queried => async (args) => {
677
704
  const ret = await queried
678
705
  .for(args.scheme)
@@ -681,6 +708,9 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
681
708
  }),
682
709
  registerNormalModuleFactoryAfterResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryAfterResolve, () => __classPrivateFieldGet(this, _Compiler_compilationParams, "f").normalModuleFactory.hooks.afterResolve, queried => async (arg) => {
683
710
  const data = {
711
+ contextInfo: {
712
+ issuer: arg.issuer
713
+ },
684
714
  request: arg.request,
685
715
  context: arg.context,
686
716
  fileDependencies: arg.fileDependencies,
@@ -4,5 +4,5 @@ import { ChunkGroup } from "./ChunkGroup";
4
4
  export declare class Entrypoint extends ChunkGroup {
5
5
  static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation): Entrypoint;
6
6
  protected constructor(inner: JsChunkGroup, compilation: JsCompilation);
7
- getRuntimeChunk(): Chunk | null;
7
+ getRuntimeChunk(): Readonly<Chunk | null>;
8
8
  }
@@ -12,9 +12,9 @@ class Entrypoint extends ChunkGroup_1.ChunkGroup {
12
12
  super(inner, compilation);
13
13
  }
14
14
  getRuntimeChunk() {
15
- const c = (0, binding_1.__entrypoint_inner_get_runtime_chunk)(this.__internal_innerUkey(), this.__internal_innerCompilation());
15
+ const c = (0, binding_1.__entrypoint_inner_get_runtime_chunk)(this.__internal__innerUkey(), this.__internal__innerCompilation());
16
16
  if (c)
17
- return Chunk_1.Chunk.__from_binding(c, this.__internal_innerCompilation());
17
+ return Chunk_1.Chunk.__from_binding(c, this.__internal__innerCompilation());
18
18
  return null;
19
19
  }
20
20
  }
package/dist/Module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsModule } from "@rspack/binding";
2
- import { Source } from "webpack-sources";
1
+ import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsFactoryMeta, JsModule } from "@rspack/binding";
2
+ import { Source } from "../compiled/webpack-sources";
3
3
  import { Compilation } from "./Compilation";
4
4
  export type ResourceData = {
5
5
  resource: string;
@@ -11,7 +11,11 @@ export type ResourceDataWithData = ResourceData & {
11
11
  data?: Record<string, any>;
12
12
  };
13
13
  export type CreateData = Partial<JsCreateData>;
14
+ export type ContextInfo = {
15
+ issuer: string;
16
+ };
14
17
  export type ResolveData = {
18
+ contextInfo: ContextInfo;
15
19
  context: string;
16
20
  request: string;
17
21
  fileDependencies: string[];
@@ -32,11 +36,12 @@ export type ContextModuleFactoryAfterResolveResult = false | {
32
36
  };
33
37
  export declare class Module {
34
38
  #private;
35
- context?: string;
36
- resource?: string;
37
- request?: string;
38
- userRequest?: string;
39
- rawRequest?: string;
39
+ context?: Readonly<string>;
40
+ resource?: Readonly<string>;
41
+ request?: Readonly<string>;
42
+ userRequest?: Readonly<string>;
43
+ rawRequest?: Readonly<string>;
44
+ factoryMeta?: Readonly<JsFactoryMeta>;
40
45
  /**
41
46
  * Records the dynamically added fields for Module on the JavaScript side.
42
47
  * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
package/dist/Module.js CHANGED
@@ -27,6 +27,7 @@ class Module {
27
27
  this.request = module.request;
28
28
  this.userRequest = module.userRequest;
29
29
  this.rawRequest = module.rawRequest;
30
+ this.factoryMeta = module.factoryMeta;
30
31
  const customModule = compilation?.__internal__getCustomModule(module.moduleIdentifier);
31
32
  this.buildInfo = customModule?.buildInfo || {};
32
33
  this.buildMeta = customModule?.buildMeta || {};
@@ -3,7 +3,6 @@ import { AsyncSeriesBailHook, HookMap, SyncHook } from "tapable";
3
3
  import { Compilation } from "./Compilation";
4
4
  import { LoaderContext } from "./config";
5
5
  export declare class NormalModule {
6
- constructor();
7
6
  static getCompilationHooks(compilation: Compilation): {
8
7
  loader: SyncHook<[LoaderContext<{}>], void, import("tapable").UnsetAdditionalOptions>;
9
8
  readResourceForScheme: any;
@@ -46,10 +46,7 @@ const deprecateAllProperties = (obj, message, code) => {
46
46
  }
47
47
  return newObj;
48
48
  };
49
- // Actually it is just a NormalModule proxy, used for hooks api alignment
50
- // Maybe we can 1:1 align to webpack NormalModule once we found a better way to reduce communicate overhead between rust and js
51
49
  class NormalModule {
52
- constructor() { }
53
50
  static getCompilationHooks(compilation) {
54
51
  if (!(compilation instanceof Compilation_1.Compilation)) {
55
52
  throw new TypeError("The 'compilation' argument must be an instance of Compilation");
@@ -58,9 +55,6 @@ class NormalModule {
58
55
  if (hooks === undefined) {
59
56
  hooks = {
60
57
  loader: new tapable_1.SyncHook(["loaderContext"]),
61
- // beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
62
- // beforeParse: new SyncHook(["module"]),
63
- // beforeSnapshot: new SyncHook(["module"]),
64
58
  // TODO webpack 6 deprecate
65
59
  readResourceForScheme: new tapable_1.HookMap(scheme => {
66
60
  const hook = hooks.readResource.for(scheme);
@@ -71,7 +65,6 @@ class NormalModule {
71
65
  });
72
66
  }),
73
67
  readResource: new tapable_1.HookMap(() => new tapable_1.AsyncSeriesBailHook(["loaderContext"]))
74
- // needBuild: new AsyncSeriesBailHook(["module", "context"])
75
68
  };
76
69
  compilationHooksMap.set(compilation, hooks);
77
70
  }
@@ -8,6 +8,7 @@ export declare class NormalModuleFactory {
8
8
  hooks: {
9
9
  resolveForScheme: liteTapable.HookMap<liteTapable.AsyncSeriesBailHook<[ResourceDataWithData], true | void>>;
10
10
  beforeResolve: liteTapable.AsyncSeriesBailHook<[ResolveData], false | void>;
11
+ factorize: liteTapable.AsyncSeriesBailHook<[ResolveData], void>;
11
12
  afterResolve: liteTapable.AsyncSeriesBailHook<[ResolveData], false | void>;
12
13
  createModule: liteTapable.AsyncSeriesBailHook<[
13
14
  NormalModuleCreateData,
@@ -28,35 +28,14 @@ const liteTapable = __importStar(require("./lite-tapable"));
28
28
  class NormalModuleFactory {
29
29
  constructor() {
30
30
  this.hooks = {
31
- // /** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
32
- // resolve: new AsyncSeriesBailHook(["resolveData"]),
33
- // /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
34
31
  resolveForScheme: new liteTapable.HookMap(() => new liteTapable.AsyncSeriesBailHook(["resourceData"])),
35
- // /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
36
- // resolveInScheme: new HookMap(
37
- // () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
38
- // ),
39
- // /** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
40
- // factorize: new AsyncSeriesBailHook(["resolveData"]),
41
- // /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
42
32
  beforeResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
43
- // /** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
33
+ factorize: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
44
34
  afterResolve: new liteTapable.AsyncSeriesBailHook(["resolveData"]),
45
- // /** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
46
35
  createModule: new liteTapable.AsyncSeriesBailHook([
47
36
  "createData",
48
37
  "resolveData"
49
38
  ])
50
- // /** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
51
- // module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
52
- // createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
53
- // parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
54
- // createGenerator: new HookMap(
55
- // () => new SyncBailHook(["generatorOptions"])
56
- // ),
57
- // generator: new HookMap(
58
- // () => new SyncHook(["generator", "generatorOptions"])
59
- // )
60
39
  };
61
40
  }
62
41
  }
@@ -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,7 @@ 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
10
  hasErrors(): boolean;
11
11
  hasWarnings(): boolean;
12
12
  toJson(opts?: StatsValue, forToString?: boolean): StatsCompilation;
@@ -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,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
  });
@@ -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
  }
@@ -464,9 +467,19 @@ function getRawJavascriptParserOptions(parser) {
464
467
  reexportExportsPresence: parser.reexportExportsPresence === false
465
468
  ? "false"
466
469
  : parser.reexportExportsPresence,
467
- strictExportPresence: parser.strictExportPresence ?? false
470
+ strictExportPresence: parser.strictExportPresence ?? false,
471
+ worker: getRawJavascriptParserOptionsWorker(parser.worker)
468
472
  };
469
473
  }
474
+ function getRawJavascriptParserOptionsWorker(worker) {
475
+ const DEFAULT_SYNTAX = [
476
+ "Worker",
477
+ "SharedWorker",
478
+ "navigator.serviceWorker.register()",
479
+ "Worker from worker_threads"
480
+ ];
481
+ return (worker === false ? [] : Array.isArray(worker) ? worker : ["..."]).flatMap(item => (item === "..." ? DEFAULT_SYNTAX : item));
482
+ }
470
483
  function getRawAssetParserOptions(parser) {
471
484
  return {
472
485
  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
  }