@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,161 @@
|
|
|
1
|
+
import { getBabelHelperFileUrl, requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
2
|
+
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js"
|
|
3
|
+
|
|
4
|
+
export const getBaseBabelPluginStructure = ({ url, isSupported }) => {
|
|
5
|
+
const isBabelPluginNeeded = (babelPluginName) => {
|
|
6
|
+
return !isSupported(babelPluginCompatMap[babelPluginName])
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const babelPluginStructure = {}
|
|
10
|
+
if (isBabelPluginNeeded("proposal-numeric-separator")) {
|
|
11
|
+
babelPluginStructure["proposal-numeric-separator"] = requireBabelPlugin(
|
|
12
|
+
"@babel/plugin-proposal-numeric-separator",
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
if (isBabelPluginNeeded("proposal-json-strings")) {
|
|
16
|
+
babelPluginStructure["proposal-json-strings"] = requireBabelPlugin(
|
|
17
|
+
"@babel/plugin-proposal-json-strings",
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
if (isBabelPluginNeeded("proposal-object-rest-spread")) {
|
|
21
|
+
babelPluginStructure["proposal-object-rest-spread"] = requireBabelPlugin(
|
|
22
|
+
"@babel/plugin-proposal-object-rest-spread",
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
if (isBabelPluginNeeded("proposal-optional-catch-binding")) {
|
|
26
|
+
babelPluginStructure["proposal-optional-catch-binding"] =
|
|
27
|
+
requireBabelPlugin("@babel/plugin-proposal-optional-catch-binding")
|
|
28
|
+
}
|
|
29
|
+
if (isBabelPluginNeeded("proposal-unicode-property-regex")) {
|
|
30
|
+
babelPluginStructure["proposal-unicode-property-regex"] =
|
|
31
|
+
requireBabelPlugin("@babel/plugin-proposal-unicode-property-regex")
|
|
32
|
+
}
|
|
33
|
+
if (isBabelPluginNeeded("transform-async-to-promises")) {
|
|
34
|
+
babelPluginStructure["transform-async-to-promises"] = [
|
|
35
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
36
|
+
{
|
|
37
|
+
topLevelAwait: "ignore", // will be handled by "jsenv:top_level_await" plugin
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
if (isBabelPluginNeeded("transform-arrow-functions")) {
|
|
42
|
+
babelPluginStructure["transform-arrow-functions"] = requireBabelPlugin(
|
|
43
|
+
"@babel/plugin-transform-arrow-functions",
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
if (isBabelPluginNeeded("transform-block-scoped-functions")) {
|
|
47
|
+
babelPluginStructure["transform-block-scoped-functions"] =
|
|
48
|
+
requireBabelPlugin("@babel/plugin-transform-block-scoped-functions")
|
|
49
|
+
}
|
|
50
|
+
if (isBabelPluginNeeded("transform-block-scoping")) {
|
|
51
|
+
babelPluginStructure["transform-block-scoping"] = requireBabelPlugin(
|
|
52
|
+
"@babel/plugin-transform-block-scoping",
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
if (isBabelPluginNeeded("transform-classes")) {
|
|
56
|
+
babelPluginStructure["transform-classes"] = requireBabelPlugin(
|
|
57
|
+
"@babel/plugin-transform-classes",
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
if (isBabelPluginNeeded("transform-computed-properties")) {
|
|
61
|
+
babelPluginStructure["transform-computed-properties"] = requireBabelPlugin(
|
|
62
|
+
"@babel/plugin-transform-computed-properties",
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
if (isBabelPluginNeeded("transform-destructuring")) {
|
|
66
|
+
babelPluginStructure["transform-destructuring"] = requireBabelPlugin(
|
|
67
|
+
"@babel/plugin-transform-destructuring",
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
if (isBabelPluginNeeded("transform-dotall-regex")) {
|
|
71
|
+
babelPluginStructure["transform-dotall-regex"] = requireBabelPlugin(
|
|
72
|
+
"@babel/plugin-transform-dotall-regex",
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
if (isBabelPluginNeeded("transform-duplicate-keys")) {
|
|
76
|
+
babelPluginStructure["transform-duplicate-keys"] = requireBabelPlugin(
|
|
77
|
+
"@babel/plugin-transform-duplicate-keys",
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
if (isBabelPluginNeeded("transform-exponentiation-operator")) {
|
|
81
|
+
babelPluginStructure["transform-exponentiation-operator"] =
|
|
82
|
+
requireBabelPlugin("@babel/plugin-transform-exponentiation-operator")
|
|
83
|
+
}
|
|
84
|
+
if (isBabelPluginNeeded("transform-for-of")) {
|
|
85
|
+
babelPluginStructure["transform-for-of"] = requireBabelPlugin(
|
|
86
|
+
"@babel/plugin-transform-for-of",
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
if (isBabelPluginNeeded("transform-function-name")) {
|
|
90
|
+
babelPluginStructure["transform-function-name"] = requireBabelPlugin(
|
|
91
|
+
"@babel/plugin-transform-function-name",
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
if (isBabelPluginNeeded("transform-literals")) {
|
|
95
|
+
babelPluginStructure["transform-literals"] = requireBabelPlugin(
|
|
96
|
+
"@babel/plugin-transform-literals",
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
if (isBabelPluginNeeded("transform-new-target")) {
|
|
100
|
+
babelPluginStructure["transform-new-target"] = requireBabelPlugin(
|
|
101
|
+
"@babel/plugin-transform-new-target",
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
if (isBabelPluginNeeded("transform-object-super")) {
|
|
105
|
+
babelPluginStructure["transform-object-super"] = requireBabelPlugin(
|
|
106
|
+
"@babel/plugin-transform-object-super",
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
if (isBabelPluginNeeded("transform-parameters")) {
|
|
110
|
+
babelPluginStructure["transform-parameters"] = requireBabelPlugin(
|
|
111
|
+
"@babel/plugin-transform-parameters",
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
if (isBabelPluginNeeded("transform-regenerator")) {
|
|
115
|
+
babelPluginStructure["transform-regenerator"] = [
|
|
116
|
+
requireBabelPlugin("@babel/plugin-transform-regenerator"),
|
|
117
|
+
{
|
|
118
|
+
asyncGenerators: true,
|
|
119
|
+
generators: true,
|
|
120
|
+
async: false,
|
|
121
|
+
},
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
if (isBabelPluginNeeded("transform-shorthand-properties")) {
|
|
125
|
+
babelPluginStructure["transform-shorthand-properties"] = [
|
|
126
|
+
requireBabelPlugin("@babel/plugin-transform-shorthand-properties"),
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
if (isBabelPluginNeeded("transform-spread")) {
|
|
130
|
+
babelPluginStructure["transform-spread"] = [
|
|
131
|
+
requireBabelPlugin("@babel/plugin-transform-spread"),
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
if (isBabelPluginNeeded("transform-sticky-regex")) {
|
|
135
|
+
babelPluginStructure["transform-sticky-regex"] = [
|
|
136
|
+
requireBabelPlugin("@babel/plugin-transform-sticky-regex"),
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
if (isBabelPluginNeeded("transform-template-literals")) {
|
|
140
|
+
babelPluginStructure["transform-template-literals"] = [
|
|
141
|
+
requireBabelPlugin("@babel/plugin-transform-template-literals"),
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
if (
|
|
145
|
+
isBabelPluginNeeded("transform-typeof-symbol") &&
|
|
146
|
+
// prevent "typeof" to be injected into itself:
|
|
147
|
+
// - not needed
|
|
148
|
+
// - would create infinite attempt to transform typeof
|
|
149
|
+
url !== getBabelHelperFileUrl("typeof")
|
|
150
|
+
) {
|
|
151
|
+
babelPluginStructure["transform-typeof-symbol"] = [
|
|
152
|
+
requireBabelPlugin("@babel/plugin-transform-typeof-symbol"),
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
if (isBabelPluginNeeded("transform-unicode-regex")) {
|
|
156
|
+
babelPluginStructure["transform-unicode-regex"] = [
|
|
157
|
+
requireBabelPlugin("@babel/plugin-transform-unicode-regex"),
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
return babelPluginStructure
|
|
161
|
+
}
|
|
File without changes
|
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
2
|
|
|
3
|
+
import { RUNTIME_COMPAT } from "@jsenv/core/src/omega/compat/runtime_compat.js"
|
|
3
4
|
import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js"
|
|
5
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./helpers/babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
4
6
|
import { babelPluginNewStylesheetAsJsenvImport } from "./new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js"
|
|
5
7
|
import { babelPluginGlobalThisAsJsenvImport } from "./global_this/babel_plugin_global_this_as_jsenv_import.js"
|
|
6
8
|
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
7
|
-
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_helper/babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
8
9
|
|
|
9
|
-
export const jsenvPluginBabel = ({
|
|
10
|
-
getCustomBabelPlugins,
|
|
11
|
-
topLevelAwait,
|
|
12
|
-
} = {}) => {
|
|
10
|
+
export const jsenvPluginBabel = ({ getCustomBabelPlugins } = {}) => {
|
|
13
11
|
const transformWithBabel = async (urlInfo, context) => {
|
|
14
12
|
const isJsModule = urlInfo.type === "js_module"
|
|
15
|
-
const isWorker =
|
|
16
|
-
|
|
17
|
-
const
|
|
13
|
+
const isWorker = urlInfo.subtype === "worker"
|
|
14
|
+
const isServiceWorker = urlInfo.subtype === "service_worker"
|
|
15
|
+
const isSharedWorker = urlInfo.subtype === "shared_worker"
|
|
16
|
+
const isWorkerContext = isWorker || isServiceWorker || isSharedWorker
|
|
17
|
+
|
|
18
|
+
let { clientRuntimeCompat } = context
|
|
19
|
+
if (isWorker) {
|
|
20
|
+
clientRuntimeCompat = RUNTIME_COMPAT.add(clientRuntimeCompat, "worker")
|
|
21
|
+
} else if (isServiceWorker) {
|
|
22
|
+
// when code is executed by a service worker we can assume
|
|
23
|
+
// the execution context supports more than the default one
|
|
24
|
+
// for instance arrow function are supported
|
|
25
|
+
clientRuntimeCompat = RUNTIME_COMPAT.add(
|
|
26
|
+
clientRuntimeCompat,
|
|
27
|
+
"service_worker",
|
|
28
|
+
)
|
|
29
|
+
} else if (isSharedWorker) {
|
|
30
|
+
clientRuntimeCompat = RUNTIME_COMPAT.add(
|
|
31
|
+
clientRuntimeCompat,
|
|
32
|
+
"shared_worker",
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { referenceUtils } = context
|
|
37
|
+
const isSupported = (feature) =>
|
|
38
|
+
RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
|
|
18
39
|
const babelPluginStructure = getBaseBabelPluginStructure({
|
|
19
40
|
url: urlInfo.url,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
usesTopLevelAwait: urlInfo.data.usesTopLevelAwait,
|
|
23
|
-
isJsModule,
|
|
24
|
-
isWorker,
|
|
41
|
+
isSupported,
|
|
42
|
+
isWorkerContext,
|
|
25
43
|
})
|
|
26
44
|
if (getCustomBabelPlugins) {
|
|
27
45
|
Object.assign(babelPluginStructure, getCustomBabelPlugins(context))
|
|
@@ -31,11 +49,12 @@ export const jsenvPluginBabel = ({
|
|
|
31
49
|
const getImportSpecifier = (clientFileUrl) => {
|
|
32
50
|
const [reference] = referenceUtils.inject({
|
|
33
51
|
type: "js_import_export",
|
|
52
|
+
expectedType: "js_module",
|
|
34
53
|
specifier: clientFileUrl,
|
|
35
54
|
})
|
|
36
55
|
return JSON.parse(reference.generatedSpecifier)
|
|
37
56
|
}
|
|
38
|
-
if (!
|
|
57
|
+
if (!isSupported("global_this")) {
|
|
39
58
|
babelPluginStructure["global-this-as-jsenv-import"] = [
|
|
40
59
|
babelPluginGlobalThisAsJsenvImport,
|
|
41
60
|
{
|
|
@@ -43,7 +62,7 @@ export const jsenvPluginBabel = ({
|
|
|
43
62
|
},
|
|
44
63
|
]
|
|
45
64
|
}
|
|
46
|
-
if (!
|
|
65
|
+
if (!isSupported("async_generator_function")) {
|
|
47
66
|
babelPluginStructure["regenerator-runtime-as-jsenv-import"] = [
|
|
48
67
|
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
49
68
|
{
|
|
@@ -51,7 +70,7 @@ export const jsenvPluginBabel = ({
|
|
|
51
70
|
},
|
|
52
71
|
]
|
|
53
72
|
}
|
|
54
|
-
if (!
|
|
73
|
+
if (!isSupported("new_stylesheet")) {
|
|
55
74
|
babelPluginStructure["new-stylesheet-as-jsenv-import"] = [
|
|
56
75
|
babelPluginNewStylesheetAsJsenvImport,
|
|
57
76
|
{
|
|
@@ -76,22 +95,19 @@ export const jsenvPluginBabel = ({
|
|
|
76
95
|
)
|
|
77
96
|
const { code, map } = await applyBabelPlugins({
|
|
78
97
|
babelPlugins,
|
|
79
|
-
|
|
80
|
-
generatedUrl: urlInfo.generatedUrl,
|
|
81
|
-
content: urlInfo.content,
|
|
98
|
+
urlInfo,
|
|
82
99
|
})
|
|
83
100
|
return {
|
|
84
101
|
content: code,
|
|
85
102
|
sourcemap: map,
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
|
-
|
|
89
105
|
return {
|
|
90
106
|
name: "jsenv:babel",
|
|
91
107
|
appliesDuring: "*",
|
|
92
|
-
|
|
93
|
-
js_module: transformWithBabel,
|
|
108
|
+
finalizeUrlContent: {
|
|
94
109
|
js_classic: transformWithBabel,
|
|
110
|
+
js_module: transformWithBabel,
|
|
95
111
|
},
|
|
96
112
|
}
|
|
97
113
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* TODO:
|
|
3
|
-
* - code should also inject helper when code uses new keyword on "CSSStyleSheet"
|
|
4
|
-
* - code should also inject helper when code uses "document.adoptedStylesheets"
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
import { pathToFileURL } from "node:url"
|
|
8
2
|
|
|
9
3
|
import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
|
|
@@ -27,6 +21,18 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
27
21
|
}
|
|
28
22
|
let usesNewStylesheet = false
|
|
29
23
|
programPath.traverse({
|
|
24
|
+
NewExpression: (path) => {
|
|
25
|
+
usesNewStylesheet = isNewCssStyleSheetCall(path.node)
|
|
26
|
+
if (usesNewStylesheet) {
|
|
27
|
+
path.stop()
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
MemberExpression: (path) => {
|
|
31
|
+
usesNewStylesheet = isDocumentAdoptedStyleSheets(path.node)
|
|
32
|
+
if (usesNewStylesheet) {
|
|
33
|
+
path.stop()
|
|
34
|
+
}
|
|
35
|
+
},
|
|
30
36
|
CallExpression: (path) => {
|
|
31
37
|
if (path.node.callee.type !== "Import") {
|
|
32
38
|
// Some other function call, not import();
|
|
@@ -90,6 +96,24 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
|
|
99
|
+
const isNewCssStyleSheetCall = (node) => {
|
|
100
|
+
return (
|
|
101
|
+
node.type === "NewExpression" &&
|
|
102
|
+
node.callee.type === "Identifier" &&
|
|
103
|
+
node.callee.name === "CSSStyleSheet"
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const isDocumentAdoptedStyleSheets = (node) => {
|
|
108
|
+
return (
|
|
109
|
+
node.type === "MemberExpression" &&
|
|
110
|
+
node.object.type === "Identifier" &&
|
|
111
|
+
node.object.name === "document" &&
|
|
112
|
+
node.property.type === "Identifier" &&
|
|
113
|
+
node.property.name === "adoptedStyleSheets"
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
93
117
|
const hasCssModuleQueryParam = (path) => {
|
|
94
118
|
const { node } = path
|
|
95
119
|
return (
|
package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { transpileWithParcel } from "@jsenv/utils/css_ast/parcel_css.js"
|
|
2
|
+
|
|
3
|
+
// https://github.com/parcel-bundler/parcel-css
|
|
4
|
+
export const jsenvPluginCssParcel = () => {
|
|
5
|
+
return {
|
|
6
|
+
name: "jsenv:css_parcel",
|
|
7
|
+
appliesDuring: "*",
|
|
8
|
+
transformUrlContent: {
|
|
9
|
+
css: (urlInfo, context) => {
|
|
10
|
+
const { code, map } = transpileWithParcel(urlInfo, context)
|
|
11
|
+
return {
|
|
12
|
+
content: String(code),
|
|
13
|
+
sourcemap: map,
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const fetchOriginalUrlInfo = async ({
|
|
2
|
+
urlInfo,
|
|
3
|
+
context,
|
|
4
|
+
searchParam,
|
|
5
|
+
expectedType,
|
|
6
|
+
}) => {
|
|
7
|
+
const urlObject = new URL(urlInfo.url)
|
|
8
|
+
const { searchParams } = urlObject
|
|
9
|
+
if (!searchParams.has(searchParam)) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
searchParams.delete(searchParam)
|
|
13
|
+
const originalUrl = urlObject.href
|
|
14
|
+
const originalReference = {
|
|
15
|
+
...(context.reference.original || context.reference),
|
|
16
|
+
expectedType,
|
|
17
|
+
}
|
|
18
|
+
originalReference.url = originalUrl
|
|
19
|
+
const originalUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(
|
|
20
|
+
originalReference.url,
|
|
21
|
+
)
|
|
22
|
+
await context.fetchUrlContent({
|
|
23
|
+
reference: originalReference,
|
|
24
|
+
urlInfo: originalUrlInfo,
|
|
25
|
+
})
|
|
26
|
+
if (originalUrlInfo.dependents.size === 0) {
|
|
27
|
+
context.urlGraph.deleteUrlInfo(originalUrlInfo.url)
|
|
28
|
+
}
|
|
29
|
+
return originalUrlInfo
|
|
30
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { urlToFilename } from "@jsenv/filesystem"
|
|
2
|
+
|
|
3
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
4
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
5
|
+
import { injectQueryParamsIntoSpecifier } from "@jsenv/utils/urls/url_utils.js"
|
|
6
|
+
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
7
|
+
|
|
8
|
+
import { fetchOriginalUrlInfo } from "../fetch_original_url_info.js"
|
|
9
|
+
import { babelPluginMetadataImportAssertions } from "./helpers/babel_plugin_metadata_import_assertions.js"
|
|
10
|
+
|
|
11
|
+
export const jsenvPluginImportAssertions = () => {
|
|
12
|
+
const importAssertions = {
|
|
13
|
+
name: "jsenv:import_assertions",
|
|
14
|
+
appliesDuring: "*",
|
|
15
|
+
transformUrlContent: {
|
|
16
|
+
js_module: async (urlInfo, context) => {
|
|
17
|
+
const importTypesToTranspile = getImportTypesToTranspile(context)
|
|
18
|
+
if (importTypesToTranspile.length === 0) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
const { metadata } = await applyBabelPlugins({
|
|
22
|
+
babelPlugins: [babelPluginMetadataImportAssertions],
|
|
23
|
+
urlInfo,
|
|
24
|
+
})
|
|
25
|
+
const { importAssertions } = metadata
|
|
26
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
27
|
+
importAssertions.forEach((importAssertion) => {
|
|
28
|
+
const assertType = importAssertion.assert.type
|
|
29
|
+
if (!importTypesToTranspile.includes(assertType)) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
const { searchParam } = importAsInfos[assertType]
|
|
33
|
+
const { path } = importAssertion
|
|
34
|
+
const { node } = path
|
|
35
|
+
if (node.type === "CallExpression") {
|
|
36
|
+
const importSpecifierPath = path.get("arguments")[0]
|
|
37
|
+
const specifier = importSpecifierPath.node.value
|
|
38
|
+
const reference = context.referenceUtils.findByGeneratedSpecifier(
|
|
39
|
+
JSON.stringify(specifier),
|
|
40
|
+
)
|
|
41
|
+
const [newReference] = context.referenceUtils.update(reference, {
|
|
42
|
+
expectedType: "js_module",
|
|
43
|
+
specifier: injectQueryParamsIntoSpecifier(specifier, {
|
|
44
|
+
[searchParam]: "",
|
|
45
|
+
}),
|
|
46
|
+
filename: `${urlToFilename(reference.url)}.js`,
|
|
47
|
+
})
|
|
48
|
+
magicSource.replace({
|
|
49
|
+
start: importSpecifierPath.node.start,
|
|
50
|
+
end: importSpecifierPath.node.end,
|
|
51
|
+
replacement: newReference.generatedSpecifier,
|
|
52
|
+
})
|
|
53
|
+
const secondArgPath = path.get("arguments")[1]
|
|
54
|
+
magicSource.remove({
|
|
55
|
+
start: secondArgPath.node.start,
|
|
56
|
+
end: secondArgPath.node.end,
|
|
57
|
+
})
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
const importSpecifierPath = path.get("source")
|
|
61
|
+
const specifier = importSpecifierPath.node.value
|
|
62
|
+
const reference = context.referenceUtils.findByGeneratedSpecifier(
|
|
63
|
+
JSON.stringify(specifier),
|
|
64
|
+
)
|
|
65
|
+
const [newReference] = context.referenceUtils.update(reference, {
|
|
66
|
+
expectedType: "js_module",
|
|
67
|
+
specifier: injectQueryParamsIntoSpecifier(specifier, {
|
|
68
|
+
[searchParam]: "",
|
|
69
|
+
}),
|
|
70
|
+
filename: `${urlToFilename(reference.url)}.js`,
|
|
71
|
+
})
|
|
72
|
+
magicSource.replace({
|
|
73
|
+
start: importSpecifierPath.node.start,
|
|
74
|
+
end: importSpecifierPath.node.end,
|
|
75
|
+
replacement: newReference.generatedSpecifier,
|
|
76
|
+
})
|
|
77
|
+
const assertionsPath = path.get("assertions")[0]
|
|
78
|
+
magicSource.remove({
|
|
79
|
+
start: assertionsPath.node.start,
|
|
80
|
+
end: assertionsPath.node.end,
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
return magicSource.toContentAndSourcemap()
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
return [importAssertions, ...jsenvPluginAsModules()]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const jsenvPluginAsModules = () => {
|
|
91
|
+
const inlineContentClientFileUrl = new URL(
|
|
92
|
+
"../../inline/client/inline_content.js",
|
|
93
|
+
import.meta.url,
|
|
94
|
+
).href
|
|
95
|
+
|
|
96
|
+
const asJsonModule = {
|
|
97
|
+
name: `jsenv:as_json_module`,
|
|
98
|
+
appliesDuring: "*",
|
|
99
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
100
|
+
const originalUrlInfo = await fetchOriginalUrlInfo({
|
|
101
|
+
urlInfo,
|
|
102
|
+
context,
|
|
103
|
+
searchParam: "as_json_module",
|
|
104
|
+
expectedType: "json",
|
|
105
|
+
})
|
|
106
|
+
if (!originalUrlInfo) {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
const jsonText = JSON.stringify(originalUrlInfo.content.trim())
|
|
110
|
+
return {
|
|
111
|
+
type: "js_module",
|
|
112
|
+
contentType: "text/javascript",
|
|
113
|
+
// here we could `export default ${jsonText}`:
|
|
114
|
+
// but js engine are optimized to recognize JSON.parse
|
|
115
|
+
// and use a faster parsing strategy
|
|
116
|
+
content: `export default JSON.parse(${jsonText})`,
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const asCssModule = {
|
|
122
|
+
name: `jsenv:as_css_module`,
|
|
123
|
+
appliesDuring: "*",
|
|
124
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
125
|
+
const originalUrlInfo = await fetchOriginalUrlInfo({
|
|
126
|
+
urlInfo,
|
|
127
|
+
context,
|
|
128
|
+
searchParam: "as_css_module",
|
|
129
|
+
expectedType: "css",
|
|
130
|
+
})
|
|
131
|
+
if (!originalUrlInfo) {
|
|
132
|
+
return null
|
|
133
|
+
}
|
|
134
|
+
const cssText = JS_QUOTES.escapeSpecialChars(originalUrlInfo.content, {
|
|
135
|
+
// If template string is choosen and runtime do not support template literals
|
|
136
|
+
// it's ok because "jsenv:new_inline_content" plugin executes after this one
|
|
137
|
+
// and convert template strings into raw strings
|
|
138
|
+
canUseTemplateString: true,
|
|
139
|
+
})
|
|
140
|
+
return {
|
|
141
|
+
type: "js_module",
|
|
142
|
+
contentType: "text/javascript",
|
|
143
|
+
content: `import { InlineContent } from ${JSON.stringify(
|
|
144
|
+
inlineContentClientFileUrl,
|
|
145
|
+
)}
|
|
146
|
+
|
|
147
|
+
const inlineContent = new InlineContent(${cssText}, { type: "text/css" })
|
|
148
|
+
const stylesheet = new CSSStyleSheet()
|
|
149
|
+
stylesheet.replaceSync(inlineContent.text)
|
|
150
|
+
export default stylesheet`,
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const asTextModule = {
|
|
156
|
+
name: `jsenv:as_text_module`,
|
|
157
|
+
appliesDuring: "*",
|
|
158
|
+
fetchUrlContent: async (urlInfo, context) => {
|
|
159
|
+
const originalUrlInfo = await fetchOriginalUrlInfo({
|
|
160
|
+
urlInfo,
|
|
161
|
+
context,
|
|
162
|
+
searchParam: "as_text_module",
|
|
163
|
+
expectedType: "text",
|
|
164
|
+
})
|
|
165
|
+
if (!originalUrlInfo) {
|
|
166
|
+
return null
|
|
167
|
+
}
|
|
168
|
+
const textPlain = JS_QUOTES.escapeSpecialChars(urlInfo.content, {
|
|
169
|
+
// If template string is choosen and runtime do not support template literals
|
|
170
|
+
// it's ok because "jsenv:new_inline_content" plugin executes after this one
|
|
171
|
+
// and convert template strings into raw strings
|
|
172
|
+
canUseTemplateString: true,
|
|
173
|
+
})
|
|
174
|
+
return {
|
|
175
|
+
type: "js_module",
|
|
176
|
+
contentType: "text/javascript",
|
|
177
|
+
content: `import { InlineContent } from ${JSON.stringify(
|
|
178
|
+
inlineContentClientFileUrl,
|
|
179
|
+
)}
|
|
180
|
+
|
|
181
|
+
const inlineContent = new InlineContent(${textPlain}, { type: "text/plain" })
|
|
182
|
+
export default inlineContent.text`,
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return [asJsonModule, asCssModule, asTextModule]
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const importAsInfos = {
|
|
191
|
+
json: {
|
|
192
|
+
searchParam: "as_json_module",
|
|
193
|
+
},
|
|
194
|
+
css: {
|
|
195
|
+
searchParam: "as_css_module",
|
|
196
|
+
},
|
|
197
|
+
text: {
|
|
198
|
+
searchParam: "as_text_module",
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const getImportTypesToTranspile = ({
|
|
203
|
+
scenario,
|
|
204
|
+
isSupportedOnCurrentClients,
|
|
205
|
+
}) => {
|
|
206
|
+
// during build always replace import assertions with the js:
|
|
207
|
+
// - means rollup can bundle more js file together
|
|
208
|
+
// - means url versioning can work for css inlined in js
|
|
209
|
+
// - avoid rollup to see import assertions
|
|
210
|
+
// We would have to tell rollup to ignore import with assertion
|
|
211
|
+
if (scenario === "build") {
|
|
212
|
+
return ["json", "css", "text"]
|
|
213
|
+
}
|
|
214
|
+
const importTypes = []
|
|
215
|
+
if (!isSupportedOnCurrentClients("import_type_json")) {
|
|
216
|
+
importTypes.push("json")
|
|
217
|
+
}
|
|
218
|
+
if (!isSupportedOnCurrentClients("import_type_css")) {
|
|
219
|
+
importTypes.push("css")
|
|
220
|
+
}
|
|
221
|
+
if (!isSupportedOnCurrentClients("import_type_text")) {
|
|
222
|
+
importTypes.push("text")
|
|
223
|
+
}
|
|
224
|
+
return importTypes
|
|
225
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
2
|
+
|
|
3
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
4
|
+
|
|
5
|
+
export const jsenvPluginTopLevelAwait = () => {
|
|
6
|
+
return {
|
|
7
|
+
name: "jsenv:top_level_await",
|
|
8
|
+
appliesDuring: "*",
|
|
9
|
+
transformUrlContent: {
|
|
10
|
+
js_module: async (urlInfo, context) => {
|
|
11
|
+
if (!urlInfo.data.usesTopLevelAwait) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
if (context.isSupportedOnCurrentClients("top_level_await")) {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
const { code, map } = await applyBabelPlugins({
|
|
18
|
+
urlInfo,
|
|
19
|
+
babelPlugins: [
|
|
20
|
+
[
|
|
21
|
+
requireBabelPlugin("babel-plugin-transform-async-to-promises"),
|
|
22
|
+
{
|
|
23
|
+
// Maybe we could pass target: "es6" when we support arrow function
|
|
24
|
+
// https://github.com/rpetrich/babel-plugin-transform-async-to-promises/blob/92755ff8c943c97596523e586b5fa515c2e99326/async-to-promises.ts#L55
|
|
25
|
+
topLevelAwait: "simple",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
],
|
|
29
|
+
})
|
|
30
|
+
return {
|
|
31
|
+
content: code,
|
|
32
|
+
sourcemap: map,
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|