@jsenv/core 23.8.2 → 23.8.7
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 +46 -39
- package/dist/jsenv_browser_system.js.map +14 -14
- package/dist/jsenv_compile_proxy.js.map +6 -6
- package/dist/jsenv_exploring_index.js.map +5 -5
- package/dist/jsenv_exploring_redirector.js.map +12 -12
- package/dist/jsenv_toolbar.js.map +7 -7
- package/dist/jsenv_toolbar_injector.js.map +5 -5
- package/helpers/babel/.eslintrc.cjs +24 -24
- package/helpers/babel/AsyncGenerator/AsyncGenerator.js +81 -81
- package/helpers/babel/AwaitValue/AwaitValue.js +3 -3
- package/helpers/babel/applyDecoratorDescriptor/applyDecoratorDescriptor.js +33 -33
- package/helpers/babel/arrayLikeToArray/arrayLikeToArray.js +7 -7
- package/helpers/babel/arrayWithHoles/arrayWithHoles.js +4 -4
- package/helpers/babel/arrayWithoutHoles/arrayWithoutHoles.js +6 -6
- package/helpers/babel/assertThisInitialized/assertThisInitialized.js +7 -7
- package/helpers/babel/asyncGeneratorDelegate/asyncGeneratorDelegate.js +40 -40
- package/helpers/babel/asyncIterator/asyncIterator.js +12 -12
- package/helpers/babel/asyncToGenerator/asyncToGenerator.js +34 -34
- package/helpers/babel/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -5
- package/helpers/babel/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -20
- package/helpers/babel/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -6
- package/helpers/babel/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -13
- package/helpers/babel/classCallCheck/classCallCheck.js +5 -5
- package/helpers/babel/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -5
- package/helpers/babel/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -6
- package/helpers/babel/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -7
- package/helpers/babel/classNameTDZError/classNameTDZError.js +4 -4
- package/helpers/babel/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -7
- package/helpers/babel/classPrivateFieldGet/classPrivateFieldGet.js +7 -7
- package/helpers/babel/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -6
- package/helpers/babel/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -5
- package/helpers/babel/classPrivateFieldSet/classPrivateFieldSet.js +8 -8
- package/helpers/babel/classPrivateMethodGet/classPrivateMethodGet.js +6 -6
- package/helpers/babel/classPrivateMethodSet/classPrivateMethodSet.js +3 -3
- package/helpers/babel/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -9
- package/helpers/babel/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -15
- package/helpers/babel/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -6
- package/helpers/babel/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -3
- package/helpers/babel/construct/construct.js +16 -16
- package/helpers/babel/createClass/createClass.js +15 -15
- package/helpers/babel/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -60
- package/helpers/babel/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -23
- package/helpers/babel/createRawReactElement/createRawReactElement.js +50 -50
- package/helpers/babel/createSuper/createSuper.js +22 -22
- package/helpers/babel/decorate/decorate.js +403 -403
- package/helpers/babel/defaults/defaults.js +11 -11
- package/helpers/babel/defineEnumerableProperties/defineEnumerableProperties.js +23 -23
- package/helpers/babel/defineProperty/defineProperty.js +18 -18
- package/helpers/babel/extends/extends.js +14 -14
- package/helpers/babel/get/get.js +13 -13
- package/helpers/babel/getPrototypeOf/getPrototypeOf.js +4 -4
- package/helpers/babel/inherits/inherits.js +15 -15
- package/helpers/babel/inheritsLoose/inheritsLoose.js +7 -7
- package/helpers/babel/initializerDefineProperty/initializerDefineProperty.js +10 -10
- package/helpers/babel/initializerWarningHelper/initializerWarningHelper.js +6 -6
- package/helpers/babel/instanceof/instanceof.js +6 -6
- package/helpers/babel/interopRequireDefault/interopRequireDefault.js +3 -3
- package/helpers/babel/interopRequireWildcard/interopRequireWildcard.js +37 -37
- package/helpers/babel/isNativeFunction/isNativeFunction.js +4 -4
- package/helpers/babel/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -21
- package/helpers/babel/iterableToArray/iterableToArray.js +7 -7
- package/helpers/babel/iterableToArrayLimit/iterableToArrayLimit.js +36 -36
- package/helpers/babel/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +10 -10
- package/helpers/babel/jsx/jsx.js +45 -45
- package/helpers/babel/maybeArrayLike/maybeArrayLike.js +10 -10
- package/helpers/babel/newArrowCheck/newArrowCheck.js +5 -5
- package/helpers/babel/nonIterableRest/nonIterableRest.js +5 -5
- package/helpers/babel/nonIterableSpread/nonIterableSpread.js +5 -5
- package/helpers/babel/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -3
- package/helpers/babel/objectSpread/objectSpread.js +23 -23
- package/helpers/babel/objectSpread2/objectSpread2.js +33 -33
- package/helpers/babel/objectWithoutProperties/objectWithoutProperties.js +19 -19
- package/helpers/babel/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -13
- package/helpers/babel/possibleConstructorReturn/possibleConstructorReturn.js +10 -10
- package/helpers/babel/readOnlyError/readOnlyError.js +4 -4
- package/helpers/babel/readme.md +9 -9
- package/helpers/babel/set/set.js +44 -44
- package/helpers/babel/setPrototypeOf/setPrototypeOf.js +6 -6
- package/helpers/babel/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -8
- package/helpers/babel/slicedToArray/slicedToArray.js +10 -10
- package/helpers/babel/slicedToArrayLoose/slicedToArrayLoose.js +13 -13
- package/helpers/babel/superPropBase/superPropBase.js +10 -10
- package/helpers/babel/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -10
- package/helpers/babel/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -7
- package/helpers/babel/tdz/tdz.js +4 -4
- package/helpers/babel/temporalRef/temporalRef.js +6 -6
- package/helpers/babel/temporalUndefined/temporalUndefined.js +3 -3
- package/helpers/babel/toArray/toArray.js +10 -10
- package/helpers/babel/toConsumableArray/toConsumableArray.js +10 -10
- package/helpers/babel/toPrimitive/toPrimitive.js +10 -10
- package/helpers/babel/toPropertyKey/toPropertyKey.js +6 -6
- package/helpers/babel/typeof/typeof.js +14 -14
- package/helpers/babel/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -12
- package/helpers/babel/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -8
- package/helpers/babel/wrapNativeSuper/wrapNativeSuper.js +30 -30
- package/helpers/babel/wrapRegExp/wrapRegExp.js +63 -63
- package/helpers/babel/writeOnlyError/writeOnlyError.js +4 -4
- package/helpers/regenerator-runtime/regenerator-runtime.js +748 -748
- package/{LICENSE → license} +21 -21
- package/package.json +2 -2
- package/src/buildProject.js +300 -300
- package/src/execute.js +184 -184
- package/src/internal/browser-launcher/jsenv-browser-system.js +203 -199
- package/src/internal/building/buildUsingRollup.js +2 -10
- package/src/internal/compiling/babel_plugin_import_assertions.js +121 -121
- package/src/internal/compiling/babel_plugin_import_metadata.js +22 -22
- package/src/internal/compiling/babel_plugin_import_visitor.js +84 -84
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +268 -268
- package/src/internal/compiling/compile-directory/updateMeta.js +154 -154
- package/src/internal/compiling/compile-directory/validateCache.js +265 -265
- package/src/internal/compiling/compileFile.js +233 -224
- package/src/internal/compiling/compileHtml.js +550 -550
- package/src/internal/compiling/createCompiledFileService.js +291 -291
- package/src/internal/compiling/html_source_file_service.js +403 -404
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +272 -270
- package/src/internal/compiling/jsenvCompilerForHtml.js +374 -308
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -0
- package/src/internal/compiling/startCompileServer.js +1086 -1048
- package/src/internal/compiling/transformResultToCompilationResult.js +220 -220
- package/src/internal/executing/coverage/babel_plugin_instrument.js +90 -90
- package/src/internal/executing/coverage/reportToCoverage.js +193 -187
- package/src/internal/executing/executePlan.js +183 -183
- package/src/internal/executing/launchAndExecute.js +458 -458
- package/src/internal/generateGroupMap/featuresCompatMap.js +29 -0
- package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +1 -8
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -246
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -112
- package/src/internal/runtime/s.js +727 -727
- package/src/internal/toolbar/jsenv-logo.svg +144 -144
- package/src/internal/toolbar/toolbar.main.css +196 -196
- package/src/internal/toolbar/toolbar.main.js +227 -227
- package/src/internal/url_conversion.js +317 -317
- package/src/startExploring.js +309 -309
|
@@ -1,308 +1,374 @@
|
|
|
1
|
-
import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
1
|
+
import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
|
+
import { moveImportMap, composeTwoImportMaps } from "@jsenv/importmap"
|
|
3
|
+
import { createDetailedMessage } from "@jsenv/logger"
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
jsenvBrowserSystemFileInfo,
|
|
7
|
+
jsenvToolbarHtmlFileInfo,
|
|
8
|
+
jsenvToolbarInjectorFileInfo,
|
|
9
|
+
} from "@jsenv/core/src/internal/jsenvInternalFiles.js"
|
|
10
|
+
import { fetchUrl } from "@jsenv/core/src/internal/fetchUrl.js"
|
|
11
|
+
import { getDefaultImportMap } from "@jsenv/core/src/internal/import-resolution/importmap-default.js"
|
|
12
|
+
import {
|
|
13
|
+
setJavaScriptSourceMappingUrl,
|
|
14
|
+
sourcemapToBase64Url,
|
|
15
|
+
} from "../sourceMappingURLUtils.js"
|
|
16
|
+
import { transformJs } from "./js-compilation-service/transformJs.js"
|
|
17
|
+
import {
|
|
18
|
+
parseHtmlString,
|
|
19
|
+
parseHtmlAstRessources,
|
|
20
|
+
collectHtmlDependenciesFromAst,
|
|
21
|
+
manipulateHtmlAst,
|
|
22
|
+
stringifyHtmlAst,
|
|
23
|
+
getHtmlNodeAttributeByName,
|
|
24
|
+
getHtmlNodeTextNode,
|
|
25
|
+
getUniqueNameForInlineHtmlNode,
|
|
26
|
+
removeHtmlNodeAttribute,
|
|
27
|
+
setHtmlNodeText,
|
|
28
|
+
visitHtmlAst,
|
|
29
|
+
replaceHtmlNode,
|
|
30
|
+
} from "./compileHtml.js"
|
|
31
|
+
import { generateCompiledFileAssetUrl } from "./compile-directory/compile-asset.js"
|
|
32
|
+
|
|
33
|
+
export const compileHtml = async ({
|
|
34
|
+
// cancellationToken,
|
|
35
|
+
logger,
|
|
36
|
+
// request,
|
|
37
|
+
code,
|
|
38
|
+
url,
|
|
39
|
+
compiledUrl,
|
|
40
|
+
projectDirectoryUrl,
|
|
41
|
+
outDirectoryRelativeUrl,
|
|
42
|
+
compileId,
|
|
43
|
+
|
|
44
|
+
transformTopLevelAwait,
|
|
45
|
+
moduleOutFormat,
|
|
46
|
+
importMetaFormat,
|
|
47
|
+
babelPluginMap,
|
|
48
|
+
|
|
49
|
+
sourcemapMethod,
|
|
50
|
+
|
|
51
|
+
jsenvScriptInjection = true,
|
|
52
|
+
jsenvToolbarInjection,
|
|
53
|
+
}) => {
|
|
54
|
+
const jsenvBrowserBuildUrlRelativeToProject = urlToRelativeUrl(
|
|
55
|
+
jsenvBrowserSystemFileInfo.jsenvBuildUrl,
|
|
56
|
+
projectDirectoryUrl,
|
|
57
|
+
)
|
|
58
|
+
const jsenvToolbarInjectorBuildRelativeUrlForProject = urlToRelativeUrl(
|
|
59
|
+
jsenvToolbarInjectorFileInfo.jsenvBuildUrl,
|
|
60
|
+
projectDirectoryUrl,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
// ideally we should try/catch html syntax error
|
|
64
|
+
const htmlAst = parseHtmlString(code)
|
|
65
|
+
|
|
66
|
+
if (moduleOutFormat !== "esmodule") {
|
|
67
|
+
await mutateRessourceHints(htmlAst)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
manipulateHtmlAst(htmlAst, {
|
|
71
|
+
scriptInjections: [
|
|
72
|
+
...(url !== jsenvToolbarHtmlFileInfo.url && jsenvScriptInjection
|
|
73
|
+
? [
|
|
74
|
+
{
|
|
75
|
+
src: `/${jsenvBrowserBuildUrlRelativeToProject}`,
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
: []),
|
|
79
|
+
...(url !== jsenvToolbarHtmlFileInfo.url && jsenvToolbarInjection
|
|
80
|
+
? [
|
|
81
|
+
{
|
|
82
|
+
src: `/${jsenvToolbarInjectorBuildRelativeUrlForProject}`,
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
: []),
|
|
86
|
+
],
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const { scripts } = parseHtmlAstRessources(htmlAst)
|
|
90
|
+
const htmlDependencies = collectHtmlDependenciesFromAst(htmlAst)
|
|
91
|
+
|
|
92
|
+
let hasImportmap = false
|
|
93
|
+
const inlineScriptsContentMap = {}
|
|
94
|
+
const importmapsToInline = []
|
|
95
|
+
scripts.forEach((script) => {
|
|
96
|
+
const typeAttribute = getHtmlNodeAttributeByName(script, "type")
|
|
97
|
+
const srcAttribute = getHtmlNodeAttributeByName(script, "src")
|
|
98
|
+
|
|
99
|
+
// importmap
|
|
100
|
+
if (typeAttribute && typeAttribute.value === "importmap") {
|
|
101
|
+
hasImportmap = true
|
|
102
|
+
|
|
103
|
+
if (srcAttribute) {
|
|
104
|
+
if (moduleOutFormat === "systemjs") {
|
|
105
|
+
typeAttribute.value = "jsenv-importmap"
|
|
106
|
+
return // no need to inline
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// we force inline because browsers supporting importmap supports only when they are inline
|
|
110
|
+
importmapsToInline.push({
|
|
111
|
+
script,
|
|
112
|
+
src: srcAttribute.value,
|
|
113
|
+
})
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const defaultImportMap = getDefaultImportMap({
|
|
118
|
+
importMapFileUrl: compiledUrl,
|
|
119
|
+
projectDirectoryUrl,
|
|
120
|
+
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${compileId}/`,
|
|
121
|
+
})
|
|
122
|
+
const inlineImportMap = JSON.parse(getHtmlNodeTextNode(script).value)
|
|
123
|
+
const mappings = composeTwoImportMaps(defaultImportMap, inlineImportMap)
|
|
124
|
+
if (moduleOutFormat === "systemjs") {
|
|
125
|
+
typeAttribute.value = "jsenv-importmap"
|
|
126
|
+
}
|
|
127
|
+
setHtmlNodeText(script, JSON.stringify(mappings, null, " "))
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// remote module script
|
|
132
|
+
if (typeAttribute && typeAttribute.value === "module" && srcAttribute) {
|
|
133
|
+
if (moduleOutFormat === "systemjs") {
|
|
134
|
+
removeHtmlNodeAttribute(script, typeAttribute)
|
|
135
|
+
}
|
|
136
|
+
removeHtmlNodeAttribute(script, srcAttribute)
|
|
137
|
+
const src = srcAttribute.value
|
|
138
|
+
const jsenvMethod =
|
|
139
|
+
moduleOutFormat === "systemjs"
|
|
140
|
+
? "executeFileUsingSystemJs"
|
|
141
|
+
: "executeFileUsingDynamicImport"
|
|
142
|
+
setHtmlNodeText(
|
|
143
|
+
script,
|
|
144
|
+
`window.__jsenv__.${jsenvMethod}(${JSON.stringify(src)})`,
|
|
145
|
+
)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// inline module script
|
|
150
|
+
const textNode = getHtmlNodeTextNode(script)
|
|
151
|
+
if (typeAttribute && typeAttribute.value === "module" && textNode) {
|
|
152
|
+
if (moduleOutFormat === "systemjs") {
|
|
153
|
+
removeHtmlNodeAttribute(script, typeAttribute)
|
|
154
|
+
}
|
|
155
|
+
removeHtmlNodeAttribute(script, srcAttribute)
|
|
156
|
+
const scriptAssetUrl = generateCompiledFileAssetUrl(
|
|
157
|
+
compiledUrl,
|
|
158
|
+
getUniqueNameForInlineHtmlNode(script, scripts, `[id].js`),
|
|
159
|
+
)
|
|
160
|
+
const specifier = `./${urlToRelativeUrl(scriptAssetUrl, compiledUrl)}`
|
|
161
|
+
inlineScriptsContentMap[specifier] = textNode.value
|
|
162
|
+
const jsenvMethod =
|
|
163
|
+
moduleOutFormat === "systemjs"
|
|
164
|
+
? "executeFileUsingSystemJs"
|
|
165
|
+
: "executeFileUsingDynamicImport"
|
|
166
|
+
setHtmlNodeText(
|
|
167
|
+
script,
|
|
168
|
+
`window.__jsenv__.${jsenvMethod}(${JSON.stringify(specifier)})`,
|
|
169
|
+
)
|
|
170
|
+
htmlDependencies.push({
|
|
171
|
+
htmlNode: script,
|
|
172
|
+
specifier,
|
|
173
|
+
})
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
if (hasImportmap === false) {
|
|
179
|
+
const defaultImportMap = getDefaultImportMap({
|
|
180
|
+
importMapFileUrl: compiledUrl,
|
|
181
|
+
projectDirectoryUrl,
|
|
182
|
+
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${compileId}/`,
|
|
183
|
+
})
|
|
184
|
+
manipulateHtmlAst(htmlAst, {
|
|
185
|
+
scriptInjections: [
|
|
186
|
+
{
|
|
187
|
+
type:
|
|
188
|
+
moduleOutFormat === "systemjs" ? "jsenv-importmap" : "importmap",
|
|
189
|
+
// in case there is no importmap, force the presence
|
|
190
|
+
// so that '@jsenv/core/' are still remapped
|
|
191
|
+
text: JSON.stringify(defaultImportMap, null, " "),
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
await Promise.all(
|
|
198
|
+
importmapsToInline.map(async ({ script, src }) => {
|
|
199
|
+
const importMapUrl = resolveUrl(src, url)
|
|
200
|
+
const importMapResponse = await fetchUrl(importMapUrl)
|
|
201
|
+
if (importMapResponse.status !== 200) {
|
|
202
|
+
logger.warn(
|
|
203
|
+
createDetailedMessage(
|
|
204
|
+
importMapResponse.status === 404
|
|
205
|
+
? `Cannot inline importmap script because file cannot be found.`
|
|
206
|
+
: `Cannot inline importmap script due to unexpected response status (${importMapResponse.status}).`,
|
|
207
|
+
{
|
|
208
|
+
"importmap script src": src,
|
|
209
|
+
"importmap url": importMapUrl,
|
|
210
|
+
"html url": url,
|
|
211
|
+
},
|
|
212
|
+
),
|
|
213
|
+
)
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const importMapContent = await importMapResponse.json()
|
|
218
|
+
const importMapInlined = moveImportMap(
|
|
219
|
+
importMapContent,
|
|
220
|
+
importMapUrl,
|
|
221
|
+
url,
|
|
222
|
+
)
|
|
223
|
+
replaceHtmlNode(
|
|
224
|
+
script,
|
|
225
|
+
`<script type="importmap">${JSON.stringify(
|
|
226
|
+
importMapInlined,
|
|
227
|
+
null,
|
|
228
|
+
" ",
|
|
229
|
+
)}</script>`,
|
|
230
|
+
{
|
|
231
|
+
attributesToIgnore: ["src"],
|
|
232
|
+
},
|
|
233
|
+
)
|
|
234
|
+
}),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
const htmlAfterTransformation = stringifyHtmlAst(htmlAst)
|
|
238
|
+
|
|
239
|
+
let assets = []
|
|
240
|
+
let assetsContent = []
|
|
241
|
+
await Promise.all(
|
|
242
|
+
Object.keys(inlineScriptsContentMap).map(async (scriptSrc) => {
|
|
243
|
+
const scriptAssetUrl = resolveUrl(scriptSrc, compiledUrl)
|
|
244
|
+
const scriptBasename = urlToRelativeUrl(scriptAssetUrl, compiledUrl)
|
|
245
|
+
const scriptOriginalFileUrl = resolveUrl(scriptBasename, url)
|
|
246
|
+
const scriptCompiledFileUrl = resolveUrl(scriptBasename, compiledUrl)
|
|
247
|
+
|
|
248
|
+
const scriptBeforeCompilation = inlineScriptsContentMap[scriptSrc]
|
|
249
|
+
let scriptTransformResult
|
|
250
|
+
try {
|
|
251
|
+
scriptTransformResult = await transformJs({
|
|
252
|
+
code: scriptBeforeCompilation,
|
|
253
|
+
url: scriptOriginalFileUrl,
|
|
254
|
+
compiledUrl: scriptCompiledFileUrl,
|
|
255
|
+
projectDirectoryUrl,
|
|
256
|
+
|
|
257
|
+
transformTopLevelAwait,
|
|
258
|
+
moduleOutFormat,
|
|
259
|
+
importMetaFormat,
|
|
260
|
+
babelPluginMap,
|
|
261
|
+
})
|
|
262
|
+
} catch (e) {
|
|
263
|
+
// If there is a syntax error in inline script
|
|
264
|
+
// we put the raw script without transformation.
|
|
265
|
+
// when systemjs will try to instantiate to script it
|
|
266
|
+
// will re-throw this syntax error.
|
|
267
|
+
// Thanks to this we see the syntax error in the
|
|
268
|
+
// document and livereloading still works
|
|
269
|
+
// because we gracefully handle this error
|
|
270
|
+
if (e.code === "PARSE_ERROR") {
|
|
271
|
+
const code = scriptBeforeCompilation
|
|
272
|
+
assets = [...assets, scriptAssetUrl]
|
|
273
|
+
assetsContent = [...assetsContent, code]
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
throw e
|
|
277
|
+
}
|
|
278
|
+
const sourcemapFileUrl = resolveUrl(
|
|
279
|
+
`${scriptBasename}.map`,
|
|
280
|
+
scriptCompiledFileUrl,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
let { code, map } = scriptTransformResult
|
|
284
|
+
const sourcemapFileRelativePathForModule = urlToRelativeUrl(
|
|
285
|
+
sourcemapFileUrl,
|
|
286
|
+
compiledUrl,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
if (sourcemapMethod === "inline") {
|
|
290
|
+
code = setJavaScriptSourceMappingUrl(code, sourcemapToBase64Url(map))
|
|
291
|
+
} else {
|
|
292
|
+
// TODO: respect "sourcemapMethod" parameter
|
|
293
|
+
code = setJavaScriptSourceMappingUrl(
|
|
294
|
+
code,
|
|
295
|
+
sourcemapFileRelativePathForModule,
|
|
296
|
+
)
|
|
297
|
+
assets = [...assets, scriptAssetUrl, sourcemapFileUrl]
|
|
298
|
+
assetsContent = [
|
|
299
|
+
...assetsContent,
|
|
300
|
+
code,
|
|
301
|
+
JSON.stringify(map, null, " "),
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
contentType: "text/html",
|
|
309
|
+
compiledSource: htmlAfterTransformation,
|
|
310
|
+
sources: [url],
|
|
311
|
+
sourcesContent: [code],
|
|
312
|
+
assets,
|
|
313
|
+
assetsContent,
|
|
314
|
+
dependencies: htmlDependencies.map(({ specifier }) => {
|
|
315
|
+
return specifier
|
|
316
|
+
}),
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// transform <link type="modulepreload"> into <link type="preload">
|
|
321
|
+
const mutateRessourceHints = async (htmlAst) => {
|
|
322
|
+
const ressourceHints = []
|
|
323
|
+
visitHtmlAst(htmlAst, (htmlNode) => {
|
|
324
|
+
if (htmlNode.nodeName !== "link") return
|
|
325
|
+
const relAttribute = getHtmlNodeAttributeByName(htmlNode, "rel")
|
|
326
|
+
const rel = relAttribute ? relAttribute.value : ""
|
|
327
|
+
const isRessourceHint = [
|
|
328
|
+
"preconnect",
|
|
329
|
+
"dns-prefetch",
|
|
330
|
+
"prefetch",
|
|
331
|
+
"preload",
|
|
332
|
+
"modulepreload",
|
|
333
|
+
].includes(rel)
|
|
334
|
+
if (!isRessourceHint) return
|
|
335
|
+
|
|
336
|
+
ressourceHints.push({ rel, htmlNode })
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
const mutations = []
|
|
340
|
+
await Promise.all(
|
|
341
|
+
ressourceHints.map(async (ressourceHint) => {
|
|
342
|
+
const hrefAttribute = getHtmlNodeAttributeByName(
|
|
343
|
+
ressourceHint.htmlNode,
|
|
344
|
+
"href",
|
|
345
|
+
)
|
|
346
|
+
const href = hrefAttribute ? hrefAttribute.value : ""
|
|
347
|
+
if (!href) return
|
|
348
|
+
|
|
349
|
+
// - "modulepreload" -> "preload" because it's now regular js script
|
|
350
|
+
const asAttribute = getHtmlNodeAttributeByName(
|
|
351
|
+
ressourceHint.htmlNode,
|
|
352
|
+
"as",
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
if (ressourceHint.rel === "modulepreload") {
|
|
356
|
+
mutations.push(() => {
|
|
357
|
+
replaceHtmlNode(
|
|
358
|
+
ressourceHint.htmlNode,
|
|
359
|
+
`<link rel="preload" as="script" />`,
|
|
360
|
+
)
|
|
361
|
+
})
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (asAttribute && asAttribute.value === "script") {
|
|
366
|
+
mutations.push(() => {
|
|
367
|
+
replaceHtmlNode(ressourceHint.htmlNode, `<link as="script" />`)
|
|
368
|
+
})
|
|
369
|
+
return
|
|
370
|
+
}
|
|
371
|
+
}),
|
|
372
|
+
)
|
|
373
|
+
mutations.forEach((mutation) => mutation())
|
|
374
|
+
}
|