@rspack/core 1.3.4 → 1.3.6

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.
@@ -1,224 +1,125 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
2
+ var __webpack_require__ = {};
3
+ __webpack_require__.d = (exports1, definition)=>{
4
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
5
+ enumerable: !0,
6
+ get: definition[key]
7
+ });
8
+ }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
9
+ 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
10
+ value: 'Module'
11
+ }), Object.defineProperty(exports1, '__esModule', {
12
+ value: !0
13
+ });
17
14
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/runtime/cssExtractHmr.ts
21
- var cssExtractHmr_exports = {};
22
- __export(cssExtractHmr_exports, {
23
- cssReload: () => cssReload,
24
- normalizeUrl: () => normalizeUrl
25
- });
26
- module.exports = __toCommonJS(cssExtractHmr_exports);
15
+ var __webpack_exports__ = {};
27
16
  function normalizeUrl(url) {
28
- const urlString = url.trim();
29
- if (/^data:/i.test(urlString)) {
30
- return urlString;
31
- }
32
- const protocol = urlString.indexOf("//") !== -1 ? `${urlString.split("//")[0]}//` : "";
33
- const components = urlString.replace(new RegExp(protocol, "i"), "").split("/");
34
- const host = components[0].toLowerCase().replace(/\.$/, "");
35
- components[0] = "";
36
- const path = components.reduce((accumulator, item) => {
37
- switch (item) {
38
- case "..":
39
- accumulator.pop();
40
- break;
41
- case ".":
42
- break;
43
- default:
44
- accumulator.push(item);
45
- }
46
- return accumulator;
47
- }, []).join("/");
48
- return protocol + host + path;
49
- }
50
- var srcByModuleId = /* @__PURE__ */ Object.create(null);
51
- var noDocument = typeof document === "undefined";
52
- var { forEach } = Array.prototype;
53
- function debounce(fn, time) {
54
- let timeout = 0;
55
- return function(...args) {
56
- const self = this;
57
- const functionCall = function functionCall2() {
58
- return fn.apply(self, args);
59
- };
60
- clearTimeout(timeout);
61
- timeout = setTimeout(functionCall, time);
62
- };
63
- }
64
- function noop() {
65
- }
66
- function getCurrentScriptUrl(moduleId) {
67
- let src = srcByModuleId[moduleId];
68
- if (!src) {
69
- if (document.currentScript) {
70
- ({ src } = document.currentScript);
71
- } else {
72
- const scripts = document.getElementsByTagName("script");
73
- const lastScriptTag = scripts[scripts.length - 1];
74
- if (lastScriptTag) {
75
- ({ src } = lastScriptTag);
76
- }
77
- }
78
- srcByModuleId[moduleId] = src;
79
- }
80
- return (fileMap) => {
81
- if (!src) {
82
- return null;
83
- }
84
- const splitResult = src.match(/([^\\/]+)\.js$/);
85
- const filename = splitResult && splitResult[1];
86
- if (!filename || !fileMap) {
87
- return [src.replace(".js", ".css")];
88
- }
89
- return fileMap.split(",").map((mapRule) => {
90
- const reg = new RegExp(`${filename}\\.js$`, "g");
91
- return normalizeUrl(
92
- src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`)
93
- );
94
- });
95
- };
17
+ let urlString = url.trim();
18
+ if (/^data:/i.test(urlString)) return urlString;
19
+ let protocol = -1 !== urlString.indexOf("//") ? `${urlString.split("//")[0]}//` : "", components = urlString.replace(RegExp(protocol, "i"), "").split("/"), host = components[0].toLowerCase().replace(/\.$/, "");
20
+ return components[0] = "", protocol + host + components.reduce((accumulator, item)=>{
21
+ switch(item){
22
+ case "..":
23
+ accumulator.pop();
24
+ break;
25
+ case ".":
26
+ break;
27
+ default:
28
+ accumulator.push(item);
29
+ }
30
+ return accumulator;
31
+ }, []).join("/");
96
32
  }
33
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
34
+ cssReload: ()=>cssReload,
35
+ normalizeUrl: ()=>normalizeUrl
36
+ });
37
+ let srcByModuleId = Object.create(null), noDocument = "undefined" == typeof document, { forEach } = Array.prototype;
38
+ function noop() {}
97
39
  function updateCss(el, url) {
98
- let normalizedUrl;
99
- if (!url) {
100
- if (!el.href) {
101
- return;
102
- }
103
- normalizedUrl = el.href.split("?")[0];
104
- } else {
105
- normalizedUrl = url;
106
- }
107
- if (!isUrlRequest(normalizedUrl)) {
108
- return;
109
- }
110
- if (el.isLoaded === false) {
111
- return;
112
- }
113
- if (!normalizedUrl || !(normalizedUrl.indexOf(".css") > -1)) {
114
- return;
115
- }
116
- el.visited = true;
117
- const newEl = el.cloneNode();
118
- newEl.isLoaded = false;
119
- newEl.addEventListener("load", () => {
120
- if (newEl.isLoaded) {
121
- return;
122
- }
123
- newEl.isLoaded = true;
124
- if (el.parentNode) {
125
- el.parentNode.removeChild(el);
126
- }
127
- });
128
- newEl.addEventListener("error", () => {
129
- if (newEl.isLoaded) {
130
- return;
131
- }
132
- newEl.isLoaded = true;
133
- if (el.parentNode) {
134
- el.parentNode.removeChild(el);
135
- }
136
- });
137
- newEl.href = `${normalizedUrl}?${Date.now()}`;
138
- const parent = el.parentNode;
139
- if (!parent) {
140
- return;
141
- }
142
- if (el.nextSibling) {
143
- parent.insertBefore(newEl, el.nextSibling);
144
- } else {
145
- parent.appendChild(newEl);
146
- }
147
- }
148
- function getReloadUrl(href, src) {
149
- let ret = "";
150
- const normalizedHref = normalizeUrl(href);
151
- src.some((url) => {
152
- if (normalizedHref.indexOf(src) > -1) {
153
- ret = url;
154
- }
155
- });
156
- return ret;
157
- }
158
- function reloadStyle(src) {
159
- if (!src) {
160
- return false;
161
- }
162
- const elements = document.querySelectorAll("link");
163
- let loaded = false;
164
- forEach.call(elements, (el) => {
165
- if (!el.href) {
166
- return;
167
- }
168
- const url = getReloadUrl(el.href, src);
169
- if (!isUrlRequest(url)) {
170
- return;
171
- }
172
- if (el.visited === true) {
173
- return;
174
- }
175
- if (url) {
176
- updateCss(el, url);
177
- loaded = true;
178
- }
179
- });
180
- return loaded;
40
+ let normalizedUrl;
41
+ if (url) normalizedUrl = url;
42
+ else {
43
+ if (!el.href) return;
44
+ normalizedUrl = el.href.split("?")[0];
45
+ }
46
+ if (!isUrlRequest(normalizedUrl) || !1 === el.isLoaded || !normalizedUrl || !(normalizedUrl.indexOf(".css") > -1)) return;
47
+ el.visited = !0;
48
+ let newEl = el.cloneNode();
49
+ newEl.isLoaded = !1, newEl.addEventListener("load", ()=>{
50
+ !newEl.isLoaded && (newEl.isLoaded = !0, el.parentNode && el.parentNode.removeChild(el));
51
+ }), newEl.addEventListener("error", ()=>{
52
+ !newEl.isLoaded && (newEl.isLoaded = !0, el.parentNode && el.parentNode.removeChild(el));
53
+ }), newEl.href = `${normalizedUrl}?${Date.now()}`;
54
+ let parent = el.parentNode;
55
+ parent && (el.nextSibling ? parent.insertBefore(newEl, el.nextSibling) : parent.appendChild(newEl));
181
56
  }
182
57
  function reloadAll() {
183
- const elements = document.querySelectorAll("link");
184
- forEach.call(elements, (el) => {
185
- if (el.visited === true) {
186
- return;
187
- }
188
- updateCss(el);
189
- });
58
+ let elements = document.querySelectorAll("link");
59
+ forEach.call(elements, (el)=>{
60
+ !0 !== el.visited && updateCss(el);
61
+ });
190
62
  }
191
63
  function isUrlRequest(url) {
192
- if (!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url)) {
193
- return false;
194
- }
195
- return true;
64
+ return !!/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
196
65
  }
197
66
  function cssReload(moduleId, options) {
198
- if (noDocument) {
199
- console.log("[HMR] No `window.document` found, CSS HMR disabled");
200
- return noop;
201
- }
202
- const getScriptSrc = getCurrentScriptUrl(moduleId);
203
- function update() {
204
- const src = getScriptSrc(options.filename);
205
- const reloaded = reloadStyle(src);
206
- if (options.locals) {
207
- console.log("[HMR] Detected local CSS Modules. Reload all CSS");
208
- reloadAll();
209
- return;
210
- }
211
- if (reloaded) {
212
- console.log("[HMR] CSS reload %s", src && src.join(" "));
213
- } else {
214
- console.log("[HMR] Reload all CSS");
215
- reloadAll();
216
- }
217
- }
218
- return debounce(update, 50);
67
+ var fn;
68
+ let timeout;
69
+ if (noDocument) return console.log("[HMR] No `window.document` found, CSS HMR disabled"), noop;
70
+ let getScriptSrc = function(moduleId) {
71
+ let src = srcByModuleId[moduleId];
72
+ if (!src) {
73
+ if (document.currentScript) ({ src } = document.currentScript);
74
+ else {
75
+ let scripts = document.getElementsByTagName("script"), lastScriptTag = scripts[scripts.length - 1];
76
+ lastScriptTag && ({ src } = lastScriptTag);
77
+ }
78
+ srcByModuleId[moduleId] = src;
79
+ }
80
+ return (fileMap)=>{
81
+ if (!src) return null;
82
+ let splitResult = src.match(/([^\\/]+)\.js$/), filename = splitResult && splitResult[1];
83
+ return filename && fileMap ? fileMap.split(",").map((mapRule)=>{
84
+ let reg = RegExp(`${filename}\\.js$`, "g");
85
+ return normalizeUrl(src.replace(reg, `${mapRule.replace(/{fileName}/g, filename)}.css`));
86
+ }) : [
87
+ src.replace(".js", ".css")
88
+ ];
89
+ };
90
+ }(moduleId);
91
+ return fn = function() {
92
+ let src = getScriptSrc(options.filename), reloaded = function(src) {
93
+ if (!src) return !1;
94
+ let elements = document.querySelectorAll("link"), loaded = !1;
95
+ return forEach.call(elements, (el)=>{
96
+ if (!el.href) return;
97
+ let url = function(href, src) {
98
+ let ret = "", normalizedHref = normalizeUrl(href);
99
+ return src.some((url)=>{
100
+ normalizedHref.indexOf(src) > -1 && (ret = url);
101
+ }), ret;
102
+ }(el.href, src);
103
+ isUrlRequest(url) && !0 !== el.visited && url && (updateCss(el, url), loaded = !0);
104
+ }), loaded;
105
+ }(src);
106
+ if (options.locals) {
107
+ console.log("[HMR] Detected local CSS Modules. Reload all CSS"), reloadAll();
108
+ return;
109
+ }
110
+ reloaded ? console.log("[HMR] CSS reload %s", src && src.join(" ")) : (console.log("[HMR] Reload all CSS"), reloadAll());
111
+ }, timeout = 0, function() {
112
+ for(var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++)args[_key] = arguments[_key];
113
+ let self = this;
114
+ clearTimeout(timeout), timeout = setTimeout(function() {
115
+ return fn.apply(self, args);
116
+ }, 50);
117
+ };
219
118
  }
220
- // Annotate the CommonJS export names for ESM import in node:
221
- 0 && (module.exports = {
222
- cssReload,
223
- normalizeUrl
119
+ for(var __webpack_i__ in exports.cssReload = __webpack_exports__.cssReload, exports.normalizeUrl = __webpack_exports__.normalizeUrl, __webpack_exports__)-1 === [
120
+ "cssReload",
121
+ "normalizeUrl"
122
+ ].indexOf(__webpack_i__) && (exports[__webpack_i__] = __webpack_exports__[__webpack_i__]);
123
+ Object.defineProperty(exports, '__esModule', {
124
+ value: !0
224
125
  });