@jsenv/core 34.3.0 → 35.0.0
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/README.md +1 -1
- package/dist/{jsenv.js → jsenv_core.js} +1054 -3850
- package/package.json +6 -21
- package/src/build/build.js +2 -2
- package/src/dev/file_service.js +8 -8
- package/src/dev/start_dev_server.js +3 -3
- package/src/dev/user_agent.js +1 -1
- package/src/main.js +0 -23
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +1 -1
- package/src/plugins/transpilation/babel/require_babel_plugin.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +1 -1
- package/dist/controllable_child_process.mjs +0 -129
- package/dist/controllable_worker_thread.mjs +0 -91
- package/dist/importmap_node_loader.mjs +0 -49
- package/dist/js/execute_using_dynamic_import.js +0 -850
- package/dist/js/resolveImport.js +0 -504
- package/dist/js/v8_coverage.js +0 -508
- package/dist/no_experimental_warnings.cjs +0 -8
- package/src/execute/execute.js +0 -111
- package/src/execute/run.js +0 -161
- package/src/execute/runtimes/browsers/chromium.js +0 -10
- package/src/execute/runtimes/browsers/firefox.js +0 -9
- package/src/execute/runtimes/browsers/from_playwright.js +0 -574
- package/src/execute/runtimes/browsers/middleware_istanbul.js +0 -65
- package/src/execute/runtimes/browsers/middleware_js_supervisor.js +0 -100
- package/src/execute/runtimes/browsers/webkit.js +0 -26
- package/src/execute/runtimes/node/child_exec_options.js +0 -166
- package/src/execute/runtimes/node/controllable_child_process.mjs +0 -135
- package/src/execute/runtimes/node/controllable_worker_thread.mjs +0 -103
- package/src/execute/runtimes/node/exec_options.js +0 -57
- package/src/execute/runtimes/node/execute_using_dynamic_import.js +0 -55
- package/src/execute/runtimes/node/exit_codes.js +0 -9
- package/src/execute/runtimes/node/importmap_node_loader.mjs +0 -51
- package/src/execute/runtimes/node/importmap_node_loader_file_url.js +0 -4
- package/src/execute/runtimes/node/kill_process_tree.js +0 -76
- package/src/execute/runtimes/node/no_experimental_warnings.cjs +0 -12
- package/src/execute/runtimes/node/no_experimental_warnings_file_url.js +0 -4
- package/src/execute/runtimes/node/node_child_process.js +0 -363
- package/src/execute/runtimes/node/node_execution_performance.js +0 -67
- package/src/execute/runtimes/node/node_worker_thread.js +0 -295
- package/src/execute/runtimes/node/profiler_v8_coverage.js +0 -56
- package/src/execute/runtimes/readme.md +0 -13
- package/src/execute/web_server_param.js +0 -74
- package/src/test/coverage/babel_plugin_instrument.js +0 -48
- package/src/test/coverage/coverage_reporter_html_directory.js +0 -32
- package/src/test/coverage/coverage_reporter_json_file.js +0 -17
- package/src/test/coverage/coverage_reporter_text_log.js +0 -19
- package/src/test/coverage/empty_coverage_factory.js +0 -52
- package/src/test/coverage/file_by_file_coverage.js +0 -25
- package/src/test/coverage/istanbul_coverage_composition.js +0 -28
- package/src/test/coverage/istanbul_coverage_map_from_coverage.js +0 -16
- package/src/test/coverage/list_files_not_covered.js +0 -15
- package/src/test/coverage/missing_coverage.js +0 -41
- package/src/test/coverage/report_to_coverage.js +0 -198
- package/src/test/coverage/v8_and_istanbul.js +0 -37
- package/src/test/coverage/v8_coverage.js +0 -26
- package/src/test/coverage/v8_coverage_composition.js +0 -24
- package/src/test/coverage/v8_coverage_node_directory.js +0 -85
- package/src/test/coverage/v8_coverage_to_istanbul.js +0 -99
- package/src/test/execute_steps.js +0 -425
- package/src/test/execute_test_plan.js +0 -372
- package/src/test/execution_colors.js +0 -10
- package/src/test/execution_steps.js +0 -65
- package/src/test/gc.js +0 -9
- package/src/test/logs_file_execution.js +0 -427
- package/src/test/logs_file_execution.test.mjs +0 -41
- package/src/test/readme.md +0 -3
- /package/src/{basic_fetch.js → helpers/basic_fetch.js} +0 -0
- /package/src/{lookup_package_directory.js → helpers/lookup_package_directory.js} +0 -0
- /package/src/{ping_server.js → helpers/ping_server.js} +0 -0
- /package/src/{require_from_jsenv.js → helpers/require_from_jsenv.js} +0 -0
- /package/src/{watch_source_files.js → helpers/watch_source_files.js} +0 -0
- /package/src/{web_url_converter.js → helpers/web_url_converter.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "35.0.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/jsenv/
|
|
13
|
+
"url": "https://github.com/jsenv/core"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=18.5.0"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
".": {
|
|
26
26
|
"import": {
|
|
27
27
|
"development": "./src/main.js",
|
|
28
|
-
"default": "./dist/
|
|
28
|
+
"default": "./dist/jsenv_core.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"./*": "./*"
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test": "node --conditions=development ./scripts/test/test.mjs",
|
|
46
46
|
"test:no_snapshot_assertion": "npm run test -- --no-snapshot-assertion",
|
|
47
47
|
"test:dev_errors_snapshots": "node --conditions=development ./tests/dev_server/errors/generate_snapshot_files.mjs",
|
|
48
|
-
"test:
|
|
48
|
+
"test:packages": "npm run test --workspaces --if-present -- --workspace",
|
|
49
49
|
"build": "node --conditions=development ./scripts/build/build.mjs",
|
|
50
50
|
"build:file_size": "node ./scripts/build/build_file_size.mjs --log",
|
|
51
51
|
"workspace:versions": "node ./scripts/publish/workspace_versions.mjs",
|
|
@@ -56,14 +56,10 @@
|
|
|
56
56
|
"certificate:install": "node ./scripts/dev/install_certificate_authority.mjs",
|
|
57
57
|
"prepublishOnly": "npm run build"
|
|
58
58
|
},
|
|
59
|
-
"optionalDependencies": {
|
|
60
|
-
"playwright": "1.x"
|
|
61
|
-
},
|
|
62
59
|
"dependencies": {
|
|
63
60
|
"@babel/plugin-proposal-dynamic-import": "7.18.6",
|
|
64
61
|
"@babel/plugin-transform-modules-systemjs": "7.20.11",
|
|
65
62
|
"@babel/plugin-transform-modules-umd": "7.18.6",
|
|
66
|
-
"@c88/v8-coverage": "0.1.1",
|
|
67
63
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
68
64
|
"@jsenv/abort": "4.2.4",
|
|
69
65
|
"@jsenv/ast": "3.0.6",
|
|
@@ -75,24 +71,12 @@
|
|
|
75
71
|
"@jsenv/node-esm-resolution": "1.0.1",
|
|
76
72
|
"@jsenv/server": "15.0.2",
|
|
77
73
|
"@jsenv/sourcemap": "1.0.10",
|
|
78
|
-
"@jsenv/uneval": "1.6.0",
|
|
79
74
|
"@jsenv/url-meta": "8.1.0",
|
|
80
75
|
"@jsenv/urls": "2.0.0",
|
|
81
76
|
"@jsenv/utils": "2.0.1",
|
|
82
|
-
"@paralleldrive/cuid2": "2.2.0",
|
|
83
77
|
"construct-style-sheets-polyfill": "3.1.0",
|
|
84
|
-
"istanbul-lib-coverage": "3.2.0",
|
|
85
|
-
"istanbul-lib-instrument": "5.2.1",
|
|
86
|
-
"istanbul-lib-report": "3.0.0",
|
|
87
|
-
"istanbul-reports": "3.1.5",
|
|
88
78
|
"launch-editor": "2.6.0",
|
|
89
|
-
"lightningcss": "1.19.0"
|
|
90
|
-
"pidtree": "0.6.0",
|
|
91
|
-
"string-width": "5.1.2",
|
|
92
|
-
"strip-ansi": "7.0.1",
|
|
93
|
-
"v8-to-istanbul": "9.1.0",
|
|
94
|
-
"webidl2": "24.2.2",
|
|
95
|
-
"wrap-ansi": "8.1.0"
|
|
79
|
+
"lightningcss": "1.19.0"
|
|
96
80
|
},
|
|
97
81
|
"devDependencies": {
|
|
98
82
|
"@babel/eslint-parser": "7.21.3",
|
|
@@ -107,6 +91,7 @@
|
|
|
107
91
|
"@jsenv/plugin-minification": "./packages/jsenv-plugin-minification/",
|
|
108
92
|
"@jsenv/plugin-placeholders": "./packages/jsenv-plugin-placeholders/",
|
|
109
93
|
"@jsenv/plugin-as-js-classic": "./packages/jsenv-plugin-as-js-classic/",
|
|
94
|
+
"@jsenv/test": "./packages/test/",
|
|
110
95
|
"eslint": "8.38.0",
|
|
111
96
|
"eslint-plugin-html": "7.1.0",
|
|
112
97
|
"eslint-plugin-import": "2.27.5",
|
package/src/build/build.js
CHANGED
|
@@ -53,8 +53,8 @@ import {
|
|
|
53
53
|
findHtmlNode,
|
|
54
54
|
} from "@jsenv/ast"
|
|
55
55
|
|
|
56
|
-
import { lookupPackageDirectory } from "../lookup_package_directory.js"
|
|
57
|
-
import { watchSourceFiles } from "../watch_source_files.js"
|
|
56
|
+
import { lookupPackageDirectory } from "../helpers/lookup_package_directory.js"
|
|
57
|
+
import { watchSourceFiles } from "../helpers/watch_source_files.js"
|
|
58
58
|
import { createUrlGraph } from "../kitchen/url_graph.js"
|
|
59
59
|
import { createKitchen } from "../kitchen/kitchen.js"
|
|
60
60
|
import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js"
|
package/src/dev/file_service.js
CHANGED
|
@@ -4,14 +4,14 @@ import { bufferToEtag } from "@jsenv/filesystem"
|
|
|
4
4
|
import { asUrlWithoutSearch } from "@jsenv/urls"
|
|
5
5
|
import { URL_META } from "@jsenv/url-meta"
|
|
6
6
|
|
|
7
|
-
import { WEB_URL_CONVERTER } from "../web_url_converter.js"
|
|
8
|
-
import { watchSourceFiles } from "../watch_source_files.js"
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { jsenvPluginServerEventsClientInjection } from "
|
|
7
|
+
import { WEB_URL_CONVERTER } from "../helpers/web_url_converter.js"
|
|
8
|
+
import { watchSourceFiles } from "../helpers/watch_source_files.js"
|
|
9
|
+
import { createUrlGraph } from "../kitchen/url_graph.js"
|
|
10
|
+
import { createKitchen } from "../kitchen/kitchen.js"
|
|
11
|
+
import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js"
|
|
12
|
+
import { getCorePlugins } from "../plugins/plugins.js"
|
|
13
|
+
import { explorerHtmlFileUrl } from "../plugins/explorer/jsenv_plugin_explorer.js"
|
|
14
|
+
import { jsenvPluginServerEventsClientInjection } from "../plugins/server_events/jsenv_plugin_server_events_client_injection.js"
|
|
15
15
|
import { parseUserAgentHeader } from "./user_agent.js"
|
|
16
16
|
|
|
17
17
|
export const createFileService = ({
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
} from "@jsenv/server"
|
|
10
10
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js"
|
|
11
11
|
|
|
12
|
-
import { lookupPackageDirectory } from "../lookup_package_directory.js"
|
|
13
|
-
import { createServerEventsDispatcher } from "
|
|
14
|
-
import { defaultRuntimeCompat } from "
|
|
12
|
+
import { lookupPackageDirectory } from "../helpers/lookup_package_directory.js"
|
|
13
|
+
import { createServerEventsDispatcher } from "../plugins/server_events/server_events_dispatcher.js"
|
|
14
|
+
import { defaultRuntimeCompat } from "../build/build.js"
|
|
15
15
|
import { createFileService } from "./file_service.js"
|
|
16
16
|
|
|
17
17
|
/**
|
package/src/dev/user_agent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memoizeByFirstArgument } from "@jsenv/utils/src/memoize/memoize_by_first_argument.js"
|
|
2
2
|
|
|
3
|
-
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
3
|
+
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js"
|
|
4
4
|
|
|
5
5
|
export const parseUserAgentHeader = memoizeByFirstArgument((userAgent) => {
|
|
6
6
|
if (userAgent.includes("node-fetch/")) {
|
package/src/main.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
// dev
|
|
2
2
|
export { startDevServer } from "./dev/start_dev_server.js"
|
|
3
|
-
// test
|
|
4
|
-
export { executeTestPlan } from "./test/execute_test_plan.js"
|
|
5
|
-
// runtimes (used to execute tests)
|
|
6
|
-
export {
|
|
7
|
-
chromium,
|
|
8
|
-
chromiumIsolatedTab,
|
|
9
|
-
} from "./execute/runtimes/browsers/chromium.js"
|
|
10
|
-
export {
|
|
11
|
-
firefox,
|
|
12
|
-
firefoxIsolatedTab,
|
|
13
|
-
} from "./execute/runtimes/browsers/firefox.js"
|
|
14
|
-
export {
|
|
15
|
-
webkit,
|
|
16
|
-
webkitIsolatedTab,
|
|
17
|
-
} from "./execute/runtimes/browsers/webkit.js"
|
|
18
|
-
export { nodeChildProcess } from "./execute/runtimes/node/node_child_process.js"
|
|
19
|
-
export { nodeWorkerThread } from "./execute/runtimes/node/node_worker_thread.js"
|
|
20
3
|
// build
|
|
21
4
|
export { build } from "./build/build.js"
|
|
22
5
|
export { startBuildServer } from "./build/start_build_server.js"
|
|
23
|
-
|
|
24
|
-
// helpers
|
|
25
|
-
export { pingServer } from "./ping_server.js"
|
|
26
|
-
|
|
27
|
-
// advanced
|
|
28
|
-
export { execute } from "./execute/execute.js"
|
|
@@ -7,7 +7,7 @@ import { getOriginalPosition } from "@jsenv/sourcemap"
|
|
|
7
7
|
import { stringifyUrlSite } from "@jsenv/urls"
|
|
8
8
|
|
|
9
9
|
import { injectSupervisorIntoHTML } from "./html_supervisor_injection.js"
|
|
10
|
-
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
10
|
+
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js"
|
|
11
11
|
|
|
12
12
|
export const supervisorFileUrl = new URL(
|
|
13
13
|
"./client/supervisor.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module"
|
|
2
2
|
import { pathToFileURL } from "node:url"
|
|
3
|
-
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
3
|
+
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js"
|
|
4
4
|
|
|
5
5
|
const babelPluginPackagePath = requireFromJsenv.resolve("@jsenv/babel-plugins")
|
|
6
6
|
const babelPluginPackageUrl = pathToFileURL(babelPluginPackagePath)
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@jsenv/sourcemap"
|
|
8
8
|
import { applyBabelPlugins } from "@jsenv/ast"
|
|
9
9
|
|
|
10
|
-
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
10
|
+
import { requireFromJsenv } from "@jsenv/core/src/helpers/require_from_jsenv.js"
|
|
11
11
|
import { requireBabelPlugin } from "../babel/require_babel_plugin.js"
|
|
12
12
|
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
13
13
|
import { babelPluginTransformImportMetaResolve } from "./helpers/babel_plugin_transform_import_meta_resolve.js"
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { uneval, executeUsingDynamicImport } from "./js/execute_using_dynamic_import.js";
|
|
2
|
-
import "node:fs";
|
|
3
|
-
import "node:inspector";
|
|
4
|
-
import "node:perf_hooks";
|
|
5
|
-
|
|
6
|
-
const ACTIONS_AVAILABLE = {
|
|
7
|
-
"execute-using-dynamic-import": executeUsingDynamicImport,
|
|
8
|
-
"execute-using-require": async ({
|
|
9
|
-
fileUrl
|
|
10
|
-
}) => {
|
|
11
|
-
const {
|
|
12
|
-
createRequire
|
|
13
|
-
} = await import("node:module");
|
|
14
|
-
const {
|
|
15
|
-
fileURLToPath
|
|
16
|
-
} = await import("node:url");
|
|
17
|
-
const filePath = fileURLToPath(fileUrl);
|
|
18
|
-
const require = createRequire(fileUrl);
|
|
19
|
-
// eslint-disable-next-line import/no-dynamic-require
|
|
20
|
-
const namespace = require(filePath);
|
|
21
|
-
const namespaceResolved = {};
|
|
22
|
-
await Promise.all(Object.keys(namespace).map(async key => {
|
|
23
|
-
const value = await namespace[key];
|
|
24
|
-
namespaceResolved[key] = value;
|
|
25
|
-
}));
|
|
26
|
-
return namespaceResolved;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const ACTION_REQUEST_EVENT_NAME = "action";
|
|
30
|
-
const ACTION_RESPONSE_EVENT_NAME = "action-result";
|
|
31
|
-
const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
|
|
32
|
-
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
|
|
33
|
-
const sendActionFailed = error => {
|
|
34
|
-
if (error.hasOwnProperty("toString")) {
|
|
35
|
-
delete error.toString;
|
|
36
|
-
}
|
|
37
|
-
sendToParent(ACTION_RESPONSE_EVENT_NAME,
|
|
38
|
-
// process.send algorithm does not send non enumerable values
|
|
39
|
-
// so use @jsenv/uneval
|
|
40
|
-
uneval({
|
|
41
|
-
status: ACTION_RESPONSE_STATUS_FAILED,
|
|
42
|
-
value: error
|
|
43
|
-
}, {
|
|
44
|
-
ignoreSymbols: true
|
|
45
|
-
}));
|
|
46
|
-
};
|
|
47
|
-
const sendActionCompleted = value => {
|
|
48
|
-
sendToParent(ACTION_RESPONSE_EVENT_NAME,
|
|
49
|
-
// here we use JSON.stringify because we should not
|
|
50
|
-
// have non enumerable value (unlike there is on Error objects)
|
|
51
|
-
// otherwise uneval is quite slow to turn a giant object
|
|
52
|
-
// into a string (and value can be giant when using coverage)
|
|
53
|
-
JSON.stringify({
|
|
54
|
-
status: ACTION_RESPONSE_STATUS_COMPLETED,
|
|
55
|
-
value
|
|
56
|
-
}));
|
|
57
|
-
};
|
|
58
|
-
const sendToParent = (type, data) => {
|
|
59
|
-
// https://nodejs.org/api/process.html#process_process_connected
|
|
60
|
-
// not connected anymore, cannot communicate with parent
|
|
61
|
-
if (!process.connected) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
// this can keep process alive longer than expected
|
|
65
|
-
// when source is a long string.
|
|
66
|
-
// It means node process may stay alive longer than expected
|
|
67
|
-
// the time to send the data to the parent.
|
|
68
|
-
process.send({
|
|
69
|
-
jsenv: true,
|
|
70
|
-
type,
|
|
71
|
-
data
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
const onceParentMessage = (type, callback) => {
|
|
75
|
-
const listener = message => {
|
|
76
|
-
if (message && message.jsenv && message.type === type) {
|
|
77
|
-
removeListener(); // commenting this line keep this process alive
|
|
78
|
-
callback(message.data);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const removeListener = () => {
|
|
82
|
-
process.removeListener("message", listener);
|
|
83
|
-
};
|
|
84
|
-
process.on("message", listener);
|
|
85
|
-
return removeListener;
|
|
86
|
-
};
|
|
87
|
-
const removeActionRequestListener = onceParentMessage(ACTION_REQUEST_EVENT_NAME, async ({
|
|
88
|
-
actionType,
|
|
89
|
-
actionParams
|
|
90
|
-
}) => {
|
|
91
|
-
const action = ACTIONS_AVAILABLE[actionType];
|
|
92
|
-
if (!action) {
|
|
93
|
-
sendActionFailed(new Error(`unknown action ${actionType}`));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let value;
|
|
97
|
-
let failed = false;
|
|
98
|
-
try {
|
|
99
|
-
value = await action(actionParams);
|
|
100
|
-
} catch (e) {
|
|
101
|
-
failed = true;
|
|
102
|
-
value = e;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// setTimeout(() => {}, 100)
|
|
106
|
-
|
|
107
|
-
if (failed) {
|
|
108
|
-
sendActionFailed(value);
|
|
109
|
-
} else {
|
|
110
|
-
sendActionCompleted(value);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// removeActionRequestListener()
|
|
114
|
-
if (actionParams.exitAfterAction) {
|
|
115
|
-
removeActionRequestListener();
|
|
116
|
-
// for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
|
|
117
|
-
// process.exit()
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// remove listener to process.on('message')
|
|
122
|
-
// which is sufficient to let child process die
|
|
123
|
-
// assuming nothing else keeps it alive
|
|
124
|
-
// process.once("SIGTERM", removeActionRequestListener)
|
|
125
|
-
// process.once("SIGINT", removeActionRequestListener)
|
|
126
|
-
|
|
127
|
-
setTimeout(() => {
|
|
128
|
-
sendToParent("ready");
|
|
129
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { parentPort } from "node:worker_threads";
|
|
2
|
-
import { uneval, executeUsingDynamicImport } from "./js/execute_using_dynamic_import.js";
|
|
3
|
-
import "node:fs";
|
|
4
|
-
import "node:inspector";
|
|
5
|
-
import "node:perf_hooks";
|
|
6
|
-
|
|
7
|
-
const ACTIONS_AVAILABLE = {
|
|
8
|
-
"execute-using-dynamic-import": executeUsingDynamicImport
|
|
9
|
-
};
|
|
10
|
-
const ACTION_REQUEST_EVENT_NAME = "action";
|
|
11
|
-
const ACTION_RESPONSE_EVENT_NAME = "action-result";
|
|
12
|
-
const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
|
|
13
|
-
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
|
|
14
|
-
const sendActionFailed = error => {
|
|
15
|
-
if (error.hasOwnProperty("toString")) {
|
|
16
|
-
delete error.toString;
|
|
17
|
-
}
|
|
18
|
-
sendToParent(ACTION_RESPONSE_EVENT_NAME,
|
|
19
|
-
// process.send algorithm does not send non enumerable values
|
|
20
|
-
// so use @jsenv/uneval
|
|
21
|
-
uneval({
|
|
22
|
-
status: ACTION_RESPONSE_STATUS_FAILED,
|
|
23
|
-
value: error
|
|
24
|
-
}, {
|
|
25
|
-
ignoreSymbols: true
|
|
26
|
-
}));
|
|
27
|
-
};
|
|
28
|
-
const sendActionCompleted = value => {
|
|
29
|
-
sendToParent(ACTION_RESPONSE_EVENT_NAME,
|
|
30
|
-
// here we use JSON.stringify because we should not
|
|
31
|
-
// have non enumerable value (unlike there is on Error objects)
|
|
32
|
-
// otherwise uneval is quite slow to turn a giant object
|
|
33
|
-
// into a string (and value can be giant when using coverage)
|
|
34
|
-
JSON.stringify({
|
|
35
|
-
status: ACTION_RESPONSE_STATUS_COMPLETED,
|
|
36
|
-
value
|
|
37
|
-
}));
|
|
38
|
-
};
|
|
39
|
-
const sendToParent = (type, data) => {
|
|
40
|
-
// this can keep process alive longer than expected
|
|
41
|
-
// when source is a long string.
|
|
42
|
-
// It means node process may stay alive longer than expected
|
|
43
|
-
// the time to send the data to the parent.
|
|
44
|
-
parentPort.postMessage({
|
|
45
|
-
jsenv: true,
|
|
46
|
-
type,
|
|
47
|
-
data
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const onceParentMessage = (type, callback) => {
|
|
51
|
-
const listener = message => {
|
|
52
|
-
if (message && message.jsenv && message.type === type) {
|
|
53
|
-
removeListener(); // commenting this line keep this worker alive
|
|
54
|
-
callback(message.data);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const removeListener = () => {
|
|
58
|
-
parentPort.removeListener("message", listener);
|
|
59
|
-
};
|
|
60
|
-
parentPort.on("message", listener);
|
|
61
|
-
return removeListener;
|
|
62
|
-
};
|
|
63
|
-
const removeActionRequestListener = onceParentMessage(ACTION_REQUEST_EVENT_NAME, async ({
|
|
64
|
-
actionType,
|
|
65
|
-
actionParams
|
|
66
|
-
}) => {
|
|
67
|
-
const action = ACTIONS_AVAILABLE[actionType];
|
|
68
|
-
if (!action) {
|
|
69
|
-
sendActionFailed(new Error(`unknown action ${actionType}`));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
let value;
|
|
73
|
-
let failed = false;
|
|
74
|
-
try {
|
|
75
|
-
value = await action(actionParams);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
failed = true;
|
|
78
|
-
value = e;
|
|
79
|
-
}
|
|
80
|
-
if (failed) {
|
|
81
|
-
sendActionFailed(value);
|
|
82
|
-
} else {
|
|
83
|
-
sendActionCompleted(value);
|
|
84
|
-
}
|
|
85
|
-
if (actionParams.exitAfterAction) {
|
|
86
|
-
removeActionRequestListener();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
sendToParent("ready");
|
|
91
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
import { normalizeImportMap, resolveImport } from "./js/resolveImport.js";
|
|
4
|
-
|
|
5
|
-
let importMap;
|
|
6
|
-
const cwdUrl = `${String(pathToFileURL(process.cwd()))}/`;
|
|
7
|
-
if (process.env.IMPORT_MAP) {
|
|
8
|
-
importMap = JSON.parse(process.env.IMPORT_MAP);
|
|
9
|
-
} else if (process.env.IMPORT_MAP_PATH) {
|
|
10
|
-
const importmapFileUrl = pathToFileURL(process.env.IMPORT_MAP_PATH);
|
|
11
|
-
const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
|
|
12
|
-
importMap = JSON.parse(importmapFileContentAsString);
|
|
13
|
-
} else {
|
|
14
|
-
const importmapFileUrl = new URL("./import_map.json", cwdUrl);
|
|
15
|
-
const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
|
|
16
|
-
importMap = JSON.parse(importmapFileContentAsString);
|
|
17
|
-
}
|
|
18
|
-
const importMapBaseUrl = process.env.IMPORT_MAP_BASE_URL || cwdUrl;
|
|
19
|
-
importMap = normalizeImportMap(importMap, importMapBaseUrl);
|
|
20
|
-
const resolve = (specifier, context, nextResolve) => {
|
|
21
|
-
try {
|
|
22
|
-
let mapped;
|
|
23
|
-
const importer = context.parentURL ? String(context.parentURL) : undefined;
|
|
24
|
-
const resolved = resolveImport({
|
|
25
|
-
specifier,
|
|
26
|
-
importer,
|
|
27
|
-
importMap,
|
|
28
|
-
defaultExtension: ".js",
|
|
29
|
-
onImportMapping: () => {
|
|
30
|
-
mapped = true;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (mapped) {
|
|
34
|
-
return {
|
|
35
|
-
shortCircuit: true,
|
|
36
|
-
url: resolved
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
} catch (e) {
|
|
40
|
-
if (e.message.includes("bare specifier")) {
|
|
41
|
-
return nextResolve(specifier, context);
|
|
42
|
-
}
|
|
43
|
-
console.error(e);
|
|
44
|
-
return nextResolve(specifier, context);
|
|
45
|
-
}
|
|
46
|
-
return nextResolve(specifier, context);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export { resolve };
|