@jsenv/core 20.3.2 → 21.0.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/.DS_Store +0 -0
- package/dist/jsenv_compile_proxy.js +4 -6
- package/dist/jsenv_compile_proxy.js.map +3 -4
- package/dist/jsenv_exploring_redirector.js +4 -6
- package/dist/jsenv_exploring_redirector.js.map +3 -4
- package/dist/jsenv_toolbar.js +7 -16
- package/dist/jsenv_toolbar.js.map +4 -6
- package/{LICENSE → license} +0 -0
- package/main.js +2 -1
- package/package.json +3 -7
- package/readme.md +8 -8
- package/src/{convertCommonJsWithRollup.js → commonJsToJavaScriptModule.js} +23 -5
- package/src/execute.js +2 -2
- package/src/executeTestPlan.js +2 -2
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +17 -14
- package/src/internal/compiling/createCompiledFileService.js +125 -64
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +1 -1
- package/src/internal/compiling/js-compilation-service/transformJs.js +1 -71
- package/src/internal/compiling/jsenvCompilerForHtml.js +146 -187
- package/src/internal/compiling/jsenvCompilerForImportmap.js +79 -13
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +33 -70
- package/src/internal/compiling/startCompileServer.js +1 -7
- package/src/internal/compiling/transformResultToCompilationResult.js +7 -2
- package/src/internal/executing/executePlan.js +2 -2
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +4 -7
- package/src/internal/toolbar/compilation/toolbar.compilation.js +3 -11
- package/src/startExploring.js +0 -2
- package/src/textToJavaScriptModule.js +10 -0
- package/src/internal/compiling/transformImportmap.js +0 -94
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { urlToContentType } from "@jsenv/server"
|
|
2
1
|
import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -9,7 +8,6 @@ import {
|
|
|
9
8
|
import { getDefaultImportMap } from "@jsenv/core/src/internal/import-resolution/importmap-default.js"
|
|
10
9
|
import { setJavaScriptSourceMappingUrl } from "../sourceMappingURLUtils.js"
|
|
11
10
|
import { transformJs } from "./js-compilation-service/transformJs.js"
|
|
12
|
-
import { compileIdToBabelPluginMap } from "./jsenvCompilerForJavaScript.js"
|
|
13
11
|
import {
|
|
14
12
|
parseHtmlString,
|
|
15
13
|
parseHtmlAstRessources,
|
|
@@ -25,30 +23,24 @@ import {
|
|
|
25
23
|
} from "./compileHtml.js"
|
|
26
24
|
import { generateCompiledFileAssetUrl } from "./compile-directory/compile-asset.js"
|
|
27
25
|
|
|
28
|
-
const
|
|
26
|
+
export const compileHtml = async ({
|
|
29
27
|
// cancellationToken,
|
|
30
28
|
// logger,
|
|
31
29
|
// request,
|
|
32
|
-
|
|
30
|
+
code,
|
|
31
|
+
url,
|
|
32
|
+
compiledUrl,
|
|
33
33
|
projectDirectoryUrl,
|
|
34
34
|
outDirectoryRelativeUrl,
|
|
35
|
-
originalFileUrl,
|
|
36
|
-
compiledFileUrl,
|
|
37
35
|
compileId,
|
|
38
|
-
|
|
39
|
-
babelPluginMap,
|
|
40
|
-
convertMap,
|
|
36
|
+
|
|
41
37
|
transformTopLevelAwait,
|
|
42
38
|
moduleOutFormat,
|
|
43
39
|
importMetaFormat,
|
|
40
|
+
babelPluginMap,
|
|
44
41
|
|
|
45
42
|
jsenvToolbarInjection,
|
|
46
43
|
}) => {
|
|
47
|
-
const contentType = urlToContentType(originalFileUrl)
|
|
48
|
-
if (contentType !== "text/html") {
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
44
|
const jsenvBrowserBuildUrlRelativeToProject = urlToRelativeUrl(
|
|
53
45
|
jsenvBrowserSystemFileInfo.jsenvBuildUrl,
|
|
54
46
|
projectDirectoryUrl,
|
|
@@ -58,189 +50,160 @@ const compileHtmlFile = ({
|
|
|
58
50
|
projectDirectoryUrl,
|
|
59
51
|
)
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// ideally we should try/catch html syntax error
|
|
64
|
-
const htmlAst = parseHtmlString(htmlBeforeCompilation)
|
|
53
|
+
// ideally we should try/catch html syntax error
|
|
54
|
+
const htmlAst = parseHtmlString(code)
|
|
65
55
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
if (moduleOutFormat !== "esmodule") {
|
|
57
|
+
await mutateRessourceHints(htmlAst)
|
|
58
|
+
}
|
|
69
59
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})
|
|
60
|
+
manipulateHtmlAst(htmlAst, {
|
|
61
|
+
scriptInjections: [
|
|
62
|
+
{
|
|
63
|
+
src: `/${jsenvBrowserBuildUrlRelativeToProject}`,
|
|
64
|
+
},
|
|
65
|
+
...(jsenvToolbarInjection && url !== jsenvToolbarHtmlFileInfo.url
|
|
66
|
+
? [
|
|
67
|
+
{
|
|
68
|
+
src: `/${jsenvToolbarInjectorBuildRelativeUrlForProject}`,
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
: []),
|
|
72
|
+
],
|
|
73
|
+
})
|
|
85
74
|
|
|
86
|
-
|
|
75
|
+
const { scripts } = parseHtmlAstRessources(htmlAst)
|
|
87
76
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
let hasImportmap = false
|
|
78
|
+
const inlineScriptsContentMap = {}
|
|
79
|
+
scripts.forEach((script) => {
|
|
80
|
+
const typeAttribute = getHtmlNodeAttributeByName(script, "type")
|
|
81
|
+
const srcAttribute = getHtmlNodeAttributeByName(script, "src")
|
|
93
82
|
|
|
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
|
-
getUniqueNameForInlineHtmlNode(script, scripts, `[id].js`),
|
|
121
|
-
)
|
|
122
|
-
const specifier = `./${urlToRelativeUrl(
|
|
123
|
-
scriptAssetUrl,
|
|
124
|
-
compiledFileUrl,
|
|
125
|
-
)}`
|
|
126
|
-
inlineScriptsContentMap[specifier] = textNode.value
|
|
83
|
+
// remote
|
|
84
|
+
if (typeAttribute && typeAttribute.value === "importmap" && srcAttribute) {
|
|
85
|
+
hasImportmap = true
|
|
86
|
+
typeAttribute.value = "jsenv-importmap"
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if (typeAttribute && typeAttribute.value === "module" && srcAttribute) {
|
|
90
|
+
removeHtmlNodeAttribute(script, typeAttribute)
|
|
91
|
+
removeHtmlNodeAttribute(script, srcAttribute)
|
|
92
|
+
setHtmlNodeText(
|
|
93
|
+
script,
|
|
94
|
+
`window.__jsenv__.executeFileUsingSystemJs(${JSON.stringify(
|
|
95
|
+
srcAttribute.value,
|
|
96
|
+
)})`,
|
|
97
|
+
)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
// inline
|
|
101
|
+
const textNode = getHtmlNodeTextNode(script)
|
|
102
|
+
if (typeAttribute && typeAttribute.value === "module" && textNode) {
|
|
103
|
+
const scriptAssetUrl = generateCompiledFileAssetUrl(
|
|
104
|
+
compiledUrl,
|
|
105
|
+
getUniqueNameForInlineHtmlNode(script, scripts, `[id].js`),
|
|
106
|
+
)
|
|
107
|
+
const specifier = `./${urlToRelativeUrl(scriptAssetUrl, compiledUrl)}`
|
|
108
|
+
inlineScriptsContentMap[specifier] = textNode.value
|
|
127
109
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
110
|
+
removeHtmlNodeAttribute(script, typeAttribute)
|
|
111
|
+
removeHtmlNodeAttribute(script, srcAttribute)
|
|
112
|
+
setHtmlNodeText(
|
|
113
|
+
script,
|
|
114
|
+
`window.__jsenv__.executeFileUsingSystemJs(${JSON.stringify(
|
|
115
|
+
specifier,
|
|
116
|
+
)})`,
|
|
117
|
+
)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
if (hasImportmap === false) {
|
|
122
|
+
const defaultImportMap = getDefaultImportMap({
|
|
123
|
+
importMapFileUrl: compiledUrl,
|
|
124
|
+
projectDirectoryUrl,
|
|
125
|
+
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${compileId}/`,
|
|
126
|
+
})
|
|
145
127
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
128
|
+
manipulateHtmlAst(htmlAst, {
|
|
129
|
+
scriptInjections: [
|
|
130
|
+
{
|
|
131
|
+
type: "jsenv-importmap",
|
|
132
|
+
// in case there is no importmap, force the presence
|
|
133
|
+
// so that '@jsenv/core/' are still remapped
|
|
134
|
+
text: JSON.stringify(defaultImportMap, null, " "),
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
})
|
|
138
|
+
}
|
|
157
139
|
|
|
158
|
-
|
|
140
|
+
const htmlAfterTransformation = stringifyHtmlAst(htmlAst)
|
|
159
141
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
169
|
-
const scriptOriginalFileUrl = resolveUrl(
|
|
170
|
-
scriptBasename,
|
|
171
|
-
originalFileUrl,
|
|
172
|
-
)
|
|
173
|
-
const scriptAfterTransformFileUrl = resolveUrl(
|
|
174
|
-
scriptBasename,
|
|
175
|
-
compiledFileUrl,
|
|
176
|
-
)
|
|
142
|
+
let assets = []
|
|
143
|
+
let assetsContent = []
|
|
144
|
+
await Promise.all(
|
|
145
|
+
Object.keys(inlineScriptsContentMap).map(async (scriptSrc) => {
|
|
146
|
+
const scriptAssetUrl = resolveUrl(scriptSrc, compiledUrl)
|
|
147
|
+
const scriptBasename = urlToRelativeUrl(scriptAssetUrl, compiledUrl)
|
|
148
|
+
const scriptOriginalFileUrl = resolveUrl(scriptBasename, url)
|
|
149
|
+
const scriptCompiledFileUrl = resolveUrl(scriptBasename, compiledUrl)
|
|
177
150
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
151
|
+
const scriptBeforeCompilation = inlineScriptsContentMap[scriptSrc]
|
|
152
|
+
let scriptTransformResult
|
|
153
|
+
try {
|
|
154
|
+
scriptTransformResult = await transformJs({
|
|
155
|
+
code: scriptBeforeCompilation,
|
|
156
|
+
url: scriptOriginalFileUrl,
|
|
157
|
+
compiledUrl: scriptCompiledFileUrl,
|
|
158
|
+
projectDirectoryUrl,
|
|
186
159
|
|
|
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
|
-
const sourcemapFileUrl = resolveUrl(
|
|
213
|
-
`${scriptBasename}.map`,
|
|
214
|
-
scriptAfterTransformFileUrl,
|
|
215
|
-
)
|
|
160
|
+
transformTopLevelAwait,
|
|
161
|
+
moduleOutFormat,
|
|
162
|
+
importMetaFormat,
|
|
163
|
+
babelPluginMap,
|
|
164
|
+
})
|
|
165
|
+
} catch (e) {
|
|
166
|
+
// If there is a syntax error in inline script
|
|
167
|
+
// we put the raw script without transformation.
|
|
168
|
+
// when systemjs will try to instantiate to script it
|
|
169
|
+
// will re-throw this syntax error.
|
|
170
|
+
// Thanks to this we see the syntax error in the
|
|
171
|
+
// document and livereloading still works
|
|
172
|
+
// because we gracefully handle this error
|
|
173
|
+
if (e.code === "PARSE_ERROR") {
|
|
174
|
+
const code = scriptBeforeCompilation
|
|
175
|
+
assets = [...assets, scriptAssetUrl]
|
|
176
|
+
assetsContent = [...assetsContent, code]
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
throw e
|
|
180
|
+
}
|
|
181
|
+
const sourcemapFileUrl = resolveUrl(
|
|
182
|
+
`${scriptBasename}.map`,
|
|
183
|
+
scriptCompiledFileUrl,
|
|
184
|
+
)
|
|
216
185
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
)
|
|
226
|
-
assets = [...assets, scriptAssetUrl, sourcemapFileUrl]
|
|
227
|
-
assetsContent = [
|
|
228
|
-
...assetsContent,
|
|
229
|
-
code,
|
|
230
|
-
JSON.stringify(map, null, " "),
|
|
231
|
-
]
|
|
232
|
-
}),
|
|
186
|
+
let { code, map } = scriptTransformResult
|
|
187
|
+
const sourcemapFileRelativePathForModule = urlToRelativeUrl(
|
|
188
|
+
sourcemapFileUrl,
|
|
189
|
+
compiledUrl,
|
|
190
|
+
)
|
|
191
|
+
code = setJavaScriptSourceMappingUrl(
|
|
192
|
+
code,
|
|
193
|
+
sourcemapFileRelativePathForModule,
|
|
233
194
|
)
|
|
195
|
+
assets = [...assets, scriptAssetUrl, sourcemapFileUrl]
|
|
196
|
+
assetsContent = [...assetsContent, code, JSON.stringify(map, null, " ")]
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
234
199
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
},
|
|
200
|
+
return {
|
|
201
|
+
contentType: "text/html",
|
|
202
|
+
compiledSource: htmlAfterTransformation,
|
|
203
|
+
sources: [url],
|
|
204
|
+
sourcesContent: [code],
|
|
205
|
+
assets,
|
|
206
|
+
assetsContent,
|
|
244
207
|
}
|
|
245
208
|
}
|
|
246
209
|
|
|
@@ -304,7 +267,3 @@ const mutateRessourceHints = async (htmlAst) => {
|
|
|
304
267
|
)
|
|
305
268
|
mutations.forEach((mutation) => mutation())
|
|
306
269
|
}
|
|
307
|
-
|
|
308
|
-
export const jsenvCompilerForHtml = {
|
|
309
|
-
"jsenv-compiler-html": compileHtmlFile,
|
|
310
|
-
}
|
|
@@ -1,22 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* allows the following:
|
|
3
|
+
*
|
|
4
|
+
* import "@jsenv/core/helpers/regenerator-runtime/regenerator-runtime.js"
|
|
5
|
+
* -> searches a file inside @jsenv/core/*
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
import { urlToRelativeUrl, urlIsInsideOf } from "@jsenv/filesystem"
|
|
10
|
+
import { composeTwoImportMaps } from "@jsenv/import-map"
|
|
11
|
+
import { jsenvCoreDirectoryUrl } from "../jsenvCoreDirectoryUrl.js"
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
export const compileImportmap = async ({ code, url }) => {
|
|
14
|
+
const importMapForProject = JSON.parse(code)
|
|
15
|
+
|
|
16
|
+
const topLevelRemappingForJsenvCore = {
|
|
17
|
+
"@jsenv/core/": urlToRelativeUrlRemapping(jsenvCoreDirectoryUrl, url),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const importmapForSelfImport = {
|
|
21
|
+
imports: topLevelRemappingForJsenvCore,
|
|
22
|
+
scopes: generateJsenvCoreScopes({
|
|
23
|
+
importMapForProject,
|
|
24
|
+
topLevelRemappingForJsenvCore,
|
|
25
|
+
}),
|
|
9
26
|
}
|
|
10
27
|
|
|
28
|
+
const importMap = [importmapForSelfImport, importMapForProject].reduce(
|
|
29
|
+
(previous, current) => composeTwoImportMaps(previous, current),
|
|
30
|
+
{},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const scopes = importMap.scopes || {}
|
|
34
|
+
const projectTopLevelMappings = importMapForProject.imports || {}
|
|
35
|
+
Object.keys(scopes).forEach((scope) => {
|
|
36
|
+
const scopedMappings = scopes[scope]
|
|
37
|
+
Object.keys(projectTopLevelMappings).forEach((key) => {
|
|
38
|
+
if (key in scopedMappings) {
|
|
39
|
+
scopedMappings[key] = projectTopLevelMappings[key]
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
11
44
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
45
|
+
contentType: "application/importmap+json",
|
|
46
|
+
compiledSource: JSON.stringify(importMap, null, " "),
|
|
47
|
+
sources: [url],
|
|
48
|
+
sourcesContent: [code],
|
|
49
|
+
assets: [],
|
|
50
|
+
assetsContent: [],
|
|
17
51
|
}
|
|
18
52
|
}
|
|
19
53
|
|
|
20
|
-
|
|
21
|
-
|
|
54
|
+
// this function just here to ensure relative urls starts with './'
|
|
55
|
+
// so that importmap do not consider them as bare specifiers
|
|
56
|
+
const urlToRelativeUrlRemapping = (url, baseUrl) => {
|
|
57
|
+
const relativeUrl = urlToRelativeUrl(url, baseUrl)
|
|
58
|
+
|
|
59
|
+
if (urlIsInsideOf(url, baseUrl)) {
|
|
60
|
+
if (relativeUrl.startsWith("../")) return relativeUrl
|
|
61
|
+
if (relativeUrl.startsWith("./")) return relativeUrl
|
|
62
|
+
return `./${relativeUrl}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return relativeUrl
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const generateJsenvCoreScopes = ({
|
|
69
|
+
importMapForProject,
|
|
70
|
+
topLevelRemappingForJsenvCore,
|
|
71
|
+
}) => {
|
|
72
|
+
const { scopes } = importMapForProject
|
|
73
|
+
|
|
74
|
+
if (!scopes) {
|
|
75
|
+
return undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// I must ensure jsenvCoreImports wins by default in every scope
|
|
79
|
+
// because scope may contains stuff like
|
|
80
|
+
// "/": "/"
|
|
81
|
+
// "/": "/folder/"
|
|
82
|
+
// to achieve this, we set jsenvCoreImports into every scope
|
|
83
|
+
const scopesForJsenvCore = {}
|
|
84
|
+
Object.keys(scopes).forEach((scopeKey) => {
|
|
85
|
+
scopesForJsenvCore[scopeKey] = topLevelRemappingForJsenvCore
|
|
86
|
+
})
|
|
87
|
+
return scopesForJsenvCore
|
|
22
88
|
}
|
|
@@ -1,84 +1,47 @@
|
|
|
1
|
-
import { urlToContentType } from "@jsenv/server"
|
|
2
1
|
import { transformJs } from "./js-compilation-service/transformJs.js"
|
|
3
2
|
import { transformResultToCompilationResult } from "./transformResultToCompilationResult.js"
|
|
4
3
|
|
|
5
|
-
const
|
|
4
|
+
export const compileJavascript = async ({
|
|
5
|
+
code,
|
|
6
|
+
map,
|
|
7
|
+
url,
|
|
8
|
+
compiledUrl,
|
|
6
9
|
projectDirectoryUrl,
|
|
7
|
-
|
|
8
|
-
compiledFileUrl,
|
|
9
|
-
compileId,
|
|
10
|
-
groupMap,
|
|
10
|
+
|
|
11
11
|
babelPluginMap,
|
|
12
|
-
convertMap,
|
|
13
12
|
transformTopLevelAwait,
|
|
14
13
|
moduleOutFormat,
|
|
15
14
|
importMetaFormat,
|
|
16
|
-
|
|
15
|
+
|
|
17
16
|
sourcemapExcludeSources,
|
|
18
17
|
}) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
babelPluginMap,
|
|
39
|
-
}),
|
|
40
|
-
convertMap,
|
|
41
|
-
transformTopLevelAwait,
|
|
42
|
-
moduleOutFormat,
|
|
43
|
-
importMetaFormat,
|
|
44
|
-
})
|
|
45
|
-
const sourcemapFileUrl = `${compiledFileUrl}.map`
|
|
46
|
-
|
|
47
|
-
return transformResultToCompilationResult(transformResult, {
|
|
48
|
-
projectDirectoryUrl,
|
|
49
|
-
originalFileContent,
|
|
50
|
-
originalFileUrl,
|
|
51
|
-
compiledFileUrl,
|
|
52
|
-
sourcemapFileUrl,
|
|
53
|
-
sourcemapMethod: writeOnFilesystem ? "comment" : "inline",
|
|
54
|
-
sourcemapExcludeSources,
|
|
55
|
-
})
|
|
18
|
+
const transformResult = await transformJs({
|
|
19
|
+
code,
|
|
20
|
+
map,
|
|
21
|
+
url,
|
|
22
|
+
compiledUrl,
|
|
23
|
+
projectDirectoryUrl,
|
|
24
|
+
|
|
25
|
+
babelPluginMap,
|
|
26
|
+
transformTopLevelAwait,
|
|
27
|
+
moduleOutFormat,
|
|
28
|
+
importMetaFormat,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return transformResultToCompilationResult(
|
|
32
|
+
{
|
|
33
|
+
contentType: "application/javascript",
|
|
34
|
+
code: transformResult.code,
|
|
35
|
+
map: transformResult.map,
|
|
36
|
+
metadata: transformResult.metadata,
|
|
56
37
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const compileIdToBabelPluginMap = (
|
|
65
|
-
compileId,
|
|
66
|
-
{ babelPluginMap, groupMap },
|
|
67
|
-
) => {
|
|
68
|
-
const babelPluginMapForGroupMap = {}
|
|
69
|
-
|
|
70
|
-
const groupBabelPluginMap = {}
|
|
71
|
-
groupMap[compileId].babelPluginRequiredNameArray.forEach(
|
|
72
|
-
(babelPluginRequiredName) => {
|
|
73
|
-
if (babelPluginRequiredName in babelPluginMap) {
|
|
74
|
-
groupBabelPluginMap[babelPluginRequiredName] =
|
|
75
|
-
babelPluginMap[babelPluginRequiredName]
|
|
76
|
-
}
|
|
38
|
+
{
|
|
39
|
+
projectDirectoryUrl,
|
|
40
|
+
originalFileContent: code,
|
|
41
|
+
originalFileUrl: url,
|
|
42
|
+
compiledFileUrl: compiledUrl,
|
|
43
|
+
sourcemapFileUrl: `${compiledUrl}.map`,
|
|
44
|
+
sourcemapExcludeSources,
|
|
77
45
|
},
|
|
78
46
|
)
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
...groupBabelPluginMap,
|
|
82
|
-
...babelPluginMapForGroupMap,
|
|
83
|
-
}
|
|
84
47
|
}
|
|
@@ -72,7 +72,6 @@ export const startCompileServer = async ({
|
|
|
72
72
|
replaceGlobalDirname = false,
|
|
73
73
|
replaceMap = {},
|
|
74
74
|
babelPluginMap = jsenvBabelPluginMap,
|
|
75
|
-
convertMap = {},
|
|
76
75
|
customCompilers = {},
|
|
77
76
|
|
|
78
77
|
// options related to the server itself
|
|
@@ -201,7 +200,6 @@ export const startCompileServer = async ({
|
|
|
201
200
|
importDefaultExtension,
|
|
202
201
|
compileServerGroupMap,
|
|
203
202
|
env,
|
|
204
|
-
convertMap,
|
|
205
203
|
inlineImportMapIntoHTML,
|
|
206
204
|
customCompilers,
|
|
207
205
|
})
|
|
@@ -272,7 +270,6 @@ export const startCompileServer = async ({
|
|
|
272
270
|
transformTopLevelAwait,
|
|
273
271
|
groupMap: compileServerGroupMap,
|
|
274
272
|
babelPluginMap,
|
|
275
|
-
convertMap,
|
|
276
273
|
customCompilers,
|
|
277
274
|
moduleOutFormat,
|
|
278
275
|
importMetaFormat,
|
|
@@ -874,7 +871,6 @@ const createOutJSONFiles = ({
|
|
|
874
871
|
importDefaultExtension,
|
|
875
872
|
compileServerGroupMap,
|
|
876
873
|
babelPluginMap,
|
|
877
|
-
convertMap,
|
|
878
874
|
replaceProcessEnvNodeEnv,
|
|
879
875
|
processEnvNodeEnv,
|
|
880
876
|
env,
|
|
@@ -897,7 +893,6 @@ const createOutJSONFiles = ({
|
|
|
897
893
|
const outDirectoryMeta = {
|
|
898
894
|
jsenvCorePackageVersion,
|
|
899
895
|
babelPluginMap,
|
|
900
|
-
convertMap,
|
|
901
896
|
compileServerGroupMap,
|
|
902
897
|
replaceProcessEnvNodeEnv,
|
|
903
898
|
processEnvNodeEnv,
|
|
@@ -914,8 +909,7 @@ const createOutJSONFiles = ({
|
|
|
914
909
|
outDirectoryRelativeUrl,
|
|
915
910
|
importDefaultExtension,
|
|
916
911
|
inlineImportMapIntoHTML,
|
|
917
|
-
|
|
918
|
-
convertPatterns: Object.keys(convertMap),
|
|
912
|
+
customCompilerPatterns: Object.keys(customCompilers),
|
|
919
913
|
}
|
|
920
914
|
outJSONFiles.env = {
|
|
921
915
|
url: envOutFileUrl,
|