@jsenv/core 23.7.1 → 23.8.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.map +1 -1
- package/dist/jsenv_compile_proxy.js.map +1 -1
- package/dist/jsenv_exploring_redirector.js.map +1 -1
- package/dist/jsenv_toolbar.js +0 -2
- package/dist/jsenv_toolbar.js.map +3 -3
- package/package.json +2 -2
- package/src/buildProject.js +300 -300
- package/src/execute.js +184 -184
- package/src/internal/browser-launcher/jsenv-browser-system.js +199 -199
- package/src/internal/compiling/babel_plugin_import_assertions.js +121 -100
- package/src/internal/compiling/babel_plugin_import_metadata.js +22 -0
- package/src/internal/compiling/babel_plugin_import_visitor.js +84 -0
- package/src/internal/compiling/compile-directory/getOrGenerateCompiledFile.js +268 -265
- package/src/internal/compiling/compile-directory/updateMeta.js +154 -150
- package/src/internal/compiling/compile-directory/validateCache.js +265 -265
- package/src/internal/compiling/compileFile.js +215 -194
- package/src/internal/compiling/compileHtml.js +550 -494
- package/src/internal/compiling/createCompiledFileService.js +291 -290
- package/src/internal/compiling/html_source_file_service.js +403 -379
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +270 -269
- package/src/internal/compiling/jsenvCompilerForHtml.js +300 -293
- package/src/internal/compiling/startCompileServer.js +1048 -1052
- package/src/internal/compiling/transformResultToCompilationResult.js +220 -217
- package/src/internal/executing/executePlan.js +183 -183
- package/src/internal/executing/launchAndExecute.js +458 -458
- package/src/internal/runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js +246 -246
- package/src/internal/runtime/createNodeRuntime/scanNodeRuntimeFeatures.js +112 -112
- package/src/internal/toolbar/toolbar.main.css +196 -188
- package/src/internal/toolbar/toolbar.main.js +227 -228
- package/src/internal/url_conversion.js +317 -317
- package/src/startExploring.js +309 -309
- package/src/internal/compiling/babel_plugin_transform_import_specifier.js +0 -86
- package/src/internal/toolbar/animation/animation.css +0 -5
- package/src/internal/toolbar/variant/variant.css +0 -3
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"import { createDetailedMessage } from \"@jsenv/logger\"\nimport { stackToString } from \"./stackToString.js\"\nimport { getOriginalCallsites } from \"./getOriginalCallsites.js\"\n\nexport const installErrorStackRemapping = ({\n fetchFile,\n resolveFile,\n SourceMapConsumer,\n indent = \" \",\n}) => {\n if (typeof fetchFile !== \"function\") {\n throw new TypeError(`fetchFile must be a function, got ${fetchFile}`)\n }\n if (typeof SourceMapConsumer !== \"function\") {\n throw new TypeError(\n `sourceMapConsumer must be a function, got ${SourceMapConsumer}`,\n )\n }\n if (typeof indent !== \"string\") {\n throw new TypeError(`indent must be a string, got ${indent}`)\n }\n\n const errorRemappingCache = new WeakMap()\n const errorRemapFailureCallbackMap = new WeakMap()\n\n let installed = false\n const previousPrepareStackTrace = Error.prepareStackTrace\n const install = () => {\n if (installed) return\n installed = true\n Error.prepareStackTrace = prepareStackTrace\n }\n\n const uninstall = () => {\n if (!installed) return\n installed = false\n Error.prepareStackTrace = previousPrepareStackTrace\n }\n\n // ensure we do not use prepareStackTrace for thoose error\n // otherwise we would recursively remap error stack\n // and if the reason causing the failure is still here\n // it would create an infinite loop\n const readErrorStack = (error) => {\n uninstall()\n const stack = error.stack\n install()\n return stack\n }\n\n const prepareStackTrace = (error, stack) => {\n const onFailure = (failureData) => {\n const failureCallbackArray = errorRemapFailureCallbackMap.get(error)\n if (failureCallbackArray) {\n failureCallbackArray.forEach((callback) => callback(failureData))\n }\n }\n\n const stackRemappingPromise = getOriginalCallsites({\n stack,\n error,\n resolveFile,\n fetchFile: memoizeFetch(fetchFile),\n SourceMapConsumer,\n readErrorStack,\n indent,\n onFailure,\n })\n errorRemappingCache.set(error, stackRemappingPromise)\n\n return stackToString(stack, { error, indent })\n }\n\n const getErrorOriginalStackString = async (\n error,\n {\n onFailure = (message) => {\n console.warn(message)\n },\n } = {},\n ) => {\n if (onFailure) {\n const remapFailureCallbackArray = errorRemapFailureCallbackMap.get(error)\n if (remapFailureCallbackArray) {\n errorRemapFailureCallbackMap.set(error, [\n ...remapFailureCallbackArray,\n onFailure,\n ])\n } else {\n errorRemapFailureCallbackMap.set(error, [onFailure])\n }\n }\n\n // ensure Error.prepareStackTrace gets triggered by reading error.stack now\n const { stack } = error\n const promise = errorRemappingCache.get(error)\n\n if (promise) {\n try {\n const originalCallsites = await promise\n errorRemapFailureCallbackMap.get(error)\n\n const firstCall = originalCallsites[0]\n if (firstCall) {\n Object.assign(error, {\n filename: firstCall.getFileName(),\n lineno: firstCall.getLineNumber(),\n columnno: firstCall.getColumnNumber(),\n })\n }\n return stackToString(originalCallsites, { error, indent })\n } catch (e) {\n onFailure(\n createDetailedMessage(`error while computing original stack.`, {\n [\"stack from error while computing\"]: readErrorStack(e),\n [\"stack from error to remap\"]: stack,\n }),\n )\n return stack\n }\n }\n\n return stack\n }\n\n install()\n\n return { getErrorOriginalStackString, uninstall }\n}\n\nconst memoizeFetch = (fetchUrl) => {\n const urlCache = {}\n return async (url) => {\n if (url in urlCache) {\n return urlCache[url]\n }\n const responsePromise = fetchUrl(url)\n urlCache[url] = responsePromise\n return responsePromise\n }\n}\n",
|
|
116
116
|
"/* eslint-env browser */\n\nimport { installErrorStackRemapping } from \"./installErrorStackRemapping.js\"\n\nexport const installBrowserErrorStackRemapping = (options = {}) =>\n installErrorStackRemapping({\n fetchFile: async (url) => {\n // browser having Error.captureStackTrace got window.fetch\n // and this executes only when Error.captureStackTrace exists\n // so no need for polyfill or whatever here\n const response = await window.fetch(url, {\n // by default a script tag is in \"no-cors\"\n // so we also fetch url with \"no-cors\"\n mode: \"no-cors\",\n })\n // we read response test before anything because once memoized fetch\n // gets annoying preventing you to read\n // body multiple times, even using response.clone()\n const text = await response.text()\n return {\n status: response.status,\n url: response.url,\n statusText: response.statusText,\n headers: responseToHeaders(response),\n text: () => text,\n json: response.json.bind(response),\n blob: response.blob.bind(response),\n arrayBuffer: response.arrayBuffer.bind(response),\n }\n },\n resolveFile: (specifier, importer = window.location.href) => {\n // browsers having Error.captureStrackTrace got window.URL\n // and this executes only when Error.captureStackTrace exists\n return String(new URL(specifier, importer))\n },\n ...options,\n })\n\nconst responseToHeaders = (response) => {\n const headers = {}\n response.headers.forEach((value, name) => {\n headers[name] = value\n })\n return headers\n}\n",
|
|
117
117
|
"import { createDetailedMessage } from \"@jsenv/logger\"\nimport { fetchUrl } from \"./fetch-browser.js\"\n\nexport const fetchAndEvalUsingFetch = async (url) => {\n const response = await fetchUrl(url)\n\n if (response.status >= 200 && response.status <= 299) {\n const text = await response.text()\n // eslint-disable-next-line no-eval\n window.eval(appendSourceURL(text, url))\n } else {\n const text = await response.text()\n throw new Error(\n createDetailedMessage(`Unexpected response for script.`, {\n [\"script url\"]: url,\n [\"response body\"]: text,\n [\"response status\"]: response.status,\n }),\n )\n }\n}\n\nconst appendSourceURL = (code, sourceURL) => {\n return `${code}\n${\"//#\"} sourceURL=${sourceURL}`\n}\n",
|
|
118
|
-
"/* eslint-env browser */\n\nimport { unevalException } from \"../unevalException.js\"\nimport { createBrowserRuntime } from \"../runtime/createBrowserRuntime/createBrowserRuntime.js\"\nimport { installBrowserErrorStackRemapping } from \"../error-stack-remapping/installBrowserErrorStackRemapping.js\"\nimport { fetchUrl } from \"../browser-utils/fetch-browser.js\"\nimport { fetchAndEvalUsingFetch } from \"../browser-utils/fetchAndEvalUsingFetch.js\"\nimport { memoize } from \"../memoize.js\"\n\nconst getNavigationStartTime = () => {\n try {\n return window.performance.timing.navigationStart\n } catch (e) {\n return Date.now()\n }\n}\n\nconst navigationStartTime = getNavigationStartTime()\n\nconst readyPromise = new Promise((resolve) => {\n if (document.readyState === \"complete\") {\n resolve()\n } else {\n const loadCallback = () => {\n window.removeEventListener(\"load\", loadCallback)\n resolve()\n }\n window.addEventListener(\"load\", loadCallback)\n }\n})\n\nconst fileExecutionMap = {}\n\nconst executionResultPromise = readyPromise.then(async () => {\n const fileExecutionResultMap = {}\n const fileExecutionResultPromises = []\n let status = \"completed\"\n let exceptionSource = \"\"\n Object.keys(fileExecutionMap).forEach((key) => {\n fileExecutionResultMap[key] = null // to get always same order for Object.keys(executionResult)\n const fileExecutionResultPromise = fileExecutionMap[key]\n fileExecutionResultPromises.push(fileExecutionResultPromise)\n fileExecutionResultPromise.then((fileExecutionResult) => {\n fileExecutionResultMap[key] = fileExecutionResult\n if (fileExecutionResult.status === \"errored\") {\n status = \"errored\"\n exceptionSource = fileExecutionResult.exceptionSource\n }\n })\n })\n await Promise.all(fileExecutionResultPromises)\n\n return {\n status,\n ...(status === \"errored\" ? { exceptionSource } : {}),\n startTime: navigationStartTime,\n endTime: Date.now(),\n fileExecutionResultMap,\n }\n})\n\nconst executeFileUsingDynamicImport = async (\n specifier,\n identifier = specifier,\n) => {\n const { currentScript } = document\n const fileExecutionResultPromise = (async () => {\n try {\n const url = new URL(specifier, document.location.href).href\n performance.mark(`jsenv_file_import_start`)\n const namespace = await import(url)\n performance.measure(`jsenv_file_import`, `jsenv_file_import_start`)\n const executionResult = {\n status: \"completed\",\n namespace,\n }\n return executionResult\n } catch (e) {\n performance.measure(`jsenv_file_import`, `jsenv_file_import_start`)\n const executionResult = {\n status: \"errored\",\n exceptionSource: unevalException(e),\n }\n onExecutionError(executionResult, { currentScript })\n return executionResult\n }\n })()\n fileExecutionMap[identifier] = fileExecutionResultPromise\n return fileExecutionResultPromise\n}\n\nconst executeFileUsingSystemJs = (specifier) => {\n // si on a déja importer ce fichier ??\n // if (specifier in fileExecutionMap) {\n\n // }\n\n const { currentScript } = document\n\n const fileExecutionResultPromise = (async () => {\n const browserRuntime = await getBrowserRuntime()\n const executionResult = await browserRuntime.executeFile(specifier, {\n measurePerformance: true,\n collectPerformance: true,\n })\n if (executionResult.status === \"errored\") {\n onExecutionError(executionResult, { currentScript })\n }\n return executionResult\n })()\n fileExecutionMap[specifier] = fileExecutionResultPromise\n return fileExecutionResultPromise\n}\n\nconst onExecutionError = (executionResult, { currentScript }) => {\n // eslint-disable-next-line no-eval\n const originalError = window.eval(executionResult.exceptionSource)\n if (originalError.code === \"NETWORK_FAILURE\") {\n if (currentScript) {\n const errorEvent = new Event(\"error\")\n currentScript.dispatchEvent(errorEvent)\n }\n } else {\n const { parsingError } = originalError\n const globalErrorEvent = new Event(\"error\")\n if (parsingError) {\n globalErrorEvent.filename = parsingError.filename\n globalErrorEvent.lineno = parsingError.lineNumber\n globalErrorEvent.message = parsingError.message\n globalErrorEvent.colno = parsingError.columnNumber\n } else {\n globalErrorEvent.filename = originalError.filename\n globalErrorEvent.lineno = originalError.lineno\n globalErrorEvent.message = originalError.message\n globalErrorEvent.colno = originalError.columnno\n }\n window.dispatchEvent(globalErrorEvent)\n }\n}\n\nconst getBrowserRuntime = memoize(async () => {\n const compileServerOrigin = document.location.origin\n const compileMetaResponse = await fetchUrl(\n `${compileServerOrigin}/.jsenv/__compile_server_meta__.json`,\n )\n const compileMeta = await compileMetaResponse.json()\n const { outDirectoryRelativeUrl, errorStackRemapping } = compileMeta\n const outDirectoryUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`\n const afterOutDirectory = document.location.href.slice(outDirectoryUrl.length)\n const parts = afterOutDirectory.split(\"/\")\n const compileId = parts[0]\n\n const browserRuntime = await createBrowserRuntime({\n compileServerOrigin,\n outDirectoryRelativeUrl,\n compileId,\n })\n\n if (errorStackRemapping && Error.captureStackTrace) {\n const { sourcemapMainFileRelativeUrl, sourcemapMappingFileRelativeUrl } =\n compileMeta\n\n await fetchAndEvalUsingFetch(\n `${compileServerOrigin}/${sourcemapMainFileRelativeUrl}`,\n )\n const { SourceMapConsumer } = window.sourceMap\n SourceMapConsumer.initialize({\n \"lib/mappings.wasm\": `${compileServerOrigin}/${sourcemapMappingFileRelativeUrl}`,\n })\n const { getErrorOriginalStackString } = installBrowserErrorStackRemapping({\n SourceMapConsumer,\n })\n\n const errorTransform = async (error) => {\n // code can throw something else than an error\n // in that case return it unchanged\n if (!error || !(error instanceof Error)) return error\n const originalStack = await getErrorOriginalStackString(error)\n error.stack = originalStack\n return error\n }\n\n const executeFile = browserRuntime.executeFile\n browserRuntime.executeFile = (file, options = {}) => {\n return executeFile(file, { errorTransform, ...options })\n }\n }\n\n return browserRuntime\n})\n\nconst livereloadingCallbacks = {}\n\nwindow.__jsenv__ = {\n livereloadingCallbacks,\n executionResultPromise,\n executeFileUsingDynamicImport,\n executeFileUsingSystemJs,\n}\n"
|
|
118
|
+
"/* eslint-env browser */\r\n\r\nimport { unevalException } from \"../unevalException.js\"\r\nimport { createBrowserRuntime } from \"../runtime/createBrowserRuntime/createBrowserRuntime.js\"\r\nimport { installBrowserErrorStackRemapping } from \"../error-stack-remapping/installBrowserErrorStackRemapping.js\"\r\nimport { fetchUrl } from \"../browser-utils/fetch-browser.js\"\r\nimport { fetchAndEvalUsingFetch } from \"../browser-utils/fetchAndEvalUsingFetch.js\"\r\nimport { memoize } from \"../memoize.js\"\r\n\r\nconst getNavigationStartTime = () => {\r\n try {\r\n return window.performance.timing.navigationStart\r\n } catch (e) {\r\n return Date.now()\r\n }\r\n}\r\n\r\nconst navigationStartTime = getNavigationStartTime()\r\n\r\nconst readyPromise = new Promise((resolve) => {\r\n if (document.readyState === \"complete\") {\r\n resolve()\r\n } else {\r\n const loadCallback = () => {\r\n window.removeEventListener(\"load\", loadCallback)\r\n resolve()\r\n }\r\n window.addEventListener(\"load\", loadCallback)\r\n }\r\n})\r\n\r\nconst fileExecutionMap = {}\r\n\r\nconst executionResultPromise = readyPromise.then(async () => {\r\n const fileExecutionResultMap = {}\r\n const fileExecutionResultPromises = []\r\n let status = \"completed\"\r\n let exceptionSource = \"\"\r\n Object.keys(fileExecutionMap).forEach((key) => {\r\n fileExecutionResultMap[key] = null // to get always same order for Object.keys(executionResult)\r\n const fileExecutionResultPromise = fileExecutionMap[key]\r\n fileExecutionResultPromises.push(fileExecutionResultPromise)\r\n fileExecutionResultPromise.then((fileExecutionResult) => {\r\n fileExecutionResultMap[key] = fileExecutionResult\r\n if (fileExecutionResult.status === \"errored\") {\r\n status = \"errored\"\r\n exceptionSource = fileExecutionResult.exceptionSource\r\n }\r\n })\r\n })\r\n await Promise.all(fileExecutionResultPromises)\r\n\r\n return {\r\n status,\r\n ...(status === \"errored\" ? { exceptionSource } : {}),\r\n startTime: navigationStartTime,\r\n endTime: Date.now(),\r\n fileExecutionResultMap,\r\n }\r\n})\r\n\r\nconst executeFileUsingDynamicImport = async (\r\n specifier,\r\n identifier = specifier,\r\n) => {\r\n const { currentScript } = document\r\n const fileExecutionResultPromise = (async () => {\r\n try {\r\n const url = new URL(specifier, document.location.href).href\r\n performance.mark(`jsenv_file_import_start`)\r\n const namespace = await import(url)\r\n performance.measure(`jsenv_file_import`, `jsenv_file_import_start`)\r\n const executionResult = {\r\n status: \"completed\",\r\n namespace,\r\n }\r\n return executionResult\r\n } catch (e) {\r\n performance.measure(`jsenv_file_import`, `jsenv_file_import_start`)\r\n const executionResult = {\r\n status: \"errored\",\r\n exceptionSource: unevalException(e),\r\n }\r\n onExecutionError(executionResult, { currentScript })\r\n return executionResult\r\n }\r\n })()\r\n fileExecutionMap[identifier] = fileExecutionResultPromise\r\n return fileExecutionResultPromise\r\n}\r\n\r\nconst executeFileUsingSystemJs = (specifier) => {\r\n // si on a déja importer ce fichier ??\r\n // if (specifier in fileExecutionMap) {\r\n\r\n // }\r\n\r\n const { currentScript } = document\r\n\r\n const fileExecutionResultPromise = (async () => {\r\n const browserRuntime = await getBrowserRuntime()\r\n const executionResult = await browserRuntime.executeFile(specifier, {\r\n measurePerformance: true,\r\n collectPerformance: true,\r\n })\r\n if (executionResult.status === \"errored\") {\r\n onExecutionError(executionResult, { currentScript })\r\n }\r\n return executionResult\r\n })()\r\n fileExecutionMap[specifier] = fileExecutionResultPromise\r\n return fileExecutionResultPromise\r\n}\r\n\r\nconst onExecutionError = (executionResult, { currentScript }) => {\r\n // eslint-disable-next-line no-eval\r\n const originalError = window.eval(executionResult.exceptionSource)\r\n if (originalError.code === \"NETWORK_FAILURE\") {\r\n if (currentScript) {\r\n const errorEvent = new Event(\"error\")\r\n currentScript.dispatchEvent(errorEvent)\r\n }\r\n } else {\r\n const { parsingError } = originalError\r\n const globalErrorEvent = new Event(\"error\")\r\n if (parsingError) {\r\n globalErrorEvent.filename = parsingError.filename\r\n globalErrorEvent.lineno = parsingError.lineNumber\r\n globalErrorEvent.message = parsingError.message\r\n globalErrorEvent.colno = parsingError.columnNumber\r\n } else {\r\n globalErrorEvent.filename = originalError.filename\r\n globalErrorEvent.lineno = originalError.lineno\r\n globalErrorEvent.message = originalError.message\r\n globalErrorEvent.colno = originalError.columnno\r\n }\r\n window.dispatchEvent(globalErrorEvent)\r\n }\r\n}\r\n\r\nconst getBrowserRuntime = memoize(async () => {\r\n const compileServerOrigin = document.location.origin\r\n const compileMetaResponse = await fetchUrl(\r\n `${compileServerOrigin}/.jsenv/__compile_server_meta__.json`,\r\n )\r\n const compileMeta = await compileMetaResponse.json()\r\n const { outDirectoryRelativeUrl, errorStackRemapping } = compileMeta\r\n const outDirectoryUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`\r\n const afterOutDirectory = document.location.href.slice(outDirectoryUrl.length)\r\n const parts = afterOutDirectory.split(\"/\")\r\n const compileId = parts[0]\r\n\r\n const browserRuntime = await createBrowserRuntime({\r\n compileServerOrigin,\r\n outDirectoryRelativeUrl,\r\n compileId,\r\n })\r\n\r\n if (errorStackRemapping && Error.captureStackTrace) {\r\n const { sourcemapMainFileRelativeUrl, sourcemapMappingFileRelativeUrl } =\r\n compileMeta\r\n\r\n await fetchAndEvalUsingFetch(\r\n `${compileServerOrigin}/${sourcemapMainFileRelativeUrl}`,\r\n )\r\n const { SourceMapConsumer } = window.sourceMap\r\n SourceMapConsumer.initialize({\r\n \"lib/mappings.wasm\": `${compileServerOrigin}/${sourcemapMappingFileRelativeUrl}`,\r\n })\r\n const { getErrorOriginalStackString } = installBrowserErrorStackRemapping({\r\n SourceMapConsumer,\r\n })\r\n\r\n const errorTransform = async (error) => {\r\n // code can throw something else than an error\r\n // in that case return it unchanged\r\n if (!error || !(error instanceof Error)) return error\r\n const originalStack = await getErrorOriginalStackString(error)\r\n error.stack = originalStack\r\n return error\r\n }\r\n\r\n const executeFile = browserRuntime.executeFile\r\n browserRuntime.executeFile = (file, options = {}) => {\r\n return executeFile(file, { errorTransform, ...options })\r\n }\r\n }\r\n\r\n return browserRuntime\r\n})\r\n\r\nconst livereloadingCallbacks = {}\r\n\r\nwindow.__jsenv__ = {\r\n livereloadingCallbacks,\r\n executionResultPromise,\r\n executeFileUsingDynamicImport,\r\n executeFileUsingSystemJs,\r\n}\r\n"
|
|
119
119
|
],
|
|
120
120
|
"names": [
|
|
121
121
|
"obj",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"import { versionCompare } from \"./versionCompare.js\"\n\nexport const versionIsBelow = (versionSupposedBelow, versionSupposedAbove) => {\n return versionCompare(versionSupposedBelow, versionSupposedAbove) < 0\n}\n",
|
|
61
61
|
"import { versionIsBelow } from \"./versionIsBelow.js\"\n\nexport const findHighestVersion = (...values) => {\n if (values.length === 0) throw new Error(`missing argument`)\n\n return values.reduce((highestVersion, value) => {\n if (versionIsBelow(highestVersion, value)) {\n return value\n }\n return highestVersion\n })\n}\n",
|
|
62
62
|
"import { findHighestVersion } from \"../semantic-versioning/index.js\"\n\nexport const resolveGroup = ({ name, version }, groupMap) => {\n return Object.keys(groupMap).find((compileIdCandidate) => {\n const { minRuntimeVersions } = groupMap[compileIdCandidate]\n const versionForGroup = minRuntimeVersions[name]\n if (!versionForGroup) {\n return false\n }\n const highestVersion = findHighestVersion(version, versionForGroup)\n return highestVersion === version\n })\n}\n",
|
|
63
|
-
"import { fetchJson } from \"../../browser-utils/fetchJson.js\"\nimport { computeCompileIdFromGroupId } from \"../computeCompileIdFromGroupId.js\"\nimport { detectBrowser } from \"../detectBrowser/detectBrowser.js\"\nimport { resolveGroup } from \"../resolveGroup.js\"\n\nexport const scanBrowserRuntimeFeatures = async ({\n coverageHandledFromOutside = false,\n failFastOnFeatureDetection = false,\n} = {}) => {\n const {\n outDirectoryRelativeUrl,\n inlineImportMapIntoHTML,\n customCompilerPatterns,\n compileServerGroupMap,\n } = await fetchJson(\"/.jsenv/__compile_server_meta__.json\")\n\n const browser = detectBrowser()\n const compileId = computeCompileIdFromGroupId({\n groupId: resolveGroup(browser, compileServerGroupMap),\n groupMap: compileServerGroupMap,\n })\n const groupInfo = compileServerGroupMap[compileId]\n\n const featuresReport = {\n importmap: undefined,\n dynamicImport: undefined,\n topLevelAwait: undefined,\n jsonImportAssertions: undefined,\n cssImportAssertions: undefined,\n newStylesheet: undefined,\n }\n await detectSupportedFeatures({\n featuresReport,\n failFastOnFeatureDetection,\n inlineImportMapIntoHTML,\n })\n const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(\n groupInfo,\n {\n featuresReport,\n coverageHandledFromOutside,\n },\n )\n\n const canAvoidCompilation =\n customCompilerPatterns.length === 0 &&\n pluginRequiredNameArray.length === 0 &&\n featuresReport.importmap &&\n featuresReport.dynamicImport &&\n featuresReport.topLevelAwait\n\n return {\n canAvoidCompilation,\n featuresReport,\n customCompilerPatterns,\n pluginRequiredNameArray,\n inlineImportMapIntoHTML,\n outDirectoryRelativeUrl,\n compileId,\n browser,\n }\n}\n\nconst detectSupportedFeatures = async ({\n featuresReport,\n failFastOnFeatureDetection,\n inlineImportMapIntoHTML,\n}) => {\n // start testing importmap support first and not in paralell\n // so that there is not module script loaded beore importmap is injected\n // it would log an error in chrome console and return undefined\n const importmap = await supportsImportmap({\n // chrome supports inline but not remote importmap\n // https://github.com/WICG/import-maps/issues/235\n\n // at this stage we won't know if the html file will use\n // an importmap or not and if that importmap is inline or specified with an src\n // so we should test if browser support local and remote importmap.\n // But there exploring server can inline importmap by transforming html\n // and in that case we can test only the local importmap support\n // so we test importmap support and the remote one\n remote: !inlineImportMapIntoHTML,\n })\n featuresReport.importmap = importmap\n if (!importmap && failFastOnFeatureDetection) {\n return\n }\n\n const dynamicImport = await supportsDynamicImport()\n featuresReport.dynamicImport = dynamicImport\n if (!dynamicImport && failFastOnFeatureDetection) {\n return\n }\n\n const topLevelAwait = await supportsTopLevelAwait()\n featuresReport.topLevelAwait = topLevelAwait\n if (!topLevelAwait && failFastOnFeatureDetection) {\n return\n }\n}\n\nconst pluginRequiredNamesFromGroupInfo = async (\n groupInfo,\n { featuresReport, coverageHandledFromOutside },\n) => {\n const { pluginRequiredNameArray } = groupInfo\n const requiredPluginNames = pluginRequiredNameArray.slice()\n const markPluginAsSupported = (name) => {\n const index = requiredPluginNames.indexOf(name)\n if (index > -1) {\n requiredPluginNames.splice(index, 1)\n }\n }\n\n // When instrumentation CAN be handed by playwright\n // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions\n // coverageHandledFromOutside is true and \"transform-instrument\" becomes non mandatory\n if (coverageHandledFromOutside) {\n markPluginAsSupported(\"transform-instrument\")\n }\n\n if (pluginRequiredNameArray.includes(\"transform-import-assertions\")) {\n const jsonImportAssertions = await supportsJsonImportAssertions()\n featuresReport.jsonImportAssertions = jsonImportAssertions\n\n const cssImportAssertions = await supportsCssImportAssertions()\n featuresReport.cssImportAssertions = cssImportAssertions\n\n if (jsonImportAssertions && cssImportAssertions) {\n markPluginAsSupported(\"transform-import-assertions\")\n }\n }\n\n if (pluginRequiredNameArray.includes(\"new-stylesheet-as-jsenv-import\")) {\n const newStylesheet = supportsNewStylesheet()\n featuresReport.newStylesheet = newStylesheet\n markPluginAsSupported(\"new-stylesheet-as-jsenv-import\")\n }\n\n return requiredPluginNames\n}\n\nconst supportsNewStylesheet = () => {\n try {\n // eslint-disable-next-line no-new\n new CSSStyleSheet()\n return true\n } catch (e) {\n return false\n }\n}\n\nconst supportsImportmap = async ({ remote = true } = {}) => {\n const specifier = asBase64Url(`export default false`)\n\n const importMap = {\n imports: {\n [specifier]: asBase64Url(`export default true`),\n },\n }\n\n const importmapScript = document.createElement(\"script\")\n const importmapString = JSON.stringify(importMap, null, \" \")\n importmapScript.type = \"importmap\"\n if (remote) {\n importmapScript.src = `data:application/json;base64,${window.btoa(\n importmapString,\n )}`\n } else {\n importmapScript.textContent = importmapString\n }\n\n document.body.appendChild(importmapScript)\n\n const scriptModule = document.createElement(\"script\")\n scriptModule.type = \"module\"\n scriptModule.src = asBase64Url(\n `import supported from \"${specifier}\"; window.__importmap_supported = supported`,\n )\n\n return new Promise((resolve, reject) => {\n scriptModule.onload = () => {\n const supported = window.__importmap_supported\n delete window.__importmap_supported\n document.body.removeChild(scriptModule)\n document.body.removeChild(importmapScript)\n resolve(supported)\n }\n scriptModule.onerror = () => {\n document.body.removeChild(scriptModule)\n document.body.removeChild(importmapScript)\n reject()\n }\n document.body.appendChild(scriptModule)\n })\n}\n\nconst supportsDynamicImport = async () => {\n const moduleSource = asBase64Url(`export default 42`)\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsTopLevelAwait = async () => {\n const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsJsonImportAssertions = async () => {\n const jsonBase64Url = asBase64Url(\"42\", \"application/json\")\n const moduleSource = asBase64Url(\n `export { default } from \"${jsonBase64Url}\" assert { type: \"json\" }`,\n )\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsCssImportAssertions = async () => {\n const cssBase64Url = asBase64Url(\"p { color: red; }\", \"text/css\")\n const moduleSource = asBase64Url(\n `export { default } from \"${cssBase64Url}\" assert { type: \"css\" }`,\n )\n try {\n const namespace = await import(moduleSource)\n return namespace.default instanceof CSSStyleSheet\n } catch (e) {\n return false\n }\n}\n\nconst asBase64Url = (text, mimeType = \"application/javascript\") => {\n return `data:${mimeType};base64,${window.btoa(text)}`\n}\n",
|
|
63
|
+
"import { fetchJson } from \"../../browser-utils/fetchJson.js\"\r\nimport { computeCompileIdFromGroupId } from \"../computeCompileIdFromGroupId.js\"\r\nimport { detectBrowser } from \"../detectBrowser/detectBrowser.js\"\r\nimport { resolveGroup } from \"../resolveGroup.js\"\r\n\r\nexport const scanBrowserRuntimeFeatures = async ({\r\n coverageHandledFromOutside = false,\r\n failFastOnFeatureDetection = false,\r\n} = {}) => {\r\n const {\r\n outDirectoryRelativeUrl,\r\n inlineImportMapIntoHTML,\r\n customCompilerPatterns,\r\n compileServerGroupMap,\r\n } = await fetchJson(\"/.jsenv/__compile_server_meta__.json\")\r\n\r\n const browser = detectBrowser()\r\n const compileId = computeCompileIdFromGroupId({\r\n groupId: resolveGroup(browser, compileServerGroupMap),\r\n groupMap: compileServerGroupMap,\r\n })\r\n const groupInfo = compileServerGroupMap[compileId]\r\n\r\n const featuresReport = {\r\n importmap: undefined,\r\n dynamicImport: undefined,\r\n topLevelAwait: undefined,\r\n jsonImportAssertions: undefined,\r\n cssImportAssertions: undefined,\r\n newStylesheet: undefined,\r\n }\r\n await detectSupportedFeatures({\r\n featuresReport,\r\n failFastOnFeatureDetection,\r\n inlineImportMapIntoHTML,\r\n })\r\n const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(\r\n groupInfo,\r\n {\r\n featuresReport,\r\n coverageHandledFromOutside,\r\n },\r\n )\r\n\r\n const canAvoidCompilation =\r\n customCompilerPatterns.length === 0 &&\r\n pluginRequiredNameArray.length === 0 &&\r\n featuresReport.importmap &&\r\n featuresReport.dynamicImport &&\r\n featuresReport.topLevelAwait\r\n\r\n return {\r\n canAvoidCompilation,\r\n featuresReport,\r\n customCompilerPatterns,\r\n pluginRequiredNameArray,\r\n inlineImportMapIntoHTML,\r\n outDirectoryRelativeUrl,\r\n compileId,\r\n browser,\r\n }\r\n}\r\n\r\nconst detectSupportedFeatures = async ({\r\n featuresReport,\r\n failFastOnFeatureDetection,\r\n inlineImportMapIntoHTML,\r\n}) => {\r\n // start testing importmap support first and not in paralell\r\n // so that there is not module script loaded beore importmap is injected\r\n // it would log an error in chrome console and return undefined\r\n const importmap = await supportsImportmap({\r\n // chrome supports inline but not remote importmap\r\n // https://github.com/WICG/import-maps/issues/235\r\n\r\n // at this stage we won't know if the html file will use\r\n // an importmap or not and if that importmap is inline or specified with an src\r\n // so we should test if browser support local and remote importmap.\r\n // But there exploring server can inline importmap by transforming html\r\n // and in that case we can test only the local importmap support\r\n // so we test importmap support and the remote one\r\n remote: !inlineImportMapIntoHTML,\r\n })\r\n featuresReport.importmap = importmap\r\n if (!importmap && failFastOnFeatureDetection) {\r\n return\r\n }\r\n\r\n const dynamicImport = await supportsDynamicImport()\r\n featuresReport.dynamicImport = dynamicImport\r\n if (!dynamicImport && failFastOnFeatureDetection) {\r\n return\r\n }\r\n\r\n const topLevelAwait = await supportsTopLevelAwait()\r\n featuresReport.topLevelAwait = topLevelAwait\r\n if (!topLevelAwait && failFastOnFeatureDetection) {\r\n return\r\n }\r\n}\r\n\r\nconst pluginRequiredNamesFromGroupInfo = async (\r\n groupInfo,\r\n { featuresReport, coverageHandledFromOutside },\r\n) => {\r\n const { pluginRequiredNameArray } = groupInfo\r\n const requiredPluginNames = pluginRequiredNameArray.slice()\r\n const markPluginAsSupported = (name) => {\r\n const index = requiredPluginNames.indexOf(name)\r\n if (index > -1) {\r\n requiredPluginNames.splice(index, 1)\r\n }\r\n }\r\n\r\n // When instrumentation CAN be handed by playwright\r\n // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions\r\n // coverageHandledFromOutside is true and \"transform-instrument\" becomes non mandatory\r\n if (coverageHandledFromOutside) {\r\n markPluginAsSupported(\"transform-instrument\")\r\n }\r\n\r\n if (pluginRequiredNameArray.includes(\"transform-import-assertions\")) {\r\n const jsonImportAssertions = await supportsJsonImportAssertions()\r\n featuresReport.jsonImportAssertions = jsonImportAssertions\r\n\r\n const cssImportAssertions = await supportsCssImportAssertions()\r\n featuresReport.cssImportAssertions = cssImportAssertions\r\n\r\n if (jsonImportAssertions && cssImportAssertions) {\r\n markPluginAsSupported(\"transform-import-assertions\")\r\n }\r\n }\r\n\r\n if (pluginRequiredNameArray.includes(\"new-stylesheet-as-jsenv-import\")) {\r\n const newStylesheet = supportsNewStylesheet()\r\n featuresReport.newStylesheet = newStylesheet\r\n markPluginAsSupported(\"new-stylesheet-as-jsenv-import\")\r\n }\r\n\r\n return requiredPluginNames\r\n}\r\n\r\nconst supportsNewStylesheet = () => {\r\n try {\r\n // eslint-disable-next-line no-new\r\n new CSSStyleSheet()\r\n return true\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsImportmap = async ({ remote = true } = {}) => {\r\n const specifier = asBase64Url(`export default false`)\r\n\r\n const importMap = {\r\n imports: {\r\n [specifier]: asBase64Url(`export default true`),\r\n },\r\n }\r\n\r\n const importmapScript = document.createElement(\"script\")\r\n const importmapString = JSON.stringify(importMap, null, \" \")\r\n importmapScript.type = \"importmap\"\r\n if (remote) {\r\n importmapScript.src = `data:application/json;base64,${window.btoa(\r\n importmapString,\r\n )}`\r\n } else {\r\n importmapScript.textContent = importmapString\r\n }\r\n\r\n document.body.appendChild(importmapScript)\r\n\r\n const scriptModule = document.createElement(\"script\")\r\n scriptModule.type = \"module\"\r\n scriptModule.src = asBase64Url(\r\n `import supported from \"${specifier}\"; window.__importmap_supported = supported`,\r\n )\r\n\r\n return new Promise((resolve, reject) => {\r\n scriptModule.onload = () => {\r\n const supported = window.__importmap_supported\r\n delete window.__importmap_supported\r\n document.body.removeChild(scriptModule)\r\n document.body.removeChild(importmapScript)\r\n resolve(supported)\r\n }\r\n scriptModule.onerror = () => {\r\n document.body.removeChild(scriptModule)\r\n document.body.removeChild(importmapScript)\r\n reject()\r\n }\r\n document.body.appendChild(scriptModule)\r\n })\r\n}\r\n\r\nconst supportsDynamicImport = async () => {\r\n const moduleSource = asBase64Url(`export default 42`)\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsTopLevelAwait = async () => {\r\n const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsJsonImportAssertions = async () => {\r\n const jsonBase64Url = asBase64Url(\"42\", \"application/json\")\r\n const moduleSource = asBase64Url(\r\n `export { default } from \"${jsonBase64Url}\" assert { type: \"json\" }`,\r\n )\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsCssImportAssertions = async () => {\r\n const cssBase64Url = asBase64Url(\"p { color: red; }\", \"text/css\")\r\n const moduleSource = asBase64Url(\r\n `export { default } from \"${cssBase64Url}\" assert { type: \"css\" }`,\r\n )\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default instanceof CSSStyleSheet\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst asBase64Url = (text, mimeType = \"application/javascript\") => {\r\n return `data:${mimeType};base64,${window.btoa(text)}`\r\n}\r\n",
|
|
64
64
|
"/* eslint-env browser */\n\nimport { scanBrowserRuntimeFeatures } from \"../runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js\"\n\nwindow.scanBrowserRuntimeFeatures = scanBrowserRuntimeFeatures\n"
|
|
65
65
|
],
|
|
66
66
|
"names": [
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"import { versionCompare } from \"./versionCompare.js\"\n\nexport const versionIsBelow = (versionSupposedBelow, versionSupposedAbove) => {\n return versionCompare(versionSupposedBelow, versionSupposedAbove) < 0\n}\n",
|
|
74
74
|
"import { versionIsBelow } from \"./versionIsBelow.js\"\n\nexport const findHighestVersion = (...values) => {\n if (values.length === 0) throw new Error(`missing argument`)\n\n return values.reduce((highestVersion, value) => {\n if (versionIsBelow(highestVersion, value)) {\n return value\n }\n return highestVersion\n })\n}\n",
|
|
75
75
|
"import { findHighestVersion } from \"../semantic-versioning/index.js\"\n\nexport const resolveGroup = ({ name, version }, groupMap) => {\n return Object.keys(groupMap).find((compileIdCandidate) => {\n const { minRuntimeVersions } = groupMap[compileIdCandidate]\n const versionForGroup = minRuntimeVersions[name]\n if (!versionForGroup) {\n return false\n }\n const highestVersion = findHighestVersion(version, versionForGroup)\n return highestVersion === version\n })\n}\n",
|
|
76
|
-
"import { fetchJson } from \"../../browser-utils/fetchJson.js\"\nimport { computeCompileIdFromGroupId } from \"../computeCompileIdFromGroupId.js\"\nimport { detectBrowser } from \"../detectBrowser/detectBrowser.js\"\nimport { resolveGroup } from \"../resolveGroup.js\"\n\nexport const scanBrowserRuntimeFeatures = async ({\n coverageHandledFromOutside = false,\n failFastOnFeatureDetection = false,\n} = {}) => {\n const {\n outDirectoryRelativeUrl,\n inlineImportMapIntoHTML,\n customCompilerPatterns,\n compileServerGroupMap,\n } = await fetchJson(\"/.jsenv/__compile_server_meta__.json\")\n\n const browser = detectBrowser()\n const compileId = computeCompileIdFromGroupId({\n groupId: resolveGroup(browser, compileServerGroupMap),\n groupMap: compileServerGroupMap,\n })\n const groupInfo = compileServerGroupMap[compileId]\n\n const featuresReport = {\n importmap: undefined,\n dynamicImport: undefined,\n topLevelAwait: undefined,\n jsonImportAssertions: undefined,\n cssImportAssertions: undefined,\n newStylesheet: undefined,\n }\n await detectSupportedFeatures({\n featuresReport,\n failFastOnFeatureDetection,\n inlineImportMapIntoHTML,\n })\n const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(\n groupInfo,\n {\n featuresReport,\n coverageHandledFromOutside,\n },\n )\n\n const canAvoidCompilation =\n customCompilerPatterns.length === 0 &&\n pluginRequiredNameArray.length === 0 &&\n featuresReport.importmap &&\n featuresReport.dynamicImport &&\n featuresReport.topLevelAwait\n\n return {\n canAvoidCompilation,\n featuresReport,\n customCompilerPatterns,\n pluginRequiredNameArray,\n inlineImportMapIntoHTML,\n outDirectoryRelativeUrl,\n compileId,\n browser,\n }\n}\n\nconst detectSupportedFeatures = async ({\n featuresReport,\n failFastOnFeatureDetection,\n inlineImportMapIntoHTML,\n}) => {\n // start testing importmap support first and not in paralell\n // so that there is not module script loaded beore importmap is injected\n // it would log an error in chrome console and return undefined\n const importmap = await supportsImportmap({\n // chrome supports inline but not remote importmap\n // https://github.com/WICG/import-maps/issues/235\n\n // at this stage we won't know if the html file will use\n // an importmap or not and if that importmap is inline or specified with an src\n // so we should test if browser support local and remote importmap.\n // But there exploring server can inline importmap by transforming html\n // and in that case we can test only the local importmap support\n // so we test importmap support and the remote one\n remote: !inlineImportMapIntoHTML,\n })\n featuresReport.importmap = importmap\n if (!importmap && failFastOnFeatureDetection) {\n return\n }\n\n const dynamicImport = await supportsDynamicImport()\n featuresReport.dynamicImport = dynamicImport\n if (!dynamicImport && failFastOnFeatureDetection) {\n return\n }\n\n const topLevelAwait = await supportsTopLevelAwait()\n featuresReport.topLevelAwait = topLevelAwait\n if (!topLevelAwait && failFastOnFeatureDetection) {\n return\n }\n}\n\nconst pluginRequiredNamesFromGroupInfo = async (\n groupInfo,\n { featuresReport, coverageHandledFromOutside },\n) => {\n const { pluginRequiredNameArray } = groupInfo\n const requiredPluginNames = pluginRequiredNameArray.slice()\n const markPluginAsSupported = (name) => {\n const index = requiredPluginNames.indexOf(name)\n if (index > -1) {\n requiredPluginNames.splice(index, 1)\n }\n }\n\n // When instrumentation CAN be handed by playwright\n // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions\n // coverageHandledFromOutside is true and \"transform-instrument\" becomes non mandatory\n if (coverageHandledFromOutside) {\n markPluginAsSupported(\"transform-instrument\")\n }\n\n if (pluginRequiredNameArray.includes(\"transform-import-assertions\")) {\n const jsonImportAssertions = await supportsJsonImportAssertions()\n featuresReport.jsonImportAssertions = jsonImportAssertions\n\n const cssImportAssertions = await supportsCssImportAssertions()\n featuresReport.cssImportAssertions = cssImportAssertions\n\n if (jsonImportAssertions && cssImportAssertions) {\n markPluginAsSupported(\"transform-import-assertions\")\n }\n }\n\n if (pluginRequiredNameArray.includes(\"new-stylesheet-as-jsenv-import\")) {\n const newStylesheet = supportsNewStylesheet()\n featuresReport.newStylesheet = newStylesheet\n markPluginAsSupported(\"new-stylesheet-as-jsenv-import\")\n }\n\n return requiredPluginNames\n}\n\nconst supportsNewStylesheet = () => {\n try {\n // eslint-disable-next-line no-new\n new CSSStyleSheet()\n return true\n } catch (e) {\n return false\n }\n}\n\nconst supportsImportmap = async ({ remote = true } = {}) => {\n const specifier = asBase64Url(`export default false`)\n\n const importMap = {\n imports: {\n [specifier]: asBase64Url(`export default true`),\n },\n }\n\n const importmapScript = document.createElement(\"script\")\n const importmapString = JSON.stringify(importMap, null, \" \")\n importmapScript.type = \"importmap\"\n if (remote) {\n importmapScript.src = `data:application/json;base64,${window.btoa(\n importmapString,\n )}`\n } else {\n importmapScript.textContent = importmapString\n }\n\n document.body.appendChild(importmapScript)\n\n const scriptModule = document.createElement(\"script\")\n scriptModule.type = \"module\"\n scriptModule.src = asBase64Url(\n `import supported from \"${specifier}\"; window.__importmap_supported = supported`,\n )\n\n return new Promise((resolve, reject) => {\n scriptModule.onload = () => {\n const supported = window.__importmap_supported\n delete window.__importmap_supported\n document.body.removeChild(scriptModule)\n document.body.removeChild(importmapScript)\n resolve(supported)\n }\n scriptModule.onerror = () => {\n document.body.removeChild(scriptModule)\n document.body.removeChild(importmapScript)\n reject()\n }\n document.body.appendChild(scriptModule)\n })\n}\n\nconst supportsDynamicImport = async () => {\n const moduleSource = asBase64Url(`export default 42`)\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsTopLevelAwait = async () => {\n const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsJsonImportAssertions = async () => {\n const jsonBase64Url = asBase64Url(\"42\", \"application/json\")\n const moduleSource = asBase64Url(\n `export { default } from \"${jsonBase64Url}\" assert { type: \"json\" }`,\n )\n try {\n const namespace = await import(moduleSource)\n return namespace.default === 42\n } catch (e) {\n return false\n }\n}\n\nconst supportsCssImportAssertions = async () => {\n const cssBase64Url = asBase64Url(\"p { color: red; }\", \"text/css\")\n const moduleSource = asBase64Url(\n `export { default } from \"${cssBase64Url}\" assert { type: \"css\" }`,\n )\n try {\n const namespace = await import(moduleSource)\n return namespace.default instanceof CSSStyleSheet\n } catch (e) {\n return false\n }\n}\n\nconst asBase64Url = (text, mimeType = \"application/javascript\") => {\n return `data:${mimeType};base64,${window.btoa(text)}`\n}\n",
|
|
76
|
+
"import { fetchJson } from \"../../browser-utils/fetchJson.js\"\r\nimport { computeCompileIdFromGroupId } from \"../computeCompileIdFromGroupId.js\"\r\nimport { detectBrowser } from \"../detectBrowser/detectBrowser.js\"\r\nimport { resolveGroup } from \"../resolveGroup.js\"\r\n\r\nexport const scanBrowserRuntimeFeatures = async ({\r\n coverageHandledFromOutside = false,\r\n failFastOnFeatureDetection = false,\r\n} = {}) => {\r\n const {\r\n outDirectoryRelativeUrl,\r\n inlineImportMapIntoHTML,\r\n customCompilerPatterns,\r\n compileServerGroupMap,\r\n } = await fetchJson(\"/.jsenv/__compile_server_meta__.json\")\r\n\r\n const browser = detectBrowser()\r\n const compileId = computeCompileIdFromGroupId({\r\n groupId: resolveGroup(browser, compileServerGroupMap),\r\n groupMap: compileServerGroupMap,\r\n })\r\n const groupInfo = compileServerGroupMap[compileId]\r\n\r\n const featuresReport = {\r\n importmap: undefined,\r\n dynamicImport: undefined,\r\n topLevelAwait: undefined,\r\n jsonImportAssertions: undefined,\r\n cssImportAssertions: undefined,\r\n newStylesheet: undefined,\r\n }\r\n await detectSupportedFeatures({\r\n featuresReport,\r\n failFastOnFeatureDetection,\r\n inlineImportMapIntoHTML,\r\n })\r\n const pluginRequiredNameArray = await pluginRequiredNamesFromGroupInfo(\r\n groupInfo,\r\n {\r\n featuresReport,\r\n coverageHandledFromOutside,\r\n },\r\n )\r\n\r\n const canAvoidCompilation =\r\n customCompilerPatterns.length === 0 &&\r\n pluginRequiredNameArray.length === 0 &&\r\n featuresReport.importmap &&\r\n featuresReport.dynamicImport &&\r\n featuresReport.topLevelAwait\r\n\r\n return {\r\n canAvoidCompilation,\r\n featuresReport,\r\n customCompilerPatterns,\r\n pluginRequiredNameArray,\r\n inlineImportMapIntoHTML,\r\n outDirectoryRelativeUrl,\r\n compileId,\r\n browser,\r\n }\r\n}\r\n\r\nconst detectSupportedFeatures = async ({\r\n featuresReport,\r\n failFastOnFeatureDetection,\r\n inlineImportMapIntoHTML,\r\n}) => {\r\n // start testing importmap support first and not in paralell\r\n // so that there is not module script loaded beore importmap is injected\r\n // it would log an error in chrome console and return undefined\r\n const importmap = await supportsImportmap({\r\n // chrome supports inline but not remote importmap\r\n // https://github.com/WICG/import-maps/issues/235\r\n\r\n // at this stage we won't know if the html file will use\r\n // an importmap or not and if that importmap is inline or specified with an src\r\n // so we should test if browser support local and remote importmap.\r\n // But there exploring server can inline importmap by transforming html\r\n // and in that case we can test only the local importmap support\r\n // so we test importmap support and the remote one\r\n remote: !inlineImportMapIntoHTML,\r\n })\r\n featuresReport.importmap = importmap\r\n if (!importmap && failFastOnFeatureDetection) {\r\n return\r\n }\r\n\r\n const dynamicImport = await supportsDynamicImport()\r\n featuresReport.dynamicImport = dynamicImport\r\n if (!dynamicImport && failFastOnFeatureDetection) {\r\n return\r\n }\r\n\r\n const topLevelAwait = await supportsTopLevelAwait()\r\n featuresReport.topLevelAwait = topLevelAwait\r\n if (!topLevelAwait && failFastOnFeatureDetection) {\r\n return\r\n }\r\n}\r\n\r\nconst pluginRequiredNamesFromGroupInfo = async (\r\n groupInfo,\r\n { featuresReport, coverageHandledFromOutside },\r\n) => {\r\n const { pluginRequiredNameArray } = groupInfo\r\n const requiredPluginNames = pluginRequiredNameArray.slice()\r\n const markPluginAsSupported = (name) => {\r\n const index = requiredPluginNames.indexOf(name)\r\n if (index > -1) {\r\n requiredPluginNames.splice(index, 1)\r\n }\r\n }\r\n\r\n // When instrumentation CAN be handed by playwright\r\n // https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions\r\n // coverageHandledFromOutside is true and \"transform-instrument\" becomes non mandatory\r\n if (coverageHandledFromOutside) {\r\n markPluginAsSupported(\"transform-instrument\")\r\n }\r\n\r\n if (pluginRequiredNameArray.includes(\"transform-import-assertions\")) {\r\n const jsonImportAssertions = await supportsJsonImportAssertions()\r\n featuresReport.jsonImportAssertions = jsonImportAssertions\r\n\r\n const cssImportAssertions = await supportsCssImportAssertions()\r\n featuresReport.cssImportAssertions = cssImportAssertions\r\n\r\n if (jsonImportAssertions && cssImportAssertions) {\r\n markPluginAsSupported(\"transform-import-assertions\")\r\n }\r\n }\r\n\r\n if (pluginRequiredNameArray.includes(\"new-stylesheet-as-jsenv-import\")) {\r\n const newStylesheet = supportsNewStylesheet()\r\n featuresReport.newStylesheet = newStylesheet\r\n markPluginAsSupported(\"new-stylesheet-as-jsenv-import\")\r\n }\r\n\r\n return requiredPluginNames\r\n}\r\n\r\nconst supportsNewStylesheet = () => {\r\n try {\r\n // eslint-disable-next-line no-new\r\n new CSSStyleSheet()\r\n return true\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsImportmap = async ({ remote = true } = {}) => {\r\n const specifier = asBase64Url(`export default false`)\r\n\r\n const importMap = {\r\n imports: {\r\n [specifier]: asBase64Url(`export default true`),\r\n },\r\n }\r\n\r\n const importmapScript = document.createElement(\"script\")\r\n const importmapString = JSON.stringify(importMap, null, \" \")\r\n importmapScript.type = \"importmap\"\r\n if (remote) {\r\n importmapScript.src = `data:application/json;base64,${window.btoa(\r\n importmapString,\r\n )}`\r\n } else {\r\n importmapScript.textContent = importmapString\r\n }\r\n\r\n document.body.appendChild(importmapScript)\r\n\r\n const scriptModule = document.createElement(\"script\")\r\n scriptModule.type = \"module\"\r\n scriptModule.src = asBase64Url(\r\n `import supported from \"${specifier}\"; window.__importmap_supported = supported`,\r\n )\r\n\r\n return new Promise((resolve, reject) => {\r\n scriptModule.onload = () => {\r\n const supported = window.__importmap_supported\r\n delete window.__importmap_supported\r\n document.body.removeChild(scriptModule)\r\n document.body.removeChild(importmapScript)\r\n resolve(supported)\r\n }\r\n scriptModule.onerror = () => {\r\n document.body.removeChild(scriptModule)\r\n document.body.removeChild(importmapScript)\r\n reject()\r\n }\r\n document.body.appendChild(scriptModule)\r\n })\r\n}\r\n\r\nconst supportsDynamicImport = async () => {\r\n const moduleSource = asBase64Url(`export default 42`)\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsTopLevelAwait = async () => {\r\n const moduleSource = asBase64Url(`export default await Promise.resolve(42)`)\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsJsonImportAssertions = async () => {\r\n const jsonBase64Url = asBase64Url(\"42\", \"application/json\")\r\n const moduleSource = asBase64Url(\r\n `export { default } from \"${jsonBase64Url}\" assert { type: \"json\" }`,\r\n )\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default === 42\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst supportsCssImportAssertions = async () => {\r\n const cssBase64Url = asBase64Url(\"p { color: red; }\", \"text/css\")\r\n const moduleSource = asBase64Url(\r\n `export { default } from \"${cssBase64Url}\" assert { type: \"css\" }`,\r\n )\r\n try {\r\n const namespace = await import(moduleSource)\r\n return namespace.default instanceof CSSStyleSheet\r\n } catch (e) {\r\n return false\r\n }\r\n}\r\n\r\nconst asBase64Url = (text, mimeType = \"application/javascript\") => {\r\n return `data:${mimeType};base64,${window.btoa(text)}`\r\n}\r\n",
|
|
77
77
|
"import { createDetailedMessage } from \"@jsenv/logger\"\n\nimport { fetchJson } from \"../browser-utils/fetchJson.js\"\n\nexport const fetchExploringJson = async ({ signal } = {}) => {\n try {\n const exploringInfo = await fetchJson(\"/.jsenv/exploring.json\", {\n signal,\n })\n return exploringInfo\n } catch (e) {\n if (signal && signal.aborted && e.name === \"AbortError\") {\n throw e\n }\n throw new Error(\n createDetailedMessage(\n `Cannot communicate with exploring server due to a network error`,\n {\n [\"error stack\"]: e.stack,\n },\n ),\n )\n }\n}\n",
|
|
78
78
|
"import { scanBrowserRuntimeFeatures } from \"../runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js\"\nimport { fetchExploringJson } from \"./fetchExploringJson.js\"\n\nconst redirect = async () => {\n const [browserRuntimeFeaturesReport, { exploringHtmlFileRelativeUrl }] =\n await Promise.all([\n scanBrowserRuntimeFeatures({\n failFastOnFeatureDetection: true,\n }),\n fetchExploringJson(),\n ])\n\n if (browserRuntimeFeaturesReport.canAvoidCompilation) {\n window.location.href = `/${exploringHtmlFileRelativeUrl}`\n return\n }\n\n const { outDirectoryRelativeUrl, compileId } = browserRuntimeFeaturesReport\n window.location.href = `/${outDirectoryRelativeUrl}${compileId}/${exploringHtmlFileRelativeUrl}`\n}\n\nredirect()\n"
|
|
79
79
|
],
|
package/dist/jsenv_toolbar.js
CHANGED
|
@@ -3108,8 +3108,6 @@
|
|
|
3108
3108
|
document.querySelector("#overflow-menu").removeAttribute("data-animate");
|
|
3109
3109
|
};
|
|
3110
3110
|
|
|
3111
|
-
/* eslint-disable import/max-dependencies */
|
|
3112
|
-
|
|
3113
3111
|
function _call(body, then, direct) {
|
|
3114
3112
|
if (direct) {
|
|
3115
3113
|
return then ? then(body()) : body();
|