@jsenv/runtime-compat 1.3.3 → 1.4.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/package.json
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/runtime-compat",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "TODO",
|
|
3
|
+
"version": "1.4.0",
|
|
5
4
|
"license": "MIT",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
7
|
"url": "https://github.com/jsenv/core",
|
|
9
8
|
"directory": "packages/internal/runtime-compat"
|
|
10
9
|
},
|
|
11
|
-
"engines": {
|
|
12
|
-
"node": ">=16.13.0"
|
|
13
|
-
},
|
|
14
|
-
"publishConfig": {
|
|
15
|
-
"access": "public"
|
|
16
|
-
},
|
|
17
10
|
"type": "module",
|
|
18
11
|
"main": "./src/main.js",
|
|
19
12
|
"files": [
|
|
20
13
|
"/src/"
|
|
21
14
|
],
|
|
15
|
+
"sideEffects": false,
|
|
22
16
|
"dependencies": {
|
|
23
|
-
"@jsenv/utils": "2.
|
|
17
|
+
"@jsenv/utils": "2.3.0",
|
|
18
|
+
"@jsenv/filesystem": "4.14.6",
|
|
19
|
+
"browserslist": "4.24.4"
|
|
24
20
|
}
|
|
25
21
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// default runtimeCompat corresponds to
|
|
2
|
+
// "we can keep <script type="module"> intact":
|
|
3
|
+
// so script_type_module + dynamic_import + import_meta
|
|
4
|
+
export const browserDefaultRuntimeCompat = {
|
|
5
|
+
// android: "8",
|
|
6
|
+
chrome: "64",
|
|
7
|
+
edge: "79",
|
|
8
|
+
firefox: "67",
|
|
9
|
+
ios: "12",
|
|
10
|
+
opera: "51",
|
|
11
|
+
safari: "11.3",
|
|
12
|
+
samsung: "9.2",
|
|
13
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
+
export { browserDefaultRuntimeCompat } from "./browser_default_runtime_compat.js";
|
|
2
|
+
export { nodeDefaultRuntimeCompat } from "./node_default_runtime_compat.js";
|
|
1
3
|
export { RUNTIME_COMPAT } from "./runtime_compat.js";
|
|
4
|
+
export { inferRuntimeCompatFromClosestPackage } from "./runtime_compat_from_package.js";
|
package/src/runtime_compat.js
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { lookupPackageDirectory, readPackageAtOrNull } from "@jsenv/filesystem";
|
|
2
|
+
import { browserDefaultRuntimeCompat } from "./browser_default_runtime_compat.js";
|
|
3
|
+
|
|
4
|
+
export const inferRuntimeCompatFromClosestPackage = async (
|
|
5
|
+
sourceUrl,
|
|
6
|
+
{ runtimeType },
|
|
7
|
+
) => {
|
|
8
|
+
const packageDirectoryUrl = lookupPackageDirectory(sourceUrl);
|
|
9
|
+
if (!packageDirectoryUrl) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const packageJSON = readPackageAtOrNull(packageDirectoryUrl);
|
|
13
|
+
if (!packageJSON) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (runtimeType === "browser") {
|
|
18
|
+
const browserlist = packageJSON.browserlist;
|
|
19
|
+
if (!browserlist) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const namespace = await import("browserslist");
|
|
23
|
+
const browserslist = namespace.default;
|
|
24
|
+
const browserslistConfig = browserslist(browserlist);
|
|
25
|
+
const runtimeCompat = {};
|
|
26
|
+
for (const browserNameAndVersion of browserslistConfig) {
|
|
27
|
+
let [name, version] = browserNameAndVersion.split(" ");
|
|
28
|
+
if (name === "ios_saf") {
|
|
29
|
+
name = "ios";
|
|
30
|
+
}
|
|
31
|
+
if (Object.keys(browserDefaultRuntimeCompat).includes(name)) {
|
|
32
|
+
runtimeCompat[name] = version;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return runtimeCompat;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const engines = packageJSON.engines;
|
|
39
|
+
if (!engines) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const node = engines.node;
|
|
43
|
+
const versionMatch = node.match(/[0-9*.]+/);
|
|
44
|
+
if (!versionMatch) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
node: versionMatch[0],
|
|
49
|
+
};
|
|
50
|
+
};
|