@jsenv/core 27.0.0-alpha.3 → 27.0.0-alpha.32
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/main.js +4 -0
- package/package.json +17 -14
- package/readme.md +4 -12
- package/src/build/build.js +690 -429
- package/src/build/build_urls_generator.js +33 -21
- package/src/build/graph_utils.js +31 -0
- package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
- package/src/build/inject_service_worker_urls.js +79 -0
- package/src/build/resync_ressource_hints.js +68 -0
- package/src/build/start_build_server.js +201 -0
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
- package/src/dev/start_dev_server.js +58 -26
- package/src/execute/execute.js +30 -4
- package/src/execute/run.js +19 -56
- package/src/execute/runtimes/browsers/from_playwright.js +201 -147
- package/src/execute/runtimes/node/controllable_file.mjs +26 -10
- package/src/execute/runtimes/node/node_execution_performance.js +67 -0
- package/src/execute/runtimes/node/node_process.js +280 -39
- package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
- package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
- package/src/omega/compat/runtime_compat.js +50 -0
- package/src/omega/errors.js +51 -58
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/file_url_converter.js +8 -50
- package/src/omega/kitchen.js +409 -286
- package/src/omega/server/file_service.js +9 -11
- package/src/omega/url_graph/url_graph_load.js +14 -7
- package/src/omega/url_graph/url_graph_report.js +17 -15
- package/src/omega/url_graph.js +32 -10
- package/src/omega/web_workers.js +42 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
- package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +27 -168
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
- package/src/plugins/bundling/css/bundle_css.js +21 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +120 -79
- package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +48 -41
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
- package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +7 -4
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_installer.js +3 -2
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_setup.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
- package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +38 -46
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
- package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +98 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +26 -8
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
- package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +37 -31
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +25 -0
- package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
- package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +61 -40
- package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +263 -0
- package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
- package/src/plugins/minification/css/minify_css.js +9 -0
- package/src/plugins/minification/html/minify_html.js +15 -0
- package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
- package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
- package/src/plugins/minification/json/minify_json.js +8 -0
- package/src/{omega/core_plugins → plugins}/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +15 -15
- package/src/{omega → plugins}/plugin_controller.js +18 -10
- package/src/plugins/plugins.js +73 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
- package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
- package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +183 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +256 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +139 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
- package/src/{omega/core_plugins/babel/babel_helper → plugins/transpilation/babel/helpers}/babel_plugin_babel_helpers_as_jsenv_imports.js +1 -2
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +161 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +38 -22
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
- package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
- package/src/{omega/core_plugins → plugins/transpilation}/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +225 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +37 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
- package/src/plugins/url_references/css/css_urls.js +49 -0
- package/src/plugins/url_references/html/html_urls.js +273 -0
- package/src/plugins/url_references/js/js_urls.js +163 -0
- package/src/plugins/url_references/jsenv_plugin_url_references.js +18 -0
- package/src/plugins/url_references/webmanifest/webmanifest_urls.js +17 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
- package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +8 -8
- package/src/test/execute_plan.js +25 -11
- package/src/test/execute_test_plan.js +14 -1
- package/src/test/logs_file_execution.js +8 -7
- package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
- package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
- package/src/dev/plugins/autoreload/sse_service.js +0 -149
- package/src/execute/runtimes/node/controlled_process.js +0 -316
- package/src/omega/core_plugins/babel/babel_helper/babel_helper_directory.js +0 -29
- package/src/omega/core_plugins/babel/babel_helper/client/.eslintrc.cjs +0 -24
- package/src/omega/core_plugins/babel/babel_helper/client/AsyncGenerator/AsyncGenerator.js +0 -81
- package/src/omega/core_plugins/babel/babel_helper/client/AwaitValue/AwaitValue.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -33
- package/src/omega/core_plugins/babel/babel_helper/client/arrayLikeToArray/arrayLikeToArray.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/arrayWithHoles/arrayWithHoles.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/arrayWithoutHoles/arrayWithoutHoles.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/assertThisInitialized/assertThisInitialized.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -40
- package/src/omega/core_plugins/babel/babel_helper/client/asyncIterator/asyncIterator.js +0 -65
- package/src/omega/core_plugins/babel/babel_helper/client/asyncToGenerator/asyncToGenerator.js +0 -34
- package/src/omega/core_plugins/babel/babel_helper/client/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -20
- package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -13
- package/src/omega/core_plugins/babel/babel_helper/client/classCallCheck/classCallCheck.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/classNameTDZError/classNameTDZError.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldGet/classPrivateFieldGet.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldSet/classPrivateFieldSet.js +0 -8
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodGet/classPrivateMethodGet.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodSet/classPrivateMethodSet.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -9
- package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -15
- package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/construct/construct.js +0 -16
- package/src/omega/core_plugins/babel/babel_helper/client/createClass/createClass.js +0 -15
- package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -60
- package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -23
- package/src/omega/core_plugins/babel/babel_helper/client/createRawReactElement/createRawReactElement.js +0 -50
- package/src/omega/core_plugins/babel/babel_helper/client/createSuper/createSuper.js +0 -22
- package/src/omega/core_plugins/babel/babel_helper/client/decorate/decorate.js +0 -403
- package/src/omega/core_plugins/babel/babel_helper/client/defaults/defaults.js +0 -11
- package/src/omega/core_plugins/babel/babel_helper/client/defineEnumerableProperties/defineEnumerableProperties.js +0 -23
- package/src/omega/core_plugins/babel/babel_helper/client/defineProperty/defineProperty.js +0 -18
- package/src/omega/core_plugins/babel/babel_helper/client/extends/extends.js +0 -14
- package/src/omega/core_plugins/babel/babel_helper/client/get/get.js +0 -19
- package/src/omega/core_plugins/babel/babel_helper/client/getPrototypeOf/getPrototypeOf.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/inherits/inherits.js +0 -19
- package/src/omega/core_plugins/babel/babel_helper/client/inheritsLoose/inheritsLoose.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/initializerDefineProperty/initializerDefineProperty.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/initializerWarningHelper/initializerWarningHelper.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/instanceof/instanceof.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/interopRequireDefault/interopRequireDefault.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/interopRequireWildcard/interopRequireWildcard.js +0 -37
- package/src/omega/core_plugins/babel/babel_helper/client/isNativeFunction/isNativeFunction.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -21
- package/src/omega/core_plugins/babel/babel_helper/client/iterableToArray/iterableToArray.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimit/iterableToArrayLimit.js +0 -36
- package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/jsx/jsx.js +0 -50
- package/src/omega/core_plugins/babel/babel_helper/client/maybeArrayLike/maybeArrayLike.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/newArrowCheck/newArrowCheck.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/nonIterableRest/nonIterableRest.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/nonIterableSpread/nonIterableSpread.js +0 -5
- package/src/omega/core_plugins/babel/babel_helper/client/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/objectSpread/objectSpread.js +0 -23
- package/src/omega/core_plugins/babel/babel_helper/client/objectSpread2/objectSpread2.js +0 -41
- package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutProperties/objectWithoutProperties.js +0 -19
- package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -13
- package/src/omega/core_plugins/babel/babel_helper/client/possibleConstructorReturn/possibleConstructorReturn.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/readOnlyError/readOnlyError.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/readme.md +0 -8
- package/src/omega/core_plugins/babel/babel_helper/client/set/set.js +0 -44
- package/src/omega/core_plugins/babel/babel_helper/client/setPrototypeOf/setPrototypeOf.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -8
- package/src/omega/core_plugins/babel/babel_helper/client/slicedToArray/slicedToArray.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/slicedToArrayLoose/slicedToArrayLoose.js +0 -13
- package/src/omega/core_plugins/babel/babel_helper/client/superPropBase/superPropBase.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -7
- package/src/omega/core_plugins/babel/babel_helper/client/tdz/tdz.js +0 -4
- package/src/omega/core_plugins/babel/babel_helper/client/temporalRef/temporalRef.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/temporalUndefined/temporalUndefined.js +0 -3
- package/src/omega/core_plugins/babel/babel_helper/client/toArray/toArray.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/toConsumableArray/toConsumableArray.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/toPrimitive/toPrimitive.js +0 -10
- package/src/omega/core_plugins/babel/babel_helper/client/toPropertyKey/toPropertyKey.js +0 -6
- package/src/omega/core_plugins/babel/babel_helper/client/typeof/typeof.js +0 -14
- package/src/omega/core_plugins/babel/babel_helper/client/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -12
- package/src/omega/core_plugins/babel/babel_helper/client/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -8
- package/src/omega/core_plugins/babel/babel_helper/client/wrapNativeSuper/wrapNativeSuper.js +0 -30
- package/src/omega/core_plugins/babel/babel_helper/client/wrapRegExp/wrapRegExp.js +0 -63
- package/src/omega/core_plugins/babel/babel_helper/client/writeOnlyError/writeOnlyError.js +0 -4
- package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +0 -187
- package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
- package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
- package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
- package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
- package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins.js +0 -39
- package/src/omega/runtime_support/runtime_support.js +0 -20
- package/src/omega/url_mentions/css_url_mentions.js +0 -63
- package/src/omega/url_mentions/html_url_mentions.js +0 -185
- package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
- package/src/omega/url_mentions/parse_url_mentions.js +0 -37
- package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
|
@@ -0,0 +1 @@
|
|
|
1
|
+
s.js exists to ease jsenv ability to find the file.
|
package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import babelParser from "@babel/parser"
|
|
2
|
+
|
|
3
|
+
export const babelPluginTransformImportMetaUrl = (babel) => {
|
|
4
|
+
return {
|
|
5
|
+
name: "transform-import-meta-url",
|
|
6
|
+
visitor: {
|
|
7
|
+
Program: (programPath) => {
|
|
8
|
+
const currentUrlIdentifier =
|
|
9
|
+
programPath.scope.generateUidIdentifier("currentUrl")
|
|
10
|
+
let used = false
|
|
11
|
+
|
|
12
|
+
programPath.traverse({
|
|
13
|
+
MemberExpression: (path) => {
|
|
14
|
+
const node = path.node
|
|
15
|
+
if (
|
|
16
|
+
node.object.type === "MetaProperty" &&
|
|
17
|
+
node.object.property.name === "meta" &&
|
|
18
|
+
node.property.name === "url"
|
|
19
|
+
) {
|
|
20
|
+
// const node = babel.types.valueToNode(10)
|
|
21
|
+
const identifier = babel.types.identifier(
|
|
22
|
+
currentUrlIdentifier.name,
|
|
23
|
+
)
|
|
24
|
+
const expressionStatement =
|
|
25
|
+
babel.types.expressionStatement(identifier)
|
|
26
|
+
path.replaceWith(expressionStatement)
|
|
27
|
+
used = true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
if (used) {
|
|
32
|
+
const ast = generateExpressionAst(`document.currentScript.src`)
|
|
33
|
+
programPath.scope.push({
|
|
34
|
+
id: currentUrlIdentifier,
|
|
35
|
+
init: ast,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const generateExpressionAst = (expression, options) => {
|
|
44
|
+
const { parseExpression } = babelParser
|
|
45
|
+
const ast = parseExpression(expression, options)
|
|
46
|
+
return ast
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// const { clientRuntimeCompat, isSupportedOnCurrentClient } = context
|
|
2
|
+
// const shouldBeCompatibleWithNode =
|
|
3
|
+
// Object.keys(clientRuntimeCompat).includes("node")
|
|
4
|
+
// const requiredFeatureNames = [
|
|
5
|
+
// "import_dynamic",
|
|
6
|
+
// "top_level_await",
|
|
7
|
+
// "global_this",
|
|
8
|
+
// // when using node we assume the code won't use browser specific feature
|
|
9
|
+
// ...(shouldBeCompatibleWithNode
|
|
10
|
+
// ? []
|
|
11
|
+
// : [
|
|
12
|
+
// "script_type_module",
|
|
13
|
+
// "worker_type_module",
|
|
14
|
+
// "import_type_json",
|
|
15
|
+
// "import_type_css",
|
|
16
|
+
// ]),
|
|
17
|
+
// // "importmap",
|
|
18
|
+
// ]
|
|
19
|
+
// const needsSystemJs = featuresRelatedToSystemJs.some((featureName) => {
|
|
20
|
+
// const isRequired = requiredFeatureNames.includes(featureName)
|
|
21
|
+
// return isRequired && !isSupportedOnCurrentClient(featureName)
|
|
22
|
+
// })
|
|
23
|
+
// if (!needsSystemJs) {
|
|
24
|
+
// return null
|
|
25
|
+
// }
|
|
26
|
+
// const { code, map } = await applyBabelPlugins({
|
|
27
|
+
|
|
28
|
+
// })
|
|
29
|
+
// return {
|
|
30
|
+
// content: code,
|
|
31
|
+
// soourcemap: map,
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// const featuresRelatedToSystemJs = [
|
|
35
|
+
// "script_type_module",
|
|
36
|
+
// "worker_type_module",
|
|
37
|
+
// "import_dynamic",
|
|
38
|
+
// "import_type_json",
|
|
39
|
+
// "import_type_css",
|
|
40
|
+
// "top_level_await",
|
|
41
|
+
// // "importmap",
|
|
42
|
+
// // "worker_importmap",
|
|
43
|
+
// ]
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Something to keep in mind:
|
|
3
|
+
* When systemjs format is used by babel, it will generated UID based on
|
|
4
|
+
* the import specifier:
|
|
5
|
+
* https://github.com/babel/babel/blob/97d1967826077f15e766778c0d64711399e9a72a/packages/babel-plugin-transform-modules-systemjs/src/index.ts#L498
|
|
6
|
+
* But at this stage import specifier are absolute file urls
|
|
7
|
+
* So without minification these specifier are long and dependent
|
|
8
|
+
* on where the files are on the filesystem.
|
|
9
|
+
* This is mitigated by minification that will shorten them
|
|
10
|
+
* But ideally babel should not generate this in the first place
|
|
11
|
+
* and prefer to unique identifier based solely on the specifier basename for instance
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createRequire } from "node:module"
|
|
15
|
+
import { readFileSync, urlToFilename } from "@jsenv/filesystem"
|
|
16
|
+
|
|
17
|
+
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
18
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
19
|
+
import { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
|
|
20
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
21
|
+
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
22
|
+
|
|
23
|
+
import { fetchOriginalUrlInfo } from "../fetch_original_url_info.js"
|
|
24
|
+
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
25
|
+
import { jsenvPluginScriptTypeModuleAsClassic } from "./jsenv_plugin_script_type_module_as_classic.js"
|
|
26
|
+
import { jsenvPluginWorkersTypeModuleAsClassic } from "./jsenv_plugin_workers_type_module_as_classic.js"
|
|
27
|
+
|
|
28
|
+
const require = createRequire(import.meta.url)
|
|
29
|
+
|
|
30
|
+
export const jsenvPluginAsJsClassic = ({ systemJsInjection }) => {
|
|
31
|
+
const systemJsClientFileUrl = new URL("./client/s.js", import.meta.url).href
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
asJsClassic({ systemJsInjection, systemJsClientFileUrl }),
|
|
35
|
+
jsenvPluginScriptTypeModuleAsClassic({
|
|
36
|
+
systemJsInjection,
|
|
37
|
+
systemJsClientFileUrl,
|
|
38
|
+
generateJsClassicFilename,
|
|
39
|
+
}),
|
|
40
|
+
jsenvPluginWorkersTypeModuleAsClassic({
|
|
41
|
+
generateJsClassicFilename,
|
|
42
|
+
}),
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const asJsClassic = ({ systemJsInjection, systemJsClientFileUrl }) => {
|
|
47
|
+
return {
|
|
48
|
+
name: "jsenv:as_js_classic",
|
|
49
|
+
appliesDuring: "*",
|
|
50
|
+
// forward ?as_js_classic to referenced urls
|
|
51
|
+
normalizeUrl: (reference, context) => {
|
|
52
|
+
// We want to propagate transformation of js module to js classic
|
|
53
|
+
// but only for import specifier (static/dynamic import + re-export)
|
|
54
|
+
// All other references won't get the ?as_js_classic
|
|
55
|
+
// otherwise we could try to transform inline ressources, specifiers inside new URL(). ...
|
|
56
|
+
if (
|
|
57
|
+
reference.type !== "js_import_export" &&
|
|
58
|
+
reference.subtype !== "system_register_arg" &&
|
|
59
|
+
reference.subtype !== "system_import_arg"
|
|
60
|
+
) {
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl)
|
|
64
|
+
if (
|
|
65
|
+
!parentUrlInfo ||
|
|
66
|
+
!new URL(parentUrlInfo.url).searchParams.has("as_js_classic")
|
|
67
|
+
) {
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
const urlTransformed = injectQueryParams(reference.url, {
|
|
71
|
+
as_js_classic: "",
|
|
72
|
+
})
|
|
73
|
+
reference.filename = generateJsClassicFilename(reference.url)
|
|
74
|
+
return urlTransformed
|
|
75
|
+
},
|
|
76
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
77
|
+
const originalUrlInfo = await fetchOriginalUrlInfo({
|
|
78
|
+
urlInfo,
|
|
79
|
+
context,
|
|
80
|
+
searchParam: "as_js_classic",
|
|
81
|
+
// override the expectedType to "js_module"
|
|
82
|
+
// because when there is ?as_js_classic it means the underlying ressource
|
|
83
|
+
// is a js_module
|
|
84
|
+
expectedType: "js_module",
|
|
85
|
+
})
|
|
86
|
+
if (!originalUrlInfo) {
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
const isJsEntryPoint =
|
|
90
|
+
// in general html files are entry points
|
|
91
|
+
// but during build js can be sepcified as an entry point
|
|
92
|
+
// (meaning there is no html file where we can inject systemjs)
|
|
93
|
+
// in that case we need to inject systemjs in the js file
|
|
94
|
+
originalUrlInfo.data.isEntryPoint ||
|
|
95
|
+
// In thoose case we need to inject systemjs the worker js file
|
|
96
|
+
originalUrlInfo.data.isWebWorkerEntryPoint
|
|
97
|
+
// if it's an entry point without dependency (it does not use import)
|
|
98
|
+
// then we can use UMD, otherwise we have to use systemjs
|
|
99
|
+
// because it is imported by systemjs
|
|
100
|
+
const jsClassicFormat =
|
|
101
|
+
isJsEntryPoint && !originalUrlInfo.data.usesImport ? "umd" : "system"
|
|
102
|
+
const { content, sourcemap } = await convertJsModuleToJsClassic({
|
|
103
|
+
systemJsInjection,
|
|
104
|
+
systemJsClientFileUrl,
|
|
105
|
+
urlInfo: originalUrlInfo,
|
|
106
|
+
isJsEntryPoint,
|
|
107
|
+
jsClassicFormat,
|
|
108
|
+
})
|
|
109
|
+
urlInfo.data.jsClassicFormat = jsClassicFormat
|
|
110
|
+
return {
|
|
111
|
+
type: "js_classic",
|
|
112
|
+
contentType: "text/javascript",
|
|
113
|
+
content,
|
|
114
|
+
sourcemap,
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const generateJsClassicFilename = (url) => {
|
|
121
|
+
const filename = urlToFilename(url)
|
|
122
|
+
const [basename, extension] = splitFileExtension(filename)
|
|
123
|
+
return `${basename}.es5${extension}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const splitFileExtension = (filename) => {
|
|
127
|
+
const dotLastIndex = filename.lastIndexOf(".")
|
|
128
|
+
if (dotLastIndex === -1) {
|
|
129
|
+
return [filename, ""]
|
|
130
|
+
}
|
|
131
|
+
return [filename.slice(0, dotLastIndex), filename.slice(dotLastIndex)]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const convertJsModuleToJsClassic = async ({
|
|
135
|
+
systemJsInjection,
|
|
136
|
+
systemJsClientFileUrl,
|
|
137
|
+
urlInfo,
|
|
138
|
+
isJsEntryPoint,
|
|
139
|
+
jsClassicFormat,
|
|
140
|
+
}) => {
|
|
141
|
+
const { code, map } = await applyBabelPlugins({
|
|
142
|
+
babelPlugins: [
|
|
143
|
+
...(jsClassicFormat === "system"
|
|
144
|
+
? [
|
|
145
|
+
// propposal-dynamic-import required with systemjs for babel8:
|
|
146
|
+
// https://github.com/babel/babel/issues/10746
|
|
147
|
+
require("@babel/plugin-proposal-dynamic-import"),
|
|
148
|
+
[
|
|
149
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
150
|
+
{
|
|
151
|
+
topLevelAwait: "return",
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
require("@babel/plugin-transform-modules-systemjs"),
|
|
155
|
+
]
|
|
156
|
+
: [
|
|
157
|
+
[
|
|
158
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
159
|
+
{
|
|
160
|
+
topLevelAwait: "simple",
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
babelPluginTransformImportMetaUrl,
|
|
164
|
+
require("@babel/plugin-transform-modules-umd"),
|
|
165
|
+
]),
|
|
166
|
+
],
|
|
167
|
+
urlInfo,
|
|
168
|
+
})
|
|
169
|
+
if (systemJsInjection && jsClassicFormat === "system" && isJsEntryPoint) {
|
|
170
|
+
const magicSource = createMagicSource(code)
|
|
171
|
+
const systemjsCode = readFileSync(systemJsClientFileUrl, { as: "string" })
|
|
172
|
+
magicSource.prepend(`${systemjsCode}\n\n`)
|
|
173
|
+
const { content, sourcemap } = magicSource.toContentAndSourcemap()
|
|
174
|
+
return {
|
|
175
|
+
content,
|
|
176
|
+
sourcemap: await composeTwoSourcemaps(map, sourcemap),
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
content: code,
|
|
181
|
+
sourcemap: map,
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
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 jsenvPluginScriptTypeModuleAsClassic = ({
|
|
18
|
+
systemJsInjection,
|
|
19
|
+
systemJsClientFileUrl,
|
|
20
|
+
generateJsClassicFilename,
|
|
21
|
+
}) => {
|
|
22
|
+
return {
|
|
23
|
+
name: "jsenv:script_type_module_as_classic",
|
|
24
|
+
appliesDuring: "*",
|
|
25
|
+
transformUrlContent: {
|
|
26
|
+
html: async (urlInfo, context) => {
|
|
27
|
+
if (
|
|
28
|
+
context.isSupportedOnCurrentClients("script_type_module") &&
|
|
29
|
+
context.isSupportedOnCurrentClients("import_dynamic")
|
|
30
|
+
) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
const htmlAst = parseHtmlString(urlInfo.content)
|
|
34
|
+
const preloadAsScriptNodes = []
|
|
35
|
+
const modulePreloadNodes = []
|
|
36
|
+
const moduleScriptNodes = []
|
|
37
|
+
const classicScriptNodes = []
|
|
38
|
+
const visitLinkNodes = (node) => {
|
|
39
|
+
if (node.nodeName !== "link") {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
const relAttribute = getHtmlNodeAttributeByName(node, "rel")
|
|
43
|
+
const rel = relAttribute ? relAttribute.value : undefined
|
|
44
|
+
if (rel === "modulepreload") {
|
|
45
|
+
modulePreloadNodes.push(node)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
if (rel === "preload") {
|
|
49
|
+
const asAttribute = getHtmlNodeAttributeByName(node, "as")
|
|
50
|
+
const as = asAttribute ? asAttribute.value : undefined
|
|
51
|
+
if (as === "script") {
|
|
52
|
+
preloadAsScriptNodes.push(node)
|
|
53
|
+
}
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const visitScriptNodes = (node) => {
|
|
58
|
+
if (node.nodeName !== "script") {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
const typeAttribute = getHtmlNodeAttributeByName(node, "type")
|
|
62
|
+
const type = typeAttribute ? typeAttribute.value : undefined
|
|
63
|
+
if (type === "module") {
|
|
64
|
+
moduleScriptNodes.push(node)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (type === undefined || type === "text/javascript") {
|
|
68
|
+
classicScriptNodes.push(node)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
visitHtmlAst(htmlAst, (node) => {
|
|
73
|
+
visitLinkNodes(node)
|
|
74
|
+
visitScriptNodes(node)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const classicScriptUrls = []
|
|
78
|
+
const moduleScriptUrls = []
|
|
79
|
+
classicScriptNodes.forEach((classicScriptNode) => {
|
|
80
|
+
const srcAttribute = getHtmlNodeAttributeByName(
|
|
81
|
+
classicScriptNode,
|
|
82
|
+
"src",
|
|
83
|
+
)
|
|
84
|
+
if (srcAttribute) {
|
|
85
|
+
const url = new URL(srcAttribute.value, urlInfo.url).href
|
|
86
|
+
classicScriptUrls.push(url)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
moduleScriptNodes.forEach((moduleScriptNode) => {
|
|
90
|
+
const srcAttribute = getHtmlNodeAttributeByName(
|
|
91
|
+
moduleScriptNode,
|
|
92
|
+
"src",
|
|
93
|
+
)
|
|
94
|
+
if (srcAttribute) {
|
|
95
|
+
const url = new URL(srcAttribute.value, urlInfo.url).href
|
|
96
|
+
moduleScriptUrls.push(url)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
const jsModuleUrls = []
|
|
101
|
+
const getReferenceAsJsClassic = async (reference) => {
|
|
102
|
+
const [newReference, newUrlInfo] = context.referenceUtils.update(
|
|
103
|
+
reference,
|
|
104
|
+
{
|
|
105
|
+
expectedType: "js_classic",
|
|
106
|
+
specifier: injectQueryParamsIntoSpecifier(reference.specifier, {
|
|
107
|
+
as_js_classic: "",
|
|
108
|
+
}),
|
|
109
|
+
filename: generateJsClassicFilename(reference.url),
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
const jsModuleUrl = newUrlInfo.url
|
|
113
|
+
if (!jsModuleUrls.includes(jsModuleUrl)) {
|
|
114
|
+
jsModuleUrls.push(newUrlInfo.url)
|
|
115
|
+
// during dev it means js modules will be cooked before server sends the HTML
|
|
116
|
+
// it's ok because:
|
|
117
|
+
// - during dev script_type_module are supported (dev use a recent browser)
|
|
118
|
+
// - even if browser is not supported it still works it's jus a bit slower
|
|
119
|
+
// because it needs to decide if systemjs will be injected or not
|
|
120
|
+
await context.cook({
|
|
121
|
+
reference: newReference,
|
|
122
|
+
urlInfo: newUrlInfo,
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
return [newReference, newUrlInfo]
|
|
126
|
+
}
|
|
127
|
+
const actions = []
|
|
128
|
+
preloadAsScriptNodes.forEach((preloadAsScriptNode) => {
|
|
129
|
+
const hrefAttribute = getHtmlNodeAttributeByName(
|
|
130
|
+
preloadAsScriptNode,
|
|
131
|
+
"href",
|
|
132
|
+
)
|
|
133
|
+
const href = hrefAttribute.value
|
|
134
|
+
const url = new URL(href, urlInfo.url).href
|
|
135
|
+
const expectedScriptType = moduleScriptUrls.includes(url)
|
|
136
|
+
? "module"
|
|
137
|
+
: "classic"
|
|
138
|
+
// keep in mind:
|
|
139
|
+
// when the url is not referenced by a <script type="module">
|
|
140
|
+
// we assume we want to preload "classic" but it might not be the case
|
|
141
|
+
// but it's unlikely to happen and people should use "modulepreload" in that case anyway
|
|
142
|
+
if (expectedScriptType === "module") {
|
|
143
|
+
actions.push(async () => {
|
|
144
|
+
const [newReference] = await getReferenceAsJsClassic(
|
|
145
|
+
context.referenceUtils.findByGeneratedSpecifier(href),
|
|
146
|
+
)
|
|
147
|
+
assignHtmlNodeAttributes(preloadAsScriptNode, {
|
|
148
|
+
href: newReference.generatedSpecifier,
|
|
149
|
+
})
|
|
150
|
+
removeHtmlNodeAttributeByName(preloadAsScriptNode, "crossorigin")
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
modulePreloadNodes.forEach((modulePreloadNode) => {
|
|
155
|
+
const hrefAttribute = getHtmlNodeAttributeByName(
|
|
156
|
+
modulePreloadNode,
|
|
157
|
+
"href",
|
|
158
|
+
)
|
|
159
|
+
const href = hrefAttribute.value
|
|
160
|
+
actions.push(async () => {
|
|
161
|
+
const [newReference] = await getReferenceAsJsClassic(
|
|
162
|
+
context.referenceUtils.findByGeneratedSpecifier(href),
|
|
163
|
+
)
|
|
164
|
+
assignHtmlNodeAttributes(modulePreloadNode, {
|
|
165
|
+
rel: "preload",
|
|
166
|
+
as: "script",
|
|
167
|
+
href: newReference.generatedSpecifier,
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
moduleScriptNodes.forEach((moduleScriptNode) => {
|
|
172
|
+
const srcAttribute = getHtmlNodeAttributeByName(
|
|
173
|
+
moduleScriptNode,
|
|
174
|
+
"src",
|
|
175
|
+
)
|
|
176
|
+
if (srcAttribute) {
|
|
177
|
+
actions.push(async () => {
|
|
178
|
+
const specifier = srcAttribute.value
|
|
179
|
+
const [newReference] = await getReferenceAsJsClassic(
|
|
180
|
+
context.referenceUtils.findByGeneratedSpecifier(specifier),
|
|
181
|
+
)
|
|
182
|
+
removeHtmlNodeAttributeByName(moduleScriptNode, "type")
|
|
183
|
+
srcAttribute.value = newReference.generatedSpecifier
|
|
184
|
+
})
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
const textNode = getHtmlNodeTextNode(moduleScriptNode)
|
|
188
|
+
actions.push(async () => {
|
|
189
|
+
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
190
|
+
htmlNodePosition.readNodePosition(moduleScriptNode, {
|
|
191
|
+
preferOriginal: true,
|
|
192
|
+
})
|
|
193
|
+
let inlineScriptUrl = generateInlineContentUrl({
|
|
194
|
+
url: urlInfo.url,
|
|
195
|
+
extension: ".js",
|
|
196
|
+
line,
|
|
197
|
+
column,
|
|
198
|
+
lineEnd,
|
|
199
|
+
columnEnd,
|
|
200
|
+
})
|
|
201
|
+
const [inlineReference] = context.referenceUtils.foundInline({
|
|
202
|
+
node: moduleScriptNode,
|
|
203
|
+
type: "script_src",
|
|
204
|
+
expectedType: "js_module",
|
|
205
|
+
// we remove 1 to the line because imagine the following html:
|
|
206
|
+
// <script>console.log('ok')</script>
|
|
207
|
+
// -> content starts same line as <script>
|
|
208
|
+
line: line - 1,
|
|
209
|
+
column,
|
|
210
|
+
isOriginalPosition: isOriginal,
|
|
211
|
+
specifier: inlineScriptUrl,
|
|
212
|
+
contentType: "application/javascript",
|
|
213
|
+
content: textNode.value,
|
|
214
|
+
})
|
|
215
|
+
const [, newUrlInfo] = await getReferenceAsJsClassic(
|
|
216
|
+
inlineReference,
|
|
217
|
+
)
|
|
218
|
+
removeHtmlNodeAttributeByName(moduleScriptNode, "type")
|
|
219
|
+
setHtmlNodeGeneratedText(moduleScriptNode, {
|
|
220
|
+
generatedText: newUrlInfo.content,
|
|
221
|
+
generatedBy: "jsenv:script_type_module_as_classic",
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
if (actions.length === 0) {
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
await Promise.all(actions.map((action) => action()))
|
|
230
|
+
if (systemJsInjection) {
|
|
231
|
+
const needsSystemJs = jsModuleUrls.some(
|
|
232
|
+
(jsModuleUrl) =>
|
|
233
|
+
context.urlGraph.getUrlInfo(jsModuleUrl).data.jsClassicFormat ===
|
|
234
|
+
"system",
|
|
235
|
+
)
|
|
236
|
+
if (needsSystemJs) {
|
|
237
|
+
const [systemJsReference] = context.referenceUtils.inject({
|
|
238
|
+
type: "script_src",
|
|
239
|
+
expectedType: "js_classic",
|
|
240
|
+
specifier: systemJsClientFileUrl,
|
|
241
|
+
})
|
|
242
|
+
injectScriptAsEarlyAsPossible(
|
|
243
|
+
htmlAst,
|
|
244
|
+
createHtmlNode({
|
|
245
|
+
"tagName": "script",
|
|
246
|
+
"src": systemJsReference.generatedSpecifier,
|
|
247
|
+
"injected-by": "jsenv:script_type_module_as_classic",
|
|
248
|
+
}),
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return stringifyHtmlAst(htmlAst)
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
}
|
|
256
|
+
}
|
package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
|
+
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
3
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
|
+
import {
|
|
5
|
+
analyzeNewWorkerOrNewSharedWorker,
|
|
6
|
+
analyzeServiceWorkerRegisterCall,
|
|
7
|
+
} from "@jsenv/utils/js_ast/js_static_analysis.js"
|
|
8
|
+
|
|
9
|
+
// TODO: handle also service worker and shared worker in this plugin
|
|
10
|
+
export const jsenvPluginWorkersTypeModuleAsClassic = ({
|
|
11
|
+
generateJsClassicFilename,
|
|
12
|
+
}) => {
|
|
13
|
+
const transformJsWorkerTypes = async (urlInfo, context) => {
|
|
14
|
+
const workersToTranspile = getWorkersToTranspile(urlInfo, context)
|
|
15
|
+
if (
|
|
16
|
+
!workersToTranspile.worker &&
|
|
17
|
+
!workersToTranspile.serviceWorker &&
|
|
18
|
+
!workersToTranspile.sharedServiceWorker
|
|
19
|
+
) {
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
const { metadata } = await applyBabelPlugins({
|
|
23
|
+
babelPlugins: [
|
|
24
|
+
[
|
|
25
|
+
babelPluginMetadataWorkerMentions,
|
|
26
|
+
{
|
|
27
|
+
workersToTranspile,
|
|
28
|
+
isJsModule: urlInfo.type === "js_module",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
],
|
|
32
|
+
urlInfo,
|
|
33
|
+
})
|
|
34
|
+
const { workerMentions } = metadata
|
|
35
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
36
|
+
workerMentions.forEach((workerMention) => {
|
|
37
|
+
if (workerMention.expectedType !== "js_module") {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
const specifier = workerMention.specifier
|
|
41
|
+
const reference = context.referenceUtils.findByGeneratedSpecifier(
|
|
42
|
+
JSON.stringify(specifier),
|
|
43
|
+
)
|
|
44
|
+
const [newReference] = context.referenceUtils.update(reference, {
|
|
45
|
+
expectedType: "js_classic",
|
|
46
|
+
specifier: injectQueryParamsIntoSpecifier(specifier, {
|
|
47
|
+
as_js_classic: "",
|
|
48
|
+
}),
|
|
49
|
+
filename: generateJsClassicFilename(reference.url),
|
|
50
|
+
})
|
|
51
|
+
magicSource.replace({
|
|
52
|
+
start: workerMention.start,
|
|
53
|
+
end: workerMention.end,
|
|
54
|
+
replacement: newReference.generatedSpecifier,
|
|
55
|
+
})
|
|
56
|
+
magicSource.replace({
|
|
57
|
+
start: workerMention.typeArgNode.value.start,
|
|
58
|
+
end: workerMention.typeArgNode.value.end,
|
|
59
|
+
replacement: JSON.stringify("classic"),
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
return magicSource.toContentAndSourcemap()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
name: "jsenv:workers_type_module_as_classic",
|
|
67
|
+
appliesDuring: "*",
|
|
68
|
+
transformUrlContent: {
|
|
69
|
+
js_module: transformJsWorkerTypes,
|
|
70
|
+
js_classic: transformJsWorkerTypes,
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const getWorkersToTranspile = (urlInfo, context) => {
|
|
76
|
+
let worker = false
|
|
77
|
+
let serviceWorker = false
|
|
78
|
+
let sharedWorker = false
|
|
79
|
+
for (const reference of urlInfo.references) {
|
|
80
|
+
if (reference.expectedType !== "js_module") {
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
reference.expectedSubtype === "worker" &&
|
|
85
|
+
!context.isSupportedOnCurrentClients("worker_type_module")
|
|
86
|
+
) {
|
|
87
|
+
worker = true
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
reference.expectedSubtype === "service_worker" &&
|
|
91
|
+
!context.isSupportedOnCurrentClients("service_worker_type_module")
|
|
92
|
+
) {
|
|
93
|
+
serviceWorker = true
|
|
94
|
+
}
|
|
95
|
+
if (
|
|
96
|
+
reference.expectedSubtype === "shared_worker" &&
|
|
97
|
+
!context.isSupportedOnCurrentClients("shared_worker_type_module")
|
|
98
|
+
) {
|
|
99
|
+
sharedWorker = true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { worker, serviceWorker, sharedWorker }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const babelPluginMetadataWorkerMentions = (
|
|
106
|
+
_,
|
|
107
|
+
{ workersToTranspile, isJsModule },
|
|
108
|
+
) => {
|
|
109
|
+
return {
|
|
110
|
+
name: "metadata-worker-mentions",
|
|
111
|
+
visitor: {
|
|
112
|
+
Program(programPath, state) {
|
|
113
|
+
const workerMentions = []
|
|
114
|
+
const visitors = {
|
|
115
|
+
NewExpression: (path) => {
|
|
116
|
+
if (workersToTranspile.worker || workersToTranspile.sharedWorker) {
|
|
117
|
+
const mentions = analyzeNewWorkerOrNewSharedWorker(path, {
|
|
118
|
+
isJsModule,
|
|
119
|
+
})
|
|
120
|
+
if (mentions) {
|
|
121
|
+
workerMentions.push(...mentions)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
if (workersToTranspile.serviceWorker) {
|
|
127
|
+
visitors.CallExpression = (path) => {
|
|
128
|
+
const mentions = analyzeServiceWorkerRegisterCall(path)
|
|
129
|
+
if (mentions) {
|
|
130
|
+
workerMentions.push(...mentions)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
programPath.traverse(visitors)
|
|
135
|
+
state.file.metadata.workerMentions = workerMentions
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
File without changes
|
package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js
RENAMED
|
File without changes
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url"
|
|
2
2
|
|
|
3
3
|
import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
|
|
4
|
-
|
|
5
4
|
import {
|
|
6
5
|
getBabelHelperFileUrl,
|
|
7
6
|
babelHelperNameFromUrl,
|
|
8
|
-
} from "
|
|
7
|
+
} from "@jsenv/babel-plugins/main.js"
|
|
9
8
|
|
|
10
9
|
// named import approach found here:
|
|
11
10
|
// https://github.com/rollup/rollup-plugin-babel/blob/18e4232a450f320f44c651aa8c495f21c74d59ac/src/helperPlugin.js#L1
|