@jsenv/core 23.7.0 → 23.7.1

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.
@@ -1,112 +1,112 @@
1
- import { detectNode } from "../detectNode/detectNode.js"
2
- import { resolveGroup } from "../resolveGroup.js"
3
- import { computeCompileIdFromGroupId } from "../computeCompileIdFromGroupId.js"
4
- import { nodeSupportsDynamicImport } from "../node-feature-detect/nodeSupportsDynamicImport.js"
5
- import { nodeSupportsTopLevelAwait } from "../node-feature-detect/nodeSupportsTopLevelAwait.js"
6
- import { fetchSource } from "./fetchSource.js"
7
-
8
- export const scanNodeRuntimeFeatures = async ({
9
- compileServerOrigin,
10
- outDirectoryRelativeUrl,
11
- }) => {
12
- const outDirectoryServerUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`
13
- const {
14
- importDefaultExtension,
15
- customCompilerPatterns,
16
- compileServerGroupMap,
17
- } = await importJson(
18
- new URL("__compile_server_meta__.json", outDirectoryServerUrl),
19
- )
20
-
21
- const node = detectNode()
22
- const compileId = computeCompileIdFromGroupId({
23
- groupId: resolveGroup(node, compileServerGroupMap),
24
- groupMap: compileServerGroupMap,
25
- })
26
- const groupInfo = compileServerGroupMap[compileId]
27
-
28
- const featuresReport = {
29
- dynamicImport: undefined,
30
- topLevelAwait: undefined,
31
- }
32
- await detectSupportedFeatures({
33
- featuresReport,
34
- failFastOnFeatureDetection: true,
35
- })
36
- const pluginRequiredNameArray = pluginRequiredNamesFromGroupInfo(groupInfo, {
37
- featuresReport,
38
- // https://nodejs.org/docs/latest-v15.x/api/cli.html#cli_node_v8_coverage_dir
39
- // instrumentation CAN be handed by process.env.NODE_V8_COVERAGE
40
- // "transform-instrument" becomes non mandatory
41
- coverageHandledFromOutside: process.env.NODE_V8_COVERAGE,
42
- })
43
-
44
- const canAvoidCompilation =
45
- // node native resolution will not auto add extension
46
- !importDefaultExtension &&
47
- customCompilerPatterns.length === 0 &&
48
- pluginRequiredNameArray.length === 0 &&
49
- featuresReport.dynamicImport &&
50
- featuresReport.topLevelAwait
51
-
52
- return {
53
- canAvoidCompilation,
54
- featuresReport,
55
- pluginRequiredNameArray,
56
- compileId,
57
- importDefaultExtension,
58
- node,
59
- }
60
- }
61
-
62
- const detectSupportedFeatures = async ({
63
- featuresReport,
64
- failFastOnFeatureDetection,
65
- }) => {
66
- const dynamicImport = await nodeSupportsDynamicImport()
67
- featuresReport.dynamicImport = dynamicImport
68
- if (failFastOnFeatureDetection && !dynamicImport) {
69
- return
70
- }
71
-
72
- const topLevelAwait = await nodeSupportsTopLevelAwait()
73
- featuresReport.topLevelAwait = topLevelAwait
74
- if (failFastOnFeatureDetection && !topLevelAwait) {
75
- return
76
- }
77
- }
78
-
79
- const importJson = async (url) => {
80
- const response = await fetchSource(url)
81
- const status = response.status
82
- if (status !== 200) {
83
- throw new Error(`unexpected response status for ${url}, got ${status}`)
84
- }
85
- const object = await response.json()
86
- return object
87
- }
88
-
89
- const pluginRequiredNamesFromGroupInfo = (
90
- groupInfo,
91
- { coverageHandledFromOutside },
92
- ) => {
93
- const { pluginRequiredNameArray } = groupInfo
94
- const requiredPluginNames = pluginRequiredNameArray.slice()
95
- const markPluginAsSupported = (name) => {
96
- const index = requiredPluginNames.indexOf(name)
97
- if (index > -1) {
98
- requiredPluginNames.splice(index, 1)
99
- }
100
- }
101
-
102
- if (coverageHandledFromOutside) {
103
- markPluginAsSupported("transform-instrument")
104
- }
105
- // We assume import assertions and constructable stylesheet won't be used
106
- // in code executed in Node.js
107
- // so event they are conceptually required, they are ignored
108
- markPluginAsSupported("transform-import-assertions")
109
- markPluginAsSupported("new-stylesheet-as-jsenv-import")
110
-
111
- return requiredPluginNames
112
- }
1
+ import { detectNode } from "../detectNode/detectNode.js"
2
+ import { resolveGroup } from "../resolveGroup.js"
3
+ import { computeCompileIdFromGroupId } from "../computeCompileIdFromGroupId.js"
4
+ import { nodeSupportsDynamicImport } from "../node-feature-detect/nodeSupportsDynamicImport.js"
5
+ import { nodeSupportsTopLevelAwait } from "../node-feature-detect/nodeSupportsTopLevelAwait.js"
6
+ import { fetchSource } from "./fetchSource.js"
7
+
8
+ export const scanNodeRuntimeFeatures = async ({
9
+ compileServerOrigin,
10
+ outDirectoryRelativeUrl,
11
+ }) => {
12
+ const outDirectoryServerUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`
13
+ const {
14
+ importDefaultExtension,
15
+ customCompilerPatterns,
16
+ compileServerGroupMap,
17
+ } = await importJson(
18
+ new URL("__compile_server_meta__.json", outDirectoryServerUrl),
19
+ )
20
+
21
+ const node = detectNode()
22
+ const compileId = computeCompileIdFromGroupId({
23
+ groupId: resolveGroup(node, compileServerGroupMap),
24
+ groupMap: compileServerGroupMap,
25
+ })
26
+ const groupInfo = compileServerGroupMap[compileId]
27
+
28
+ const featuresReport = {
29
+ dynamicImport: undefined,
30
+ topLevelAwait: undefined,
31
+ }
32
+ await detectSupportedFeatures({
33
+ featuresReport,
34
+ failFastOnFeatureDetection: true,
35
+ })
36
+ const pluginRequiredNameArray = pluginRequiredNamesFromGroupInfo(groupInfo, {
37
+ featuresReport,
38
+ // https://nodejs.org/docs/latest-v15.x/api/cli.html#cli_node_v8_coverage_dir
39
+ // instrumentation CAN be handed by process.env.NODE_V8_COVERAGE
40
+ // "transform-instrument" becomes non mandatory
41
+ coverageHandledFromOutside: process.env.NODE_V8_COVERAGE,
42
+ })
43
+
44
+ const canAvoidCompilation =
45
+ // node native resolution will not auto add extension
46
+ !importDefaultExtension &&
47
+ customCompilerPatterns.length === 0 &&
48
+ pluginRequiredNameArray.length === 0 &&
49
+ featuresReport.dynamicImport &&
50
+ featuresReport.topLevelAwait
51
+
52
+ return {
53
+ canAvoidCompilation,
54
+ featuresReport,
55
+ pluginRequiredNameArray,
56
+ compileId,
57
+ importDefaultExtension,
58
+ node,
59
+ }
60
+ }
61
+
62
+ const detectSupportedFeatures = async ({
63
+ featuresReport,
64
+ failFastOnFeatureDetection,
65
+ }) => {
66
+ const dynamicImport = await nodeSupportsDynamicImport()
67
+ featuresReport.dynamicImport = dynamicImport
68
+ if (failFastOnFeatureDetection && !dynamicImport) {
69
+ return
70
+ }
71
+
72
+ const topLevelAwait = await nodeSupportsTopLevelAwait()
73
+ featuresReport.topLevelAwait = topLevelAwait
74
+ if (failFastOnFeatureDetection && !topLevelAwait) {
75
+ return
76
+ }
77
+ }
78
+
79
+ const importJson = async (url) => {
80
+ const response = await fetchSource(url)
81
+ const status = response.status
82
+ if (status !== 200) {
83
+ throw new Error(`unexpected response status for ${url}, got ${status}`)
84
+ }
85
+ const object = await response.json()
86
+ return object
87
+ }
88
+
89
+ const pluginRequiredNamesFromGroupInfo = (
90
+ groupInfo,
91
+ { coverageHandledFromOutside },
92
+ ) => {
93
+ const { pluginRequiredNameArray } = groupInfo
94
+ const requiredPluginNames = pluginRequiredNameArray.slice()
95
+ const markPluginAsSupported = (name) => {
96
+ const index = requiredPluginNames.indexOf(name)
97
+ if (index > -1) {
98
+ requiredPluginNames.splice(index, 1)
99
+ }
100
+ }
101
+
102
+ if (coverageHandledFromOutside) {
103
+ markPluginAsSupported("transform-instrument")
104
+ }
105
+ // We assume import assertions and constructable stylesheet won't be used
106
+ // in code executed in Node.js
107
+ // so event they are conceptually required, they are ignored
108
+ markPluginAsSupported("transform-import-assertions")
109
+ markPluginAsSupported("new-stylesheet-as-jsenv-import")
110
+
111
+ return requiredPluginNames
112
+ }