@jsenv/core 24.2.2 → 24.4.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 (156) hide show
  1. package/dist/browser_runtime/browser_runtime-fbd309a1.js +5137 -0
  2. package/dist/browser_runtime/browser_runtime-fbd309a1.js.map +1064 -0
  3. package/dist/{jsenv_browser_system.js → browser_system/browser_system-29eda202.js} +12 -12
  4. package/dist/{jsenv_browser_system.js.map → browser_system/browser_system-29eda202.js.map} +64 -64
  5. package/dist/build_manifest.js +12 -0
  6. package/dist/compile_proxy/assets/s.js-749702e8.map +242 -0
  7. package/dist/compile_proxy/compile_proxy-405777e6.html +2074 -0
  8. package/dist/compile_proxy/compile_proxy.html__inline__20-39c0801c.js.map +385 -0
  9. package/dist/{jsenv_event_source_client.js → event_source_client/event_source_client-9f14c8b9.js} +39 -21
  10. package/dist/event_source_client/event_source_client-9f14c8b9.js.map +127 -0
  11. package/dist/redirector/assets/s.js-749702e8.map +242 -0
  12. package/dist/redirector/redirector-237cd168.html +2118 -0
  13. package/dist/redirector/redirector.html__inline__15-33acb0b9.js.map +390 -0
  14. package/dist/toolbar/assets/compilation.css-209d68b4.map +12 -0
  15. package/dist/toolbar/assets/eventsource.css-38cd0a36.map +12 -0
  16. package/dist/toolbar/assets/execution.css-0ebe522f.map +12 -0
  17. package/dist/toolbar/assets/focus.css-3f9c156d.map +12 -0
  18. package/dist/toolbar/assets/light-theme.css-78b19a80.map +12 -0
  19. package/dist/toolbar/assets/overflow-menu.css-d9688a1c.map +12 -0
  20. package/dist/toolbar/assets/s.js-749702e8.map +242 -0
  21. package/dist/toolbar/assets/settings.css-2b81b245.map +12 -0
  22. package/dist/toolbar/assets/toolbar.main.css-846920e9.map +28 -0
  23. package/dist/toolbar/assets/tooltip.css-03395ee6.map +12 -0
  24. package/dist/toolbar/toolbar-29e91dcd.html +4779 -0
  25. package/dist/toolbar/toolbar.main-53e1ab2b.js.map +795 -0
  26. package/dist/toolbar_injector/assets/jsenv-logo-188b9ca6.svg +95 -0
  27. package/dist/{jsenv_toolbar_injector.js → toolbar_injector/toolbar_injector-0af91b43.js} +87 -65
  28. package/dist/toolbar_injector/toolbar_injector-0af91b43.js.map +294 -0
  29. package/main.js +0 -1
  30. package/package.json +2 -1
  31. package/readme.md +10 -7
  32. package/src/buildProject.js +6 -2
  33. package/src/dev_server.js +22 -130
  34. package/src/execute.js +7 -10
  35. package/src/executeTestPlan.js +7 -1
  36. package/src/importUsingChildProcess.js +1 -1
  37. package/src/internal/{runtime/detectBrowser/detectBrowser.js → browser_detection/browser_detection.js} +0 -0
  38. package/src/internal/{runtime/detectBrowser → browser_detection}/detectAndroid.js +0 -0
  39. package/src/internal/{runtime/detectBrowser → browser_detection}/detectChrome.js +0 -0
  40. package/src/internal/{runtime/detectBrowser → browser_detection}/detectEdge.js +0 -0
  41. package/src/internal/{runtime/detectBrowser → browser_detection}/detectElectron.js +0 -0
  42. package/src/internal/{runtime/detectBrowser → browser_detection}/detectFirefox.js +0 -0
  43. package/src/internal/{runtime/detectBrowser → browser_detection}/detectIOS.js +0 -0
  44. package/src/internal/{runtime/detectBrowser → browser_detection}/detectInternetExplorer.js +0 -0
  45. package/src/internal/{runtime/detectBrowser → browser_detection}/detectOpera.js +0 -0
  46. package/src/internal/{runtime/detectBrowser → browser_detection}/detectSafari.js +0 -0
  47. package/src/internal/{runtime/detectBrowser → browser_detection}/util.js +0 -0
  48. package/src/internal/{runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js → browser_feature_detection/browser_feature_detection.js} +116 -81
  49. package/src/internal/browser_feature_detection/compile_proxy.html +27 -0
  50. package/src/internal/browser_launcher/browser_runtime_report.js +75 -0
  51. package/src/internal/{browser-launcher → browser_launcher}/executeHtmlFile.js +13 -16
  52. package/src/internal/browser_launcher/from_playwright.js +314 -0
  53. package/src/internal/{browser-launcher → browser_launcher}/trackPageToNotify.js +0 -0
  54. package/src/internal/{browser-launcher/jsenv-browser-system.js → browser_runtime/browser_runtime.js} +4 -4
  55. package/src/internal/{runtime/createBrowserRuntime/createBrowserSystem.js → browser_runtime/browser_system.js} +3 -2
  56. package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/createBrowserRuntime.js +7 -5
  57. package/src/internal/{browser-launcher → browser_runtime}/displayErrorInDocument.js +0 -0
  58. package/src/internal/{browser-launcher → browser_runtime}/displayErrorNotification.js +2 -4
  59. package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/evalSource.js +2 -0
  60. package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/makeNamespaceTransferable.js +0 -0
  61. package/src/internal/{browser-utils → browser_utils}/fetch-browser.js +2 -0
  62. package/src/internal/{browser-utils → browser_utils}/fetchAndEvalUsingFetch.js +3 -0
  63. package/src/internal/{browser-utils → browser_utils}/fetchAndEvalUsingScript.js +2 -0
  64. package/src/internal/{browser-utils → browser_utils}/fetchJson.js +0 -0
  65. package/src/internal/{browser-utils → browser_utils}/fetchUsingXHR.js +4 -4
  66. package/src/internal/building/buildUsingRollup.js +4 -0
  67. package/src/internal/building/createJsenvRollupPlugin.js +19 -9
  68. package/src/internal/building/css/applyPostCss.js +19 -8
  69. package/src/internal/building/css/moveCssUrls.js +44 -0
  70. package/src/internal/building/css/parseCssRessource.js +67 -17
  71. package/src/internal/building/css/parseCssUrls.js +29 -23
  72. package/src/internal/building/css/postcss_plugin_url_visitor.js +11 -20
  73. package/src/internal/building/css/replaceCssUrls.js +38 -19
  74. package/src/internal/building/css_module.js +6 -10
  75. package/src/internal/building/html/parseHtmlRessource.js +37 -11
  76. package/src/internal/building/parseRessource.js +3 -0
  77. package/src/internal/building/ressource_builder.js +12 -3
  78. package/src/internal/compiling/babel_plugin_import_assertions.js +1 -2
  79. package/src/internal/compiling/html_source_file_service.js +23 -21
  80. package/src/internal/compiling/jsenvCompilerForHtml.js +15 -22
  81. package/src/internal/compiling/startCompileServer.js +37 -32
  82. package/src/internal/dev_server/event_source_client/event_source_connection.js +28 -19
  83. package/src/internal/dev_server/exploring/exploring.html +7 -2
  84. package/src/internal/dev_server/exploring/fetchExploringJson.js +4 -9
  85. package/src/internal/dev_server/redirector/redirector.html +37 -2
  86. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +4 -7
  87. package/src/internal/dev_server/toolbar/eventsource/toolbar.eventsource.js +2 -2
  88. package/src/internal/dev_server/toolbar/notification/toolbar.notification.js +75 -44
  89. package/src/internal/dev_server/toolbar/toolbar.html +31 -5
  90. package/src/internal/dev_server/toolbar/toolbar.injector.js +55 -36
  91. package/src/internal/dev_server/toolbar/toolbar.main.js +45 -31
  92. package/src/internal/dev_server/toolbar/util/fetching.js +1 -1
  93. package/src/internal/executing/executeConcurrently.js +15 -11
  94. package/src/internal/executing/executePlan.js +3 -2
  95. package/src/internal/generateGroupMap/one_runtime_compat.js +1 -1
  96. package/src/internal/generateGroupMap/runtime_compat_composition.js +1 -1
  97. package/src/internal/generateGroupMap/runtime_support.js +1 -1
  98. package/src/internal/jsenvInternalFiles.js +0 -26
  99. package/src/internal/jsenv_builds.js +19 -0
  100. package/src/internal/{runtime/node-feature-detect/feature-detect-dynamic-import.mjs → node_feature_detection/feature_detect_dynamic_import.mjs} +0 -0
  101. package/src/internal/{runtime/node-feature-detect/feature-detect-top-level-await.mjs → node_feature_detection/feature_detect_top_level_await.mjs} +0 -0
  102. package/src/internal/{runtime/node-feature-detect → node_feature_detection}/nodeSupportsDynamicImport.js +0 -0
  103. package/src/internal/node_feature_detection/nodeSupportsTopLevelAwait.js +16 -0
  104. package/src/internal/{runtime/createNodeRuntime/scanNodeRuntimeFeatures.js → node_feature_detection/node_feature_detection.js} +12 -13
  105. package/src/internal/{node-launcher → node_launcher}/createChildProcessOptions.js +0 -0
  106. package/src/internal/{node-launcher → node_launcher}/createControllableNodeProcess.js +9 -14
  107. package/src/internal/{node-launcher → node_launcher}/kill_process_tree.js +0 -0
  108. package/src/internal/node_launcher/node_runtime_report.js +71 -0
  109. package/src/internal/{node-launcher → node_launcher}/processOptions.js +0 -0
  110. package/src/internal/{runtime/detectNode → node_runtime}/detectNode.js +0 -0
  111. package/src/internal/{runtime/createNodeRuntime → node_runtime}/evalSource.js +1 -1
  112. package/src/internal/{runtime/createNodeRuntime → node_runtime}/fetchSource.js +1 -1
  113. package/src/internal/{node-launcher → node_runtime}/nodeControllableFile.mjs +14 -11
  114. package/src/internal/{runtime/createNodeRuntime/createNodeExecutionWithDynamicImport.js → node_runtime/node_execution_dynamic_import.js} +34 -6
  115. package/src/internal/node_runtime/node_execution_performance.js +67 -0
  116. package/src/internal/{runtime/createNodeRuntime/createNodeExecutionWithSystemJs.js → node_runtime/node_execution_systemjs.js} +38 -24
  117. package/src/internal/{runtime/createNodeRuntime/createNodeSystem.js → node_runtime/node_system.js} +4 -4
  118. package/src/internal/runtime/computeCompileIdFromGroupId.js +1 -0
  119. package/src/internal/runtime/resolveGroup.js +1 -1
  120. package/src/internal/runtime/resolveRuntimeGroup.js +2 -2
  121. package/src/internal/{semantic-versioning → semantic_versioning}/findHighestVersion.js +0 -0
  122. package/src/internal/{semantic-versioning → semantic_versioning}/findLowestVersion.js +0 -0
  123. package/src/internal/{semantic-versioning → semantic_versioning}/index.js +0 -0
  124. package/src/internal/{semantic-versioning → semantic_versioning}/valueToVersion.js +0 -0
  125. package/src/internal/{semantic-versioning → semantic_versioning}/versionCompare.js +0 -0
  126. package/src/internal/{semantic-versioning → semantic_versioning}/versionIsAbove.js +0 -0
  127. package/src/internal/{semantic-versioning → semantic_versioning}/versionIsBelow.js +0 -0
  128. package/src/internal/{semantic-versioning → semantic_versioning}/versionIsEqual.js +0 -0
  129. package/src/launchBrowser.js +33 -492
  130. package/src/launchNode.js +36 -7
  131. package/src/requireUsingChildProcess.js +1 -1
  132. package/dist/jsenv_compile_proxy.js +0 -1339
  133. package/dist/jsenv_compile_proxy.js.map +0 -378
  134. package/dist/jsenv_event_source_client.js.map +0 -126
  135. package/dist/jsenv_exploring_index.js +0 -1092
  136. package/dist/jsenv_exploring_index.js.map +0 -353
  137. package/dist/jsenv_exploring_redirector.js +0 -1386
  138. package/dist/jsenv_exploring_redirector.js.map +0 -384
  139. package/dist/jsenv_redirector.js +0 -1388
  140. package/dist/jsenv_redirector.js.map +0 -384
  141. package/dist/jsenv_toolbar.js +0 -2880
  142. package/dist/jsenv_toolbar.js.map +0 -771
  143. package/dist/jsenv_toolbar_injector.js.map +0 -301
  144. package/src/internal/browser-launcher/createSharing.js +0 -70
  145. package/src/internal/browser-launcher/jsenv_compile_proxy.html +0 -13
  146. package/src/internal/browser-launcher/jsenv_compile_proxy.js +0 -5
  147. package/src/internal/dev_server/event_source_client/event_source_client_file_info.js +0 -17
  148. package/src/internal/dev_server/exploring/exploring_file_info.js +0 -21
  149. package/src/internal/dev_server/redirector/redirector.js +0 -30
  150. package/src/internal/dev_server/redirector/redirector_file_info.js +0 -24
  151. package/src/internal/dev_server/toolbar/backtolist/toolbar.backtolist.js +0 -33
  152. package/src/internal/dev_server/toolbar/toolbar_file_info.js +0 -37
  153. package/src/internal/node-launcher/node-js-file.js +0 -110
  154. package/src/internal/runtime/createNodeRuntime/createNodeRuntime.js +0 -32
  155. package/src/internal/runtime/node-feature-detect/nodeSupportsTopLevelAwait.js +0 -18
  156. package/src/nodeRuntime.js +0 -5
@@ -1,502 +1,43 @@
1
- // https://github.com/microsoft/playwright/blob/master/docs/api.md
2
-
3
- import { createDetailedMessage } from "@jsenv/logger"
4
- import {
5
- Abort,
6
- createCallbackListNotifiedOnce,
7
- createCallbackList,
8
- raceProcessTeardownEvents,
9
- } from "@jsenv/abort"
10
- import { memoize } from "@jsenv/filesystem"
11
-
12
- import { fetchUrl } from "./internal/fetchUrl.js"
13
- import { validateResponse } from "./internal/response_validation.js"
14
- import { trackPageToNotify } from "./internal/browser-launcher/trackPageToNotify.js"
15
- import { createSharing } from "./internal/browser-launcher/createSharing.js"
16
- import { executeHtmlFile } from "./internal/browser-launcher/executeHtmlFile.js"
1
+ import { createRuntimeFromPlaywright } from "@jsenv/core/src/internal/browser_launcher/from_playwright.js"
17
2
  import {
18
3
  PLAYWRIGHT_CHROMIUM_VERSION,
19
4
  PLAYWRIGHT_FIREFOX_VERSION,
20
5
  PLAYWRIGHT_WEBKIT_VERSION,
21
6
  } from "./playwright_browser_versions.js"
22
7
 
23
- const chromiumSharing = createSharing()
24
- export const chromiumRuntime = {
25
- name: "chromium",
26
- version: PLAYWRIGHT_CHROMIUM_VERSION,
27
- }
28
- chromiumRuntime.launch = async ({
29
- signal = new AbortController().signal,
30
- browserServerLogLevel,
31
- chromiumExecutablePath,
32
-
33
- projectDirectoryUrl,
34
- compileServerOrigin,
35
- outDirectoryRelativeUrl,
36
-
37
- collectPerformance,
38
- measurePerformance,
39
- collectCoverage,
40
- coverageIgnorePredicate,
41
- coverageForceIstanbul,
42
-
43
- headless = true,
44
- // about debug check https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypelaunchserveroptions
45
- debug = false,
46
- debugPort = 0,
47
- stopOnExit = true,
48
- share = false,
49
- }) => {
50
- const launchBrowserOperation = Abort.startOperation()
51
- launchBrowserOperation.addAbortSignal(signal)
52
-
53
- const sharingToken = share
54
- ? chromiumSharing.getSharingToken({
55
- chromiumExecutablePath,
56
- headless,
57
- debug,
58
- debugPort,
59
- })
60
- : chromiumSharing.getUniqueSharingToken()
61
- if (!sharingToken.isUsed()) {
62
- const { chromium } = await importPlaywright({ browserName: "chromium" })
63
- const launchOperation = launchBrowser("chromium", {
64
- browserClass: chromium,
65
- launchBrowserOperation,
66
- options: {
67
- headless,
68
- executablePath: chromiumExecutablePath,
69
- ...(debug ? { devtools: true } : {}),
70
- args: [
71
- // https://github.com/GoogleChrome/puppeteer/issues/1834
72
- // https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips
73
- // "--disable-dev-shm-usage",
74
- ...(debug ? [`--remote-debugging-port=${debugPort}`] : []),
75
- ],
76
- },
77
- stopOnExit,
78
- })
79
- sharingToken.setSharedValue(launchOperation)
80
- }
81
-
82
- const [browserPromise, stopUsingBrowser] = sharingToken.useSharedValue()
83
- launchBrowserOperation.addEndCallback(stopUsingBrowser)
84
- const browser = await browserPromise
85
-
86
- if (debug) {
87
- // https://github.com/puppeteer/puppeteer/blob/v2.0.0/docs/api.md#browserwsendpoint
88
- // https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target
89
- const webSocketEndpoint = browser.wsEndpoint()
90
- const webSocketUrl = new URL(webSocketEndpoint)
91
- const browserEndpoint = `http://${webSocketUrl.host}/json/version`
92
- const browserResponse = await fetchUrl(browserEndpoint, {
93
- signal,
94
- ignoreHttpsError: true,
95
- })
96
- const { isValid, message, details } = await validateResponse(
97
- browserResponse,
98
- )
99
- if (!isValid) {
100
- throw new Error(createDetailedMessage(message, details))
8
+ export const chromiumRuntime = createRuntimeFromPlaywright({
9
+ browserName: "chromium",
10
+ browserVersion: PLAYWRIGHT_CHROMIUM_VERSION,
11
+ coveragePlaywrightAPIAvailable: true,
12
+ })
13
+ export const chromiumTabRuntime = chromiumRuntime.tab
14
+
15
+ export const firefoxRuntime = createRuntimeFromPlaywright({
16
+ browserName: "firefox",
17
+ browserVersion: PLAYWRIGHT_FIREFOX_VERSION,
18
+ })
19
+ export const firefoxTabRuntime = firefoxRuntime.tab
20
+
21
+ export const webkitRuntime = createRuntimeFromPlaywright({
22
+ browserName: "webkit",
23
+ browserVersion: PLAYWRIGHT_WEBKIT_VERSION,
24
+ ignoreErrorHook: (error) => {
25
+ // we catch error during execution but safari throw unhandled rejection
26
+ // in a non-deterministic way.
27
+ // I suppose it's due to some race condition to decide if the promise is catched or not
28
+ // for now we'll ignore unhandled rejection on wekbkit
29
+ if (error.name === "Unhandled Promise Rejection") {
30
+ return true
101
31
  }
102
-
103
- const browserResponseObject = JSON.parse(browserResponse.body)
104
- const { webSocketDebuggerUrl } = browserResponseObject
105
- console.log(`Debugger listening on ${webSocketDebuggerUrl}`)
106
- }
107
-
108
- const browserHooks = browserToRuntimeHooks(browser, {
109
- browserServerLogLevel,
110
-
111
- projectDirectoryUrl,
112
- compileServerOrigin,
113
- outDirectoryRelativeUrl,
114
-
115
- collectPerformance,
116
- measurePerformance,
117
- collectCoverage,
118
- coverageIgnorePredicate,
119
- coverageForceIstanbul,
120
- coveragePlaywrightAPIAvailable: true,
121
- })
122
-
123
- return {
124
- browser,
125
- ...browserHooks,
126
- }
127
- }
128
- export const chromiumTabRuntime = {
129
- ...chromiumRuntime,
130
- launch: (params) =>
131
- chromiumRuntime.launch({
132
- shared: true,
133
- ...params,
134
- }),
135
- }
136
-
137
- const firefoxSharing = createSharing()
138
- export const firefoxRuntime = {
139
- name: "firefox",
140
- version: PLAYWRIGHT_FIREFOX_VERSION,
141
- }
142
- firefoxRuntime.launch = async ({
143
- signal = new AbortController().signal,
144
- firefoxExecutablePath,
145
- browserServerLogLevel,
146
-
147
- projectDirectoryUrl,
148
- compileServerOrigin,
149
- outDirectoryRelativeUrl,
150
-
151
- collectPerformance,
152
- measurePerformance,
153
- collectCoverage,
154
- coverageIgnorePredicate,
155
- coverageForceIstanbul,
156
-
157
- headless = true,
158
- stopOnExit = true,
159
- share = false,
160
- }) => {
161
- const launchBrowserOperation = Abort.startOperation()
162
- launchBrowserOperation.addAbortSignal(signal)
163
-
164
- const sharingToken = share
165
- ? firefoxSharing.getSharingToken({ firefoxExecutablePath, headless })
166
- : firefoxSharing.getUniqueSharingToken()
167
- if (!sharingToken.isUsed()) {
168
- const { firefox } = await importPlaywright({ browserName: "firefox" })
169
- const launchOperation = launchBrowser("firefox", {
170
- browserClass: firefox,
171
-
172
- launchBrowserOperation,
173
- options: {
174
- headless,
175
- executablePath: firefoxExecutablePath,
176
- },
177
- stopOnExit,
178
- })
179
- sharingToken.setSharedValue(launchOperation)
180
- }
181
-
182
- const [browserPromise, stopUsingBrowser] = sharingToken.useSharedValue()
183
- launchBrowserOperation.addEndCallback(stopUsingBrowser)
184
- const browser = await browserPromise
185
-
186
- const browserHooks = browserToRuntimeHooks(browser, {
187
- launchBrowserOperation,
188
- browserServerLogLevel,
189
-
190
- projectDirectoryUrl,
191
- compileServerOrigin,
192
- outDirectoryRelativeUrl,
193
-
194
- collectPerformance,
195
- measurePerformance,
196
- collectCoverage,
197
- coverageIgnorePredicate,
198
- coverageForceIstanbul,
199
- })
200
-
201
- return {
202
- browser,
203
- ...browserHooks,
204
- }
205
- }
206
- export const firefoxTabRuntime = {
207
- ...firefoxRuntime,
208
- launch: (params) =>
209
- firefoxRuntime.launch({
210
- shared: true,
211
- ...params,
212
- }),
213
- }
214
-
215
- const webkitSharing = createSharing()
216
- export const webkitRuntime = {
217
- name: "webkit",
218
- version: PLAYWRIGHT_WEBKIT_VERSION,
219
- }
220
- webkitRuntime.launch = async ({
221
- signal = new AbortController().signal,
222
- browserServerLogLevel,
223
- webkitExecutablePath,
224
-
225
- projectDirectoryUrl,
226
- compileServerOrigin,
227
- outDirectoryRelativeUrl,
228
-
229
- collectPerformance,
230
- measurePerformance,
231
- collectCoverage,
232
- coverageIgnorePredicate,
233
- coverageForceIstanbul,
234
-
235
- headless = true,
236
- stopOnExit = true,
237
- share = false,
238
- }) => {
239
- const launchBrowserOperation = Abort.startOperation()
240
- launchBrowserOperation.addAbortSignal(signal)
241
-
242
- const sharingToken = share
243
- ? webkitSharing.getSharingToken({ webkitExecutablePath, headless })
244
- : webkitSharing.getUniqueSharingToken()
245
-
246
- if (!sharingToken.isUsed()) {
247
- const { webkit } = await await importPlaywright({ browserName: "webkit" })
248
- const launchOperation = launchBrowser("webkit", {
249
- browserClass: webkit,
250
- launchBrowserOperation,
251
- options: {
252
- headless,
253
- executablePath: webkitExecutablePath,
254
- },
255
- stopOnExit,
256
- })
257
- sharingToken.setSharedValue(launchOperation)
258
- }
259
-
260
- const [browserPromise, stopUsingBrowser] = sharingToken.useSharedValue()
261
- launchBrowserOperation.addEndCallback(stopUsingBrowser)
262
- const browser = await browserPromise
263
-
264
- const browserHooks = browserToRuntimeHooks(browser, {
265
- launchBrowserOperation,
266
- browserServerLogLevel,
267
-
268
- projectDirectoryUrl,
269
- compileServerOrigin,
270
- outDirectoryRelativeUrl,
271
-
272
- collectPerformance,
273
- measurePerformance,
274
- collectCoverage,
275
- coverageIgnorePredicate,
276
- coverageForceIstanbul,
277
- ignoreErrorHook: (error) => {
278
- // we catch error during execution but safari throw unhandled rejection
279
- // in a non-deterministic way.
280
- // I suppose it's due to some race condition to decide if the promise is catched or not
281
- // for now we'll ignore unhandled rejection on wekbkit
282
- if (error.name === "Unhandled Promise Rejection") {
283
- return true
284
- }
285
- return false
286
- },
287
- transformErrorHook: (error) => {
288
- // Force error stack to contain the error message
289
- // because it's not the case on webkit
290
- error.stack = `${error.message}
32
+ return false
33
+ },
34
+ transformErrorHook: (error) => {
35
+ // Force error stack to contain the error message
36
+ // because it's not the case on webkit
37
+ error.stack = `${error.message}
291
38
  at ${error.stack}`
292
39
 
293
- return error
294
- },
295
- })
296
-
297
- return {
298
- browser,
299
- ...browserHooks,
300
- }
301
- }
302
- export const webkitTabRuntime = {
303
- ...webkitRuntime,
304
- launch: (params) =>
305
- webkitRuntime.launch({
306
- shared: true,
307
- ...params,
308
- }),
309
- }
310
-
311
- const launchBrowser = async (
312
- browserName,
313
- { launchBrowserOperation, browserClass, options, stopOnExit },
314
- ) => {
315
- if (stopOnExit) {
316
- launchBrowserOperation.addAbortSource((abort) => {
317
- return raceProcessTeardownEvents(
318
- {
319
- SIGHUP: true,
320
- SIGTERM: true,
321
- SIGINT: true,
322
- beforeExit: true,
323
- exit: true,
324
- },
325
- abort,
326
- )
327
- })
328
- }
329
-
330
- try {
331
- const browser = await browserClass.launch({
332
- ...options,
333
- // let's handle them to close properly browser + remove listener
334
- // instead of relying on playwright to do so
335
- handleSIGINT: false,
336
- handleSIGTERM: false,
337
- handleSIGHUP: false,
338
- })
339
- launchBrowserOperation.throwIfAborted()
340
- return browser
341
- } catch (e) {
342
- if (launchBrowserOperation.signal.aborted && isTargetClosedError(e)) {
343
- // rethrow the abort error
344
- launchBrowserOperation.throwIfAborted()
345
- }
346
- throw e
347
- } finally {
348
- await launchBrowserOperation.end()
349
- }
350
- }
351
-
352
- const importPlaywright = async ({ browserName }) => {
353
- try {
354
- const namespace = await import("playwright")
355
- return namespace
356
- } catch (e) {
357
- if (e.code === "ERR_MODULE_NOT_FOUND") {
358
- throw new Error(
359
- createDetailedMessage(
360
- `"playwright" not found. You need playwright in your dependencies when using "${browserName}Runtime"`,
361
- {
362
- suggestion: `npm install --save-dev playwright`,
363
- },
364
- ),
365
- { cause: e },
366
- )
367
- }
368
- throw e
369
- }
370
- }
371
-
372
- const stopBrowser = async (browser) => {
373
- const disconnected = browser.isConnected()
374
- ? new Promise((resolve) => {
375
- const disconnectedCallback = () => {
376
- browser.removeListener("disconnected", disconnectedCallback)
377
- resolve()
378
- }
379
- browser.on("disconnected", disconnectedCallback)
380
- })
381
- : Promise.resolve()
382
-
383
- // for some reason without this 100ms timeout
384
- // browser.close() never resolves (playwright does not like something)
385
- await new Promise((resolve) => setTimeout(resolve, 100))
386
-
387
- await browser.close()
388
- await disconnected
389
- }
390
-
391
- const browserToRuntimeHooks = (
392
- browser,
393
- {
394
- projectDirectoryUrl,
395
- compileServerOrigin,
396
- outDirectoryRelativeUrl,
397
-
398
- collectPerformance,
399
- measurePerformance,
400
- collectCoverage,
401
- coverageIgnorePredicate,
402
- coverageForceIstanbul,
403
- coveragePlaywrightAPIAvailable = false,
404
- ignoreErrorHook = () => false,
405
- transformErrorHook = (error) => error,
40
+ return error
406
41
  },
407
- ) => {
408
- const stopCallbackList = createCallbackListNotifiedOnce()
409
- const stoppedCallbackList = createCallbackListNotifiedOnce()
410
- const stop = memoize(async (reason) => {
411
- await stopCallbackList.notify({ reason })
412
- stoppedCallbackList.notify({ reason })
413
- return { graceful: false }
414
- })
415
-
416
- // https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-disconnected
417
- browser.on("disconnected", () => {
418
- stop()
419
- })
420
-
421
- stopCallbackList.add(async () => {
422
- await stopBrowser(browser)
423
- })
424
-
425
- const errorCallbackList = createCallbackList()
426
-
427
- const outputCallbackList = createCallbackList()
428
-
429
- const execute = async ({
430
- signal,
431
- fileRelativeUrl,
432
- ignoreHTTPSErrors = true, // we mostly use self signed certificates during tests
433
- }) => {
434
- const executeOperation = Abort.startOperation()
435
- executeOperation.addAbortSignal(signal)
436
- executeOperation.throwIfAborted()
437
- // open a tab to execute to the file
438
- const browserContext = await browser.newContext({ ignoreHTTPSErrors })
439
- executeOperation.throwIfAborted()
440
- const page = await browserContext.newPage()
441
- executeOperation.addEndCallback(async () => {
442
- try {
443
- await browserContext.close()
444
- } catch (e) {
445
- if (isTargetClosedError(e)) {
446
- return
447
- }
448
- throw e
449
- }
450
- })
451
- // track tab error and console
452
- const stopTrackingToNotify = trackPageToNotify(page, {
453
- onError: (error) => {
454
- error = transformErrorHook(error)
455
- if (!ignoreErrorHook(error)) {
456
- errorCallbackList.notify(error)
457
- }
458
- },
459
- onConsole: outputCallbackList.notify,
460
- })
461
- stoppedCallbackList.add(stopTrackingToNotify)
462
-
463
- const result = await executeHtmlFile(fileRelativeUrl, {
464
- executeOperation,
465
-
466
- projectDirectoryUrl,
467
- compileServerOrigin,
468
- outDirectoryRelativeUrl,
469
-
470
- page,
471
- measurePerformance,
472
- collectPerformance,
473
- collectCoverage,
474
- coverageForceIstanbul,
475
- coveragePlaywrightAPIAvailable,
476
- coverageIgnorePredicate,
477
- transformErrorHook,
478
- })
479
- return result
480
- }
481
-
482
- return {
483
- stoppedCallbackList,
484
- errorCallbackList,
485
- outputCallbackList,
486
- execute,
487
- stop,
488
- }
489
- }
490
-
491
- const isTargetClosedError = (error) => {
492
- if (error.message.match(/Protocol error \(.*?\): Target closed/)) {
493
- return true
494
- }
495
- if (error.message.match(/Protocol error \(.*?\): Browser.*?closed/)) {
496
- return true
497
- }
498
- if (error.message.includes("browserContext.close: Browser closed")) {
499
- return true
500
- }
501
- return false
502
- }
42
+ })
43
+ export const webkitTabRuntime = webkitRuntime.tab
package/src/launchNode.js CHANGED
@@ -3,7 +3,8 @@ import { loggerToLogLevel } from "@jsenv/logger"
3
3
 
4
4
  import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
5
5
  import { escapeRegexpSpecialCharacters } from "./internal/escapeRegexpSpecialCharacters.js"
6
- import { createControllableNodeProcess } from "./internal/node-launcher/createControllableNodeProcess.js"
6
+ import { createControllableNodeProcess } from "./internal/node_launcher/createControllableNodeProcess.js"
7
+ import { getNodeRuntimeReport } from "./internal/node_launcher/node_runtime_report.js"
7
8
 
8
9
  export const nodeRuntime = {
9
10
  name: "node",
@@ -15,6 +16,7 @@ nodeRuntime.launch = async ({
15
16
  logProcessCommand,
16
17
 
17
18
  projectDirectoryUrl,
19
+ compileServerId,
18
20
  compileServerOrigin,
19
21
  outDirectoryRelativeUrl,
20
22
 
@@ -34,7 +36,7 @@ nodeRuntime.launch = async ({
34
36
  stdout,
35
37
  stderr,
36
38
  stopAfterExecute,
37
- canUseNativeModuleSystem,
39
+ forceSystemJs,
38
40
 
39
41
  remap = true,
40
42
  }) => {
@@ -103,7 +105,6 @@ nodeRuntime.launch = async ({
103
105
 
104
106
  fileRelativeUrl,
105
107
  executionId,
106
- canUseNativeModuleSystem,
107
108
  exitAfterAction: stopAfterExecute,
108
109
 
109
110
  measurePerformance,
@@ -114,11 +115,39 @@ nodeRuntime.launch = async ({
114
115
  remap,
115
116
  }
116
117
 
117
- let executionResult = await requestActionOnChildProcess({
118
- signal,
119
- actionType: "execute-using-dynamic-import-fallback-on-systemjs",
120
- actionParams: executeParams,
118
+ // the computation of runtime features can be cached
119
+ const nodeFeatures = await getNodeRuntimeReport({
120
+ runtime: nodeRuntime,
121
+ compileServerId,
122
+ compileServerOrigin,
123
+ outDirectoryRelativeUrl,
124
+ // https://nodejs.org/docs/latest-v15.x/api/cli.html#cli_node_v8_coverage_dir
125
+ // instrumentation CAN be handed by process.env.NODE_V8_COVERAGE
126
+ // "transform-instrument" becomes non mandatory
127
+ coverageHandledFromOutside:
128
+ !coverageForceIstanbul && process.env.NODE_V8_COVERAGE,
121
129
  })
130
+ const { canAvoidCompilation, compileId, importDefaultExtension } =
131
+ nodeFeatures
132
+
133
+ let executionResult
134
+ if (canAvoidCompilation && !forceSystemJs) {
135
+ executionResult = await requestActionOnChildProcess({
136
+ signal,
137
+ actionType: "execute-using-dynamic-import",
138
+ actionParams: executeParams,
139
+ })
140
+ } else {
141
+ executionResult = await requestActionOnChildProcess({
142
+ signal,
143
+ actionType: "execute-using-systemjs",
144
+ actionParams: {
145
+ compileId,
146
+ importDefaultExtension,
147
+ ...executeParams,
148
+ },
149
+ })
150
+ }
122
151
 
123
152
  executionResult = transformExecutionResult(executionResult, {
124
153
  compileServerOrigin,
@@ -1,5 +1,5 @@
1
1
  import { launchAndExecute } from "./internal/executing/launchAndExecute.js"
2
- import { createControllableNodeProcess } from "./internal/node-launcher/createControllableNodeProcess.js"
2
+ import { createControllableNodeProcess } from "./internal/node_launcher/createControllableNodeProcess.js"
3
3
 
4
4
  export const requireUsingChildProcess = async (
5
5
  fileUrl,