@jsenv/core 27.0.0-alpha.63 → 27.0.0-alpha.66
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/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
- package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
- package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
- package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
- package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
- package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
- package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
- package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
- package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
- package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
- package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
- package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
- package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
- package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
- package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
- package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
- package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
- package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
- package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
- package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
- package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
- package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/construct/construct.js +15 -0
- package/dist/babel_helpers/createClass/createClass.js +18 -0
- package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
- package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
- package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
- package/dist/babel_helpers/createSuper/createSuper.js +22 -0
- package/dist/babel_helpers/decorate/decorate.js +622 -0
- package/dist/babel_helpers/defaults/defaults.js +14 -0
- package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
- package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
- package/dist/babel_helpers/extends/extends.js +16 -0
- package/dist/babel_helpers/get/get.js +21 -0
- package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
- package/dist/babel_helpers/inherits/inherits.js +21 -0
- package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
- package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
- package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
- package/dist/babel_helpers/instanceof/instanceof.js +7 -0
- package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
- package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
- package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
- package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
- package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
- package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
- package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
- package/dist/babel_helpers/jsx/jsx.js +49 -0
- package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
- package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
- package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
- package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
- package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
- package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
- package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
- package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
- package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
- package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
- package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
- package/dist/babel_helpers/readme.md +8 -0
- package/dist/babel_helpers/set/set.js +51 -0
- package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
- package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
- package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
- package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
- package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
- package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
- package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
- package/dist/babel_helpers/tdz/tdz.js +4 -0
- package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
- package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
- package/dist/babel_helpers/toArray/toArray.js +5 -0
- package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
- package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
- package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
- package/dist/babel_helpers/typeof/typeof.js +7 -0
- package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
- package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
- package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
- package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
- package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
- package/dist/html/explorer.html +557 -0
- package/dist/js/controllable_file.mjs +227 -0
- package/dist/{event_source_client.js → js/event_source_client.js} +19 -244
- package/dist/js/global_this.js +32 -0
- package/dist/js/html_supervisor_installer.js +522 -0
- package/dist/js/html_supervisor_setup.js +79 -0
- package/dist/{import_meta_hot.js → js/import_meta_hot.js} +1 -3
- package/dist/js/inline_content.js +8 -0
- package/dist/js/new_stylesheet.js +409 -0
- package/dist/js/regenerator_runtime.js +721 -0
- package/dist/js/s.js +429 -0
- package/dist/main.js +13383 -0
- package/dist/other/jsenv.png +0 -0
- package/main.js +1 -0
- package/package.json +18 -14
- package/src/build/build.js +175 -69
- package/src/build/build_urls_generator.js +18 -2
- package/src/build/inject_global_version_mappings.js +18 -5
- package/src/build/inject_service_worker_urls.js +1 -1
- package/src/build/resync_ressource_hints.js +56 -9
- package/src/build/start_build_server.js +38 -29
- package/src/dev/plugins/explorer/client/explorer.html +1 -1
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
- package/src/dev/start_dev_server.js +18 -4
- package/src/execute/execute.js +3 -0
- package/src/execute/runtimes/browsers/from_playwright.js +10 -0
- package/src/execute/runtimes/node/node_process.js +8 -0
- package/src/omega/errors.js +10 -7
- package/src/omega/kitchen.js +251 -340
- package/src/omega/server/file_service.js +34 -17
- package/src/omega/url_graph/url_graph_load.js +10 -17
- package/src/omega/url_graph/url_graph_report.js +2 -2
- package/src/omega/url_graph/url_info_transformations.js +1 -4
- package/src/omega/url_graph.js +7 -3
- package/src/omega/url_specifier_encoding.js +59 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +5 -10
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +1 -3
- package/src/plugins/bundling/js_module/bundle_js_module.js +66 -24
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +178 -53
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +9 -13
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +6 -6
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +5 -10
- package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
- package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
- package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +16 -2
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
- package/src/plugins/plugin_controller.js +17 -3
- package/src/plugins/plugins.js +15 -15
- package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +20 -10
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +302 -0
- package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +2 -0
- package/src/plugins/url_analysis/html/html_urls.js +3 -0
- package/src/plugins/url_analysis/js/js_urls.js +2 -1
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +94 -1
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +3 -0
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +0 -3
- package/src/test/execute_plan.js +34 -13
- package/src/test/execute_test_plan.js +2 -0
- package/src/test/logs_file_execution.js +47 -38
- package/dist/event_source_client.js.map +0 -188
- package/dist/html_supervisor_installer.js +0 -1236
- package/dist/html_supervisor_installer.js.map +0 -337
- package/dist/html_supervisor_setup.js +0 -95
- package/dist/html_supervisor_setup.js.map +0 -57
- package/dist/import_meta_hot.js.map +0 -42
- package/src/jsenv_root_directory_url.js +0 -1
- package/src/omega/compat/default_runtime_compat.js +0 -11
- package/src/plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -61
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +0 -270
- package/src/plugins/transpilation/babel/new_stylesheet/client/.eslintrc.cjs +0 -24
- package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
|
@@ -19,31 +19,42 @@ import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
|
19
19
|
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
20
20
|
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
21
21
|
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
22
|
+
import { fetchOriginalUrlInfo } from "@jsenv/utils/graph/fetch_original_url_info.js"
|
|
22
23
|
|
|
23
|
-
import { fetchOriginalUrlInfo } from "../fetch_original_url_info.js"
|
|
24
24
|
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
25
|
+
import { jsenvPluginAsJsClassicHtml } from "./jsenv_plugin_as_js_classic_html.js"
|
|
26
|
+
import { jsenvPluginAsJsClassicWorkers } from "./jsenv_plugin_as_js_classic_workers.js"
|
|
27
27
|
|
|
28
28
|
const require = createRequire(import.meta.url)
|
|
29
29
|
|
|
30
30
|
export const jsenvPluginAsJsClassic = ({ systemJsInjection }) => {
|
|
31
|
-
const systemJsClientFileUrl = new URL(
|
|
31
|
+
const systemJsClientFileUrl = new URL(
|
|
32
|
+
"./client/s.js?js_classic",
|
|
33
|
+
import.meta.url,
|
|
34
|
+
).href
|
|
32
35
|
|
|
33
36
|
return [
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
jsenvPluginAsJsClassicConversion({
|
|
38
|
+
systemJsInjection,
|
|
39
|
+
systemJsClientFileUrl,
|
|
40
|
+
}),
|
|
41
|
+
jsenvPluginAsJsClassicHtml({
|
|
36
42
|
systemJsInjection,
|
|
37
43
|
systemJsClientFileUrl,
|
|
38
44
|
generateJsClassicFilename,
|
|
39
45
|
}),
|
|
40
|
-
|
|
46
|
+
jsenvPluginAsJsClassicWorkers({
|
|
41
47
|
generateJsClassicFilename,
|
|
42
48
|
}),
|
|
43
49
|
]
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
// propagate ?as_js_classic to referenced urls
|
|
53
|
+
// and perform the conversion during fetchUrlContent
|
|
54
|
+
const jsenvPluginAsJsClassicConversion = ({
|
|
55
|
+
systemJsInjection,
|
|
56
|
+
systemJsClientFileUrl,
|
|
57
|
+
}) => {
|
|
47
58
|
const propagateJsClassicSearchParam = (reference, context) => {
|
|
48
59
|
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
49
60
|
if (
|
|
@@ -60,9 +71,8 @@ const asJsClassic = ({ systemJsInjection, systemJsClientFileUrl }) => {
|
|
|
60
71
|
}
|
|
61
72
|
|
|
62
73
|
return {
|
|
63
|
-
name: "jsenv:
|
|
74
|
+
name: "jsenv:as_js_classic_conversion",
|
|
64
75
|
appliesDuring: "*",
|
|
65
|
-
// forward ?as_js_classic to referenced urls
|
|
66
76
|
redirectUrl: {
|
|
67
77
|
// We want to propagate transformation of js module to js classic to:
|
|
68
78
|
// - import specifier (static/dynamic import + re-export)
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHtmlNodeAttributeByName,
|
|
3
|
+
getHtmlNodeTextNode,
|
|
4
|
+
parseHtmlString,
|
|
5
|
+
removeHtmlNodeAttributeByName,
|
|
6
|
+
assignHtmlNodeAttributes,
|
|
7
|
+
stringifyHtmlAst,
|
|
8
|
+
visitHtmlAst,
|
|
9
|
+
htmlNodePosition,
|
|
10
|
+
setHtmlNodeGeneratedText,
|
|
11
|
+
injectScriptAsEarlyAsPossible,
|
|
12
|
+
createHtmlNode,
|
|
13
|
+
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
14
|
+
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
15
|
+
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
16
|
+
|
|
17
|
+
export const jsenvPluginAsJsClassicHtml = ({
|
|
18
|
+
systemJsInjection,
|
|
19
|
+
systemJsClientFileUrl,
|
|
20
|
+
generateJsClassicFilename,
|
|
21
|
+
}) => {
|
|
22
|
+
return {
|
|
23
|
+
name: "jsenv:as_js_classic_html",
|
|
24
|
+
appliesDuring: "*",
|
|
25
|
+
transformUrlContent: {
|
|
26
|
+
html: async (urlInfo, context) => {
|
|
27
|
+
const shouldTransformScriptTypeModule =
|
|
28
|
+
!context.isSupportedOnCurrentClients("script_type_module") ||
|
|
29
|
+
!context.isSupportedOnCurrentClients("import_dynamic")
|
|
30
|
+
const htmlAst = parseHtmlString(urlInfo.content)
|
|
31
|
+
const preloadAsScriptNodes = []
|
|
32
|
+
const modulePreloadNodes = []
|
|
33
|
+
const moduleScriptNodes = []
|
|
34
|
+
const classicScriptNodes = []
|
|
35
|
+
const visitLinkNodes = (node) => {
|
|
36
|
+
if (node.nodeName !== "link") {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
const relAttribute = getHtmlNodeAttributeByName(node, "rel")
|
|
40
|
+
const rel = relAttribute ? relAttribute.value : undefined
|
|
41
|
+
if (rel === "modulepreload") {
|
|
42
|
+
modulePreloadNodes.push(node)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
if (rel === "preload") {
|
|
46
|
+
const asAttribute = getHtmlNodeAttributeByName(node, "as")
|
|
47
|
+
const asValue = asAttribute ? asAttribute.value : undefined
|
|
48
|
+
if (asValue === "script") {
|
|
49
|
+
preloadAsScriptNodes.push(node)
|
|
50
|
+
}
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const visitScriptNodes = (node) => {
|
|
55
|
+
if (node.nodeName !== "script") {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
const typeAttribute = getHtmlNodeAttributeByName(node, "type")
|
|
59
|
+
const type = typeAttribute ? typeAttribute.value : undefined
|
|
60
|
+
if (type === "module") {
|
|
61
|
+
moduleScriptNodes.push(node)
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
if (type === undefined || type === "text/javascript") {
|
|
65
|
+
classicScriptNodes.push(node)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
visitHtmlAst(htmlAst, (node) => {
|
|
70
|
+
visitLinkNodes(node)
|
|
71
|
+
visitScriptNodes(node)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const actions = []
|
|
75
|
+
const jsModuleUrls = []
|
|
76
|
+
const convertedUrls = []
|
|
77
|
+
const getReferenceAsJsClassic = async (
|
|
78
|
+
reference,
|
|
79
|
+
{
|
|
80
|
+
// we don't cook ressource hints
|
|
81
|
+
// because they might refer to ressource that will be modified during build
|
|
82
|
+
// It also means something else HAVE to reference that url in order to cook it
|
|
83
|
+
// so that the preload is deleted by "resync_ressource_hints.js" otherwise
|
|
84
|
+
cookIt = false,
|
|
85
|
+
} = {},
|
|
86
|
+
) => {
|
|
87
|
+
const newReferenceProps = {
|
|
88
|
+
expectedType: "js_classic",
|
|
89
|
+
specifier: injectQueryParamsIntoSpecifier(reference.specifier, {
|
|
90
|
+
as_js_classic: "",
|
|
91
|
+
}),
|
|
92
|
+
filename: generateJsClassicFilename(reference.url),
|
|
93
|
+
}
|
|
94
|
+
const [newReference, newUrlInfo] = context.referenceUtils.update(
|
|
95
|
+
reference,
|
|
96
|
+
newReferenceProps,
|
|
97
|
+
)
|
|
98
|
+
const convertedUrl = newUrlInfo.url
|
|
99
|
+
if (!convertedUrls.includes(convertedUrl)) {
|
|
100
|
+
convertedUrls.push(convertedUrl)
|
|
101
|
+
}
|
|
102
|
+
if (cookIt) {
|
|
103
|
+
// during dev it means js modules will be cooked before server sends the HTML
|
|
104
|
+
// it's ok because:
|
|
105
|
+
// - during dev script_type_module are supported (dev use a recent browser)
|
|
106
|
+
// - even if browser is not supported it still works it's jus a bit slower
|
|
107
|
+
// because it needs to decide if systemjs will be injected or not
|
|
108
|
+
await context.cook(newUrlInfo, { reference: newReference })
|
|
109
|
+
}
|
|
110
|
+
return [newReference, newUrlInfo]
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
classicScriptNodes.forEach((classicScriptNode) => {
|
|
114
|
+
const srcAttribute = getHtmlNodeAttributeByName(
|
|
115
|
+
classicScriptNode,
|
|
116
|
+
"src",
|
|
117
|
+
)
|
|
118
|
+
if (srcAttribute) {
|
|
119
|
+
const reference = urlInfo.references.find(
|
|
120
|
+
(ref) =>
|
|
121
|
+
ref.generatedSpecifier === srcAttribute.value &&
|
|
122
|
+
ref.type === "script_src",
|
|
123
|
+
)
|
|
124
|
+
const urlObject = new URL(reference.url)
|
|
125
|
+
if (urlObject.searchParams.has("as_js_classic")) {
|
|
126
|
+
const convertedUrl = urlObject.href
|
|
127
|
+
convertedUrls.push(convertedUrl)
|
|
128
|
+
urlObject.searchParams.delete("as_js_classic")
|
|
129
|
+
const jsModuleUrl = urlObject.href
|
|
130
|
+
jsModuleUrls.push(jsModuleUrl)
|
|
131
|
+
actions.push(async () => {
|
|
132
|
+
const urlInfo = context.urlGraph.getUrlInfo(convertedUrl)
|
|
133
|
+
await context.cook(urlInfo, { reference })
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
moduleScriptNodes.forEach((moduleScriptNode) => {
|
|
139
|
+
const srcAttribute = getHtmlNodeAttributeByName(
|
|
140
|
+
moduleScriptNode,
|
|
141
|
+
"src",
|
|
142
|
+
)
|
|
143
|
+
if (srcAttribute) {
|
|
144
|
+
const reference = urlInfo.references.find(
|
|
145
|
+
(ref) =>
|
|
146
|
+
ref.generatedSpecifier === srcAttribute.value &&
|
|
147
|
+
ref.type === "script_src" &&
|
|
148
|
+
ref.expectedType === "js_module",
|
|
149
|
+
)
|
|
150
|
+
jsModuleUrls.push(reference.url)
|
|
151
|
+
if (shouldTransformScriptTypeModule) {
|
|
152
|
+
actions.push(async () => {
|
|
153
|
+
const [newReference] = await getReferenceAsJsClassic(
|
|
154
|
+
reference,
|
|
155
|
+
{
|
|
156
|
+
cookIt: true,
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
removeHtmlNodeAttributeByName(moduleScriptNode, "type")
|
|
160
|
+
srcAttribute.value = newReference.generatedSpecifier
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
if (shouldTransformScriptTypeModule) {
|
|
166
|
+
const textNode = getHtmlNodeTextNode(moduleScriptNode)
|
|
167
|
+
actions.push(async () => {
|
|
168
|
+
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
169
|
+
htmlNodePosition.readNodePosition(moduleScriptNode, {
|
|
170
|
+
preferOriginal: true,
|
|
171
|
+
})
|
|
172
|
+
let inlineScriptUrl = generateInlineContentUrl({
|
|
173
|
+
url: urlInfo.url,
|
|
174
|
+
extension: ".js",
|
|
175
|
+
line,
|
|
176
|
+
column,
|
|
177
|
+
lineEnd,
|
|
178
|
+
columnEnd,
|
|
179
|
+
})
|
|
180
|
+
const [inlineReference] = context.referenceUtils.foundInline({
|
|
181
|
+
node: moduleScriptNode,
|
|
182
|
+
type: "script_src",
|
|
183
|
+
expectedType: "js_module",
|
|
184
|
+
isOriginalPosition: isOriginal,
|
|
185
|
+
// we remove 1 to the line because imagine the following html:
|
|
186
|
+
// <script>console.log('ok')</script>
|
|
187
|
+
// -> content starts same line as <script>
|
|
188
|
+
specifierLine: line - 1,
|
|
189
|
+
specifierColumn: column,
|
|
190
|
+
specifier: inlineScriptUrl,
|
|
191
|
+
contentType: "application/javascript",
|
|
192
|
+
content: textNode.value,
|
|
193
|
+
})
|
|
194
|
+
const [, newUrlInfo] = await getReferenceAsJsClassic(
|
|
195
|
+
inlineReference,
|
|
196
|
+
{ cookIt: true },
|
|
197
|
+
)
|
|
198
|
+
removeHtmlNodeAttributeByName(moduleScriptNode, "type")
|
|
199
|
+
setHtmlNodeGeneratedText(moduleScriptNode, {
|
|
200
|
+
generatedText: newUrlInfo.content,
|
|
201
|
+
generatedBy: "jsenv:as_js_classic_html",
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
if (shouldTransformScriptTypeModule) {
|
|
207
|
+
preloadAsScriptNodes.forEach((preloadAsScriptNode) => {
|
|
208
|
+
const hrefAttribute = getHtmlNodeAttributeByName(
|
|
209
|
+
preloadAsScriptNode,
|
|
210
|
+
"href",
|
|
211
|
+
)
|
|
212
|
+
const href = hrefAttribute.value
|
|
213
|
+
const reference = urlInfo.references.find(
|
|
214
|
+
(ref) =>
|
|
215
|
+
ref.generatedSpecifier === href &&
|
|
216
|
+
ref.type === "link_href" &&
|
|
217
|
+
ref.expectedType === undefined,
|
|
218
|
+
)
|
|
219
|
+
const expectedScriptType = jsModuleUrls.includes(reference.url)
|
|
220
|
+
? "module"
|
|
221
|
+
: "classic"
|
|
222
|
+
if (expectedScriptType === "module") {
|
|
223
|
+
actions.push(async () => {
|
|
224
|
+
// reference modified by <script type="module"> conversion
|
|
225
|
+
let newReference
|
|
226
|
+
if (reference.next) {
|
|
227
|
+
newReference = reference.next
|
|
228
|
+
} else {
|
|
229
|
+
// when the url is not referenced by a <script type="module">
|
|
230
|
+
// we assume we want to preload "classic" but it might not be the case
|
|
231
|
+
// but it's unlikely to happen and people should use "modulepreload" in that case anyway
|
|
232
|
+
;[newReference] = await getReferenceAsJsClassic(reference)
|
|
233
|
+
}
|
|
234
|
+
assignHtmlNodeAttributes(preloadAsScriptNode, {
|
|
235
|
+
href: newReference.generatedSpecifier,
|
|
236
|
+
})
|
|
237
|
+
removeHtmlNodeAttributeByName(
|
|
238
|
+
preloadAsScriptNode,
|
|
239
|
+
"crossorigin",
|
|
240
|
+
)
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
modulePreloadNodes.forEach((modulePreloadNode) => {
|
|
245
|
+
const hrefAttribute = getHtmlNodeAttributeByName(
|
|
246
|
+
modulePreloadNode,
|
|
247
|
+
"href",
|
|
248
|
+
)
|
|
249
|
+
const href = hrefAttribute.value
|
|
250
|
+
const reference = urlInfo.references.find(
|
|
251
|
+
(ref) =>
|
|
252
|
+
ref.generatedSpecifier === href &&
|
|
253
|
+
ref.type === "link_href" &&
|
|
254
|
+
ref.expectedType === "js_module",
|
|
255
|
+
)
|
|
256
|
+
actions.push(async () => {
|
|
257
|
+
let newReference
|
|
258
|
+
if (reference.next) {
|
|
259
|
+
newReference = reference.next
|
|
260
|
+
} else {
|
|
261
|
+
;[newReference] = await getReferenceAsJsClassic(reference)
|
|
262
|
+
}
|
|
263
|
+
assignHtmlNodeAttributes(modulePreloadNode, {
|
|
264
|
+
rel: "preload",
|
|
265
|
+
as: "script",
|
|
266
|
+
href: newReference.generatedSpecifier,
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (actions.length === 0) {
|
|
273
|
+
return null
|
|
274
|
+
}
|
|
275
|
+
await Promise.all(actions.map((action) => action()))
|
|
276
|
+
if (systemJsInjection) {
|
|
277
|
+
const needsSystemJs = convertedUrls.some(
|
|
278
|
+
(convertedUrl) =>
|
|
279
|
+
context.urlGraph.getUrlInfo(convertedUrl).data.jsClassicFormat ===
|
|
280
|
+
"system",
|
|
281
|
+
)
|
|
282
|
+
if (needsSystemJs) {
|
|
283
|
+
const [systemJsReference] = context.referenceUtils.inject({
|
|
284
|
+
type: "script_src",
|
|
285
|
+
expectedType: "js_classic",
|
|
286
|
+
specifier: systemJsClientFileUrl,
|
|
287
|
+
})
|
|
288
|
+
injectScriptAsEarlyAsPossible(
|
|
289
|
+
htmlAst,
|
|
290
|
+
createHtmlNode({
|
|
291
|
+
"tagName": "script",
|
|
292
|
+
"src": systemJsReference.generatedSpecifier,
|
|
293
|
+
"injected-by": "jsenv:as_js_classic_html",
|
|
294
|
+
}),
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return stringifyHtmlAst(htmlAst)
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const jsenvPluginAsJsClassicWorkers = ({
|
|
4
4
|
generateJsClassicFilename,
|
|
5
5
|
}) => {
|
|
6
6
|
const updateReference = (reference) => {
|
|
@@ -19,7 +19,7 @@ export const jsenvPluginWorkersTypeModuleAsClassic = ({
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
|
-
name: "jsenv:
|
|
22
|
+
name: "jsenv:as_js_classic_workers",
|
|
23
23
|
appliesDuring: "*",
|
|
24
24
|
redirectUrl: {
|
|
25
25
|
js_url_specifier: (reference, context) => {
|
|
@@ -7,7 +7,10 @@ import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_pl
|
|
|
7
7
|
import { babelPluginGlobalThisAsJsenvImport } from "./global_this/babel_plugin_global_this_as_jsenv_import.js"
|
|
8
8
|
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
9
9
|
|
|
10
|
-
export const jsenvPluginBabel = ({
|
|
10
|
+
export const jsenvPluginBabel = ({
|
|
11
|
+
getCustomBabelPlugins,
|
|
12
|
+
babelHelpersAsImport = true,
|
|
13
|
+
} = {}) => {
|
|
11
14
|
const transformWithBabel = async (urlInfo, context) => {
|
|
12
15
|
const isJsModule = urlInfo.type === "js_module"
|
|
13
16
|
const isWorker = urlInfo.subtype === "worker"
|
|
@@ -55,7 +58,7 @@ export const jsenvPluginBabel = ({ getCustomBabelPlugins } = {}) => {
|
|
|
55
58
|
Object.assign(babelPluginStructure, getCustomBabelPlugins(context))
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
if (isJsModule) {
|
|
61
|
+
if (isJsModule && babelHelpersAsImport) {
|
|
59
62
|
if (!isSupported("global_this")) {
|
|
60
63
|
babelPluginStructure["global-this-as-jsenv-import"] = [
|
|
61
64
|
babelPluginGlobalThisAsJsenvImport,
|
|
@@ -14,8 +14,7 @@ import { urlToFilename } from "@jsenv/filesystem"
|
|
|
14
14
|
|
|
15
15
|
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
16
16
|
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
17
|
-
|
|
18
|
-
import { fetchOriginalUrlInfo } from "../fetch_original_url_info.js"
|
|
17
|
+
import { fetchOriginalUrlInfo } from "@jsenv/utils/graph/fetch_original_url_info.js"
|
|
19
18
|
|
|
20
19
|
export const jsenvPluginImportAssertions = () => {
|
|
21
20
|
const updateReference = (reference, searchParam) => {
|
|
@@ -19,6 +19,7 @@ export const jsenvPluginTranspilation = ({
|
|
|
19
19
|
jsModuleAsJsClassic = true,
|
|
20
20
|
systemJsInjection = true,
|
|
21
21
|
topLevelAwait = true,
|
|
22
|
+
babelHelpersAsImport = true,
|
|
22
23
|
getCustomBabelPlugins,
|
|
23
24
|
}) => {
|
|
24
25
|
return [
|
|
@@ -28,6 +29,7 @@ export const jsenvPluginTranspilation = ({
|
|
|
28
29
|
jsenvPluginBabel({
|
|
29
30
|
topLevelAwait,
|
|
30
31
|
getCustomBabelPlugins,
|
|
32
|
+
babelHelpersAsImport,
|
|
31
33
|
}),
|
|
32
34
|
// but the conversion from js_module to js_classic
|
|
33
35
|
// we want to do it after bundling
|
|
@@ -51,10 +51,11 @@ export const parseAndTransformJsUrls = async (urlInfo, context) => {
|
|
|
51
51
|
typePropertyNode: jsMention.typePropertyNode,
|
|
52
52
|
})
|
|
53
53
|
actions.push(async () => {
|
|
54
|
+
const replacement = await referenceUtils.readGeneratedSpecifier(reference)
|
|
54
55
|
magicSource.replace({
|
|
55
56
|
start: jsMention.specifierStart,
|
|
56
57
|
end: jsMention.specifierEnd,
|
|
57
|
-
replacement
|
|
58
|
+
replacement,
|
|
58
59
|
})
|
|
59
60
|
if (reference.mutation) {
|
|
60
61
|
reference.mutation(magicSource)
|
|
@@ -1,18 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeStructuredMetaMap,
|
|
3
|
+
urlToMeta,
|
|
4
|
+
urlToRelativeUrl,
|
|
5
|
+
} from "@jsenv/filesystem"
|
|
6
|
+
|
|
1
7
|
import { parseAndTransformHtmlUrls } from "./html/html_urls.js"
|
|
2
8
|
import { parseAndTransformCssUrls } from "./css/css_urls.js"
|
|
3
9
|
import { parseAndTransformJsUrls } from "./js/js_urls.js"
|
|
4
10
|
import { parseAndTransformWebmanifestUrls } from "./webmanifest/webmanifest_urls.js"
|
|
5
11
|
|
|
6
|
-
export const jsenvPluginUrlAnalysis = () => {
|
|
12
|
+
export const jsenvPluginUrlAnalysis = ({ rootDirectoryUrl, include }) => {
|
|
13
|
+
let getIncludeInfo = () => undefined
|
|
14
|
+
if (include) {
|
|
15
|
+
const includeMetaMap = normalizeStructuredMetaMap(
|
|
16
|
+
{
|
|
17
|
+
include,
|
|
18
|
+
},
|
|
19
|
+
rootDirectoryUrl,
|
|
20
|
+
)
|
|
21
|
+
getIncludeInfo = (url) => {
|
|
22
|
+
const meta = urlToMeta({
|
|
23
|
+
url,
|
|
24
|
+
structuredMetaMap: includeMetaMap,
|
|
25
|
+
})
|
|
26
|
+
return meta.include
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
7
30
|
return {
|
|
8
31
|
name: "jsenv:url_analysis",
|
|
9
32
|
appliesDuring: "*",
|
|
33
|
+
redirectUrl: (reference) => {
|
|
34
|
+
if (
|
|
35
|
+
reference.specifier[0] === "#" &&
|
|
36
|
+
// For Html, css and in general "#" refer to a ressource in the page
|
|
37
|
+
// so that urls must be kept intact
|
|
38
|
+
// However for js import specifiers they have a different meaning and we want
|
|
39
|
+
// to resolve them (https://nodejs.org/api/packages.html#imports for instance)
|
|
40
|
+
reference.type !== "js_import_export"
|
|
41
|
+
) {
|
|
42
|
+
reference.shouldHandle = false
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
const includeInfo = getIncludeInfo(reference.url)
|
|
46
|
+
if (includeInfo === true) {
|
|
47
|
+
reference.shouldHandle = true
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
if (includeInfo === false) {
|
|
51
|
+
reference.shouldHandle = false
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (reference.url.startsWith("data:")) {
|
|
55
|
+
reference.shouldHandle = true
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (reference.url.startsWith("file:")) {
|
|
59
|
+
reference.shouldHandle = true
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
},
|
|
10
63
|
transformUrlContent: {
|
|
11
64
|
html: parseAndTransformHtmlUrls,
|
|
12
65
|
css: parseAndTransformCssUrls,
|
|
13
66
|
js_classic: parseAndTransformJsUrls,
|
|
14
67
|
js_module: parseAndTransformJsUrls,
|
|
15
68
|
webmanifest: parseAndTransformWebmanifestUrls,
|
|
69
|
+
directory: (urlInfo, context) => {
|
|
70
|
+
const originalDirectoryReference = findOriginalDirectoryReference(
|
|
71
|
+
urlInfo,
|
|
72
|
+
context,
|
|
73
|
+
)
|
|
74
|
+
const directoryRelativeUrl = urlToRelativeUrl(
|
|
75
|
+
urlInfo.url,
|
|
76
|
+
context.rootDirectoryUrl,
|
|
77
|
+
)
|
|
78
|
+
JSON.parse(urlInfo.content).forEach((directoryEntryName) => {
|
|
79
|
+
context.referenceUtils.found({
|
|
80
|
+
type: "filesystem",
|
|
81
|
+
subtype: "directory_entry",
|
|
82
|
+
specifier: directoryEntryName,
|
|
83
|
+
trace: `"${directoryRelativeUrl}${directoryEntryName}" entry in directory referenced by ${originalDirectoryReference.trace}`,
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
},
|
|
16
87
|
},
|
|
17
88
|
}
|
|
18
89
|
}
|
|
90
|
+
|
|
91
|
+
const findOriginalDirectoryReference = (urlInfo, context) => {
|
|
92
|
+
const findNonFileSystemAncestor = (urlInfo) => {
|
|
93
|
+
for (const dependentUrl of urlInfo.dependents) {
|
|
94
|
+
const dependentUrlInfo = context.urlGraph.getUrlInfo(dependentUrl)
|
|
95
|
+
if (dependentUrlInfo.type !== "directory") {
|
|
96
|
+
return [dependentUrlInfo, urlInfo]
|
|
97
|
+
}
|
|
98
|
+
const found = findNonFileSystemAncestor(dependentUrlInfo)
|
|
99
|
+
if (found) {
|
|
100
|
+
return found
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return []
|
|
104
|
+
}
|
|
105
|
+
const [ancestor, child] = findNonFileSystemAncestor(urlInfo)
|
|
106
|
+
if (!ancestor) {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
const ref = ancestor.references.find((ref) => ref.url === child.url)
|
|
110
|
+
return ref
|
|
111
|
+
}
|
|
@@ -12,6 +12,9 @@ export const parseAndTransformWebmanifestUrls = async (urlInfo, context) => {
|
|
|
12
12
|
icon.src = await context.referenceUtils.readGeneratedSpecifier(reference)
|
|
13
13
|
})
|
|
14
14
|
})
|
|
15
|
+
if (actions.length === 0) {
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
15
18
|
await Promise.all(actions.map((action) => action()))
|
|
16
19
|
return JSON.stringify(manifest, null, " ")
|
|
17
20
|
}
|