@jsenv/core 34.2.2 → 35.0.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 (87) hide show
  1. package/README.md +1 -1
  2. package/dist/html/explorer.html +5 -4
  3. package/dist/{jsenv.js → jsenv_core.js} +840 -3914
  4. package/package.json +7 -21
  5. package/src/build/build.js +34 -16
  6. package/src/build/version_mappings_injection.js +20 -27
  7. package/src/dev/file_service.js +9 -9
  8. package/src/dev/start_dev_server.js +3 -3
  9. package/src/dev/user_agent.js +1 -1
  10. package/src/kitchen/kitchen.js +5 -3
  11. package/src/main.js +0 -23
  12. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +2 -2
  13. package/src/plugins/importmap/jsenv_plugin_importmap.js +6 -2
  14. package/src/plugins/{inline/jsenv_plugin_html_inline_content.js → inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js} +12 -6
  15. package/src/plugins/{inline/jsenv_plugin_inline.js → inline_content_analysis/jsenv_plugin_inline_content_analysis.js} +8 -10
  16. package/src/plugins/{inline/jsenv_plugin_js_inline_content.js → inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js} +4 -2
  17. package/src/plugins/inlining/jsenv_plugin_inlining.js +22 -0
  18. package/src/plugins/{inline/jsenv_plugin_inline_query_param.js → inlining/jsenv_plugin_inlining_as_data_url.js} +16 -9
  19. package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +149 -0
  20. package/src/plugins/plugins.js +5 -2
  21. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +11 -10
  22. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +2 -2
  23. package/src/plugins/supervisor/html_supervisor_injection.js +23 -25
  24. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +1 -1
  25. package/src/plugins/transpilation/babel/require_babel_plugin.js +1 -1
  26. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +20 -5
  27. package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +1 -1
  28. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +2 -2
  29. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +3 -3
  30. package/src/plugins/url_analysis/html/html_urls.js +1 -1
  31. package/dist/controllable_child_process.mjs +0 -129
  32. package/dist/controllable_worker_thread.mjs +0 -91
  33. package/dist/js/execute_using_dynamic_import.js +0 -850
  34. package/dist/js/v8_coverage.js +0 -508
  35. package/src/execute/execute.js +0 -109
  36. package/src/execute/run.js +0 -161
  37. package/src/execute/runtimes/browsers/chromium.js +0 -10
  38. package/src/execute/runtimes/browsers/firefox.js +0 -9
  39. package/src/execute/runtimes/browsers/from_playwright.js +0 -574
  40. package/src/execute/runtimes/browsers/middleware_istanbul.js +0 -65
  41. package/src/execute/runtimes/browsers/middleware_js_supervisor.js +0 -100
  42. package/src/execute/runtimes/browsers/webkit.js +0 -26
  43. package/src/execute/runtimes/node/child_exec_options.js +0 -166
  44. package/src/execute/runtimes/node/controllable_child_process.mjs +0 -135
  45. package/src/execute/runtimes/node/controllable_worker_thread.mjs +0 -103
  46. package/src/execute/runtimes/node/exec_options.js +0 -44
  47. package/src/execute/runtimes/node/execute_using_dynamic_import.js +0 -55
  48. package/src/execute/runtimes/node/exit_codes.js +0 -9
  49. package/src/execute/runtimes/node/kill_process_tree.js +0 -76
  50. package/src/execute/runtimes/node/node_child_process.js +0 -348
  51. package/src/execute/runtimes/node/node_execution_performance.js +0 -67
  52. package/src/execute/runtimes/node/node_worker_thread.js +0 -282
  53. package/src/execute/runtimes/node/profiler_v8_coverage.js +0 -56
  54. package/src/execute/runtimes/readme.md +0 -13
  55. package/src/execute/web_server_param.js +0 -74
  56. package/src/test/coverage/babel_plugin_instrument.js +0 -48
  57. package/src/test/coverage/coverage_reporter_html_directory.js +0 -32
  58. package/src/test/coverage/coverage_reporter_json_file.js +0 -17
  59. package/src/test/coverage/coverage_reporter_text_log.js +0 -19
  60. package/src/test/coverage/empty_coverage_factory.js +0 -52
  61. package/src/test/coverage/file_by_file_coverage.js +0 -25
  62. package/src/test/coverage/istanbul_coverage_composition.js +0 -28
  63. package/src/test/coverage/istanbul_coverage_map_from_coverage.js +0 -16
  64. package/src/test/coverage/list_files_not_covered.js +0 -15
  65. package/src/test/coverage/missing_coverage.js +0 -41
  66. package/src/test/coverage/report_to_coverage.js +0 -198
  67. package/src/test/coverage/v8_and_istanbul.js +0 -37
  68. package/src/test/coverage/v8_coverage.js +0 -26
  69. package/src/test/coverage/v8_coverage_composition.js +0 -24
  70. package/src/test/coverage/v8_coverage_node_directory.js +0 -85
  71. package/src/test/coverage/v8_coverage_to_istanbul.js +0 -99
  72. package/src/test/execute_steps.js +0 -425
  73. package/src/test/execute_test_plan.js +0 -372
  74. package/src/test/execution_colors.js +0 -10
  75. package/src/test/execution_steps.js +0 -65
  76. package/src/test/gc.js +0 -9
  77. package/src/test/logs_file_execution.js +0 -427
  78. package/src/test/logs_file_execution.test.mjs +0 -41
  79. package/src/test/readme.md +0 -3
  80. /package/src/{basic_fetch.js → helpers/basic_fetch.js} +0 -0
  81. /package/src/{lookup_package_directory.js → helpers/lookup_package_directory.js} +0 -0
  82. /package/src/{ping_server.js → helpers/ping_server.js} +0 -0
  83. /package/src/{require_from_jsenv.js → helpers/require_from_jsenv.js} +0 -0
  84. /package/src/{watch_source_files.js → helpers/watch_source_files.js} +0 -0
  85. /package/src/{web_url_converter.js → helpers/web_url_converter.js} +0 -0
  86. /package/src/plugins/{inline → inline_content_analysis}/client/inline_content.js +0 -0
  87. /package/src/plugins/{inline → inline_content_analysis}/jsenv_plugin_data_urls.js +0 -0
@@ -1,76 +0,0 @@
1
- import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
2
-
3
- // see also https://github.com/sindresorhus/execa/issues/96
4
- export const killProcessTree = async (
5
- processId,
6
- { signal, timeout = 2000 },
7
- ) => {
8
- const pidtree = requireFromJsenv("pidtree")
9
-
10
- let descendantProcessIds
11
- try {
12
- descendantProcessIds = await pidtree(processId)
13
- } catch (e) {
14
- if (e.message === "No matching pid found") {
15
- descendantProcessIds = []
16
- } else {
17
- throw e
18
- }
19
- }
20
- descendantProcessIds.forEach((descendantProcessId) => {
21
- try {
22
- process.kill(descendantProcessId, signal)
23
- } catch (error) {
24
- // ignore
25
- }
26
- })
27
-
28
- try {
29
- process.kill(processId, signal)
30
- } catch (e) {
31
- if (e.code !== "ESRCH") {
32
- throw e
33
- }
34
- }
35
-
36
- let remainingIds = [...descendantProcessIds, processId]
37
-
38
- const updateRemainingIds = () => {
39
- remainingIds = remainingIds.filter((remainingId) => {
40
- try {
41
- process.kill(remainingId, 0)
42
- return true
43
- } catch (e) {
44
- return false
45
- }
46
- })
47
- }
48
-
49
- let timeSpentWaiting = 0
50
-
51
- const check = async () => {
52
- updateRemainingIds()
53
- if (remainingIds.length === 0) {
54
- return
55
- }
56
-
57
- if (timeSpentWaiting > timeout) {
58
- const timeoutError = new Error(
59
- `timed out waiting for ${
60
- remainingIds.length
61
- } process to exit (${remainingIds.join(" ")})`,
62
- )
63
- timeoutError.code = "TIMEOUT"
64
- throw timeoutError
65
- }
66
-
67
- await new Promise((resolve) => setTimeout(resolve, 400))
68
- timeSpentWaiting += 400
69
- await check()
70
- }
71
-
72
- await new Promise((resolve) => {
73
- setTimeout(resolve, 0)
74
- })
75
- await check()
76
- }
@@ -1,348 +0,0 @@
1
- import { fork } from "node:child_process"
2
- import { fileURLToPath } from "node:url"
3
- import {
4
- Abort,
5
- raceCallbacks,
6
- createCallbackListNotifiedOnce,
7
- } from "@jsenv/abort"
8
- import { createDetailedMessage } from "@jsenv/log"
9
- import { memoize } from "@jsenv/utils/src/memoize/memoize.js"
10
-
11
- import { createChildExecOptions } from "./child_exec_options.js"
12
- import { ExecOptions } from "./exec_options.js"
13
- import { killProcessTree } from "./kill_process_tree.js"
14
- import { EXIT_CODES } from "./exit_codes.js"
15
-
16
- const CONTROLLABLE_CHILD_PROCESS_URL = new URL(
17
- "./controllable_child_process.mjs?entry_point",
18
- import.meta.url,
19
- ).href
20
-
21
- export const nodeChildProcess = {
22
- type: "node",
23
- name: "node_child_process",
24
- version: process.version.slice(1),
25
- }
26
-
27
- nodeChildProcess.run = async ({
28
- signal = new AbortController().signal,
29
- logger,
30
- logProcessCommand = false,
31
- rootDirectoryUrl,
32
- fileRelativeUrl,
33
-
34
- keepRunning,
35
- gracefulStopAllocatedMs = 4000,
36
- stopSignal,
37
- onConsole,
38
-
39
- coverageEnabled = false,
40
- coverageConfig,
41
- coverageMethodForNodeJs,
42
- coverageFileUrl,
43
- collectPerformance,
44
-
45
- env,
46
- debugPort,
47
- debugMode,
48
- debugModeInheritBreak,
49
- inheritProcessEnv = true,
50
- commandLineOptions = [],
51
- stdin = "pipe",
52
- stdout = "pipe",
53
- stderr = "pipe",
54
- }) => {
55
- if (env !== undefined && typeof env !== "object") {
56
- throw new TypeError(`env must be an object, got ${env}`)
57
- }
58
- env = {
59
- ...env,
60
- JSENV: true,
61
- }
62
- if (coverageMethodForNodeJs !== "NODE_V8_COVERAGE") {
63
- env.NODE_V8_COVERAGE = ""
64
- }
65
- commandLineOptions = [
66
- "--experimental-import-meta-resolve",
67
- ...commandLineOptions,
68
- ]
69
-
70
- const cleanupCallbackList = createCallbackListNotifiedOnce()
71
- const cleanup = async (reason) => {
72
- await cleanupCallbackList.notify({ reason })
73
- }
74
-
75
- const childExecOptions = await createChildExecOptions({
76
- signal,
77
- debugPort,
78
- debugMode,
79
- debugModeInheritBreak,
80
- })
81
- const execArgv = ExecOptions.toExecArgv({
82
- ...childExecOptions,
83
- ...ExecOptions.fromExecArgv(commandLineOptions),
84
- })
85
- const envForChildProcess = {
86
- ...(inheritProcessEnv ? process.env : {}),
87
- ...env,
88
- }
89
- logger[logProcessCommand ? "info" : "debug"](
90
- `${process.argv[0]} ${execArgv.join(" ")} ${fileURLToPath(
91
- CONTROLLABLE_CHILD_PROCESS_URL,
92
- )}`,
93
- )
94
- const childProcess = fork(fileURLToPath(CONTROLLABLE_CHILD_PROCESS_URL), {
95
- execArgv,
96
- // silent: true
97
- stdio: ["pipe", "pipe", "pipe", "ipc"],
98
- env: envForChildProcess,
99
- })
100
- logger.debug(
101
- createDetailedMessage(`child process forked (pid ${childProcess.pid})`, {
102
- "custom env": JSON.stringify(env, null, " "),
103
- }),
104
- )
105
- // if we pass stream, pipe them https://github.com/sindresorhus/execa/issues/81
106
- if (typeof stdin === "object") {
107
- stdin.pipe(childProcess.stdin)
108
- }
109
- if (typeof stdout === "object") {
110
- childProcess.stdout.pipe(stdout)
111
- }
112
- if (typeof stderr === "object") {
113
- childProcess.stderr.pipe(stderr)
114
- }
115
- const childProcessReadyPromise = new Promise((resolve) => {
116
- onceChildProcessMessage(childProcess, "ready", resolve)
117
- })
118
- const removeOutputListener = installChildProcessOutputListener(
119
- childProcess,
120
- ({ type, text }) => {
121
- onConsole({ type, text })
122
- },
123
- )
124
- const stop = memoize(async ({ gracefulStopAllocatedMs } = {}) => {
125
- // all libraries are facing problem on windows when trying
126
- // to kill a process spawning other processes.
127
- // "killProcessTree" is theorically correct but sometimes keep process handing forever.
128
- // Inside GitHub workflow the whole Virtual machine gets unresponsive and ends up being killed
129
- // There is no satisfying solution to this problem so we stick to the basic
130
- // childProcess.kill()
131
- if (process.platform === "win32") {
132
- childProcess.kill()
133
- return
134
- }
135
- if (gracefulStopAllocatedMs) {
136
- try {
137
- await killProcessTree(childProcess.pid, {
138
- signal: GRACEFUL_STOP_SIGNAL,
139
- timeout: gracefulStopAllocatedMs,
140
- })
141
- return
142
- } catch (e) {
143
- if (e.code === "TIMEOUT") {
144
- logger.debug(
145
- `kill with SIGTERM because gracefulStop still pending after ${gracefulStopAllocatedMs}ms`,
146
- )
147
- await killProcessTree(childProcess.pid, {
148
- signal: GRACEFUL_STOP_FAILED_SIGNAL,
149
- })
150
- return
151
- }
152
- throw e
153
- }
154
- }
155
- await killProcessTree(childProcess.pid, { signal: STOP_SIGNAL })
156
- return
157
- })
158
-
159
- const actionOperation = Abort.startOperation()
160
- actionOperation.addAbortSignal(signal)
161
- const winnerPromise = new Promise((resolve) => {
162
- raceCallbacks(
163
- {
164
- aborted: (cb) => {
165
- return actionOperation.addAbortCallback(cb)
166
- },
167
- // https://nodejs.org/api/child_process.html#child_process_event_disconnect
168
- // disconnect: (cb) => {
169
- // return onceProcessEvent(childProcess, "disconnect", cb)
170
- // },
171
- // https://nodejs.org/api/child_process.html#child_process_event_error
172
- error: (cb) => {
173
- return onceChildProcessEvent(childProcess, "error", cb)
174
- },
175
- exit: (cb) => {
176
- return onceChildProcessEvent(childProcess, "exit", (code, signal) => {
177
- cb({ code, signal })
178
- })
179
- },
180
- response: (cb) => {
181
- return onceChildProcessMessage(childProcess, "action-result", cb)
182
- },
183
- },
184
- resolve,
185
- )
186
- })
187
- const result = {
188
- status: "executing",
189
- errors: [],
190
- namespace: null,
191
- }
192
-
193
- const writeResult = async () => {
194
- actionOperation.throwIfAborted()
195
- await childProcessReadyPromise
196
- actionOperation.throwIfAborted()
197
- await sendToChildProcess(childProcess, {
198
- type: "action",
199
- data: {
200
- actionType: "execute-using-dynamic-import",
201
- actionParams: {
202
- rootDirectoryUrl,
203
- fileUrl: new URL(fileRelativeUrl, rootDirectoryUrl).href,
204
- collectPerformance,
205
- coverageEnabled,
206
- coverageConfig,
207
- coverageMethodForNodeJs,
208
- coverageFileUrl,
209
- exitAfterAction: true,
210
- },
211
- },
212
- })
213
- const winner = await winnerPromise
214
- if (winner.name === "aborted") {
215
- result.status = "aborted"
216
- return
217
- }
218
- if (winner.name === "error") {
219
- const error = winner.data
220
- removeOutputListener()
221
- result.status = "failed"
222
- result.errors.push(error)
223
- return
224
- }
225
- if (winner.name === "exit") {
226
- const { code } = winner.data
227
- await cleanup("process exit")
228
- if (code === 12) {
229
- result.status = "failed"
230
- result.errors.push(
231
- new Error(
232
- `node process exited with 12 (the forked child process wanted to use a non-available port for debug)`,
233
- ),
234
- )
235
- return
236
- }
237
- if (
238
- code === null ||
239
- code === 0 ||
240
- code === EXIT_CODES.SIGINT ||
241
- code === EXIT_CODES.SIGTERM ||
242
- code === EXIT_CODES.SIGABORT
243
- ) {
244
- result.status = "failed"
245
- result.errors.push(new Error(`node process exited during execution`))
246
- return
247
- }
248
- // process.exit(1) in child process or process.exitCode = 1 + process.exit()
249
- // means there was an error even if we don't know exactly what.
250
- result.status = "failed"
251
- result.errors.push(
252
- new Error(`node process exited with code ${code} during execution`),
253
- )
254
- return
255
- }
256
- const { status, value } = winner.data
257
- if (status === "action-failed") {
258
- result.status = "failed"
259
- result.errors.push(value)
260
- return
261
- }
262
- const { namespace, performance, coverage } = value
263
- result.status = "completed"
264
- result.namespace = namespace
265
- result.performance = performance
266
- result.coverage = coverage
267
- }
268
-
269
- try {
270
- await writeResult()
271
- } catch (e) {
272
- result.status = "failed"
273
- result.errors.push(e)
274
- }
275
- if (keepRunning) {
276
- stopSignal.notify = stop
277
- } else {
278
- await stop({
279
- gracefulStopAllocatedMs,
280
- })
281
- }
282
- await actionOperation.end()
283
- return result
284
- }
285
-
286
- // http://man7.org/linux/man-pages/man7/signal.7.html
287
- // https:// github.com/nodejs/node/blob/1d9511127c419ec116b3ddf5fc7a59e8f0f1c1e4/lib/internal/child_process.js#L472
288
- const GRACEFUL_STOP_SIGNAL = "SIGTERM"
289
- const STOP_SIGNAL = "SIGKILL"
290
- // it would be more correct if GRACEFUL_STOP_FAILED_SIGNAL was SIGHUP instead of SIGKILL.
291
- // but I'm not sure and it changes nothing so just use SIGKILL
292
- const GRACEFUL_STOP_FAILED_SIGNAL = "SIGKILL"
293
-
294
- const sendToChildProcess = async (childProcess, { type, data }) => {
295
- return new Promise((resolve, reject) => {
296
- childProcess.send(
297
- {
298
- jsenv: true,
299
- type,
300
- data,
301
- },
302
- (error) => {
303
- if (error) {
304
- reject(error)
305
- } else {
306
- resolve()
307
- }
308
- },
309
- )
310
- })
311
- }
312
-
313
- const installChildProcessOutputListener = (childProcess, callback) => {
314
- // beware that we may receive ansi output here, should not be a problem but keep that in mind
315
- const stdoutDataCallback = (chunk) => {
316
- callback({ type: "log", text: String(chunk) })
317
- }
318
- childProcess.stdout.on("data", stdoutDataCallback)
319
- const stdErrorDataCallback = (chunk) => {
320
- callback({ type: "error", text: String(chunk) })
321
- }
322
- childProcess.stderr.on("data", stdErrorDataCallback)
323
- return () => {
324
- childProcess.stdout.removeListener("data", stdoutDataCallback)
325
- childProcess.stderr.removeListener("data", stdoutDataCallback)
326
- }
327
- }
328
-
329
- const onceChildProcessMessage = (childProcess, type, callback) => {
330
- const onmessage = (message) => {
331
- if (message && message.jsenv && message.type === type) {
332
- childProcess.removeListener("message", onmessage)
333
- // eslint-disable-next-line no-eval
334
- callback(message.data ? eval(`(${message.data})`) : "")
335
- }
336
- }
337
- childProcess.on("message", onmessage)
338
- return () => {
339
- childProcess.removeListener("message", onmessage)
340
- }
341
- }
342
-
343
- const onceChildProcessEvent = (childProcess, type, callback) => {
344
- childProcess.once(type, callback)
345
- return () => {
346
- childProcess.removeListener(type, callback)
347
- }
348
- }
@@ -1,67 +0,0 @@
1
- import { PerformanceObserver, performance } from "node:perf_hooks"
2
-
3
- export const startObservingPerformances = () => {
4
- const measureEntries = []
5
- // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html
6
- const perfObserver = new PerformanceObserver(
7
- (
8
- // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceobserverentrylist
9
- list,
10
- ) => {
11
- const perfMeasureEntries = list.getEntriesByType("measure")
12
- measureEntries.push(...perfMeasureEntries)
13
- },
14
- )
15
- perfObserver.observe({
16
- entryTypes: ["measure"],
17
- })
18
- return async () => {
19
- // wait for node to call the performance observer
20
- await new Promise((resolve) => {
21
- setTimeout(resolve)
22
- })
23
- performance.clearMarks()
24
- perfObserver.disconnect()
25
- return {
26
- ...readNodePerformance(),
27
- measures: measuresFromMeasureEntries(measureEntries),
28
- }
29
- }
30
- }
31
-
32
- const readNodePerformance = () => {
33
- const nodePerformance = {
34
- nodeTiming: asPlainObject(performance.nodeTiming),
35
- timeOrigin: performance.timeOrigin,
36
- eventLoopUtilization: performance.eventLoopUtilization(),
37
- }
38
- return nodePerformance
39
- }
40
-
41
- // remove getters that cannot be stringified
42
- const asPlainObject = (objectWithGetters) => {
43
- const objectWithoutGetters = {}
44
- Object.keys(objectWithGetters).forEach((key) => {
45
- objectWithoutGetters[key] = objectWithGetters[key]
46
- })
47
- return objectWithoutGetters
48
- }
49
-
50
- const measuresFromMeasureEntries = (measureEntries) => {
51
- const measures = {}
52
- // Sort to ensure measures order is predictable
53
- // It seems to be already predictable on Node 16+ but
54
- // it's not the case on Node 14.
55
- measureEntries.sort((a, b) => {
56
- return a.startTime - b.startTime
57
- })
58
- measureEntries.forEach(
59
- (
60
- // https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#perf_hooks_class_performanceentry
61
- perfMeasureEntry,
62
- ) => {
63
- measures[perfMeasureEntry.name] = perfMeasureEntry.duration
64
- },
65
- )
66
- return measures
67
- }