@rspack/core 1.0.0-alpha.4 → 1.0.0-beta.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.
- package/compiled/zod/index.d.ts +138 -52
- package/compiled/zod/index.js +300 -103
- package/compiled/zod/package.json +1 -1
- package/compiled/zod-validation-error/index.js +6 -6
- package/dist/Compilation.d.ts +21 -3
- package/dist/Compilation.js +64 -49
- package/dist/Compiler.js +28 -28
- package/dist/ErrorHelpers.js +2 -4
- package/dist/FileSystem.js +6 -6
- package/dist/Module.js +2 -6
- package/dist/ModuleTypeConstants.d.ts +45 -69
- package/dist/ModuleTypeConstants.js +24 -77
- package/dist/NormalModule.js +6 -6
- package/dist/Stats.js +4 -6
- package/dist/Template.d.ts +31 -147
- package/dist/Template.js +40 -236
- package/dist/Watching.js +2 -2
- package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
- package/dist/builtin-loader/lightningcss/index.js +175 -0
- package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
- package/dist/builtin-plugin/DefinePlugin.js +9 -13
- package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
- package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
- package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
- package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
- package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
- package/dist/builtin-plugin/SplitChunksPlugin.js +7 -17
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
- package/dist/builtin-plugin/base.js +1 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
- package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
- package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
- package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
- package/dist/builtin-plugin/css-extract/loader.js +6 -6
- package/dist/builtin-plugin/css-extract/utils.js +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.d.ts +3 -3
- package/dist/builtin-plugin/lazy-compilation/backend.js +1 -1
- package/dist/config/adapter.d.ts +1 -1
- package/dist/config/adapter.js +31 -30
- package/dist/config/adapterRuleUse.d.ts +5 -5
- package/dist/config/adapterRuleUse.js +23 -1
- package/dist/config/browserslistTargetHandler.d.ts +17 -15
- package/dist/config/browserslistTargetHandler.js +27 -33
- package/dist/config/defaults.js +27 -28
- package/dist/config/normalization.d.ts +2 -0
- package/dist/config/normalization.js +5 -5
- package/dist/config/target.d.ts +48 -109
- package/dist/config/target.js +50 -86
- package/dist/config/zod.d.ts +2398 -2212
- package/dist/config/zod.js +29 -19
- package/dist/container/ContainerPlugin.d.ts +7 -7
- package/dist/container/options.js +1 -1
- package/dist/exports.d.ts +4 -4
- package/dist/exports.js +2 -2
- package/dist/lib/CacheFacade.js +1 -0
- package/dist/lib/EntryOptionPlugin.js +2 -2
- package/dist/lib/ModuleFilenameHelpers.js +1 -3
- package/dist/lib/WebpackError.js +1 -1
- package/dist/lib/cache/mergeEtags.js +5 -11
- package/dist/lib/formatLocation.js +3 -5
- package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
- package/dist/loader-runner/LoaderLoadingError.js +3 -5
- package/dist/loader-runner/index.js +23 -25
- package/dist/loader-runner/loadLoader.d.ts +11 -2
- package/dist/loader-runner/loadLoader.js +18 -20
- package/dist/logging/createConsoleLogger.js +2 -6
- package/dist/logging/truncateArgs.js +5 -9
- package/dist/node/NodeWatchFileSystem.js +5 -5
- package/dist/node/nodeConsole.js +2 -4
- package/dist/rspack.js +6 -6
- package/dist/rspackOptionsApply.js +3 -3
- package/dist/stats/DefaultStatsFactoryPlugin.js +65 -20
- package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
- package/dist/stats/DefaultStatsPrinterPlugin.js +12 -17
- package/dist/stats/StatsFactory.js +13 -17
- package/dist/stats/StatsPrinter.js +7 -9
- package/dist/stats/statsFactoryUtils.d.ts +9 -10
- package/dist/util/AssetInfo.js +11 -7
- package/dist/util/SplitChunkSize.js +1 -1
- package/dist/util/bindingVersionCheck.js +6 -6
- package/dist/util/cleverMerge.d.ts +33 -57
- package/dist/util/cleverMerge.js +89 -145
- package/dist/util/comparators.js +3 -5
- package/dist/util/createHash.d.ts +4 -3
- package/dist/util/createHash.js +31 -45
- package/dist/util/fs.js +16 -20
- package/dist/util/hash/BatchedHash.d.ts +24 -9
- package/dist/util/hash/BatchedHash.js +16 -13
- package/dist/util/hash/index.d.ts +9 -9
- package/dist/util/hash/index.js +14 -11
- package/dist/util/hash/md4.d.ts +29 -2
- package/dist/util/hash/md4.js +7 -3
- package/dist/util/hash/wasm-hash.d.ts +52 -5
- package/dist/util/hash/wasm-hash.js +19 -22
- package/dist/util/hash/xxhash64.d.ts +29 -2
- package/dist/util/hash/xxhash64.js +7 -3
- package/dist/util/identifier.js +13 -19
- package/dist/util/index.js +1 -1
- package/dist/util/memoize.js +7 -9
- package/package.json +9 -8
- package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
no-console,
|
|
6
|
-
func-names
|
|
7
|
-
*/
|
|
8
|
-
/** @typedef {any} TODO */
|
|
9
|
-
const normalizeUrl = require("./normalize-url");
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cssReload = void 0;
|
|
4
|
+
const normalizeUrl_1 = require("./normalizeUrl");
|
|
10
5
|
const srcByModuleId = Object.create(null);
|
|
11
6
|
const noDocument = typeof document === "undefined";
|
|
12
7
|
const { forEach } = Array.prototype;
|
|
13
|
-
/**
|
|
14
|
-
* @param {function} fn
|
|
15
|
-
* @param {number} time
|
|
16
|
-
* @returns {(function(): void)|*}
|
|
17
|
-
*/
|
|
18
8
|
function debounce(fn, time) {
|
|
19
9
|
let timeout = 0;
|
|
20
10
|
return function () {
|
|
21
11
|
// @ts-ignore
|
|
22
12
|
const self = this;
|
|
23
|
-
// eslint-disable-next-line prefer-rest-params
|
|
24
13
|
const args = arguments;
|
|
25
14
|
const functionCall = function functionCall() {
|
|
26
15
|
return fn.apply(self, args);
|
|
27
16
|
};
|
|
28
17
|
clearTimeout(timeout);
|
|
29
|
-
// @ts-ignore
|
|
30
18
|
timeout = setTimeout(functionCall, time);
|
|
31
19
|
};
|
|
32
20
|
}
|
|
33
21
|
function noop() { }
|
|
34
|
-
/**
|
|
35
|
-
* @param {TODO} moduleId
|
|
36
|
-
* @returns {TODO}
|
|
37
|
-
*/
|
|
38
22
|
function getCurrentScriptUrl(moduleId) {
|
|
39
23
|
let src = srcByModuleId[moduleId];
|
|
40
24
|
if (!src) {
|
|
41
25
|
if (document.currentScript) {
|
|
42
|
-
({ src } =
|
|
26
|
+
({ src } = document.currentScript);
|
|
43
27
|
}
|
|
44
28
|
else {
|
|
45
29
|
const scripts = document.getElementsByTagName("script");
|
|
@@ -50,10 +34,6 @@ function getCurrentScriptUrl(moduleId) {
|
|
|
50
34
|
}
|
|
51
35
|
srcByModuleId[moduleId] = src;
|
|
52
36
|
}
|
|
53
|
-
/**
|
|
54
|
-
* @param {string} fileMap
|
|
55
|
-
* @returns {null | string[]}
|
|
56
|
-
*/
|
|
57
37
|
return function (fileMap) {
|
|
58
38
|
if (!src) {
|
|
59
39
|
return null;
|
|
@@ -68,23 +48,18 @@ function getCurrentScriptUrl(moduleId) {
|
|
|
68
48
|
}
|
|
69
49
|
return fileMap.split(",").map(mapRule => {
|
|
70
50
|
const reg = new RegExp(`${filename}\\.js$`, "g");
|
|
71
|
-
return normalizeUrl(src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`));
|
|
51
|
+
return (0, normalizeUrl_1.normalizeUrl)(src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`));
|
|
72
52
|
});
|
|
73
53
|
};
|
|
74
54
|
}
|
|
75
|
-
/**
|
|
76
|
-
* @param {TODO} el
|
|
77
|
-
* @param {string} [url]
|
|
78
|
-
*/
|
|
79
55
|
function updateCss(el, url) {
|
|
80
56
|
if (!url) {
|
|
81
57
|
if (!el.href) {
|
|
82
58
|
return;
|
|
83
59
|
}
|
|
84
|
-
// eslint-disable-next-line
|
|
85
60
|
url = el.href.split("?")[0];
|
|
86
61
|
}
|
|
87
|
-
if (!isUrlRequest(
|
|
62
|
+
if (!isUrlRequest(url)) {
|
|
88
63
|
return;
|
|
89
64
|
}
|
|
90
65
|
if (el.isLoaded === false) {
|
|
@@ -95,7 +70,6 @@ function updateCss(el, url) {
|
|
|
95
70
|
if (!url || !(url.indexOf(".css") > -1)) {
|
|
96
71
|
return;
|
|
97
72
|
}
|
|
98
|
-
// eslint-disable-next-line no-param-reassign
|
|
99
73
|
el.visited = true;
|
|
100
74
|
const newEl = el.cloneNode();
|
|
101
75
|
newEl.isLoaded = false;
|
|
@@ -104,48 +78,33 @@ function updateCss(el, url) {
|
|
|
104
78
|
return;
|
|
105
79
|
}
|
|
106
80
|
newEl.isLoaded = true;
|
|
107
|
-
el.parentNode
|
|
81
|
+
el.parentNode?.removeChild(el);
|
|
108
82
|
});
|
|
109
83
|
newEl.addEventListener("error", () => {
|
|
110
84
|
if (newEl.isLoaded) {
|
|
111
85
|
return;
|
|
112
86
|
}
|
|
113
87
|
newEl.isLoaded = true;
|
|
114
|
-
el.parentNode
|
|
88
|
+
el.parentNode?.removeChild(el);
|
|
115
89
|
});
|
|
116
90
|
newEl.href = `${url}?${Date.now()}`;
|
|
117
91
|
if (el.nextSibling) {
|
|
118
|
-
el.parentNode
|
|
92
|
+
el.parentNode?.insertBefore(newEl, el.nextSibling);
|
|
119
93
|
}
|
|
120
94
|
else {
|
|
121
|
-
el.parentNode
|
|
95
|
+
el.parentNode?.appendChild(newEl);
|
|
122
96
|
}
|
|
123
97
|
}
|
|
124
|
-
/**
|
|
125
|
-
* @param {string} href
|
|
126
|
-
* @param {TODO} src
|
|
127
|
-
* @returns {TODO}
|
|
128
|
-
*/
|
|
129
98
|
function getReloadUrl(href, src) {
|
|
130
|
-
let ret;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
src.some(
|
|
134
|
-
/**
|
|
135
|
-
* @param {string} url
|
|
136
|
-
*/
|
|
137
|
-
// eslint-disable-next-line array-callback-return
|
|
138
|
-
url => {
|
|
99
|
+
let ret = "";
|
|
100
|
+
href = (0, normalizeUrl_1.normalizeUrl)(href);
|
|
101
|
+
src.some(url => {
|
|
139
102
|
if (href.indexOf(src) > -1) {
|
|
140
103
|
ret = url;
|
|
141
104
|
}
|
|
142
105
|
});
|
|
143
106
|
return ret;
|
|
144
107
|
}
|
|
145
|
-
/**
|
|
146
|
-
* @param {string} [src]
|
|
147
|
-
* @returns {boolean}
|
|
148
|
-
*/
|
|
149
108
|
function reloadStyle(src) {
|
|
150
109
|
if (!src) {
|
|
151
110
|
return false;
|
|
@@ -179,10 +138,6 @@ function reloadAll() {
|
|
|
179
138
|
updateCss(el);
|
|
180
139
|
});
|
|
181
140
|
}
|
|
182
|
-
/**
|
|
183
|
-
* @param {string} url
|
|
184
|
-
* @returns {boolean}
|
|
185
|
-
*/
|
|
186
141
|
function isUrlRequest(url) {
|
|
187
142
|
// An URL is not an request if
|
|
188
143
|
// It is not http or https
|
|
@@ -191,12 +146,7 @@ function isUrlRequest(url) {
|
|
|
191
146
|
}
|
|
192
147
|
return true;
|
|
193
148
|
}
|
|
194
|
-
|
|
195
|
-
* @param {TODO} moduleId
|
|
196
|
-
* @param {TODO} options
|
|
197
|
-
* @returns {TODO}
|
|
198
|
-
*/
|
|
199
|
-
module.exports = function (moduleId, options) {
|
|
149
|
+
function cssReload(moduleId, options) {
|
|
200
150
|
if (noDocument) {
|
|
201
151
|
console.log("no window.document found, will not HMR CSS");
|
|
202
152
|
return noop;
|
|
@@ -211,7 +161,7 @@ module.exports = function (moduleId, options) {
|
|
|
211
161
|
return;
|
|
212
162
|
}
|
|
213
163
|
if (reloaded) {
|
|
214
|
-
console.log("[HMR] css reload %s", src
|
|
164
|
+
console.log("[HMR] css reload %s", src?.join(" "));
|
|
215
165
|
}
|
|
216
166
|
else {
|
|
217
167
|
console.log("[HMR] Reload all css");
|
|
@@ -219,4 +169,5 @@ module.exports = function (moduleId, options) {
|
|
|
219
169
|
}
|
|
220
170
|
}
|
|
221
171
|
return debounce(update, 50);
|
|
222
|
-
}
|
|
172
|
+
}
|
|
173
|
+
exports.cssReload = cssReload;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeUrl = void 0;
|
|
4
|
+
function normalizeUrl(urlString) {
|
|
5
|
+
urlString = urlString.trim();
|
|
6
|
+
if (/^data:/i.test(urlString)) {
|
|
7
|
+
return urlString;
|
|
8
|
+
}
|
|
9
|
+
var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : "";
|
|
10
|
+
var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
|
|
11
|
+
var host = components[0].toLowerCase().replace(/\.$/, "");
|
|
12
|
+
components[0] = "";
|
|
13
|
+
var path = components
|
|
9
14
|
.reduce(function (accumulator, item) {
|
|
10
15
|
switch (item) {
|
|
11
16
|
case "..":
|
|
@@ -17,22 +22,8 @@ function normalizeUrl(pathComponents) {
|
|
|
17
22
|
accumulator.push(item);
|
|
18
23
|
}
|
|
19
24
|
return accumulator;
|
|
20
|
-
},
|
|
25
|
+
}, [])
|
|
21
26
|
.join("/");
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @param {string} urlString
|
|
25
|
-
* @returns {string}
|
|
26
|
-
*/
|
|
27
|
-
module.exports = function (urlString) {
|
|
28
|
-
urlString = urlString.trim();
|
|
29
|
-
if (/^data:/i.test(urlString)) {
|
|
30
|
-
return urlString;
|
|
31
|
-
}
|
|
32
|
-
var protocol = urlString.indexOf("//") !== -1 ? urlString.split("//")[0] + "//" : "";
|
|
33
|
-
var components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
|
|
34
|
-
var host = components[0].toLowerCase().replace(/\.$/, "");
|
|
35
|
-
components[0] = "";
|
|
36
|
-
var path = normalizeUrl(components);
|
|
37
27
|
return protocol + host + path;
|
|
38
|
-
}
|
|
28
|
+
}
|
|
29
|
+
exports.normalizeUrl = normalizeUrl;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pitch = exports.SINGLE_DOT_PATH_SEGMENT = exports.BASE_URI = exports.ABSOLUTE_PUBLIC_PATH = exports.AUTO_PUBLIC_PATH = exports.MODULE_TYPE = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
const loader_options_json_1 = __importDefault(require("./loader-options.json"));
|
|
10
10
|
const utils_1 = require("./utils");
|
|
@@ -21,7 +21,7 @@ function hotLoader(content, context) {
|
|
|
21
21
|
return `${content}
|
|
22
22
|
if(module.hot) {
|
|
23
23
|
// ${Date.now()}
|
|
24
|
-
var cssReload = require(${(0, utils_1.stringifyRequest)(context.loaderContext,
|
|
24
|
+
var cssReload = require(${(0, utils_1.stringifyRequest)(context.loaderContext, node_path_1.default.join(__dirname, "./hmr/hotModuleReplacement.js"))}).cssReload(module.id, ${JSON.stringify({
|
|
25
25
|
...context.options,
|
|
26
26
|
locals: !!context.locals
|
|
27
27
|
})});
|
|
@@ -101,14 +101,14 @@ const pitch = function (request, _, data) {
|
|
|
101
101
|
originalExports.__esModule &&
|
|
102
102
|
(!originalExports.default || !("locals" in originalExports.default));
|
|
103
103
|
if (namedExport) {
|
|
104
|
-
Object.keys(originalExports)
|
|
104
|
+
for (const key of Object.keys(originalExports)) {
|
|
105
105
|
if (key !== "default") {
|
|
106
106
|
if (!locals) {
|
|
107
107
|
locals = {};
|
|
108
108
|
}
|
|
109
109
|
/** @type {Locals} */ locals[key] = originalExports[key];
|
|
110
110
|
}
|
|
111
|
-
}
|
|
111
|
+
}
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
114
|
locals = exports && exports.locals;
|
|
@@ -171,7 +171,7 @@ const pitch = function (request, _, data) {
|
|
|
171
171
|
}
|
|
172
172
|
return `\n${esModule ? "export default" : "module.exports = "} ${JSON.stringify(locals)};`;
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
if (esModule) {
|
|
175
175
|
return "\nexport {};";
|
|
176
176
|
}
|
|
177
177
|
return "";
|
|
@@ -202,7 +202,7 @@ const pitch = function (request, _, data) {
|
|
|
202
202
|
callback(null, resultSource, undefined, additionalData);
|
|
203
203
|
};
|
|
204
204
|
this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, {
|
|
205
|
-
publicPath: /** @type {
|
|
205
|
+
publicPath: /** @type {Filename} */ publicPathForExtract,
|
|
206
206
|
baseUri: `${exports.BASE_URI}/`
|
|
207
207
|
}, (error, exports) => {
|
|
208
208
|
if (error) {
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.stringifyLocal = exports.stringifyRequest = exports.isRelativePath = exports.isAbsolutePath = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
function isAbsolutePath(str) {
|
|
9
|
-
return
|
|
9
|
+
return node_path_1.default.posix.isAbsolute(str) || node_path_1.default.win32.isAbsolute(str);
|
|
10
10
|
}
|
|
11
11
|
exports.isAbsolutePath = isAbsolutePath;
|
|
12
12
|
const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
|
|
@@ -28,7 +28,7 @@ function stringifyRequest(loaderContext, request) {
|
|
|
28
28
|
const query = splittedPart ? splittedPart[2] : "";
|
|
29
29
|
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
30
30
|
if (isAbsolutePath(singlePath) && context) {
|
|
31
|
-
singlePath =
|
|
31
|
+
singlePath = node_path_1.default.relative(context, singlePath);
|
|
32
32
|
if (isAbsolutePath(singlePath)) {
|
|
33
33
|
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
|
34
34
|
// In this case, we leave the path platform-specific without replacing any separators.
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import type { IncomingMessage, ServerOptions as ServerOptionsImport, ServerResponse } from "http";
|
|
6
|
-
import type { ListenOptions, Server } from "net";
|
|
7
|
-
import type { SecureContextOptions, TlsOptions } from "tls";
|
|
5
|
+
import type { IncomingMessage, ServerOptions as ServerOptionsImport, ServerResponse } from "node:http";
|
|
6
|
+
import type { ListenOptions, Server } from "node:net";
|
|
7
|
+
import type { SecureContextOptions, TlsOptions } from "node:tls";
|
|
8
8
|
import type { Compiler } from "../..";
|
|
9
9
|
export interface LazyCompilationDefaultBackendOptions {
|
|
10
10
|
/**
|
|
@@ -16,7 +16,7 @@ const getBackend = (options) => (compiler, callback) => {
|
|
|
16
16
|
const createServer = typeof options.server === "function"
|
|
17
17
|
? options.server
|
|
18
18
|
: (() => {
|
|
19
|
-
const http = isHttps ? require("https") : require("http");
|
|
19
|
+
const http = isHttps ? require("node:https") : require("node:http");
|
|
20
20
|
return http.createServer.bind(http, options.server);
|
|
21
21
|
})();
|
|
22
22
|
const listen = typeof options.listen === "function"
|
package/dist/config/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RawLibraryOptions, type RawOptions } from "@rspack/binding";
|
|
2
2
|
import type { Compiler } from "../Compiler";
|
|
3
3
|
import { type LoaderContext, type LoaderDefinition, type LoaderDefinitionFunction } from "./adapterRuleUse";
|
|
4
4
|
import type { RspackOptionsNormalized } from "./normalization";
|
package/dist/config/adapter.js
CHANGED
|
@@ -4,13 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getRawChunkLoading = exports.getRawLibrary = exports.getRawResolve = exports.getRawOptions = void 0;
|
|
7
|
-
const
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const binding_1 = require("@rspack/binding");
|
|
8
9
|
const Stats_1 = require("../Stats");
|
|
9
10
|
const util_1 = require("../util");
|
|
10
11
|
const identifier_1 = require("../util/identifier");
|
|
11
12
|
const adapterRuleUse_1 = require("./adapterRuleUse");
|
|
12
13
|
const getRawOptions = (options, compiler) => {
|
|
13
|
-
(0,
|
|
14
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(options.context) && !(0, util_1.isNil)(options.devtool) && !(0, util_1.isNil)(options.cache), "context, devtool, cache should not be nil after defaults");
|
|
14
15
|
const devtool = options.devtool === false ? "" : options.devtool;
|
|
15
16
|
const mode = options.mode;
|
|
16
17
|
const experiments = getRawExperiments(options.experiments);
|
|
@@ -68,9 +69,7 @@ function getRawExtensionAlias(alias = {}) {
|
|
|
68
69
|
if (Array.isArray(value)) {
|
|
69
70
|
return [key, value];
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
return [key, [value]];
|
|
73
|
-
}
|
|
72
|
+
return [key, [value]];
|
|
74
73
|
});
|
|
75
74
|
return Object.fromEntries(entries);
|
|
76
75
|
}
|
|
@@ -86,14 +85,14 @@ function getRawResolveByDependency(byDependency) {
|
|
|
86
85
|
return Object.fromEntries(Object.entries(byDependency).map(([k, v]) => [k, getRawResolve(v)]));
|
|
87
86
|
}
|
|
88
87
|
function getRawTsConfig(tsConfig) {
|
|
89
|
-
(0,
|
|
88
|
+
(0, node_assert_1.default)(typeof tsConfig !== "string", "should resolve string tsConfig in normalization");
|
|
90
89
|
if (tsConfig === undefined)
|
|
91
90
|
return tsConfig;
|
|
92
91
|
const { configFile, references } = tsConfig;
|
|
93
92
|
return {
|
|
94
93
|
configFile,
|
|
95
|
-
referencesType: references
|
|
96
|
-
references: references
|
|
94
|
+
referencesType: references === "auto" ? "auto" : references ? "manual" : "disabled",
|
|
95
|
+
references: references === "auto" ? undefined : references
|
|
97
96
|
};
|
|
98
97
|
}
|
|
99
98
|
function getRawResolve(resolve) {
|
|
@@ -157,6 +156,8 @@ function getRawOutput(output) {
|
|
|
157
156
|
workerWasmLoading: workerWasmLoading === false ? "false" : workerWasmLoading,
|
|
158
157
|
workerPublicPath: output.workerPublicPath,
|
|
159
158
|
scriptType: output.scriptType === false ? "false" : output.scriptType,
|
|
159
|
+
charset: output.charset,
|
|
160
|
+
chunkLoadTimeout: output.chunkLoadTimeout,
|
|
160
161
|
environment: output.environment
|
|
161
162
|
};
|
|
162
163
|
}
|
|
@@ -209,7 +210,7 @@ function getRawLibraryName(name) {
|
|
|
209
210
|
throw new Error("unreachable");
|
|
210
211
|
}
|
|
211
212
|
function getRawModule(module, options) {
|
|
212
|
-
(0,
|
|
213
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(module.defaultRules), "module.defaultRules should not be nil after defaults");
|
|
213
214
|
// "..." in defaultRules will be flatten in `applyModuleDefaults`, and "..." in rules is empty, so it's safe to use `as RuleSetRule[]` at here
|
|
214
215
|
const ruleSet = [
|
|
215
216
|
{ rules: module.defaultRules },
|
|
@@ -331,7 +332,7 @@ const getRawModuleRule = (rule, path, options, upperType) => {
|
|
|
331
332
|
if (rule.test && !tryMatch(path, rule.test)) {
|
|
332
333
|
return false;
|
|
333
334
|
}
|
|
334
|
-
|
|
335
|
+
if (rule.resource && !tryMatch(path, rule.resource)) {
|
|
335
336
|
return false;
|
|
336
337
|
}
|
|
337
338
|
if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) {
|
|
@@ -349,14 +350,14 @@ const getRawModuleRule = (rule, path, options, upperType) => {
|
|
|
349
350
|
function getRawRuleSetCondition(condition) {
|
|
350
351
|
if (typeof condition === "string") {
|
|
351
352
|
return {
|
|
352
|
-
type:
|
|
353
|
-
|
|
353
|
+
type: binding_1.RawRuleSetConditionType.string,
|
|
354
|
+
string: condition
|
|
354
355
|
};
|
|
355
356
|
}
|
|
356
357
|
if (condition instanceof RegExp) {
|
|
357
358
|
return {
|
|
358
|
-
type:
|
|
359
|
-
|
|
359
|
+
type: binding_1.RawRuleSetConditionType.regexp,
|
|
360
|
+
regexp: {
|
|
360
361
|
source: condition.source,
|
|
361
362
|
flags: condition.flags
|
|
362
363
|
}
|
|
@@ -364,20 +365,20 @@ function getRawRuleSetCondition(condition) {
|
|
|
364
365
|
}
|
|
365
366
|
if (typeof condition === "function") {
|
|
366
367
|
return {
|
|
367
|
-
type:
|
|
368
|
-
|
|
368
|
+
type: binding_1.RawRuleSetConditionType.func,
|
|
369
|
+
func: condition
|
|
369
370
|
};
|
|
370
371
|
}
|
|
371
372
|
if (Array.isArray(condition)) {
|
|
372
373
|
return {
|
|
373
|
-
type:
|
|
374
|
-
|
|
374
|
+
type: binding_1.RawRuleSetConditionType.array,
|
|
375
|
+
array: condition.map(i => getRawRuleSetCondition(i))
|
|
375
376
|
};
|
|
376
377
|
}
|
|
377
378
|
if (typeof condition === "object" && condition !== null) {
|
|
378
379
|
return {
|
|
379
|
-
type:
|
|
380
|
-
|
|
380
|
+
type: binding_1.RawRuleSetConditionType.logical,
|
|
381
|
+
logical: [getRawRuleSetLogicalConditions(condition)]
|
|
381
382
|
};
|
|
382
383
|
}
|
|
383
384
|
throw new Error("unreachable: condition should be one of string, RegExp, Array, Object");
|
|
@@ -408,41 +409,41 @@ function getRawParserOptions(parser, type) {
|
|
|
408
409
|
asset: getRawAssetParserOptions(parser)
|
|
409
410
|
};
|
|
410
411
|
}
|
|
411
|
-
|
|
412
|
+
if (type === "javascript") {
|
|
412
413
|
// Filter this out, since `parser["javascript"]` already merge into `parser["javascript/*"]` in default.ts
|
|
413
414
|
return;
|
|
414
415
|
}
|
|
415
|
-
|
|
416
|
+
if (type === "javascript/auto") {
|
|
416
417
|
return {
|
|
417
418
|
type: "javascript/auto",
|
|
418
419
|
javascript: getRawJavascriptParserOptions(parser)
|
|
419
420
|
};
|
|
420
421
|
}
|
|
421
|
-
|
|
422
|
+
if (type === "javascript/dynamic") {
|
|
422
423
|
return {
|
|
423
424
|
type: "javascript/dynamic",
|
|
424
425
|
javascript: getRawJavascriptParserOptions(parser)
|
|
425
426
|
};
|
|
426
427
|
}
|
|
427
|
-
|
|
428
|
+
if (type === "javascript/esm") {
|
|
428
429
|
return {
|
|
429
430
|
type: "javascript/esm",
|
|
430
431
|
javascript: getRawJavascriptParserOptions(parser)
|
|
431
432
|
};
|
|
432
433
|
}
|
|
433
|
-
|
|
434
|
+
if (type === "css") {
|
|
434
435
|
return {
|
|
435
436
|
type: "css",
|
|
436
437
|
css: getRawCssParserOptions(parser)
|
|
437
438
|
};
|
|
438
439
|
}
|
|
439
|
-
|
|
440
|
+
if (type === "css/auto") {
|
|
440
441
|
return {
|
|
441
442
|
type: "css/auto",
|
|
442
443
|
cssAuto: getRawCssParserOptions(parser)
|
|
443
444
|
};
|
|
444
445
|
}
|
|
445
|
-
|
|
446
|
+
if (type === "css/module") {
|
|
446
447
|
return {
|
|
447
448
|
type: "css/module",
|
|
448
449
|
cssModule: getRawCssParserOptions(parser)
|
|
@@ -607,7 +608,7 @@ function getRawCssAutoOrModuleGeneratorOptions(options) {
|
|
|
607
608
|
};
|
|
608
609
|
}
|
|
609
610
|
function getRawOptimization(optimization) {
|
|
610
|
-
(0,
|
|
611
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(optimization.removeAvailableModules) &&
|
|
611
612
|
!(0, util_1.isNil)(optimization.sideEffects) &&
|
|
612
613
|
!(0, util_1.isNil)(optimization.realContentHash) &&
|
|
613
614
|
!(0, util_1.isNil)(optimization.providedExports) &&
|
|
@@ -629,7 +630,7 @@ function getRawSnapshotOptions(_snapshot) {
|
|
|
629
630
|
}
|
|
630
631
|
function getRawExperiments(experiments) {
|
|
631
632
|
const { topLevelAwait, rspackFuture } = experiments;
|
|
632
|
-
(0,
|
|
633
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(topLevelAwait) && !(0, util_1.isNil)(rspackFuture));
|
|
633
634
|
return {
|
|
634
635
|
topLevelAwait,
|
|
635
636
|
rspackFuture: getRawRspackFutureOptions(rspackFuture)
|
|
@@ -642,7 +643,7 @@ function getRawNode(node) {
|
|
|
642
643
|
if (node === false) {
|
|
643
644
|
return undefined;
|
|
644
645
|
}
|
|
645
|
-
(0,
|
|
646
|
+
(0, node_assert_1.default)(!(0, util_1.isNil)(node.__dirname) && !(0, util_1.isNil)(node.global) && !(0, util_1.isNil)(node.__filename));
|
|
646
647
|
return {
|
|
647
648
|
dirname: String(node.__dirname),
|
|
648
649
|
filename: String(node.__filename),
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { JsAssetInfo, RawModuleRuleUse, RawOptions } from "@rspack/binding";
|
|
3
3
|
import type { ResolveRequest } from "../../compiled/enhanced-resolve";
|
|
4
|
-
import type { Compiler } from "../Compiler";
|
|
5
|
-
import type { Logger } from "../logging/Logger";
|
|
6
|
-
import Hash = require("../util/hash");
|
|
7
4
|
import type { Compilation } from "../Compilation";
|
|
5
|
+
import type { Compiler } from "../Compiler";
|
|
8
6
|
import type { Module } from "../Module";
|
|
9
7
|
import { type LoaderObject } from "../loader-runner";
|
|
10
|
-
import type {
|
|
8
|
+
import type { Logger } from "../logging/Logger";
|
|
9
|
+
import type Hash from "../util/hash";
|
|
10
|
+
import type { Mode, PublicPath, Resolve, RuleSetUseItem, Target } from "./zod";
|
|
11
11
|
export declare const BUILTIN_LOADER_PREFIX = "builtin:";
|
|
12
12
|
export interface ComposeJsUseOptions {
|
|
13
13
|
devtool: RawOptions["devtool"];
|
|
@@ -87,7 +87,7 @@ export interface LoaderContext<OptionsType = {}> {
|
|
|
87
87
|
getMissingDependencies(): string[];
|
|
88
88
|
addBuildDependency(file: string): void;
|
|
89
89
|
importModule(request: string, options: {
|
|
90
|
-
publicPath?:
|
|
90
|
+
publicPath?: PublicPath;
|
|
91
91
|
baseUri?: string;
|
|
92
92
|
}, callback: (err?: Error, res?: any) => void): void;
|
|
93
93
|
fs: any;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isUseSimpleSourceMap = exports.isUseSourceMap = exports.createRawModuleRuleUses = exports.BUILTIN_LOADER_PREFIX = void 0;
|
|
4
4
|
const builtin_loader_1 = require("../builtin-loader");
|
|
5
|
+
const lightningcss_1 = require("../builtin-loader/lightningcss");
|
|
5
6
|
const loader_runner_1 = require("../loader-runner");
|
|
6
7
|
const util_1 = require("../util");
|
|
8
|
+
const browserslist = require("../../compiled/browserslist");
|
|
7
9
|
exports.BUILTIN_LOADER_PREFIX = "builtin:";
|
|
8
10
|
function createRawModuleRuleUses(uses, path, options) {
|
|
9
11
|
const normalizeRuleSetUseItem = (item) => typeof item === "string" ? { loader: item } : item;
|
|
@@ -13,7 +15,7 @@ function createRawModuleRuleUses(uses, path, options) {
|
|
|
13
15
|
return createRawModuleRuleUsesImpl(allUses, path, options);
|
|
14
16
|
}
|
|
15
17
|
exports.createRawModuleRuleUses = createRawModuleRuleUses;
|
|
16
|
-
const getSwcLoaderOptions = (o,
|
|
18
|
+
const getSwcLoaderOptions = (o, _) => {
|
|
17
19
|
if (o && typeof o === "object" && o.rspackExperiments) {
|
|
18
20
|
const expr = o.rspackExperiments;
|
|
19
21
|
if (expr.import || expr.pluginImport) {
|
|
@@ -22,10 +24,30 @@ const getSwcLoaderOptions = (o, options) => {
|
|
|
22
24
|
}
|
|
23
25
|
return o;
|
|
24
26
|
};
|
|
27
|
+
const getLightningcssLoaderOptions = (o, _) => {
|
|
28
|
+
if (o && typeof o === "object") {
|
|
29
|
+
if (o.targets && typeof o.targets === "string") {
|
|
30
|
+
o.targets = (0, lightningcss_1.browserslistToTargets)(browserslist(o.targets));
|
|
31
|
+
}
|
|
32
|
+
if (o.targets && Array.isArray(o.targets)) {
|
|
33
|
+
o.targets = (0, lightningcss_1.browserslistToTargets)(o.targets);
|
|
34
|
+
}
|
|
35
|
+
if (o.include) {
|
|
36
|
+
o.include = (0, lightningcss_1.toFeatures)(o.include);
|
|
37
|
+
}
|
|
38
|
+
if (o.exclude) {
|
|
39
|
+
o.exclude = (0, lightningcss_1.toFeatures)(o.exclude);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return o;
|
|
43
|
+
};
|
|
25
44
|
function getBuiltinLoaderOptions(identifier, o, options) {
|
|
26
45
|
if (identifier.startsWith(`${exports.BUILTIN_LOADER_PREFIX}swc-loader`)) {
|
|
27
46
|
return getSwcLoaderOptions(o, options);
|
|
28
47
|
}
|
|
48
|
+
if (identifier.startsWith(`${exports.BUILTIN_LOADER_PREFIX}lightningcss-loader`)) {
|
|
49
|
+
return getLightningcssLoaderOptions(o, options);
|
|
50
|
+
}
|
|
29
51
|
return o;
|
|
30
52
|
}
|
|
31
53
|
function createRawModuleRuleUsesImpl(uses, path, options) {
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
export type ApiTargetProperties = import("./target").ApiTargetProperties;
|
|
2
|
-
export type EcmaTargetProperties = import("./target").EcmaTargetProperties;
|
|
3
|
-
export type PlatformTargetProperties = import("./target").PlatformTargetProperties;
|
|
4
|
-
export type BrowserslistHandlerConfig = {
|
|
5
|
-
configPath?: string | undefined;
|
|
6
|
-
env?: string | undefined;
|
|
7
|
-
query?: string | undefined;
|
|
8
|
-
};
|
|
9
1
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/browserslistTargetHandler.js
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Author Sergey Melyukov @smelukov
|
|
7
|
+
* Copyright (c) JS Foundation and other contributors
|
|
8
|
+
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
12
9
|
*/
|
|
13
|
-
|
|
10
|
+
import type { ApiTargetProperties, EcmaTargetProperties, PlatformTargetProperties } from "./target";
|
|
14
11
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
12
|
+
* @param input input string
|
|
13
|
+
* @param context the context directory
|
|
14
|
+
* @returns selected browsers
|
|
18
15
|
*/
|
|
19
|
-
export
|
|
16
|
+
export declare const load: (input: string | null | undefined, context: string) => string[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* @param browsers supported browsers list
|
|
19
|
+
* @returns target properties
|
|
20
|
+
*/
|
|
21
|
+
export declare const resolve: (browsers: string[]) => EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties;
|