@jsenv/core 23.5.2 → 23.7.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 (123) hide show
  1. package/{license → LICENSE} +21 -21
  2. package/dist/jsenv_browser_system.js +35 -35
  3. package/dist/jsenv_browser_system.js.map +14 -14
  4. package/dist/jsenv_compile_proxy.js +47 -128
  5. package/dist/jsenv_compile_proxy.js.map +25 -62
  6. package/dist/jsenv_exploring_index.js.map +5 -5
  7. package/dist/jsenv_exploring_redirector.js +47 -54
  8. package/dist/jsenv_exploring_redirector.js.map +17 -19
  9. package/dist/jsenv_toolbar.js +47 -128
  10. package/dist/jsenv_toolbar.js.map +12 -47
  11. package/dist/jsenv_toolbar_injector.js.map +5 -5
  12. package/helpers/babel/.eslintrc.cjs +24 -24
  13. package/helpers/babel/AsyncGenerator/AsyncGenerator.js +81 -81
  14. package/helpers/babel/AwaitValue/AwaitValue.js +3 -3
  15. package/helpers/babel/applyDecoratorDescriptor/applyDecoratorDescriptor.js +33 -33
  16. package/helpers/babel/arrayLikeToArray/arrayLikeToArray.js +7 -7
  17. package/helpers/babel/arrayWithHoles/arrayWithHoles.js +4 -4
  18. package/helpers/babel/arrayWithoutHoles/arrayWithoutHoles.js +6 -6
  19. package/helpers/babel/assertThisInitialized/assertThisInitialized.js +7 -7
  20. package/helpers/babel/asyncGeneratorDelegate/asyncGeneratorDelegate.js +40 -40
  21. package/helpers/babel/asyncIterator/asyncIterator.js +12 -12
  22. package/helpers/babel/asyncToGenerator/asyncToGenerator.js +34 -34
  23. package/helpers/babel/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -5
  24. package/helpers/babel/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -20
  25. package/helpers/babel/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -6
  26. package/helpers/babel/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -13
  27. package/helpers/babel/classCallCheck/classCallCheck.js +5 -5
  28. package/helpers/babel/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -5
  29. package/helpers/babel/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -6
  30. package/helpers/babel/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -7
  31. package/helpers/babel/classNameTDZError/classNameTDZError.js +4 -4
  32. package/helpers/babel/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -7
  33. package/helpers/babel/classPrivateFieldGet/classPrivateFieldGet.js +7 -7
  34. package/helpers/babel/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -6
  35. package/helpers/babel/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -5
  36. package/helpers/babel/classPrivateFieldSet/classPrivateFieldSet.js +8 -8
  37. package/helpers/babel/classPrivateMethodGet/classPrivateMethodGet.js +6 -6
  38. package/helpers/babel/classPrivateMethodSet/classPrivateMethodSet.js +3 -3
  39. package/helpers/babel/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -9
  40. package/helpers/babel/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -15
  41. package/helpers/babel/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -6
  42. package/helpers/babel/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -3
  43. package/helpers/babel/construct/construct.js +16 -16
  44. package/helpers/babel/createClass/createClass.js +15 -15
  45. package/helpers/babel/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -60
  46. package/helpers/babel/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -23
  47. package/helpers/babel/createRawReactElement/createRawReactElement.js +50 -50
  48. package/helpers/babel/createSuper/createSuper.js +22 -22
  49. package/helpers/babel/decorate/decorate.js +403 -403
  50. package/helpers/babel/defaults/defaults.js +11 -11
  51. package/helpers/babel/defineEnumerableProperties/defineEnumerableProperties.js +23 -23
  52. package/helpers/babel/defineProperty/defineProperty.js +18 -18
  53. package/helpers/babel/extends/extends.js +14 -14
  54. package/helpers/babel/get/get.js +13 -13
  55. package/helpers/babel/getPrototypeOf/getPrototypeOf.js +4 -4
  56. package/helpers/babel/inherits/inherits.js +15 -15
  57. package/helpers/babel/inheritsLoose/inheritsLoose.js +7 -7
  58. package/helpers/babel/initializerDefineProperty/initializerDefineProperty.js +10 -10
  59. package/helpers/babel/initializerWarningHelper/initializerWarningHelper.js +6 -6
  60. package/helpers/babel/instanceof/instanceof.js +6 -6
  61. package/helpers/babel/interopRequireDefault/interopRequireDefault.js +3 -3
  62. package/helpers/babel/interopRequireWildcard/interopRequireWildcard.js +37 -37
  63. package/helpers/babel/isNativeFunction/isNativeFunction.js +4 -4
  64. package/helpers/babel/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -21
  65. package/helpers/babel/iterableToArray/iterableToArray.js +7 -7
  66. package/helpers/babel/iterableToArrayLimit/iterableToArrayLimit.js +36 -36
  67. package/helpers/babel/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +10 -10
  68. package/helpers/babel/jsx/jsx.js +45 -45
  69. package/helpers/babel/maybeArrayLike/maybeArrayLike.js +10 -10
  70. package/helpers/babel/newArrowCheck/newArrowCheck.js +5 -5
  71. package/helpers/babel/nonIterableRest/nonIterableRest.js +5 -5
  72. package/helpers/babel/nonIterableSpread/nonIterableSpread.js +5 -5
  73. package/helpers/babel/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -3
  74. package/helpers/babel/objectSpread/objectSpread.js +23 -23
  75. package/helpers/babel/objectSpread2/objectSpread2.js +33 -33
  76. package/helpers/babel/objectWithoutProperties/objectWithoutProperties.js +19 -19
  77. package/helpers/babel/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -13
  78. package/helpers/babel/possibleConstructorReturn/possibleConstructorReturn.js +10 -10
  79. package/helpers/babel/readOnlyError/readOnlyError.js +4 -4
  80. package/helpers/babel/readme.md +9 -9
  81. package/helpers/babel/set/set.js +44 -44
  82. package/helpers/babel/setPrototypeOf/setPrototypeOf.js +6 -6
  83. package/helpers/babel/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -8
  84. package/helpers/babel/slicedToArray/slicedToArray.js +10 -10
  85. package/helpers/babel/slicedToArrayLoose/slicedToArrayLoose.js +13 -13
  86. package/helpers/babel/superPropBase/superPropBase.js +10 -10
  87. package/helpers/babel/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -10
  88. package/helpers/babel/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -7
  89. package/helpers/babel/tdz/tdz.js +4 -4
  90. package/helpers/babel/temporalRef/temporalRef.js +6 -6
  91. package/helpers/babel/temporalUndefined/temporalUndefined.js +3 -3
  92. package/helpers/babel/toArray/toArray.js +10 -10
  93. package/helpers/babel/toConsumableArray/toConsumableArray.js +10 -10
  94. package/helpers/babel/toPrimitive/toPrimitive.js +10 -10
  95. package/helpers/babel/toPropertyKey/toPropertyKey.js +6 -6
  96. package/helpers/babel/typeof/typeof.js +14 -14
  97. package/helpers/babel/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -12
  98. package/helpers/babel/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -8
  99. package/helpers/babel/wrapNativeSuper/wrapNativeSuper.js +30 -30
  100. package/helpers/babel/wrapRegExp/wrapRegExp.js +63 -63
  101. package/helpers/babel/writeOnlyError/writeOnlyError.js +4 -4
  102. package/helpers/regenerator-runtime/regenerator-runtime.js +748 -748
  103. package/package.json +4 -2
  104. package/src/buildProject.js +300 -300
  105. package/src/execute.js +184 -184
  106. package/src/internal/browser-launcher/jsenv-browser-system.js +199 -199
  107. package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +20 -30
  108. package/src/internal/compiling/compile-directory/validateCache.js +23 -15
  109. package/src/internal/compiling/compileFile.js +36 -59
  110. package/src/internal/compiling/compileHtml.js +1 -4
  111. package/src/internal/compiling/createCompiledFileService.js +290 -290
  112. package/src/internal/compiling/startCompileServer.js +1052 -1131
  113. package/src/internal/executing/coverage/babel_plugin_instrument.js +90 -90
  114. package/src/internal/executing/coverage/reportToCoverage.js +187 -187
  115. package/src/internal/executing/executePlan.js +183 -183
  116. package/src/internal/executing/launchAndExecute.js +458 -450
  117. package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -250
  118. package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -115
  119. package/src/internal/runtime/s.js +727 -727
  120. package/src/internal/toolbar/jsenv-logo.svg +144 -144
  121. package/src/internal/url_conversion.js +317 -317
  122. package/src/launchNode.js +210 -210
  123. package/src/startExploring.js +309 -309
@@ -1,290 +1,290 @@
1
- import { nextService, fetchFileSystem } from "@jsenv/server"
2
- import {
3
- resolveUrl,
4
- resolveDirectoryUrl,
5
- normalizeStructuredMetaMap,
6
- urlToMeta,
7
- } from "@jsenv/filesystem"
8
-
9
- import { serverUrlToCompileInfo } from "@jsenv/core/src/internal/url_conversion.js"
10
- import { setUrlExtension } from "../url_utils.js"
11
- import {
12
- COMPILE_ID_BUILD_GLOBAL,
13
- COMPILE_ID_BUILD_GLOBAL_FILES,
14
- COMPILE_ID_BUILD_COMMONJS,
15
- COMPILE_ID_BUILD_COMMONJS_FILES,
16
- } from "../CONSTANTS.js"
17
- import { compileFile } from "./compileFile.js"
18
- import { compileHtml } from "./jsenvCompilerForHtml.js"
19
- import { compileImportmap } from "./jsenvCompilerForImportmap.js"
20
- import { compileJavascript } from "./jsenvCompilerForJavaScript.js"
21
-
22
- const jsenvCompilers = {
23
- "**/*.js": compileJavascript,
24
- "**/*.jsx": compileJavascript,
25
- "**/*.ts": compileJavascript,
26
- "**/*.tsx": compileJavascript,
27
- "**/*.mjs": compileJavascript,
28
-
29
- "**/*.html": compileHtml,
30
- "**/*.importmap": compileImportmap,
31
- }
32
-
33
- export const createCompiledFileService = ({
34
- compileServerOperation,
35
- logger,
36
-
37
- projectDirectoryUrl,
38
- outDirectoryRelativeUrl,
39
-
40
- runtimeSupport,
41
- transformTopLevelAwait,
42
- moduleOutFormat,
43
- importMetaFormat,
44
- babelPluginMap,
45
- groupMap,
46
- customCompilers,
47
-
48
- jsenvToolbarInjection,
49
-
50
- projectFileRequestedCallback,
51
- useFilesystemAsCache,
52
- compileCacheStrategy,
53
- sourcemapMethod,
54
- sourcemapExcludeSources,
55
- }) => {
56
- Object.keys(customCompilers).forEach((key) => {
57
- const value = customCompilers[key]
58
- if (typeof value !== "function") {
59
- throw new TypeError(
60
- `Compiler must be a function, found ${value} for "${key}"`,
61
- )
62
- }
63
- })
64
- const compileMeta = normalizeStructuredMetaMap(
65
- {
66
- jsenvCompiler: jsenvCompilers,
67
- customCompiler: customCompilers,
68
- },
69
- projectDirectoryUrl,
70
- )
71
-
72
- return (request) => {
73
- const { origin, ressource } = request
74
- // we use "ressourceToPathname" to remove eventual query param from the url
75
- // Without this a pattern like "**/*.js" would not match "file.js?t=1"
76
- // This would result in file not being compiled when they should
77
- const requestUrl = `${origin}${ressourceToPathname(ressource)}`
78
-
79
- const requestCompileInfo = serverUrlToCompileInfo(requestUrl, {
80
- outDirectoryRelativeUrl,
81
- compileServerOrigin: origin,
82
- })
83
-
84
- // not inside compile directory -> nothing to compile
85
- if (!requestCompileInfo.insideCompileDirectory) {
86
- return null
87
- }
88
-
89
- const { compileId, afterCompileId } = requestCompileInfo
90
- // serve files inside /.jsenv/out/* directly without compilation
91
- // this is just to allow some files to be written inside outDirectory and read directly
92
- // if asked by the client (such as env.json, groupMap.json, meta.json)
93
- if (!compileId) {
94
- return fetchFileSystem(
95
- new URL(request.ressource.slice(1), projectDirectoryUrl),
96
- {
97
- headers: request.headers,
98
- etagEnabled: true,
99
- },
100
- )
101
- }
102
-
103
- const allowedCompileIds = [
104
- ...Object.keys(groupMap),
105
- COMPILE_ID_BUILD_GLOBAL,
106
- COMPILE_ID_BUILD_GLOBAL_FILES,
107
- COMPILE_ID_BUILD_COMMONJS,
108
- COMPILE_ID_BUILD_COMMONJS_FILES,
109
- ]
110
- if (!allowedCompileIds.includes(compileId)) {
111
- return {
112
- status: 400,
113
- statusText: `compileId must be one of ${allowedCompileIds}, received ${compileId}`,
114
- }
115
- }
116
-
117
- // nothing after compileId, we don't know what to compile (not supposed to happen)
118
- if (afterCompileId === "") {
119
- return null
120
- }
121
-
122
- const originalFileRelativeUrl = afterCompileId
123
- projectFileRequestedCallback(originalFileRelativeUrl, request)
124
-
125
- const originalFileUrl = `${projectDirectoryUrl}${originalFileRelativeUrl}`
126
- const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
127
- const compileDirectoryUrl = resolveDirectoryUrl(
128
- compileDirectoryRelativeUrl,
129
- projectDirectoryUrl,
130
- )
131
- const compiledFileUrl = resolveUrl(
132
- originalFileRelativeUrl,
133
- compileDirectoryUrl,
134
- )
135
-
136
- const compiler = getCompiler({ originalFileUrl, compileMeta })
137
- // no compiler -> serve original file
138
- // we don't redirect otherwise it complexify ressource tracking
139
- // and url resolution
140
- if (!compiler) {
141
- return nextService({
142
- ...request,
143
- ressource: `/${originalFileRelativeUrl}`,
144
- })
145
- }
146
-
147
- // compile this if needed
148
- const compileResponsePromise = compileFile({
149
- compileServerOperation,
150
- logger,
151
-
152
- projectDirectoryUrl,
153
- originalFileUrl,
154
- compiledFileUrl,
155
-
156
- writeOnFilesystem: true, // we always need them
157
- useFilesystemAsCache,
158
- compileCacheStrategy,
159
- projectFileRequestedCallback,
160
- request,
161
- compile: ({ signal, code, map }) => {
162
- return compiler({
163
- signal,
164
- logger,
165
-
166
- code,
167
- map,
168
- url: originalFileUrl,
169
- compiledUrl: compiledFileUrl,
170
- projectDirectoryUrl,
171
- compileServerOrigin: request.origin,
172
- outDirectoryRelativeUrl,
173
- compileId,
174
-
175
- runtimeSupport,
176
- moduleOutFormat,
177
- importMetaFormat,
178
- transformTopLevelAwait,
179
- babelPluginMap: babelPluginMapFromCompileId(compileId, {
180
- babelPluginMap,
181
- groupMap,
182
- }),
183
-
184
- sourcemapMethod,
185
- sourcemapExcludeSources,
186
- jsenvToolbarInjection,
187
- })
188
- },
189
- })
190
- return compileResponsePromise
191
- }
192
- }
193
-
194
- const getCompiler = ({ originalFileUrl, compileMeta }) => {
195
- const { jsenvCompiler, customCompiler } = urlToMeta({
196
- url: originalFileUrl,
197
- structuredMetaMap: compileMeta,
198
- })
199
-
200
- if (!jsenvCompiler && !customCompiler) {
201
- return null
202
- }
203
-
204
- // there is only a jsenvCompiler
205
- if (jsenvCompiler && !customCompiler) {
206
- return jsenvCompiler
207
- }
208
-
209
- // there is a custom compiler and potentially a jsenv compiler
210
- return async (params) => {
211
- // do custom compilation first
212
- const customResult = await customCompiler(params)
213
- // then check if jsenv compiler should apply
214
- // to the new result contentType
215
- const jsenvCompilerAfterCustomCompilation =
216
- getJsenvCompilerAfterCustomCompilation({
217
- url: originalFileUrl,
218
- contentType: customResult.contentType,
219
- compileMeta,
220
- })
221
- if (!jsenvCompilerAfterCustomCompilation) {
222
- return customResult
223
- }
224
- const jsenvResult = await jsenvCompilerAfterCustomCompilation({
225
- ...params,
226
- code: customResult.compiledSource,
227
- map: customResult.sourcemap,
228
- })
229
- return jsenvResult
230
- }
231
- }
232
-
233
- const getJsenvCompilerAfterCustomCompilation = ({
234
- url,
235
- contentType,
236
- compileMeta,
237
- }) => {
238
- const extensionToForce = contentTypeExtensions[contentType]
239
- const urlForcingExtension = extensionToForce
240
- ? setUrlExtension(url, extensionToForce)
241
- : url
242
- const { jsenvCompiler } = urlToMeta({
243
- url: urlForcingExtension,
244
- structuredMetaMap: compileMeta,
245
- })
246
- return jsenvCompiler
247
- }
248
-
249
- // should match contentType where there is a jsenv compiler
250
- // back to an extension
251
- const contentTypeExtensions = {
252
- "application/javascript": ".js",
253
- "text/html": ".html",
254
- "application/importmap+json": ".importmap",
255
- // "text/css": ".css",
256
- }
257
-
258
- const babelPluginMapFromCompileId = (
259
- compileId,
260
- { babelPluginMap, groupMap },
261
- ) => {
262
- const babelPluginMapForGroup = {}
263
-
264
- groupMap[compileId].pluginRequiredNameArray.forEach((requiredPluginName) => {
265
- const babelPlugin = babelPluginMap[requiredPluginName]
266
- if (babelPlugin) {
267
- babelPluginMapForGroup[requiredPluginName] = babelPlugin
268
- }
269
- })
270
-
271
- Object.keys(babelPluginMap).forEach((key) => {
272
- if (key.startsWith("syntax-")) {
273
- babelPluginMapForGroup[key] = babelPluginMap[key]
274
- }
275
- if (key === "transform-replace-expressions") {
276
- babelPluginMapForGroup[key] = babelPluginMap[key]
277
- }
278
- })
279
-
280
- return babelPluginMapForGroup
281
- }
282
-
283
- const ressourceToPathname = (ressource) => {
284
- const searchSeparatorIndex = ressource.indexOf("?")
285
- const pathname =
286
- searchSeparatorIndex === -1
287
- ? ressource
288
- : ressource.slice(0, searchSeparatorIndex)
289
- return pathname
290
- }
1
+ import { nextService, fetchFileSystem } from "@jsenv/server"
2
+ import {
3
+ resolveUrl,
4
+ resolveDirectoryUrl,
5
+ normalizeStructuredMetaMap,
6
+ urlToMeta,
7
+ } from "@jsenv/filesystem"
8
+
9
+ import { serverUrlToCompileInfo } from "@jsenv/core/src/internal/url_conversion.js"
10
+ import { setUrlExtension } from "../url_utils.js"
11
+ import {
12
+ COMPILE_ID_BUILD_GLOBAL,
13
+ COMPILE_ID_BUILD_GLOBAL_FILES,
14
+ COMPILE_ID_BUILD_COMMONJS,
15
+ COMPILE_ID_BUILD_COMMONJS_FILES,
16
+ } from "../CONSTANTS.js"
17
+ import { compileFile } from "./compileFile.js"
18
+ import { compileHtml } from "./jsenvCompilerForHtml.js"
19
+ import { compileImportmap } from "./jsenvCompilerForImportmap.js"
20
+ import { compileJavascript } from "./jsenvCompilerForJavaScript.js"
21
+
22
+ const jsenvCompilers = {
23
+ "**/*.js": compileJavascript,
24
+ "**/*.jsx": compileJavascript,
25
+ "**/*.ts": compileJavascript,
26
+ "**/*.tsx": compileJavascript,
27
+ "**/*.mjs": compileJavascript,
28
+
29
+ "**/*.html": compileHtml,
30
+ "**/*.importmap": compileImportmap,
31
+ }
32
+
33
+ export const createCompiledFileService = ({
34
+ compileServerOperation,
35
+ logger,
36
+
37
+ projectDirectoryUrl,
38
+ outDirectoryRelativeUrl,
39
+
40
+ runtimeSupport,
41
+ transformTopLevelAwait,
42
+ moduleOutFormat,
43
+ importMetaFormat,
44
+ babelPluginMap,
45
+ groupMap,
46
+ customCompilers,
47
+
48
+ jsenvToolbarInjection,
49
+
50
+ projectFileRequestedCallback,
51
+ compileCacheStrategy,
52
+ sourcemapMethod,
53
+ sourcemapExcludeSources,
54
+ }) => {
55
+ Object.keys(customCompilers).forEach((key) => {
56
+ const value = customCompilers[key]
57
+ if (typeof value !== "function") {
58
+ throw new TypeError(
59
+ `Compiler must be a function, found ${value} for "${key}"`,
60
+ )
61
+ }
62
+ })
63
+ const compileMeta = normalizeStructuredMetaMap(
64
+ {
65
+ jsenvCompiler: jsenvCompilers,
66
+ customCompiler: customCompilers,
67
+ },
68
+ projectDirectoryUrl,
69
+ )
70
+
71
+ return (request) => {
72
+ const { origin, ressource } = request
73
+ // we use "ressourceToPathname" to remove eventual query param from the url
74
+ // Without this a pattern like "**/*.js" would not match "file.js?t=1"
75
+ // This would result in file not being compiled when they should
76
+ const requestUrl = `${origin}${ressourceToPathname(ressource)}`
77
+
78
+ const requestCompileInfo = serverUrlToCompileInfo(requestUrl, {
79
+ outDirectoryRelativeUrl,
80
+ compileServerOrigin: origin,
81
+ })
82
+
83
+ // not inside compile directory -> nothing to compile
84
+ if (!requestCompileInfo.insideCompileDirectory) {
85
+ return null
86
+ }
87
+
88
+ const { compileId, afterCompileId } = requestCompileInfo
89
+ // serve files inside /.jsenv/* directly without compilation
90
+ // this is just to allow some files to be written inside outDirectory and read directly
91
+ // if asked by the client (such __compile_server_meta__.json)
92
+ if (!compileId) {
93
+ return fetchFileSystem(
94
+ new URL(request.ressource.slice(1), projectDirectoryUrl),
95
+ {
96
+ headers: request.headers,
97
+ etagEnabled: true,
98
+ },
99
+ )
100
+ }
101
+
102
+ const allowedCompileIds = [
103
+ ...Object.keys(groupMap),
104
+ COMPILE_ID_BUILD_GLOBAL,
105
+ COMPILE_ID_BUILD_GLOBAL_FILES,
106
+ COMPILE_ID_BUILD_COMMONJS,
107
+ COMPILE_ID_BUILD_COMMONJS_FILES,
108
+ ]
109
+ if (!allowedCompileIds.includes(compileId)) {
110
+ return {
111
+ status: 400,
112
+ statusText: `compileId must be one of ${allowedCompileIds}, received ${compileId}`,
113
+ }
114
+ }
115
+
116
+ // nothing after compileId, we don't know what to compile (not supposed to happen)
117
+ if (afterCompileId === "") {
118
+ return null
119
+ }
120
+
121
+ const originalFileRelativeUrl = afterCompileId
122
+ projectFileRequestedCallback(originalFileRelativeUrl, request)
123
+
124
+ const originalFileUrl = `${projectDirectoryUrl}${originalFileRelativeUrl}`
125
+ const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
126
+ const compileDirectoryUrl = resolveDirectoryUrl(
127
+ compileDirectoryRelativeUrl,
128
+ projectDirectoryUrl,
129
+ )
130
+ const compiledFileUrl = resolveUrl(
131
+ originalFileRelativeUrl,
132
+ compileDirectoryUrl,
133
+ )
134
+
135
+ const compiler = getCompiler({ originalFileUrl, compileMeta })
136
+ // no compiler -> serve original file
137
+ // we don't redirect otherwise it complexify ressource tracking
138
+ // and url resolution
139
+ if (!compiler) {
140
+ return nextService({
141
+ ...request,
142
+ ressource: `/${originalFileRelativeUrl}`,
143
+ })
144
+ }
145
+
146
+ // compile this if needed
147
+ const compileResponsePromise = compileFile({
148
+ compileServerOperation,
149
+ logger,
150
+
151
+ projectDirectoryUrl,
152
+ originalFileUrl,
153
+ compiledFileUrl,
154
+
155
+ compileCacheStrategy,
156
+ projectFileRequestedCallback,
157
+ request,
158
+ compile: ({ code, map }) => {
159
+ return compiler({
160
+ logger,
161
+
162
+ code,
163
+ map,
164
+ url: originalFileUrl,
165
+ compiledUrl: compiledFileUrl,
166
+ projectDirectoryUrl,
167
+ compileServerOrigin: request.origin,
168
+ outDirectoryRelativeUrl,
169
+ compileId,
170
+ request,
171
+
172
+ runtimeSupport,
173
+ moduleOutFormat,
174
+ importMetaFormat,
175
+ transformTopLevelAwait,
176
+ babelPluginMap: babelPluginMapFromCompileId(compileId, {
177
+ babelPluginMap,
178
+ groupMap,
179
+ }),
180
+
181
+ sourcemapMethod,
182
+ sourcemapExcludeSources,
183
+ jsenvToolbarInjection,
184
+ })
185
+ },
186
+ })
187
+ return compileResponsePromise
188
+ }
189
+ }
190
+
191
+ const getCompiler = ({ originalFileUrl, compileMeta }) => {
192
+ const { jsenvCompiler, customCompiler } = urlToMeta({
193
+ url: originalFileUrl,
194
+ structuredMetaMap: compileMeta,
195
+ })
196
+
197
+ if (!jsenvCompiler && !customCompiler) {
198
+ return null
199
+ }
200
+
201
+ // there is only a jsenvCompiler
202
+ if (jsenvCompiler && !customCompiler) {
203
+ return jsenvCompiler
204
+ }
205
+
206
+ // there is a custom compiler and potentially a jsenv compiler
207
+ return async (params) => {
208
+ // do custom compilation first
209
+ const customResult = await customCompiler(params)
210
+ // then check if jsenv compiler should apply
211
+ // to the new result contentType
212
+ const jsenvCompilerAfterCustomCompilation =
213
+ getJsenvCompilerAfterCustomCompilation({
214
+ url: originalFileUrl,
215
+ contentType: customResult.contentType,
216
+ compileMeta,
217
+ })
218
+ if (!jsenvCompilerAfterCustomCompilation) {
219
+ return customResult
220
+ }
221
+ const jsenvResult = await jsenvCompilerAfterCustomCompilation({
222
+ ...params,
223
+ code: customResult.compiledSource,
224
+ map: customResult.sourcemap,
225
+ })
226
+ return {
227
+ ...customResult,
228
+ ...jsenvResult,
229
+ }
230
+ }
231
+ }
232
+
233
+ const getJsenvCompilerAfterCustomCompilation = ({
234
+ url,
235
+ contentType,
236
+ compileMeta,
237
+ }) => {
238
+ const extensionToForce = contentTypeExtensions[contentType]
239
+ const urlForcingExtension = extensionToForce
240
+ ? setUrlExtension(url, extensionToForce)
241
+ : url
242
+ const { jsenvCompiler } = urlToMeta({
243
+ url: urlForcingExtension,
244
+ structuredMetaMap: compileMeta,
245
+ })
246
+ return jsenvCompiler
247
+ }
248
+
249
+ // should match contentType where there is a jsenv compiler
250
+ // back to an extension
251
+ const contentTypeExtensions = {
252
+ "application/javascript": ".js",
253
+ "text/html": ".html",
254
+ "application/importmap+json": ".importmap",
255
+ // "text/css": ".css",
256
+ }
257
+
258
+ const babelPluginMapFromCompileId = (
259
+ compileId,
260
+ { babelPluginMap, groupMap },
261
+ ) => {
262
+ const babelPluginMapForGroup = {}
263
+
264
+ groupMap[compileId].pluginRequiredNameArray.forEach((requiredPluginName) => {
265
+ const babelPlugin = babelPluginMap[requiredPluginName]
266
+ if (babelPlugin) {
267
+ babelPluginMapForGroup[requiredPluginName] = babelPlugin
268
+ }
269
+ })
270
+
271
+ Object.keys(babelPluginMap).forEach((key) => {
272
+ if (key.startsWith("syntax-")) {
273
+ babelPluginMapForGroup[key] = babelPluginMap[key]
274
+ }
275
+ if (key === "transform-replace-expressions") {
276
+ babelPluginMapForGroup[key] = babelPluginMap[key]
277
+ }
278
+ })
279
+
280
+ return babelPluginMapForGroup
281
+ }
282
+
283
+ const ressourceToPathname = (ressource) => {
284
+ const searchSeparatorIndex = ressource.indexOf("?")
285
+ const pathname =
286
+ searchSeparatorIndex === -1
287
+ ? ressource
288
+ : ressource.slice(0, searchSeparatorIndex)
289
+ return pathname
290
+ }