@jsenv/core 27.0.0-alpha.64 → 27.0.0-alpha.67

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 (151) hide show
  1. package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
  2. package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
  3. package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
  4. package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
  5. package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
  6. package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
  7. package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
  8. package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
  9. package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
  10. package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
  11. package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
  12. package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
  13. package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
  14. package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
  15. package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
  16. package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
  17. package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
  18. package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
  19. package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
  20. package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
  21. package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
  22. package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
  23. package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
  24. package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
  25. package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
  26. package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
  27. package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
  28. package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
  29. package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
  30. package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
  31. package/dist/babel_helpers/construct/construct.js +15 -0
  32. package/dist/babel_helpers/createClass/createClass.js +18 -0
  33. package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
  34. package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
  35. package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
  36. package/dist/babel_helpers/createSuper/createSuper.js +22 -0
  37. package/dist/babel_helpers/decorate/decorate.js +622 -0
  38. package/dist/babel_helpers/defaults/defaults.js +14 -0
  39. package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
  40. package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
  41. package/dist/babel_helpers/extends/extends.js +16 -0
  42. package/dist/babel_helpers/get/get.js +21 -0
  43. package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
  44. package/dist/babel_helpers/inherits/inherits.js +21 -0
  45. package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
  46. package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
  47. package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
  48. package/dist/babel_helpers/instanceof/instanceof.js +7 -0
  49. package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
  50. package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
  51. package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
  52. package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
  53. package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
  54. package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
  55. package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
  56. package/dist/babel_helpers/jsx/jsx.js +49 -0
  57. package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
  58. package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
  59. package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
  60. package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
  61. package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
  62. package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
  63. package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
  64. package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
  65. package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
  66. package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
  67. package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
  68. package/dist/babel_helpers/readme.md +8 -0
  69. package/dist/babel_helpers/set/set.js +51 -0
  70. package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
  71. package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
  72. package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
  73. package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
  74. package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
  75. package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
  76. package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
  77. package/dist/babel_helpers/tdz/tdz.js +4 -0
  78. package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
  79. package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
  80. package/dist/babel_helpers/toArray/toArray.js +5 -0
  81. package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
  82. package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
  83. package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
  84. package/dist/babel_helpers/typeof/typeof.js +7 -0
  85. package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
  86. package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
  87. package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
  88. package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
  89. package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
  90. package/dist/html/explorer.html +557 -0
  91. package/dist/js/controllable_file.mjs +227 -0
  92. package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
  93. package/dist/js/global_this.js +32 -0
  94. package/dist/js/html_supervisor_installer.js +522 -0
  95. package/dist/js/html_supervisor_setup.js +79 -0
  96. package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
  97. package/dist/js/inline_content.js +8 -0
  98. package/dist/js/new_stylesheet.js +409 -0
  99. package/dist/js/regenerator_runtime.js +721 -0
  100. package/dist/js/s.js +429 -0
  101. package/dist/main.js +13450 -0
  102. package/dist/other/jsenv.png +0 -0
  103. package/dist/s.js.map +59 -62
  104. package/package.json +16 -12
  105. package/src/build/build.js +169 -68
  106. package/src/build/build_urls_generator.js +18 -2
  107. package/src/build/inject_service_worker_urls.js +1 -1
  108. package/src/build/resync_ressource_hints.js +56 -9
  109. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  110. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
  111. package/src/dev/start_dev_server.js +17 -3
  112. package/src/execute/execute.js +3 -0
  113. package/src/omega/errors.js +12 -9
  114. package/src/omega/kitchen.js +252 -217
  115. package/src/omega/server/file_service.js +1 -1
  116. package/src/omega/url_graph/url_graph_report.js +2 -2
  117. package/src/omega/url_graph/url_info_transformations.js +10 -5
  118. package/src/omega/url_graph.js +3 -2
  119. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
  120. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
  121. package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
  122. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +185 -53
  123. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
  124. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
  125. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
  126. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +2 -2
  127. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +12 -2
  128. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
  129. package/src/plugins/plugin_controller.js +17 -3
  130. package/src/plugins/plugins.js +16 -19
  131. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +17 -19
  132. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_script_type_module_as_classic.js → jsenv_plugin_as_js_classic_html.js} +0 -0
  133. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +9 -4
  134. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +1 -2
  135. package/src/plugins/url_analysis/css/css_urls.js +1 -1
  136. package/src/plugins/url_analysis/html/html_urls.js +4 -1
  137. package/src/plugins/url_analysis/js/js_urls.js +3 -2
  138. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
  139. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
  140. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
  141. package/src/test/execute_plan.js +3 -1
  142. package/dist/event_source_client.js.map +0 -188
  143. package/dist/html_supervisor_installer.js +0 -1236
  144. package/dist/html_supervisor_installer.js.map +0 -337
  145. package/dist/html_supervisor_setup.js +0 -95
  146. package/dist/html_supervisor_setup.js.map +0 -57
  147. package/dist/import_meta_hot.js.map +0 -42
  148. package/src/jsenv_root_directory_url.js +0 -1
  149. package/src/omega/compat/default_runtime_compat.js +0 -11
  150. package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
  151. package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
@@ -0,0 +1,227 @@
1
+ import v8 from "node:v8";
2
+ import { uneval } from "@jsenv/uneval";
3
+ import { performance, PerformanceObserver } from "node:perf_hooks";
4
+
5
+ const startObservingPerformances = () => {
6
+ const measureEntries = []; // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html
7
+
8
+ const perfObserver = new PerformanceObserver(( // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceobserverentrylist
9
+ list) => {
10
+ const perfMeasureEntries = list.getEntriesByType("measure");
11
+ measureEntries.push(...perfMeasureEntries);
12
+ });
13
+ perfObserver.observe({
14
+ entryTypes: ["measure"]
15
+ });
16
+ return async () => {
17
+ // wait for node to call the performance observer
18
+ await new Promise(resolve => {
19
+ setTimeout(resolve);
20
+ });
21
+ performance.clearMarks();
22
+ perfObserver.disconnect();
23
+ return { ...readNodePerformance(),
24
+ measures: measuresFromMeasureEntries(measureEntries)
25
+ };
26
+ };
27
+ };
28
+
29
+ const readNodePerformance = () => {
30
+ const nodePerformance = {
31
+ nodeTiming: asPlainObject(performance.nodeTiming),
32
+ timeOrigin: performance.timeOrigin,
33
+ eventLoopUtilization: performance.eventLoopUtilization()
34
+ };
35
+ return nodePerformance;
36
+ }; // remove getters that cannot be stringified
37
+
38
+
39
+ const asPlainObject = objectWithGetters => {
40
+ const objectWithoutGetters = {};
41
+ Object.keys(objectWithGetters).forEach(key => {
42
+ objectWithoutGetters[key] = objectWithGetters[key];
43
+ });
44
+ return objectWithoutGetters;
45
+ };
46
+
47
+ const measuresFromMeasureEntries = measureEntries => {
48
+ const measures = {}; // Sort to ensure measures order is predictable
49
+ // It seems to be already predictable on Node 16+ but
50
+ // it's not the case on Node 14.
51
+
52
+ measureEntries.sort((a, b) => {
53
+ return a.startTime - b.startTime;
54
+ });
55
+ measureEntries.forEach(( // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceentry
56
+ perfMeasureEntry) => {
57
+ measures[perfMeasureEntry.name] = perfMeasureEntry.duration;
58
+ });
59
+ return measures;
60
+ };
61
+
62
+ const ACTIONS_AVAILABLE = {
63
+ "execute-using-dynamic-import": async ({
64
+ fileUrl,
65
+ collectPerformance
66
+ }) => {
67
+ const getNamespace = async () => {
68
+ const namespace = await import(fileUrl);
69
+ const namespaceResolved = {};
70
+ await Promise.all([...Object.keys(namespace).map(async key => {
71
+ const value = await namespace[key];
72
+ namespaceResolved[key] = value;
73
+ })]);
74
+ return namespaceResolved;
75
+ };
76
+
77
+ if (collectPerformance) {
78
+ const getPerformance = startObservingPerformances();
79
+ const namespace = await getNamespace();
80
+ const performance = await getPerformance();
81
+ return {
82
+ namespace,
83
+ performance
84
+ };
85
+ }
86
+
87
+ const namespace = await getNamespace();
88
+ return {
89
+ namespace
90
+ };
91
+ },
92
+ "execute-using-require": async ({
93
+ fileUrl
94
+ }) => {
95
+ const {
96
+ createRequire
97
+ } = await import("module");
98
+ const {
99
+ fileURLToPath
100
+ } = await import("url");
101
+ const filePath = fileURLToPath(fileUrl);
102
+
103
+ const require = createRequire(fileUrl); // eslint-disable-next-line import/no-dynamic-require
104
+
105
+
106
+ const namespace = require(filePath);
107
+
108
+ const namespaceResolved = {};
109
+ await Promise.all([...Object.keys(namespace).map(async key => {
110
+ const value = await namespace[key];
111
+ namespaceResolved[key] = value;
112
+ })]);
113
+ return namespaceResolved;
114
+ }
115
+ };
116
+ const ACTION_REQUEST_EVENT_NAME = "action";
117
+ const ACTION_RESPONSE_EVENT_NAME = "action-result";
118
+ const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
119
+ const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
120
+
121
+ const sendActionFailed = error => {
122
+ if (error.hasOwnProperty("toString")) {
123
+ delete error.toString;
124
+ }
125
+
126
+ sendToParent(ACTION_RESPONSE_EVENT_NAME, // process.send algorithm does not send non enumerable values
127
+ // so use @jsenv/uneval
128
+ uneval({
129
+ status: ACTION_RESPONSE_STATUS_FAILED,
130
+ value: error
131
+ }, {
132
+ ignoreSymbols: true
133
+ }));
134
+ };
135
+
136
+ const sendActionCompleted = value => {
137
+ sendToParent(ACTION_RESPONSE_EVENT_NAME, // here we use JSON.stringify because we should not
138
+ // have non enumerable value (unlike there is on Error objects)
139
+ // otherwise uneval is quite slow to turn a giant object
140
+ // into a string (and value can be giant when using coverage)
141
+ JSON.stringify({
142
+ status: ACTION_RESPONSE_STATUS_COMPLETED,
143
+ value
144
+ }));
145
+ };
146
+
147
+ const sendToParent = (type, data) => {
148
+ // https://nodejs.org/api/process.html#process_process_connected
149
+ // not connected anymore, cannot communicate with parent
150
+ if (!process.connected) {
151
+ return;
152
+ } // this can keep process alive longer than expected
153
+ // when source is a long string.
154
+ // It means node process may stay alive longer than expected
155
+ // the time to send the data to the parent.
156
+
157
+
158
+ process.send({
159
+ type,
160
+ data
161
+ });
162
+ };
163
+
164
+ const onceProcessMessage = (type, callback) => {
165
+ const listener = event => {
166
+ if (event.type === type) {
167
+ // commenting line below keep this process alive
168
+ removeListener(); // eslint-disable-next-line no-eval
169
+
170
+ callback(eval(`(${event.data})`));
171
+ }
172
+ };
173
+
174
+ const removeListener = () => {
175
+ process.removeListener("message", listener);
176
+ };
177
+
178
+ process.on("message", listener);
179
+ return removeListener;
180
+ };
181
+
182
+ const removeActionRequestListener = onceProcessMessage(ACTION_REQUEST_EVENT_NAME, async ({
183
+ actionType,
184
+ actionParams
185
+ }) => {
186
+ const action = ACTIONS_AVAILABLE[actionType];
187
+
188
+ if (!action) {
189
+ sendActionFailed(new Error(`unknown action ${actionType}`));
190
+ return;
191
+ }
192
+
193
+ let value;
194
+ let failed = false;
195
+
196
+ try {
197
+ value = await action(actionParams);
198
+ } catch (e) {
199
+ failed = true;
200
+ value = e;
201
+ }
202
+
203
+ if (process.env.NODE_V8_COVERAGE) {
204
+ v8.takeCoverage(); // if (actionParams.stopCoverageAfterExecution) {
205
+ // v8.stopCoverage()
206
+ // }
207
+ } // setTimeout(() => {}, 100)
208
+
209
+
210
+ if (failed) {
211
+ sendActionFailed(value);
212
+ } else {
213
+ sendActionCompleted(value);
214
+ } // removeActionRequestListener()
215
+
216
+
217
+ if (actionParams.exitAfterAction) {
218
+ removeActionRequestListener(); // for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
219
+ // process.exit()
220
+ }
221
+ }); // remove listener to process.on('message')
222
+ // which is sufficient to let child process die
223
+ // assuming nothing else keeps it alive
224
+ // process.once("SIGTERM", removeActionRequestListener)
225
+ // process.once("SIGINT", removeActionRequestListener)
226
+
227
+ setTimeout(() => sendToParent("ready"));
@@ -1,209 +1,6 @@
1
+ import { createEventSourceConnection } from "@jsenv/utils/event_source/event_source.js";
1
2
  import { urlHotMetas } from "./import_meta_hot.js";
2
-
3
- /* eslint-env browser */
4
- const createEventSourceConnection = (eventSourceUrl, events = {}, {
5
- retryMaxAttempt = Infinity,
6
- retryAllocatedMs = Infinity,
7
- lastEventId
8
- } = {}) => {
9
- const {
10
- EventSource
11
- } = window;
12
-
13
- if (typeof EventSource !== "function") {
14
- return () => {};
15
- }
16
-
17
- const eventSourceOrigin = new URL(eventSourceUrl).origin;
18
- Object.keys(events).forEach(eventName => {
19
- const eventCallback = events[eventName];
20
-
21
- events[eventName] = e => {
22
- if (e.origin === eventSourceOrigin) {
23
- if (e.lastEventId) {
24
- lastEventId = e.lastEventId;
25
- }
26
-
27
- eventCallback(e);
28
- }
29
- };
30
- });
31
- const status = {
32
- value: "default",
33
- goTo: value => {
34
- if (value === status.value) {
35
- return;
36
- }
37
-
38
- status.value = value;
39
- status.onchange();
40
- },
41
- onchange: () => {}
42
- };
43
-
44
- let _disconnect = () => {};
45
-
46
- const attemptConnection = url => {
47
- const eventSource = new EventSource(url, {
48
- withCredentials: true
49
- });
50
-
51
- _disconnect = () => {
52
- if (status.value !== "connecting" && status.value !== "connected") {
53
- console.warn("disconnect() ignored because connection is ".concat(status.value));
54
- return;
55
- }
56
-
57
- eventSource.onerror = undefined;
58
- eventSource.close();
59
- Object.keys(events).forEach(eventName => {
60
- eventSource.removeEventListener(eventName, events[eventName]);
61
- });
62
- status.goTo("disconnected");
63
- };
64
-
65
- let retryCount = 0;
66
- let firstRetryMs = Date.now();
67
-
68
- eventSource.onerror = errorEvent => {
69
- if (errorEvent.target.readyState === EventSource.CONNECTING) {
70
- if (retryCount > retryMaxAttempt) {
71
- console.info("could not connect after ".concat(retryMaxAttempt, " attempt"));
72
-
73
- _disconnect();
74
-
75
- return;
76
- }
77
-
78
- if (retryCount === 0) {
79
- firstRetryMs = Date.now();
80
- } else {
81
- const allRetryDuration = Date.now() - firstRetryMs;
82
-
83
- if (retryAllocatedMs && allRetryDuration > retryAllocatedMs) {
84
- console.info("could not connect in less than ".concat(retryAllocatedMs, " ms"));
85
-
86
- _disconnect();
87
-
88
- return;
89
- }
90
- }
91
-
92
- retryCount++;
93
- status.goTo("connecting");
94
- return;
95
- }
96
-
97
- if (errorEvent.target.readyState === EventSource.CLOSED) {
98
- _disconnect();
99
-
100
- return;
101
- }
102
- };
103
-
104
- eventSource.onopen = () => {
105
- status.goTo("connected");
106
- };
107
-
108
- Object.keys(events).forEach(eventName => {
109
- eventSource.addEventListener(eventName, events[eventName]);
110
- });
111
-
112
- if (!events.hasOwnProperty("welcome")) {
113
- eventSource.addEventListener("welcome", e => {
114
- if (e.origin === eventSourceOrigin && e.lastEventId) {
115
- lastEventId = e.lastEventId;
116
- }
117
- });
118
- }
119
-
120
- status.goTo("connecting");
121
- };
122
-
123
- let connect = () => {
124
- attemptConnection(eventSourceUrl);
125
-
126
- connect = () => {
127
- attemptConnection(lastEventId ? addLastEventIdIntoUrlSearchParams(eventSourceUrl, lastEventId) : eventSourceUrl);
128
- };
129
- };
130
-
131
- const removePageUnloadListener = listenPageUnload(() => {
132
- if (status.value === "connecting" || status.value === "connected") {
133
- _disconnect();
134
- }
135
- });
136
-
137
- const destroy = () => {
138
- removePageUnloadListener();
139
-
140
- _disconnect();
141
- };
142
-
143
- return {
144
- status,
145
- connect,
146
- disconnect: () => _disconnect(),
147
- destroy
148
- };
149
- };
150
-
151
- const addLastEventIdIntoUrlSearchParams = (url, lastEventId) => {
152
- if (url.indexOf("?") === -1) {
153
- url += "?";
154
- } else {
155
- url += "&";
156
- }
157
-
158
- return "".concat(url, "last-event-id=").concat(encodeURIComponent(lastEventId));
159
- }; // const listenPageMightFreeze = (callback) => {
160
- // const removePageHideListener = listenEvent(window, "pagehide", (pageHideEvent) => {
161
- // if (pageHideEvent.persisted === true) {
162
- // callback(pageHideEvent)
163
- // }
164
- // })
165
- // return removePageHideListener
166
- // }
167
- // const listenPageFreeze = (callback) => {
168
- // const removeFreezeListener = listenEvent(document, "freeze", (freezeEvent) => {
169
- // callback(freezeEvent)
170
- // })
171
- // return removeFreezeListener
172
- // }
173
- // const listenPageIsRestored = (callback) => {
174
- // const removeResumeListener = listenEvent(document, "resume", (resumeEvent) => {
175
- // removePageshowListener()
176
- // callback(resumeEvent)
177
- // })
178
- // const removePageshowListener = listenEvent(window, "pageshow", (pageshowEvent) => {
179
- // if (pageshowEvent.persisted === true) {
180
- // removePageshowListener()
181
- // removeResumeListener()
182
- // callback(pageshowEvent)
183
- // }
184
- // })
185
- // return () => {
186
- // removeResumeListener()
187
- // removePageshowListener()
188
- // }
189
- // }
190
-
191
-
192
- const listenPageUnload = callback => {
193
- const removePageHideListener = listenEvent(window, "pagehide", pageHideEvent => {
194
- if (pageHideEvent.persisted !== true) {
195
- callback(pageHideEvent);
196
- }
197
- });
198
- return removePageHideListener;
199
- };
200
-
201
- const listenEvent = (emitter, event, callback) => {
202
- emitter.addEventListener(event, callback);
203
- return () => {
204
- emitter.removeEventListener(event, callback);
205
- };
206
- };
3
+ import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js";
207
4
 
208
5
  const isAutoreloadEnabled = () => {
209
6
  const value = window.localStorage.getItem("autoreload");
@@ -238,27 +35,6 @@ const injectQuery = (url, query) => {
238
35
  return String(urlObject);
239
36
  };
240
37
 
241
- const htmlAttributeSrcSet = {
242
- parse: srcset => {
243
- const srcCandidates = [];
244
- srcset.split(",").forEach(set => {
245
- const [specifier, descriptor] = set.trim().split(" ");
246
- srcCandidates.push({
247
- specifier,
248
- descriptor
249
- });
250
- });
251
- return srcCandidates;
252
- },
253
- stringify: srcCandidates => {
254
- const srcset = srcCandidates.map(({
255
- specifier,
256
- descriptor
257
- }) => "".concat(specifier, " ").concat(descriptor)).join(", ");
258
- return srcset;
259
- }
260
- };
261
-
262
38
  const reloadHtmlPage = () => {
263
39
  window.location.reload(true);
264
40
  }; // This function can consider everything as hot reloadable:
@@ -295,10 +71,10 @@ const reloadDOMNodesUsingUrl = urlToReload => {
295
71
  });
296
72
  };
297
73
 
298
- Array.from(document.querySelectorAll("link[rel=\"stylesheet\"]")).forEach(link => {
74
+ Array.from(document.querySelectorAll(`link[rel="stylesheet"]`)).forEach(link => {
299
75
  visitNodeAttributeAsUrl(link, "href");
300
76
  });
301
- Array.from(document.querySelectorAll("link[rel=\"icon\"]")).forEach(link => {
77
+ Array.from(document.querySelectorAll(`link[rel="icon"]`)).forEach(link => {
302
78
  visitNodeAttributeAsUrl(link, "href");
303
79
  });
304
80
  Array.from(document.querySelector("script")).forEach(script => {
@@ -323,7 +99,7 @@ const reloadDOMNodesUsingUrl = urlToReload => {
323
99
  if (srcset) {
324
100
  const srcCandidates = htmlAttributeSrcSet.parse(srcset);
325
101
  srcCandidates.forEach(srcCandidate => {
326
- const url = new URL(srcCandidate.specifier, "".concat(window.location.href));
102
+ const url = new URL(srcCandidate.specifier, `${window.location.href}`);
327
103
 
328
104
  if (shouldReloadUrl(url)) {
329
105
  srcCandidate.specifier = injectQuery(url, {
@@ -415,7 +191,8 @@ const applyReloadMessageEffects = async () => {
415
191
  }, e => {
416
192
  // TODO: reuse error display from html supervisor
417
193
  console.error(e);
418
- console.error("[hmr] Failed to reload after ".concat(reloadMessage.reason, ".\nThis could be due to syntax errors or importing non-existent modules (see errors above)"));
194
+ console.error(`[hmr] Failed to reload after ${reloadMessage.reason}.
195
+ This could be due to syntax errors or importing non-existent modules (see errors above)`);
419
196
  reloadMessage.status = "failed";
420
197
  reloadMessagesSignal.onchange();
421
198
  });
@@ -443,40 +220,40 @@ const applyHotReload = async ({
443
220
  acceptedBy
444
221
  }) => {
445
222
  await previous;
446
- const urlToFetch = new URL(boundary, "".concat(window.location.origin, "/")).href;
223
+ const urlToFetch = new URL(boundary, `${window.location.origin}/`).href;
447
224
  const urlHotMeta = urlHotMetas[urlToFetch]; // TODO: we should return when there is no url hot meta because
448
225
  // it means code was not executed (code splitting with dynamic import)
449
226
  // if (!urlHotMeta) {return }
450
227
 
451
228
  if (type === "prune") {
452
- console.groupCollapsed("[jsenv] prune: ".concat(boundary, " (inside ").concat(acceptedBy, ")"));
229
+ console.groupCollapsed(`[jsenv] prune: ${boundary} (inside ${acceptedBy})`);
453
230
  } else if (acceptedBy === boundary) {
454
- console.groupCollapsed("[jsenv] hot reloading: ".concat(boundary));
231
+ console.groupCollapsed(`[jsenv] hot reloading: ${boundary}`);
455
232
  } else {
456
- console.groupCollapsed("[jsenv] hot reloading: ".concat(acceptedBy, " inside ").concat(boundary));
233
+ console.groupCollapsed(`[jsenv] hot reloading: ${acceptedBy} inside ${boundary}`);
457
234
  }
458
235
 
459
236
  if (urlHotMeta && urlHotMeta.disposeCallback) {
460
- console.log("call dispose callback");
237
+ console.log(`call dispose callback`);
461
238
  await urlHotMeta.disposeCallback();
462
239
  }
463
240
 
464
241
  if (type === "prune") {
465
242
  delete urlHotMetas[urlToFetch];
466
- console.log("cleanup pruned url");
243
+ console.log(`cleanup pruned url`);
467
244
  console.groupEnd();
468
245
  return null;
469
246
  }
470
247
 
471
248
  if (type === "js_module") {
472
- console.log("importing js module");
249
+ console.log(`importing js module`);
473
250
  const namespace = await reloadJsImport(urlToFetch);
474
251
 
475
252
  if (urlHotMeta && urlHotMeta.acceptCallback) {
476
253
  await urlHotMeta.acceptCallback(namespace);
477
254
  }
478
255
 
479
- console.log("js module import done");
256
+ console.log(`js module import done`);
480
257
  console.groupEnd();
481
258
  return namespace;
482
259
  }
@@ -487,15 +264,15 @@ const applyHotReload = async ({
487
264
  return null;
488
265
  }
489
266
 
490
- console.log("reloading url");
491
- const urlToReload = new URL(acceptedBy, "".concat(window.location.origin, "/")).href;
267
+ console.log(`reloading url`);
268
+ const urlToReload = new URL(acceptedBy, `${window.location.origin}/`).href;
492
269
  reloadDOMNodesUsingUrl(urlToReload);
493
- console.log("url reloaded");
270
+ console.log(`url reloaded`);
494
271
  console.groupEnd();
495
272
  return null;
496
273
  }
497
274
 
498
- console.warn("unknown update type: \"".concat(type, "\""));
275
+ console.warn(`unknown update type: "${type}"`);
499
276
  return null;
500
277
  }, Promise.resolve());
501
278
  };
@@ -545,5 +322,3 @@ window.__jsenv_event_source_client__ = {
545
322
  // )
546
323
  // })
547
324
  // }
548
-
549
- //# sourceMappingURL=event_source_client.js.map
@@ -0,0 +1,32 @@
1
+ // https://mathiasbynens.be/notes/globalthis
2
+
3
+ /* eslint-disable no-redeclare */
4
+
5
+ /* global globalThis */
6
+ let globalObject;
7
+
8
+ if (typeof globalThis === "object") {
9
+ globalObject = globalThis;
10
+ } else {
11
+ if (undefined) {
12
+ globalObject = undefined;
13
+ } else {
14
+ // eslint-disable-next-line no-extend-native
15
+ Object.defineProperty(Object.prototype, "__global__", {
16
+ get() {
17
+ return this;
18
+ },
19
+
20
+ configurable: true
21
+ }); // eslint-disable-next-line no-undef
22
+
23
+ globalObject = __global__;
24
+ delete Object.prototype.__global__;
25
+ }
26
+
27
+ globalObject.globalThis = globalObject;
28
+ }
29
+
30
+ var globalObject$1 = globalObject;
31
+
32
+ export { globalObject$1 as default };