@jsenv/core 22.4.0 → 23.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/jsenv_browser_system.js +331 -256
- package/dist/jsenv_browser_system.js.map +55 -33
- package/dist/jsenv_compile_proxy.js +186 -108
- package/dist/jsenv_compile_proxy.js.map +48 -42
- package/dist/jsenv_exploring_redirector.js +148 -71
- package/dist/jsenv_exploring_redirector.js.map +26 -20
- package/dist/jsenv_toolbar.js +215 -104
- package/dist/jsenv_toolbar.js.map +39 -26
- package/helpers/new_stylesheet/new_stylesheet.js +411 -0
- package/{LICENSE → license} +0 -0
- package/main.js +8 -7
- package/package.json +23 -19
- package/readme.md +9 -6
- package/src/buildProject.js +3 -7
- package/src/execute.js +23 -10
- package/src/executeTestPlan.js +0 -4
- package/src/importUsingChildProcess.js +36 -32
- package/src/internal/{babel-plugin-replace-expressions.js → babel_plugin_replace_expressions.js} +0 -0
- package/src/internal/{babel-plugin-transform-import-meta.js → babel_plugin_transform_import_meta.js} +0 -0
- package/src/internal/browser-launcher/executeHtmlFile.js +6 -8
- package/src/internal/browser-launcher/jsenv-browser-system.js +3 -0
- package/src/internal/building/asset_url_versioning.js +5 -9
- package/src/internal/building/buildServiceWorker.js +6 -13
- package/src/internal/building/buildUsingRollup.js +41 -4
- package/src/internal/building/build_logs.js +11 -0
- package/src/internal/building/build_stats.js +7 -1
- package/src/internal/building/createJsenvRollupPlugin.js +402 -297
- package/src/internal/building/css/parseCssRessource.js +67 -71
- package/src/internal/building/css/parseCssUrls.js +2 -2
- package/src/internal/building/css/{postcss-urlhash-plugin.js → postcss_plugin_url_visitor.js} +43 -21
- package/src/internal/building/css/replaceCssUrls.js +17 -14
- package/src/internal/building/css_module.js +47 -0
- package/src/internal/building/html/parseHtmlRessource.js +44 -43
- package/src/internal/building/import_references.js +81 -0
- package/src/internal/building/importmap/parseImportmapRessource.js +5 -2
- package/src/internal/building/js/minifyJs.js +30 -3
- package/src/internal/building/js/parseJsRessource.js +70 -77
- package/src/internal/building/json/parseJsonRessource.js +3 -2
- package/src/internal/building/parseRessource.js +11 -8
- package/src/internal/building/parsing.utils.js +4 -15
- package/src/internal/building/ressource_builder.js +142 -114
- package/src/internal/building/ressource_builder_util.js +31 -18
- package/src/internal/building/{fetchSourcemap.js → sourcemap_loader.js} +29 -27
- package/src/internal/building/svg/parseSvgRessource.js +7 -3
- package/src/internal/building/url-versioning.js +2 -1
- package/src/internal/building/url_fetcher.js +79 -0
- package/src/internal/building/url_loader.js +267 -0
- package/src/internal/building/url_trace.js +1 -1
- package/src/internal/building/webmanifest/parseWebmanifestRessource.js +9 -4
- package/src/internal/compiling/{js-compilation-service/ensureGlobalThisImportBabelPlugin.js → babel_plugin_global_this_as_jsenv_import.js} +4 -2
- package/src/internal/compiling/babel_plugin_import_assertions.js +100 -0
- package/src/internal/compiling/babel_plugin_new_stylesheet_as_jsenv_import.js +109 -0
- package/src/internal/compiling/babel_plugin_transform_import_specifier.js +86 -0
- package/src/internal/compiling/babel_plugins.js +2 -0
- package/src/internal/compiling/createCompiledFileService.js +46 -15
- package/src/internal/compiling/html_source_file_service.js +2 -2
- package/src/internal/compiling/js-compilation-service/{transformBabelHelperToImportBabelPlugin.js → babel_plugin_babel_helpers_as_jsenv_imports.js} +1 -1
- package/src/internal/compiling/js-compilation-service/{ensureRegeneratorRuntimeImportBabelPlugin.js → babel_plugin_regenerator_runtime_as_jsenv_import.js} +1 -1
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +7 -16
- package/src/internal/compiling/js-compilation-service/transformJs.js +0 -2
- package/src/internal/compiling/jsenvCompilerForHtml.js +2 -7
- package/src/internal/compiling/rollup_plugin_commonjs_named_exports.js +2 -2
- package/src/internal/compiling/startCompileServer.js +11 -4
- package/src/internal/escapeTemplateStringSpecialCharacters.js +20 -0
- package/src/internal/executing/coverage/{babel-plugin-instrument.js → babel_plugin_instrument.js} +17 -6
- package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +1 -1
- package/src/internal/executing/executeConcurrently.js +5 -3
- package/src/internal/executing/executePlan.js +16 -2
- package/src/internal/executing/generateFileExecutionSteps.js +2 -1
- package/src/internal/executing/launchAndExecute.js +43 -69
- package/src/internal/executing/writeLog.js +25 -18
- package/src/internal/exploring/exploring.css +2 -1
- package/src/internal/exploring/exploring.redirector.js +0 -1
- package/src/internal/generateGroupMap/generateGroupMap.js +14 -10
- package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +30 -0
- package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -6
- package/src/internal/generateGroupMap/one_runtime_compat.js +9 -38
- package/src/internal/generateGroupMap/runtime_compat.js +9 -24
- package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -12
- package/src/internal/generateGroupMap/runtime_support.js +53 -0
- package/src/internal/jsenvInternalFiles.js +0 -1
- package/src/internal/node-launcher/createControllableNodeProcess.js +2 -3
- package/src/internal/response_validation.js +143 -0
- package/src/internal/runtime/createBrowserRuntime/createBrowserRuntime.js +8 -3
- package/src/internal/runtime/createBrowserRuntime/createBrowserSystem.js +165 -25
- package/src/internal/runtime/createBrowserRuntime/displayErrorInDocument.js +7 -6
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +124 -68
- package/src/internal/runtime/createNodeRuntime/createNodeRuntime.js +8 -86
- package/src/internal/runtime/createNodeRuntime/createNodeSystem.js +53 -9
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +115 -0
- package/src/internal/runtime/module-registration.js +86 -136
- package/src/internal/runtime/resolveGroup.js +2 -3
- package/src/internal/toolbar/compilation/toolbar.compilation.js +15 -17
- package/src/internal/toolbar/eventsource/toolbar.eventsource.js +35 -8
- package/src/internal/toolbar/toolbar.main.js +7 -4
- package/src/internal/url_utils.js +33 -0
- package/src/internal/url_utils.test.js +39 -0
- package/src/jsonToJavaScriptModule.js +12 -0
- package/src/launchBrowser.js +50 -34
- package/src/launchNode.js +6 -3
- package/src/requireUsingChildProcess.js +36 -32
- package/src/startExploring.js +25 -11
- package/src/internal/building/transformImportMetaUrlReferences.js +0 -71
- package/src/internal/runtime/resolveBrowserGroup.js +0 -5
- package/src/internal/runtime/resolveNodeGroup.js +0 -5
- package/src/internal/validateResponseStatusIsOk.js +0 -91
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md
|
|
2
|
+
// https://github.com/mjackson/babel-plugin-import-visitor
|
|
3
|
+
|
|
4
|
+
export const babelPluginTransformImportSpecifier = (
|
|
5
|
+
babel,
|
|
6
|
+
{ transformImportSpecifier = ({ specifier }) => specifier } = {},
|
|
7
|
+
) => {
|
|
8
|
+
return {
|
|
9
|
+
name: "transform-import-specifier",
|
|
10
|
+
|
|
11
|
+
// manipulateOptions(opts, parserOpts) {
|
|
12
|
+
// parserOpts.plugins.push(
|
|
13
|
+
// "dynamicImport",
|
|
14
|
+
// "exportDefaultFrom",
|
|
15
|
+
// "exportNamespaceFrom",
|
|
16
|
+
// "importMeta",
|
|
17
|
+
// )
|
|
18
|
+
// },
|
|
19
|
+
|
|
20
|
+
visitor: {
|
|
21
|
+
CallExpression: (path) => {
|
|
22
|
+
if (path.node.callee.type !== "Import") {
|
|
23
|
+
// Some other function call, not import();
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (path.node.arguments[0].type !== "StringLiteral") {
|
|
28
|
+
// Non-string argument, probably a variable or expression, e.g.
|
|
29
|
+
// import(moduleId)
|
|
30
|
+
// import('./' + moduleName)
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
transformStringLiteralAtPath(
|
|
35
|
+
path.get("arguments")[0],
|
|
36
|
+
transformImportSpecifier,
|
|
37
|
+
babel,
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
ExportAllDeclaration: (path) => {
|
|
42
|
+
transformStringLiteralAtPath(
|
|
43
|
+
path.get("source"),
|
|
44
|
+
transformImportSpecifier,
|
|
45
|
+
babel,
|
|
46
|
+
)
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
ExportNamedDeclaration: (path) => {
|
|
50
|
+
if (!path.node.source) {
|
|
51
|
+
// This export has no "source", so it's probably
|
|
52
|
+
// a local variable or function, e.g.
|
|
53
|
+
// export { varName }
|
|
54
|
+
// export const constName = ...
|
|
55
|
+
// export function funcName() {}
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
transformStringLiteralAtPath(
|
|
60
|
+
path.get("source"),
|
|
61
|
+
transformImportSpecifier,
|
|
62
|
+
babel,
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
ImportDeclaration: (path) => {
|
|
67
|
+
transformStringLiteralAtPath(
|
|
68
|
+
path.get("source"),
|
|
69
|
+
transformImportSpecifier,
|
|
70
|
+
babel,
|
|
71
|
+
)
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const transformStringLiteralAtPath = (path, transform, babel) => {
|
|
78
|
+
const value = path.node.value
|
|
79
|
+
const valueTransformed = transform({
|
|
80
|
+
specifier: value,
|
|
81
|
+
path,
|
|
82
|
+
})
|
|
83
|
+
if (valueTransformed !== value) {
|
|
84
|
+
path.replaceWith(babel.types.stringLiteral(valueTransformed))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -4,11 +4,13 @@ export const getMinimalBabelPluginMap = () => {
|
|
|
4
4
|
const syntaxDynamicImport = require("@babel/plugin-syntax-dynamic-import")
|
|
5
5
|
const syntaxImportMeta = require("@babel/plugin-syntax-import-meta")
|
|
6
6
|
const syntaxNumericSeparator = require("@babel/plugin-syntax-numeric-separator")
|
|
7
|
+
const syntaxImportAssertions = require("@babel/plugin-syntax-import-assertions")
|
|
7
8
|
|
|
8
9
|
return {
|
|
9
10
|
"syntax-dynamic-import": syntaxDynamicImport,
|
|
10
11
|
"syntax-import-meta": syntaxImportMeta,
|
|
11
12
|
"syntax-numeric-separator": syntaxNumericSeparator,
|
|
13
|
+
"synyax-import-assertions": syntaxImportAssertions,
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "@jsenv/filesystem"
|
|
8
8
|
|
|
9
9
|
import { serverUrlToCompileInfo } from "@jsenv/core/src/internal/url_conversion.js"
|
|
10
|
+
import { setUrlExtension } from "../url_utils.js"
|
|
10
11
|
import {
|
|
11
12
|
COMPILE_ID_BUILD_GLOBAL,
|
|
12
13
|
COMPILE_ID_BUILD_GLOBAL_FILES,
|
|
@@ -194,20 +195,27 @@ const getCompiler = ({ originalFileUrl, compileMeta }) => {
|
|
|
194
195
|
return null
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
if (!jsenvCompiler && customCompiler) {
|
|
198
|
-
return customCompiler
|
|
199
|
-
}
|
|
200
|
-
|
|
201
198
|
// there is only a jsenvCompiler
|
|
202
199
|
if (jsenvCompiler && !customCompiler) {
|
|
203
200
|
return jsenvCompiler
|
|
204
201
|
}
|
|
205
202
|
|
|
206
|
-
//
|
|
207
|
-
// we'll do the custom compilation first, then jsenv compilation
|
|
203
|
+
// there is a custom compiler and potentially a jsenv compiler
|
|
208
204
|
return async (params) => {
|
|
205
|
+
// do custom compilation first
|
|
209
206
|
const customResult = await customCompiler(params)
|
|
210
|
-
|
|
207
|
+
// then check if jsenv compiler should apply
|
|
208
|
+
// to the new result contentType
|
|
209
|
+
const jsenvCompilerAfterCustomCompilation =
|
|
210
|
+
getJsenvCompilerAfterCustomCompilation({
|
|
211
|
+
url: originalFileUrl,
|
|
212
|
+
contentType: customResult.contentType,
|
|
213
|
+
compileMeta,
|
|
214
|
+
})
|
|
215
|
+
if (!jsenvCompilerAfterCustomCompilation) {
|
|
216
|
+
return customResult
|
|
217
|
+
}
|
|
218
|
+
const jsenvResult = await jsenvCompilerAfterCustomCompilation({
|
|
211
219
|
...params,
|
|
212
220
|
code: customResult.compiledSource,
|
|
213
221
|
map: customResult.sourcemap,
|
|
@@ -216,20 +224,43 @@ const getCompiler = ({ originalFileUrl, compileMeta }) => {
|
|
|
216
224
|
}
|
|
217
225
|
}
|
|
218
226
|
|
|
227
|
+
const getJsenvCompilerAfterCustomCompilation = ({
|
|
228
|
+
url,
|
|
229
|
+
contentType,
|
|
230
|
+
compileMeta,
|
|
231
|
+
}) => {
|
|
232
|
+
const extensionToForce = contentTypeExtensions[contentType]
|
|
233
|
+
const urlForcingExtension = extensionToForce
|
|
234
|
+
? setUrlExtension(url, extensionToForce)
|
|
235
|
+
: url
|
|
236
|
+
const { jsenvCompiler } = urlToMeta({
|
|
237
|
+
url: urlForcingExtension,
|
|
238
|
+
structuredMetaMap: compileMeta,
|
|
239
|
+
})
|
|
240
|
+
return jsenvCompiler
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// should match contentType where there is a jsenv compiler
|
|
244
|
+
// back to an extension
|
|
245
|
+
const contentTypeExtensions = {
|
|
246
|
+
"application/javascript": ".js",
|
|
247
|
+
"text/html": ".html",
|
|
248
|
+
"application/importmap+json": ".importmap",
|
|
249
|
+
// "text/css": ".css",
|
|
250
|
+
}
|
|
251
|
+
|
|
219
252
|
const babelPluginMapFromCompileId = (
|
|
220
253
|
compileId,
|
|
221
254
|
{ babelPluginMap, groupMap },
|
|
222
255
|
) => {
|
|
223
256
|
const babelPluginMapForGroup = {}
|
|
224
257
|
|
|
225
|
-
groupMap[compileId].
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
},
|
|
232
|
-
)
|
|
258
|
+
groupMap[compileId].pluginRequiredNameArray.forEach((requiredPluginName) => {
|
|
259
|
+
const babelPlugin = babelPluginMap[requiredPluginName]
|
|
260
|
+
if (babelPlugin) {
|
|
261
|
+
babelPluginMapForGroup[requiredPluginName] = babelPlugin
|
|
262
|
+
}
|
|
263
|
+
})
|
|
233
264
|
|
|
234
265
|
Object.keys(babelPluginMap).forEach((key) => {
|
|
235
266
|
if (key.startsWith("syntax-")) {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
urlToRelativeUrl,
|
|
16
16
|
urlToExtension,
|
|
17
17
|
readFile,
|
|
18
|
-
|
|
18
|
+
urlToFilename,
|
|
19
19
|
urlIsInsideOf,
|
|
20
20
|
} from "@jsenv/filesystem"
|
|
21
21
|
import { moveImportMap } from "@jsenv/importmap"
|
|
@@ -195,7 +195,7 @@ const transformHTMLSourceFile = async ({
|
|
|
195
195
|
const scriptIdentifier = getUniqueNameForInlineHtmlNode(
|
|
196
196
|
script,
|
|
197
197
|
scripts,
|
|
198
|
-
`${
|
|
198
|
+
`${urlToFilename(fileUrl)}__inline__[id].js`,
|
|
199
199
|
)
|
|
200
200
|
onInlineModuleScript({
|
|
201
201
|
scriptContent: textNode.value,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
// a named import
|
|
13
13
|
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-plugin-external-helpers/src/index.js
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const babelPluginBabelHelpersAsJsenvImports = (api) => {
|
|
16
16
|
// https://github.com/babel/babel/tree/master/packages/babel-helper-module-imports
|
|
17
17
|
const { addDefault } = require("@babel/helper-module-imports")
|
|
18
18
|
|
|
@@ -12,7 +12,7 @@ const regeneratorRuntimeHelperDirectoryUrl = resolveUrl(
|
|
|
12
12
|
jsenvCoreDirectoryUrl,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const babelPluginRegeneratorRuntimeAsJsenvImport = (api, options) => {
|
|
16
16
|
const { addSideEffect } = require("@babel/helper-module-imports")
|
|
17
17
|
|
|
18
18
|
api.assertVersion(7)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { urlToFileSystemPath } from "@jsenv/filesystem"
|
|
3
3
|
|
|
4
4
|
import { require } from "@jsenv/core/src/internal/require.js"
|
|
5
|
-
import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/
|
|
5
|
+
import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/babel_plugin_transform_import_meta.js"
|
|
6
6
|
import {
|
|
7
7
|
getMinimalBabelPluginMap,
|
|
8
8
|
babelPluginsFromBabelPluginMap,
|
|
@@ -11,9 +11,8 @@ import {
|
|
|
11
11
|
|
|
12
12
|
import { findAsyncPluginNameInBabelPluginMap } from "./findAsyncPluginNameInBabelPluginMap.js"
|
|
13
13
|
import { ansiToHTML } from "./ansiToHTML.js"
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { transformBabelHelperToImportBabelPlugin } from "./transformBabelHelperToImportBabelPlugin.js"
|
|
14
|
+
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
15
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
17
16
|
import { filePathToBabelHelperName } from "./babelHelper.js"
|
|
18
17
|
|
|
19
18
|
export const jsenvTransform = async ({
|
|
@@ -31,7 +30,6 @@ export const jsenvTransform = async ({
|
|
|
31
30
|
allowTopLevelAwait,
|
|
32
31
|
transformTopLevelAwait,
|
|
33
32
|
transformGenerator,
|
|
34
|
-
transformGlobalThis,
|
|
35
33
|
regeneratorRuntimeImportPath,
|
|
36
34
|
sourcemapEnabled,
|
|
37
35
|
}) => {
|
|
@@ -67,8 +65,8 @@ export const jsenvTransform = async ({
|
|
|
67
65
|
if (transformGenerator) {
|
|
68
66
|
babelPluginMap = {
|
|
69
67
|
...babelPluginMap,
|
|
70
|
-
"
|
|
71
|
-
|
|
68
|
+
"regenerator-runtime-as-jsenv-import": [
|
|
69
|
+
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
72
70
|
{
|
|
73
71
|
regeneratorRuntimeImportPath,
|
|
74
72
|
},
|
|
@@ -76,13 +74,6 @@ export const jsenvTransform = async ({
|
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
|
|
79
|
-
if (transformGlobalThis) {
|
|
80
|
-
babelPluginMap = {
|
|
81
|
-
...babelPluginMap,
|
|
82
|
-
"ensure-global-this-import": [ensureGlobalThisImportBabelPlugin],
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
77
|
babelPluginMap = {
|
|
87
78
|
...getMinimalBabelPluginMap(),
|
|
88
79
|
"transform-import-meta": [
|
|
@@ -145,8 +136,8 @@ export const jsenvTransform = async ({
|
|
|
145
136
|
...babelPluginMap,
|
|
146
137
|
...(babelHelpersInjectionAsImport
|
|
147
138
|
? {
|
|
148
|
-
"
|
|
149
|
-
|
|
139
|
+
"babel-helpers-as-jsenv-imports": [
|
|
140
|
+
babelPluginBabelHelpersAsJsenvImports,
|
|
150
141
|
],
|
|
151
142
|
}
|
|
152
143
|
: {}),
|
|
@@ -15,7 +15,6 @@ export const transformJs = async ({
|
|
|
15
15
|
allowTopLevelAwait = true,
|
|
16
16
|
transformTopLevelAwait = true,
|
|
17
17
|
transformGenerator = true,
|
|
18
|
-
transformGlobalThis = true,
|
|
19
18
|
sourcemapEnabled = true,
|
|
20
19
|
}) => {
|
|
21
20
|
if (typeof projectDirectoryUrl !== "string") {
|
|
@@ -51,7 +50,6 @@ export const transformJs = async ({
|
|
|
51
50
|
allowTopLevelAwait,
|
|
52
51
|
transformTopLevelAwait,
|
|
53
52
|
transformGenerator,
|
|
54
|
-
transformGlobalThis,
|
|
55
53
|
sourcemapEnabled,
|
|
56
54
|
})
|
|
57
55
|
code = transformResult.code
|
|
@@ -236,8 +236,6 @@ const mutateRessourceHints = async (htmlAst) => {
|
|
|
236
236
|
const href = hrefAttribute ? hrefAttribute.value : ""
|
|
237
237
|
if (!href) return
|
|
238
238
|
|
|
239
|
-
// - as="script" -> as="fetch" because jsenv uses
|
|
240
|
-
// fetch to load ressources (see "fetchSource" in createBrowserRuntime.js)
|
|
241
239
|
// - "modulepreload" -> "preload" because it's now regular js script
|
|
242
240
|
const asAttribute = getHtmlNodeAttributeByName(
|
|
243
241
|
ressourceHint.htmlNode,
|
|
@@ -248,7 +246,7 @@ const mutateRessourceHints = async (htmlAst) => {
|
|
|
248
246
|
mutations.push(() => {
|
|
249
247
|
replaceHtmlNode(
|
|
250
248
|
ressourceHint.htmlNode,
|
|
251
|
-
`<link rel="preload" as="
|
|
249
|
+
`<link rel="preload" as="script" />`,
|
|
252
250
|
)
|
|
253
251
|
})
|
|
254
252
|
return
|
|
@@ -256,10 +254,7 @@ const mutateRessourceHints = async (htmlAst) => {
|
|
|
256
254
|
|
|
257
255
|
if (asAttribute && asAttribute.value === "script") {
|
|
258
256
|
mutations.push(() => {
|
|
259
|
-
replaceHtmlNode(
|
|
260
|
-
ressourceHint.htmlNode,
|
|
261
|
-
`<link as="fetch" crossorigin />`,
|
|
262
|
-
)
|
|
257
|
+
replaceHtmlNode(ressourceHint.htmlNode, `<link as="script" />`)
|
|
263
258
|
})
|
|
264
259
|
return
|
|
265
260
|
}
|
|
@@ -66,7 +66,7 @@ export const rollupPluginCommonJsNamedExports = ({ logger }) => {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
/*
|
|
70
70
|
* Attempt #1: Static analysis: Lower Fidelity, but faster.
|
|
71
71
|
* Do our best job to statically scan a file for named exports. This uses "cjs-module-lexer", the
|
|
72
72
|
* same CJS export scanner that Node.js uses internally. Very fast, but only works on some modules,
|
|
@@ -117,7 +117,7 @@ const detectStaticExports = ({ logger, fileUrl, visited = new Set() }) => {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
/*
|
|
121
121
|
* Attempt #2b - Sandboxed runtime analysis: More powerful, but slower.
|
|
122
122
|
* This will only work on UMD and very simple CJS files (require not supported).
|
|
123
123
|
* Uses VM2 to run safely sandbox untrusted code (no access no Node.js primitives, just JS).
|
|
@@ -29,9 +29,7 @@ import {
|
|
|
29
29
|
} from "@jsenv/filesystem"
|
|
30
30
|
|
|
31
31
|
import { loadBabelPluginMapFromFile } from "./load_babel_plugin_map_from_file.js"
|
|
32
|
-
import {
|
|
33
|
-
extractSyntaxBabelPluginMap,
|
|
34
|
-
} from "./babel_plugins.js"
|
|
32
|
+
import { extractSyntaxBabelPluginMap } from "./babel_plugins.js"
|
|
35
33
|
import { generateGroupMap } from "../generateGroupMap/generateGroupMap.js"
|
|
36
34
|
import { createCallbackList } from "../createCallbackList.js"
|
|
37
35
|
import {
|
|
@@ -40,7 +38,10 @@ import {
|
|
|
40
38
|
sourcemapMappingFileInfo,
|
|
41
39
|
} from "../jsenvInternalFiles.js"
|
|
42
40
|
import { jsenvCoreDirectoryUrl } from "../jsenvCoreDirectoryUrl.js"
|
|
43
|
-
import { babelPluginReplaceExpressions } from "../
|
|
41
|
+
import { babelPluginReplaceExpressions } from "../babel_plugin_replace_expressions.js"
|
|
42
|
+
import { babelPluginGlobalThisAsJsenvImport } from "./babel_plugin_global_this_as_jsenv_import.js"
|
|
43
|
+
import { babelPluginNewStylesheetAsJsenvImport } from "./babel_plugin_new_stylesheet_as_jsenv_import.js"
|
|
44
|
+
import { babelPluginImportAssertions } from "./babel_plugin_import_assertions.js"
|
|
44
45
|
import { createCompiledFileService } from "./createCompiledFileService.js"
|
|
45
46
|
import { urlIsCompilationAsset } from "./compile-directory/compile-asset.js"
|
|
46
47
|
import { createTransformHtmlSourceFileService } from "./html_source_file_service.js"
|
|
@@ -136,6 +137,9 @@ export const startCompileServer = async ({
|
|
|
136
137
|
babelConfigFileUrl,
|
|
137
138
|
})
|
|
138
139
|
babelPluginMap = {
|
|
140
|
+
"global-this-as-jsenv-import": babelPluginGlobalThisAsJsenvImport,
|
|
141
|
+
"new-stylesheet-as-jsenv-import": babelPluginNewStylesheetAsJsenvImport,
|
|
142
|
+
"transform-import-assertions": babelPluginImportAssertions,
|
|
139
143
|
...babelPluginMapFromFile,
|
|
140
144
|
...babelPluginMap,
|
|
141
145
|
}
|
|
@@ -240,6 +244,7 @@ export const startCompileServer = async ({
|
|
|
240
244
|
inlineImportMapIntoHTML,
|
|
241
245
|
babelPluginMap,
|
|
242
246
|
customCompilers,
|
|
247
|
+
jsenvToolbarInjection,
|
|
243
248
|
})
|
|
244
249
|
if (compileServerCanWriteOnFilesystem) {
|
|
245
250
|
await setupOutDirectory({
|
|
@@ -915,6 +920,7 @@ const createOutJSONFiles = ({
|
|
|
915
920
|
env,
|
|
916
921
|
inlineImportMapIntoHTML,
|
|
917
922
|
customCompilers,
|
|
923
|
+
jsenvToolbarInjection,
|
|
918
924
|
}) => {
|
|
919
925
|
const outJSONFiles = {}
|
|
920
926
|
const outDirectoryUrl = resolveUrl(
|
|
@@ -937,6 +943,7 @@ const createOutJSONFiles = ({
|
|
|
937
943
|
replaceProcessEnvNodeEnv,
|
|
938
944
|
processEnvNodeEnv,
|
|
939
945
|
customCompilerPatterns,
|
|
946
|
+
jsenvToolbarInjection,
|
|
940
947
|
}
|
|
941
948
|
outJSONFiles.meta = {
|
|
942
949
|
url: metaOutFileUrl,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// https://github.com/mgenware/string-to-template-literal/blob/main/src/main.ts#L1
|
|
2
|
+
|
|
3
|
+
export const escapeTemplateStringSpecialCharacters = (string) => {
|
|
4
|
+
string = String(string)
|
|
5
|
+
let i = 0
|
|
6
|
+
let escapedString = ""
|
|
7
|
+
|
|
8
|
+
while (i < string.length) {
|
|
9
|
+
const char = string[i]
|
|
10
|
+
i++
|
|
11
|
+
escapedString += isTemplateStringSpecialChar(char) ? `\\${char}` : char
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return escapedString
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const isTemplateStringSpecialChar = (char) =>
|
|
18
|
+
templateStringSpecialChars.indexOf(char) > -1
|
|
19
|
+
|
|
20
|
+
const templateStringSpecialChars = ["\\", "`", "$"]
|
package/src/internal/executing/coverage/{babel-plugin-instrument.js → babel_plugin_instrument.js}
RENAMED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
resolveUrl,
|
|
3
|
+
normalizeStructuredMetaMap,
|
|
4
|
+
urlToMeta,
|
|
5
|
+
} from "@jsenv/filesystem"
|
|
2
6
|
import { require } from "../../require.js"
|
|
3
7
|
|
|
4
8
|
// https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
|
|
@@ -47,15 +51,22 @@ export const babelPluginInstrument = (api, options) => {
|
|
|
47
51
|
|
|
48
52
|
if (useInlineSourceMaps) {
|
|
49
53
|
// https://github.com/istanbuljs/babel-plugin-istanbul/commit/a9e15643d249a2985e4387e4308022053b2cd0ad#diff-1fdf421c05c1140f6d71444ea2b27638R65
|
|
50
|
-
inputSourceMap =
|
|
54
|
+
inputSourceMap =
|
|
55
|
+
opts.inputSourceMap || file.inputMap
|
|
56
|
+
? file.inputMap.sourcemap
|
|
57
|
+
: null
|
|
51
58
|
} else {
|
|
52
59
|
inputSourceMap = opts.inputSourceMap
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
this.__dv__ = programVisitor(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
this.__dv__ = programVisitor(
|
|
63
|
+
types,
|
|
64
|
+
opts.filenameRelative || opts.filename,
|
|
65
|
+
{
|
|
66
|
+
coverageVariable: "__coverage__",
|
|
67
|
+
inputSourceMap,
|
|
68
|
+
},
|
|
69
|
+
)
|
|
59
70
|
this.__dv__.enter(path)
|
|
60
71
|
},
|
|
61
72
|
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getMinimalBabelPluginMap,
|
|
7
7
|
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
8
8
|
|
|
9
|
-
import { babelPluginInstrument } from "./
|
|
9
|
+
import { babelPluginInstrument } from "./babel_plugin_instrument.js"
|
|
10
10
|
import { createEmptyCoverage } from "./createEmptyCoverage.js"
|
|
11
11
|
|
|
12
12
|
export const relativeUrlToEmptyCoverage = async (
|
|
@@ -126,14 +126,14 @@ export const executeConcurrently = async (
|
|
|
126
126
|
|
|
127
127
|
...executionParams,
|
|
128
128
|
collectCoverage: coverage,
|
|
129
|
-
|
|
129
|
+
runtimeParams: {
|
|
130
130
|
projectDirectoryUrl,
|
|
131
131
|
compileServerOrigin,
|
|
132
132
|
outDirectoryRelativeUrl,
|
|
133
133
|
collectCoverage: coverage,
|
|
134
134
|
coverageConfig,
|
|
135
135
|
coverageForceIstanbul,
|
|
136
|
-
...executionParams.
|
|
136
|
+
...executionParams.runtimeParams,
|
|
137
137
|
},
|
|
138
138
|
executeParams: {
|
|
139
139
|
fileRelativeUrl,
|
|
@@ -186,7 +186,9 @@ export const executeConcurrently = async (
|
|
|
186
186
|
) {
|
|
187
187
|
previousExecutionLog = previousExecutionLog.update(log)
|
|
188
188
|
} else {
|
|
189
|
-
previousExecutionLog = writeLog(log
|
|
189
|
+
previousExecutionLog = writeLog(log, {
|
|
190
|
+
mightUpdate: completedExecutionLogMerging,
|
|
191
|
+
})
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { mergeRuntimeSupport } from "@jsenv/core/src/internal/generateGroupMap/runtime_support.js"
|
|
1
2
|
import { startCompileServer } from "../compiling/startCompileServer.js"
|
|
2
|
-
import { babelPluginInstrument } from "./coverage/
|
|
3
|
+
import { babelPluginInstrument } from "./coverage/babel_plugin_instrument.js"
|
|
3
4
|
import { generateExecutionSteps } from "./generateExecutionSteps.js"
|
|
4
5
|
import { executeConcurrently } from "./executeConcurrently.js"
|
|
5
6
|
|
|
@@ -41,7 +42,6 @@ export const executePlan = async (
|
|
|
41
42
|
babelPluginMap,
|
|
42
43
|
babelConfigFileUrl,
|
|
43
44
|
customCompilers,
|
|
44
|
-
runtimeSupport,
|
|
45
45
|
} = {},
|
|
46
46
|
) => {
|
|
47
47
|
if (coverage) {
|
|
@@ -54,6 +54,20 @@ export const executePlan = async (
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
const runtimeSupport = {}
|
|
58
|
+
Object.keys(plan).forEach((filePattern) => {
|
|
59
|
+
const filePlan = plan[filePattern]
|
|
60
|
+
Object.keys(filePlan).forEach((executionName) => {
|
|
61
|
+
const executionConfig = filePlan[executionName]
|
|
62
|
+
const { runtime } = executionConfig
|
|
63
|
+
if (runtime) {
|
|
64
|
+
mergeRuntimeSupport(runtimeSupport, {
|
|
65
|
+
[runtime.name]: runtime.version,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
57
71
|
const compileServer = await startCompileServer({
|
|
58
72
|
cancellationToken,
|
|
59
73
|
compileServerLogLevel,
|
|
@@ -2,6 +2,7 @@ import { createDetailedMessage } from "@jsenv/logger"
|
|
|
2
2
|
|
|
3
3
|
export const generateFileExecutionSteps = ({ fileRelativeUrl, filePlan }) => {
|
|
4
4
|
const fileExecutionSteps = []
|
|
5
|
+
|
|
5
6
|
Object.keys(filePlan).forEach((executionName) => {
|
|
6
7
|
const stepConfig = filePlan[executionName]
|
|
7
8
|
if (stepConfig === null || stepConfig === undefined) {
|
|
@@ -11,7 +12,7 @@ export const generateFileExecutionSteps = ({ fileRelativeUrl, filePlan }) => {
|
|
|
11
12
|
if (typeof stepConfig !== "object") {
|
|
12
13
|
throw new TypeError(
|
|
13
14
|
createDetailedMessage(
|
|
14
|
-
`found unexpected value in plan, they must be object
|
|
15
|
+
`found unexpected value in plan, they must be object`,
|
|
15
16
|
{
|
|
16
17
|
["file relative path"]: fileRelativeUrl,
|
|
17
18
|
["execution name"]: executionName,
|