@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
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
readFile,
|
|
5
5
|
ensureWindowsDriveLetter,
|
|
6
6
|
} from "@jsenv/filesystem"
|
|
7
|
+
|
|
7
8
|
import {
|
|
8
9
|
replaceBackSlashesWithSlashes,
|
|
9
10
|
startsWithWindowsDriveLetter,
|
|
@@ -20,7 +21,7 @@ import { testFilePresence } from "./compile-directory/fs-optimized-for-cache.js"
|
|
|
20
21
|
const isWindows = process.platform === "win32"
|
|
21
22
|
|
|
22
23
|
export const transformResultToCompilationResult = async (
|
|
23
|
-
{ code, map,
|
|
24
|
+
{ contentType, code, map, metadata = {} },
|
|
24
25
|
{
|
|
25
26
|
projectDirectoryUrl,
|
|
26
27
|
originalFileContent,
|
|
@@ -37,6 +38,9 @@ export const transformResultToCompilationResult = async (
|
|
|
37
38
|
sourcemapMethod = "comment", // "comment", "inline"
|
|
38
39
|
},
|
|
39
40
|
) => {
|
|
41
|
+
if (typeof contentType !== "string") {
|
|
42
|
+
throw new TypeError(`contentType must be a string, got ${contentType}`)
|
|
43
|
+
}
|
|
40
44
|
if (typeof projectDirectoryUrl !== "string") {
|
|
41
45
|
throw new TypeError(
|
|
42
46
|
`projectDirectoryUrl must be a string, got ${projectDirectoryUrl}`,
|
|
@@ -146,8 +150,9 @@ export const transformResultToCompilationResult = async (
|
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
return {
|
|
149
|
-
compiledSource: output,
|
|
150
153
|
contentType,
|
|
154
|
+
compiledSource: output,
|
|
155
|
+
sourcemap: map,
|
|
151
156
|
sources,
|
|
152
157
|
sourcesContent,
|
|
153
158
|
assets,
|
|
@@ -39,7 +39,7 @@ export const executePlan = async (
|
|
|
39
39
|
compileServerCanReadFromFilesystem,
|
|
40
40
|
compileServerCanWriteOnFilesystem,
|
|
41
41
|
babelPluginMap,
|
|
42
|
-
|
|
42
|
+
customCompilers,
|
|
43
43
|
runtimeSupport,
|
|
44
44
|
} = {},
|
|
45
45
|
) => {
|
|
@@ -78,7 +78,7 @@ export const executePlan = async (
|
|
|
78
78
|
compileServerCanWriteOnFilesystem,
|
|
79
79
|
keepProcessAlive: true, // to be sure it stays alive
|
|
80
80
|
babelPluginMap,
|
|
81
|
-
|
|
81
|
+
customCompilers,
|
|
82
82
|
runtimeSupport,
|
|
83
83
|
})
|
|
84
84
|
|
|
@@ -21,8 +21,7 @@ export const scanBrowserRuntimeFeatures = async ({
|
|
|
21
21
|
groupMap,
|
|
22
22
|
})
|
|
23
23
|
const groupInfo = groupMap[compileId]
|
|
24
|
-
const { inlineImportMapIntoHTML,
|
|
25
|
-
envJson
|
|
24
|
+
const { inlineImportMapIntoHTML, customCompilerPatterns } = envJson
|
|
26
25
|
|
|
27
26
|
const featuresReport = {
|
|
28
27
|
babelPluginRequiredNames: babelPluginRequiredNamesFromGroupInfo(groupInfo, {
|
|
@@ -32,16 +31,14 @@ export const scanBrowserRuntimeFeatures = async ({
|
|
|
32
31
|
failFastOnFeatureDetection,
|
|
33
32
|
groupInfo,
|
|
34
33
|
inlineImportMapIntoHTML,
|
|
35
|
-
|
|
34
|
+
customCompilerPatterns,
|
|
36
35
|
coverageInstrumentationRequired,
|
|
37
36
|
})),
|
|
38
|
-
|
|
39
|
-
convertPatterns,
|
|
37
|
+
customCompilerPatterns,
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
const canAvoidCompilation =
|
|
43
|
-
featuresReport.
|
|
44
|
-
featuresReport.customCompilerNames.length === 0 &&
|
|
41
|
+
featuresReport.customCompilerPatterns.length === 0 &&
|
|
45
42
|
featuresReport.jsenvPluginRequiredNames.length === 0 &&
|
|
46
43
|
featuresReport.babelPluginRequiredNames.length === 0 &&
|
|
47
44
|
featuresReport.importmapSupported &&
|
|
@@ -166,21 +166,13 @@ const getBrowserSupportMessage = ({
|
|
|
166
166
|
)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
const {
|
|
170
|
-
const
|
|
171
|
-
if (convertPatternCount === 0) {
|
|
172
|
-
// no need to talk about something unused
|
|
173
|
-
} else {
|
|
174
|
-
parts.push(`convertMap is used with the following keys: ${convertPatterns}`)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const { customCompilerNames } = featuresReport
|
|
178
|
-
const customCompilerCount = customCompilerNames.length
|
|
169
|
+
const { customCompilerPatterns } = featuresReport
|
|
170
|
+
const customCompilerCount = customCompilerPatterns.length
|
|
179
171
|
if (customCompilerCount === 0) {
|
|
180
172
|
// no need to talk about something unused
|
|
181
173
|
} else {
|
|
182
174
|
parts.push(
|
|
183
|
-
`${customCompilerCount} custom compilers enabled: ${
|
|
175
|
+
`${customCompilerCount} custom compilers enabled: ${customCompilerPatterns}`,
|
|
184
176
|
)
|
|
185
177
|
}
|
|
186
178
|
|
package/src/startExploring.js
CHANGED
|
@@ -44,7 +44,6 @@ export const startExploring = async ({
|
|
|
44
44
|
keepProcessAlive = true,
|
|
45
45
|
|
|
46
46
|
babelPluginMap,
|
|
47
|
-
convertMap,
|
|
48
47
|
runtimeSupportDuringDev = jsenvRuntimeSupportDuringDev,
|
|
49
48
|
compileServerLogLevel,
|
|
50
49
|
compileServerCanReadFromFilesystem,
|
|
@@ -116,7 +115,6 @@ export const startExploring = async ({
|
|
|
116
115
|
compileServerCertificate,
|
|
117
116
|
compileServerPrivateKey,
|
|
118
117
|
babelPluginMap,
|
|
119
|
-
convertMap,
|
|
120
118
|
runtimeSupport: runtimeSupportDuringDev,
|
|
121
119
|
livereloadWatchConfig,
|
|
122
120
|
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const textToJavaScriptModule = async ({ code, url }) => {
|
|
2
|
+
return {
|
|
3
|
+
compiledSource: `export default "${JSON.stringify(code)}"`,
|
|
4
|
+
contentType: "application/javascript",
|
|
5
|
+
sources: [url],
|
|
6
|
+
sourcesContent: [code],
|
|
7
|
+
assets: [],
|
|
8
|
+
assetsContent: [],
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { urlToRelativeUrl, urlIsInsideOf } from "@jsenv/filesystem"
|
|
10
|
-
import { composeTwoImportMaps } from "@jsenv/import-map"
|
|
11
|
-
import { jsenvCoreDirectoryUrl } from "../jsenvCoreDirectoryUrl.js"
|
|
12
|
-
|
|
13
|
-
export const transformImportmap = async (
|
|
14
|
-
importmapBeforeTransformation,
|
|
15
|
-
{ originalFileUrl },
|
|
16
|
-
) => {
|
|
17
|
-
const importMapForProject = JSON.parse(importmapBeforeTransformation)
|
|
18
|
-
|
|
19
|
-
const topLevelRemappingForJsenvCore = {
|
|
20
|
-
"@jsenv/core/": urlToRelativeUrlRemapping(
|
|
21
|
-
jsenvCoreDirectoryUrl,
|
|
22
|
-
originalFileUrl,
|
|
23
|
-
),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const importmapForSelfImport = {
|
|
27
|
-
imports: topLevelRemappingForJsenvCore,
|
|
28
|
-
scopes: generateJsenvCoreScopes({
|
|
29
|
-
importMapForProject,
|
|
30
|
-
topLevelRemappingForJsenvCore,
|
|
31
|
-
}),
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const importMap = [importmapForSelfImport, importMapForProject].reduce(
|
|
35
|
-
(previous, current) => composeTwoImportMaps(previous, current),
|
|
36
|
-
{},
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
const scopes = importMap.scopes || {}
|
|
40
|
-
const projectTopLevelMappings = importMapForProject.imports || {}
|
|
41
|
-
Object.keys(scopes).forEach((scope) => {
|
|
42
|
-
const scopedMappings = scopes[scope]
|
|
43
|
-
Object.keys(projectTopLevelMappings).forEach((key) => {
|
|
44
|
-
if (key in scopedMappings) {
|
|
45
|
-
scopedMappings[key] = projectTopLevelMappings[key]
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
compiledSource: JSON.stringify(importMap, null, " "),
|
|
52
|
-
contentType: "application/importmap+json",
|
|
53
|
-
sources: [originalFileUrl],
|
|
54
|
-
sourcesContent: [importmapBeforeTransformation],
|
|
55
|
-
assets: [],
|
|
56
|
-
assetsContent: [],
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// this function just here to ensure relative urls starts with './'
|
|
61
|
-
// so that importmap do not consider them as bare specifiers
|
|
62
|
-
const urlToRelativeUrlRemapping = (url, baseUrl) => {
|
|
63
|
-
const relativeUrl = urlToRelativeUrl(url, baseUrl)
|
|
64
|
-
|
|
65
|
-
if (urlIsInsideOf(url, baseUrl)) {
|
|
66
|
-
if (relativeUrl.startsWith("../")) return relativeUrl
|
|
67
|
-
if (relativeUrl.startsWith("./")) return relativeUrl
|
|
68
|
-
return `./${relativeUrl}`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return relativeUrl
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const generateJsenvCoreScopes = ({
|
|
75
|
-
importMapForProject,
|
|
76
|
-
topLevelRemappingForJsenvCore,
|
|
77
|
-
}) => {
|
|
78
|
-
const { scopes } = importMapForProject
|
|
79
|
-
|
|
80
|
-
if (!scopes) {
|
|
81
|
-
return undefined
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// I must ensure jsenvCoreImports wins by default in every scope
|
|
85
|
-
// because scope may contains stuff like
|
|
86
|
-
// "/": "/"
|
|
87
|
-
// "/": "/folder/"
|
|
88
|
-
// to achieve this, we set jsenvCoreImports into every scope
|
|
89
|
-
const scopesForJsenvCore = {}
|
|
90
|
-
Object.keys(scopes).forEach((scopeKey) => {
|
|
91
|
-
scopesForJsenvCore[scopeKey] = topLevelRemappingForJsenvCore
|
|
92
|
-
})
|
|
93
|
-
return scopesForJsenvCore
|
|
94
|
-
}
|