@jsenv/core 27.0.0-alpha.3 → 27.0.0-alpha.30
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 +527 -307
- 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} +108 -78
- 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 +31 -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,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Transforms code to make it compatible with browser that would not be able to
|
|
3
|
+
* run it otherwise. For instance:
|
|
4
|
+
* - const -> var
|
|
5
|
+
* - async/await -> promises
|
|
6
|
+
* Anything that is not standard (import.meta.dev for instance) is outside the scope
|
|
7
|
+
* of this plugin
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { jsenvPluginCssParcel } from "./css_parcel/jsenv_plugin_css_parcel.js"
|
|
11
|
+
import { jsenvPluginImportAssertions } from "./import_assertions/jsenv_plugin_import_assertions.js"
|
|
12
|
+
import { jsenvPluginAsJsClassic } from "./as_js_classic/jsenv_plugin_as_js_classic.js"
|
|
13
|
+
import { jsenvPluginBabel } from "./babel/jsenv_plugin_babel.js"
|
|
14
|
+
import { jsenvPluginTopLevelAwait } from "./jsenv_plugin_top_level_await.js"
|
|
15
|
+
|
|
16
|
+
export const jsenvPluginTranspilation = ({
|
|
17
|
+
importAssertions = true,
|
|
18
|
+
css = true,
|
|
19
|
+
jsModuleAsJsClassic = true,
|
|
20
|
+
systemJsInjection = true,
|
|
21
|
+
topLevelAwait = true,
|
|
22
|
+
getCustomBabelPlugins,
|
|
23
|
+
}) => {
|
|
24
|
+
return [
|
|
25
|
+
// import assertions we want it all the time
|
|
26
|
+
...(importAssertions ? [jsenvPluginImportAssertions()] : []),
|
|
27
|
+
// babel also so that rollup can bundle babel helpers for instance
|
|
28
|
+
jsenvPluginBabel({
|
|
29
|
+
topLevelAwait,
|
|
30
|
+
getCustomBabelPlugins,
|
|
31
|
+
}),
|
|
32
|
+
// but the conversion from js_module to js_classic
|
|
33
|
+
// we want to do it after bundling
|
|
34
|
+
// so the build function will disable jsModuleAsJsClassic during build
|
|
35
|
+
// and enable it manually during postbuild
|
|
36
|
+
...(jsModuleAsJsClassic
|
|
37
|
+
? [jsenvPluginAsJsClassic({ systemJsInjection })]
|
|
38
|
+
: []),
|
|
39
|
+
// topLevelAwait must come after js_module_as_js_classic because it's related to the module format
|
|
40
|
+
// so we want to wait to know the module format before transforming things related to top level await
|
|
41
|
+
...(topLevelAwait ? [jsenvPluginTopLevelAwait(topLevelAwait)] : []),
|
|
42
|
+
...(css ? [jsenvPluginCssParcel()] : []),
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
6
|
+
import { applyPostCss } from "@jsenv/utils/css_ast/apply_post_css.js"
|
|
7
|
+
import { postCssPluginUrlVisitor } from "@jsenv/utils/css_ast/postcss_plugin_url_visitor.js"
|
|
8
|
+
|
|
9
|
+
export const parseAndTransformCssUrls = async (urlInfo, context) => {
|
|
10
|
+
const actions = []
|
|
11
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
12
|
+
await applyPostCss({
|
|
13
|
+
sourcemaps: false,
|
|
14
|
+
plugins: [
|
|
15
|
+
postCssPluginUrlVisitor({
|
|
16
|
+
urlVisitor: ({
|
|
17
|
+
declarationNode,
|
|
18
|
+
type,
|
|
19
|
+
specifier,
|
|
20
|
+
line,
|
|
21
|
+
column,
|
|
22
|
+
start,
|
|
23
|
+
end,
|
|
24
|
+
}) => {
|
|
25
|
+
const [reference] = context.referenceUtils.found({
|
|
26
|
+
node: declarationNode,
|
|
27
|
+
type: `css_${type}`,
|
|
28
|
+
specifier,
|
|
29
|
+
line,
|
|
30
|
+
column,
|
|
31
|
+
})
|
|
32
|
+
actions.push(async () => {
|
|
33
|
+
magicSource.replace({
|
|
34
|
+
start,
|
|
35
|
+
end,
|
|
36
|
+
replacement: await context.referenceUtils.readGeneratedSpecifier(
|
|
37
|
+
reference,
|
|
38
|
+
),
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
url: urlInfo.data.rawUrl || urlInfo.url,
|
|
45
|
+
content: urlInfo.content,
|
|
46
|
+
})
|
|
47
|
+
await Promise.all(actions.map((action) => action()))
|
|
48
|
+
return magicSource.toContentAndSourcemap()
|
|
49
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseHtmlString,
|
|
3
|
+
stringifyHtmlAst,
|
|
4
|
+
getHtmlNodeAttributeByName,
|
|
5
|
+
htmlNodePosition,
|
|
6
|
+
visitHtmlAst,
|
|
7
|
+
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
8
|
+
import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js"
|
|
9
|
+
|
|
10
|
+
export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
|
|
11
|
+
const url = urlInfo.data.rawUrl || urlInfo.url
|
|
12
|
+
const content = urlInfo.content
|
|
13
|
+
const { scenario, referenceUtils } = context
|
|
14
|
+
const htmlAst = parseHtmlString(content, {
|
|
15
|
+
storeOriginalPositions: scenario !== "build",
|
|
16
|
+
})
|
|
17
|
+
const actions = []
|
|
18
|
+
visitHtmlUrls({
|
|
19
|
+
url,
|
|
20
|
+
htmlAst,
|
|
21
|
+
onUrl: ({
|
|
22
|
+
type,
|
|
23
|
+
subtype,
|
|
24
|
+
expectedType,
|
|
25
|
+
line,
|
|
26
|
+
column,
|
|
27
|
+
originalLine,
|
|
28
|
+
originalColumn,
|
|
29
|
+
specifier,
|
|
30
|
+
attribute,
|
|
31
|
+
}) => {
|
|
32
|
+
const isRessourceHint = [
|
|
33
|
+
"preconnect",
|
|
34
|
+
"dns-prefetch",
|
|
35
|
+
"prefetch",
|
|
36
|
+
"preload",
|
|
37
|
+
"modulepreload",
|
|
38
|
+
].includes(subtype)
|
|
39
|
+
const [reference] = referenceUtils.found({
|
|
40
|
+
type,
|
|
41
|
+
expectedType,
|
|
42
|
+
line,
|
|
43
|
+
column,
|
|
44
|
+
originalLine,
|
|
45
|
+
originalColumn,
|
|
46
|
+
specifier,
|
|
47
|
+
isRessourceHint,
|
|
48
|
+
})
|
|
49
|
+
actions.push(async () => {
|
|
50
|
+
attribute.value = await referenceUtils.readGeneratedSpecifier(reference)
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
await Promise.all(actions.map((action) => action()))
|
|
55
|
+
return {
|
|
56
|
+
content: stringifyHtmlAst(htmlAst),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
61
|
+
const addDependency = ({
|
|
62
|
+
type,
|
|
63
|
+
subtype,
|
|
64
|
+
expectedType,
|
|
65
|
+
node,
|
|
66
|
+
attribute,
|
|
67
|
+
specifier,
|
|
68
|
+
}) => {
|
|
69
|
+
const generatedFromInlineContent = Boolean(
|
|
70
|
+
getHtmlNodeAttributeByName(node, "generated-from-inline-content"),
|
|
71
|
+
)
|
|
72
|
+
let position
|
|
73
|
+
if (generatedFromInlineContent) {
|
|
74
|
+
// when generated from inline content,
|
|
75
|
+
// line, column is not "src" nor "generated-from-src" but "original-position"
|
|
76
|
+
position = htmlNodePosition.readNodePosition(node)
|
|
77
|
+
} else {
|
|
78
|
+
position = htmlNodePosition.readAttributePosition(node, attribute.name)
|
|
79
|
+
}
|
|
80
|
+
const {
|
|
81
|
+
line,
|
|
82
|
+
column,
|
|
83
|
+
// originalLine, originalColumn
|
|
84
|
+
} = position
|
|
85
|
+
onUrl({
|
|
86
|
+
type,
|
|
87
|
+
subtype,
|
|
88
|
+
expectedType,
|
|
89
|
+
line,
|
|
90
|
+
column,
|
|
91
|
+
// originalLine, originalColumn
|
|
92
|
+
specifier,
|
|
93
|
+
attribute,
|
|
94
|
+
// injected:Boolean(getHtmlNodeAttributeByName(node, "injected-by"))
|
|
95
|
+
// srcGeneratedFromInlineContent
|
|
96
|
+
...readFetchMetas(node),
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
const onNode = (node) => {
|
|
100
|
+
if (node.nodeName === "link") {
|
|
101
|
+
const relAttribute = getHtmlNodeAttributeByName(node, "rel")
|
|
102
|
+
const rel = relAttribute ? relAttribute.value : undefined
|
|
103
|
+
const typeAttribute = getHtmlNodeAttributeByName(node, "type")
|
|
104
|
+
const type = typeAttribute ? typeAttribute.value : undefined
|
|
105
|
+
visitAttributeAsUrlSpecifier({
|
|
106
|
+
type: "link_href",
|
|
107
|
+
subtype: rel,
|
|
108
|
+
node,
|
|
109
|
+
attributeName: "href",
|
|
110
|
+
expectedContentType: type,
|
|
111
|
+
expectedType: {
|
|
112
|
+
manifest: "webmanifest",
|
|
113
|
+
modulepreload: "js_module",
|
|
114
|
+
stylesheet: "css",
|
|
115
|
+
}[rel],
|
|
116
|
+
})
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
// if (node.nodeName === "style") {
|
|
120
|
+
// // styles.push(node)
|
|
121
|
+
// return
|
|
122
|
+
// }
|
|
123
|
+
if (node.nodeName === "script") {
|
|
124
|
+
const typeAttributeNode = getHtmlNodeAttributeByName(node, "type")
|
|
125
|
+
visitAttributeAsUrlSpecifier({
|
|
126
|
+
type: "script_src",
|
|
127
|
+
expectedType: {
|
|
128
|
+
"undefined": "js_classic",
|
|
129
|
+
"text/javascript": "js_classic",
|
|
130
|
+
"module": "js_module",
|
|
131
|
+
"importmap": "importmap",
|
|
132
|
+
}[typeAttributeNode ? typeAttributeNode.value : undefined],
|
|
133
|
+
node,
|
|
134
|
+
attributeName: "src",
|
|
135
|
+
})
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
if (node.nodeName === "a") {
|
|
139
|
+
visitAttributeAsUrlSpecifier({
|
|
140
|
+
type: "a_href",
|
|
141
|
+
node,
|
|
142
|
+
attributeName: "href",
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
if (node.nodeName === "iframe") {
|
|
146
|
+
visitAttributeAsUrlSpecifier({
|
|
147
|
+
type: "iframe_src",
|
|
148
|
+
node,
|
|
149
|
+
attributeName: "src",
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
if (node.nodeName === "img") {
|
|
153
|
+
visitAttributeAsUrlSpecifier({
|
|
154
|
+
type: "img_src",
|
|
155
|
+
node,
|
|
156
|
+
attributeName: "src",
|
|
157
|
+
})
|
|
158
|
+
visitSrcset({
|
|
159
|
+
type: "img_srcset",
|
|
160
|
+
node,
|
|
161
|
+
})
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
if (node.nodeName === "source") {
|
|
165
|
+
visitAttributeAsUrlSpecifier({
|
|
166
|
+
type: "source_src",
|
|
167
|
+
node,
|
|
168
|
+
attributeName: "src",
|
|
169
|
+
})
|
|
170
|
+
visitSrcset({
|
|
171
|
+
type: "source_srcset",
|
|
172
|
+
node,
|
|
173
|
+
})
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
// svg <image> tag
|
|
177
|
+
if (node.nodeName === "image") {
|
|
178
|
+
visitAttributeAsUrlSpecifier({
|
|
179
|
+
type: "image_href",
|
|
180
|
+
node,
|
|
181
|
+
attributeName: "href",
|
|
182
|
+
})
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (node.nodeName === "use") {
|
|
186
|
+
visitAttributeAsUrlSpecifier({
|
|
187
|
+
type: "use_href",
|
|
188
|
+
node,
|
|
189
|
+
attributeName: "href",
|
|
190
|
+
})
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const visitAttributeAsUrlSpecifier = ({
|
|
195
|
+
type,
|
|
196
|
+
subtype,
|
|
197
|
+
expectedType,
|
|
198
|
+
node,
|
|
199
|
+
attributeName,
|
|
200
|
+
}) => {
|
|
201
|
+
const attribute = getHtmlNodeAttributeByName(node, attributeName)
|
|
202
|
+
const value = attribute ? attribute.value : undefined
|
|
203
|
+
if (value) {
|
|
204
|
+
const generatedBy = getHtmlNodeAttributeByName(node, "generated-by")
|
|
205
|
+
if (generatedBy) {
|
|
206
|
+
// during build the importmap is inlined
|
|
207
|
+
// and shoud not be considered as a dependency anymore
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
addDependency({
|
|
211
|
+
type,
|
|
212
|
+
subtype,
|
|
213
|
+
expectedType,
|
|
214
|
+
node,
|
|
215
|
+
attribute,
|
|
216
|
+
specifier:
|
|
217
|
+
attributeName === "generated-from-src" ||
|
|
218
|
+
attributeName === "generated-from-href"
|
|
219
|
+
? new URL(value, url).href
|
|
220
|
+
: value,
|
|
221
|
+
})
|
|
222
|
+
} else if (attributeName === "src") {
|
|
223
|
+
visitAttributeAsUrlSpecifier({
|
|
224
|
+
type,
|
|
225
|
+
subtype,
|
|
226
|
+
expectedType,
|
|
227
|
+
node,
|
|
228
|
+
attributeName: "generated-from-src",
|
|
229
|
+
})
|
|
230
|
+
} else if (attributeName === "href") {
|
|
231
|
+
visitAttributeAsUrlSpecifier({
|
|
232
|
+
type,
|
|
233
|
+
subtype,
|
|
234
|
+
expectedType,
|
|
235
|
+
node,
|
|
236
|
+
attributeName: "generated-from-href",
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const visitSrcset = ({ type, node }) => {
|
|
241
|
+
const srcsetAttribute = getHtmlNodeAttributeByName(node, "srcset")
|
|
242
|
+
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined
|
|
243
|
+
if (srcset) {
|
|
244
|
+
const srcCandidates = htmlAttributeSrcSet.parse(srcset)
|
|
245
|
+
srcCandidates.forEach((srcCandidate) => {
|
|
246
|
+
addDependency({
|
|
247
|
+
type,
|
|
248
|
+
node,
|
|
249
|
+
attribute: srcsetAttribute,
|
|
250
|
+
specifier: srcCandidate.specifier,
|
|
251
|
+
})
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
visitHtmlAst(htmlAst, onNode)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const crossOriginCompatibleTagNames = ["script", "link", "img", "source"]
|
|
259
|
+
const integrityCompatibleTagNames = ["script", "link", "img", "source"]
|
|
260
|
+
const readFetchMetas = (node) => {
|
|
261
|
+
const meta = {}
|
|
262
|
+
if (crossOriginCompatibleTagNames.includes(node.nodeName)) {
|
|
263
|
+
const crossoriginAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
|
|
264
|
+
meta.crossorigin = crossoriginAttribute
|
|
265
|
+
? crossoriginAttribute.value
|
|
266
|
+
: undefined
|
|
267
|
+
}
|
|
268
|
+
if (integrityCompatibleTagNames.includes(node.nodeName)) {
|
|
269
|
+
const integrityAttribute = getHtmlNodeAttributeByName(node, "integrity")
|
|
270
|
+
meta.integrity = integrityAttribute ? integrityAttribute.value : undefined
|
|
271
|
+
}
|
|
272
|
+
return meta
|
|
273
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
|
+
import {
|
|
3
|
+
analyzeImportCall,
|
|
4
|
+
isImportCall,
|
|
5
|
+
analyzeImportExportDeclaration,
|
|
6
|
+
analyzeNewUrlCall,
|
|
7
|
+
analyzeNewWorkerOrNewSharedWorker,
|
|
8
|
+
analyzeImportScriptCalls,
|
|
9
|
+
analyzeSystemRegisterCall,
|
|
10
|
+
analyzeSystemImportCall,
|
|
11
|
+
analyzeServiceWorkerRegisterCall,
|
|
12
|
+
} from "@jsenv/utils/js_ast/js_static_analysis.js"
|
|
13
|
+
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
14
|
+
import { isWebWorkerUrlInfo } from "@jsenv/core/src/omega/web_workers.js"
|
|
15
|
+
|
|
16
|
+
export const parseAndTransformJsUrls = async (urlInfo, context) => {
|
|
17
|
+
const isJsModule = urlInfo.type === "js_module"
|
|
18
|
+
const isWebWorker = isWebWorkerUrlInfo(urlInfo)
|
|
19
|
+
const { metadata } = await applyBabelPlugins({
|
|
20
|
+
babelPlugins: [
|
|
21
|
+
[babelPluginMetadataJsUrlMentions, { isJsModule, isWebWorker }],
|
|
22
|
+
],
|
|
23
|
+
urlInfo,
|
|
24
|
+
})
|
|
25
|
+
const { jsMentions, usesTopLevelAwait, usesImport, usesExport } = metadata
|
|
26
|
+
urlInfo.data.usesImport = usesImport
|
|
27
|
+
urlInfo.data.usesExport = usesExport
|
|
28
|
+
urlInfo.data.usesTopLevelAwait = usesTopLevelAwait
|
|
29
|
+
|
|
30
|
+
const { rootDirectoryUrl, referenceUtils } = context
|
|
31
|
+
const actions = []
|
|
32
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
33
|
+
jsMentions.forEach((jsMention) => {
|
|
34
|
+
const [reference] = referenceUtils.found({
|
|
35
|
+
type: jsMention.type,
|
|
36
|
+
subtype: jsMention.subtype,
|
|
37
|
+
expectedType: jsMention.expectedType,
|
|
38
|
+
expectedSubtype: jsMention.expectedSubtype || urlInfo.subtype,
|
|
39
|
+
line: jsMention.line,
|
|
40
|
+
column: jsMention.column,
|
|
41
|
+
specifier: jsMention.specifier,
|
|
42
|
+
data: jsMention.data,
|
|
43
|
+
baseUrl: {
|
|
44
|
+
"StringLiteral": jsMention.baseUrl,
|
|
45
|
+
"window.origin": rootDirectoryUrl,
|
|
46
|
+
"import.meta.url": urlInfo.url,
|
|
47
|
+
}[jsMention.baseUrlType],
|
|
48
|
+
})
|
|
49
|
+
actions.push(async () => {
|
|
50
|
+
magicSource.replace({
|
|
51
|
+
start: jsMention.start,
|
|
52
|
+
end: jsMention.end,
|
|
53
|
+
replacement: await referenceUtils.readGeneratedSpecifier(reference),
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
await Promise.all(actions.map((action) => action()))
|
|
58
|
+
return magicSource.toContentAndSourcemap()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* see also
|
|
63
|
+
* https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md
|
|
64
|
+
* https://github.com/mjackson/babel-plugin-import-visitor
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
const babelPluginMetadataJsUrlMentions = (_, { isJsModule, isWebWorker }) => {
|
|
68
|
+
return {
|
|
69
|
+
name: "metadata-js-mentions",
|
|
70
|
+
visitor: {
|
|
71
|
+
Program(programPath, state) {
|
|
72
|
+
const jsMentions = []
|
|
73
|
+
let usesImport = false
|
|
74
|
+
let usesExport = false
|
|
75
|
+
let usesTopLevelAwait = false
|
|
76
|
+
|
|
77
|
+
const callOneStaticAnalyzer = (path, analyzer) => {
|
|
78
|
+
const returnValue = analyzer(path)
|
|
79
|
+
if (returnValue === null) {
|
|
80
|
+
return false
|
|
81
|
+
}
|
|
82
|
+
if (Array.isArray(returnValue)) {
|
|
83
|
+
jsMentions.push(...returnValue)
|
|
84
|
+
return true
|
|
85
|
+
}
|
|
86
|
+
if (typeof returnValue === "object") {
|
|
87
|
+
jsMentions.push(returnValue)
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
const callStaticAnalyzers = (path, analysers) => {
|
|
93
|
+
for (const analyzer of analysers) {
|
|
94
|
+
if (callOneStaticAnalyzer(path, analyzer)) {
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const visitors = {
|
|
101
|
+
AwaitExpression: (path) => {
|
|
102
|
+
const closestFunction = path.getFunctionParent()
|
|
103
|
+
if (!closestFunction) {
|
|
104
|
+
usesTopLevelAwait = true
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
NewExpression: (path) => {
|
|
108
|
+
callStaticAnalyzers(path, [
|
|
109
|
+
(path) => analyzeNewWorkerOrNewSharedWorker(path, { isJsModule }),
|
|
110
|
+
(path) => analyzeNewUrlCall(path, { isJsModule }),
|
|
111
|
+
])
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
const callExpressionStaticAnalysers = [
|
|
115
|
+
...(isJsModule
|
|
116
|
+
? [analyzeImportCall]
|
|
117
|
+
: [analyzeSystemRegisterCall, analyzeSystemImportCall]),
|
|
118
|
+
...(isWebWorker ? [analyzeImportScriptCalls] : []),
|
|
119
|
+
analyzeServiceWorkerRegisterCall,
|
|
120
|
+
]
|
|
121
|
+
visitors.CallExpression = (path) => {
|
|
122
|
+
if (isJsModule && !usesImport && isImportCall(path.node)) {
|
|
123
|
+
usesImport = true
|
|
124
|
+
}
|
|
125
|
+
callStaticAnalyzers(path, callExpressionStaticAnalysers)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (isJsModule) {
|
|
129
|
+
Object.assign(visitors, {
|
|
130
|
+
ExportNamedDeclaration: (path) => {
|
|
131
|
+
if (!usesImport && path.node.source) {
|
|
132
|
+
usesImport = true
|
|
133
|
+
}
|
|
134
|
+
usesExport = true
|
|
135
|
+
callStaticAnalyzers(path, [analyzeImportExportDeclaration])
|
|
136
|
+
},
|
|
137
|
+
ExportAllDeclaration: (path) => {
|
|
138
|
+
usesImport = true
|
|
139
|
+
usesExport = true
|
|
140
|
+
callStaticAnalyzers(path, [analyzeImportExportDeclaration])
|
|
141
|
+
},
|
|
142
|
+
ExportDefaultDeclaration: (path) => {
|
|
143
|
+
if (!usesImport && path.node.source) {
|
|
144
|
+
usesImport = true
|
|
145
|
+
}
|
|
146
|
+
usesExport = true
|
|
147
|
+
callStaticAnalyzers(path, [analyzeImportExportDeclaration])
|
|
148
|
+
},
|
|
149
|
+
ImportDeclaration: (path) => {
|
|
150
|
+
usesImport = true
|
|
151
|
+
callStaticAnalyzers(path, [analyzeImportExportDeclaration])
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
programPath.traverse(visitors)
|
|
156
|
+
state.file.metadata.jsMentions = jsMentions
|
|
157
|
+
state.file.metadata.usesImport = usesImport
|
|
158
|
+
state.file.metadata.usesExport = usesExport
|
|
159
|
+
state.file.metadata.usesTopLevelAwait = usesTopLevelAwait
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parseAndTransformHtmlUrls } from "./html/html_urls.js"
|
|
2
|
+
import { parseAndTransformCssUrls } from "./css/css_urls.js"
|
|
3
|
+
import { parseAndTransformJsUrls } from "./js/js_urls.js"
|
|
4
|
+
import { parseAndTransformWebmanifestUrls } from "./webmanifest/webmanifest_urls.js"
|
|
5
|
+
|
|
6
|
+
export const jsenvPluginUrlReferences = () => {
|
|
7
|
+
return {
|
|
8
|
+
name: "jsenv:url_references",
|
|
9
|
+
appliesDuring: "*",
|
|
10
|
+
transformUrlContent: {
|
|
11
|
+
html: parseAndTransformHtmlUrls,
|
|
12
|
+
css: parseAndTransformCssUrls,
|
|
13
|
+
js_classic: parseAndTransformJsUrls,
|
|
14
|
+
js_module: parseAndTransformJsUrls,
|
|
15
|
+
webmanifest: parseAndTransformWebmanifestUrls,
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const parseAndTransformWebmanifestUrls = async (urlInfo, context) => {
|
|
2
|
+
const content = urlInfo.content
|
|
3
|
+
const manifest = JSON.parse(content)
|
|
4
|
+
const actions = []
|
|
5
|
+
const { icons = [] } = manifest
|
|
6
|
+
icons.forEach((icon) => {
|
|
7
|
+
const [reference] = context.referenceUtils.found({
|
|
8
|
+
type: "webmanifest_icon_src",
|
|
9
|
+
specifier: icon.src,
|
|
10
|
+
})
|
|
11
|
+
actions.push(async () => {
|
|
12
|
+
icon.src = await context.referenceUtils.readGeneratedSpecifier(reference)
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
await Promise.all(actions.map((action) => action()))
|
|
16
|
+
return JSON.stringify(manifest, null, " ")
|
|
17
|
+
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export const jsenvPluginUrlResolution = () => {
|
|
2
|
-
const urlResolver = (
|
|
3
|
-
|
|
2
|
+
const urlResolver = (reference) => {
|
|
3
|
+
if (reference.specifier[0] === "#") {
|
|
4
|
+
reference.external = true
|
|
5
|
+
}
|
|
6
|
+
return new URL(
|
|
7
|
+
reference.specifier,
|
|
8
|
+
reference.baseUrl || reference.parentUrl,
|
|
9
|
+
).href
|
|
4
10
|
}
|
|
5
11
|
return {
|
|
6
12
|
name: "jsenv:url_resolution",
|
|
7
13
|
appliesDuring: "*",
|
|
8
|
-
|
|
14
|
+
resolveUrl: {
|
|
9
15
|
"entry_point": urlResolver,
|
|
10
|
-
"js_import_export": urlResolver,
|
|
11
16
|
"link_href": urlResolver,
|
|
12
17
|
"script_src": urlResolver,
|
|
13
18
|
"a_href": urlResolver,
|
|
@@ -21,8 +26,10 @@ export const jsenvPluginUrlResolution = () => {
|
|
|
21
26
|
"css_@import": urlResolver,
|
|
22
27
|
"css_url": urlResolver,
|
|
23
28
|
"sourcemap_comment": urlResolver,
|
|
24
|
-
"
|
|
29
|
+
"js_import_export": urlResolver,
|
|
30
|
+
"js_url_specifier": urlResolver,
|
|
25
31
|
"js_inline_content": urlResolver,
|
|
32
|
+
"webmanifest_icon_src": urlResolver,
|
|
26
33
|
},
|
|
27
34
|
}
|
|
28
35
|
}
|
|
@@ -4,27 +4,27 @@ export const jsenvPluginUrlVersion = ({
|
|
|
4
4
|
return {
|
|
5
5
|
name: "jsenv:url_version",
|
|
6
6
|
appliesDuring: "*", // maybe only during dev?
|
|
7
|
-
|
|
7
|
+
normalizeUrl: (reference) => {
|
|
8
8
|
// "v" search param goal is to enable long-term cache
|
|
9
9
|
// for server response headers
|
|
10
10
|
// it is also used by hmr to bypass browser cache
|
|
11
11
|
// this goal is achieved when we reach this part of the code
|
|
12
12
|
// We get rid of this params so that urlGraph and other parts of the code
|
|
13
13
|
// recognize the url (it is not considered as a different url)
|
|
14
|
-
const urlObject = new URL(url)
|
|
14
|
+
const urlObject = new URL(reference.url)
|
|
15
15
|
urlObject.searchParams.delete("v")
|
|
16
16
|
return urlObject.href
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
if (!data.version) {
|
|
18
|
+
transformUrl: (reference) => {
|
|
19
|
+
if (!reference.data.version) {
|
|
20
20
|
return null
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
if (urlObject.searchParams.has("v")) {
|
|
22
|
+
if (reference.searchParams.has("v")) {
|
|
24
23
|
return null
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
return {
|
|
26
|
+
v: reference.data.version,
|
|
27
|
+
}
|
|
28
28
|
},
|
|
29
29
|
augmentResponse: ({ url }) => {
|
|
30
30
|
if (!longTermCache) {
|