@jsenv/core 23.1.4 → 23.3.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.
- package/dist/jsenv_browser_system.js +36 -99
- package/dist/jsenv_browser_system.js.map +12 -21
- package/dist/jsenv_compile_proxy.js +18 -82
- package/dist/jsenv_compile_proxy.js.map +11 -21
- package/dist/jsenv_exploring_index.js +127 -274
- package/dist/jsenv_exploring_index.js.map +76 -90
- package/dist/jsenv_exploring_redirector.js +21 -89
- package/dist/jsenv_exploring_redirector.js.map +13 -25
- package/dist/jsenv_toolbar.js +81 -149
- package/dist/jsenv_toolbar.js.map +50 -61
- package/dist/jsenv_toolbar_injector.js +56 -124
- package/dist/jsenv_toolbar_injector.js.map +27 -41
- package/package.json +15 -19
- package/src/buildProject.js +130 -122
- package/src/execute.js +47 -47
- package/src/executeTestPlan.js +107 -125
- package/src/importUsingChildProcess.js +2 -1
- package/src/internal/browser-launcher/executeHtmlFile.js +32 -12
- package/src/internal/browser-utils/fetch-browser.js +4 -29
- package/src/internal/browser-utils/fetchUsingXHR.js +5 -7
- package/src/internal/building/buildUsingRollup.js +59 -24
- package/src/internal/building/build_logs.js +7 -6
- package/src/internal/building/createJsenvRollupPlugin.js +10 -33
- package/src/internal/building/ressource_builder.js +3 -6
- package/src/internal/building/sourcemap_loader.js +4 -5
- package/src/internal/building/url_fetcher.js +2 -5
- package/src/internal/building/url_loader.js +3 -6
- package/src/internal/building/url_trace.js +3 -4
- package/src/internal/compiling/compileFile.js +1 -2
- package/src/internal/compiling/createCompiledFileService.js +12 -9
- package/src/internal/compiling/startCompileServer.js +85 -133
- package/src/internal/executing/coverage/generateCoverageJsonFile.js +20 -3
- package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +18 -30
- package/src/internal/executing/coverage/reportToCoverage.js +44 -24
- package/src/internal/executing/coverage/v8CoverageFromNodeV8Directory.js +2 -15
- package/src/internal/executing/createSummaryLog.js +48 -37
- package/src/internal/executing/executeConcurrently.js +96 -52
- package/src/internal/executing/executePlan.js +93 -67
- package/src/internal/executing/executionLogs.js +31 -38
- package/src/internal/executing/execution_colors.js +9 -0
- package/src/internal/executing/generateExecutionSteps.js +3 -2
- package/src/internal/executing/launchAndExecute.js +207 -271
- package/src/internal/exploring/fetchExploringJson.js +3 -4
- package/src/internal/fetchUrl.js +6 -2
- package/src/internal/logs/msAsDuration.js +1 -1
- package/src/internal/node-launcher/createChildProcessOptions.js +4 -5
- package/src/internal/node-launcher/createControllableNodeProcess.js +120 -229
- package/src/internal/node-launcher/kill_process_tree.js +76 -0
- package/src/internal/node-launcher/nodeControllableFile.mjs +16 -10
- package/src/internal/{promise_track_race.js → promise_race.js} +2 -2
- package/src/internal/runtime/s.js +25 -24
- package/src/internal/toolbar/util/animation.js +3 -7
- package/src/internal/toolbar/util/fetching.js +1 -30
- package/src/jsenvServiceWorkerFinalizer.js +1 -2
- package/src/launchBrowser.js +146 -139
- package/src/launchNode.js +29 -17
- package/src/playwright_browser_versions.js +3 -3
- package/src/requireUsingChildProcess.js +2 -1
- package/src/startExploring.js +55 -74
- package/src/internal/createCallbackList.js +0 -21
- package/src/internal/executeJsenvAsyncFunction.js +0 -34
- package/src/internal/executing/logUtils.js +0 -30
- package/src/internal/executing/writeLog.js +0 -106
- package/src/internal/executing/writeLog.test-manual.js +0 -62
- package/src/internal/logs/log_style.js +0 -52
- package/src/internal/trackRessources.js +0 -23
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createCancellationToken,
|
|
3
|
-
createOperation,
|
|
4
|
-
createStoppableOperation,
|
|
5
|
-
createCancellationSource,
|
|
6
|
-
composeCancellationToken,
|
|
7
|
-
errorToCancelReason,
|
|
8
|
-
} from "@jsenv/cancellation"
|
|
9
1
|
import { createLogger, createDetailedMessage } from "@jsenv/logger"
|
|
2
|
+
import { Abort, raceCallbacks } from "@jsenv/abort"
|
|
10
3
|
|
|
11
|
-
import { promiseTrackRace } from "../promise_track_race.js"
|
|
12
4
|
import { composeIstanbulCoverages } from "./coverage/composeIstanbulCoverages.js"
|
|
13
5
|
|
|
14
|
-
const TIMING_BEFORE_EXECUTION = "before-execution"
|
|
15
|
-
const TIMING_DURING_EXECUTION = "during-execution"
|
|
16
|
-
const TIMING_AFTER_EXECUTION = "after-execution"
|
|
17
|
-
|
|
18
6
|
export const launchAndExecute = async ({
|
|
7
|
+
signal = new AbortController().signal,
|
|
19
8
|
launchAndExecuteLogLevel,
|
|
20
|
-
cancellationToken = createCancellationToken(),
|
|
21
9
|
|
|
22
10
|
runtime,
|
|
23
11
|
runtimeParams,
|
|
@@ -39,7 +27,7 @@ export const launchAndExecute = async ({
|
|
|
39
27
|
// however unit test will pass true because they want to move on
|
|
40
28
|
stopAfterExecute = false,
|
|
41
29
|
stopAfterExecuteReason = "stop after execute",
|
|
42
|
-
// when launch returns {
|
|
30
|
+
// when launch returns { stoppedCallbackList, gracefulStop, stop }
|
|
43
31
|
// the launched runtime have that amount of ms for disconnected to resolve
|
|
44
32
|
// before we call stop
|
|
45
33
|
gracefulStopAllocatedMs = 4000,
|
|
@@ -51,7 +39,6 @@ export const launchAndExecute = async ({
|
|
|
51
39
|
// by default throw on error after execution
|
|
52
40
|
throw error
|
|
53
41
|
},
|
|
54
|
-
runtimeDisconnectCallback = () => {},
|
|
55
42
|
|
|
56
43
|
coverageV8MergeConflictIsExpected,
|
|
57
44
|
} = {}) => {
|
|
@@ -68,16 +55,19 @@ export const launchAndExecute = async ({
|
|
|
68
55
|
|
|
69
56
|
let executionResultTransformer = (executionResult) => executionResult
|
|
70
57
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
const launchAndExecuteOperation = Abort.startOperation()
|
|
59
|
+
launchAndExecuteOperation.addAbortSignal(signal)
|
|
60
|
+
|
|
61
|
+
const hasAllocatedMs =
|
|
62
|
+
typeof allocatedMs === "number" && allocatedMs !== Infinity
|
|
63
|
+
let timeoutAbortSource
|
|
64
|
+
|
|
65
|
+
if (hasAllocatedMs) {
|
|
66
|
+
timeoutAbortSource = launchAndExecuteOperation.timeout(
|
|
67
|
+
// FIXME: if allocatedMs is veryyyyyy big
|
|
68
|
+
// setTimeout may be called immediatly
|
|
69
|
+
// in that case we should just throw that the number is too big
|
|
70
|
+
allocatedMs,
|
|
81
71
|
)
|
|
82
72
|
}
|
|
83
73
|
|
|
@@ -166,7 +156,7 @@ export const launchAndExecute = async ({
|
|
|
166
156
|
executionResultTransformer = composeTransformer(
|
|
167
157
|
executionResultTransformer,
|
|
168
158
|
(executionResult) => {
|
|
169
|
-
const { coverage, indirectCoverage } = executionResult
|
|
159
|
+
const { coverage = {}, indirectCoverage } = executionResult
|
|
170
160
|
if (indirectCoverage) {
|
|
171
161
|
executionResult.coverage = composeIstanbulCoverages(
|
|
172
162
|
[coverage, indirectCoverage],
|
|
@@ -191,274 +181,200 @@ export const launchAndExecute = async ({
|
|
|
191
181
|
)
|
|
192
182
|
}
|
|
193
183
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
184
|
+
if (measureDuration) {
|
|
185
|
+
const startMs = Date.now()
|
|
186
|
+
executionResultTransformer = composeTransformer(
|
|
187
|
+
executionResultTransformer,
|
|
188
|
+
(executionResult) => {
|
|
189
|
+
const endMs = Date.now()
|
|
190
|
+
executionResult.startMs = startMs
|
|
191
|
+
executionResult.endMs = endMs
|
|
192
|
+
return executionResult
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
const runtimeLabel = `${runtime.name}/${runtime.version}`
|
|
199
|
+
logger.debug(`launch ${runtimeLabel} to execute something in it`)
|
|
198
200
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
launchAndExecuteOperation.throwIfAborted()
|
|
202
|
+
const launchReturnValue = await runtime.launch({
|
|
203
|
+
signal: launchAndExecuteOperation.signal,
|
|
204
|
+
logger,
|
|
205
|
+
stopAfterExecute,
|
|
201
206
|
measurePerformance,
|
|
202
207
|
collectPerformance,
|
|
203
208
|
...runtimeParams,
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
runtimeStartedCallback,
|
|
214
|
-
runtimeStoppedCallback,
|
|
215
|
-
}
|
|
216
|
-
const hasAllocatedMs =
|
|
217
|
-
typeof allocatedMs === "number" && allocatedMs !== Infinity
|
|
218
|
-
if (hasAllocatedMs) {
|
|
219
|
-
const TIMEOUT_CANCEL_REASON = "timeout"
|
|
220
|
-
|
|
221
|
-
const timeoutCancellationSource = createCancellationSource()
|
|
222
|
-
|
|
223
|
-
const id = setTimeout(() => {
|
|
224
|
-
// here if allocatedMs is very big
|
|
225
|
-
// setTimeout may be called immediatly
|
|
226
|
-
// in that case we should just throw that hte number is too big
|
|
227
|
-
timeoutCancellationSource.cancel(TIMEOUT_CANCEL_REASON)
|
|
228
|
-
}, allocatedMs)
|
|
229
|
-
const timeoutCancel = () => clearTimeout(id)
|
|
230
|
-
|
|
231
|
-
cancellationToken.register(timeoutCancel)
|
|
232
|
-
|
|
233
|
-
const externalOrTimeoutCancellationToken = composeCancellationToken(
|
|
234
|
-
cancellationToken,
|
|
235
|
-
timeoutCancellationSource.token,
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
executionResult = await computeExecutionResult({
|
|
240
|
-
...executionParams,
|
|
241
|
-
cancellationToken: externalOrTimeoutCancellationToken,
|
|
242
|
-
})
|
|
243
|
-
timeoutCancel()
|
|
244
|
-
} catch (e) {
|
|
245
|
-
if (errorToCancelReason(e) === TIMEOUT_CANCEL_REASON) {
|
|
246
|
-
executionResult = createTimedoutExecutionResult()
|
|
209
|
+
})
|
|
210
|
+
validateLaunchReturnValue(launchReturnValue)
|
|
211
|
+
|
|
212
|
+
const stopRuntime = async (reason) => {
|
|
213
|
+
const { stop } = launchReturnValue
|
|
214
|
+
logger.debug(`${runtimeLabel}: stop() because ${reason}`)
|
|
215
|
+
const { graceful } = await stop({ reason, gracefulStopAllocatedMs })
|
|
216
|
+
if (graceful) {
|
|
217
|
+
logger.debug(`${runtimeLabel}: runtime stopped gracefully`)
|
|
247
218
|
} else {
|
|
248
|
-
|
|
219
|
+
logger.debug(`${runtimeLabel}: runtime stopped`)
|
|
249
220
|
}
|
|
250
221
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
222
|
+
launchAndExecuteOperation.addAbortCallback(async () => {
|
|
223
|
+
await stopRuntime("Operation aborted")
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
logger.debug(createDetailedMessage(`${runtimeLabel}: runtime launched`))
|
|
227
|
+
runtimeStartedCallback()
|
|
228
|
+
|
|
229
|
+
logger.debug(`${runtimeLabel}: start execution`)
|
|
230
|
+
const {
|
|
231
|
+
errorCallbackList,
|
|
232
|
+
outputCallbackList,
|
|
233
|
+
stoppedCallbackList,
|
|
234
|
+
execute,
|
|
235
|
+
finalizeExecutionResult = (executionResult) => executionResult,
|
|
236
|
+
} = launchReturnValue
|
|
237
|
+
executionResultTransformer = composeTransformer(
|
|
238
|
+
executionResultTransformer,
|
|
239
|
+
finalizeExecutionResult,
|
|
240
|
+
)
|
|
241
|
+
outputCallbackList.add(runtimeConsoleCallback)
|
|
242
|
+
|
|
243
|
+
let executionResult = await callExecute({
|
|
244
|
+
launchAndExecuteOperation,
|
|
245
|
+
errorCallbackList,
|
|
246
|
+
stoppedCallbackList,
|
|
247
|
+
execute,
|
|
248
|
+
executeParams,
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
if (stopAfterExecute) {
|
|
252
|
+
// stopping runtime is part of the execution
|
|
253
|
+
try {
|
|
254
|
+
await stopRuntime(stopAfterExecuteReason)
|
|
255
|
+
} catch (e) {
|
|
256
|
+
executionResult = createErroredExecutionResult({
|
|
257
|
+
error: e,
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
// when the process is still alive
|
|
262
|
+
// we want to catch error to notify runtimeErrorAfterExecutionCallback
|
|
263
|
+
// and throw that error by default
|
|
264
|
+
errorCallbackList.add((error) => {
|
|
265
|
+
runtimeErrorAfterExecutionCallback(error)
|
|
266
|
+
})
|
|
267
|
+
stoppedCallbackList.add(() => {
|
|
268
|
+
logger.debug(`${runtimeLabel}: runtime stopped after execution`)
|
|
269
|
+
runtimeStoppedCallback()
|
|
270
|
+
})
|
|
271
|
+
}
|
|
254
272
|
|
|
255
|
-
|
|
256
|
-
|
|
273
|
+
if (executionResult.status === "errored") {
|
|
274
|
+
// debug log level because this error happens during execution
|
|
275
|
+
// there is no need to log it.
|
|
276
|
+
// the code will know the execution errored because it receives
|
|
277
|
+
// an errored execution result
|
|
278
|
+
logger.debug(
|
|
279
|
+
createDetailedMessage(`error during execution`, {
|
|
280
|
+
["error stack"]: executionResult.error.stack,
|
|
281
|
+
["execute params"]: JSON.stringify(executeParams, null, " "),
|
|
282
|
+
["runtime"]: runtime,
|
|
283
|
+
}),
|
|
284
|
+
)
|
|
285
|
+
} else {
|
|
286
|
+
logger.debug(`${runtimeLabel}: execution ${executionResult.status}`)
|
|
287
|
+
}
|
|
257
288
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
}
|
|
289
|
+
return executionResultTransformer(executionResult)
|
|
290
|
+
} catch (e) {
|
|
291
|
+
if (Abort.isAbortError(e)) {
|
|
292
|
+
// we should stop runtime too
|
|
264
293
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
294
|
+
if (timeoutAbortSource && timeoutAbortSource.signal.aborted) {
|
|
295
|
+
const executionResult = createTimedoutExecutionResult()
|
|
296
|
+
return executionResultTransformer(executionResult)
|
|
297
|
+
}
|
|
298
|
+
const executionResult = createAbortedExecutionResult()
|
|
299
|
+
return executionResultTransformer(executionResult)
|
|
300
|
+
}
|
|
301
|
+
throw e
|
|
302
|
+
} finally {
|
|
303
|
+
await launchAndExecuteOperation.end()
|
|
269
304
|
}
|
|
270
305
|
}
|
|
271
306
|
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
runtimeParams,
|
|
307
|
+
const callExecute = async ({
|
|
308
|
+
launchAndExecuteOperation,
|
|
309
|
+
errorCallbackList,
|
|
310
|
+
stoppedCallbackList,
|
|
311
|
+
execute,
|
|
278
312
|
executeParams,
|
|
279
|
-
|
|
280
|
-
stopAfterExecute,
|
|
281
|
-
stopAfterExecuteReason,
|
|
282
|
-
gracefulStopAllocatedMs,
|
|
283
|
-
runtimeStartedCallback,
|
|
284
|
-
runtimeStoppedCallback,
|
|
285
|
-
runtimeConsoleCallback,
|
|
286
|
-
runtimeErrorAfterExecutionCallback,
|
|
287
|
-
runtimeDisconnectCallback,
|
|
288
313
|
}) => {
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const value = await runtime.launch({
|
|
297
|
-
logger,
|
|
298
|
-
cancellationToken,
|
|
299
|
-
stopAfterExecute,
|
|
300
|
-
...runtimeParams,
|
|
301
|
-
})
|
|
302
|
-
runtimeStartedCallback()
|
|
303
|
-
return value
|
|
304
|
-
},
|
|
305
|
-
stop: async ({ gracefulStop, stop }, reason) => {
|
|
306
|
-
// external code can cancel using cancellationToken at any time.
|
|
307
|
-
// it is important to keep the code inside this stop function because once cancelled
|
|
308
|
-
// all code after the operation won't execute because it will be rejected with
|
|
309
|
-
// the cancellation error
|
|
310
|
-
|
|
311
|
-
let stoppedGracefully
|
|
312
|
-
|
|
313
|
-
if (gracefulStop && gracefulStopAllocatedMs) {
|
|
314
|
-
logger.debug(
|
|
315
|
-
`${runtimeLabel}: runtime.gracefulStop() because ${reason}`,
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
const gracefulStopPromise = (async () => {
|
|
319
|
-
await gracefulStop({ reason })
|
|
320
|
-
return true
|
|
321
|
-
})()
|
|
322
|
-
|
|
323
|
-
const stopPromise = (async () => {
|
|
324
|
-
stoppedGracefully = await new Promise(async (resolve) => {
|
|
325
|
-
const timeoutId = setTimeout(() => {
|
|
326
|
-
resolve(false)
|
|
327
|
-
}, gracefulStopAllocatedMs)
|
|
328
|
-
try {
|
|
329
|
-
await gracefulStopPromise
|
|
330
|
-
resolve(true)
|
|
331
|
-
} finally {
|
|
332
|
-
clearTimeout(timeoutId)
|
|
333
|
-
}
|
|
334
|
-
})
|
|
335
|
-
if (stoppedGracefully) {
|
|
336
|
-
return stoppedGracefully
|
|
314
|
+
const winnerPromise = new Promise((resolve, reject) => {
|
|
315
|
+
raceCallbacks(
|
|
316
|
+
{
|
|
317
|
+
aborted: (cb) => {
|
|
318
|
+
launchAndExecuteOperation.signal.addEventListener("abort", cb)
|
|
319
|
+
return () => {
|
|
320
|
+
launchAndExecuteOperation.signal.removeEventListener("abort", cb)
|
|
337
321
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
logger.debug(
|
|
356
|
-
`${runtimeLabel}: runtime stopped${
|
|
357
|
-
stoppedGracefully ? " gracefully" : ""
|
|
358
|
-
}`,
|
|
359
|
-
)
|
|
360
|
-
runtimeStoppedCallback({ stoppedGracefully })
|
|
361
|
-
},
|
|
322
|
+
},
|
|
323
|
+
error: (cb) => {
|
|
324
|
+
return errorCallbackList.add(cb)
|
|
325
|
+
},
|
|
326
|
+
stopped: (cb) => {
|
|
327
|
+
return stoppedCallbackList.add(cb)
|
|
328
|
+
},
|
|
329
|
+
executed: (cb) => {
|
|
330
|
+
const executed = execute({
|
|
331
|
+
signal: launchAndExecuteOperation.signal,
|
|
332
|
+
...executeParams,
|
|
333
|
+
})
|
|
334
|
+
executed.then(cb, reject)
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
resolve,
|
|
338
|
+
)
|
|
362
339
|
})
|
|
363
340
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const {
|
|
367
|
-
execute,
|
|
368
|
-
disconnected,
|
|
369
|
-
registerErrorCallback = () => {},
|
|
370
|
-
registerConsoleCallback = () => {},
|
|
371
|
-
finalizeExecutionResult = (executionResult) => executionResult,
|
|
372
|
-
} = launchReturnValue
|
|
373
|
-
|
|
374
|
-
logger.debug(createDetailedMessage(`${runtimeLabel}: runtime launched.`))
|
|
375
|
-
|
|
376
|
-
logger.debug(`${runtimeLabel}: start execution.`)
|
|
377
|
-
registerConsoleCallback(runtimeConsoleCallback)
|
|
378
|
-
|
|
379
|
-
const executeOperation = createOperation({
|
|
380
|
-
cancellationToken,
|
|
381
|
-
start: async () => {
|
|
382
|
-
let timing = TIMING_BEFORE_EXECUTION
|
|
383
|
-
|
|
384
|
-
disconnected.then(() => {
|
|
385
|
-
logger.debug(`${runtimeLabel}: runtime disconnected ${timing}.`)
|
|
386
|
-
runtimeDisconnectCallback({ timing })
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
const executed = execute(executeParams)
|
|
390
|
-
|
|
391
|
-
timing = TIMING_DURING_EXECUTION
|
|
392
|
-
|
|
393
|
-
const raceResult = await promiseTrackRace([disconnected, executed])
|
|
394
|
-
timing = TIMING_AFTER_EXECUTION
|
|
341
|
+
launchAndExecuteOperation.throwIfAborted()
|
|
342
|
+
const winner = await winnerPromise
|
|
395
343
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (stopAfterExecute) {
|
|
401
|
-
// if there is an error while stopping the runtine
|
|
402
|
-
// the execution is considered as failed
|
|
403
|
-
try {
|
|
404
|
-
await launchOperation.stop(stopAfterExecuteReason)
|
|
405
|
-
} catch (e) {
|
|
406
|
-
return finalizeExecutionResult(
|
|
407
|
-
createErroredExecutionResult({
|
|
408
|
-
error: e,
|
|
409
|
-
}),
|
|
410
|
-
)
|
|
411
|
-
}
|
|
412
|
-
} else {
|
|
413
|
-
// when the process is still alive
|
|
414
|
-
// we want to catch error to notify runtimeErrorAfterExecutionCallback
|
|
415
|
-
// and throw that error by default
|
|
416
|
-
registerErrorCallback((error) => {
|
|
417
|
-
runtimeErrorAfterExecutionCallback(error)
|
|
418
|
-
})
|
|
419
|
-
}
|
|
344
|
+
if (winner.name === "aborted") {
|
|
345
|
+
launchAndExecuteOperation.throwIfAborted()
|
|
346
|
+
}
|
|
420
347
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
// there is no need to log it.
|
|
427
|
-
// the code will know the execution errored because it receives
|
|
428
|
-
// an errored execution result
|
|
429
|
-
logger.debug(
|
|
430
|
-
createDetailedMessage(`error ${TIMING_DURING_EXECUTION}.`, {
|
|
431
|
-
["error stack"]: executionResult.error.stack,
|
|
432
|
-
["execute params"]: JSON.stringify(executeParams, null, " "),
|
|
433
|
-
["runtime"]: runtime,
|
|
434
|
-
}),
|
|
435
|
-
)
|
|
436
|
-
return finalizeExecutionResult(
|
|
437
|
-
createErroredExecutionResult(executionResult),
|
|
438
|
-
)
|
|
439
|
-
}
|
|
348
|
+
if (winner.name === "error") {
|
|
349
|
+
return createErroredExecutionResult({
|
|
350
|
+
error: winner.data,
|
|
351
|
+
})
|
|
352
|
+
}
|
|
440
353
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
})
|
|
354
|
+
if (winner.name === "stopped") {
|
|
355
|
+
return createErroredExecutionResult({
|
|
356
|
+
error: new Error(`runtime stopped during execution`),
|
|
357
|
+
})
|
|
358
|
+
}
|
|
447
359
|
|
|
448
|
-
const
|
|
360
|
+
const executeResult = winner.data
|
|
361
|
+
const { status } = executeResult
|
|
449
362
|
|
|
450
|
-
|
|
363
|
+
if (status === "errored") {
|
|
364
|
+
return createErroredExecutionResult(executeResult)
|
|
365
|
+
}
|
|
366
|
+
return createCompletedExecutionResult(executeResult)
|
|
451
367
|
}
|
|
452
368
|
|
|
453
|
-
const
|
|
369
|
+
const createAbortedExecutionResult = () => {
|
|
454
370
|
return {
|
|
455
|
-
status: "
|
|
371
|
+
status: "aborted",
|
|
456
372
|
}
|
|
457
373
|
}
|
|
458
374
|
|
|
459
|
-
const
|
|
375
|
+
const createTimedoutExecutionResult = () => {
|
|
460
376
|
return {
|
|
461
|
-
status: "
|
|
377
|
+
status: "timedout",
|
|
462
378
|
}
|
|
463
379
|
}
|
|
464
380
|
|
|
@@ -488,22 +404,42 @@ const normalizeNamespace = (namespace) => {
|
|
|
488
404
|
return normalized
|
|
489
405
|
}
|
|
490
406
|
|
|
407
|
+
const composeCallback = (previousCallback, callback) => {
|
|
408
|
+
return (...args) => {
|
|
409
|
+
previousCallback(...args)
|
|
410
|
+
return callback(...args)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const composeTransformer = (previousTransformer, transformer) => {
|
|
415
|
+
return async (value) => {
|
|
416
|
+
const transformedValue = await previousTransformer(value)
|
|
417
|
+
return transformer(transformedValue)
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
491
421
|
const validateLaunchReturnValue = (launchReturnValue) => {
|
|
492
422
|
if (launchReturnValue === null) {
|
|
493
|
-
throw new Error(`launch must return an object, got null`)
|
|
423
|
+
throw new Error(`runtime.launch must return an object, got null`)
|
|
494
424
|
}
|
|
495
425
|
|
|
496
426
|
if (typeof launchReturnValue !== "object") {
|
|
497
|
-
throw new Error(
|
|
427
|
+
throw new Error(
|
|
428
|
+
`runtime.launch must return an object, got ${launchReturnValue}`,
|
|
429
|
+
)
|
|
498
430
|
}
|
|
499
431
|
|
|
500
432
|
const { execute } = launchReturnValue
|
|
501
433
|
if (typeof execute !== "function") {
|
|
502
|
-
throw new Error(
|
|
434
|
+
throw new Error(
|
|
435
|
+
`runtime.launch must return an execute function, got ${execute}`,
|
|
436
|
+
)
|
|
503
437
|
}
|
|
504
438
|
|
|
505
|
-
const {
|
|
506
|
-
if (!
|
|
507
|
-
throw new Error(
|
|
439
|
+
const { stoppedCallbackList } = launchReturnValue
|
|
440
|
+
if (!stoppedCallbackList) {
|
|
441
|
+
throw new Error(
|
|
442
|
+
`runtime.launch must return a stoppedCallbackList object, got ${stoppedCallbackList}`,
|
|
443
|
+
)
|
|
508
444
|
}
|
|
509
445
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
2
|
-
import { isCancelError } from "@jsenv/cancellation/main.browser.js"
|
|
3
2
|
|
|
4
3
|
import { fetchJson } from "../browser-utils/fetchJson.js"
|
|
5
4
|
|
|
6
|
-
export const fetchExploringJson = async ({
|
|
5
|
+
export const fetchExploringJson = async ({ signal } = {}) => {
|
|
7
6
|
try {
|
|
8
7
|
const exploringInfo = await fetchJson("/.jsenv/exploring.json", {
|
|
9
|
-
|
|
8
|
+
signal,
|
|
10
9
|
})
|
|
11
10
|
return exploringInfo
|
|
12
11
|
} catch (e) {
|
|
13
|
-
if (
|
|
12
|
+
if (signal && signal.aborted && e.name === "AbortError") {
|
|
14
13
|
throw e
|
|
15
14
|
}
|
|
16
15
|
throw new Error(
|
package/src/internal/fetchUrl.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { globalAgent } from "node:https"
|
|
2
|
-
import { fetchUrl as serverFetchUrl
|
|
2
|
+
import { fetchUrl as serverFetchUrl } from "@jsenv/server"
|
|
3
|
+
import { headersToObject } from "@jsenv/server/src/internal/headersToObject.js"
|
|
3
4
|
|
|
4
5
|
// ideally we should only pass this to the fetch below
|
|
5
6
|
globalAgent.options.rejectUnauthorized = false
|
|
@@ -8,7 +9,10 @@ export const fetchUrl = async (
|
|
|
8
9
|
url,
|
|
9
10
|
{ ignoreHttpsError = true, ...rest } = {},
|
|
10
11
|
) => {
|
|
11
|
-
const response = await serverFetchUrl(url, {
|
|
12
|
+
const response = await serverFetchUrl(url, {
|
|
13
|
+
ignoreHttpsError,
|
|
14
|
+
...rest,
|
|
15
|
+
})
|
|
12
16
|
|
|
13
17
|
return {
|
|
14
18
|
url: response.url,
|
|
@@ -5,7 +5,7 @@ const humanizeDuration = require("humanize-duration")
|
|
|
5
5
|
export const msAsDuration = (metricValue) => {
|
|
6
6
|
return humanizeDuration(metricValue, {
|
|
7
7
|
largest: 2,
|
|
8
|
-
maxDecimalPoints: metricValue < 1 ?
|
|
8
|
+
maxDecimalPoints: metricValue < 0.1 ? 3 : metricValue < 1000 ? 2 : 1,
|
|
9
9
|
// units: ["s"]
|
|
10
10
|
})
|
|
11
11
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createCancellationToken } from "@jsenv/cancellation"
|
|
2
1
|
import { findFreePort } from "@jsenv/server"
|
|
3
2
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
4
3
|
|
|
@@ -14,7 +13,7 @@ const AVAILABLE_DEBUG_MODE = [
|
|
|
14
13
|
]
|
|
15
14
|
|
|
16
15
|
export const createChildProcessOptions = async ({
|
|
17
|
-
|
|
16
|
+
signal = new AbortController().signal,
|
|
18
17
|
// https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_automatically-attach-debugger-to-nodejs-subprocesses
|
|
19
18
|
processExecArgv = process.execArgv,
|
|
20
19
|
processDebugPort = process.debugPort,
|
|
@@ -38,7 +37,7 @@ export const createChildProcessOptions = async ({
|
|
|
38
37
|
const childProcessOptions = processOptionsFromExecArgv(processExecArgv)
|
|
39
38
|
|
|
40
39
|
await mutateDebuggingOptions(childProcessOptions, {
|
|
41
|
-
|
|
40
|
+
signal,
|
|
42
41
|
processDebugPort,
|
|
43
42
|
debugMode,
|
|
44
43
|
debugPort,
|
|
@@ -52,7 +51,7 @@ const mutateDebuggingOptions = async (
|
|
|
52
51
|
childProcessOptions,
|
|
53
52
|
{
|
|
54
53
|
// ensure multiline
|
|
55
|
-
|
|
54
|
+
signal,
|
|
56
55
|
processDebugPort,
|
|
57
56
|
debugMode,
|
|
58
57
|
debugPort,
|
|
@@ -92,7 +91,7 @@ const mutateDebuggingOptions = async (
|
|
|
92
91
|
// support assigning a child spawned without a specific port
|
|
93
92
|
const childDebugPortOptionValue =
|
|
94
93
|
debugPort === 0
|
|
95
|
-
? await findFreePort(processDebugPort + 37, {
|
|
94
|
+
? await findFreePort(processDebugPort + 37, { signal })
|
|
96
95
|
: debugPort
|
|
97
96
|
// replace child debug port
|
|
98
97
|
if (parentDebugPortOptionName) {
|