@rspack/core 0.7.0 → 0.7.1-canary-06990bb-20240531053011

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.
@@ -90,6 +90,10 @@ export declare class Compilation {
90
90
  ExecuteModuleArgument,
91
91
  ExecuteModuleContext
92
92
  ]>;
93
+ additionalTreeRuntimeRequirements: liteTapable.SyncHook<[
94
+ Chunk,
95
+ Set<string>
96
+ ], void>;
93
97
  runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>;
94
98
  afterSeal: liteTapable.AsyncSeriesHook<[], void>;
95
99
  };
@@ -144,6 +144,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
144
144
  statsPrinter: new tapable.SyncHook(["statsPrinter", "options"]),
145
145
  buildModule: new liteTapable.SyncHook(["module"]),
146
146
  executeModule: new liteTapable.SyncHook(["options", "context"]),
147
+ additionalTreeRuntimeRequirements: new liteTapable.SyncHook([
148
+ "chunk",
149
+ "runtimeRequirements"
150
+ ]),
147
151
  runtimeModule: new liteTapable.SyncHook(["module", "chunk"]),
148
152
  afterSeal: new liteTapable.AsyncSeriesHook([])
149
153
  };
package/dist/Compiler.js CHANGED
@@ -591,6 +591,14 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
591
591
  }
592
592
  });
593
593
  }),
594
+ registerCompilationAdditionalTreeRuntimeRequirements: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind
595
+ .CompilationAdditionalTreeRuntimeRequirements, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.additionalTreeRuntimeRequirements, queried => ({ chunk, runtimeRequirements }) => {
596
+ const set = (0, RuntimeGlobals_1.__from_binding_runtime_globals)(runtimeRequirements);
597
+ queried.call(Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")), set);
598
+ return {
599
+ runtimeRequirements: (0, RuntimeGlobals_1.__to_binding_runtime_globals)(set)
600
+ };
601
+ }),
594
602
  registerCompilationRuntimeModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationRuntimeModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.runtimeModule, queried => ({ module, chunk }) => {
595
603
  const originSource = module.source?.source;
596
604
  queried.call(module, Chunk_1.Chunk.__from_binding(chunk, __classPrivateFieldGet(this, _Compiler_compilation, "f")));
@@ -7,6 +7,9 @@
7
7
  * Copyright (c) JS Foundation and other contributors
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
+ import { JsRuntimeGlobals } from "@rspack/binding";
11
+ export declare function __from_binding_runtime_globals(runtimeRequirements: JsRuntimeGlobals): Set<string>;
12
+ export declare function __to_binding_runtime_globals(runtimeRequirements: Set<string>): JsRuntimeGlobals;
10
13
  export declare const RuntimeGlobals: {
11
14
  /**
12
15
  * the internal require function
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuntimeGlobals = void 0;
4
2
  /**
5
3
  * The following code is modified based on
6
4
  * https://github.com/webpack/webpack/blob/v5.88.2/lib/RuntimeGlobals.js
@@ -10,6 +8,38 @@ exports.RuntimeGlobals = void 0;
10
8
  * Copyright (c) JS Foundation and other contributors
11
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
12
10
  */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RuntimeGlobals = exports.__to_binding_runtime_globals = exports.__from_binding_runtime_globals = void 0;
13
+ const REVERSE_RUNTIME_GLOBALS = new Map();
14
+ function __from_binding_runtime_globals(runtimeRequirements) {
15
+ const res = new Set();
16
+ for (let flag of runtimeRequirements.value) {
17
+ if (flag in exports.RuntimeGlobals) {
18
+ res.add(exports.RuntimeGlobals[flag]);
19
+ }
20
+ else {
21
+ res.add(flag);
22
+ }
23
+ }
24
+ return res;
25
+ }
26
+ exports.__from_binding_runtime_globals = __from_binding_runtime_globals;
27
+ function __to_binding_runtime_globals(runtimeRequirements) {
28
+ const res = {
29
+ value: []
30
+ };
31
+ for (let flag of Array.from(runtimeRequirements)) {
32
+ const item = REVERSE_RUNTIME_GLOBALS.get(flag);
33
+ if (typeof item === "string") {
34
+ res.value.push(item);
35
+ }
36
+ else {
37
+ res.value.push(flag);
38
+ }
39
+ }
40
+ return res;
41
+ }
42
+ exports.__to_binding_runtime_globals = __to_binding_runtime_globals;
13
43
  exports.RuntimeGlobals = {
14
44
  /**
15
45
  * the internal require function
@@ -322,3 +352,6 @@ exports.RuntimeGlobals = {
322
352
  */
323
353
  asyncModule: "__webpack_require__.a"
324
354
  };
355
+ for (let entry of Object.entries(exports.RuntimeGlobals)) {
356
+ REVERSE_RUNTIME_GLOBALS.set(entry[1], entry[0]);
357
+ }
@@ -27,6 +27,11 @@
27
27
  },
28
28
  "layer": {
29
29
  "type": "string"
30
+ },
31
+ "defaultExport": {
32
+ "type": "boolean",
33
+ "description": "Duplicate the named export with CSS modules locals to the default export (only when `esModules: true` for css-loader).",
34
+ "link": "https://github.com/webpack-contrib/mini-css-extract-plugin#defaultexports"
30
35
  }
31
36
  }
32
37
  }
@@ -9,6 +9,7 @@ export interface CssExtractRspackLoaderOptions {
9
9
  emit?: boolean;
10
10
  esModule?: boolean;
11
11
  layer?: boolean;
12
+ defaultExport?: boolean;
12
13
  }
13
14
  declare const loader: LoaderDefinition;
14
15
  export declare const pitch: LoaderDefinition["pitch"];
@@ -133,16 +133,39 @@ const pitch = function (request, _, data) {
133
133
  callback(e);
134
134
  return;
135
135
  }
136
- const result = locals
137
- ? namedExport
138
- ? Object.keys(locals)
139
- .map(key => `\nexport var ${key} = ${(0, utils_1.stringifyLocal)(
140
- /** @type {Locals} */ locals[key])};`)
141
- .join("")
142
- : `\n${esModule ? "export default" : "module.exports ="} ${JSON.stringify(locals)};`
143
- : esModule
144
- ? `\nexport {};`
145
- : "";
136
+ const result = (function makeResult() {
137
+ if (locals) {
138
+ if (namedExport) {
139
+ const identifiers = Array.from((function* generateIdentifiers() {
140
+ let identifierId = 0;
141
+ for (const key of Object.keys(locals)) {
142
+ identifierId += 1;
143
+ yield [`_${identifierId.toString(16)}`, key];
144
+ }
145
+ })());
146
+ const localsString = identifiers
147
+ .map(([id, key]) => `\nvar ${id} = ${(0, utils_1.stringifyLocal)(
148
+ /** @type {Locals} */ locals[key])};`)
149
+ .join("");
150
+ const exportsString = `export { ${identifiers
151
+ .map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
152
+ .join(", ")} }`;
153
+ const defaultExport = typeof options.defaultExport !== "undefined"
154
+ ? options.defaultExport
155
+ : false;
156
+ return defaultExport
157
+ ? `${localsString}\n${exportsString}\nexport default { ${identifiers
158
+ .map(([id, key]) => `${JSON.stringify(key)}: ${id}`)
159
+ .join(", ")} }\n`
160
+ : `${localsString}\n${exportsString}\n`;
161
+ }
162
+ return `\n${esModule ? "export default" : "module.exports = "} ${JSON.stringify(locals)};`;
163
+ }
164
+ else if (esModule) {
165
+ return "\nexport {};";
166
+ }
167
+ return "";
168
+ })();
146
169
  let resultSource = `// extracted by ${index_1.CssExtractRspackPlugin.pluginName}`;
147
170
  // only attempt hotreloading if the css is actually used for something other than hash values
148
171
  resultSource +=
@@ -457,7 +457,15 @@ function getRawJavascriptParserOptions(parser) {
457
457
  ? parser.url
458
458
  : "true",
459
459
  exprContextCritical: parser.exprContextCritical ?? true,
460
- wrappedContextCritical: parser.wrappedContextCritical ?? false
460
+ wrappedContextCritical: parser.wrappedContextCritical ?? false,
461
+ exportsPresence: parser.exportsPresence === false ? "false" : parser.exportsPresence,
462
+ importExportsPresence: parser.importExportsPresence === false
463
+ ? "false"
464
+ : parser.importExportsPresence,
465
+ reexportExportsPresence: parser.reexportExportsPresence === false
466
+ ? "false"
467
+ : parser.reexportExportsPresence,
468
+ strictExportPresence: parser.strictExportPresence ?? false
461
469
  };
462
470
  }
463
471
  function getRawAssetParserOptions(parser) {
@@ -5,7 +5,7 @@ import { Compiler } from "../Compiler";
5
5
  import { Logger } from "../logging/Logger";
6
6
  import Hash = require("../util/hash");
7
7
  import { Compilation } from "../Compilation";
8
- import { Mode, Resolve, RuleSetUseItem } from "./zod";
8
+ import { Mode, Resolve, RuleSetUseItem, Target } from "./zod";
9
9
  export interface ComposeJsUseOptions {
10
10
  devtool: RawOptions["devtool"];
11
11
  context: RawOptions["context"];
@@ -76,6 +76,7 @@ export interface LoaderContext<OptionsType = {}> {
76
76
  */
77
77
  loaders: LoaderObject[];
78
78
  mode?: Mode;
79
+ target?: Target;
79
80
  hot?: boolean;
80
81
  /**
81
82
  * @param schema To provide the best performance, Rspack does not perform the schema validation. If your loader requires schema validation, please call scheme-utils or zod on your own.
@@ -82,6 +82,10 @@ const applyRspackOptionsDefaults = (options) => {
82
82
  : "var";
83
83
  });
84
84
  applyNodeDefaults(options.node, { targetProperties });
85
+ applyLoaderDefaults(options.loader, {
86
+ targetProperties,
87
+ environment: options.output.environment
88
+ });
85
89
  F(options, "performance", () => production &&
86
90
  targetProperties &&
87
91
  (targetProperties.browser || targetProperties.browser === null)
@@ -139,6 +143,10 @@ const applyJavascriptParserOptionsDefaults = (parserOptions, fallback) => {
139
143
  D(parserOptions, "url", fallback?.url ?? true);
140
144
  D(parserOptions, "exprContextCritical", fallback?.exprContextCritical ?? true);
141
145
  D(parserOptions, "wrappedContextCritical", fallback?.wrappedContextCritical ?? false);
146
+ D(parserOptions, "exportsPresence", fallback?.exportsPresence);
147
+ D(parserOptions, "importExportsPresence", fallback?.importExportsPresence);
148
+ D(parserOptions, "reexportExportsPresence", fallback?.reexportExportsPresence);
149
+ D(parserOptions, "strictExportPresence", fallback?.strictExportPresence ?? false);
142
150
  };
143
151
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
144
152
  (0, assertNotNil_1.assertNotNill)(module.parser);
@@ -600,6 +608,28 @@ const applyExternalsPresetsDefaults = (externalsPresets, { targetProperties }) =
600
608
  targetProperties.electron &&
601
609
  targetProperties.electronRenderer);
602
610
  };
611
+ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
612
+ F(loader, "target", () => {
613
+ if (targetProperties) {
614
+ if (targetProperties.electron) {
615
+ if (targetProperties.electronMain)
616
+ return "electron-main";
617
+ if (targetProperties.electronPreload)
618
+ return "electron-preload";
619
+ if (targetProperties.electronRenderer)
620
+ return "electron-renderer";
621
+ return "electron";
622
+ }
623
+ if (targetProperties.nwjs)
624
+ return "nwjs";
625
+ if (targetProperties.node)
626
+ return "node";
627
+ if (targetProperties.web)
628
+ return "web";
629
+ }
630
+ });
631
+ D(loader, "environment", environment);
632
+ };
603
633
  const applyNodeDefaults = (node, { targetProperties }) => {
604
634
  if (node === false)
605
635
  return;
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type { Compilation } from "../Compilation";
11
- import type { AssetModuleFilename, Bail, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LazyCompilationOptions, LibraryOptions, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
11
+ import type { AssetModuleFilename, Bail, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LazyCompilationOptions, LibraryOptions, Loader, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
13
  export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
14
  export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
@@ -110,6 +110,7 @@ export interface RspackOptionsNormalized {
110
110
  infrastructureLogging: InfrastructureLogging;
111
111
  devtool?: DevTool;
112
112
  node: Node;
113
+ loader: Loader;
113
114
  snapshot: SnapshotOptions;
114
115
  cache?: CacheOptions;
115
116
  stats: StatsValue;
@@ -144,6 +144,7 @@ const getNormalizedRspackOptions = (config) => {
144
144
  node: nestedConfig(config.node, node => node && {
145
145
  ...node
146
146
  }),
147
+ loader: cloneObject(config.loader),
147
148
  snapshot: nestedConfig(config.snapshot, _snapshot => ({})),
148
149
  cache: optionalNestedConfig(config.cache, cache => cache),
149
150
  stats: nestedConfig(config.stats, stats => {