@jsenv/core 25.4.7 → 25.6.2

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 (60) hide show
  1. package/dist/browser_runtime/asset-manifest.json +2 -2
  2. package/dist/browser_runtime/browser_runtime_c81cd9af.js +5300 -0
  3. package/dist/browser_runtime/browser_runtime_c81cd9af.js.map +1089 -0
  4. package/dist/build_manifest.js +6 -6
  5. package/dist/compile_proxy/asset-manifest.json +2 -2
  6. package/dist/compile_proxy/{compile_proxy.html__inline__20_f4285042.js.map → compile_proxy.html__inline__20_c05fdc30.js.map} +2 -2
  7. package/dist/compile_proxy/{compile_proxy_ab528227.html → compile_proxy_93ec4247.html} +7 -4
  8. package/dist/event_source_client/asset-manifest.json +2 -2
  9. package/dist/event_source_client/event_source_client_69f48287.js +354 -0
  10. package/dist/event_source_client/{event_source_client_80644aee.js.map → event_source_client_69f48287.js.map} +2 -2
  11. package/dist/redirector/asset-manifest.json +2 -2
  12. package/dist/redirector/{redirector.html__inline__12_404b8295.js.map → redirector.html__inline__12_20421b23.js.map} +2 -2
  13. package/dist/redirector/{redirector_6df2620a.html → redirector_ddc79416.html} +7 -4
  14. package/dist/toolbar/asset-manifest.json +5 -5
  15. package/dist/toolbar/assets/{compilation.css_e37c747b.map → compilation.css_7421bd55.map} +3 -3
  16. package/dist/toolbar/assets/settings.css_942b5a9e.map +12 -0
  17. package/dist/toolbar/assets/{toolbar.main.css_269d7ce2.map → toolbar.main.css_b7d8bec1.map} +4 -4
  18. package/dist/toolbar/{toolbar.main_2c56a4e0.js.map → toolbar.main_7d7783d3.js.map} +2 -2
  19. package/dist/toolbar/{toolbar_17abd09a.html → toolbar_d6045dd0.html} +17 -11
  20. package/dist/toolbar_injector/asset-manifest.json +2 -2
  21. package/dist/toolbar_injector/toolbar_injector_c8c214dd.js +977 -0
  22. package/dist/toolbar_injector/{toolbar_injector_0f93509c.js.map → toolbar_injector_c8c214dd.js.map} +4 -4
  23. package/helpers/babel/asyncIterator/asyncIterator.js +61 -8
  24. package/helpers/babel/createClass/createClass.js +12 -12
  25. package/helpers/babel/inherits/inherits.js +10 -6
  26. package/helpers/babel/jsx/jsx.js +27 -22
  27. package/helpers/babel/objectSpread2/objectSpread2.js +22 -14
  28. package/helpers/babel/readme.md +3 -8
  29. package/helpers/babel/wrapRegExp/wrapRegExp.js +29 -29
  30. package/package.json +36 -36
  31. package/readme.md +21 -18
  32. package/src/buildProject.js +12 -20
  33. package/src/dev_server.js +6 -4
  34. package/src/executeTestPlan.js +20 -19
  35. package/src/internal/building/buildUsingRollup.js +5 -20
  36. package/src/internal/building/build_logs.js +33 -37
  37. package/src/internal/building/build_stats.js +2 -1
  38. package/src/internal/building/es_to_system.js +34 -0
  39. package/src/internal/building/import_references.js +0 -1
  40. package/src/internal/building/rollup_plugin_jsenv.js +146 -43
  41. package/src/internal/compiling/createCompiledFileService.js +0 -4
  42. package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -3
  43. package/src/internal/compiling/jsenv_directory/compile_context.js +1 -10
  44. package/src/internal/compiling/jsenv_directory/compile_profile.js +1 -2
  45. package/src/internal/compiling/startCompileServer.js +0 -14
  46. package/src/internal/dev_server/toolbar/compilation/compilation.css +3 -2
  47. package/src/internal/dev_server/toolbar/settings/settings.css +1 -2
  48. package/src/internal/dev_server/toolbar/toolbar.html +8 -4
  49. package/src/internal/executing/coverage/reportToCoverage.js +1 -0
  50. package/src/internal/executing/coverage_utils/v8_coverage_from_directory.js +2 -1
  51. package/src/internal/executing/executePlan.js +450 -60
  52. package/src/internal/jsenvCoreDirectoryUrl.js +7 -18
  53. package/src/internal/runtime/s.js +3 -2
  54. package/src/internal/runtime_support/runtime_support.js +1 -1
  55. package/dist/browser_runtime/browser_runtime_0e3396a1.js +0 -5298
  56. package/dist/browser_runtime/browser_runtime_0e3396a1.js.map +0 -1089
  57. package/dist/event_source_client/event_source_client_80644aee.js +0 -356
  58. package/dist/toolbar/assets/settings.css_61548139.map +0 -12
  59. package/dist/toolbar_injector/toolbar_injector_0f93509c.js +0 -976
  60. package/src/internal/executing/executeConcurrently.js +0 -440
@@ -1,440 +0,0 @@
1
- import { existsSync } from "node:fs"
2
- import { memoryUsage } from "node:process"
3
- import wrapAnsi from "wrap-ansi"
4
- import cuid from "cuid"
5
- import { loggerToLevels } from "@jsenv/logger"
6
- import { createLog, startSpinner } from "@jsenv/log"
7
- import {
8
- urlToFileSystemPath,
9
- resolveUrl,
10
- writeDirectory,
11
- ensureEmptyDirectory,
12
- normalizeStructuredMetaMap,
13
- urlToMeta,
14
- } from "@jsenv/filesystem"
15
- import { Abort, createCallbackListNotifiedOnce } from "@jsenv/abort"
16
-
17
- import { launchAndExecute } from "../executing/launchAndExecute.js"
18
- import { reportToCoverage } from "./coverage/reportToCoverage.js"
19
- import { formatExecuting, formatExecutionResult } from "./executionLogs.js"
20
- import { createSummaryLog } from "./createSummaryLog.js"
21
- import { ensureGlobalGc } from "./gc.js"
22
-
23
- export const executeConcurrently = async (
24
- executionSteps,
25
- {
26
- multipleExecutionsOperation,
27
-
28
- logger,
29
- launchAndExecuteLogLevel,
30
-
31
- projectDirectoryUrl,
32
- compileServer,
33
- babelPluginMap,
34
-
35
- logSummary,
36
- logMemoryHeapUsage,
37
- completedExecutionLogMerging,
38
- completedExecutionLogAbbreviation,
39
-
40
- maxExecutionsInParallel,
41
- defaultMsAllocatedPerExecution,
42
- stopAfterExecute,
43
- cooldownBetweenExecutions,
44
- gcBetweenExecutions,
45
-
46
- coverage,
47
- coverageConfig,
48
- coverageIncludeMissing,
49
- coverageForceIstanbul,
50
- coverageV8ConflictWarning,
51
- coverageTempDirectoryRelativeUrl,
52
- runtimeSupport,
53
-
54
- beforeExecutionCallback = () => {},
55
- afterExecutionCallback = () => {},
56
- },
57
- ) => {
58
- if (completedExecutionLogMerging && !process.stdout.isTTY) {
59
- completedExecutionLogMerging = false
60
- logger.debug(
61
- `Force completedExecutionLogMerging to false because process.stdout.isTTY is false`,
62
- )
63
- }
64
- const executionLogsEnabled = loggerToLevels(logger).info
65
- const executionSpinner = executionLogsEnabled && process.stdout.isTTY
66
-
67
- const startMs = Date.now()
68
- const report = {}
69
- const executionCount = executionSteps.length
70
-
71
- let transformReturnValue = (value) => value
72
-
73
- if (gcBetweenExecutions) {
74
- ensureGlobalGc()
75
- }
76
-
77
- const coverageTempDirectoryUrl = resolveUrl(
78
- coverageTempDirectoryRelativeUrl,
79
- projectDirectoryUrl,
80
- )
81
-
82
- const structuredMetaMapForCover = normalizeStructuredMetaMap(
83
- {
84
- cover: coverageConfig,
85
- },
86
- projectDirectoryUrl,
87
- )
88
- const coverageIgnorePredicate = (url) => {
89
- return !urlToMeta({
90
- url: resolveUrl(url, projectDirectoryUrl),
91
- structuredMetaMap: structuredMetaMapForCover,
92
- }).cover
93
- }
94
-
95
- if (coverage) {
96
- // in case runned multiple times, we don't want to keep writing lot of files in this directory
97
- if (!process.env.NODE_V8_COVERAGE) {
98
- await ensureEmptyDirectory(coverageTempDirectoryUrl)
99
- }
100
-
101
- if (runtimeSupport.node) {
102
- // v8 coverage is written in a directoy and auto propagate to subprocesses
103
- // through process.env.NODE_V8_COVERAGE.
104
- if (!coverageForceIstanbul && !process.env.NODE_V8_COVERAGE) {
105
- const v8CoverageDirectory = resolveUrl(
106
- `./node_v8/${cuid()}`,
107
- coverageTempDirectoryUrl,
108
- )
109
- await writeDirectory(v8CoverageDirectory, { allowUseless: true })
110
- process.env.NODE_V8_COVERAGE = urlToFileSystemPath(v8CoverageDirectory)
111
- }
112
- }
113
-
114
- transformReturnValue = async (value) => {
115
- if (multipleExecutionsOperation.signal.aborted) {
116
- // don't try to do the coverage stuff
117
- return value
118
- }
119
-
120
- try {
121
- value.coverage = await reportToCoverage(value.report, {
122
- signal: multipleExecutionsOperation.signal,
123
- logger,
124
- projectDirectoryUrl,
125
- babelPluginMap,
126
- coverageConfig,
127
- coverageIncludeMissing,
128
- coverageForceIstanbul,
129
- coverageIgnorePredicate,
130
- coverageV8ConflictWarning,
131
- })
132
- } catch (e) {
133
- if (Abort.isAbortError(e)) {
134
- return value
135
- }
136
- throw e
137
- }
138
- return value
139
- }
140
- }
141
-
142
- logger.info("")
143
- let executionLog = createLog({ newLine: "" })
144
- let abortedCount = 0
145
- let timedoutCount = 0
146
- let erroredCount = 0
147
- let completedCount = 0
148
- const stopAfterAllExecutionCallbackList = createCallbackListNotifiedOnce()
149
-
150
- const executionsDone = await executeInParallel({
151
- multipleExecutionsOperation,
152
- maxExecutionsInParallel,
153
- cooldownBetweenExecutions,
154
- executionSteps,
155
- start: async (paramsFromStep) => {
156
- const executionIndex = executionSteps.indexOf(paramsFromStep)
157
- const { executionName, fileRelativeUrl, runtime } = paramsFromStep
158
- const runtimeName = runtime.name
159
- const runtimeVersion = runtime.version
160
-
161
- const executionParams = {
162
- // the params below can be overriden by executionDefaultParams
163
- measurePerformance: false,
164
- collectPerformance: false,
165
- captureConsole: true,
166
- stopAfterExecute,
167
- stopAfterExecuteReason: "execution-done",
168
- allocatedMs: defaultMsAllocatedPerExecution,
169
- ...paramsFromStep,
170
- runtime,
171
- // mirrorConsole: false because file will be executed in parallel
172
- // so log would be a mess to read
173
- mirrorConsole: false,
174
- }
175
-
176
- const beforeExecutionInfo = {
177
- fileRelativeUrl,
178
- runtimeName,
179
- runtimeVersion,
180
- executionIndex,
181
- executionParams,
182
- }
183
-
184
- let spinner
185
- if (executionSpinner) {
186
- spinner = startSpinner({
187
- log: executionLog,
188
- text: formatExecuting(beforeExecutionInfo, {
189
- executionCount,
190
- abortedCount,
191
- timedoutCount,
192
- erroredCount,
193
- completedCount,
194
- ...(logMemoryHeapUsage
195
- ? { memoryHeap: memoryUsage().heapUsed }
196
- : {}),
197
- }),
198
- })
199
- }
200
- beforeExecutionCallback(beforeExecutionInfo)
201
-
202
- const filePath = urlToFileSystemPath(
203
- `${projectDirectoryUrl}${fileRelativeUrl}`,
204
- )
205
- let executionResult
206
- if (existsSync(filePath)) {
207
- executionResult = await launchAndExecute({
208
- signal: multipleExecutionsOperation.signal,
209
- launchAndExecuteLogLevel,
210
-
211
- ...executionParams,
212
- collectCoverage: coverage,
213
- coverageTempDirectoryUrl,
214
- runtimeParams: {
215
- projectDirectoryUrl,
216
- compileServerOrigin: compileServer.origin,
217
- compileServerId: compileServer.id,
218
- jsenvDirectoryRelativeUrl: compileServer.jsenvDirectoryRelativeUrl,
219
-
220
- collectCoverage: coverage,
221
- coverageIgnorePredicate,
222
- coverageForceIstanbul,
223
- stopAfterAllExecutionCallbackList,
224
- ...executionParams.runtimeParams,
225
- },
226
- executeParams: {
227
- fileRelativeUrl,
228
- ...executionParams.executeParams,
229
- },
230
- coverageV8ConflictWarning,
231
- })
232
- } else {
233
- executionResult = {
234
- status: "errored",
235
- error: new Error(
236
- `No file at ${fileRelativeUrl} for execution "${executionName}"`,
237
- ),
238
- }
239
- }
240
- if (fileRelativeUrl in report === false) {
241
- report[fileRelativeUrl] = {}
242
- }
243
- report[fileRelativeUrl][executionName] = executionResult
244
- const afterExecutionInfo = {
245
- ...beforeExecutionInfo,
246
- endMs: Date.now(),
247
- executionResult,
248
- }
249
- afterExecutionCallback(afterExecutionInfo)
250
-
251
- if (executionResult.status === "aborted") {
252
- abortedCount++
253
- } else if (executionResult.status === "timedout") {
254
- timedoutCount++
255
- } else if (executionResult.status === "errored") {
256
- erroredCount++
257
- } else if (executionResult.status === "completed") {
258
- completedCount++
259
- }
260
-
261
- if (gcBetweenExecutions) {
262
- global.gc()
263
- }
264
-
265
- if (executionLogsEnabled) {
266
- let log = formatExecutionResult(afterExecutionInfo, {
267
- completedExecutionLogAbbreviation,
268
- executionCount,
269
- abortedCount,
270
- timedoutCount,
271
- erroredCount,
272
- completedCount,
273
- ...(logMemoryHeapUsage ? { memoryHeap: memoryUsage().heapUsed } : {}),
274
- })
275
- log = `${log}
276
-
277
- `
278
- const { columns = 80 } = process.stdout
279
- log = wrapAnsi(log, columns, {
280
- trim: false,
281
- hard: true,
282
- wordWrap: false,
283
- })
284
-
285
- // replace spinner with this execution result
286
- if (spinner) spinner.stop()
287
- executionLog.write(log)
288
-
289
- const canOverwriteLog = canOverwriteLogGetter({
290
- completedExecutionLogMerging,
291
- executionResult,
292
- })
293
- if (canOverwriteLog) {
294
- // nothing to do, we reuse the current executionLog object
295
- } else {
296
- executionLog.destroy()
297
- executionLog = createLog({ newLine: "" })
298
- }
299
- }
300
- },
301
- })
302
-
303
- if (stopAfterExecute) {
304
- stopAfterAllExecutionCallbackList.notify()
305
- }
306
-
307
- const summaryCounts = reportToSummary(report)
308
-
309
- const summary = {
310
- executionCount,
311
- ...summaryCounts,
312
- // when execution is aborted, the remaining executions are "cancelled"
313
- cancelledCount:
314
- executionCount -
315
- executionsDone.length -
316
- // we substract abortedCount because they are not pushed into executionsDone
317
- summaryCounts.abortedCount,
318
- duration: Date.now() - startMs,
319
- }
320
- if (logSummary) {
321
- logger.info(createSummaryLog(summary))
322
- }
323
-
324
- return transformReturnValue({
325
- summary,
326
- report,
327
- })
328
- }
329
-
330
- const canOverwriteLogGetter = ({
331
- completedExecutionLogMerging,
332
- executionResult,
333
- }) => {
334
- if (!completedExecutionLogMerging) {
335
- return false
336
- }
337
-
338
- if (executionResult.status === "aborted") {
339
- return true
340
- }
341
-
342
- if (executionResult.status !== "completed") {
343
- return false
344
- }
345
-
346
- const { consoleCalls = [] } = executionResult
347
- if (consoleCalls.length > 0) {
348
- return false
349
- }
350
-
351
- return true
352
- }
353
-
354
- const executeInParallel = async ({
355
- multipleExecutionsOperation,
356
- executionSteps,
357
- start,
358
- maxExecutionsInParallel = 1,
359
- cooldownBetweenExecutions,
360
- }) => {
361
- const executionResults = []
362
- let progressionIndex = 0
363
- let remainingExecutionCount = executionSteps.length
364
-
365
- const nextChunk = async () => {
366
- if (multipleExecutionsOperation.signal.aborted) {
367
- return
368
- }
369
-
370
- const outputPromiseArray = []
371
- while (
372
- remainingExecutionCount > 0 &&
373
- outputPromiseArray.length < maxExecutionsInParallel
374
- ) {
375
- remainingExecutionCount--
376
- const outputPromise = executeOne(progressionIndex)
377
- progressionIndex++
378
- outputPromiseArray.push(outputPromise)
379
- }
380
-
381
- if (outputPromiseArray.length) {
382
- await Promise.all(outputPromiseArray)
383
- if (remainingExecutionCount > 0) {
384
- await nextChunk()
385
- }
386
- }
387
- }
388
-
389
- const executeOne = async (index) => {
390
- const input = executionSteps[index]
391
- const output = await start(input)
392
- if (!multipleExecutionsOperation.signal.aborted) {
393
- executionResults[index] = output
394
- }
395
- if (cooldownBetweenExecutions) {
396
- await new Promise((resolve) =>
397
- setTimeout(resolve, cooldownBetweenExecutions),
398
- )
399
- }
400
- }
401
-
402
- await nextChunk()
403
-
404
- return executionResults
405
- }
406
-
407
- const reportToSummary = (report) => {
408
- const fileNames = Object.keys(report)
409
-
410
- const countResultMatching = (predicate) => {
411
- return fileNames.reduce((previous, fileName) => {
412
- const fileExecutionResult = report[fileName]
413
-
414
- return (
415
- previous +
416
- Object.keys(fileExecutionResult).filter((executionName) => {
417
- const fileExecutionResultForRuntime =
418
- fileExecutionResult[executionName]
419
- return predicate(fileExecutionResultForRuntime)
420
- }).length
421
- )
422
- }, 0)
423
- }
424
-
425
- const abortedCount = countResultMatching(({ status }) => status === "aborted")
426
- const timedoutCount = countResultMatching(
427
- ({ status }) => status === "timedout",
428
- )
429
- const erroredCount = countResultMatching(({ status }) => status === "errored")
430
- const completedCount = countResultMatching(
431
- ({ status }) => status === "completed",
432
- )
433
-
434
- return {
435
- abortedCount,
436
- timedoutCount,
437
- erroredCount,
438
- completedCount,
439
- }
440
- }