@jsenv/test 1.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 (56) hide show
  1. package/dist/controllable_child_process.mjs +129 -0
  2. package/dist/controllable_worker_thread.mjs +91 -0
  3. package/dist/importmap_node_loader.mjs +551 -0
  4. package/dist/js/execute_using_dynamic_import.js +850 -0
  5. package/dist/js/v8_coverage.js +508 -0
  6. package/dist/jsenv_test.js +5993 -0
  7. package/dist/no_experimental_warnings.cjs +10 -0
  8. package/package.json +56 -0
  9. package/src/coverage/babel_plugin_instrument.js +48 -0
  10. package/src/coverage/coverage_reporter_html_directory.js +32 -0
  11. package/src/coverage/coverage_reporter_json_file.js +17 -0
  12. package/src/coverage/coverage_reporter_text_log.js +19 -0
  13. package/src/coverage/empty_coverage_factory.js +52 -0
  14. package/src/coverage/file_by_file_coverage.js +25 -0
  15. package/src/coverage/istanbul_coverage_composition.js +28 -0
  16. package/src/coverage/istanbul_coverage_map_from_coverage.js +16 -0
  17. package/src/coverage/list_files_not_covered.js +15 -0
  18. package/src/coverage/missing_coverage.js +41 -0
  19. package/src/coverage/report_to_coverage.js +198 -0
  20. package/src/coverage/v8_and_istanbul.js +37 -0
  21. package/src/coverage/v8_coverage.js +26 -0
  22. package/src/coverage/v8_coverage_composition.js +24 -0
  23. package/src/coverage/v8_coverage_node_directory.js +85 -0
  24. package/src/coverage/v8_coverage_to_istanbul.js +99 -0
  25. package/src/execution/execute.js +111 -0
  26. package/src/execution/execute_steps.js +423 -0
  27. package/src/execution/execute_test_plan.js +372 -0
  28. package/src/execution/execution_colors.js +10 -0
  29. package/src/execution/execution_steps.js +65 -0
  30. package/src/execution/gc.js +9 -0
  31. package/src/execution/logs_file_execution.js +427 -0
  32. package/src/execution/logs_file_execution.test.mjs +41 -0
  33. package/src/execution/run.js +160 -0
  34. package/src/execution/web_server_param.js +73 -0
  35. package/src/main.js +10 -0
  36. package/src/runtime_browsers/chromium.js +24 -0
  37. package/src/runtime_browsers/firefox.js +23 -0
  38. package/src/runtime_browsers/middleware_istanbul.js +65 -0
  39. package/src/runtime_browsers/middleware_js_supervisor.js +98 -0
  40. package/src/runtime_browsers/using_playwright.js +573 -0
  41. package/src/runtime_browsers/webkit.js +40 -0
  42. package/src/runtime_node/child_exec_options.js +166 -0
  43. package/src/runtime_node/controllable_child_process.mjs +135 -0
  44. package/src/runtime_node/controllable_worker_thread.mjs +103 -0
  45. package/src/runtime_node/exec_options.js +57 -0
  46. package/src/runtime_node/execute_using_dynamic_import.js +53 -0
  47. package/src/runtime_node/exit_codes.js +9 -0
  48. package/src/runtime_node/importmap_node_loader.mjs +51 -0
  49. package/src/runtime_node/importmap_node_loader_file_url.js +4 -0
  50. package/src/runtime_node/kill_process_tree.js +76 -0
  51. package/src/runtime_node/no_experimental_warnings.cjs +13 -0
  52. package/src/runtime_node/no_experimental_warnings_file_url.js +4 -0
  53. package/src/runtime_node/node_child_process.js +374 -0
  54. package/src/runtime_node/node_execution_performance.js +67 -0
  55. package/src/runtime_node/node_worker_thread.js +301 -0
  56. package/src/runtime_node/profiler_v8_coverage.js +56 -0
@@ -0,0 +1,166 @@
1
+ import { findFreePort } from "@jsenv/server"
2
+
3
+ import { createDetailedMessage } from "@jsenv/log"
4
+ import { ExecOptions } from "./exec_options.js"
5
+
6
+ export const createChildExecOptions = async ({
7
+ signal = new AbortController().signal,
8
+ // https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_automatically-attach-debugger-to-nodejs-subprocesses
9
+ processExecArgv = process.execArgv,
10
+ processDebugPort = process.debugPort,
11
+
12
+ debugPort = 0,
13
+ debugMode = "inherit",
14
+ debugModeInheritBreak = true,
15
+ } = {}) => {
16
+ if (
17
+ typeof debugMode === "string" &&
18
+ AVAILABLE_DEBUG_MODE.indexOf(debugMode) === -1
19
+ ) {
20
+ throw new TypeError(
21
+ createDetailedMessage(`unexpected debug mode.`, {
22
+ ["debug mode"]: debugMode,
23
+ ["allowed debug mode"]: AVAILABLE_DEBUG_MODE,
24
+ }),
25
+ )
26
+ }
27
+ const childExecOptions = ExecOptions.fromExecArgv(processExecArgv)
28
+ await mutateDebuggingOptions(childExecOptions, {
29
+ signal,
30
+ processDebugPort,
31
+ debugMode,
32
+ debugPort,
33
+ debugModeInheritBreak,
34
+ })
35
+ return childExecOptions
36
+ }
37
+
38
+ const AVAILABLE_DEBUG_MODE = [
39
+ "none",
40
+ "inherit",
41
+ "inspect",
42
+ "inspect-brk",
43
+ "debug",
44
+ "debug-brk",
45
+ ]
46
+
47
+ const mutateDebuggingOptions = async (
48
+ childExecOptions,
49
+ {
50
+ // ensure multiline
51
+ signal,
52
+ processDebugPort,
53
+ debugMode,
54
+ debugPort,
55
+ debugModeInheritBreak,
56
+ },
57
+ ) => {
58
+ const parentDebugInfo = getDebugInfo(childExecOptions)
59
+ const parentDebugModeOptionName = parentDebugInfo.debugModeOptionName
60
+ const parentDebugPortOptionName = parentDebugInfo.debugPortOptionName
61
+ const childDebugModeOptionName = getChildDebugModeOptionName({
62
+ parentDebugModeOptionName,
63
+ debugMode,
64
+ debugModeInheritBreak,
65
+ })
66
+
67
+ if (!childDebugModeOptionName) {
68
+ // remove debug mode and debug port fron child options
69
+ if (parentDebugModeOptionName) {
70
+ delete childExecOptions[parentDebugModeOptionName]
71
+ }
72
+ if (parentDebugPortOptionName) {
73
+ delete childExecOptions[parentDebugPortOptionName]
74
+ }
75
+ return
76
+ }
77
+
78
+ // replace child debug mode
79
+ if (
80
+ parentDebugModeOptionName &&
81
+ parentDebugModeOptionName !== childDebugModeOptionName
82
+ ) {
83
+ delete childExecOptions[parentDebugModeOptionName]
84
+ }
85
+ childExecOptions[childDebugModeOptionName] = ""
86
+
87
+ // this is required because vscode does not
88
+ // support assigning a child spawned without a specific port
89
+ const childDebugPortOptionValue =
90
+ debugPort === 0
91
+ ? await findFreePort(processDebugPort + 37, { signal })
92
+ : debugPort
93
+ // replace child debug port
94
+ if (parentDebugPortOptionName) {
95
+ delete childExecOptions[parentDebugPortOptionName]
96
+ }
97
+ childExecOptions[childDebugModeOptionName] = portToArgValue(
98
+ childDebugPortOptionValue,
99
+ )
100
+ }
101
+
102
+ const getChildDebugModeOptionName = ({
103
+ parentDebugModeOptionName,
104
+ debugMode,
105
+ debugModeInheritBreak,
106
+ }) => {
107
+ if (debugMode === "none") {
108
+ return undefined
109
+ }
110
+ if (debugMode !== "inherit") {
111
+ return `--${debugMode}`
112
+ }
113
+ if (!parentDebugModeOptionName) {
114
+ return undefined
115
+ }
116
+ if (!debugModeInheritBreak && parentDebugModeOptionName === "--inspect-brk") {
117
+ return "--inspect"
118
+ }
119
+ if (!debugModeInheritBreak && parentDebugModeOptionName === "--debug-brk") {
120
+ return "--debug"
121
+ }
122
+ return parentDebugModeOptionName
123
+ }
124
+
125
+ const portToArgValue = (port) => {
126
+ if (typeof port !== "number") return ""
127
+ if (port === 0) return ""
128
+ return port
129
+ }
130
+
131
+ // https://nodejs.org/en/docs/guides/debugging-getting-started/
132
+ const getDebugInfo = (processOptions) => {
133
+ const inspectOption = processOptions["--inspect"]
134
+ if (inspectOption !== undefined) {
135
+ return {
136
+ debugModeOptionName: "--inspect",
137
+ debugPortOptionName: "--inspect-port",
138
+ }
139
+ }
140
+ const inspectBreakOption = processOptions["--inspect-brk"]
141
+ if (inspectBreakOption !== undefined) {
142
+ return {
143
+ debugModeOptionName: "--inspect-brk",
144
+ debugPortOptionName: "--inspect-port",
145
+ }
146
+ }
147
+ const debugOption = processOptions["--debug"]
148
+ if (debugOption !== undefined) {
149
+ return {
150
+ debugModeOptionName: "--debug",
151
+ debugPortOptionName: "--debug-port",
152
+ }
153
+ }
154
+ const debugBreakOption = processOptions["--debug-brk"]
155
+ if (debugBreakOption !== undefined) {
156
+ return {
157
+ debugModeOptionName: "--debug-brk",
158
+ debugPortOptionName: "--debug-port",
159
+ }
160
+ }
161
+ return {}
162
+ }
163
+
164
+ // export const processIsExecutedByVSCode = () => {
165
+ // return typeof process.env.VSCODE_PID === "string"
166
+ // }
@@ -0,0 +1,135 @@
1
+ import { uneval } from "@jsenv/uneval"
2
+
3
+ import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js"
4
+
5
+ const ACTIONS_AVAILABLE = {
6
+ "execute-using-dynamic-import": executeUsingDynamicImport,
7
+ "execute-using-require": async ({ fileUrl }) => {
8
+ const { createRequire } = await import("node:module")
9
+ const { fileURLToPath } = await import("node:url")
10
+ const filePath = fileURLToPath(fileUrl)
11
+ const require = createRequire(fileUrl)
12
+ // eslint-disable-next-line import/no-dynamic-require
13
+ const namespace = require(filePath)
14
+ const namespaceResolved = {}
15
+ await Promise.all(
16
+ Object.keys(namespace).map(async (key) => {
17
+ const value = await namespace[key]
18
+ namespaceResolved[key] = value
19
+ }),
20
+ )
21
+ return namespaceResolved
22
+ },
23
+ }
24
+ const ACTION_REQUEST_EVENT_NAME = "action"
25
+ const ACTION_RESPONSE_EVENT_NAME = "action-result"
26
+ const ACTION_RESPONSE_STATUS_FAILED = "action-failed"
27
+ const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed"
28
+
29
+ const sendActionFailed = (error) => {
30
+ if (error.hasOwnProperty("toString")) {
31
+ delete error.toString
32
+ }
33
+ sendToParent(
34
+ ACTION_RESPONSE_EVENT_NAME,
35
+ // process.send algorithm does not send non enumerable values
36
+ // so use @jsenv/uneval
37
+ uneval(
38
+ {
39
+ status: ACTION_RESPONSE_STATUS_FAILED,
40
+ value: error,
41
+ },
42
+ { ignoreSymbols: true },
43
+ ),
44
+ )
45
+ }
46
+
47
+ const sendActionCompleted = (value) => {
48
+ sendToParent(
49
+ ACTION_RESPONSE_EVENT_NAME,
50
+ // here we use JSON.stringify because we should not
51
+ // have non enumerable value (unlike there is on Error objects)
52
+ // otherwise uneval is quite slow to turn a giant object
53
+ // into a string (and value can be giant when using coverage)
54
+ JSON.stringify({
55
+ status: ACTION_RESPONSE_STATUS_COMPLETED,
56
+ value,
57
+ }),
58
+ )
59
+ }
60
+
61
+ const sendToParent = (type, data) => {
62
+ // https://nodejs.org/api/process.html#process_process_connected
63
+ // not connected anymore, cannot communicate with parent
64
+ if (!process.connected) {
65
+ return
66
+ }
67
+ // this can keep process alive longer than expected
68
+ // when source is a long string.
69
+ // It means node process may stay alive longer than expected
70
+ // the time to send the data to the parent.
71
+ process.send({
72
+ jsenv: true,
73
+ type,
74
+ data,
75
+ })
76
+ }
77
+
78
+ const onceParentMessage = (type, callback) => {
79
+ const listener = (message) => {
80
+ if (message && message.jsenv && message.type === type) {
81
+ removeListener() // commenting this line keep this process alive
82
+ callback(message.data)
83
+ }
84
+ }
85
+ const removeListener = () => {
86
+ process.removeListener("message", listener)
87
+ }
88
+ process.on("message", listener)
89
+ return removeListener
90
+ }
91
+
92
+ const removeActionRequestListener = onceParentMessage(
93
+ ACTION_REQUEST_EVENT_NAME,
94
+ async ({ actionType, actionParams }) => {
95
+ const action = ACTIONS_AVAILABLE[actionType]
96
+ if (!action) {
97
+ sendActionFailed(new Error(`unknown action ${actionType}`))
98
+ return
99
+ }
100
+
101
+ let value
102
+ let failed = false
103
+ try {
104
+ value = await action(actionParams)
105
+ } catch (e) {
106
+ failed = true
107
+ value = e
108
+ }
109
+
110
+ // setTimeout(() => {}, 100)
111
+
112
+ if (failed) {
113
+ sendActionFailed(value)
114
+ } else {
115
+ sendActionCompleted(value)
116
+ }
117
+
118
+ // removeActionRequestListener()
119
+ if (actionParams.exitAfterAction) {
120
+ removeActionRequestListener()
121
+ // for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
122
+ // process.exit()
123
+ }
124
+ },
125
+ )
126
+
127
+ // remove listener to process.on('message')
128
+ // which is sufficient to let child process die
129
+ // assuming nothing else keeps it alive
130
+ // process.once("SIGTERM", removeActionRequestListener)
131
+ // process.once("SIGINT", removeActionRequestListener)
132
+
133
+ setTimeout(() => {
134
+ sendToParent("ready")
135
+ })
@@ -0,0 +1,103 @@
1
+ import { parentPort } from "node:worker_threads"
2
+ import { uneval } from "@jsenv/uneval"
3
+
4
+ import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js"
5
+
6
+ const ACTIONS_AVAILABLE = {
7
+ "execute-using-dynamic-import": executeUsingDynamicImport,
8
+ }
9
+ const ACTION_REQUEST_EVENT_NAME = "action"
10
+ const ACTION_RESPONSE_EVENT_NAME = "action-result"
11
+ const ACTION_RESPONSE_STATUS_FAILED = "action-failed"
12
+ const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed"
13
+
14
+ const sendActionFailed = (error) => {
15
+ if (error.hasOwnProperty("toString")) {
16
+ delete error.toString
17
+ }
18
+ sendToParent(
19
+ ACTION_RESPONSE_EVENT_NAME,
20
+ // process.send algorithm does not send non enumerable values
21
+ // so use @jsenv/uneval
22
+ uneval(
23
+ {
24
+ status: ACTION_RESPONSE_STATUS_FAILED,
25
+ value: error,
26
+ },
27
+ { ignoreSymbols: true },
28
+ ),
29
+ )
30
+ }
31
+
32
+ const sendActionCompleted = (value) => {
33
+ sendToParent(
34
+ ACTION_RESPONSE_EVENT_NAME,
35
+ // here we use JSON.stringify because we should not
36
+ // have non enumerable value (unlike there is on Error objects)
37
+ // otherwise uneval is quite slow to turn a giant object
38
+ // into a string (and value can be giant when using coverage)
39
+ JSON.stringify({
40
+ status: ACTION_RESPONSE_STATUS_COMPLETED,
41
+ value,
42
+ }),
43
+ )
44
+ }
45
+
46
+ const sendToParent = (type, data) => {
47
+ // this can keep process alive longer than expected
48
+ // when source is a long string.
49
+ // It means node process may stay alive longer than expected
50
+ // the time to send the data to the parent.
51
+ parentPort.postMessage({
52
+ jsenv: true,
53
+ type,
54
+ data,
55
+ })
56
+ }
57
+
58
+ const onceParentMessage = (type, callback) => {
59
+ const listener = (message) => {
60
+ if (message && message.jsenv && message.type === type) {
61
+ removeListener() // commenting this line keep this worker alive
62
+ callback(message.data)
63
+ }
64
+ }
65
+ const removeListener = () => {
66
+ parentPort.removeListener("message", listener)
67
+ }
68
+ parentPort.on("message", listener)
69
+ return removeListener
70
+ }
71
+
72
+ const removeActionRequestListener = onceParentMessage(
73
+ ACTION_REQUEST_EVENT_NAME,
74
+ async ({ actionType, actionParams }) => {
75
+ const action = ACTIONS_AVAILABLE[actionType]
76
+ if (!action) {
77
+ sendActionFailed(new Error(`unknown action ${actionType}`))
78
+ return
79
+ }
80
+
81
+ let value
82
+ let failed = false
83
+ try {
84
+ value = await action(actionParams)
85
+ } catch (e) {
86
+ failed = true
87
+ value = e
88
+ }
89
+
90
+ if (failed) {
91
+ sendActionFailed(value)
92
+ } else {
93
+ sendActionCompleted(value)
94
+ }
95
+ if (actionParams.exitAfterAction) {
96
+ removeActionRequestListener()
97
+ }
98
+ },
99
+ )
100
+
101
+ setTimeout(() => {
102
+ sendToParent("ready")
103
+ })
@@ -0,0 +1,57 @@
1
+ export const ExecOptions = {
2
+ fromExecArgv: (execArgv) => {
3
+ const execOptions = {}
4
+ let i = 0
5
+ while (i < execArgv.length) {
6
+ const execArg = execArgv[i]
7
+ const option = execOptionFromExecArg(execArg)
8
+ const existing = execOptions[option.name]
9
+ if (existing) {
10
+ execOptions[option.name] = Array.isArray(existing)
11
+ ? [...existing, option.value]
12
+ : [existing, option.value]
13
+ } else {
14
+ execOptions[option.name] = option.value
15
+ }
16
+ i++
17
+ }
18
+ return execOptions
19
+ },
20
+ toExecArgv: (execOptions) => {
21
+ const execArgv = []
22
+ Object.keys(execOptions).forEach((optionName) => {
23
+ const optionValue = execOptions[optionName]
24
+ if (optionValue === "unset") {
25
+ return
26
+ }
27
+ if (optionValue === "") {
28
+ execArgv.push(optionName)
29
+ return
30
+ }
31
+ if (Array.isArray(optionValue)) {
32
+ optionValue.forEach((subValue) => {
33
+ execArgv.push(`${optionName}=${subValue}`)
34
+ })
35
+ } else {
36
+ execArgv.push(`${optionName}=${optionValue}`)
37
+ }
38
+ })
39
+ return execArgv
40
+ },
41
+ }
42
+
43
+ const execOptionFromExecArg = (execArg) => {
44
+ const equalCharIndex = execArg.indexOf("=")
45
+ if (equalCharIndex === -1) {
46
+ return {
47
+ name: execArg,
48
+ value: "",
49
+ }
50
+ }
51
+ const name = execArg.slice(0, equalCharIndex)
52
+ const value = execArg.slice(equalCharIndex + 1)
53
+ return {
54
+ name,
55
+ value,
56
+ }
57
+ }
@@ -0,0 +1,53 @@
1
+ import { writeFileSync } from "node:fs"
2
+
3
+ import { startJsCoverage } from "./profiler_v8_coverage.js"
4
+ import { startObservingPerformances } from "./node_execution_performance.js"
5
+
6
+ export const executeUsingDynamicImport = async ({
7
+ rootDirectoryUrl,
8
+ fileUrl,
9
+ collectPerformance,
10
+ coverageEnabled,
11
+ coverageConfig,
12
+ coverageMethodForNodeJs,
13
+ coverageFileUrl,
14
+ }) => {
15
+ const result = {}
16
+ const afterImportCallbacks = []
17
+ if (coverageEnabled && coverageMethodForNodeJs === "Profiler") {
18
+ const { filterV8Coverage } = await import("../coverage/v8_coverage.js")
19
+ const { stopJsCoverage } = await startJsCoverage()
20
+ afterImportCallbacks.push(async () => {
21
+ const coverage = await stopJsCoverage()
22
+ const coverageLight = await filterV8Coverage(coverage, {
23
+ rootDirectoryUrl,
24
+ coverageConfig,
25
+ })
26
+ writeFileSync(
27
+ new URL(coverageFileUrl),
28
+ JSON.stringify(coverageLight, null, " "),
29
+ )
30
+ })
31
+ }
32
+ if (collectPerformance) {
33
+ const getPerformance = startObservingPerformances()
34
+ afterImportCallbacks.push(async () => {
35
+ const performance = await getPerformance()
36
+ result.performance = performance
37
+ })
38
+ }
39
+ const namespace = await import(fileUrl)
40
+ const namespaceResolved = {}
41
+ await Promise.all(
42
+ Object.keys(namespace).map(async (key) => {
43
+ const value = await namespace[key]
44
+ namespaceResolved[key] = value
45
+ }),
46
+ )
47
+ result.namespace = namespaceResolved
48
+ await afterImportCallbacks.reduce(async (previous, afterImportCallback) => {
49
+ await previous
50
+ await afterImportCallback()
51
+ }, Promise.resolve())
52
+ return result
53
+ }
@@ -0,0 +1,9 @@
1
+ // https://nodejs.org/api/process.html#process_signal_events
2
+ const SIGINT_SIGNAL_NUMBER = 2
3
+ const SIGABORT_SIGNAL_NUMBER = 6
4
+ const SIGTERM_SIGNAL_NUMBER = 15
5
+ export const EXIT_CODES = {
6
+ SIGINT: 128 + SIGINT_SIGNAL_NUMBER,
7
+ SIGABORT: 128 + SIGABORT_SIGNAL_NUMBER,
8
+ SIGTERM: 128 + SIGTERM_SIGNAL_NUMBER,
9
+ }
@@ -0,0 +1,51 @@
1
+ import { readFileSync } from "node:fs"
2
+ import { pathToFileURL } from "node:url"
3
+ import { normalizeImportMap, resolveImport } from "@jsenv/importmap"
4
+
5
+ let importMap
6
+
7
+ const cwdUrl = `${String(pathToFileURL(process.cwd()))}/`
8
+
9
+ if (process.env.IMPORT_MAP) {
10
+ importMap = JSON.parse(process.env.IMPORT_MAP)
11
+ } else if (process.env.IMPORT_MAP_PATH) {
12
+ const importmapFileUrl = pathToFileURL(process.env.IMPORT_MAP_PATH)
13
+ const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8")
14
+ importMap = JSON.parse(importmapFileContentAsString)
15
+ } else {
16
+ const importmapFileUrl = new URL("./import_map.json", cwdUrl)
17
+ const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8")
18
+ importMap = JSON.parse(importmapFileContentAsString)
19
+ }
20
+
21
+ const importMapBaseUrl = process.env.IMPORT_MAP_BASE_URL || cwdUrl
22
+ importMap = normalizeImportMap(importMap, importMapBaseUrl)
23
+
24
+ export const resolve = (specifier, context, nextResolve) => {
25
+ try {
26
+ let mapped
27
+ const importer = context.parentURL ? String(context.parentURL) : undefined
28
+ const resolved = resolveImport({
29
+ specifier,
30
+ importer,
31
+ importMap,
32
+ defaultExtension: ".js",
33
+ onImportMapping: () => {
34
+ mapped = true
35
+ },
36
+ })
37
+ if (mapped) {
38
+ return {
39
+ shortCircuit: true,
40
+ url: resolved,
41
+ }
42
+ }
43
+ } catch (e) {
44
+ if (e.message.includes("bare specifier")) {
45
+ return nextResolve(specifier, context)
46
+ }
47
+ console.error(e)
48
+ return nextResolve(specifier, context)
49
+ }
50
+ return nextResolve(specifier, context)
51
+ }
@@ -0,0 +1,4 @@
1
+ export const IMPORTMAP_NODE_LOADER_FILE_URL = new URL(
2
+ "./importmap_node_loader.mjs?entry_point",
3
+ import.meta.url,
4
+ ).href
@@ -0,0 +1,76 @@
1
+ import { requireFromJsenv } from "@jsenv/core/src/helpers/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
+ }
@@ -0,0 +1,13 @@
1
+ // see https://github.com/nodejs/node/issues/47478
2
+ const originalEmit = process.emit
3
+ process.emit = (event, error) => {
4
+ if (event === "warning" && error.name === "ExperimentalWarning") {
5
+ if (
6
+ error.message.includes("--experimental-loader") ||
7
+ error.message.includes("Custom ESM Loaders is an experimental")
8
+ ) {
9
+ return false
10
+ }
11
+ }
12
+ return originalEmit.call(process, event, error)
13
+ }
@@ -0,0 +1,4 @@
1
+ export const NO_EXPERIMENTAL_WARNING_FILE_URL = new URL(
2
+ "./no_experimental_warnings.cjs?entry_point",
3
+ import.meta.url,
4
+ ).href