@jsenv/core 23.1.4 → 23.2.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 (66) hide show
  1. package/dist/jsenv_browser_system.js +18 -82
  2. package/dist/jsenv_browser_system.js.map +11 -20
  3. package/dist/jsenv_compile_proxy.js +18 -82
  4. package/dist/jsenv_compile_proxy.js.map +11 -21
  5. package/dist/jsenv_exploring_index.js +127 -274
  6. package/dist/jsenv_exploring_index.js.map +76 -90
  7. package/dist/jsenv_exploring_redirector.js +21 -89
  8. package/dist/jsenv_exploring_redirector.js.map +13 -25
  9. package/dist/jsenv_toolbar.js +81 -149
  10. package/dist/jsenv_toolbar.js.map +50 -61
  11. package/dist/jsenv_toolbar_injector.js +56 -124
  12. package/dist/jsenv_toolbar_injector.js.map +27 -41
  13. package/{LICENSE → license} +0 -0
  14. package/package.json +6 -10
  15. package/src/abort/abortable.js +172 -0
  16. package/src/abort/callback_list.js +64 -0
  17. package/src/abort/callback_race.js +34 -0
  18. package/src/abort/cleaner.js +22 -0
  19. package/src/abort/main.js +32 -0
  20. package/src/abort/process_teardown_events.js +59 -0
  21. package/src/buildProject.js +132 -123
  22. package/src/execute.js +108 -107
  23. package/src/executeTestPlan.js +101 -121
  24. package/src/importUsingChildProcess.js +2 -1
  25. package/src/internal/browser-launcher/executeHtmlFile.js +22 -10
  26. package/src/internal/browser-utils/fetch-browser.js +4 -29
  27. package/src/internal/browser-utils/fetchUsingXHR.js +5 -7
  28. package/src/internal/building/buildUsingRollup.js +60 -24
  29. package/src/internal/building/createJsenvRollupPlugin.js +13 -31
  30. package/src/internal/building/ressource_builder.js +3 -6
  31. package/src/internal/building/sourcemap_loader.js +4 -5
  32. package/src/internal/building/url_fetcher.js +2 -5
  33. package/src/internal/building/url_loader.js +3 -6
  34. package/src/internal/compiling/compileFile.js +1 -2
  35. package/src/internal/compiling/createCompiledFileService.js +4 -4
  36. package/src/internal/compiling/startCompileServer.js +52 -109
  37. package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +19 -30
  38. package/src/internal/executing/coverage/reportToCoverage.js +44 -24
  39. package/src/internal/executing/coverage/v8CoverageFromNodeV8Directory.js +2 -15
  40. package/src/internal/executing/createSummaryLog.js +47 -34
  41. package/src/internal/executing/executeConcurrently.js +89 -47
  42. package/src/internal/executing/executePlan.js +33 -7
  43. package/src/internal/executing/executionLogs.js +25 -28
  44. package/src/internal/executing/execution_colors.js +15 -0
  45. package/src/internal/executing/generateExecutionSteps.js +3 -2
  46. package/src/internal/executing/launchAndExecute.js +213 -257
  47. package/src/internal/exploring/fetchExploringJson.js +3 -4
  48. package/src/internal/fetchUrl.js +6 -2
  49. package/src/internal/logs/log_style.js +16 -28
  50. package/src/internal/logs/msAsDuration.js +1 -1
  51. package/src/internal/node-launcher/createChildProcessOptions.js +4 -5
  52. package/src/internal/node-launcher/createControllableNodeProcess.js +117 -229
  53. package/src/internal/node-launcher/kill_process_tree.js +76 -0
  54. package/src/internal/node-launcher/nodeControllableFile.mjs +16 -10
  55. package/src/internal/{promise_track_race.js → promise_race.js} +2 -2
  56. package/src/internal/toolbar/util/animation.js +3 -7
  57. package/src/internal/toolbar/util/fetching.js +1 -30
  58. package/src/jsenvServiceWorkerFinalizer.js +1 -2
  59. package/src/launchBrowser.js +127 -127
  60. package/src/launchNode.js +32 -17
  61. package/src/playwright_browser_versions.js +3 -3
  62. package/src/requireUsingChildProcess.js +2 -1
  63. package/src/signal/signal.js +65 -0
  64. package/src/startExploring.js +69 -73
  65. package/src/internal/executeJsenvAsyncFunction.js +0 -34
  66. package/src/internal/trackRessources.js +0 -23
@@ -1,14 +1,13 @@
1
- import {
2
- createCancellationToken,
3
- composeCancellationToken,
4
- } from "@jsenv/cancellation"
5
1
  import {
6
2
  normalizeStructuredMetaMap,
7
3
  collectFiles,
8
4
  urlToRelativeUrl,
9
5
  } from "@jsenv/filesystem"
10
6
 
11
- import { executeJsenvAsyncFunction } from "./internal/executeJsenvAsyncFunction.js"
7
+ import {
8
+ Abortable,
9
+ raceProcessTeardownEvents,
10
+ } from "@jsenv/core/src/abort/main.js"
12
11
  import { jsenvCoreDirectoryUrl } from "./internal/jsenvCoreDirectoryUrl.js"
13
12
  import {
14
13
  assertProjectDirectoryUrl,
@@ -31,8 +30,8 @@ import {
31
30
  import { jsenvRuntimeSupportDuringDev } from "./jsenvRuntimeSupportDuringDev.js"
32
31
 
33
32
  export const startExploring = async ({
34
- cancellationToken = createCancellationToken(),
35
- cancelOnSIGINT = false,
33
+ signal = new AbortController().signal,
34
+ handleSIGINT = true,
36
35
 
37
36
  explorableConfig = jsenvExplorableConfig,
38
37
  projectDirectoryUrl,
@@ -58,79 +57,76 @@ export const startExploring = async ({
58
57
  livereloadWatchConfig,
59
58
  jsenvDirectoryClean,
60
59
  }) => {
61
- const jsenvStartExploringFunction = async ({ jsenvCancellationToken }) => {
62
- cancellationToken = composeCancellationToken(
63
- cancellationToken,
64
- jsenvCancellationToken,
65
- )
60
+ projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
61
+ await assertProjectDirectoryExists({ projectDirectoryUrl })
66
62
 
67
- projectDirectoryUrl = assertProjectDirectoryUrl({ projectDirectoryUrl })
68
- await assertProjectDirectoryExists({ projectDirectoryUrl })
69
-
70
- const outDirectoryRelativeUrl = computeOutDirectoryRelativeUrl({
71
- projectDirectoryUrl,
72
- jsenvDirectoryRelativeUrl,
73
- outDirectoryName,
74
- })
63
+ const exploringServerOperation = Abortable.fromSignal(signal)
64
+ if (handleSIGINT) {
65
+ Abortable.effect(exploringServerOperation, (cb) =>
66
+ raceProcessTeardownEvents(
67
+ {
68
+ SIGINT: true,
69
+ },
70
+ cb,
71
+ ),
72
+ )
73
+ }
75
74
 
76
- const redirectFiles = createRedirectFilesService({
77
- projectDirectoryUrl,
78
- outDirectoryRelativeUrl,
79
- })
80
- const serveExploringData = createExploringDataService({
81
- projectDirectoryUrl,
82
- outDirectoryRelativeUrl,
83
- explorableConfig,
84
- livereloading,
85
- })
86
- const serveExplorableListAsJson = createExplorableListAsJsonService({
87
- projectDirectoryUrl,
88
- outDirectoryRelativeUrl,
89
- explorableConfig,
90
- })
75
+ const outDirectoryRelativeUrl = computeOutDirectoryRelativeUrl({
76
+ projectDirectoryUrl,
77
+ jsenvDirectoryRelativeUrl,
78
+ outDirectoryName,
79
+ })
91
80
 
92
- const compileServer = await startCompileServer({
93
- cancellationToken,
94
- projectDirectoryUrl,
95
- keepProcessAlive,
96
- livereloadSSE: livereloading,
97
- accessControlAllowRequestOrigin: true,
98
- accessControlAllowRequestMethod: true,
99
- accessControlAllowRequestHeaders: true,
100
- accessControlAllowCredentials: true,
101
- stopOnPackageVersionChange: true,
102
- jsenvToolbarInjection: jsenvToolbar,
103
- customServices: {
104
- "service:exploring-redirect": (request) => redirectFiles(request),
105
- "service:exploring-data": (request) => serveExploringData(request),
106
- "service:explorables": (request) => serveExplorableListAsJson(request),
107
- },
108
- customCompilers,
109
- jsenvDirectoryRelativeUrl,
110
- outDirectoryName,
111
- inlineImportMapIntoHTML,
81
+ const redirectFiles = createRedirectFilesService({
82
+ projectDirectoryUrl,
83
+ outDirectoryRelativeUrl,
84
+ })
85
+ const serveExploringData = createExploringDataService({
86
+ projectDirectoryUrl,
87
+ outDirectoryRelativeUrl,
88
+ explorableConfig,
89
+ livereloading,
90
+ })
91
+ const serveExplorableListAsJson = createExplorableListAsJsonService({
92
+ projectDirectoryUrl,
93
+ outDirectoryRelativeUrl,
94
+ explorableConfig,
95
+ })
112
96
 
113
- compileServerLogLevel,
114
- compileServerCanReadFromFilesystem,
115
- compileServerCanWriteOnFilesystem,
116
- compileServerPort,
117
- compileServerProtocol,
118
- compileServerHttp2,
119
- compileServerCertificate,
120
- compileServerPrivateKey,
121
- sourcemapMethod,
122
- babelPluginMap,
123
- runtimeSupport: runtimeSupportDuringDev,
124
- livereloadWatchConfig,
125
- jsenvDirectoryClean,
126
- })
97
+ const compileServer = await startCompileServer({
98
+ signal: exploringServerOperation.signal,
99
+ keepProcessAlive,
127
100
 
128
- return compileServer
129
- }
101
+ projectDirectoryUrl,
102
+ livereloadSSE: livereloading,
103
+ jsenvToolbarInjection: jsenvToolbar,
104
+ customServices: {
105
+ "service:exploring-redirect": (request) => redirectFiles(request),
106
+ "service:exploring-data": (request) => serveExploringData(request),
107
+ "service:explorables": (request) => serveExplorableListAsJson(request),
108
+ },
109
+ customCompilers,
110
+ jsenvDirectoryRelativeUrl,
111
+ outDirectoryName,
112
+ inlineImportMapIntoHTML,
130
113
 
131
- return executeJsenvAsyncFunction(jsenvStartExploringFunction, {
132
- cancelOnSIGINT,
114
+ compileServerLogLevel,
115
+ compileServerCanReadFromFilesystem,
116
+ compileServerCanWriteOnFilesystem,
117
+ compileServerPort,
118
+ compileServerProtocol,
119
+ compileServerHttp2,
120
+ compileServerCertificate,
121
+ compileServerPrivateKey,
122
+ sourcemapMethod,
123
+ babelPluginMap,
124
+ runtimeSupport: runtimeSupportDuringDev,
125
+ livereloadWatchConfig,
126
+ jsenvDirectoryClean,
133
127
  })
128
+
129
+ return compileServer
134
130
  }
135
131
 
136
132
  const createRedirectFilesService = ({ projectDirectoryUrl }) => {
@@ -1,34 +0,0 @@
1
- import {
2
- executeAsyncFunction,
3
- createCancellationSource,
4
- } from "@jsenv/cancellation"
5
- import { SIGINTSignal } from "@jsenv/node-signals"
6
-
7
- export const executeJsenvAsyncFunction = (
8
- fn,
9
- { cancelOnSIGINT = false } = {},
10
- ) => {
11
- return executeAsyncFunction(
12
- async () => {
13
- const jsenvCancellationSource = createCancellationSource()
14
- const jsenvCancellationToken = jsenvCancellationSource.token
15
-
16
- if (cancelOnSIGINT) {
17
- const unregister = SIGINTSignal.addCallback(() => {
18
- jsenvCancellationSource.cancel("process SIGINT")
19
- })
20
- try {
21
- return await fn({ jsenvCancellationToken })
22
- } finally {
23
- unregister()
24
- }
25
- }
26
-
27
- return fn({ jsenvCancellationToken })
28
- },
29
- {
30
- catchCancellation: true,
31
- considerUnhandledRejectionsAsExceptions: true,
32
- },
33
- )
34
- }
@@ -1,23 +0,0 @@
1
- import { memoize } from "@jsenv/filesystem"
2
-
3
- export const trackRessources = () => {
4
- const callbackArray = []
5
-
6
- const registerCleanupCallback = (callback) => {
7
- if (typeof callback !== "function")
8
- throw new TypeError(`callback must be a function
9
- callback: ${callback}`)
10
- callbackArray.push(callback)
11
- return () => {
12
- const index = callbackArray.indexOf(callback)
13
- if (index > -1) callbackArray.splice(index, 1)
14
- }
15
- }
16
-
17
- const cleanup = memoize(async (reason) => {
18
- const localCallbackArray = callbackArray.slice()
19
- await Promise.all(localCallbackArray.map((callback) => callback(reason)))
20
- })
21
-
22
- return { registerCleanupCallback, cleanup }
23
- }