@rspack/core 0.7.6-canary-f272bd8-20240625122346 → 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 (66) 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 +40 -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/JavascriptModulesPlugin.d.ts +15 -9
  36. package/dist/builtin-plugin/JavascriptModulesPlugin.js +50 -1
  37. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +0 -28
  38. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +20 -69
  39. package/dist/builtin-plugin/css-extract/index.d.ts +2 -2
  40. package/dist/config/adapter.js +23 -10
  41. package/dist/config/adapterRuleUse.js +0 -11
  42. package/dist/config/defaults.js +22 -30
  43. package/dist/config/normalization.js +13 -5
  44. package/dist/config/zod.d.ts +168 -43
  45. package/dist/config/zod.js +23 -11
  46. package/dist/container/ModuleFederationPlugin.js +1 -1
  47. package/dist/container/default.runtime.js +1 -170
  48. package/dist/exports.d.ts +3 -2
  49. package/dist/exports.js +5 -2
  50. package/dist/lite-tapable/index.js +2 -2
  51. package/dist/loader-runner/index.js +28 -7
  52. package/dist/rspackOptionsApply.js +3 -0
  53. package/dist/stats/DefaultStatsFactoryPlugin.js +35 -11
  54. package/dist/stats/DefaultStatsPrinterPlugin.js +2 -2
  55. package/dist/stats/statsFactoryUtils.d.ts +13 -4
  56. package/dist/util/index.d.ts +2 -2
  57. package/dist/util/index.js +4 -3
  58. package/dist/util/memoize.js +5 -1
  59. package/dist/util/source.d.ts +1 -1
  60. package/dist/util/source.js +1 -1
  61. package/package.json +12 -7
  62. package/dist/builtin-loader/swc/emotion.d.ts +0 -17
  63. package/dist/builtin-loader/swc/emotion.js +0 -22
  64. package/dist/builtin-loader/swc/relay.d.ts +0 -5
  65. package/dist/builtin-loader/swc/relay.js +0 -48
  66. package/dist/container/default.runtime.d.ts +0 -2
package/dist/Compiler.js CHANGED
@@ -77,6 +77,7 @@ const Logger_1 = require("./logging/Logger");
77
77
  const util_1 = require("./util");
78
78
  const assertNotNil_1 = require("./util/assertNotNil");
79
79
  const bindingVersionCheck_1 = require("./util/bindingVersionCheck");
80
+ const createHash_1 = require("./util/createHash");
80
81
  const identifier_1 = require("./util/identifier");
81
82
  class Compiler {
82
83
  constructor(context, options) {
@@ -651,16 +652,27 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
651
652
  __classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
652
653
  }),
653
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)),
654
- 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)),
655
- 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
+ }),
656
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)),
657
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
+ }),
658
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)),
659
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)),
660
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)),
661
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()),
662
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) => {
663
672
  const normalizedResolveData = {
673
+ contextInfo: {
674
+ issuer: resolveData.issuer
675
+ },
664
676
  request: resolveData.request,
665
677
  context: resolveData.context,
666
678
  fileDependencies: [],
@@ -672,6 +684,22 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
672
684
  resolveData.context = normalizedResolveData.context;
673
685
  return [ret, resolveData];
674
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
+ }),
675
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) => {
676
704
  const ret = await queried
677
705
  .for(args.scheme)
@@ -680,6 +708,9 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
680
708
  }),
681
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) => {
682
710
  const data = {
711
+ contextInfo: {
712
+ issuer: arg.issuer
713
+ },
683
714
  request: arg.request,
684
715
  context: arg.context,
685
716
  fileDependencies: arg.fileDependencies,
@@ -728,6 +759,13 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
728
759
  })
729
760
  : false;
730
761
  return result;
762
+ }),
763
+ registerJavascriptModulesChunkHashTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.JavascriptModulesChunkHash, () => builtin_plugin_1.JavascriptModulesPlugin.getCompilationHooks(__classPrivateFieldGet(this, _Compiler_compilation, "f"))
764
+ .chunkHash, queried => (chunk) => {
765
+ const hash = (0, createHash_1.createHash)(this.options.output.hashFunction);
766
+ queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), hash);
767
+ const digestResult = hash.digest(this.options.output.hashDigest);
768
+ return Buffer.from(digestResult);
731
769
  })
732
770
  }, "f");
733
771
  __classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, __classPrivateFieldGet(this, _Compiler_builtinPlugins, "f"), __classPrivateFieldGet(this, _Compiler_registers, "f"), FileSystem_1.ThreadsafeWritableNodeFS.__to_binding(this.outputFileSystem)), "f");
@@ -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
  });
@@ -1,10 +1,16 @@
1
- import { BuiltinPluginName } from "@rspack/binding";
2
- export declare const JavascriptModulesPlugin: {
3
- new (): {
4
- name: BuiltinPluginName;
5
- _options: void;
6
- affectedHooks: "make" | "compile" | "emit" | "afterEmit" | "invalid" | "done" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
7
- raw(): import("@rspack/binding").BuiltinPlugin;
8
- apply(compiler: import("../Compiler").Compiler): void;
9
- };
1
+ import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding";
2
+ import { Compilation } from "../Compilation";
3
+ import * as liteTapable from "../lite-tapable";
4
+ import { RspackBuiltinPlugin } from "./base";
5
+ import Hash = require("../util/hash");
6
+ import { Chunk } from "../Chunk";
7
+ export type CompilationHooks = {
8
+ chunkHash: liteTapable.SyncHook<[Chunk, Hash]>;
10
9
  };
10
+ export declare class JavascriptModulesPlugin extends RspackBuiltinPlugin {
11
+ name: BuiltinPluginName;
12
+ affectedHooks: "compilation";
13
+ constructor();
14
+ raw(): BuiltinPlugin;
15
+ static getCompilationHooks(compilation: Compilation): CompilationHooks;
16
+ }
@@ -1,6 +1,55 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.JavascriptModulesPlugin = void 0;
4
27
  const binding_1 = require("@rspack/binding");
28
+ const Compilation_1 = require("../Compilation");
29
+ const liteTapable = __importStar(require("../lite-tapable"));
5
30
  const base_1 = require("./base");
6
- exports.JavascriptModulesPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.JavascriptModulesPlugin, () => { }, "compilation");
31
+ const compilationHooksMap = new WeakMap();
32
+ class JavascriptModulesPlugin extends base_1.RspackBuiltinPlugin {
33
+ constructor() {
34
+ super();
35
+ this.name = binding_1.BuiltinPluginName.JavascriptModulesPlugin;
36
+ this.affectedHooks = "compilation";
37
+ }
38
+ raw() {
39
+ return (0, base_1.createBuiltinPlugin)(this.name, undefined);
40
+ }
41
+ static getCompilationHooks(compilation) {
42
+ if (!(compilation instanceof Compilation_1.Compilation)) {
43
+ throw new TypeError("The 'compilation' argument must be an instance of Compilation");
44
+ }
45
+ let hooks = compilationHooksMap.get(compilation);
46
+ if (hooks === undefined) {
47
+ hooks = {
48
+ chunkHash: new liteTapable.SyncHook(["chunk", "hash"])
49
+ };
50
+ compilationHooksMap.set(compilation, hooks);
51
+ }
52
+ return hooks;
53
+ }
54
+ }
55
+ exports.JavascriptModulesPlugin = JavascriptModulesPlugin;
@@ -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,