@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
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Needs to be updated so that it sill works in the following cases:
|
|
3
|
-
* - templates literals transformed to regular stuff by babel
|
|
4
|
-
* - tagged name renamed by rollup
|
|
5
|
-
* - the template named is minified by terser
|
|
6
|
-
* In the cases above I must remain capable to recoginize the template literal
|
|
7
|
-
* to be able to update the urls inside (and even version the urls)
|
|
8
|
-
* because url versioning happens after minification it can be challenging
|
|
9
|
-
*
|
|
10
|
-
* TODO: use "keep_classnames" https://github.com/terser/terser#compress-options
|
|
11
|
-
* so that new InlineContent can be recognized after minification
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
15
|
-
import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
|
|
16
|
-
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
17
|
-
import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js"
|
|
18
|
-
|
|
19
|
-
export const jsenvPluginNewInlineContent = ({ allowEscapeForVersioning }) => {
|
|
20
|
-
return {
|
|
21
|
-
name: "jsenv:new_inline_content",
|
|
22
|
-
appliesDuring: "*",
|
|
23
|
-
transform: {
|
|
24
|
-
js_module: async (
|
|
25
|
-
{ url, generatedUrl, content, originalContent },
|
|
26
|
-
{ referenceUtils, cook, isSupportedOnRuntime },
|
|
27
|
-
) => {
|
|
28
|
-
const { metadata } = await applyBabelPlugins({
|
|
29
|
-
babelPlugins: [babelPluginMetadataInlineContentCalls],
|
|
30
|
-
url,
|
|
31
|
-
generatedUrl,
|
|
32
|
-
content,
|
|
33
|
-
})
|
|
34
|
-
const { inlineContentCalls } = metadata
|
|
35
|
-
if (inlineContentCalls.length === 0) {
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
const magicSource = createMagicSource(content)
|
|
39
|
-
await inlineContentCalls.reduce(async (previous, inlineContentCall) => {
|
|
40
|
-
await previous
|
|
41
|
-
const inlineUrl = generateInlineContentUrl({
|
|
42
|
-
url,
|
|
43
|
-
extension: {
|
|
44
|
-
"application/json": ".json",
|
|
45
|
-
"text/css": ".css",
|
|
46
|
-
"text/plain": ".txt",
|
|
47
|
-
"application/octet-stream": "",
|
|
48
|
-
}[inlineContentCall.contentType],
|
|
49
|
-
line: inlineContentCall.line,
|
|
50
|
-
column: inlineContentCall.column,
|
|
51
|
-
lineEnd: inlineContentCall.lineEnd,
|
|
52
|
-
columnEnd: inlineContentCall.columnEnd,
|
|
53
|
-
})
|
|
54
|
-
let { quote } = inlineContentCall
|
|
55
|
-
if (
|
|
56
|
-
quote === "`" &&
|
|
57
|
-
!isSupportedOnRuntime("transform-template-literals")
|
|
58
|
-
) {
|
|
59
|
-
// if quote is "`" and template literals are not supported
|
|
60
|
-
// we'll use a regular string (single or double quote)
|
|
61
|
-
// when rendering the string
|
|
62
|
-
quote = JS_QUOTES.pickBest(inlineContentCall.content)
|
|
63
|
-
}
|
|
64
|
-
const [inlineReference, inlineUrlInfo] = referenceUtils.foundInline({
|
|
65
|
-
type: "js_inline_content",
|
|
66
|
-
isOriginal: content === originalContent,
|
|
67
|
-
line: inlineContentCall.line,
|
|
68
|
-
column: inlineContentCall.column,
|
|
69
|
-
specifier: inlineUrl,
|
|
70
|
-
contentType: inlineContentCall.contentType,
|
|
71
|
-
content: inlineContentCall.content,
|
|
72
|
-
})
|
|
73
|
-
inlineUrlInfo.jsQuote = quote
|
|
74
|
-
inlineReference.escape = (value) =>
|
|
75
|
-
JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
|
|
76
|
-
await cook({
|
|
77
|
-
reference: inlineReference,
|
|
78
|
-
urlInfo: inlineUrlInfo,
|
|
79
|
-
})
|
|
80
|
-
magicSource.replace({
|
|
81
|
-
start: inlineContentCall.start,
|
|
82
|
-
end: inlineContentCall.end,
|
|
83
|
-
replacement: JS_QUOTES.escapeSpecialChars(inlineUrlInfo.content, {
|
|
84
|
-
quote,
|
|
85
|
-
allowEscapeForVersioning,
|
|
86
|
-
}),
|
|
87
|
-
})
|
|
88
|
-
}, Promise.resolve())
|
|
89
|
-
return magicSource.toContentAndSourcemap()
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const babelPluginMetadataInlineContentCalls = () => {
|
|
96
|
-
return {
|
|
97
|
-
name: "metadata-inline-content-calls",
|
|
98
|
-
visitor: {
|
|
99
|
-
Program: (programPath, state) => {
|
|
100
|
-
const inlineContentCalls = []
|
|
101
|
-
programPath.traverse({
|
|
102
|
-
NewExpression: (path) => {
|
|
103
|
-
const newInlineContentCall = parseAsNewInlineContentCall(path)
|
|
104
|
-
if (newInlineContentCall) {
|
|
105
|
-
inlineContentCalls.push(newInlineContentCall)
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
state.file.metadata.inlineContentCalls = inlineContentCalls
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const parseAsNewInlineContentCall = (path) => {
|
|
116
|
-
const node = path.node
|
|
117
|
-
if (node.callee.type === "Identifier") {
|
|
118
|
-
// terser rename import to use a shorter name
|
|
119
|
-
const name = getOriginalName(path, node.callee.name)
|
|
120
|
-
if (name !== "InlineContent") {
|
|
121
|
-
return null
|
|
122
|
-
}
|
|
123
|
-
} else if (node.callee.id) {
|
|
124
|
-
// terser might combine new InlineContent('') declaration and usage
|
|
125
|
-
if (node.callee.id.type !== "Identifier") {
|
|
126
|
-
return null
|
|
127
|
-
}
|
|
128
|
-
const name = getOriginalName(path, node.callee.id.name)
|
|
129
|
-
if (name !== "InlineContent") {
|
|
130
|
-
return null
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (node.arguments.length !== 2) {
|
|
134
|
-
return null
|
|
135
|
-
}
|
|
136
|
-
const [firstArg, secondArg] = node.arguments
|
|
137
|
-
if (secondArg.type !== "ObjectExpression") {
|
|
138
|
-
return null
|
|
139
|
-
}
|
|
140
|
-
const typePropertyNode = secondArg.properties.find((property) => {
|
|
141
|
-
return (
|
|
142
|
-
property.key.type === "Identifier" &&
|
|
143
|
-
property.key.name === "type" &&
|
|
144
|
-
property.type === "ObjectProperty" &&
|
|
145
|
-
property.value.type === "StringLiteral"
|
|
146
|
-
)
|
|
147
|
-
})
|
|
148
|
-
if (!typePropertyNode) {
|
|
149
|
-
return null
|
|
150
|
-
}
|
|
151
|
-
const type = typePropertyNode.value.value
|
|
152
|
-
if (firstArg.type === "StringLiteral") {
|
|
153
|
-
const position = getNodePosition(firstArg)
|
|
154
|
-
return {
|
|
155
|
-
nodeType: "StringLiteral",
|
|
156
|
-
quote: firstArg.extra.raw[0],
|
|
157
|
-
contentType: type,
|
|
158
|
-
content: firstArg.value,
|
|
159
|
-
...position,
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (firstArg.type === "TemplateLiteral") {
|
|
163
|
-
const quasis = firstArg.quasis
|
|
164
|
-
if (quasis.length !== 1) {
|
|
165
|
-
return null
|
|
166
|
-
}
|
|
167
|
-
const templateElementNode = quasis[0]
|
|
168
|
-
const position = getNodePosition(firstArg)
|
|
169
|
-
return {
|
|
170
|
-
nodeType: "TemplateLiteral",
|
|
171
|
-
quote: "`",
|
|
172
|
-
contentType: type,
|
|
173
|
-
content: templateElementNode.value.cooked,
|
|
174
|
-
...position,
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return null
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const getNodePosition = (node) => {
|
|
181
|
-
return {
|
|
182
|
-
start: node.start,
|
|
183
|
-
end: node.end,
|
|
184
|
-
line: node.loc.start.line,
|
|
185
|
-
column: node.loc.start.column,
|
|
186
|
-
lineEnd: node.loc.end.line,
|
|
187
|
-
columnEnd: node.loc.end.column,
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const getOriginalName = (path, name) => {
|
|
192
|
-
const binding = path.scope.getBinding(name)
|
|
193
|
-
if (!binding) {
|
|
194
|
-
return name
|
|
195
|
-
}
|
|
196
|
-
if (binding.path.type === "ImportSpecifier") {
|
|
197
|
-
const importedName = binding.path.node.imported.name
|
|
198
|
-
if (name === importedName) {
|
|
199
|
-
return name
|
|
200
|
-
}
|
|
201
|
-
return getOriginalName(path, importedName)
|
|
202
|
-
}
|
|
203
|
-
if (binding.path.type === "VariableDeclarator") {
|
|
204
|
-
if (binding.path.node.init.type === "Identifier") {
|
|
205
|
-
const previousName = binding.path.node.init.name
|
|
206
|
-
return getOriginalName(path, previousName)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return name
|
|
210
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const jsenvPluginLeadingSlash = () => {
|
|
2
|
-
return {
|
|
3
|
-
name: "jsenv:leading_slash",
|
|
4
|
-
appliesDuring: "*",
|
|
5
|
-
resolve: ({ specifier }, { rootDirectoryUrl }) => {
|
|
6
|
-
if (specifier[0] !== "/") {
|
|
7
|
-
return null
|
|
8
|
-
}
|
|
9
|
-
return new URL(specifier.slice(1), rootDirectoryUrl).href
|
|
10
|
-
},
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { jsenvPluginLeadingSlash } from "./core_plugins/leading_slash/jsenv_plugin_leading_slash.js"
|
|
2
|
-
import { jsenvPluginImportmap } from "./core_plugins/importmap/jsenv_plugin_importmap.js"
|
|
3
|
-
import { jsenvPluginUrlResolution } from "./core_plugins/url_resolution/jsenv_plugin_url_resolution.js"
|
|
4
|
-
import { jsenvPluginNodeEsmResolution } from "./core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js"
|
|
5
|
-
import { jsenvPluginUrlVersion } from "./core_plugins/url_version/jsenv_plugin_url_version.js"
|
|
6
|
-
import { jsenvPluginFileUrls } from "./core_plugins/file_urls/jsenv_plugin_file_urls.js"
|
|
7
|
-
import { jsenvPluginFileSystemMagic } from "./core_plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js"
|
|
8
|
-
import { jsenvPluginInline } from "./core_plugins/inline/jsenv_plugin_inline.js"
|
|
9
|
-
import { jsenvPluginHtmlSupervisor } from "./core_plugins/html_supervisor/jsenv_plugin_html_supervisor.js"
|
|
10
|
-
import { jsenvPluginCommonJsGlobals } from "./core_plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js"
|
|
11
|
-
import { jsenvPluginImportAssertions } from "./core_plugins/import_assertions/jsenv_plugin_import_assertions.js"
|
|
12
|
-
import { jsenvPluginImportMetaScenarios } from "./core_plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js"
|
|
13
|
-
import { jsenvPluginBabel } from "./core_plugins/babel/jsenv_plugin_babel.js"
|
|
14
|
-
|
|
15
|
-
export const getCorePlugins = ({
|
|
16
|
-
htmlSupervisor,
|
|
17
|
-
nodeEsmResolution,
|
|
18
|
-
fileSystemMagicResolution,
|
|
19
|
-
babel,
|
|
20
|
-
} = {}) => {
|
|
21
|
-
const asFewAsPossible = false // useful during dev
|
|
22
|
-
return [
|
|
23
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportAssertions()]),
|
|
24
|
-
...(asFewAsPossible ? [] : [jsenvPluginHtmlSupervisor(htmlSupervisor)]), // before inline as it turns inline <script> into <script src>
|
|
25
|
-
...(asFewAsPossible ? [] : [jsenvPluginInline()]), // before "file urls" to resolve and load inline urls
|
|
26
|
-
jsenvPluginImportmap(), // before node esm to handle bare specifiers before node esm
|
|
27
|
-
jsenvPluginFileUrls(),
|
|
28
|
-
jsenvPluginLeadingSlash(),
|
|
29
|
-
jsenvPluginNodeEsmResolution(nodeEsmResolution), // before url resolution to handle "js_import_export" resolution
|
|
30
|
-
jsenvPluginUrlResolution(),
|
|
31
|
-
...(asFewAsPossible
|
|
32
|
-
? []
|
|
33
|
-
: [jsenvPluginFileSystemMagic(fileSystemMagicResolution)]),
|
|
34
|
-
jsenvPluginUrlVersion(),
|
|
35
|
-
...(asFewAsPossible ? [] : [jsenvPluginCommonJsGlobals()]),
|
|
36
|
-
...(asFewAsPossible ? [] : [jsenvPluginImportMetaScenarios()]),
|
|
37
|
-
jsenvPluginBabel(babel),
|
|
38
|
-
]
|
|
39
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { findHighestVersion } from "@jsenv/utils/semantic_versioning/highest_version.js"
|
|
2
|
-
|
|
3
|
-
export const isFeatureSupportedOnRuntimes = (
|
|
4
|
-
runtimeSupport,
|
|
5
|
-
featureCompat = {},
|
|
6
|
-
) => {
|
|
7
|
-
const runtimeNames = Object.keys(runtimeSupport)
|
|
8
|
-
return runtimeNames.every((runtimeName) => {
|
|
9
|
-
const runtimeVersion = runtimeSupport[runtimeName]
|
|
10
|
-
const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
|
|
11
|
-
const highestVersion = findHighestVersion(
|
|
12
|
-
runtimeVersion,
|
|
13
|
-
runtimeVersionCompatible,
|
|
14
|
-
)
|
|
15
|
-
if (highestVersion !== runtimeVersion) {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
return true
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { applyPostCss } from "@jsenv/utils/css_ast/apply_post_css.js"
|
|
6
|
-
import { postCssPluginUrlVisitor } from "@jsenv/utils/css_ast/postcss_plugin_url_visitor.js"
|
|
7
|
-
import { replaceCssUrls } from "@jsenv/utils/css_ast/replace_css_urls.js"
|
|
8
|
-
|
|
9
|
-
export const parseCssUrlMentions = async ({ url, content }) => {
|
|
10
|
-
const cssUrlMentions = []
|
|
11
|
-
await applyPostCss({
|
|
12
|
-
sourcemaps: false,
|
|
13
|
-
plugins: [
|
|
14
|
-
postCssPluginUrlVisitor({
|
|
15
|
-
urlVisitor: ({ type, url, specifier, urlNode }) => {
|
|
16
|
-
cssUrlMentions.push({
|
|
17
|
-
type: `css_${type}`,
|
|
18
|
-
specifier,
|
|
19
|
-
start: urlNode.sourceIndex,
|
|
20
|
-
end: urlNode.sourceEndIndex,
|
|
21
|
-
url,
|
|
22
|
-
})
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
url,
|
|
27
|
-
content,
|
|
28
|
-
})
|
|
29
|
-
return {
|
|
30
|
-
urlMentions: cssUrlMentions,
|
|
31
|
-
replaceUrls: async (getReplacement) => {
|
|
32
|
-
// we can't use magic source because urlMention.start/end do not match the url specifier
|
|
33
|
-
// const magicSource = createMagicSource({ url, content })
|
|
34
|
-
// cssUrlMentions.forEach((urlMention) => {
|
|
35
|
-
// magicSource.replace({
|
|
36
|
-
// start: urlMention.start,
|
|
37
|
-
// end: urlMention.end,
|
|
38
|
-
// replacement: JSON.stringify(transformUrlMention(urlMention)),
|
|
39
|
-
// })
|
|
40
|
-
// })
|
|
41
|
-
// return magicSource.toContentAndSourcemap()
|
|
42
|
-
const result = await replaceCssUrls({
|
|
43
|
-
url,
|
|
44
|
-
content,
|
|
45
|
-
urlVisitor: ({ url, replace }) => {
|
|
46
|
-
const cssUrlMention = cssUrlMentions.find(
|
|
47
|
-
(urlMention) => urlMention.url === url,
|
|
48
|
-
)
|
|
49
|
-
if (cssUrlMention) {
|
|
50
|
-
const replacement = getReplacement(cssUrlMention)
|
|
51
|
-
if (replacement) {
|
|
52
|
-
replace(replacement)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
return {
|
|
58
|
-
content: result.content,
|
|
59
|
-
sourcemap: result.map,
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
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 parseHtmlUrlMentions = ({ url, content, scenario }) => {
|
|
11
|
-
const htmlAst = parseHtmlString(content, {
|
|
12
|
-
storeOriginalPositions: scenario !== "build",
|
|
13
|
-
})
|
|
14
|
-
const htmlUrlMentions = collectHtmlUrlMentions({ url, htmlAst })
|
|
15
|
-
return {
|
|
16
|
-
urlMentions: htmlUrlMentions,
|
|
17
|
-
replaceUrls: (getReplacement) => {
|
|
18
|
-
htmlUrlMentions.forEach((urlMention) => {
|
|
19
|
-
const replacement = getReplacement(urlMention)
|
|
20
|
-
if (replacement) {
|
|
21
|
-
urlMention.attribute.value = replacement
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
return {
|
|
25
|
-
content: stringifyHtmlAst(htmlAst),
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const collectHtmlUrlMentions = ({ url, htmlAst }) => {
|
|
32
|
-
const htmlUrlMentions = []
|
|
33
|
-
const addDependency = ({ type, node, attribute, specifier }) => {
|
|
34
|
-
const injected = Boolean(getHtmlNodeAttributeByName(node, "injected-by"))
|
|
35
|
-
const srcGeneratedFromInlineContent = Boolean(
|
|
36
|
-
getHtmlNodeAttributeByName(node, "src-generated-from-inline-content"),
|
|
37
|
-
)
|
|
38
|
-
let position
|
|
39
|
-
if (srcGeneratedFromInlineContent) {
|
|
40
|
-
// when generated from inline content,
|
|
41
|
-
// line, column is not "src" nor "content-src" but "original-position"
|
|
42
|
-
position = htmlNodePosition.readNodePosition(node)
|
|
43
|
-
} else {
|
|
44
|
-
position = htmlNodePosition.readAttributePosition(node, attribute.name)
|
|
45
|
-
}
|
|
46
|
-
const { line, column, originalLine, originalColumn } = position
|
|
47
|
-
htmlUrlMentions.push({
|
|
48
|
-
type,
|
|
49
|
-
htmlNode: node,
|
|
50
|
-
attribute,
|
|
51
|
-
injected,
|
|
52
|
-
srcGeneratedFromInlineContent,
|
|
53
|
-
specifier,
|
|
54
|
-
line,
|
|
55
|
-
column,
|
|
56
|
-
originalLine,
|
|
57
|
-
originalColumn,
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
const onNode = (node) => {
|
|
61
|
-
if (node.nodeName === "link") {
|
|
62
|
-
visitAttributeAsUrlSpecifier({
|
|
63
|
-
type: "link_href",
|
|
64
|
-
node,
|
|
65
|
-
attributeName: "href",
|
|
66
|
-
})
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
// if (node.nodeName === "style") {
|
|
70
|
-
// // styles.push(node)
|
|
71
|
-
// return
|
|
72
|
-
// }
|
|
73
|
-
if (node.nodeName === "script") {
|
|
74
|
-
visitAttributeAsUrlSpecifier({
|
|
75
|
-
type: "script_src",
|
|
76
|
-
node,
|
|
77
|
-
attributeName: "src",
|
|
78
|
-
})
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (node.nodeName === "a") {
|
|
82
|
-
visitAttributeAsUrlSpecifier({
|
|
83
|
-
type: "a_href",
|
|
84
|
-
node,
|
|
85
|
-
attributeName: "href",
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
if (node.nodeName === "iframe") {
|
|
89
|
-
visitAttributeAsUrlSpecifier({
|
|
90
|
-
type: "iframe_src",
|
|
91
|
-
node,
|
|
92
|
-
attributeName: "src",
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
if (node.nodeName === "img") {
|
|
96
|
-
visitAttributeAsUrlSpecifier({
|
|
97
|
-
type: "img_src",
|
|
98
|
-
node,
|
|
99
|
-
attributeName: "src",
|
|
100
|
-
})
|
|
101
|
-
visitSrcset({
|
|
102
|
-
type: "img_srcset",
|
|
103
|
-
node,
|
|
104
|
-
})
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
if (node.nodeName === "source") {
|
|
108
|
-
visitAttributeAsUrlSpecifier({
|
|
109
|
-
type: "source_src",
|
|
110
|
-
node,
|
|
111
|
-
attributeName: "src",
|
|
112
|
-
})
|
|
113
|
-
visitSrcset({
|
|
114
|
-
type: "source_srcset",
|
|
115
|
-
node,
|
|
116
|
-
})
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
// svg <image> tag
|
|
120
|
-
if (node.nodeName === "image") {
|
|
121
|
-
visitAttributeAsUrlSpecifier({
|
|
122
|
-
type: "image_href",
|
|
123
|
-
node,
|
|
124
|
-
attributeName: "href",
|
|
125
|
-
})
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
if (node.nodeName === "use") {
|
|
129
|
-
visitAttributeAsUrlSpecifier({
|
|
130
|
-
type: "use_href",
|
|
131
|
-
node,
|
|
132
|
-
attributeName: "href",
|
|
133
|
-
})
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const visitAttributeAsUrlSpecifier = ({ type, node, attributeName }) => {
|
|
138
|
-
const attribute = getHtmlNodeAttributeByName(node, attributeName)
|
|
139
|
-
const value = attribute ? attribute.value : undefined
|
|
140
|
-
if (value) {
|
|
141
|
-
const inlinedBy = getHtmlNodeAttributeByName(node, "inlined-by")
|
|
142
|
-
if (inlinedBy) {
|
|
143
|
-
// during build the importmap is inlined
|
|
144
|
-
// and shoud not be considered as a dependency anymore
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
addDependency({
|
|
148
|
-
type,
|
|
149
|
-
node,
|
|
150
|
-
attribute,
|
|
151
|
-
specifier:
|
|
152
|
-
attributeName === "content-src" ? new URL(value, url).href : value,
|
|
153
|
-
})
|
|
154
|
-
} else if (attributeName === "src") {
|
|
155
|
-
visitAttributeAsUrlSpecifier({
|
|
156
|
-
type,
|
|
157
|
-
node,
|
|
158
|
-
attributeName: "content-src",
|
|
159
|
-
})
|
|
160
|
-
} else if (attributeName === "href") {
|
|
161
|
-
visitAttributeAsUrlSpecifier({
|
|
162
|
-
type,
|
|
163
|
-
node,
|
|
164
|
-
attributeName: "content-href",
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const visitSrcset = ({ type, node }) => {
|
|
169
|
-
const srcsetAttribute = getHtmlNodeAttributeByName(node, "srcset")
|
|
170
|
-
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined
|
|
171
|
-
if (srcset) {
|
|
172
|
-
const srcCandidates = htmlAttributeSrcSet.parse(srcset)
|
|
173
|
-
srcCandidates.forEach((srcCandidate) => {
|
|
174
|
-
addDependency({
|
|
175
|
-
type,
|
|
176
|
-
node,
|
|
177
|
-
attribute: srcsetAttribute,
|
|
178
|
-
specifier: srcCandidate.specifier,
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
visitHtmlAst(htmlAst, onNode)
|
|
184
|
-
return htmlUrlMentions
|
|
185
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { collectProgramUrlMentions } from "@jsenv/utils/js_ast/program_url_mentions.js"
|
|
2
|
-
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
3
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
4
|
-
|
|
5
|
-
export const parseJsModuleUrlMentions = async ({
|
|
6
|
-
url,
|
|
7
|
-
generatedUrl,
|
|
8
|
-
content,
|
|
9
|
-
}) => {
|
|
10
|
-
const { metadata } = await applyBabelPlugins({
|
|
11
|
-
babelPlugins: [
|
|
12
|
-
babelPluginMetadataUrlMentions,
|
|
13
|
-
babelPluginMetadataUsesTopLevelAwait,
|
|
14
|
-
],
|
|
15
|
-
url,
|
|
16
|
-
generatedUrl,
|
|
17
|
-
content,
|
|
18
|
-
})
|
|
19
|
-
const { urlMentions, usesTopLevelAwait } = metadata
|
|
20
|
-
return {
|
|
21
|
-
urlMentions,
|
|
22
|
-
replaceUrls: async (getReplacement) => {
|
|
23
|
-
const magicSource = createMagicSource(content)
|
|
24
|
-
urlMentions.forEach((urlMention) => {
|
|
25
|
-
const replacement = getReplacement(urlMention)
|
|
26
|
-
if (replacement) {
|
|
27
|
-
const { start, end } = urlMention
|
|
28
|
-
magicSource.replace({
|
|
29
|
-
start,
|
|
30
|
-
end,
|
|
31
|
-
replacement,
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
return magicSource.toContentAndSourcemap()
|
|
36
|
-
},
|
|
37
|
-
data: {
|
|
38
|
-
usesTopLevelAwait,
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const babelPluginMetadataUrlMentions = () => {
|
|
44
|
-
return {
|
|
45
|
-
name: "metadata-url-mentions",
|
|
46
|
-
visitor: {
|
|
47
|
-
Program(programPath, state) {
|
|
48
|
-
const urlMentions = []
|
|
49
|
-
collectProgramUrlMentions(programPath).forEach(
|
|
50
|
-
({ type, subtype, path, specifierPath }) => {
|
|
51
|
-
const specifierNode = specifierPath.node
|
|
52
|
-
if (specifierNode.type === "StringLiteral") {
|
|
53
|
-
urlMentions.push({
|
|
54
|
-
type,
|
|
55
|
-
subtype,
|
|
56
|
-
path,
|
|
57
|
-
specifier: specifierNode.value,
|
|
58
|
-
start: specifierNode.start,
|
|
59
|
-
end: specifierNode.end,
|
|
60
|
-
line: specifierNode.loc.start.line,
|
|
61
|
-
column: specifierNode.loc.start.column,
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
)
|
|
66
|
-
state.file.metadata.urlMentions = urlMentions
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const babelPluginMetadataUsesTopLevelAwait = () => {
|
|
73
|
-
return {
|
|
74
|
-
name: "metadata-uses-top-level-await",
|
|
75
|
-
visitor: {
|
|
76
|
-
Program: (programPath, state) => {
|
|
77
|
-
let usesTopLevelAwait = false
|
|
78
|
-
programPath.traverse({
|
|
79
|
-
AwaitExpression: (awaitPath) => {
|
|
80
|
-
const closestFunction = awaitPath.getFunctionParent()
|
|
81
|
-
if (!closestFunction) {
|
|
82
|
-
usesTopLevelAwait = true
|
|
83
|
-
awaitPath.stop()
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
})
|
|
87
|
-
state.file.metadata.usesTopLevelAwait = usesTopLevelAwait
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { parseHtmlUrlMentions } from "./html_url_mentions.js"
|
|
2
|
-
import { parseCssUrlMentions } from "./css_url_mentions.js"
|
|
3
|
-
import { parseJsModuleUrlMentions } from "./js_module_url_mentions.js"
|
|
4
|
-
import { parseWorkerClassicUrlMentions } from "./worker_classic_url_mentions.js"
|
|
5
|
-
|
|
6
|
-
const parsers = {
|
|
7
|
-
html: parseHtmlUrlMentions,
|
|
8
|
-
css: parseCssUrlMentions,
|
|
9
|
-
js_classic: (urlInfo) => {
|
|
10
|
-
if (urlInfo.subtype === "worker" || urlInfo.subtype === "service_worker") {
|
|
11
|
-
return parseWorkerClassicUrlMentions(urlInfo)
|
|
12
|
-
}
|
|
13
|
-
return {}
|
|
14
|
-
},
|
|
15
|
-
js_module: parseJsModuleUrlMentions,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const parseUrlMentions = async ({ type, url, content, scenario }) => {
|
|
19
|
-
const parser = parsers[type]
|
|
20
|
-
if (!parser) {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
const {
|
|
24
|
-
urlMentions = [],
|
|
25
|
-
hotDecline = false,
|
|
26
|
-
hotAcceptSelf = false,
|
|
27
|
-
replaceUrls,
|
|
28
|
-
data,
|
|
29
|
-
} = await parser({ url, content, scenario })
|
|
30
|
-
return {
|
|
31
|
-
urlMentions,
|
|
32
|
-
hotDecline,
|
|
33
|
-
hotAcceptSelf,
|
|
34
|
-
replaceUrls,
|
|
35
|
-
data,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
2
|
-
|
|
3
|
-
export const jsenvPluginImportScriptsBundler = () => {
|
|
4
|
-
return {
|
|
5
|
-
name: "jsenv:import_scripts_bundler",
|
|
6
|
-
bundle: {
|
|
7
|
-
js_classic: async (workerUrlInfos, { urlGraph }) => {
|
|
8
|
-
const bundleResult = {}
|
|
9
|
-
workerUrlInfos.forEach((workerUrlInfo) => {
|
|
10
|
-
const magicSource = createMagicSource(workerUrlInfo.content)
|
|
11
|
-
const visitDependencies = (urlInfo) => {
|
|
12
|
-
urlInfo.dependencies.forEach((dependencyUrl) => {
|
|
13
|
-
const dependencyUrlInfo = urlGraph.getUrlInfo(dependencyUrl)
|
|
14
|
-
// what if there was some sourcemap for this urlInfo?
|
|
15
|
-
// we should compose it too
|
|
16
|
-
magicSource.append(dependencyUrlInfo.content)
|
|
17
|
-
visitDependencies(dependencyUrlInfo)
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
visitDependencies(workerUrlInfo)
|
|
21
|
-
const { content, sourcemap } = magicSource.toContentAndSourcemap()
|
|
22
|
-
bundleResult[workerUrlInfo.url] = {
|
|
23
|
-
type: "worker_classic",
|
|
24
|
-
content,
|
|
25
|
-
sourcemap,
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
return bundleResult
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const parseWorkerClassicUrlMentions = () => {
|
|
35
|
-
// use babel_plugin_inline_worker_imports.js
|
|
36
|
-
return {}
|
|
37
|
-
}
|