@jsenv/core 27.0.0-alpha.9 → 27.0.0-alpha.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +95 -0
- package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -0
- package/dist/babel_helpers/applyDecoratorDescriptor/applyDecoratorDescriptor.js +29 -0
- package/dist/babel_helpers/applyDecs/applyDecs.js +756 -0
- package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +9 -0
- package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +4 -0
- package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +5 -0
- package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +8 -0
- package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +52 -0
- package/dist/babel_helpers/asyncIterator/asyncIterator.js +78 -0
- package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +39 -0
- package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +4 -0
- package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +24 -0
- package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +7 -0
- package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +14 -0
- package/dist/babel_helpers/classCallCheck/classCallCheck.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +5 -0
- package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +6 -0
- package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +8 -0
- package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +4 -0
- package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -0
- package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +7 -0
- package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +5 -0
- package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +7 -0
- package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -0
- package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +9 -0
- package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -0
- package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +3 -0
- package/dist/babel_helpers/construct/construct.js +15 -0
- package/dist/babel_helpers/createClass/createClass.js +18 -0
- package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +63 -0
- package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +22 -0
- package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +50 -0
- package/dist/babel_helpers/createSuper/createSuper.js +22 -0
- package/dist/babel_helpers/decorate/decorate.js +622 -0
- package/dist/babel_helpers/defaults/defaults.js +14 -0
- package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +26 -0
- package/dist/babel_helpers/defineProperty/defineProperty.js +19 -0
- package/dist/babel_helpers/extends/extends.js +16 -0
- package/dist/babel_helpers/get/get.js +21 -0
- package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +2 -0
- package/dist/babel_helpers/identity/identity.js +3 -0
- package/dist/babel_helpers/inherits/inherits.js +21 -0
- package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -0
- package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +10 -0
- package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +3 -0
- package/dist/babel_helpers/instanceof/instanceof.js +7 -0
- package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +5 -0
- package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +49 -0
- package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +4 -0
- package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +21 -0
- package/dist/babel_helpers/iterableToArray/iterableToArray.js +3 -0
- package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +38 -0
- package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +13 -0
- package/dist/babel_helpers/jsx/jsx.js +49 -0
- package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +10 -0
- package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +5 -0
- package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +3 -0
- package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +3 -0
- package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +3 -0
- package/dist/babel_helpers/objectSpread/objectSpread.js +22 -0
- package/dist/babel_helpers/objectSpread2/objectSpread2.js +41 -0
- package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +20 -0
- package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +15 -0
- package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +10 -0
- package/dist/babel_helpers/readOnlyError/readOnlyError.js +4 -0
- package/dist/babel_helpers/set/set.js +51 -0
- package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +5 -0
- package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +8 -0
- package/dist/babel_helpers/slicedToArray/slicedToArray.js +5 -0
- package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +7 -0
- package/dist/babel_helpers/superPropBase/superPropBase.js +10 -0
- package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +11 -0
- package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +8 -0
- package/dist/babel_helpers/tdz/tdz.js +4 -0
- package/dist/babel_helpers/temporalRef/temporalRef.js +5 -0
- package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +3 -0
- package/dist/babel_helpers/toArray/toArray.js +5 -0
- package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +5 -0
- package/dist/babel_helpers/toPrimitive/toPrimitive.js +14 -0
- package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -0
- package/dist/babel_helpers/typeof/typeof.js +7 -0
- package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -0
- package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +7 -0
- package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +35 -0
- package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +67 -0
- package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +4 -0
- package/dist/html/explorer.html +557 -0
- package/dist/js/controllable_file.mjs +227 -0
- package/dist/js/event_source_client.js +528 -0
- package/dist/js/global_this.js +32 -0
- package/dist/js/html_supervisor_installer.js +522 -0
- package/dist/js/html_supervisor_setup.js +82 -0
- package/dist/js/import_meta_hot.js +84 -0
- package/dist/js/inline_content.js +8 -0
- package/dist/js/new_stylesheet.js +409 -0
- package/dist/js/regenerator_runtime.js +721 -0
- package/dist/js/s.js +429 -0
- package/dist/js/uneval.js +804 -0
- package/dist/main.js +25163 -0
- package/dist/other/jsenv.png +0 -0
- package/dist/s.js +626 -0
- package/dist/s.js.map +205 -0
- package/package.json +61 -57
- package/readme.md +6 -14
- package/src/build/build.js +1040 -551
- package/src/build/build_urls_generator.js +65 -25
- package/src/build/graph_utils.js +31 -0
- package/src/build/inject_global_version_mappings.js +93 -0
- package/src/build/inject_service_worker_urls.js +79 -0
- package/src/build/resync_ressource_hints.js +114 -0
- package/src/build/start_build_server.js +217 -0
- package/src/build/version_generator.js +60 -0
- package/src/dev/plugins/explorer/client/explorer.html +1 -1
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +9 -14
- package/src/dev/plugins/toolbar/client/util/fetching.js +1 -1
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +6 -4
- package/src/dev/start_dev_server.js +173 -38
- package/src/execute/execute.js +35 -8
- package/src/execute/run.js +21 -57
- package/src/execute/runtimes/browsers/from_playwright.js +224 -153
- package/src/execute/runtimes/node/child_exec_options.js +1 -1
- package/src/execute/runtimes/node/controllable_file.mjs +26 -10
- package/src/execute/runtimes/node/kill_process_tree.js +2 -4
- package/src/execute/runtimes/node/node_execution_performance.js +67 -0
- package/src/execute/runtimes/node/node_process.js +288 -39
- package/src/helpers/command/command.js +73 -0
- package/src/{dev/plugins/autoreload/client/event_source_connection.js → helpers/event_source/event_source.js} +2 -0
- package/src/helpers/event_source/sse_service.js +53 -0
- package/src/helpers/worker_reload.js +57 -0
- package/src/main.js +27 -0
- package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +30 -7
- package/src/omega/{runtime_support/runtime_support.js → compat/runtime_compat.js} +16 -17
- package/src/omega/errors.js +63 -67
- package/src/omega/fetched_content_compliance.js +24 -0
- package/src/omega/file_url_converter.js +9 -51
- package/src/omega/kitchen.js +607 -466
- package/src/omega/omega_server.js +2 -3
- package/src/omega/server/file_service.js +88 -41
- package/src/omega/server/user_agent.js +5 -5
- package/src/omega/url_graph/{url_graph_sort.js → sort_by_dependencies.js} +3 -5
- package/src/omega/url_graph/url_graph_load.js +31 -23
- package/src/omega/url_graph/url_graph_report.js +94 -51
- package/src/omega/url_graph/url_info_transformations.js +54 -24
- package/src/omega/url_graph.js +88 -19
- package/src/omega/url_specifier_encoding.js +59 -0
- 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 +19 -12
- package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +6 -3
- 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/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
- 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 +140 -0
- package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
- package/src/plugins/bundling/js_module/bundle_js_module.js +362 -0
- package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
- package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +56 -43
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +190 -0
- 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/plugins/html_supervisor/client/html_supervisor_installer.js +254 -0
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +82 -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/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +239 -0
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +16 -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 +15 -18
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +100 -0
- package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -10
- 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 +56 -54
- package/src/plugins/inject_globals/inject_globals.js +57 -0
- package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +24 -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 +22 -21
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +159 -0
- package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
- package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +8 -11
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +294 -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 +13 -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/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +162 -0
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +12 -0
- package/src/{omega → plugins}/plugin_controller.js +57 -12
- package/src/plugins/plugins.js +91 -0
- package/src/plugins/transpilation/as_js_classic/client/s.js +429 -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 +209 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +282 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_workers.js +55 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +2 -3
- package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +3 -4
- package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +14 -17
- 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 +40 -33
- package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +32 -9
- 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 +2 -3
- package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
- package/src/plugins/transpilation/babel/require_babel_plugin.js +8 -0
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +184 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +80 -0
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +46 -0
- package/src/plugins/url_analysis/css/css_urls.js +48 -0
- package/src/plugins/url_analysis/html/html_urls.js +257 -0
- package/src/plugins/url_analysis/js/js_urls.js +69 -0
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +110 -0
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +20 -0
- package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +9 -5
- package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
- package/src/require_from_jsenv.js +3 -0
- package/src/test/coverage/babel_plugin_instrument.js +82 -0
- package/src/test/coverage/coverage_reporter_html_directory.js +36 -0
- package/src/test/coverage/coverage_reporter_json_file.js +22 -0
- package/src/test/coverage/coverage_reporter_text_log.js +19 -0
- package/src/test/coverage/empty_coverage_factory.js +52 -0
- package/src/test/coverage/file_by_file_coverage.js +25 -0
- package/src/test/coverage/istanbul_coverage_composition.js +28 -0
- package/src/test/coverage/istanbul_coverage_map_from_coverage.js +16 -0
- package/src/test/coverage/list_files_not_covered.js +15 -0
- package/src/test/coverage/missing_coverage.js +41 -0
- package/src/test/coverage/report_to_coverage.js +196 -0
- package/src/test/coverage/v8_and_istanbul.js +37 -0
- package/src/test/coverage/v8_coverage_composition.js +24 -0
- package/src/test/coverage/v8_coverage_from_directory.js +87 -0
- package/src/test/coverage/v8_coverage_to_istanbul.js +99 -0
- package/src/test/execute_plan.js +87 -46
- package/src/test/execute_test_plan.js +40 -28
- package/src/test/execution_steps.js +2 -5
- package/src/test/logs_file_execution.js +56 -49
- package/main.js +0 -19
- package/src/build/inject_version_mappings.js +0 -62
- package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -227
- package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
- package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
- 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/new_stylesheet/client/.eslintrc.cjs +0 -24
- package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
- package/src/omega/core_plugins/filesystem_magic/jsenv_plugin_filesystem_magic.js +0 -58
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
- package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
- package/src/omega/core_plugins/html_supervisor/jsenv_plugin_html_supervisor.js +0 -233
- package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
- 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_js_and_css_inside_html.js +0 -142
- package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -207
- package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
- package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
- package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
- package/src/omega/core_plugins.js +0 -39
- package/src/omega/runtime_support/default_runtime_support.js +0 -13
- 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,149 +0,0 @@
|
|
|
1
|
-
import { createSSERoom } from "@jsenv/server"
|
|
2
|
-
import { registerDirectoryLifecycle } from "@jsenv/filesystem"
|
|
3
|
-
import {
|
|
4
|
-
createCallbackList,
|
|
5
|
-
createCallbackListNotifiedOnce,
|
|
6
|
-
} from "@jsenv/abort"
|
|
7
|
-
|
|
8
|
-
export const createSSEService = ({
|
|
9
|
-
rootDirectoryUrl,
|
|
10
|
-
autoreloadPatterns,
|
|
11
|
-
onFileChange,
|
|
12
|
-
hotUpdateCallbackList,
|
|
13
|
-
}) => {
|
|
14
|
-
const destroyCallbackList = createCallbackListNotifiedOnce()
|
|
15
|
-
const projectFileModified = createCallbackList()
|
|
16
|
-
const projectFileRemoved = createCallbackList()
|
|
17
|
-
const projectFileAdded = createCallbackList()
|
|
18
|
-
const watchProjectFiles = (callback) => {
|
|
19
|
-
const removeModifiedCallback = projectFileModified.add((relativeUrl) => {
|
|
20
|
-
callback({
|
|
21
|
-
event: "modified",
|
|
22
|
-
relativeUrl,
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
const removeRemovedCallback = projectFileRemoved.add((relativeUrl) => {
|
|
26
|
-
callback({
|
|
27
|
-
event: "removed",
|
|
28
|
-
relativeUrl,
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
const removeAddedCallback = projectFileRemoved.add((relativeUrl) => {
|
|
32
|
-
callback({
|
|
33
|
-
event: "added",
|
|
34
|
-
relativeUrl,
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
return () => {
|
|
38
|
-
removeModifiedCallback()
|
|
39
|
-
removeRemovedCallback()
|
|
40
|
-
removeAddedCallback()
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// wait 100ms to actually start watching
|
|
44
|
-
// otherwise server starting is delayed by the filesystem scan done in
|
|
45
|
-
// registerDirectoryLifecycle
|
|
46
|
-
const timeout = setTimeout(() => {
|
|
47
|
-
const unregisterDirectoryLifecyle = registerDirectoryLifecycle(
|
|
48
|
-
rootDirectoryUrl,
|
|
49
|
-
{
|
|
50
|
-
watchDescription: {
|
|
51
|
-
...autoreloadPatterns,
|
|
52
|
-
".jsenv/": false,
|
|
53
|
-
},
|
|
54
|
-
updated: ({ relativeUrl }) => {
|
|
55
|
-
projectFileModified.notify(relativeUrl)
|
|
56
|
-
},
|
|
57
|
-
removed: ({ relativeUrl }) => {
|
|
58
|
-
projectFileRemoved.notify(relativeUrl)
|
|
59
|
-
},
|
|
60
|
-
added: ({ relativeUrl }) => {
|
|
61
|
-
projectFileAdded.notify(relativeUrl)
|
|
62
|
-
},
|
|
63
|
-
keepProcessAlive: false,
|
|
64
|
-
recursive: true,
|
|
65
|
-
},
|
|
66
|
-
)
|
|
67
|
-
destroyCallbackList.add(unregisterDirectoryLifecyle)
|
|
68
|
-
}, 100)
|
|
69
|
-
destroyCallbackList.add(() => {
|
|
70
|
-
clearTimeout(timeout)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const cache = []
|
|
74
|
-
const sseRoomLimit = 100
|
|
75
|
-
const getOrCreateSSERoom = (request) => {
|
|
76
|
-
const htmlFileRelativeUrl = request.ressource.slice(1)
|
|
77
|
-
const cacheEntry = cache.find(
|
|
78
|
-
(cacheEntryCandidate) =>
|
|
79
|
-
cacheEntryCandidate.htmlFileRelativeUrl === htmlFileRelativeUrl,
|
|
80
|
-
)
|
|
81
|
-
if (cacheEntry) {
|
|
82
|
-
return cacheEntry.sseRoom
|
|
83
|
-
}
|
|
84
|
-
const sseRoom = createSSERoom({
|
|
85
|
-
retryDuration: 2000,
|
|
86
|
-
historyLength: 100,
|
|
87
|
-
welcomeEventEnabled: true,
|
|
88
|
-
effect: () => {
|
|
89
|
-
const removeHotUpdateCallback = hotUpdateCallbackList.add(
|
|
90
|
-
(hotUpdate) => {
|
|
91
|
-
if (hotUpdate.declined) {
|
|
92
|
-
sseRoom.sendEvent({
|
|
93
|
-
type: "reload",
|
|
94
|
-
data: JSON.stringify({
|
|
95
|
-
cause: hotUpdate.cause,
|
|
96
|
-
type: "full",
|
|
97
|
-
typeReason: hotUpdate.reason,
|
|
98
|
-
declinedBy: hotUpdate.declinedBy,
|
|
99
|
-
}),
|
|
100
|
-
})
|
|
101
|
-
} else {
|
|
102
|
-
sseRoom.sendEvent({
|
|
103
|
-
type: "reload",
|
|
104
|
-
data: JSON.stringify({
|
|
105
|
-
cause: hotUpdate.cause,
|
|
106
|
-
type: "hot",
|
|
107
|
-
typeReason: hotUpdate.reason,
|
|
108
|
-
hotInstructions: hotUpdate.instructions,
|
|
109
|
-
}),
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
)
|
|
114
|
-
const stopWatching = watchProjectFiles(({ relativeUrl, event }) => {
|
|
115
|
-
onFileChange({ relativeUrl, event })
|
|
116
|
-
})
|
|
117
|
-
return () => {
|
|
118
|
-
removeHotUpdateCallback()
|
|
119
|
-
stopWatching()
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
const removeSSECleanupCallback = destroyCallbackList.add(() => {
|
|
125
|
-
removeSSECleanupCallback()
|
|
126
|
-
sseRoom.close()
|
|
127
|
-
})
|
|
128
|
-
cache.push({
|
|
129
|
-
htmlFileRelativeUrl,
|
|
130
|
-
sseRoom,
|
|
131
|
-
cleanup: () => {
|
|
132
|
-
removeSSECleanupCallback()
|
|
133
|
-
sseRoom.close()
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
if (cache.length >= sseRoomLimit) {
|
|
137
|
-
const firstCacheEntry = cache.shift()
|
|
138
|
-
firstCacheEntry.cleanup()
|
|
139
|
-
}
|
|
140
|
-
return sseRoom
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
getOrCreateSSERoom,
|
|
145
|
-
destroy: () => {
|
|
146
|
-
destroyCallbackList.notify()
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { fork } from "node:child_process"
|
|
2
|
-
import { urlToFileSystemPath } from "@jsenv/filesystem"
|
|
3
|
-
import { createDetailedMessage } from "@jsenv/logger"
|
|
4
|
-
import {
|
|
5
|
-
Abort,
|
|
6
|
-
raceCallbacks,
|
|
7
|
-
createCallbackListNotifiedOnce,
|
|
8
|
-
} from "@jsenv/abort"
|
|
9
|
-
import { uneval } from "@jsenv/uneval"
|
|
10
|
-
|
|
11
|
-
import { memoize } from "@jsenv/utils/memoize/memoize.js"
|
|
12
|
-
|
|
13
|
-
import { createChildExecOptions } from "./child_exec_options.js"
|
|
14
|
-
import { ExecOptions } from "./exec_options.js"
|
|
15
|
-
import { killProcessTree } from "./kill_process_tree.js"
|
|
16
|
-
|
|
17
|
-
const NODE_CONTROLLABLE_FILE_URL = new URL(
|
|
18
|
-
"./controllable_file.mjs",
|
|
19
|
-
import.meta.url,
|
|
20
|
-
).href
|
|
21
|
-
|
|
22
|
-
export const createControlledProcess = async ({
|
|
23
|
-
signal = new AbortController().signal,
|
|
24
|
-
logger,
|
|
25
|
-
logProcessCommand = false,
|
|
26
|
-
|
|
27
|
-
onStop,
|
|
28
|
-
onError,
|
|
29
|
-
onConsole,
|
|
30
|
-
|
|
31
|
-
debugPort,
|
|
32
|
-
debugMode,
|
|
33
|
-
debugModeInheritBreak,
|
|
34
|
-
commandLineOptions = [],
|
|
35
|
-
env,
|
|
36
|
-
inheritProcessEnv = true,
|
|
37
|
-
|
|
38
|
-
stdin = "pipe",
|
|
39
|
-
stdout = "pipe",
|
|
40
|
-
stderr = "pipe",
|
|
41
|
-
}) => {
|
|
42
|
-
if (env !== undefined && typeof env !== "object") {
|
|
43
|
-
throw new TypeError(`env must be an object, got ${env}`)
|
|
44
|
-
}
|
|
45
|
-
const cleanupCallbackList = createCallbackListNotifiedOnce()
|
|
46
|
-
const cleanup = async (reason) => {
|
|
47
|
-
await cleanupCallbackList.notify({ reason })
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const childExecOptions = await createChildExecOptions({
|
|
51
|
-
signal,
|
|
52
|
-
debugPort,
|
|
53
|
-
debugMode,
|
|
54
|
-
debugModeInheritBreak,
|
|
55
|
-
})
|
|
56
|
-
const execArgv = ExecOptions.toExecArgv({
|
|
57
|
-
...childExecOptions,
|
|
58
|
-
...ExecOptions.fromExecArgv(commandLineOptions),
|
|
59
|
-
})
|
|
60
|
-
const envForChildProcess = {
|
|
61
|
-
...(inheritProcessEnv ? process.env : {}),
|
|
62
|
-
...env,
|
|
63
|
-
}
|
|
64
|
-
logger[logProcessCommand ? "info" : "debug"](
|
|
65
|
-
`${process.argv[0]} ${execArgv.join(" ")} ${urlToFileSystemPath(
|
|
66
|
-
NODE_CONTROLLABLE_FILE_URL,
|
|
67
|
-
)}`,
|
|
68
|
-
)
|
|
69
|
-
const childProcess = fork(urlToFileSystemPath(NODE_CONTROLLABLE_FILE_URL), {
|
|
70
|
-
execArgv,
|
|
71
|
-
// silent: true
|
|
72
|
-
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
73
|
-
env: envForChildProcess,
|
|
74
|
-
})
|
|
75
|
-
logger.debug(
|
|
76
|
-
createDetailedMessage(`child process forked (pid ${childProcess.pid})`, {
|
|
77
|
-
"execArgv": execArgv.join(`\n`),
|
|
78
|
-
"custom env": JSON.stringify(env, null, " "),
|
|
79
|
-
}),
|
|
80
|
-
)
|
|
81
|
-
// if we pass stream, pipe them https://github.com/sindresorhus/execa/issues/81
|
|
82
|
-
if (typeof stdin === "object") {
|
|
83
|
-
stdin.pipe(childProcess.stdin)
|
|
84
|
-
}
|
|
85
|
-
if (typeof stdout === "object") {
|
|
86
|
-
childProcess.stdout.pipe(stdout)
|
|
87
|
-
}
|
|
88
|
-
if (typeof stderr === "object") {
|
|
89
|
-
childProcess.stderr.pipe(stderr)
|
|
90
|
-
}
|
|
91
|
-
const childProcessReadyPromise = new Promise((resolve) => {
|
|
92
|
-
onceProcessMessage(childProcess, "ready", resolve)
|
|
93
|
-
})
|
|
94
|
-
const removeOutputListener = installProcessOutputListener(
|
|
95
|
-
childProcess,
|
|
96
|
-
({ type, text }) => {
|
|
97
|
-
onConsole({ type, text })
|
|
98
|
-
},
|
|
99
|
-
)
|
|
100
|
-
const stop = memoize(async ({ gracefulStopAllocatedMs } = {}) => {
|
|
101
|
-
// all libraries are facing problem on windows when trying
|
|
102
|
-
// to kill a process spawning other processes.
|
|
103
|
-
// "killProcessTree" is theorically correct but sometimes keep process handing forever.
|
|
104
|
-
// Inside GitHub workflow the whole Virtual machine gets unresponsive and ends up being killed
|
|
105
|
-
// There is no satisfying solution to this problem so we stick to the basic
|
|
106
|
-
// childProcess.kill()
|
|
107
|
-
if (process.platform === "win32") {
|
|
108
|
-
childProcess.kill()
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
if (gracefulStopAllocatedMs) {
|
|
112
|
-
try {
|
|
113
|
-
await killProcessTree(childProcess.pid, {
|
|
114
|
-
signal: GRACEFUL_STOP_SIGNAL,
|
|
115
|
-
timeout: gracefulStopAllocatedMs,
|
|
116
|
-
})
|
|
117
|
-
return
|
|
118
|
-
} catch (e) {
|
|
119
|
-
if (e.code === "TIMEOUT") {
|
|
120
|
-
logger.debug(
|
|
121
|
-
`kill with SIGTERM because gracefulStop still pending after ${gracefulStopAllocatedMs}ms`,
|
|
122
|
-
)
|
|
123
|
-
await killProcessTree(childProcess.pid, {
|
|
124
|
-
signal: GRACEFUL_STOP_FAILED_SIGNAL,
|
|
125
|
-
})
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
throw e
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
await killProcessTree(childProcess.pid, { signal: STOP_SIGNAL })
|
|
132
|
-
return
|
|
133
|
-
})
|
|
134
|
-
raceCallbacks(
|
|
135
|
-
{
|
|
136
|
-
// https://nodejs.org/api/child_process.html#child_process_event_disconnect
|
|
137
|
-
// disconnect: (cb) => {
|
|
138
|
-
// return onceProcessEvent(childProcess, "disconnect", cb)
|
|
139
|
-
// },
|
|
140
|
-
// https://nodejs.org/api/child_process.html#child_process_event_error
|
|
141
|
-
error: (cb) => {
|
|
142
|
-
return onceProcessEvent(childProcess, "error", cb)
|
|
143
|
-
},
|
|
144
|
-
exit: (cb) => {
|
|
145
|
-
return onceProcessEvent(childProcess, "exit", (code, signal) => {
|
|
146
|
-
cb({ code, signal })
|
|
147
|
-
})
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
(winner) => {
|
|
151
|
-
const raceEffects = {
|
|
152
|
-
// disconnect: () => {
|
|
153
|
-
// stoppedCallbackList.notify()
|
|
154
|
-
// },
|
|
155
|
-
error: (error) => {
|
|
156
|
-
removeOutputListener()
|
|
157
|
-
if (
|
|
158
|
-
!childProcess.connected &&
|
|
159
|
-
error.code === "ERR_IPC_DISCONNECTED"
|
|
160
|
-
) {
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
onError(error)
|
|
164
|
-
},
|
|
165
|
-
exit: async ({ code, signal }) => {
|
|
166
|
-
// process.exit(1) in child process or process.exitCode = 1 + process.exit()
|
|
167
|
-
// means there was an error even if we don't know exactly what.
|
|
168
|
-
if (
|
|
169
|
-
code !== null &&
|
|
170
|
-
code !== 0 &&
|
|
171
|
-
code !== SIGINT_EXIT_CODE &&
|
|
172
|
-
code !== SIGTERM_EXIT_CODE &&
|
|
173
|
-
code !== SIGABORT_EXIT_CODE
|
|
174
|
-
) {
|
|
175
|
-
onError(createExitWithFailureCodeError(code))
|
|
176
|
-
}
|
|
177
|
-
await cleanup("process exit")
|
|
178
|
-
onStop({ code, signal })
|
|
179
|
-
},
|
|
180
|
-
}
|
|
181
|
-
raceEffects[winner.name](winner.data)
|
|
182
|
-
},
|
|
183
|
-
)
|
|
184
|
-
const requestActionOnChildProcess = async ({
|
|
185
|
-
signal,
|
|
186
|
-
actionType,
|
|
187
|
-
actionParams,
|
|
188
|
-
}) => {
|
|
189
|
-
const actionOperation = Abort.startOperation()
|
|
190
|
-
actionOperation.addAbortSignal(signal)
|
|
191
|
-
try {
|
|
192
|
-
const result = await new Promise(async (resolve, reject) => {
|
|
193
|
-
actionOperation.throwIfAborted()
|
|
194
|
-
await childProcessReadyPromise
|
|
195
|
-
onceProcessMessage(
|
|
196
|
-
childProcess,
|
|
197
|
-
"action-result",
|
|
198
|
-
({ status, value }) => {
|
|
199
|
-
if (status === "action-completed") {
|
|
200
|
-
resolve(value)
|
|
201
|
-
} else {
|
|
202
|
-
reject(value)
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
)
|
|
206
|
-
logger.debug(
|
|
207
|
-
createDetailedMessage(`ask child process to perform an action`, {
|
|
208
|
-
actionType,
|
|
209
|
-
actionParams: JSON.stringify(actionParams, null, " "),
|
|
210
|
-
}),
|
|
211
|
-
)
|
|
212
|
-
try {
|
|
213
|
-
actionOperation.throwIfAborted()
|
|
214
|
-
await sendToProcess(childProcess, "action", {
|
|
215
|
-
actionType,
|
|
216
|
-
actionParams,
|
|
217
|
-
})
|
|
218
|
-
} catch (e) {
|
|
219
|
-
if (Abort.isAbortError(e) && actionOperation.signal.aborted) {
|
|
220
|
-
throw e
|
|
221
|
-
}
|
|
222
|
-
logger.error(
|
|
223
|
-
createDetailedMessage(`error while sending message to child`, {
|
|
224
|
-
["error stack"]: e.stack,
|
|
225
|
-
}),
|
|
226
|
-
)
|
|
227
|
-
throw e
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
return result
|
|
231
|
-
} finally {
|
|
232
|
-
await actionOperation.end()
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
execArgv,
|
|
237
|
-
stop,
|
|
238
|
-
requestActionOnChildProcess,
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// https://nodejs.org/api/process.html#process_signal_events
|
|
243
|
-
const SIGINT_SIGNAL_NUMBER = 2
|
|
244
|
-
const SIGABORT_SIGNAL_NUMBER = 6
|
|
245
|
-
const SIGTERM_SIGNAL_NUMBER = 15
|
|
246
|
-
const SIGINT_EXIT_CODE = 128 + SIGINT_SIGNAL_NUMBER
|
|
247
|
-
const SIGABORT_EXIT_CODE = 128 + SIGABORT_SIGNAL_NUMBER
|
|
248
|
-
const SIGTERM_EXIT_CODE = 128 + SIGTERM_SIGNAL_NUMBER
|
|
249
|
-
// http://man7.org/linux/man-pages/man7/signal.7.html
|
|
250
|
-
// https:// github.com/nodejs/node/blob/1d9511127c419ec116b3ddf5fc7a59e8f0f1c1e4/lib/internal/child_process.js#L472
|
|
251
|
-
const GRACEFUL_STOP_SIGNAL = "SIGTERM"
|
|
252
|
-
const STOP_SIGNAL = "SIGKILL"
|
|
253
|
-
// it would be more correct if GRACEFUL_STOP_FAILED_SIGNAL was SIGHUP instead of SIGKILL.
|
|
254
|
-
// but I'm not sure and it changes nothing so just use SIGKILL
|
|
255
|
-
const GRACEFUL_STOP_FAILED_SIGNAL = "SIGKILL"
|
|
256
|
-
|
|
257
|
-
const sendToProcess = async (childProcess, type, data) => {
|
|
258
|
-
const source = uneval(data, { functionAllowed: true })
|
|
259
|
-
return new Promise((resolve, reject) => {
|
|
260
|
-
childProcess.send({ type, data: source }, (error) => {
|
|
261
|
-
if (error) {
|
|
262
|
-
reject(error)
|
|
263
|
-
} else {
|
|
264
|
-
resolve()
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
})
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const installProcessOutputListener = (childProcess, callback) => {
|
|
271
|
-
// beware that we may receive ansi output here, should not be a problem but keep that in mind
|
|
272
|
-
const stdoutDataCallback = (chunk) => {
|
|
273
|
-
callback({ type: "log", text: String(chunk) })
|
|
274
|
-
}
|
|
275
|
-
childProcess.stdout.on("data", stdoutDataCallback)
|
|
276
|
-
const stdErrorDataCallback = (chunk) => {
|
|
277
|
-
callback({ type: "error", text: String(chunk) })
|
|
278
|
-
}
|
|
279
|
-
childProcess.stderr.on("data", stdErrorDataCallback)
|
|
280
|
-
return () => {
|
|
281
|
-
childProcess.stdout.removeListener("data", stdoutDataCallback)
|
|
282
|
-
childProcess.stderr.removeListener("data", stdoutDataCallback)
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const createExitWithFailureCodeError = (code) => {
|
|
287
|
-
if (code === 12) {
|
|
288
|
-
return new Error(
|
|
289
|
-
`child exited with 12: forked child wanted to use a non available port for debug`,
|
|
290
|
-
)
|
|
291
|
-
}
|
|
292
|
-
const error = new Error(`child exited with ${code}`)
|
|
293
|
-
error.exitCode = code
|
|
294
|
-
return error
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const onceProcessMessage = (childProcess, type, callback) => {
|
|
298
|
-
const onmessage = (message) => {
|
|
299
|
-
if (message.type === type) {
|
|
300
|
-
childProcess.removeListener("message", onmessage)
|
|
301
|
-
// eslint-disable-next-line no-eval
|
|
302
|
-
callback(message.data ? eval(`(${message.data})`) : "")
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
childProcess.on("message", onmessage)
|
|
306
|
-
return () => {
|
|
307
|
-
childProcess.removeListener("message", onmessage)
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const onceProcessEvent = (childProcess, type, callback) => {
|
|
312
|
-
childProcess.once(type, callback)
|
|
313
|
-
return () => {
|
|
314
|
-
childProcess.removeListener(type, callback)
|
|
315
|
-
}
|
|
316
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const eslintConfig = require("../../../../../../.eslintrc.cjs")
|
|
2
|
-
|
|
3
|
-
// babel helpers are copy pasted from the babel repository
|
|
4
|
-
Object.assign(eslintConfig.rules, {
|
|
5
|
-
"eqeqeq": ["off"],
|
|
6
|
-
"no-eq-null": ["off"],
|
|
7
|
-
"no-undef-init": ["off"],
|
|
8
|
-
"dot-notation": ["off"],
|
|
9
|
-
"consistent-return": ["off"],
|
|
10
|
-
"one-var": ["off"],
|
|
11
|
-
"object-shorthand": ["off"],
|
|
12
|
-
"no-return-assign": ["off"],
|
|
13
|
-
"prefer-template": ["off"],
|
|
14
|
-
"prefer-rest-params": ["off"],
|
|
15
|
-
"no-void": ["off"],
|
|
16
|
-
"no-implicit-coercion": ["off"],
|
|
17
|
-
"prefer-spread": ["off"],
|
|
18
|
-
"no-loop-func": ["off"],
|
|
19
|
-
"no-negated-condition": ["off"],
|
|
20
|
-
"no-func-assign": ["off"],
|
|
21
|
-
"no-else-return": ["off"],
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
module.exports = eslintConfig
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs"
|
|
2
|
-
import { urlToContentType } from "@jsenv/server"
|
|
3
|
-
import {
|
|
4
|
-
urlIsInsideOf,
|
|
5
|
-
urlToRelativeUrl,
|
|
6
|
-
fileSystemRootUrl,
|
|
7
|
-
} from "@jsenv/filesystem"
|
|
8
|
-
import { ContentType } from "@jsenv/utils/src/content_type.js"
|
|
9
|
-
|
|
10
|
-
export const jsenvPluginFileUrls = () => {
|
|
11
|
-
return [jsenvPluginResolveAbsoluteFileUrls(), jsenvPluginLoadFileUrls()]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const jsenvPluginResolveAbsoluteFileUrls = () => {
|
|
15
|
-
return {
|
|
16
|
-
name: "jsenv:resolve_absolute_file_urls",
|
|
17
|
-
appliesDuring: {
|
|
18
|
-
// during dev and test it's a browser running the code
|
|
19
|
-
// so absolute file urls needs to be relativized
|
|
20
|
-
dev: true,
|
|
21
|
-
test: true,
|
|
22
|
-
// during build it's fine to use file:// urls
|
|
23
|
-
build: false,
|
|
24
|
-
},
|
|
25
|
-
resolve: ({ specifier }, { rootDirectoryUrl }) => {
|
|
26
|
-
if (!specifier.startsWith("/@fs/")) {
|
|
27
|
-
return null
|
|
28
|
-
}
|
|
29
|
-
const url = new URL(specifier.slice("/@fs".length), rootDirectoryUrl).href
|
|
30
|
-
return url
|
|
31
|
-
},
|
|
32
|
-
formatReferencedUrl: ({ url }, { rootDirectoryUrl }) => {
|
|
33
|
-
if (!url.startsWith("file:")) {
|
|
34
|
-
return null
|
|
35
|
-
}
|
|
36
|
-
const specifier = urlIsInsideOf(url, rootDirectoryUrl)
|
|
37
|
-
? `/${urlToRelativeUrl(url, rootDirectoryUrl)}`
|
|
38
|
-
: `/@fs/${url.slice(fileSystemRootUrl.length)}`
|
|
39
|
-
return specifier
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const jsenvPluginLoadFileUrls = () => {
|
|
45
|
-
return {
|
|
46
|
-
name: "jsenv:load_file_urls",
|
|
47
|
-
appliesDuring: "*",
|
|
48
|
-
load: ({ url }) => {
|
|
49
|
-
if (!url.startsWith("file:")) {
|
|
50
|
-
return null
|
|
51
|
-
}
|
|
52
|
-
const urlObject = new URL(url)
|
|
53
|
-
const fileBuffer = readFileSync(urlObject)
|
|
54
|
-
const contentType = urlToContentType(url)
|
|
55
|
-
if (ContentType.isTextual(contentType)) {
|
|
56
|
-
return {
|
|
57
|
-
contentType,
|
|
58
|
-
content: String(fileBuffer),
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
contentType,
|
|
63
|
-
content: fileBuffer,
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/resolve.ts
|
|
2
|
-
|
|
3
|
-
import { realpathSync } from "node:fs"
|
|
4
|
-
import { pathToFileURL } from "node:url"
|
|
5
|
-
import { urlToExtension } from "@jsenv/filesystem"
|
|
6
|
-
import { applyFileSystemMagicResolution } from "@jsenv/node-esm-resolution"
|
|
7
|
-
|
|
8
|
-
export const jsenvPluginFileSystemMagic = ({
|
|
9
|
-
magicExtensions = ["inherit"],
|
|
10
|
-
magicDirectoryIndex = true,
|
|
11
|
-
preservesSymlink = true,
|
|
12
|
-
} = {}) => {
|
|
13
|
-
return {
|
|
14
|
-
name: "jsenv:filesystem_magic",
|
|
15
|
-
appliesDuring: "*",
|
|
16
|
-
normalize: ({ parentUrl, url }) => {
|
|
17
|
-
// http, https, data, about, etc
|
|
18
|
-
if (!url.startsWith("file:")) {
|
|
19
|
-
return null
|
|
20
|
-
}
|
|
21
|
-
const urlObject = new URL(url)
|
|
22
|
-
const { search, hash } = urlObject
|
|
23
|
-
urlObject.search = ""
|
|
24
|
-
urlObject.hash = ""
|
|
25
|
-
const filesystemResolution = applyFileSystemMagicResolution(
|
|
26
|
-
urlObject.href,
|
|
27
|
-
{
|
|
28
|
-
magicDirectoryIndex,
|
|
29
|
-
magicExtensions: getExtensionsToTry(magicExtensions, parentUrl),
|
|
30
|
-
},
|
|
31
|
-
)
|
|
32
|
-
if (!filesystemResolution.found) {
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
35
|
-
const fileUrlRaw = filesystemResolution.url
|
|
36
|
-
const fileUrl = `${fileUrlRaw}${search}${hash}`
|
|
37
|
-
if (preservesSymlink) {
|
|
38
|
-
return fileUrl
|
|
39
|
-
}
|
|
40
|
-
const realPath = realpathSync(urlObject)
|
|
41
|
-
const realFileUrl = `${pathToFileURL(realPath)}${search}${hash}`
|
|
42
|
-
return realFileUrl
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const getExtensionsToTry = (magicExtensions, importer) => {
|
|
48
|
-
const extensionsSet = new Set()
|
|
49
|
-
magicExtensions.forEach((magicExtension) => {
|
|
50
|
-
if (magicExtension === "inherit") {
|
|
51
|
-
const importerExtension = urlToExtension(importer)
|
|
52
|
-
extensionsSet.add(importerExtension)
|
|
53
|
-
} else {
|
|
54
|
-
extensionsSet.add(magicExtension)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
return Array.from(extensionsSet.values())
|
|
58
|
-
}
|