@jsenv/core 23.6.2 → 23.7.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.
Files changed (119) hide show
  1. package/{license → LICENSE} +21 -21
  2. package/dist/jsenv_browser_system.js +35 -35
  3. package/dist/jsenv_browser_system.js.map +14 -14
  4. package/dist/jsenv_compile_proxy.js +47 -128
  5. package/dist/jsenv_compile_proxy.js.map +25 -62
  6. package/dist/jsenv_exploring_index.js.map +5 -5
  7. package/dist/jsenv_exploring_redirector.js +47 -54
  8. package/dist/jsenv_exploring_redirector.js.map +17 -19
  9. package/dist/jsenv_toolbar.js +47 -128
  10. package/dist/jsenv_toolbar.js.map +12 -47
  11. package/dist/jsenv_toolbar_injector.js.map +5 -5
  12. package/helpers/babel/.eslintrc.cjs +24 -24
  13. package/helpers/babel/AsyncGenerator/AsyncGenerator.js +81 -81
  14. package/helpers/babel/AwaitValue/AwaitValue.js +3 -3
  15. package/helpers/babel/applyDecoratorDescriptor/applyDecoratorDescriptor.js +33 -33
  16. package/helpers/babel/arrayLikeToArray/arrayLikeToArray.js +7 -7
  17. package/helpers/babel/arrayWithHoles/arrayWithHoles.js +4 -4
  18. package/helpers/babel/arrayWithoutHoles/arrayWithoutHoles.js +6 -6
  19. package/helpers/babel/assertThisInitialized/assertThisInitialized.js +7 -7
  20. package/helpers/babel/asyncGeneratorDelegate/asyncGeneratorDelegate.js +40 -40
  21. package/helpers/babel/asyncIterator/asyncIterator.js +12 -12
  22. package/helpers/babel/asyncToGenerator/asyncToGenerator.js +34 -34
  23. package/helpers/babel/awaitAsyncGenerator/awaitAsyncGenerator.js +5 -5
  24. package/helpers/babel/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +20 -20
  25. package/helpers/babel/classApplyDescriptorGet/classApplyDescriptorGet.js +6 -6
  26. package/helpers/babel/classApplyDescriptorSet/classApplyDescriptorSet.js +13 -13
  27. package/helpers/babel/classCallCheck/classCallCheck.js +5 -5
  28. package/helpers/babel/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -5
  29. package/helpers/babel/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -6
  30. package/helpers/babel/classExtractFieldDescriptor/classExtractFieldDescriptor.js +7 -7
  31. package/helpers/babel/classNameTDZError/classNameTDZError.js +4 -4
  32. package/helpers/babel/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +7 -7
  33. package/helpers/babel/classPrivateFieldGet/classPrivateFieldGet.js +7 -7
  34. package/helpers/babel/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +6 -6
  35. package/helpers/babel/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -5
  36. package/helpers/babel/classPrivateFieldSet/classPrivateFieldSet.js +8 -8
  37. package/helpers/babel/classPrivateMethodGet/classPrivateMethodGet.js +6 -6
  38. package/helpers/babel/classPrivateMethodSet/classPrivateMethodSet.js +3 -3
  39. package/helpers/babel/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +9 -9
  40. package/helpers/babel/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -15
  41. package/helpers/babel/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +6 -6
  42. package/helpers/babel/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -3
  43. package/helpers/babel/construct/construct.js +16 -16
  44. package/helpers/babel/createClass/createClass.js +15 -15
  45. package/helpers/babel/createForOfIteratorHelper/createForOfIteratorHelper.js +60 -60
  46. package/helpers/babel/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +23 -23
  47. package/helpers/babel/createRawReactElement/createRawReactElement.js +50 -50
  48. package/helpers/babel/createSuper/createSuper.js +22 -22
  49. package/helpers/babel/decorate/decorate.js +403 -403
  50. package/helpers/babel/defaults/defaults.js +11 -11
  51. package/helpers/babel/defineEnumerableProperties/defineEnumerableProperties.js +23 -23
  52. package/helpers/babel/defineProperty/defineProperty.js +18 -18
  53. package/helpers/babel/extends/extends.js +14 -14
  54. package/helpers/babel/get/get.js +13 -13
  55. package/helpers/babel/getPrototypeOf/getPrototypeOf.js +4 -4
  56. package/helpers/babel/inherits/inherits.js +15 -15
  57. package/helpers/babel/inheritsLoose/inheritsLoose.js +7 -7
  58. package/helpers/babel/initializerDefineProperty/initializerDefineProperty.js +10 -10
  59. package/helpers/babel/initializerWarningHelper/initializerWarningHelper.js +6 -6
  60. package/helpers/babel/instanceof/instanceof.js +6 -6
  61. package/helpers/babel/interopRequireDefault/interopRequireDefault.js +3 -3
  62. package/helpers/babel/interopRequireWildcard/interopRequireWildcard.js +37 -37
  63. package/helpers/babel/isNativeFunction/isNativeFunction.js +4 -4
  64. package/helpers/babel/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -21
  65. package/helpers/babel/iterableToArray/iterableToArray.js +7 -7
  66. package/helpers/babel/iterableToArrayLimit/iterableToArrayLimit.js +36 -36
  67. package/helpers/babel/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +10 -10
  68. package/helpers/babel/jsx/jsx.js +45 -45
  69. package/helpers/babel/maybeArrayLike/maybeArrayLike.js +10 -10
  70. package/helpers/babel/newArrowCheck/newArrowCheck.js +5 -5
  71. package/helpers/babel/nonIterableRest/nonIterableRest.js +5 -5
  72. package/helpers/babel/nonIterableSpread/nonIterableSpread.js +5 -5
  73. package/helpers/babel/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -3
  74. package/helpers/babel/objectSpread/objectSpread.js +23 -23
  75. package/helpers/babel/objectSpread2/objectSpread2.js +33 -33
  76. package/helpers/babel/objectWithoutProperties/objectWithoutProperties.js +19 -19
  77. package/helpers/babel/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +13 -13
  78. package/helpers/babel/possibleConstructorReturn/possibleConstructorReturn.js +10 -10
  79. package/helpers/babel/readOnlyError/readOnlyError.js +4 -4
  80. package/helpers/babel/readme.md +9 -9
  81. package/helpers/babel/set/set.js +44 -44
  82. package/helpers/babel/setPrototypeOf/setPrototypeOf.js +6 -6
  83. package/helpers/babel/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -8
  84. package/helpers/babel/slicedToArray/slicedToArray.js +10 -10
  85. package/helpers/babel/slicedToArrayLoose/slicedToArrayLoose.js +13 -13
  86. package/helpers/babel/superPropBase/superPropBase.js +10 -10
  87. package/helpers/babel/taggedTemplateLiteral/taggedTemplateLiteral.js +10 -10
  88. package/helpers/babel/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +7 -7
  89. package/helpers/babel/tdz/tdz.js +4 -4
  90. package/helpers/babel/temporalRef/temporalRef.js +6 -6
  91. package/helpers/babel/temporalUndefined/temporalUndefined.js +3 -3
  92. package/helpers/babel/toArray/toArray.js +10 -10
  93. package/helpers/babel/toConsumableArray/toConsumableArray.js +10 -10
  94. package/helpers/babel/toPrimitive/toPrimitive.js +10 -10
  95. package/helpers/babel/toPropertyKey/toPropertyKey.js +6 -6
  96. package/helpers/babel/typeof/typeof.js +14 -14
  97. package/helpers/babel/unsupportedIterableToArray/unsupportedIterableToArray.js +12 -12
  98. package/helpers/babel/wrapAsyncGenerator/wrapAsyncGenerator.js +8 -8
  99. package/helpers/babel/wrapNativeSuper/wrapNativeSuper.js +30 -30
  100. package/helpers/babel/wrapRegExp/wrapRegExp.js +63 -63
  101. package/helpers/babel/writeOnlyError/writeOnlyError.js +4 -4
  102. package/helpers/regenerator-runtime/regenerator-runtime.js +748 -748
  103. package/package.json +4 -2
  104. package/src/buildProject.js +300 -300
  105. package/src/execute.js +184 -184
  106. package/src/internal/browser-launcher/jsenv-browser-system.js +199 -199
  107. package/src/internal/compiling/createCompiledFileService.js +290 -290
  108. package/src/internal/compiling/startCompileServer.js +1052 -1131
  109. package/src/internal/executing/coverage/babel_plugin_instrument.js +90 -90
  110. package/src/internal/executing/coverage/reportToCoverage.js +187 -187
  111. package/src/internal/executing/executePlan.js +183 -183
  112. package/src/internal/executing/launchAndExecute.js +458 -450
  113. package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -250
  114. package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -115
  115. package/src/internal/runtime/s.js +727 -727
  116. package/src/internal/toolbar/jsenv-logo.svg +144 -144
  117. package/src/internal/url_conversion.js +317 -317
  118. package/src/launchNode.js +210 -210
  119. package/src/startExploring.js +309 -309
@@ -1,250 +1,246 @@
1
- import { fetchJson } from "../../browser-utils/fetchJson.js"
2
- import { computeCompileIdFromGroupId } from "../computeCompileIdFromGroupId.js"
3
- import { detectBrowser } from "../detectBrowser/detectBrowser.js"
4
- import { resolveGroup } from "../resolveGroup.js"
5
-
6
- export const scanBrowserRuntimeFeatures = async ({
7
- coverageHandledFromOutside = false,
8
- failFastOnFeatureDetection = false,
9
- } = {}) => {
10
- const { outDirectoryRelativeUrl } = await fetchJson(
11
- "/.jsenv/compile-meta.json",
12
- )
13
- const groupMapUrl = `/${outDirectoryRelativeUrl}groupMap.json`
14
- const envFileUrl = `/${outDirectoryRelativeUrl}env.json`
15
- const [groupMap, envJson] = await Promise.all([
16
- fetchJson(groupMapUrl),
17
- fetchJson(envFileUrl),
18
- ])
19
-
20
- const browser = detectBrowser()
21
- const compileId = computeCompileIdFromGroupId({
22
- groupId: resolveGroup(browser, groupMap),
23
- groupMap,
24
- })
25
- const groupInfo = groupMap[compileId]
26
- const { inlineImportMapIntoHTML, customCompilerPatterns } = envJson
27
-
28
- const featuresReport = {
29
- importmap: undefined,
30
- dynamicImport: undefined,
31
- topLevelAwait: undefined,
32
- jsonImportAssertions: undefined,
33
- cssImportAssertions: undefined,
34
- newStylesheet: undefined,
35
- }
36
- await detectSupportedFeatures({
37
- featuresReport,
38
- failFastOnFeatureDetection,
39
- inlineImportMapIntoHTML,
40
- })
41
- const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(
42
- groupInfo,
43
- {
44
- featuresReport,
45
- coverageHandledFromOutside,
46
- },
47
- )
48
-
49
- const canAvoidCompilation =
50
- customCompilerPatterns.length === 0 &&
51
- pluginRequiredNameArray.length === 0 &&
52
- featuresReport.importmap &&
53
- featuresReport.dynamicImport &&
54
- featuresReport.topLevelAwait
55
-
56
- return {
57
- canAvoidCompilation,
58
- featuresReport,
59
- customCompilerPatterns,
60
- pluginRequiredNameArray,
61
- inlineImportMapIntoHTML,
62
- outDirectoryRelativeUrl,
63
- compileId,
64
- browser,
65
- }
66
- }
67
-
68
- const detectSupportedFeatures = async ({
69
- featuresReport,
70
- failFastOnFeatureDetection,
71
- inlineImportMapIntoHTML,
72
- }) => {
73
- // start testing importmap support first and not in paralell
74
- // so that there is not module script loaded beore importmap is injected
75
- // it would log an error in chrome console and return undefined
76
- const importmap = await supportsImportmap({
77
- // chrome supports inline but not remote importmap
78
- // https://github.com/WICG/import-maps/issues/235
79
-
80
- // at this stage we won't know if the html file will use
81
- // an importmap or not and if that importmap is inline or specified with an src
82
- // so we should test if browser support local and remote importmap.
83
- // But there exploring server can inline importmap by transforming html
84
- // and in that case we can test only the local importmap support
85
- // so we test importmap support and the remote one
86
- remote: !inlineImportMapIntoHTML,
87
- })
88
- featuresReport.importmap = importmap
89
- if (!importmap && failFastOnFeatureDetection) {
90
- return
91
- }
92
-
93
- const dynamicImport = await supportsDynamicImport()
94
- featuresReport.dynamicImport = dynamicImport
95
- if (!dynamicImport && failFastOnFeatureDetection) {
96
- return
97
- }
98
-
99
- const topLevelAwait = await supportsTopLevelAwait()
100
- featuresReport.topLevelAwait = topLevelAwait
101
- if (!topLevelAwait && failFastOnFeatureDetection) {
102
- return
103
- }
104
- }
105
-
106
- const pluginRequiredNamesFromGroupInfo = async (
107
- groupInfo,
108
- { featuresReport, coverageHandledFromOutside },
109
- ) => {
110
- const { pluginRequiredNameArray } = groupInfo
111
- const requiredPluginNames = pluginRequiredNameArray.slice()
112
- const markPluginAsSupported = (name) => {
113
- const index = requiredPluginNames.indexOf(name)
114
- if (index > -1) {
115
- requiredPluginNames.splice(index, 1)
116
- }
117
- }
118
-
119
- // When instrumentation CAN be handed by playwright
120
- // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions
121
- // coverageHandledFromOutside is true and "transform-instrument" becomes non mandatory
122
- if (coverageHandledFromOutside) {
123
- markPluginAsSupported("transform-instrument")
124
- }
125
-
126
- if (pluginRequiredNameArray.includes("transform-import-assertions")) {
127
- const jsonImportAssertions = await supportsJsonImportAssertions()
128
- featuresReport.jsonImportAssertions = jsonImportAssertions
129
-
130
- const cssImportAssertions = await supportsCssImportAssertions()
131
- featuresReport.cssImportAssertions = cssImportAssertions
132
-
133
- if (jsonImportAssertions && cssImportAssertions) {
134
- markPluginAsSupported("transform-import-assertions")
135
- }
136
- }
137
-
138
- if (pluginRequiredNameArray.includes("new-stylesheet-as-jsenv-import")) {
139
- const newStylesheet = supportsNewStylesheet()
140
- featuresReport.newStylesheet = newStylesheet
141
- markPluginAsSupported("new-stylesheet-as-jsenv-import")
142
- }
143
-
144
- return requiredPluginNames
145
- }
146
-
147
- const supportsNewStylesheet = () => {
148
- try {
149
- // eslint-disable-next-line no-new
150
- new CSSStyleSheet()
151
- return true
152
- } catch (e) {
153
- return false
154
- }
155
- }
156
-
157
- const supportsImportmap = async ({ remote = true } = {}) => {
158
- const specifier = asBase64Url(`export default false`)
159
-
160
- const importMap = {
161
- imports: {
162
- [specifier]: asBase64Url(`export default true`),
163
- },
164
- }
165
-
166
- const importmapScript = document.createElement("script")
167
- const importmapString = JSON.stringify(importMap, null, " ")
168
- importmapScript.type = "importmap"
169
- if (remote) {
170
- importmapScript.src = `data:application/json;base64,${window.btoa(
171
- importmapString,
172
- )}`
173
- } else {
174
- importmapScript.textContent = importmapString
175
- }
176
-
177
- document.body.appendChild(importmapScript)
178
-
179
- const scriptModule = document.createElement("script")
180
- scriptModule.type = "module"
181
- scriptModule.src = asBase64Url(
182
- `import supported from "${specifier}"; window.__importmap_supported = supported`,
183
- )
184
-
185
- return new Promise((resolve, reject) => {
186
- scriptModule.onload = () => {
187
- const supported = window.__importmap_supported
188
- delete window.__importmap_supported
189
- document.body.removeChild(scriptModule)
190
- document.body.removeChild(importmapScript)
191
- resolve(supported)
192
- }
193
- scriptModule.onerror = () => {
194
- document.body.removeChild(scriptModule)
195
- document.body.removeChild(importmapScript)
196
- reject()
197
- }
198
- document.body.appendChild(scriptModule)
199
- })
200
- }
201
-
202
- const supportsDynamicImport = async () => {
203
- const moduleSource = asBase64Url(`export default 42`)
204
- try {
205
- const namespace = await import(moduleSource)
206
- return namespace.default === 42
207
- } catch (e) {
208
- return false
209
- }
210
- }
211
-
212
- const supportsTopLevelAwait = async () => {
213
- const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)
214
- try {
215
- const namespace = await import(moduleSource)
216
- return namespace.default === 42
217
- } catch (e) {
218
- return false
219
- }
220
- }
221
-
222
- const supportsJsonImportAssertions = async () => {
223
- const jsonBase64Url = asBase64Url("42", "application/json")
224
- const moduleSource = asBase64Url(
225
- `export { default } from "${jsonBase64Url}" assert { type: "json" }`,
226
- )
227
- try {
228
- const namespace = await import(moduleSource)
229
- return namespace.default === 42
230
- } catch (e) {
231
- return false
232
- }
233
- }
234
-
235
- const supportsCssImportAssertions = async () => {
236
- const cssBase64Url = asBase64Url("p { color: red; }", "text/css")
237
- const moduleSource = asBase64Url(
238
- `export { default } from "${cssBase64Url}" assert { type: "css" }`,
239
- )
240
- try {
241
- const namespace = await import(moduleSource)
242
- return namespace.default instanceof CSSStyleSheet
243
- } catch (e) {
244
- return false
245
- }
246
- }
247
-
248
- const asBase64Url = (text, mimeType = "application/javascript") => {
249
- return `data:${mimeType};base64,${window.btoa(text)}`
250
- }
1
+ import { fetchJson } from "../../browser-utils/fetchJson.js"
2
+ import { computeCompileIdFromGroupId } from "../computeCompileIdFromGroupId.js"
3
+ import { detectBrowser } from "../detectBrowser/detectBrowser.js"
4
+ import { resolveGroup } from "../resolveGroup.js"
5
+
6
+ export const scanBrowserRuntimeFeatures = async ({
7
+ coverageHandledFromOutside = false,
8
+ failFastOnFeatureDetection = false,
9
+ } = {}) => {
10
+ const {
11
+ outDirectoryRelativeUrl,
12
+ inlineImportMapIntoHTML,
13
+ customCompilerPatterns,
14
+ compileServerGroupMap,
15
+ } = await fetchJson("/.jsenv/__compile_server_meta__.json")
16
+
17
+ const browser = detectBrowser()
18
+ const compileId = computeCompileIdFromGroupId({
19
+ groupId: resolveGroup(browser, compileServerGroupMap),
20
+ groupMap: compileServerGroupMap,
21
+ })
22
+ const groupInfo = compileServerGroupMap[compileId]
23
+
24
+ const featuresReport = {
25
+ importmap: undefined,
26
+ dynamicImport: undefined,
27
+ topLevelAwait: undefined,
28
+ jsonImportAssertions: undefined,
29
+ cssImportAssertions: undefined,
30
+ newStylesheet: undefined,
31
+ }
32
+ await detectSupportedFeatures({
33
+ featuresReport,
34
+ failFastOnFeatureDetection,
35
+ inlineImportMapIntoHTML,
36
+ })
37
+ const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(
38
+ groupInfo,
39
+ {
40
+ featuresReport,
41
+ coverageHandledFromOutside,
42
+ },
43
+ )
44
+
45
+ const canAvoidCompilation =
46
+ customCompilerPatterns.length === 0 &&
47
+ pluginRequiredNameArray.length === 0 &&
48
+ featuresReport.importmap &&
49
+ featuresReport.dynamicImport &&
50
+ featuresReport.topLevelAwait
51
+
52
+ return {
53
+ canAvoidCompilation,
54
+ featuresReport,
55
+ customCompilerPatterns,
56
+ pluginRequiredNameArray,
57
+ inlineImportMapIntoHTML,
58
+ outDirectoryRelativeUrl,
59
+ compileId,
60
+ browser,
61
+ }
62
+ }
63
+
64
+ const detectSupportedFeatures = async ({
65
+ featuresReport,
66
+ failFastOnFeatureDetection,
67
+ inlineImportMapIntoHTML,
68
+ }) => {
69
+ // start testing importmap support first and not in paralell
70
+ // so that there is not module script loaded beore importmap is injected
71
+ // it would log an error in chrome console and return undefined
72
+ const importmap = await supportsImportmap({
73
+ // chrome supports inline but not remote importmap
74
+ // https://github.com/WICG/import-maps/issues/235
75
+
76
+ // at this stage we won't know if the html file will use
77
+ // an importmap or not and if that importmap is inline or specified with an src
78
+ // so we should test if browser support local and remote importmap.
79
+ // But there exploring server can inline importmap by transforming html
80
+ // and in that case we can test only the local importmap support
81
+ // so we test importmap support and the remote one
82
+ remote: !inlineImportMapIntoHTML,
83
+ })
84
+ featuresReport.importmap = importmap
85
+ if (!importmap && failFastOnFeatureDetection) {
86
+ return
87
+ }
88
+
89
+ const dynamicImport = await supportsDynamicImport()
90
+ featuresReport.dynamicImport = dynamicImport
91
+ if (!dynamicImport && failFastOnFeatureDetection) {
92
+ return
93
+ }
94
+
95
+ const topLevelAwait = await supportsTopLevelAwait()
96
+ featuresReport.topLevelAwait = topLevelAwait
97
+ if (!topLevelAwait && failFastOnFeatureDetection) {
98
+ return
99
+ }
100
+ }
101
+
102
+ const pluginRequiredNamesFromGroupInfo = async (
103
+ groupInfo,
104
+ { featuresReport, coverageHandledFromOutside },
105
+ ) => {
106
+ const { pluginRequiredNameArray } = groupInfo
107
+ const requiredPluginNames = pluginRequiredNameArray.slice()
108
+ const markPluginAsSupported = (name) => {
109
+ const index = requiredPluginNames.indexOf(name)
110
+ if (index > -1) {
111
+ requiredPluginNames.splice(index, 1)
112
+ }
113
+ }
114
+
115
+ // When instrumentation CAN be handed by playwright
116
+ // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions
117
+ // coverageHandledFromOutside is true and "transform-instrument" becomes non mandatory
118
+ if (coverageHandledFromOutside) {
119
+ markPluginAsSupported("transform-instrument")
120
+ }
121
+
122
+ if (pluginRequiredNameArray.includes("transform-import-assertions")) {
123
+ const jsonImportAssertions = await supportsJsonImportAssertions()
124
+ featuresReport.jsonImportAssertions = jsonImportAssertions
125
+
126
+ const cssImportAssertions = await supportsCssImportAssertions()
127
+ featuresReport.cssImportAssertions = cssImportAssertions
128
+
129
+ if (jsonImportAssertions && cssImportAssertions) {
130
+ markPluginAsSupported("transform-import-assertions")
131
+ }
132
+ }
133
+
134
+ if (pluginRequiredNameArray.includes("new-stylesheet-as-jsenv-import")) {
135
+ const newStylesheet = supportsNewStylesheet()
136
+ featuresReport.newStylesheet = newStylesheet
137
+ markPluginAsSupported("new-stylesheet-as-jsenv-import")
138
+ }
139
+
140
+ return requiredPluginNames
141
+ }
142
+
143
+ const supportsNewStylesheet = () => {
144
+ try {
145
+ // eslint-disable-next-line no-new
146
+ new CSSStyleSheet()
147
+ return true
148
+ } catch (e) {
149
+ return false
150
+ }
151
+ }
152
+
153
+ const supportsImportmap = async ({ remote = true } = {}) => {
154
+ const specifier = asBase64Url(`export default false`)
155
+
156
+ const importMap = {
157
+ imports: {
158
+ [specifier]: asBase64Url(`export default true`),
159
+ },
160
+ }
161
+
162
+ const importmapScript = document.createElement("script")
163
+ const importmapString = JSON.stringify(importMap, null, " ")
164
+ importmapScript.type = "importmap"
165
+ if (remote) {
166
+ importmapScript.src = `data:application/json;base64,${window.btoa(
167
+ importmapString,
168
+ )}`
169
+ } else {
170
+ importmapScript.textContent = importmapString
171
+ }
172
+
173
+ document.body.appendChild(importmapScript)
174
+
175
+ const scriptModule = document.createElement("script")
176
+ scriptModule.type = "module"
177
+ scriptModule.src = asBase64Url(
178
+ `import supported from "${specifier}"; window.__importmap_supported = supported`,
179
+ )
180
+
181
+ return new Promise((resolve, reject) => {
182
+ scriptModule.onload = () => {
183
+ const supported = window.__importmap_supported
184
+ delete window.__importmap_supported
185
+ document.body.removeChild(scriptModule)
186
+ document.body.removeChild(importmapScript)
187
+ resolve(supported)
188
+ }
189
+ scriptModule.onerror = () => {
190
+ document.body.removeChild(scriptModule)
191
+ document.body.removeChild(importmapScript)
192
+ reject()
193
+ }
194
+ document.body.appendChild(scriptModule)
195
+ })
196
+ }
197
+
198
+ const supportsDynamicImport = async () => {
199
+ const moduleSource = asBase64Url(`export default 42`)
200
+ try {
201
+ const namespace = await import(moduleSource)
202
+ return namespace.default === 42
203
+ } catch (e) {
204
+ return false
205
+ }
206
+ }
207
+
208
+ const supportsTopLevelAwait = async () => {
209
+ const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)
210
+ try {
211
+ const namespace = await import(moduleSource)
212
+ return namespace.default === 42
213
+ } catch (e) {
214
+ return false
215
+ }
216
+ }
217
+
218
+ const supportsJsonImportAssertions = async () => {
219
+ const jsonBase64Url = asBase64Url("42", "application/json")
220
+ const moduleSource = asBase64Url(
221
+ `export { default } from "${jsonBase64Url}" assert { type: "json" }`,
222
+ )
223
+ try {
224
+ const namespace = await import(moduleSource)
225
+ return namespace.default === 42
226
+ } catch (e) {
227
+ return false
228
+ }
229
+ }
230
+
231
+ const supportsCssImportAssertions = async () => {
232
+ const cssBase64Url = asBase64Url("p { color: red; }", "text/css")
233
+ const moduleSource = asBase64Url(
234
+ `export { default } from "${cssBase64Url}" assert { type: "css" }`,
235
+ )
236
+ try {
237
+ const namespace = await import(moduleSource)
238
+ return namespace.default instanceof CSSStyleSheet
239
+ } catch (e) {
240
+ return false
241
+ }
242
+ }
243
+
244
+ const asBase64Url = (text, mimeType = "application/javascript") => {
245
+ return `data:${mimeType};base64,${window.btoa(text)}`
246
+ }