@rspack/core 1.0.10 → 1.0.12

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 (219) hide show
  1. package/compiled/browserslist/index.js +94 -49
  2. package/compiled/browserslist/package.json +1 -1
  3. package/dist/builtin-plugin/css-extract/utils.d.ts +1 -0
  4. package/dist/config/types.d.ts +309 -0
  5. package/dist/config/zod.d.ts +22 -534
  6. package/dist/cssExtractHmr.js +224 -0
  7. package/dist/cssExtractLoader.js +277 -0
  8. package/dist/index.js +23255 -31
  9. package/dist/{builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts → runtime/cssExtractHmr.d.ts} +1 -0
  10. package/dist/runtime/moduleFederationDefaultRuntime.d.ts +2 -0
  11. package/dist/stats/statsFactoryUtils.d.ts +1 -0
  12. package/package.json +8 -5
  13. package/compiled/json-parse-even-better-errors/index.d.ts +0 -1
  14. package/compiled/json-parse-even-better-errors/index.js +0 -193
  15. package/compiled/json-parse-even-better-errors/package.json +0 -1
  16. package/compiled/neo-async/index.d.ts +0 -685
  17. package/compiled/neo-async/index.js +0 -9207
  18. package/compiled/neo-async/license +0 -22
  19. package/compiled/neo-async/package.json +0 -1
  20. package/compiled/zod-validation-error/index.d.ts +0 -41
  21. package/compiled/zod-validation-error/index.js +0 -335
  22. package/compiled/zod-validation-error/license +0 -9
  23. package/compiled/zod-validation-error/package.json +0 -1
  24. package/dist/Chunk.js +0 -118
  25. package/dist/ChunkGraph.js +0 -27
  26. package/dist/ChunkGroup.js +0 -76
  27. package/dist/Compilation.js +0 -854
  28. package/dist/Compiler.js +0 -925
  29. package/dist/ContextModuleFactory.js +0 -36
  30. package/dist/DependenciesBlock.js +0 -30
  31. package/dist/Dependency.js +0 -43
  32. package/dist/Entrypoint.js +0 -21
  33. package/dist/ErrorHelpers.js +0 -62
  34. package/dist/ExecuteModulePlugin.js +0 -46
  35. package/dist/FileSystem.js +0 -34
  36. package/dist/FileSystemInfo.js +0 -2
  37. package/dist/Module.js +0 -226
  38. package/dist/ModuleTypeConstants.js +0 -92
  39. package/dist/MultiCompiler.js +0 -440
  40. package/dist/MultiStats.js +0 -161
  41. package/dist/MultiWatching.js +0 -62
  42. package/dist/NormalModule.js +0 -97
  43. package/dist/NormalModuleFactory.js +0 -43
  44. package/dist/Resolver.js +0 -39
  45. package/dist/ResolverFactory.js +0 -61
  46. package/dist/RspackError.js +0 -21
  47. package/dist/RuleSetCompiler.js +0 -10
  48. package/dist/RuntimeGlobals.js +0 -357
  49. package/dist/RuntimeModule.js +0 -58
  50. package/dist/Stats.js +0 -161
  51. package/dist/Template.js +0 -206
  52. package/dist/Watching.js +0 -290
  53. package/dist/builtin-loader/index.js +0 -17
  54. package/dist/builtin-loader/lightningcss/index.js +0 -175
  55. package/dist/builtin-loader/swc/index.js +0 -5
  56. package/dist/builtin-loader/swc/pluginImport.js +0 -35
  57. package/dist/builtin-loader/swc/react.js +0 -7
  58. package/dist/builtin-loader/swc/types.js +0 -2
  59. package/dist/builtin-plugin/APIPlugin.js +0 -6
  60. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.js +0 -6
  61. package/dist/builtin-plugin/AssetModulesPlugin.js +0 -6
  62. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.js +0 -6
  63. package/dist/builtin-plugin/BannerPlugin.js +0 -22
  64. package/dist/builtin-plugin/BundlerInfoRspackPlugin.js +0 -12
  65. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.js +0 -6
  66. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.js +0 -6
  67. package/dist/builtin-plugin/ContextReplacementPlugin.js +0 -43
  68. package/dist/builtin-plugin/CopyRspackPlugin.js +0 -21
  69. package/dist/builtin-plugin/CssModulesPlugin.js +0 -6
  70. package/dist/builtin-plugin/DataUriPlugin.js +0 -6
  71. package/dist/builtin-plugin/DefinePlugin.js +0 -44
  72. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.js +0 -6
  73. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.js +0 -6
  74. package/dist/builtin-plugin/DynamicEntryPlugin.js +0 -36
  75. package/dist/builtin-plugin/ElectronTargetPlugin.js +0 -6
  76. package/dist/builtin-plugin/EnableChunkLoadingPlugin.js +0 -6
  77. package/dist/builtin-plugin/EnableLibraryPlugin.js +0 -39
  78. package/dist/builtin-plugin/EnableWasmLoadingPlugin.js +0 -6
  79. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.js +0 -6
  80. package/dist/builtin-plugin/EntryPlugin.js +0 -34
  81. package/dist/builtin-plugin/EvalDevToolModulePlugin.js +0 -6
  82. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.js +0 -16
  83. package/dist/builtin-plugin/ExternalsPlugin.js +0 -51
  84. package/dist/builtin-plugin/FetchCompileAsyncWasmPlugin.js +0 -6
  85. package/dist/builtin-plugin/FileUriPlugin.js +0 -6
  86. package/dist/builtin-plugin/FlagDependencyExportsPlugin.js +0 -6
  87. package/dist/builtin-plugin/FlagDependencyUsagePlugin.js +0 -6
  88. package/dist/builtin-plugin/HotModuleReplacementPlugin.js +0 -18
  89. package/dist/builtin-plugin/HtmlRspackPlugin.js +0 -285
  90. package/dist/builtin-plugin/HttpExternalsRspackPlugin.js +0 -11
  91. package/dist/builtin-plugin/IgnorePlugin.js +0 -20
  92. package/dist/builtin-plugin/InferAsyncModulesPlugin.js +0 -6
  93. package/dist/builtin-plugin/JavascriptModulesPlugin.js +0 -55
  94. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +0 -9
  95. package/dist/builtin-plugin/JsonModulesPlugin.js +0 -6
  96. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +0 -30
  97. package/dist/builtin-plugin/LimitChunkCountPlugin.js +0 -8
  98. package/dist/builtin-plugin/MangleExportsPlugin.js +0 -6
  99. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.js +0 -6
  100. package/dist/builtin-plugin/ModuleChunkFormatPlugin.js +0 -6
  101. package/dist/builtin-plugin/ModuleConcatenationPlugin.js +0 -6
  102. package/dist/builtin-plugin/NamedChunkIdsPlugin.js +0 -6
  103. package/dist/builtin-plugin/NamedModuleIdsPlugin.js +0 -6
  104. package/dist/builtin-plugin/NaturalChunkIdsPlugin.js +0 -6
  105. package/dist/builtin-plugin/NaturalModuleIdsPlugin.js +0 -6
  106. package/dist/builtin-plugin/NoEmitOnErrorsPlugin.js +0 -6
  107. package/dist/builtin-plugin/NodeTargetPlugin.js +0 -6
  108. package/dist/builtin-plugin/ProgressPlugin.js +0 -15
  109. package/dist/builtin-plugin/ProvidePlugin.js +0 -14
  110. package/dist/builtin-plugin/RealContentHashPlugin.js +0 -6
  111. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.js +0 -6
  112. package/dist/builtin-plugin/RuntimeChunkPlugin.js +0 -6
  113. package/dist/builtin-plugin/RuntimePlugin.js +0 -6
  114. package/dist/builtin-plugin/SideEffectsFlagPlugin.js +0 -6
  115. package/dist/builtin-plugin/SizeLimitsPlugin.js +0 -9
  116. package/dist/builtin-plugin/SourceMapDevToolPlugin.js +0 -14
  117. package/dist/builtin-plugin/SplitChunksPlugin.js +0 -92
  118. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +0 -80
  119. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.js +0 -6
  120. package/dist/builtin-plugin/WebWorkerTemplatePlugin.js +0 -6
  121. package/dist/builtin-plugin/WorkerPlugin.js +0 -31
  122. package/dist/builtin-plugin/base.js +0 -58
  123. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +0 -182
  124. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +0 -2
  125. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.js +0 -31
  126. package/dist/builtin-plugin/css-extract/index.js +0 -105
  127. package/dist/builtin-plugin/css-extract/loader.js +0 -204
  128. package/dist/builtin-plugin/css-extract/utils.js +0 -51
  129. package/dist/builtin-plugin/index.js +0 -84
  130. package/dist/builtin-plugin/lazy-compilation/backend.js +0 -139
  131. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.js +0 -6
  132. package/dist/builtin-plugin/lazy-compilation/plugin.js +0 -60
  133. package/dist/config/adapter.js +0 -691
  134. package/dist/config/adapterRuleUse.js +0 -107
  135. package/dist/config/browserslistTargetHandler.js +0 -345
  136. package/dist/config/defaults.js +0 -876
  137. package/dist/config/index.js +0 -20
  138. package/dist/config/normalization.js +0 -299
  139. package/dist/config/target.js +0 -318
  140. package/dist/config/types.js +0 -3
  141. package/dist/config/zod.js +0 -1030
  142. package/dist/container/ContainerPlugin.js +0 -50
  143. package/dist/container/ContainerReferencePlugin.js +0 -49
  144. package/dist/container/ModuleFederationPlugin.js +0 -137
  145. package/dist/container/ModuleFederationPluginV1.js +0 -63
  146. package/dist/container/ModuleFederationRuntimePlugin.js +0 -6
  147. package/dist/container/options.js +0 -48
  148. package/dist/error/ConcurrentCompilationError.js +0 -20
  149. package/dist/exports.js +0 -183
  150. package/dist/lib/AbstractMethodError.js +0 -51
  151. package/dist/lib/Cache.js +0 -111
  152. package/dist/lib/CacheFacade.js +0 -321
  153. package/dist/lib/Dependency.js +0 -11
  154. package/dist/lib/EntryOptionPlugin.js +0 -89
  155. package/dist/lib/EnvironmentPlugin.js +0 -57
  156. package/dist/lib/HookWebpackError.js +0 -83
  157. package/dist/lib/IgnoreWarningsPlugin.js +0 -35
  158. package/dist/lib/LoaderOptionsPlugin.js +0 -74
  159. package/dist/lib/LoaderTargetPlugin.js +0 -37
  160. package/dist/lib/ModuleFilenameHelpers.js +0 -83
  161. package/dist/lib/NormalModuleReplacementPlugin.js +0 -85
  162. package/dist/lib/WebpackError.js +0 -20
  163. package/dist/lib/cache/MemoryCachePlugin.js +0 -40
  164. package/dist/lib/cache/getLazyHashedEtag.js +0 -73
  165. package/dist/lib/cache/mergeEtags.js +0 -74
  166. package/dist/lib/formatLocation.js +0 -64
  167. package/dist/loader-runner/LoaderLoadingError.js +0 -19
  168. package/dist/loader-runner/index.js +0 -735
  169. package/dist/loader-runner/loadLoader.js +0 -64
  170. package/dist/logging/Logger.js +0 -143
  171. package/dist/logging/createConsoleLogger.js +0 -176
  172. package/dist/logging/runtime.js +0 -37
  173. package/dist/logging/truncateArgs.js +0 -81
  174. package/dist/node/NodeEnvironmentPlugin.js +0 -50
  175. package/dist/node/NodeTemplatePlugin.js +0 -26
  176. package/dist/node/NodeWatchFileSystem.js +0 -144
  177. package/dist/node/nodeConsole.js +0 -146
  178. package/dist/rspack.js +0 -123
  179. package/dist/rspackOptionsApply.js +0 -274
  180. package/dist/sharing/ConsumeSharedPlugin.js +0 -69
  181. package/dist/sharing/ProvideSharedPlugin.js +0 -50
  182. package/dist/sharing/SharePlugin.js +0 -66
  183. package/dist/sharing/ShareRuntimePlugin.js +0 -26
  184. package/dist/sharing/utils.js +0 -8
  185. package/dist/stats/DefaultStatsFactoryPlugin.js +0 -1173
  186. package/dist/stats/DefaultStatsPresetPlugin.js +0 -305
  187. package/dist/stats/DefaultStatsPrinterPlugin.js +0 -1069
  188. package/dist/stats/StatsFactory.js +0 -167
  189. package/dist/stats/StatsPrinter.js +0 -142
  190. package/dist/stats/statsFactoryUtils.js +0 -341
  191. package/dist/util/ArrayQueue.js +0 -108
  192. package/dist/util/AssetInfo.js +0 -39
  193. package/dist/util/IterableHelpers.js +0 -35
  194. package/dist/util/MergeCaller.js +0 -24
  195. package/dist/util/SizeFormatHelpers.js +0 -24
  196. package/dist/util/SplitChunkSize.js +0 -18
  197. package/dist/util/assertNotNil.js +0 -9
  198. package/dist/util/assetCondition.js +0 -2
  199. package/dist/util/bindingVersionCheck.js +0 -124
  200. package/dist/util/cleverMerge.js +0 -504
  201. package/dist/util/comparators.js +0 -108
  202. package/dist/util/createHash.js +0 -161
  203. package/dist/util/createReadonlyMap.js +0 -29
  204. package/dist/util/fake.js +0 -28
  205. package/dist/util/fs.js +0 -120
  206. package/dist/util/hash/BatchedHash.js +0 -69
  207. package/dist/util/hash/index.js +0 -39
  208. package/dist/util/hash/md4.js +0 -27
  209. package/dist/util/hash/wasm-hash.js +0 -167
  210. package/dist/util/hash/xxhash64.js +0 -27
  211. package/dist/util/identifier.js +0 -330
  212. package/dist/util/index.js +0 -123
  213. package/dist/util/memoize.js +0 -61
  214. package/dist/util/scheme.js +0 -57
  215. package/dist/util/smartGrouping.js +0 -148
  216. package/dist/util/source.js +0 -42
  217. package/dist/util/validate.js +0 -77
  218. package/dist/util/webpack.js +0 -27
  219. /package/dist/{container/default.runtime.js → moduleFederationDefaultRuntime.js} +0 -0
@@ -1,735 +0,0 @@
1
- "use strict";
2
- /**
3
- * The following code is modified based on
4
- * https://github.com/webpack/loader-runner
5
- *
6
- * MIT Licensed
7
- * Author Tobias Koppers @sokra
8
- * Copyright (c) JS Foundation and other contributors
9
- * https://github.com/webpack/loader-runner/blob/main/LICENSE
10
- */
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
- if (kind === "m") throw new TypeError("Private method is not writable");
13
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
- };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- var _LoaderObject_loaderItem;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.parsePathQueryFragment = exports.runLoaders = exports.LoaderObject = void 0;
28
- const node_querystring_1 = __importDefault(require("node:querystring"));
29
- const node_assert_1 = __importDefault(require("node:assert"));
30
- const node_util_1 = require("node:util");
31
- const binding_1 = require("@rspack/binding");
32
- const webpack_sources_1 = require("../../compiled/webpack-sources");
33
- const Module_1 = require("../Module");
34
- const NormalModule_1 = require("../NormalModule");
35
- const RspackError_1 = require("../RspackError");
36
- const adapterRuleUse_1 = require("../config/adapterRuleUse");
37
- const util_1 = require("../util");
38
- const createHash_1 = require("../util/createHash");
39
- const identifier_1 = require("../util/identifier");
40
- const memoize_1 = require("../util/memoize");
41
- const loadLoader_1 = __importDefault(require("./loadLoader"));
42
- function createLoaderObject(loader, compiler) {
43
- const obj = {
44
- path: null,
45
- query: null,
46
- fragment: null,
47
- options: null,
48
- ident: null,
49
- normal: null,
50
- pitch: null,
51
- raw: null,
52
- data: null,
53
- pitchExecuted: false,
54
- normalExecuted: false
55
- };
56
- Object.defineProperty(obj, "request", {
57
- enumerable: true,
58
- get: () => obj.path.replace(/#/g, "\u200b#") +
59
- obj.query.replace(/#/g, "\u200b#") +
60
- obj.fragment,
61
- set: value => {
62
- const splittedRequest = (0, identifier_1.parseResourceWithoutFragment)(value.request);
63
- obj.path = splittedRequest.path;
64
- obj.query = splittedRequest.query;
65
- obj.fragment = "";
66
- obj.options =
67
- obj.options === null
68
- ? splittedRequest.query
69
- ? splittedRequest.query.slice(1)
70
- : undefined
71
- : obj.options;
72
- if (typeof obj.options === "string" && obj.options[0] === "?") {
73
- const ident = obj.options.slice(1);
74
- if (ident === "[[missing ident]]") {
75
- throw new Error("No ident is provided by referenced loader. " +
76
- "When using a function for Rule.use in config you need to " +
77
- "provide an 'ident' property for referenced loader options.");
78
- }
79
- obj.options = compiler.__internal__ruleSet.references.get(ident);
80
- if (obj.options === undefined) {
81
- throw new Error("Invalid ident is provided by referenced loader");
82
- }
83
- obj.ident = ident;
84
- }
85
- // CHANGE: `rspack_core` returns empty string for `undefined` type.
86
- // Comply to webpack test case: tests/webpack-test/cases/loaders/cjs-loader-type/index.js
87
- obj.type = value.type === "" ? undefined : value.type;
88
- if (obj.options === null)
89
- obj.query = "";
90
- else if (obj.options === undefined)
91
- obj.query = "";
92
- else if (typeof obj.options === "string")
93
- obj.query = `?${obj.options}`;
94
- else if (obj.ident)
95
- obj.query = `??${obj.ident}`;
96
- else if (typeof obj.options === "object" && obj.options.ident)
97
- obj.query = `??${obj.options.ident}`;
98
- else
99
- obj.query = `?${JSON.stringify(obj.options)}`;
100
- }
101
- });
102
- obj.request = loader;
103
- if (Object.preventExtensions) {
104
- Object.preventExtensions(obj);
105
- }
106
- return obj;
107
- }
108
- class LoaderObject {
109
- constructor(loaderItem, compiler) {
110
- _LoaderObject_loaderItem.set(this, void 0);
111
- const { request, path, query, fragment, options, ident, normal, pitch, raw, type } = createLoaderObject(loaderItem, compiler);
112
- this.request = request;
113
- this.path = path;
114
- this.query = query;
115
- this.fragment = fragment;
116
- this.options = options;
117
- this.ident = ident;
118
- this.normal = normal;
119
- this.pitch = pitch;
120
- this.raw = raw;
121
- this.type = type;
122
- __classPrivateFieldSet(this, _LoaderObject_loaderItem, loaderItem, "f");
123
- }
124
- get pitchExecuted() {
125
- return __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").pitchExecuted;
126
- }
127
- set pitchExecuted(value) {
128
- (0, node_assert_1.default)(value);
129
- __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").pitchExecuted = true;
130
- }
131
- get normalExecuted() {
132
- return __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").normalExecuted;
133
- }
134
- set normalExecuted(value) {
135
- (0, node_assert_1.default)(value);
136
- __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").normalExecuted = true;
137
- }
138
- // A data object shared between the pitch and the normal phase
139
- get data() {
140
- return new Proxy((__classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").data = __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").data ?? {}), {
141
- set: (_, property, value) => {
142
- if (typeof property === "string") {
143
- __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").data[property] = value;
144
- }
145
- return true;
146
- },
147
- get: (_, property) => {
148
- if (typeof property === "string") {
149
- return __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").data[property];
150
- }
151
- }
152
- });
153
- }
154
- // A data object shared between the pitch and the normal phase
155
- set data(data) {
156
- __classPrivateFieldGet(this, _LoaderObject_loaderItem, "f").data = data;
157
- }
158
- shouldYield() {
159
- return this.request.startsWith(adapterRuleUse_1.BUILTIN_LOADER_PREFIX);
160
- }
161
- static __from_binding(loaderItem, compiler) {
162
- return new this(loaderItem, compiler);
163
- }
164
- static __to_binding(loader) {
165
- return __classPrivateFieldGet(loader, _LoaderObject_loaderItem, "f");
166
- }
167
- }
168
- exports.LoaderObject = LoaderObject;
169
- _LoaderObject_loaderItem = new WeakMap();
170
- class JsSourceMap {
171
- static __from_binding(map) {
172
- return (0, util_1.isNil)(map) ? undefined : (0, util_1.toObject)(map);
173
- }
174
- static __to_binding(map) {
175
- return (0, util_1.serializeObject)(map);
176
- }
177
- }
178
- const loadLoaderAsync = (0, node_util_1.promisify)(loadLoader_1.default);
179
- const runSyncOrAsync = (0, node_util_1.promisify)(function runSyncOrAsync(fn, context, args, callback) {
180
- let isSync = true;
181
- let isDone = false;
182
- let isError = false; // internal error
183
- let reportedError = false;
184
- context.async = function async() {
185
- if (isDone) {
186
- if (reportedError)
187
- return undefined; // ignore
188
- throw new Error("async(): The callback was already called.");
189
- }
190
- isSync = false;
191
- return innerCallback;
192
- };
193
- const innerCallback = (err, ...args) => {
194
- if (isDone) {
195
- if (reportedError)
196
- return; // ignore
197
- throw new Error("callback(): The callback was already called.");
198
- }
199
- isDone = true;
200
- isSync = false;
201
- try {
202
- callback(err, args);
203
- }
204
- catch (e) {
205
- isError = true;
206
- throw e;
207
- }
208
- };
209
- context.callback = innerCallback;
210
- try {
211
- const result = (function LOADER_EXECUTION() {
212
- return fn.apply(context, args);
213
- })();
214
- if (isSync) {
215
- isDone = true;
216
- if (result === undefined) {
217
- callback(null, []);
218
- return;
219
- }
220
- if (result &&
221
- typeof result === "object" &&
222
- typeof result.then === "function") {
223
- result.then((r) => {
224
- callback(null, [r]);
225
- }, callback);
226
- return;
227
- }
228
- callback(null, [result]);
229
- return;
230
- }
231
- }
232
- catch (e) {
233
- // use string for napi getter
234
- const err = e;
235
- if ("hideStack" in err && err.hideStack) {
236
- err.hideStack = "true";
237
- }
238
- if (isError)
239
- throw e;
240
- if (isDone) {
241
- // loader is already "done", so we cannot use the callback function
242
- // for better debugging we print the error on the console
243
- if (e instanceof Error)
244
- console.error(e.stack);
245
- else
246
- console.error(e);
247
- return;
248
- }
249
- isDone = true;
250
- reportedError = true;
251
- callback(e, []);
252
- }
253
- });
254
- function dirname(path) {
255
- if (path === "/")
256
- return "/";
257
- const i = path.lastIndexOf("/");
258
- const j = path.lastIndexOf("\\");
259
- const i2 = path.indexOf("/");
260
- const j2 = path.indexOf("\\");
261
- const idx = i > j ? i : j;
262
- const idx2 = i > j ? i2 : j2;
263
- if (idx < 0)
264
- return path;
265
- if (idx === idx2)
266
- return path.slice(0, idx + 1);
267
- return path.slice(0, idx);
268
- }
269
- function getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
270
- if (loaderContext.loaders?.length &&
271
- index < loaderContext.loaders.length &&
272
- index >= 0 &&
273
- loaderContext.loaders[index]) {
274
- return loaderContext.loaders[index];
275
- }
276
- return null;
277
- }
278
- async function runLoaders(compiler, context) {
279
- const loaderState = context.loaderState;
280
- //
281
- const { resource } = context.resourceData;
282
- const splittedResource = resource && parsePathQueryFragment(resource);
283
- const resourcePath = splittedResource ? splittedResource.path : undefined;
284
- const resourceQuery = splittedResource ? splittedResource.query : undefined;
285
- const resourceFragment = splittedResource
286
- ? splittedResource.fragment
287
- : undefined;
288
- const contextDirectory = resourcePath ? dirname(resourcePath) : null;
289
- // execution state
290
- const fileDependencies = context.fileDependencies;
291
- const contextDependencies = context.contextDependencies;
292
- const missingDependencies = context.missingDependencies;
293
- const buildDependencies = context.buildDependencies;
294
- /// Construct `loaderContext`
295
- const loaderContext = {};
296
- loaderContext.loaders = context.loaderItems.map(item => {
297
- return LoaderObject.__from_binding(item, compiler);
298
- });
299
- loaderContext.hot = context.hot;
300
- loaderContext.context = contextDirectory;
301
- loaderContext.resourcePath = resourcePath;
302
- loaderContext.resourceQuery = resourceQuery;
303
- loaderContext.resourceFragment = resourceFragment;
304
- loaderContext.dependency = loaderContext.addDependency =
305
- function addDependency(file) {
306
- fileDependencies.push(file);
307
- };
308
- loaderContext.addContextDependency = function addContextDependency(context) {
309
- contextDependencies.push(context);
310
- };
311
- loaderContext.addMissingDependency = function addMissingDependency(context) {
312
- missingDependencies.push(context);
313
- };
314
- loaderContext.addBuildDependency = function addBuildDependency(file) {
315
- buildDependencies.push(file);
316
- };
317
- loaderContext.getDependencies = function getDependencies() {
318
- return fileDependencies.slice();
319
- };
320
- loaderContext.getContextDependencies = function getContextDependencies() {
321
- return contextDependencies.slice();
322
- };
323
- loaderContext.getMissingDependencies = function getMissingDependencies() {
324
- return missingDependencies.slice();
325
- };
326
- loaderContext.clearDependencies = function clearDependencies() {
327
- fileDependencies.length = 0;
328
- contextDependencies.length = 0;
329
- missingDependencies.length = 0;
330
- context.cacheable = true;
331
- };
332
- loaderContext.importModule = function importModule(request, userOptions, callback) {
333
- const options = userOptions ? userOptions : {};
334
- if (!callback) {
335
- return new Promise((resolve, reject) => {
336
- compiler
337
- ._lastCompilation.__internal_getInner()
338
- .importModule(request, options.layer, options.publicPath, options.baseUri, context._module.moduleIdentifier, loaderContext.context, (err, res) => {
339
- if (err)
340
- reject(err);
341
- else {
342
- for (const dep of res.buildDependencies) {
343
- this.addBuildDependency(dep);
344
- }
345
- for (const dep of res.contextDependencies) {
346
- this.addContextDependency(dep);
347
- }
348
- for (const dep of res.missingDependencies) {
349
- this.addMissingDependency(dep);
350
- }
351
- for (const dep of res.fileDependencies) {
352
- this.addDependency(dep);
353
- }
354
- if (res.cacheable === false) {
355
- this.cacheable(false);
356
- }
357
- resolve(compiler.__internal__getModuleExecutionResult(res.id));
358
- }
359
- });
360
- });
361
- }
362
- return compiler
363
- ._lastCompilation.__internal_getInner()
364
- .importModule(request, options.layer, options.publicPath, options.baseUri, context._module.moduleIdentifier, loaderContext.context, (err, res) => {
365
- if (err) {
366
- callback(err, undefined);
367
- }
368
- else {
369
- for (const dep of res.buildDependencies) {
370
- this.addBuildDependency(dep);
371
- }
372
- for (const dep of res.contextDependencies) {
373
- this.addContextDependency(dep);
374
- }
375
- for (const dep of res.missingDependencies) {
376
- this.addMissingDependency(dep);
377
- }
378
- for (const dep of res.fileDependencies) {
379
- this.addDependency(dep);
380
- }
381
- if (res.cacheable === false) {
382
- this.cacheable(false);
383
- }
384
- callback(undefined, compiler.__internal__getModuleExecutionResult(res.id));
385
- }
386
- });
387
- };
388
- Object.defineProperty(loaderContext, "resource", {
389
- enumerable: true,
390
- get: () => {
391
- if (loaderContext.resourcePath === undefined)
392
- return undefined;
393
- return (loaderContext.resourcePath.replace(/#/g, "\u200b#") +
394
- loaderContext.resourceQuery.replace(/#/g, "\u200b#") +
395
- loaderContext.resourceFragment);
396
- },
397
- set: value => {
398
- const splittedResource = value && parsePathQueryFragment(value);
399
- loaderContext.resourcePath = splittedResource
400
- ? splittedResource.path
401
- : undefined;
402
- loaderContext.resourceQuery = splittedResource
403
- ? splittedResource.query
404
- : undefined;
405
- loaderContext.resourceFragment = splittedResource
406
- ? splittedResource.fragment
407
- : undefined;
408
- }
409
- });
410
- Object.defineProperty(loaderContext, "request", {
411
- enumerable: true,
412
- get: () => loaderContext.loaders
413
- .map(o => o.request)
414
- .concat(loaderContext.resource || "")
415
- .join("!")
416
- });
417
- Object.defineProperty(loaderContext, "remainingRequest", {
418
- enumerable: true,
419
- get: () => {
420
- if (loaderContext.loaderIndex >= loaderContext.loaders.length - 1 &&
421
- !loaderContext.resource)
422
- return "";
423
- return loaderContext.loaders
424
- .slice(loaderContext.loaderIndex + 1)
425
- .map(o => o.request)
426
- .concat(loaderContext.resource || "")
427
- .join("!");
428
- }
429
- });
430
- Object.defineProperty(loaderContext, "currentRequest", {
431
- enumerable: true,
432
- get: () => loaderContext.loaders
433
- .slice(loaderContext.loaderIndex)
434
- .map(o => o.request)
435
- .concat(loaderContext.resource || "")
436
- .join("!")
437
- });
438
- Object.defineProperty(loaderContext, "previousRequest", {
439
- enumerable: true,
440
- get: () => loaderContext.loaders
441
- .slice(0, loaderContext.loaderIndex)
442
- .map(o => o.request)
443
- .join("!")
444
- });
445
- Object.defineProperty(loaderContext, "query", {
446
- enumerable: true,
447
- get: () => {
448
- const entry = loaderContext.loaders[loaderContext.loaderIndex];
449
- return entry.options && typeof entry.options === "object"
450
- ? entry.options
451
- : entry.query;
452
- }
453
- });
454
- loaderContext.version = 2;
455
- loaderContext.sourceMap = compiler.options.devtool
456
- ? (0, adapterRuleUse_1.isUseSourceMap)(compiler.options.devtool)
457
- : context._module.useSourceMap ?? false;
458
- loaderContext.mode = compiler.options.mode;
459
- Object.assign(loaderContext, compiler.options.loader);
460
- const getResolveContext = () => {
461
- return {
462
- fileDependencies: {
463
- // @ts-expect-error: Mocking insert-only `Set<T>`
464
- add: d => {
465
- loaderContext.addDependency(d);
466
- }
467
- },
468
- contextDependencies: {
469
- // @ts-expect-error: Mocking insert-only `Set<T>`
470
- add: d => {
471
- loaderContext.addContextDependency(d);
472
- }
473
- },
474
- missingDependencies: {
475
- // @ts-expect-error: Mocking insert-only `Set<T>`
476
- add: d => {
477
- loaderContext.addMissingDependency(d);
478
- }
479
- }
480
- };
481
- };
482
- const resolver = compiler._lastCompilation.resolverFactory.get("normal");
483
- loaderContext.resolve = function resolve(context, request, callback) {
484
- resolver.resolve({}, context, request, getResolveContext(), callback);
485
- };
486
- loaderContext.getResolve = function getResolve(options) {
487
- const child = options ? resolver.withOptions(options) : resolver;
488
- return (context, request, callback) => {
489
- if (callback) {
490
- child.resolve({}, context, request, getResolveContext(), callback);
491
- return;
492
- }
493
- // TODO: (type) our native resolver return value is "string | false" but webpack type is "string"
494
- return new Promise((resolve, reject) => {
495
- child.resolve({}, context, request, getResolveContext(), (err, result) => {
496
- if (err)
497
- reject(err);
498
- else
499
- resolve(result);
500
- });
501
- });
502
- };
503
- };
504
- loaderContext.getLogger = function getLogger(name) {
505
- return compiler._lastCompilation.getLogger([name, resource].filter(Boolean).join("|"));
506
- };
507
- loaderContext.rootContext = compiler.context;
508
- loaderContext.emitError = function emitError(err) {
509
- let error = err;
510
- if (!(error instanceof Error)) {
511
- error = new RspackError_1.NonErrorEmittedError(error);
512
- }
513
- error.name = "ModuleError";
514
- error.message = `${error.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
515
- error = (0, util_1.concatErrorMsgAndStack)(error);
516
- error.moduleIdentifier = this._module.identifier();
517
- compiler._lastCompilation.__internal__pushRspackDiagnostic({
518
- error,
519
- severity: binding_1.JsRspackSeverity.Error
520
- });
521
- };
522
- loaderContext.emitWarning = function emitWarning(warn) {
523
- let warning = warn;
524
- if (!(warning instanceof Error)) {
525
- warning = new RspackError_1.NonErrorEmittedError(warning);
526
- }
527
- warning.name = "ModuleWarning";
528
- warning.message = `${warning.message} (from: ${(0, util_1.stringifyLoaderObject)(loaderContext.loaders[loaderContext.loaderIndex])})`;
529
- warning = (0, util_1.concatErrorMsgAndStack)(warning);
530
- warning.moduleIdentifier = this._module.identifier();
531
- compiler._lastCompilation.__internal__pushRspackDiagnostic({
532
- error: warning,
533
- severity: binding_1.JsRspackSeverity.Warn
534
- });
535
- };
536
- loaderContext.emitFile = function emitFile(name, content, sourceMap, assetInfo) {
537
- let source = undefined;
538
- if (sourceMap) {
539
- if (typeof sourceMap === "string" &&
540
- (loaderContext.sourceMap ||
541
- (compiler.options.devtool &&
542
- (0, adapterRuleUse_1.isUseSimpleSourceMap)(compiler.options.devtool)))) {
543
- source = new webpack_sources_1.OriginalSource(content, (0, identifier_1.makePathsRelative)(contextDirectory, sourceMap, compiler));
544
- }
545
- if (this.sourceMap) {
546
- source = new webpack_sources_1.SourceMapSource(
547
- // @ts-expect-error webpack-sources type declaration is wrong
548
- content, name, (0, identifier_1.makePathsRelative)(contextDirectory, sourceMap, compiler));
549
- }
550
- }
551
- else {
552
- source = new webpack_sources_1.RawSource(
553
- // @ts-expect-error webpack-sources type declaration is wrong
554
- content);
555
- }
556
- compiler._lastCompilation.__internal__emit_asset_from_loader(name, source, assetInfo, context._moduleIdentifier);
557
- };
558
- loaderContext.fs = compiler.inputFileSystem;
559
- loaderContext.experiments = {
560
- emitDiagnostic: (diagnostic) => {
561
- const d = Object.assign({}, diagnostic, {
562
- message: diagnostic.severity === "warning"
563
- ? `ModuleWarning: ${diagnostic.message}`
564
- : `ModuleError: ${diagnostic.message}`,
565
- moduleIdentifier: context._module.moduleIdentifier
566
- });
567
- compiler._lastCompilation.__internal__pushDiagnostic((0, binding_1.formatDiagnostic)(d));
568
- }
569
- };
570
- const getAbsolutify = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindCache(compiler.root));
571
- const getAbsolutifyInContext = (0, memoize_1.memoize)(() => identifier_1.absolutify.bindContextCache(contextDirectory, compiler.root));
572
- const getContextify = (0, memoize_1.memoize)(() => identifier_1.contextify.bindCache(compiler.root));
573
- const getContextifyInContext = (0, memoize_1.memoize)(() => identifier_1.contextify.bindContextCache(contextDirectory, compiler.root));
574
- loaderContext.utils = {
575
- absolutify: (context, request) => {
576
- return context === contextDirectory
577
- ? getAbsolutifyInContext()(request)
578
- : getAbsolutify()(context, request);
579
- },
580
- contextify: (context, request) => {
581
- return context === contextDirectory
582
- ? getContextifyInContext()(request)
583
- : getContextify()(context, request);
584
- },
585
- createHash: type => {
586
- return (0, createHash_1.createHash)(type || compiler._lastCompilation.outputOptions.hashFunction);
587
- }
588
- };
589
- loaderContext._compiler = compiler;
590
- loaderContext._compilation = compiler._lastCompilation;
591
- loaderContext._module = Module_1.Module.__from_binding(context._module, compiler._lastCompilation);
592
- loaderContext.getOptions = () => {
593
- const loader = getCurrentLoader(loaderContext);
594
- let options = loader?.options;
595
- if (typeof options === "string") {
596
- if (options.startsWith("{") && options.endsWith("}")) {
597
- try {
598
- const parseJson = require("../../compiled/json-parse-even-better-errors");
599
- options = parseJson(options);
600
- }
601
- catch (e) {
602
- throw new Error(`Cannot parse string options: ${e.message}`);
603
- }
604
- }
605
- else {
606
- options = node_querystring_1.default.parse(options);
607
- }
608
- }
609
- if (options === null || options === undefined) {
610
- options = {};
611
- }
612
- return options;
613
- };
614
- let compilation = compiler._lastCompilation;
615
- let step = 0;
616
- while (compilation) {
617
- NormalModule_1.NormalModule.getCompilationHooks(compilation).loader.call(loaderContext, loaderContext._module);
618
- compilation = compilation.compiler.parentCompilation;
619
- step++;
620
- if (step > 1000) {
621
- throw Error("Too many nested child compiler, exceeded max limitation 1000");
622
- }
623
- }
624
- /// Sync with `context`
625
- Object.defineProperty(loaderContext, "loaderIndex", {
626
- enumerable: true,
627
- get: () => context.loaderIndex,
628
- set: loaderIndex => (context.loaderIndex = loaderIndex)
629
- });
630
- Object.defineProperty(loaderContext, "cacheable", {
631
- enumerable: true,
632
- get: () => (cacheable) => {
633
- if (cacheable === false) {
634
- context.cacheable = cacheable;
635
- }
636
- }
637
- });
638
- Object.defineProperty(loaderContext, "data", {
639
- enumerable: true,
640
- get: () => loaderContext.loaders[loaderContext.loaderIndex].data,
641
- set: data => (loaderContext.loaders[loaderContext.loaderIndex].data = data)
642
- });
643
- Object.defineProperty(loaderContext, "__internal__parseMeta", {
644
- enumerable: true,
645
- get: () => context.__internal__parseMeta
646
- });
647
- switch (loaderState) {
648
- case binding_1.JsLoaderState.Pitching: {
649
- while (loaderContext.loaderIndex < loaderContext.loaders.length) {
650
- const currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
651
- if (currentLoaderObject.shouldYield())
652
- break;
653
- if (currentLoaderObject.pitchExecuted) {
654
- loaderContext.loaderIndex += 1;
655
- continue;
656
- }
657
- await loadLoaderAsync(currentLoaderObject);
658
- const fn = currentLoaderObject.pitch;
659
- currentLoaderObject.pitchExecuted = true;
660
- if (!fn)
661
- continue;
662
- const args = (await runSyncOrAsync(fn, loaderContext, [
663
- loaderContext.remainingRequest,
664
- loaderContext.previousRequest,
665
- currentLoaderObject.data
666
- ])) || [];
667
- const hasArg = args.some(value => value !== undefined);
668
- if (hasArg) {
669
- const [content, sourceMap, additionalData] = args;
670
- context.content = (0, util_1.isNil)(content) ? null : (0, util_1.toBuffer)(content);
671
- context.sourceMap = (0, util_1.serializeObject)(sourceMap);
672
- context.additionalData = additionalData;
673
- break;
674
- }
675
- }
676
- break;
677
- }
678
- case binding_1.JsLoaderState.Normal: {
679
- let content = context.content;
680
- let sourceMap = JsSourceMap.__from_binding(context.sourceMap);
681
- let additionalData = context.additionalData;
682
- while (loaderContext.loaderIndex >= 0) {
683
- const currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
684
- if (currentLoaderObject.shouldYield())
685
- break;
686
- if (currentLoaderObject.normalExecuted) {
687
- loaderContext.loaderIndex--;
688
- continue;
689
- }
690
- await loadLoaderAsync(currentLoaderObject);
691
- const fn = currentLoaderObject.normal;
692
- currentLoaderObject.normalExecuted = true;
693
- if (!fn)
694
- continue;
695
- const args = [content, sourceMap, additionalData];
696
- convertArgs(args, !!currentLoaderObject.raw);
697
- [content, sourceMap, additionalData] =
698
- (await runSyncOrAsync(fn, loaderContext, args)) || [];
699
- }
700
- context.content = (0, util_1.isNil)(content) ? null : (0, util_1.toBuffer)(content);
701
- context.sourceMap = JsSourceMap.__to_binding(sourceMap);
702
- context.additionalData = additionalData;
703
- break;
704
- }
705
- default:
706
- throw new Error(`Unexpected loader runner state: ${loaderState}`);
707
- }
708
- // update loader state
709
- context.loaderItems = loaderContext.loaders.map(item => LoaderObject.__to_binding(item));
710
- return context;
711
- }
712
- exports.runLoaders = runLoaders;
713
- function utf8BufferToString(buf) {
714
- const str = buf.toString("utf-8");
715
- if (str.charCodeAt(0) === 0xfeff) {
716
- return str.slice(1);
717
- }
718
- return str;
719
- }
720
- function convertArgs(args, raw) {
721
- if (!raw && Buffer.isBuffer(args[0]))
722
- args[0] = utf8BufferToString(args[0]);
723
- else if (raw && typeof args[0] === "string")
724
- args[0] = Buffer.from(args[0], "utf-8");
725
- }
726
- const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
727
- function parsePathQueryFragment(str) {
728
- const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
729
- return {
730
- path: match?.[1].replace(/\u200b(.)/g, "$1") || "",
731
- query: match?.[2] ? match[2].replace(/\u200b(.)/g, "$1") : "",
732
- fragment: match?.[3] || ""
733
- };
734
- }
735
- exports.parsePathQueryFragment = parsePathQueryFragment;