@rspack/core 1.0.0-alpha.5 → 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.
Files changed (89) hide show
  1. package/compiled/zod/index.d.ts +138 -52
  2. package/compiled/zod/index.js +300 -103
  3. package/compiled/zod/package.json +1 -1
  4. package/compiled/zod-validation-error/index.js +6 -6
  5. package/dist/Compilation.d.ts +21 -3
  6. package/dist/Compilation.js +64 -49
  7. package/dist/Compiler.js +28 -28
  8. package/dist/ErrorHelpers.js +2 -4
  9. package/dist/Module.js +2 -6
  10. package/dist/ModuleTypeConstants.d.ts +45 -69
  11. package/dist/ModuleTypeConstants.js +24 -77
  12. package/dist/Stats.js +4 -6
  13. package/dist/Template.d.ts +31 -147
  14. package/dist/Template.js +40 -236
  15. package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
  16. package/dist/builtin-loader/lightningcss/index.js +175 -0
  17. package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
  18. package/dist/builtin-plugin/DefinePlugin.js +9 -13
  19. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  20. package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
  21. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
  22. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
  23. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
  24. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
  25. package/dist/builtin-plugin/SplitChunksPlugin.js +5 -15
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
  27. package/dist/builtin-plugin/base.js +1 -3
  28. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
  29. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
  30. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
  31. package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
  32. package/dist/builtin-plugin/css-extract/loader.js +5 -5
  33. package/dist/config/adapter.d.ts +1 -1
  34. package/dist/config/adapter.js +24 -23
  35. package/dist/config/adapterRuleUse.d.ts +5 -5
  36. package/dist/config/adapterRuleUse.js +23 -1
  37. package/dist/config/browserslistTargetHandler.d.ts +17 -15
  38. package/dist/config/browserslistTargetHandler.js +27 -33
  39. package/dist/config/defaults.js +20 -21
  40. package/dist/config/normalization.d.ts +2 -0
  41. package/dist/config/normalization.js +5 -5
  42. package/dist/config/target.d.ts +48 -109
  43. package/dist/config/target.js +50 -86
  44. package/dist/config/zod.d.ts +2391 -2205
  45. package/dist/config/zod.js +28 -18
  46. package/dist/container/ContainerPlugin.d.ts +7 -7
  47. package/dist/container/options.js +1 -1
  48. package/dist/exports.d.ts +4 -4
  49. package/dist/exports.js +2 -2
  50. package/dist/lib/CacheFacade.js +1 -0
  51. package/dist/lib/ModuleFilenameHelpers.js +1 -3
  52. package/dist/lib/cache/mergeEtags.js +5 -11
  53. package/dist/lib/formatLocation.js +3 -5
  54. package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
  55. package/dist/loader-runner/LoaderLoadingError.js +3 -5
  56. package/dist/loader-runner/index.js +7 -9
  57. package/dist/loader-runner/loadLoader.d.ts +11 -2
  58. package/dist/loader-runner/loadLoader.js +17 -19
  59. package/dist/logging/createConsoleLogger.js +2 -6
  60. package/dist/logging/truncateArgs.js +5 -9
  61. package/dist/node/nodeConsole.js +1 -3
  62. package/dist/stats/DefaultStatsFactoryPlugin.js +17 -7
  63. package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
  64. package/dist/stats/DefaultStatsPrinterPlugin.js +11 -16
  65. package/dist/stats/StatsFactory.js +13 -17
  66. package/dist/stats/StatsPrinter.js +7 -9
  67. package/dist/util/AssetInfo.js +11 -7
  68. package/dist/util/SplitChunkSize.js +1 -1
  69. package/dist/util/cleverMerge.d.ts +33 -57
  70. package/dist/util/cleverMerge.js +89 -145
  71. package/dist/util/comparators.js +3 -5
  72. package/dist/util/createHash.d.ts +4 -3
  73. package/dist/util/createHash.js +31 -45
  74. package/dist/util/fs.js +9 -13
  75. package/dist/util/hash/BatchedHash.d.ts +24 -9
  76. package/dist/util/hash/BatchedHash.js +16 -13
  77. package/dist/util/hash/index.d.ts +9 -9
  78. package/dist/util/hash/index.js +14 -11
  79. package/dist/util/hash/md4.d.ts +29 -2
  80. package/dist/util/hash/md4.js +7 -3
  81. package/dist/util/hash/wasm-hash.d.ts +52 -5
  82. package/dist/util/hash/wasm-hash.js +19 -22
  83. package/dist/util/hash/xxhash64.d.ts +29 -2
  84. package/dist/util/hash/xxhash64.js +7 -3
  85. package/dist/util/identifier.js +9 -15
  86. package/dist/util/index.js +1 -1
  87. package/dist/util/memoize.js +7 -9
  88. package/package.json +9 -8
  89. package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
@@ -1,45 +1,29 @@
1
1
  "use strict";
2
- /* eslint-env browser */
3
- /*
4
- eslint-disable
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 } = /** @type {HTMLScriptElement} */ (document.currentScript));
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(/** @type {string} */ (url))) {
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.removeChild(el);
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.removeChild(el);
88
+ el.parentNode?.removeChild(el);
115
89
  });
116
90
  newEl.href = `${url}?${Date.now()}`;
117
91
  if (el.nextSibling) {
118
- el.parentNode.insertBefore(newEl, el.nextSibling);
92
+ el.parentNode?.insertBefore(newEl, el.nextSibling);
119
93
  }
120
94
  else {
121
- el.parentNode.appendChild(newEl);
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
- // eslint-disable-next-line no-param-reassign
132
- href = normalizeUrl(href);
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.join(" "));
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;
@@ -0,0 +1,2 @@
1
+ declare function normalizeUrl(urlString: string): string;
2
+ export { normalizeUrl };
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
- /* eslint-disable */
3
- /**
4
- * @param {string[]} pathComponents
5
- * @returns {string}
6
- */
7
- function normalizeUrl(pathComponents) {
8
- return pathComponents
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
- }, /** @type {string[]} */ ([]))
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;
@@ -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, node_path_1.default.join(__dirname, "./hmr/hotModuleReplacement.js"))})(module.id, ${JSON.stringify({
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).forEach(key => {
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
- else if (esModule) {
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 {string} */ publicPathForExtract,
205
+ publicPath: /** @type {Filename} */ publicPathForExtract,
206
206
  baseUri: `${exports.BASE_URI}/`
207
207
  }, (error, exports) => {
208
208
  if (error) {
@@ -1,4 +1,4 @@
1
- import type { RawLibraryOptions, RawOptions } from "@rspack/binding";
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";
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRawChunkLoading = exports.getRawLibrary = exports.getRawResolve = exports.getRawOptions = void 0;
7
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");
@@ -68,9 +69,7 @@ function getRawExtensionAlias(alias = {}) {
68
69
  if (Array.isArray(value)) {
69
70
  return [key, value];
70
71
  }
71
- else {
72
- return [key, [value]];
73
- }
72
+ return [key, [value]];
74
73
  });
75
74
  return Object.fromEntries(entries);
76
75
  }
@@ -92,8 +91,8 @@ function getRawTsConfig(tsConfig) {
92
91
  const { configFile, references } = tsConfig;
93
92
  return {
94
93
  configFile,
95
- referencesType: references == "auto" ? "auto" : references ? "manual" : "disabled",
96
- references: references == "auto" ? undefined : 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
  }
@@ -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
- else if (rule.resource && !tryMatch(path, rule.resource)) {
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: "string",
353
- stringMatcher: condition
353
+ type: binding_1.RawRuleSetConditionType.string,
354
+ string: condition
354
355
  };
355
356
  }
356
357
  if (condition instanceof RegExp) {
357
358
  return {
358
- type: "regexp",
359
- regexpMatcher: {
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: "function",
368
- funcMatcher: condition
368
+ type: binding_1.RawRuleSetConditionType.func,
369
+ func: condition
369
370
  };
370
371
  }
371
372
  if (Array.isArray(condition)) {
372
373
  return {
373
- type: "array",
374
- arrayMatcher: condition.map(i => getRawRuleSetCondition(i))
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: "logical",
380
- logicalMatcher: [getRawRuleSetLogicalConditions(condition)]
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
- else if (type === "javascript") {
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
- else if (type === "javascript/auto") {
416
+ if (type === "javascript/auto") {
416
417
  return {
417
418
  type: "javascript/auto",
418
419
  javascript: getRawJavascriptParserOptions(parser)
419
420
  };
420
421
  }
421
- else if (type === "javascript/dynamic") {
422
+ if (type === "javascript/dynamic") {
422
423
  return {
423
424
  type: "javascript/dynamic",
424
425
  javascript: getRawJavascriptParserOptions(parser)
425
426
  };
426
427
  }
427
- else if (type === "javascript/esm") {
428
+ if (type === "javascript/esm") {
428
429
  return {
429
430
  type: "javascript/esm",
430
431
  javascript: getRawJavascriptParserOptions(parser)
431
432
  };
432
433
  }
433
- else if (type === "css") {
434
+ if (type === "css") {
434
435
  return {
435
436
  type: "css",
436
437
  css: getRawCssParserOptions(parser)
437
438
  };
438
439
  }
439
- else if (type === "css/auto") {
440
+ if (type === "css/auto") {
440
441
  return {
441
442
  type: "css/auto",
442
443
  cssAuto: getRawCssParserOptions(parser)
443
444
  };
444
445
  }
445
- else if (type === "css/module") {
446
+ if (type === "css/module") {
446
447
  return {
447
448
  type: "css/module",
448
449
  cssModule: getRawCssParserOptions(parser)
@@ -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 { Mode, Resolve, RuleSetUseItem, Target } from "./zod";
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?: string;
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, options) => {
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
- * @param {string[]} browsers supported browsers list
11
- * @returns {EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties} target properties
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
- export function resolve(browsers: string[]): EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties;
10
+ import type { ApiTargetProperties, EcmaTargetProperties, PlatformTargetProperties } from "./target";
14
11
  /**
15
- * @param {string | null | undefined} input input string
16
- * @param {string} context the context directory
17
- * @returns {string[] | undefined} selected browsers
12
+ * @param input input string
13
+ * @param context the context directory
14
+ * @returns selected browsers
18
15
  */
19
- export function load(input: string | null | undefined, context: string): string[] | undefined;
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;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * The following code is modified based on
3
4
  * https://github.com/webpack/webpack/blob/4b4ca3b/lib/config/browserslistTargetHandler.js
@@ -7,43 +8,38 @@
7
8
  * Copyright (c) JS Foundation and other contributors
8
9
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
10
  */
10
- "use strict";
11
- const browserslist = require("../../compiled/browserslist");
12
- const path = require("node:path");
13
- /** @typedef {import("./target").ApiTargetProperties} ApiTargetProperties */
14
- /** @typedef {import("./target").EcmaTargetProperties} EcmaTargetProperties */
15
- /** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.resolve = exports.load = void 0;
16
+ const node_path_1 = __importDefault(require("node:path"));
17
+ const browserslist_1 = __importDefault(require("../../compiled/browserslist"));
16
18
  // [[C:]/path/to/config][:env]
17
19
  const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
18
20
  /**
19
- * @typedef {Object} BrowserslistHandlerConfig
20
- * @property {string=} configPath
21
- * @property {string=} env
22
- * @property {string=} query
23
- */
24
- /**
25
- * @param {string | null | undefined} input input string
26
- * @param {string} context the context directory
27
- * @returns {BrowserslistHandlerConfig} config
21
+ * @param input input string
22
+ * @param context the context directory
23
+ * @returns config
28
24
  */
29
25
  const parse = (input, context) => {
30
26
  if (!input) {
31
27
  return {};
32
28
  }
33
- if (path.isAbsolute(input)) {
29
+ if (node_path_1.default.isAbsolute(input)) {
34
30
  const [, configPath, env] = inputRx.exec(input) || [];
35
31
  return { configPath, env };
36
32
  }
37
- const config = browserslist.findConfig(context);
33
+ const config = browserslist_1.default.findConfig(context);
38
34
  if (config && Object.keys(config).includes(input)) {
39
35
  return { env: input };
40
36
  }
41
37
  return { query: input };
42
38
  };
43
39
  /**
44
- * @param {string | null | undefined} input input string
45
- * @param {string} context the context directory
46
- * @returns {string[] | undefined} selected browsers
40
+ * @param input input string
41
+ * @param context the context directory
42
+ * @returns selected browsers
47
43
  */
48
44
  const load = (input, context) => {
49
45
  const { configPath, env, query } = parse(input, context);
@@ -53,26 +49,27 @@ const load = (input, context) => {
53
49
  const config = query
54
50
  ? query
55
51
  : configPath
56
- ? browserslist.loadConfig({
52
+ ? browserslist_1.default.loadConfig({
57
53
  config: configPath,
58
54
  env
59
55
  })
60
- : browserslist.loadConfig({ path: context, env });
56
+ : browserslist_1.default.loadConfig({ path: context, env });
61
57
  if (!config)
62
58
  return;
63
- return browserslist(config);
59
+ return (0, browserslist_1.default)(config);
64
60
  };
61
+ exports.load = load;
65
62
  /**
66
- * @param {string[]} browsers supported browsers list
67
- * @returns {EcmaTargetProperties & PlatformTargetProperties & ApiTargetProperties} target properties
63
+ * @param browsers supported browsers list
64
+ * @returns target properties
68
65
  */
69
- const resolve = browsers => {
66
+ const resolve = (browsers) => {
70
67
  /**
71
68
  * Checks all against a version number
72
- * @param {Record<string, number | [number, number]>} versions first supported version
73
- * @returns {boolean} true if supports
69
+ * @param versions first supported version
70
+ * @returns true if supports
74
71
  */
75
- const rawChecker = versions => {
72
+ const rawChecker = (versions) => {
76
73
  return browsers.every(v => {
77
74
  const [name, parsedVersion] = v.split(" ");
78
75
  if (!name)
@@ -344,7 +341,4 @@ const resolve = browsers => {
344
341
  require: nodeProperty
345
342
  };
346
343
  };
347
- module.exports = {
348
- resolve,
349
- load
350
- };
344
+ exports.resolve = resolve;