@atlaspack/runtime-browser-hmr 2.14.0 → 2.14.1-canary.10

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _plugin() {
8
+ const data = require("@atlaspack/plugin");
9
+ _plugin = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _fs() {
15
+ const data = _interopRequireDefault(require("fs"));
16
+ _fs = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _path() {
22
+ const data = _interopRequireDefault(require("path"));
23
+ _path = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+ // Without this, the hmr-runtime.js is transpiled with the React Refresh swc transform because it
30
+ // lives in `/app/packages/runtimes/...` and thus the `config` in the JSTransformer is actually the
31
+ // user's package.json, and hmr-runtime.js is transpiled as a JSX asset.
32
+ const FILENAME =
33
+ // $FlowFixMe
34
+ process.env.ATLASPACK_BUILD_REPL && process.browser ? '/' + __filename : __filename;
35
+ const HMR_RUNTIME = _fs().default.readFileSync(_path().default.join(__dirname, './loaders/hmr-runtime.js'), 'utf8');
36
+ var _default = exports.default = new (_plugin().Runtime)({
37
+ apply({
38
+ bundle,
39
+ options
40
+ }) {
41
+ if (bundle.type !== 'js' || !options.hmrOptions || bundle.env.isLibrary || bundle.env.isWorklet() || bundle.env.sourceType === 'script') {
42
+ return;
43
+ }
44
+ const {
45
+ host,
46
+ port
47
+ } = options.hmrOptions;
48
+ return {
49
+ filePath: FILENAME,
50
+ code: `var HMR_HOST = ${JSON.stringify(host != null && host !== '0.0.0.0' ? host : null)};` + `var HMR_PORT = ${JSON.stringify(port != null && (
51
+ // Default to the HTTP port in the browser, only override
52
+ // in watch mode or if hmr port != serve port
53
+ !options.serveOptions || options.serveOptions.port !== port) ? port : null)};` + `var HMR_SECURE = ${JSON.stringify(!!(options.serveOptions && options.serveOptions.https))};` + `var HMR_ENV_HASH = "${bundle.env.id}";` + `var HMR_USE_SSE = ${JSON.stringify(
54
+ // $FlowFixMe
55
+ !!(process.env.ATLASPACK_BUILD_REPL && process.browser))};` + `module.bundle.HMR_BUNDLE_ID = ${JSON.stringify(bundle.id)};` + HMR_RUNTIME,
56
+ isEntry: true,
57
+ env: {
58
+ sourceType: 'module'
59
+ }
60
+ };
61
+ }
62
+ });
@@ -0,0 +1,506 @@
1
+ "use strict";
2
+
3
+ /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */
4
+ /*::
5
+ import type {
6
+ HMRAsset,
7
+ HMRMessage,
8
+ } from '@atlaspack/reporter-dev-server/src/HMRServer';
9
+ interface ParcelRequire {
10
+ (string): mixed;
11
+ cache: {|[string]: ParcelModule|};
12
+ hotData: {|[string]: mixed|};
13
+ Module: any;
14
+ parent: ?ParcelRequire;
15
+ isParcelRequire: true;
16
+ modules: {|[string]: [Function, {|[string]: string|}]|};
17
+ HMR_BUNDLE_ID: string;
18
+ root: ParcelRequire;
19
+ }
20
+ interface ParcelModule {
21
+ hot: {|
22
+ data: mixed,
23
+ accept(cb: (Function) => void): void,
24
+ dispose(cb: (mixed) => void): void,
25
+ // accept(deps: Array<string> | string, cb: (Function) => void): void,
26
+ // decline(): void,
27
+ _acceptCallbacks: Array<(Function) => void>,
28
+ _disposeCallbacks: Array<(mixed) => void>,
29
+ |};
30
+ }
31
+ interface ExtensionContext {
32
+ runtime: {|
33
+ reload(): void,
34
+ getURL(url: string): string;
35
+ getManifest(): {manifest_version: number, ...};
36
+ |};
37
+ }
38
+ declare var module: {bundle: ParcelRequire, ...};
39
+ declare var HMR_HOST: string;
40
+ declare var HMR_PORT: string;
41
+ declare var HMR_ENV_HASH: string;
42
+ declare var HMR_SECURE: boolean;
43
+ declare var HMR_USE_SSE: boolean;
44
+ declare var chrome: ExtensionContext;
45
+ declare var browser: ExtensionContext;
46
+ declare var __parcel__import__: (string) => Promise<void>;
47
+ declare var __parcel__importScripts__: (string) => Promise<void>;
48
+ declare var globalThis: typeof self;
49
+ declare var ServiceWorkerGlobalScope: Object;
50
+ */
51
+ var OVERLAY_ID = '__parcel__error__overlay__';
52
+ var OldModule = module.bundle.Module;
53
+ function Module(moduleName) {
54
+ OldModule.call(this, moduleName);
55
+ this.hot = {
56
+ data: module.bundle.hotData[moduleName],
57
+ _acceptCallbacks: [],
58
+ _disposeCallbacks: [],
59
+ accept: function (fn) {
60
+ this._acceptCallbacks.push(fn || function () {});
61
+ },
62
+ dispose: function (fn) {
63
+ this._disposeCallbacks.push(fn);
64
+ }
65
+ };
66
+ module.bundle.hotData[moduleName] = undefined;
67
+ }
68
+ module.bundle.Module = Module;
69
+ module.bundle.hotData = {};
70
+ var checkedAssets /*: {|[string]: boolean|} */, assetsToDispose /*: Array<[ParcelRequire, string]> */, assetsToAccept /*: Array<[ParcelRequire, string]> */;
71
+
72
+ function getHostname() {
73
+ return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
74
+ }
75
+ function getPort() {
76
+ return HMR_PORT || location.port;
77
+ }
78
+
79
+ // eslint-disable-next-line no-redeclare
80
+ var parent = module.bundle.parent;
81
+ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
82
+ var hostname = getHostname();
83
+ var port = getPort();
84
+ var protocol = HMR_SECURE || location.protocol == 'https:' && !['localhost', '127.0.0.1', '0.0.0.0'].includes(hostname) ? 'wss' : 'ws';
85
+ var ws;
86
+ if (HMR_USE_SSE) {
87
+ ws = new EventSource('/__parcel_hmr');
88
+ } else {
89
+ try {
90
+ ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
91
+ } catch (err) {
92
+ if (err.message) {
93
+ console.error(err.message);
94
+ }
95
+ ws = {};
96
+ }
97
+ }
98
+
99
+ // Web extension context
100
+ var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
101
+
102
+ // Safari doesn't support sourceURL in error stacks.
103
+ // eval may also be disabled via CSP, so do a quick check.
104
+ var supportsSourceURL = false;
105
+ try {
106
+ (0, eval)('throw new Error("test"); //# sourceURL=test.js');
107
+ } catch (err) {
108
+ supportsSourceURL = err.stack.includes('test.js');
109
+ }
110
+
111
+ // $FlowFixMe
112
+ ws.onmessage = async function (event /*: {data: string, ...} */) {
113
+ checkedAssets = {} /*: {|[string]: boolean|} */;
114
+ assetsToAccept = [];
115
+ assetsToDispose = [];
116
+ var data /*: HMRMessage */ = JSON.parse(event.data);
117
+ if (data.type === 'reload') {
118
+ fullReload();
119
+ } else if (data.type === 'update') {
120
+ // Remove error overlay if there is one
121
+ if (typeof document !== 'undefined') {
122
+ removeErrorOverlay();
123
+ }
124
+ let assets = data.assets.filter(asset => asset.envHash === HMR_ENV_HASH);
125
+
126
+ // Handle HMR Update
127
+ let handled = assets.every(asset => {
128
+ return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
129
+ });
130
+ if (handled) {
131
+ console.clear();
132
+
133
+ // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
134
+ if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
135
+ window.dispatchEvent(new CustomEvent('parcelhmraccept'));
136
+ }
137
+ await hmrApplyUpdates(assets);
138
+
139
+ // Dispose all old assets.
140
+ let processedAssets = {} /*: {|[string]: boolean|} */;
141
+ for (let i = 0; i < assetsToDispose.length; i++) {
142
+ let id = assetsToDispose[i][1];
143
+ if (!processedAssets[id]) {
144
+ hmrDispose(assetsToDispose[i][0], id);
145
+ processedAssets[id] = true;
146
+ }
147
+ }
148
+
149
+ // Run accept callbacks. This will also re-execute other disposed assets in topological order.
150
+ processedAssets = {};
151
+ for (let i = 0; i < assetsToAccept.length; i++) {
152
+ let id = assetsToAccept[i][1];
153
+ if (!processedAssets[id]) {
154
+ hmrAccept(assetsToAccept[i][0], id);
155
+ processedAssets[id] = true;
156
+ }
157
+ }
158
+ } else fullReload();
159
+ }
160
+ if (data.type === 'error') {
161
+ // Log parcel errors to console
162
+ for (let ansiDiagnostic of data.diagnostics.ansi) {
163
+ let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
164
+ console.error('🚨 [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
165
+ }
166
+ if (typeof document !== 'undefined') {
167
+ // Render the fancy html overlay
168
+ removeErrorOverlay();
169
+ var overlay = createErrorOverlay(data.diagnostics.html);
170
+ // $FlowFixMe
171
+ document.body.appendChild(overlay);
172
+ }
173
+ }
174
+ };
175
+ if (ws instanceof WebSocket) {
176
+ ws.onerror = function (e) {
177
+ if (e.message) {
178
+ console.error(e.message);
179
+ }
180
+ };
181
+ ws.onclose = function () {
182
+ console.warn('[parcel] 🚨 Connection to the HMR server was lost');
183
+ };
184
+ }
185
+ }
186
+ function removeErrorOverlay() {
187
+ var overlay = document.getElementById(OVERLAY_ID);
188
+ if (overlay) {
189
+ overlay.remove();
190
+ console.log('[parcel] ✨ Error resolved');
191
+ }
192
+ }
193
+ function createErrorOverlay(diagnostics) {
194
+ var overlay = document.createElement('div');
195
+ overlay.id = OVERLAY_ID;
196
+ let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
197
+ for (let diagnostic of diagnostics) {
198
+ let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame) => {
199
+ return `${p}
200
+ <a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
201
+ ${frame.code}`;
202
+ }, '') : diagnostic.stack;
203
+ errorHTML += `
204
+ <div>
205
+ <div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
206
+ 🚨 ${diagnostic.message}
207
+ </div>
208
+ <pre>${stack}</pre>
209
+ <div>
210
+ ${diagnostic.hints.map(hint => '<div>💡 ' + hint + '</div>').join('')}
211
+ </div>
212
+ ${diagnostic.documentation ? `<div>📝 <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
213
+ </div>
214
+ `;
215
+ }
216
+ errorHTML += '</div>';
217
+ overlay.innerHTML = errorHTML;
218
+ return overlay;
219
+ }
220
+ function fullReload() {
221
+ if ('reload' in location) {
222
+ location.reload();
223
+ } else if (extCtx && extCtx.runtime && extCtx.runtime.reload) {
224
+ extCtx.runtime.reload();
225
+ }
226
+ }
227
+ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */{
228
+ var modules = bundle.modules;
229
+ if (!modules) {
230
+ return [];
231
+ }
232
+ var parents = [];
233
+ var k, d, dep;
234
+ for (k in modules) {
235
+ for (d in modules[k][1]) {
236
+ dep = modules[k][1][d];
237
+ if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) {
238
+ parents.push([bundle, k]);
239
+ }
240
+ }
241
+ }
242
+ if (bundle.parent) {
243
+ parents = parents.concat(getParents(bundle.parent, id));
244
+ }
245
+ return parents;
246
+ }
247
+ function updateLink(link) {
248
+ var href = link.getAttribute('href');
249
+ if (!href) {
250
+ return;
251
+ }
252
+ var newLink = link.cloneNode();
253
+ newLink.onload = function () {
254
+ if (link.parentNode !== null) {
255
+ // $FlowFixMe
256
+ link.parentNode.removeChild(link);
257
+ }
258
+ };
259
+ newLink.setAttribute('href',
260
+ // $FlowFixMe
261
+ href.split('?')[0] + '?' + Date.now());
262
+ // $FlowFixMe
263
+ link.parentNode.insertBefore(newLink, link.nextSibling);
264
+ }
265
+ var cssTimeout = null;
266
+ function reloadCSS() {
267
+ if (cssTimeout) {
268
+ return;
269
+ }
270
+ cssTimeout = setTimeout(function () {
271
+ var links = document.querySelectorAll('link[rel="stylesheet"]');
272
+ for (var i = 0; i < links.length; i++) {
273
+ // $FlowFixMe[incompatible-type]
274
+ var href /*: string */ = links[i].getAttribute('href');
275
+ var hostname = getHostname();
276
+ var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
277
+ var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
278
+ if (!absolute) {
279
+ updateLink(links[i]);
280
+ }
281
+ }
282
+ cssTimeout = null;
283
+ }, 50);
284
+ }
285
+ function hmrDownload(asset) {
286
+ if (asset.type === 'js') {
287
+ if (typeof document !== 'undefined') {
288
+ let script = document.createElement('script');
289
+ script.src = asset.url + '?t=' + Date.now();
290
+ if (asset.outputFormat === 'esmodule') {
291
+ script.type = 'module';
292
+ }
293
+ return new Promise((resolve, reject) => {
294
+ var _document$head;
295
+ script.onload = () => resolve(script);
296
+ script.onerror = reject;
297
+ (_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
298
+ });
299
+ } else if (typeof importScripts === 'function') {
300
+ // Worker scripts
301
+ if (asset.outputFormat === 'esmodule') {
302
+ return __parcel__import__(asset.url + '?t=' + Date.now());
303
+ } else {
304
+ return new Promise((resolve, reject) => {
305
+ try {
306
+ __parcel__importScripts__(asset.url + '?t=' + Date.now());
307
+ resolve();
308
+ } catch (err) {
309
+ reject(err);
310
+ }
311
+ });
312
+ }
313
+ }
314
+ }
315
+ }
316
+ async function hmrApplyUpdates(assets) {
317
+ global.parcelHotUpdate = Object.create(null);
318
+ let scriptsToRemove;
319
+ try {
320
+ // If sourceURL comments aren't supported in eval, we need to load
321
+ // the update from the dev server over HTTP so that stack traces
322
+ // are correct in errors/logs. This is much slower than eval, so
323
+ // we only do it if needed (currently just Safari).
324
+ // https://bugs.webkit.org/show_bug.cgi?id=137297
325
+ // This path is also taken if a CSP disallows eval.
326
+ if (!supportsSourceURL) {
327
+ let promises = assets.map(asset => {
328
+ var _hmrDownload;
329
+ return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch(err => {
330
+ // Web extension fix
331
+ if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
332
+ extCtx.runtime.reload();
333
+ return;
334
+ }
335
+ throw err;
336
+ });
337
+ });
338
+ scriptsToRemove = await Promise.all(promises);
339
+ }
340
+ assets.forEach(function (asset) {
341
+ hmrApply(module.bundle.root, asset);
342
+ });
343
+ } finally {
344
+ delete global.parcelHotUpdate;
345
+ if (scriptsToRemove) {
346
+ scriptsToRemove.forEach(script => {
347
+ if (script) {
348
+ var _document$head2;
349
+ (_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
350
+ }
351
+ });
352
+ }
353
+ }
354
+ }
355
+ function hmrApply(bundle /*: ParcelRequire */, asset /*: HMRAsset */) {
356
+ var modules = bundle.modules;
357
+ if (!modules) {
358
+ return;
359
+ }
360
+ if (asset.type === 'css') {
361
+ reloadCSS();
362
+ } else if (asset.type === 'js') {
363
+ let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
364
+ if (deps) {
365
+ if (modules[asset.id]) {
366
+ // Remove dependencies that are removed and will become orphaned.
367
+ // This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
368
+ let oldDeps = modules[asset.id][1];
369
+ for (let dep in oldDeps) {
370
+ if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
371
+ let id = oldDeps[dep];
372
+ let parents = getParents(module.bundle.root, id);
373
+ if (parents.length === 1) {
374
+ hmrDelete(module.bundle.root, id);
375
+ }
376
+ }
377
+ }
378
+ }
379
+ if (supportsSourceURL) {
380
+ // Global eval. We would use `new Function` here but browser
381
+ // support for source maps is better with eval.
382
+ (0, eval)(asset.output);
383
+ }
384
+
385
+ // $FlowFixMe
386
+ let fn = global.parcelHotUpdate[asset.id];
387
+ modules[asset.id] = [fn, deps];
388
+ } else if (bundle.parent) {
389
+ hmrApply(bundle.parent, asset);
390
+ }
391
+ }
392
+ }
393
+ function hmrDelete(bundle, id) {
394
+ let modules = bundle.modules;
395
+ if (!modules) {
396
+ return;
397
+ }
398
+ if (modules[id]) {
399
+ // Collect dependencies that will become orphaned when this module is deleted.
400
+ let deps = modules[id][1];
401
+ let orphans = [];
402
+ for (let dep in deps) {
403
+ let parents = getParents(module.bundle.root, deps[dep]);
404
+ if (parents.length === 1) {
405
+ orphans.push(deps[dep]);
406
+ }
407
+ }
408
+
409
+ // Delete the module. This must be done before deleting dependencies in case of circular dependencies.
410
+ delete modules[id];
411
+ delete bundle.cache[id];
412
+
413
+ // Now delete the orphans.
414
+ orphans.forEach(id => {
415
+ hmrDelete(module.bundle.root, id);
416
+ });
417
+ } else if (bundle.parent) {
418
+ hmrDelete(bundle.parent, id);
419
+ }
420
+ }
421
+ function hmrAcceptCheck(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
422
+ if (hmrAcceptCheckOne(bundle, id, depsByBundle)) {
423
+ return true;
424
+ }
425
+
426
+ // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
427
+ let parents = getParents(module.bundle.root, id);
428
+ let accepted = false;
429
+ while (parents.length > 0) {
430
+ let v = parents.shift();
431
+ let a = hmrAcceptCheckOne(v[0], v[1], null);
432
+ if (a) {
433
+ // If this parent accepts, stop traversing upward, but still consider siblings.
434
+ accepted = true;
435
+ } else {
436
+ // Otherwise, queue the parents in the next level upward.
437
+ let p = getParents(module.bundle.root, v[1]);
438
+ if (p.length === 0) {
439
+ // If there are no parents, then we've reached an entry without accepting. Reload.
440
+ accepted = false;
441
+ break;
442
+ }
443
+ parents.push(...p);
444
+ }
445
+ }
446
+ return accepted;
447
+ }
448
+ function hmrAcceptCheckOne(bundle /*: ParcelRequire */, id /*: string */, depsByBundle /*: ?{ [string]: { [string]: string } }*/) {
449
+ var modules = bundle.modules;
450
+ if (!modules) {
451
+ return;
452
+ }
453
+ if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
454
+ // If we reached the root bundle without finding where the asset should go,
455
+ // there's nothing to do. Mark as "accepted" so we don't reload the page.
456
+ if (!bundle.parent) {
457
+ return true;
458
+ }
459
+ return hmrAcceptCheck(bundle.parent, id, depsByBundle);
460
+ }
461
+ if (checkedAssets[id]) {
462
+ return true;
463
+ }
464
+ checkedAssets[id] = true;
465
+ var cached = bundle.cache[id];
466
+ assetsToDispose.push([bundle, id]);
467
+ if (!cached || cached.hot && cached.hot._acceptCallbacks.length) {
468
+ assetsToAccept.push([bundle, id]);
469
+ return true;
470
+ }
471
+ }
472
+ function hmrDispose(bundle /*: ParcelRequire */, id /*: string */) {
473
+ var cached = bundle.cache[id];
474
+ bundle.hotData[id] = {};
475
+ if (cached && cached.hot) {
476
+ cached.hot.data = bundle.hotData[id];
477
+ }
478
+ if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
479
+ cached.hot._disposeCallbacks.forEach(function (cb) {
480
+ cb(bundle.hotData[id]);
481
+ });
482
+ }
483
+ delete bundle.cache[id];
484
+ }
485
+ function hmrAccept(bundle /*: ParcelRequire */, id /*: string */) {
486
+ // Execute the module.
487
+ bundle(id);
488
+
489
+ // Run the accept callbacks in the new version of the module.
490
+ var cached = bundle.cache[id];
491
+ if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
492
+ cached.hot._acceptCallbacks.forEach(function (cb) {
493
+ var assetsToAlsoAccept = cb(function () {
494
+ return getParents(module.bundle.root, id);
495
+ });
496
+ if (assetsToAlsoAccept && assetsToAccept.length) {
497
+ assetsToAlsoAccept.forEach(function (a) {
498
+ hmrDispose(a[0], a[1]);
499
+ });
500
+
501
+ // $FlowFixMe[method-unbinding]
502
+ assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
503
+ }
504
+ });
505
+ }
506
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/runtime-browser-hmr",
3
- "version": "2.14.0",
3
+ "version": "2.14.1-canary.10+3b66d6b4b",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,12 +12,12 @@
12
12
  "main": "lib/HMRRuntime.js",
13
13
  "source": "src/HMRRuntime.js",
14
14
  "engines": {
15
- "atlaspack": "^2.12.0",
16
15
  "node": ">= 16.0.0"
17
16
  },
18
17
  "dependencies": {
19
- "@atlaspack/plugin": "2.14.0",
20
- "@atlaspack/utils": "2.14.0"
18
+ "@atlaspack/plugin": "2.14.1-canary.10+3b66d6b4b",
19
+ "@atlaspack/utils": "2.14.1-canary.10+3b66d6b4b"
21
20
  },
22
- "type": "commonjs"
21
+ "type": "commonjs",
22
+ "gitHead": "3b66d6b4bfd652ab3b41e86aacf3e47d39cd5a70"
23
23
  }