@jsenv/core 27.0.0-alpha.6 → 27.0.0-alpha.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/package.json +1 -1
- package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +1 -4
- package/src/omega/core_plugins/babel/jsenv_plugin_babel.js +18 -4
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +1 -4
- package/src/omega/kitchen.js +3 -13
- package/src/omega/runtime_support/features_compatibility.js +40 -1
- package/src/omega/runtime_support/runtime_support.js +48 -16
package/package.json
CHANGED
|
@@ -10,10 +10,7 @@ export const getBaseBabelPluginStructure = ({
|
|
|
10
10
|
isJsModule,
|
|
11
11
|
}) => {
|
|
12
12
|
const isBabelPluginNeeded = (babelPluginName) => {
|
|
13
|
-
return !isSupportedOnRuntime(
|
|
14
|
-
babelPluginName,
|
|
15
|
-
babelPluginCompatMap[babelPluginName],
|
|
16
|
-
)
|
|
13
|
+
return !isSupportedOnRuntime(babelPluginCompatMap[babelPluginName])
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
const babelPluginStructure = {}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
2
|
|
|
3
|
+
import { RUNTIME_SUPPORT } from "@jsenv/core/src/omega/runtime_support/runtime_support.js"
|
|
3
4
|
import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js"
|
|
4
5
|
import { babelPluginBabelHelpersAsJsenvImports } from "./helpers/babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
5
6
|
import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js"
|
|
@@ -12,16 +13,29 @@ export const jsenvPluginBabel = ({
|
|
|
12
13
|
} = {}) => {
|
|
13
14
|
const transformWithBabel = async (urlInfo, context) => {
|
|
14
15
|
const isJsModule = urlInfo.type === "js_module"
|
|
15
|
-
const isWorker =
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
const isWorker = urlInfo.subtype === "worker"
|
|
17
|
+
const isServiceWorker = urlInfo.subtype === "service_worker"
|
|
18
|
+
const isWorkerContext = isWorker || isServiceWorker
|
|
19
|
+
let { runtimeSupport } = context
|
|
20
|
+
if (isServiceWorker) {
|
|
21
|
+
// when code is executed by a service worker we can assume
|
|
22
|
+
// the execution context supports more than the default one
|
|
23
|
+
// for instance arrow function are supported
|
|
24
|
+
runtimeSupport = RUNTIME_SUPPORT.add(runtimeSupport, "service_worker")
|
|
25
|
+
}
|
|
26
|
+
if (isWorker) {
|
|
27
|
+
runtimeSupport = RUNTIME_SUPPORT.add(runtimeSupport, "worker")
|
|
28
|
+
}
|
|
29
|
+
const { referenceUtils } = context
|
|
30
|
+
const isSupportedOnRuntime = (feature) =>
|
|
31
|
+
RUNTIME_SUPPORT.isSupported(runtimeSupport, feature)
|
|
18
32
|
const babelPluginStructure = getBaseBabelPluginStructure({
|
|
19
33
|
url: urlInfo.url,
|
|
20
34
|
isSupportedOnRuntime,
|
|
21
35
|
topLevelAwait,
|
|
22
36
|
usesTopLevelAwait: urlInfo.data.usesTopLevelAwait,
|
|
23
37
|
isJsModule,
|
|
24
|
-
|
|
38
|
+
isWorkerContext,
|
|
25
39
|
})
|
|
26
40
|
if (getCustomBabelPlugins) {
|
|
27
41
|
Object.assign(babelPluginStructure, getCustomBabelPlugins(context))
|
|
@@ -52,10 +52,7 @@ export const jsenvPluginNewInlineContent = ({ allowEscapeForVersioning }) => {
|
|
|
52
52
|
columnEnd: inlineContentCall.columnEnd,
|
|
53
53
|
})
|
|
54
54
|
let { quote } = inlineContentCall
|
|
55
|
-
if (
|
|
56
|
-
quote === "`" &&
|
|
57
|
-
!isSupportedOnRuntime("transform-template-literals")
|
|
58
|
-
) {
|
|
55
|
+
if (quote === "`" && !isSupportedOnRuntime("template_literals")) {
|
|
59
56
|
// if quote is "`" and template literals are not supported
|
|
60
57
|
// we'll use a regular string (single or double quote)
|
|
61
58
|
// when rendering the string
|
package/src/omega/kitchen.js
CHANGED
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
import { stringifyUrlSite } from "@jsenv/utils/urls/url_trace.js"
|
|
11
11
|
|
|
12
12
|
import { createUrlInfoTransformer } from "./url_graph/url_info_transformations.js"
|
|
13
|
-
import {
|
|
14
|
-
import { isFeatureSupportedOnRuntimes } from "./runtime_support/runtime_support.js"
|
|
13
|
+
import { RUNTIME_SUPPORT } from "./runtime_support/runtime_support.js"
|
|
15
14
|
import { fileUrlConverter } from "./file_url_converter.js"
|
|
16
15
|
import { parseUrlMentions } from "./url_mentions/parse_url_mentions.js"
|
|
17
16
|
import {
|
|
@@ -185,14 +184,6 @@ export const createKitchen = ({
|
|
|
185
184
|
},
|
|
186
185
|
})
|
|
187
186
|
|
|
188
|
-
const isSupported = ({
|
|
189
|
-
runtimeSupport,
|
|
190
|
-
featureName,
|
|
191
|
-
featureCompat = featuresCompatMap[featureName],
|
|
192
|
-
}) => {
|
|
193
|
-
return isFeatureSupportedOnRuntimes(runtimeSupport, featureCompat)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
187
|
const load = async ({ reference, urlInfo, context }) => {
|
|
197
188
|
try {
|
|
198
189
|
const loadReturnValue = urlInfo.isInline
|
|
@@ -274,8 +265,8 @@ export const createKitchen = ({
|
|
|
274
265
|
reference,
|
|
275
266
|
outDirectoryUrl,
|
|
276
267
|
runtimeSupport,
|
|
277
|
-
isSupportedOnRuntime: (
|
|
278
|
-
return isSupported(
|
|
268
|
+
isSupportedOnRuntime: (feature) => {
|
|
269
|
+
return RUNTIME_SUPPORT.isSupported(runtimeSupport, feature)
|
|
279
270
|
},
|
|
280
271
|
cook: (params) => {
|
|
281
272
|
return cookDuringCook({
|
|
@@ -585,7 +576,6 @@ export const createKitchen = ({
|
|
|
585
576
|
urlInfoTransformer,
|
|
586
577
|
rootDirectoryUrl,
|
|
587
578
|
jsenvDirectoryUrl,
|
|
588
|
-
isSupported,
|
|
589
579
|
createReference,
|
|
590
580
|
resolveReference,
|
|
591
581
|
cook,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const featureCompats = {
|
|
2
2
|
script_type_module: {
|
|
3
3
|
edge: "16",
|
|
4
4
|
firefox: "60",
|
|
@@ -52,6 +52,7 @@ export const featuresCompatMap = {
|
|
|
52
52
|
chrome: "93",
|
|
53
53
|
edge: "93",
|
|
54
54
|
},
|
|
55
|
+
import_type_text: {},
|
|
55
56
|
// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet#browser_compatibility
|
|
56
57
|
new_stylesheet: {
|
|
57
58
|
chrome: "73",
|
|
@@ -59,6 +60,33 @@ export const featuresCompatMap = {
|
|
|
59
60
|
opera: "53",
|
|
60
61
|
android: "73",
|
|
61
62
|
},
|
|
63
|
+
// https://caniuse.com/?search=worker
|
|
64
|
+
worker: {
|
|
65
|
+
ie: "10",
|
|
66
|
+
edge: "12",
|
|
67
|
+
firefox: "3.5",
|
|
68
|
+
chrome: "4",
|
|
69
|
+
opera: "11.5",
|
|
70
|
+
safari: "4",
|
|
71
|
+
ios: "5",
|
|
72
|
+
android: "4.4",
|
|
73
|
+
},
|
|
74
|
+
service_worker: {
|
|
75
|
+
edge: "17",
|
|
76
|
+
firefox: "44",
|
|
77
|
+
chrome: "40",
|
|
78
|
+
safari: "11.1",
|
|
79
|
+
opera: "27",
|
|
80
|
+
ios: "11.3",
|
|
81
|
+
android: "12.12",
|
|
82
|
+
},
|
|
83
|
+
service_worker_type_module: {
|
|
84
|
+
chrome: "80",
|
|
85
|
+
edge: "80",
|
|
86
|
+
opera: "67",
|
|
87
|
+
android: "80",
|
|
88
|
+
},
|
|
89
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#browser_compatibility
|
|
62
90
|
worker_type_module: {
|
|
63
91
|
chrome: "80",
|
|
64
92
|
edge: "80",
|
|
@@ -88,4 +116,15 @@ export const featuresCompatMap = {
|
|
|
88
116
|
samsung: "8",
|
|
89
117
|
electron: "3",
|
|
90
118
|
},
|
|
119
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#browser_compatibility
|
|
120
|
+
template_literals: {
|
|
121
|
+
chrome: "41",
|
|
122
|
+
edge: "12",
|
|
123
|
+
firefox: "34",
|
|
124
|
+
opera: "28",
|
|
125
|
+
safari: "9",
|
|
126
|
+
ios: "9",
|
|
127
|
+
android: "4",
|
|
128
|
+
node: "4",
|
|
129
|
+
},
|
|
91
130
|
}
|
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
import { findHighestVersion } from "@jsenv/utils/semantic_versioning/highest_version.js"
|
|
2
|
+
import { featureCompats } from "./features_compatibility.js"
|
|
2
3
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
export const RUNTIME_SUPPORT = {
|
|
5
|
+
featureCompats,
|
|
6
|
+
|
|
7
|
+
add: (originalRuntimeSupport, feature) => {
|
|
8
|
+
const featureCompat = getFeatureCompat(feature)
|
|
9
|
+
const runtimeSupport = {
|
|
10
|
+
...originalRuntimeSupport,
|
|
11
|
+
}
|
|
12
|
+
Object.keys(featureCompat).forEach((runtimeName) => {
|
|
13
|
+
const firstVersion = originalRuntimeSupport[runtimeName]
|
|
14
|
+
const secondVersion = featureCompat[runtimeName]
|
|
15
|
+
runtimeSupport[runtimeName] = firstVersion
|
|
16
|
+
? findHighestVersion(firstVersion, secondVersion)
|
|
17
|
+
: secondVersion
|
|
18
|
+
})
|
|
19
|
+
return runtimeSupport
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
isSupported: (runtimeSupport, feature) => {
|
|
23
|
+
const featureCompat = getFeatureCompat(feature)
|
|
24
|
+
const runtimeNames = Object.keys(runtimeSupport)
|
|
25
|
+
return runtimeNames.every((runtimeName) => {
|
|
26
|
+
const runtimeVersion = runtimeSupport[runtimeName]
|
|
27
|
+
const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
|
|
28
|
+
const highestVersion = findHighestVersion(
|
|
29
|
+
runtimeVersion,
|
|
30
|
+
runtimeVersionCompatible,
|
|
31
|
+
)
|
|
32
|
+
if (highestVersion !== runtimeVersion) {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
return true
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getFeatureCompat = (feature) => {
|
|
41
|
+
if (typeof feature === "string") {
|
|
42
|
+
const compat = featureCompats[feature]
|
|
43
|
+
if (!compat) {
|
|
44
|
+
throw new Error(`"${feature}" feature is unknown`)
|
|
17
45
|
}
|
|
18
|
-
return
|
|
19
|
-
}
|
|
46
|
+
return compat
|
|
47
|
+
}
|
|
48
|
+
if (typeof feature !== "object") {
|
|
49
|
+
throw new TypeError(`feature must be a string or an object, got ${feature}`)
|
|
50
|
+
}
|
|
51
|
+
return feature
|
|
20
52
|
}
|