@jsenv/core 35.0.3 → 35.0.4
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/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +1 -1
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
2
|
-
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
|
|
3
|
-
import { createLogger, createTaskLog } from "@jsenv/log"
|
|
1
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem";
|
|
2
|
+
import { Abort, raceProcessTeardownEvents } from "@jsenv/abort";
|
|
3
|
+
import { createLogger, createTaskLog } from "@jsenv/log";
|
|
4
4
|
import {
|
|
5
5
|
jsenvAccessControlAllowedHeaders,
|
|
6
6
|
startServer,
|
|
7
7
|
jsenvServiceCORS,
|
|
8
8
|
jsenvServiceErrorHandler,
|
|
9
|
-
} from "@jsenv/server"
|
|
10
|
-
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js"
|
|
9
|
+
} from "@jsenv/server";
|
|
10
|
+
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js";
|
|
11
11
|
|
|
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
|
-
import { createFileService } from "./file_service.js"
|
|
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
|
+
import { createFileService } from "./file_service.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Start a server for source files:
|
|
@@ -68,34 +68,34 @@ export const startDevServer = async ({
|
|
|
68
68
|
}) => {
|
|
69
69
|
// params type checking
|
|
70
70
|
{
|
|
71
|
-
const unexpectedParamNames = Object.keys(rest)
|
|
71
|
+
const unexpectedParamNames = Object.keys(rest);
|
|
72
72
|
if (unexpectedParamNames.length > 0) {
|
|
73
73
|
throw new TypeError(
|
|
74
74
|
`${unexpectedParamNames.join(",")}: there is no such param`,
|
|
75
|
-
)
|
|
75
|
+
);
|
|
76
76
|
}
|
|
77
77
|
sourceDirectoryUrl = assertAndNormalizeDirectoryUrl(
|
|
78
78
|
sourceDirectoryUrl,
|
|
79
79
|
"sourceDirectoryUrl",
|
|
80
|
-
)
|
|
80
|
+
);
|
|
81
81
|
if (outDirectoryUrl === undefined) {
|
|
82
82
|
if (!process.env.CI) {
|
|
83
|
-
const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl)
|
|
83
|
+
const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
|
|
84
84
|
if (packageDirectoryUrl) {
|
|
85
|
-
outDirectoryUrl = `${packageDirectoryUrl}.jsenv
|
|
85
|
+
outDirectoryUrl = `${packageDirectoryUrl}.jsenv/`;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
} else if (outDirectoryUrl !== null && outDirectoryUrl !== false) {
|
|
89
89
|
outDirectoryUrl = assertAndNormalizeDirectoryUrl(
|
|
90
90
|
outDirectoryUrl,
|
|
91
91
|
"outDirectoryUrl",
|
|
92
|
-
)
|
|
92
|
+
);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const logger = createLogger({ logLevel })
|
|
97
|
-
const operation = Abort.startOperation()
|
|
98
|
-
operation.addAbortSignal(signal)
|
|
96
|
+
const logger = createLogger({ logLevel });
|
|
97
|
+
const operation = Abort.startOperation();
|
|
98
|
+
operation.addAbortSignal(signal);
|
|
99
99
|
if (handleSIGINT) {
|
|
100
100
|
operation.addAbortSource((abort) => {
|
|
101
101
|
return raceProcessTeardownEvents(
|
|
@@ -103,19 +103,19 @@ export const startDevServer = async ({
|
|
|
103
103
|
SIGINT: true,
|
|
104
104
|
},
|
|
105
105
|
abort,
|
|
106
|
-
)
|
|
107
|
-
})
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
108
|
}
|
|
109
109
|
const startDevServerTask = createTaskLog("start dev server", {
|
|
110
110
|
disabled: !logger.levels.info,
|
|
111
|
-
})
|
|
111
|
+
});
|
|
112
112
|
|
|
113
|
-
const serverStopCallbacks = []
|
|
114
|
-
const serverEventsDispatcher = createServerEventsDispatcher()
|
|
113
|
+
const serverStopCallbacks = [];
|
|
114
|
+
const serverEventsDispatcher = createServerEventsDispatcher();
|
|
115
115
|
serverStopCallbacks.push(() => {
|
|
116
|
-
serverEventsDispatcher.destroy()
|
|
117
|
-
})
|
|
118
|
-
const contextCache = new Map()
|
|
116
|
+
serverEventsDispatcher.destroy();
|
|
117
|
+
});
|
|
118
|
+
const contextCache = new Map();
|
|
119
119
|
const server = await startServer({
|
|
120
120
|
signal,
|
|
121
121
|
stopOnExit: false,
|
|
@@ -137,12 +137,12 @@ export const startDevServer = async ({
|
|
|
137
137
|
{
|
|
138
138
|
handleRequest: (request) => {
|
|
139
139
|
if (request.headers["x-server-inspect"]) {
|
|
140
|
-
return { status: 200 }
|
|
140
|
+
return { status: 200 };
|
|
141
141
|
}
|
|
142
142
|
if (request.pathname === "/__params__.json") {
|
|
143
143
|
const json = JSON.stringify({
|
|
144
144
|
sourceDirectoryUrl,
|
|
145
|
-
})
|
|
145
|
+
});
|
|
146
146
|
return {
|
|
147
147
|
status: 200,
|
|
148
148
|
headers: {
|
|
@@ -150,12 +150,12 @@ export const startDevServer = async ({
|
|
|
150
150
|
"content-length": Buffer.byteLength(json),
|
|
151
151
|
},
|
|
152
152
|
body: json,
|
|
153
|
-
}
|
|
153
|
+
};
|
|
154
154
|
}
|
|
155
|
-
return null
|
|
155
|
+
return null;
|
|
156
156
|
},
|
|
157
157
|
injectResponseHeaders: () => {
|
|
158
|
-
return { server: "jsenv_dev_server/1" }
|
|
158
|
+
return { server: "jsenv_dev_server/1" };
|
|
159
159
|
},
|
|
160
160
|
},
|
|
161
161
|
jsenvServiceCORS({
|
|
@@ -202,7 +202,7 @@ export const startDevServer = async ({
|
|
|
202
202
|
}),
|
|
203
203
|
handleWebsocket: (websocket, { request }) => {
|
|
204
204
|
if (request.headers["sec-websocket-protocol"] === "jsenv") {
|
|
205
|
-
serverEventsDispatcher.addWebsocket(websocket, request)
|
|
205
|
+
serverEventsDispatcher.addWebsocket(websocket, request);
|
|
206
206
|
}
|
|
207
207
|
},
|
|
208
208
|
},
|
|
@@ -211,7 +211,7 @@ export const startDevServer = async ({
|
|
|
211
211
|
handleError: (error) => {
|
|
212
212
|
const getResponseForError = () => {
|
|
213
213
|
if (error && error.asResponse) {
|
|
214
|
-
return error.asResponse()
|
|
214
|
+
return error.asResponse();
|
|
215
215
|
}
|
|
216
216
|
if (
|
|
217
217
|
error &&
|
|
@@ -219,20 +219,20 @@ export const startDevServer = async ({
|
|
|
219
219
|
) {
|
|
220
220
|
return {
|
|
221
221
|
status: 403,
|
|
222
|
-
}
|
|
222
|
+
};
|
|
223
223
|
}
|
|
224
|
-
return convertFileSystemErrorToResponseProperties(error)
|
|
225
|
-
}
|
|
226
|
-
const response = getResponseForError()
|
|
224
|
+
return convertFileSystemErrorToResponseProperties(error);
|
|
225
|
+
};
|
|
226
|
+
const response = getResponseForError();
|
|
227
227
|
if (!response) {
|
|
228
|
-
return null
|
|
228
|
+
return null;
|
|
229
229
|
}
|
|
230
230
|
const body = JSON.stringify({
|
|
231
231
|
status: response.status,
|
|
232
232
|
statusText: response.statusText,
|
|
233
233
|
headers: response.headers,
|
|
234
234
|
body: response.body,
|
|
235
|
-
})
|
|
235
|
+
});
|
|
236
236
|
return {
|
|
237
237
|
status: 200,
|
|
238
238
|
headers: {
|
|
@@ -240,7 +240,7 @@ export const startDevServer = async ({
|
|
|
240
240
|
"content-length": Buffer.byteLength(body),
|
|
241
241
|
},
|
|
242
242
|
body,
|
|
243
|
-
}
|
|
243
|
+
};
|
|
244
244
|
},
|
|
245
245
|
},
|
|
246
246
|
// default error handling
|
|
@@ -248,29 +248,29 @@ export const startDevServer = async ({
|
|
|
248
248
|
sendErrorDetails: true,
|
|
249
249
|
}),
|
|
250
250
|
],
|
|
251
|
-
})
|
|
251
|
+
});
|
|
252
252
|
server.stoppedPromise.then((reason) => {
|
|
253
|
-
onStop()
|
|
253
|
+
onStop();
|
|
254
254
|
serverStopCallbacks.forEach((serverStopCallback) => {
|
|
255
|
-
serverStopCallback(reason)
|
|
256
|
-
})
|
|
257
|
-
serverStopCallbacks.length = 0
|
|
258
|
-
})
|
|
259
|
-
startDevServerTask.done()
|
|
255
|
+
serverStopCallback(reason);
|
|
256
|
+
});
|
|
257
|
+
serverStopCallbacks.length = 0;
|
|
258
|
+
});
|
|
259
|
+
startDevServerTask.done();
|
|
260
260
|
if (hostname) {
|
|
261
|
-
delete server.origins.localip
|
|
262
|
-
delete server.origins.externalip
|
|
261
|
+
delete server.origins.localip;
|
|
262
|
+
delete server.origins.externalip;
|
|
263
263
|
}
|
|
264
|
-
logger.info(``)
|
|
264
|
+
logger.info(``);
|
|
265
265
|
Object.keys(server.origins).forEach((key) => {
|
|
266
|
-
logger.info(`- ${server.origins[key]}`)
|
|
267
|
-
})
|
|
268
|
-
logger.info(``)
|
|
266
|
+
logger.info(`- ${server.origins[key]}`);
|
|
267
|
+
});
|
|
268
|
+
logger.info(``);
|
|
269
269
|
return {
|
|
270
270
|
origin: server.origin,
|
|
271
271
|
stop: () => {
|
|
272
|
-
server.stop()
|
|
272
|
+
server.stop();
|
|
273
273
|
},
|
|
274
274
|
contextCache,
|
|
275
|
-
}
|
|
276
|
-
}
|
|
275
|
+
};
|
|
276
|
+
};
|
package/src/dev/user_agent.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { memoizeByFirstArgument } from "@jsenv/utils/src/memoize/memoize_by_first_argument.js"
|
|
1
|
+
import { memoizeByFirstArgument } from "@jsenv/utils/src/memoize/memoize_by_first_argument.js";
|
|
2
2
|
|
|
3
|
-
import { requireFromJsenv } from "@jsenv/core/src/helpers/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/")) {
|
|
@@ -9,14 +9,14 @@ export const parseUserAgentHeader = memoizeByFirstArgument((userAgent) => {
|
|
|
9
9
|
return {
|
|
10
10
|
runtimeName: "node",
|
|
11
11
|
runtimeVersion: process.version.slice(1),
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
|
-
const UA = requireFromJsenv("@financial-times/polyfill-useragent-normaliser")
|
|
15
|
-
const { ua } = new UA(userAgent)
|
|
16
|
-
const { family, major, minor, patch } = ua
|
|
14
|
+
const UA = requireFromJsenv("@financial-times/polyfill-useragent-normaliser");
|
|
15
|
+
const { ua } = new UA(userAgent);
|
|
16
|
+
const { family, major, minor, patch } = ua;
|
|
17
17
|
return {
|
|
18
18
|
runtimeName: family.toLowerCase(),
|
|
19
19
|
runtimeVersion:
|
|
20
20
|
family === "Other" ? "unknown" : `${major}.${minor}${patch}`,
|
|
21
|
-
}
|
|
22
|
-
})
|
|
21
|
+
};
|
|
22
|
+
});
|
|
@@ -2,15 +2,15 @@ export const basicFetch = async (
|
|
|
2
2
|
url,
|
|
3
3
|
{ rejectUnauthorized = true, method = "GET", headers = {} } = {},
|
|
4
4
|
) => {
|
|
5
|
-
let requestModule
|
|
5
|
+
let requestModule;
|
|
6
6
|
if (url.startsWith("http:")) {
|
|
7
|
-
requestModule = await import("node:http")
|
|
7
|
+
requestModule = await import("node:http");
|
|
8
8
|
} else {
|
|
9
|
-
requestModule = await import("node:https")
|
|
9
|
+
requestModule = await import("node:https");
|
|
10
10
|
}
|
|
11
|
-
const { request } = requestModule
|
|
11
|
+
const { request } = requestModule;
|
|
12
12
|
|
|
13
|
-
const urlObject = new URL(url)
|
|
13
|
+
const urlObject = new URL(url);
|
|
14
14
|
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
16
16
|
const req = request({
|
|
@@ -20,34 +20,34 @@ export const basicFetch = async (
|
|
|
20
20
|
path: urlObject.pathname,
|
|
21
21
|
method,
|
|
22
22
|
headers,
|
|
23
|
-
})
|
|
23
|
+
});
|
|
24
24
|
req.on("response", (response) => {
|
|
25
25
|
resolve({
|
|
26
26
|
status: response.statusCode,
|
|
27
27
|
headers: response.headers,
|
|
28
28
|
json: () => {
|
|
29
|
-
req.setTimeout(0)
|
|
30
|
-
req.destroy()
|
|
29
|
+
req.setTimeout(0);
|
|
30
|
+
req.destroy();
|
|
31
31
|
return new Promise((resolve) => {
|
|
32
32
|
if (response.headers["content-type"] !== "application/json") {
|
|
33
|
-
console.warn("not json")
|
|
33
|
+
console.warn("not json");
|
|
34
34
|
}
|
|
35
|
-
let responseBody = ""
|
|
36
|
-
response.setEncoding("utf8")
|
|
35
|
+
let responseBody = "";
|
|
36
|
+
response.setEncoding("utf8");
|
|
37
37
|
response.on("data", (chunk) => {
|
|
38
|
-
responseBody += chunk
|
|
39
|
-
})
|
|
38
|
+
responseBody += chunk;
|
|
39
|
+
});
|
|
40
40
|
response.on("end", () => {
|
|
41
|
-
resolve(JSON.parse(responseBody))
|
|
42
|
-
})
|
|
41
|
+
resolve(JSON.parse(responseBody));
|
|
42
|
+
});
|
|
43
43
|
response.on("error", (e) => {
|
|
44
|
-
reject(e)
|
|
45
|
-
})
|
|
46
|
-
})
|
|
44
|
+
reject(e);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
47
|
},
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
req.on("error", reject)
|
|
51
|
-
req.end()
|
|
52
|
-
})
|
|
53
|
-
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
req.on("error", reject);
|
|
51
|
+
req.end();
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { exec } from "node:child_process"
|
|
2
|
-
import { createDetailedMessage, createLogger, UNICODE } from "@jsenv/log"
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { createDetailedMessage, createLogger, UNICODE } from "@jsenv/log";
|
|
3
3
|
|
|
4
4
|
export const executeCommand = (
|
|
5
5
|
command,
|
|
@@ -13,10 +13,10 @@ export const executeCommand = (
|
|
|
13
13
|
timeout,
|
|
14
14
|
} = {},
|
|
15
15
|
) => {
|
|
16
|
-
const logger = createLogger({ logLevel })
|
|
16
|
+
const logger = createLogger({ logLevel });
|
|
17
17
|
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
19
|
-
logger.debug(`${UNICODE.COMMAND} ${command}`)
|
|
19
|
+
logger.debug(`${UNICODE.COMMAND} ${command}`);
|
|
20
20
|
const commandProcess = exec(command, {
|
|
21
21
|
signal,
|
|
22
22
|
cwd:
|
|
@@ -26,35 +26,35 @@ export const executeCommand = (
|
|
|
26
26
|
env,
|
|
27
27
|
timeout,
|
|
28
28
|
silent: true,
|
|
29
|
-
})
|
|
29
|
+
});
|
|
30
30
|
commandProcess.on("error", (error) => {
|
|
31
31
|
if (error && error.code === "ETIMEDOUT") {
|
|
32
|
-
logger.error(`timeout after ${timeout} ms`)
|
|
33
|
-
reject(error)
|
|
32
|
+
logger.error(`timeout after ${timeout} ms`);
|
|
33
|
+
reject(error);
|
|
34
34
|
} else {
|
|
35
|
-
reject(error)
|
|
35
|
+
reject(error);
|
|
36
36
|
}
|
|
37
|
-
})
|
|
38
|
-
const stdoutDatas = []
|
|
37
|
+
});
|
|
38
|
+
const stdoutDatas = [];
|
|
39
39
|
commandProcess.stdout.on("data", (data) => {
|
|
40
|
-
stdoutDatas.push(data)
|
|
41
|
-
logger.debug(data)
|
|
42
|
-
onStderr(data)
|
|
43
|
-
})
|
|
44
|
-
let stderrDatas = []
|
|
40
|
+
stdoutDatas.push(data);
|
|
41
|
+
logger.debug(data);
|
|
42
|
+
onStderr(data);
|
|
43
|
+
});
|
|
44
|
+
let stderrDatas = [];
|
|
45
45
|
commandProcess.stderr.on("data", (data) => {
|
|
46
|
-
stderrDatas.push(data)
|
|
47
|
-
logger.debug(data)
|
|
48
|
-
onStdout(data)
|
|
49
|
-
})
|
|
46
|
+
stderrDatas.push(data);
|
|
47
|
+
logger.debug(data);
|
|
48
|
+
onStdout(data);
|
|
49
|
+
});
|
|
50
50
|
if (commandProcess.stdin) {
|
|
51
51
|
commandProcess.stdin.on("error", (error) => {
|
|
52
|
-
reject(error)
|
|
53
|
-
})
|
|
52
|
+
reject(error);
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
commandProcess.on("exit", (exitCode, signal) => {
|
|
56
56
|
if (signal) {
|
|
57
|
-
reject(new Error(`killed with ${signal}`))
|
|
57
|
+
reject(new Error(`killed with ${signal}`));
|
|
58
58
|
}
|
|
59
59
|
if (exitCode) {
|
|
60
60
|
reject(
|
|
@@ -64,10 +64,10 @@ export const executeCommand = (
|
|
|
64
64
|
// "command stdout": stdoutDatas.join(""),
|
|
65
65
|
}),
|
|
66
66
|
),
|
|
67
|
-
)
|
|
68
|
-
return
|
|
67
|
+
);
|
|
68
|
+
return;
|
|
69
69
|
}
|
|
70
|
-
resolve({ exitCode, signal })
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
}
|
|
70
|
+
resolve({ exitCode, signal });
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import { existsSync } from "node:fs"
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
|
|
3
3
|
export const lookupPackageDirectory = (currentUrl) => {
|
|
4
4
|
if (currentUrl === "file:///") {
|
|
5
|
-
return null
|
|
5
|
+
return null;
|
|
6
6
|
}
|
|
7
|
-
const packageJsonFileUrl = `${currentUrl}package.json
|
|
7
|
+
const packageJsonFileUrl = `${currentUrl}package.json`;
|
|
8
8
|
if (existsSync(new URL(packageJsonFileUrl))) {
|
|
9
|
-
return currentUrl
|
|
9
|
+
return currentUrl;
|
|
10
10
|
}
|
|
11
|
-
return lookupPackageDirectory(getParentUrl(currentUrl))
|
|
12
|
-
}
|
|
11
|
+
return lookupPackageDirectory(getParentUrl(currentUrl));
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
const getParentUrl = (url) => {
|
|
15
15
|
if (url.startsWith("file://")) {
|
|
16
16
|
// With node.js new URL('../', 'file:///C:/').href
|
|
17
17
|
// returns "file:///C:/" instead of "file:///"
|
|
18
|
-
const resource = url.slice("file://".length)
|
|
19
|
-
const slashLastIndex = resource.lastIndexOf("/")
|
|
18
|
+
const resource = url.slice("file://".length);
|
|
19
|
+
const slashLastIndex = resource.lastIndexOf("/");
|
|
20
20
|
if (slashLastIndex === -1) {
|
|
21
|
-
return url
|
|
21
|
+
return url;
|
|
22
22
|
}
|
|
23
|
-
const lastCharIndex = resource.length - 1
|
|
23
|
+
const lastCharIndex = resource.length - 1;
|
|
24
24
|
if (slashLastIndex === lastCharIndex) {
|
|
25
|
-
const slashBeforeLastIndex = resource.lastIndexOf(
|
|
25
|
+
const slashBeforeLastIndex = resource.lastIndexOf(
|
|
26
|
+
"/",
|
|
27
|
+
slashLastIndex - 1,
|
|
28
|
+
);
|
|
26
29
|
if (slashBeforeLastIndex === -1) {
|
|
27
|
-
return url
|
|
30
|
+
return url;
|
|
28
31
|
}
|
|
29
|
-
return `file://${resource.slice(0, slashBeforeLastIndex + 1)}
|
|
32
|
+
return `file://${resource.slice(0, slashBeforeLastIndex + 1)}`;
|
|
30
33
|
}
|
|
31
|
-
return `file://${resource.slice(0, slashLastIndex + 1)}
|
|
34
|
+
return `file://${resource.slice(0, slashLastIndex + 1)}`;
|
|
32
35
|
}
|
|
33
|
-
return new URL(url.endsWith("/") ? "../" : "./", url).href
|
|
34
|
-
}
|
|
36
|
+
return new URL(url.endsWith("/") ? "../" : "./", url).href;
|
|
37
|
+
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { createServer } from "node:net"
|
|
1
|
+
import { createServer } from "node:net";
|
|
2
2
|
|
|
3
3
|
export const pingServer = async (url) => {
|
|
4
|
-
const server = createServer()
|
|
5
|
-
const { hostname, port } = new URL(url)
|
|
4
|
+
const server = createServer();
|
|
5
|
+
const { hostname, port } = new URL(url);
|
|
6
6
|
|
|
7
7
|
try {
|
|
8
8
|
await new Promise((resolve, reject) => {
|
|
9
|
-
server.on("error", reject)
|
|
9
|
+
server.on("error", reject);
|
|
10
10
|
server.on("listening", () => {
|
|
11
|
-
resolve()
|
|
12
|
-
})
|
|
13
|
-
server.listen(port, hostname)
|
|
14
|
-
})
|
|
11
|
+
resolve();
|
|
12
|
+
});
|
|
13
|
+
server.listen(port, hostname);
|
|
14
|
+
});
|
|
15
15
|
} catch (error) {
|
|
16
16
|
if (error && error.code === "EADDRINUSE") {
|
|
17
|
-
return true
|
|
17
|
+
return true;
|
|
18
18
|
}
|
|
19
19
|
if (error && error.code === "EACCES") {
|
|
20
|
-
return true
|
|
20
|
+
return true;
|
|
21
21
|
}
|
|
22
|
-
throw error
|
|
22
|
+
throw error;
|
|
23
23
|
}
|
|
24
24
|
await new Promise((resolve, reject) => {
|
|
25
|
-
server.on("error", reject)
|
|
26
|
-
server.on("close", resolve)
|
|
27
|
-
server.close()
|
|
28
|
-
})
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
25
|
+
server.on("error", reject);
|
|
26
|
+
server.on("close", resolve);
|
|
27
|
+
server.close();
|
|
28
|
+
});
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module"
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
|
|
3
|
-
export const requireFromJsenv = createRequire(import.meta.url)
|
|
3
|
+
export const requireFromJsenv = createRequire(import.meta.url);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { registerDirectoryLifecycle } from "@jsenv/filesystem"
|
|
1
|
+
import { registerDirectoryLifecycle } from "@jsenv/filesystem";
|
|
2
2
|
|
|
3
3
|
export const watchSourceFiles = (
|
|
4
4
|
sourceDirectoryUrl,
|
|
@@ -19,7 +19,7 @@ export const watchSourceFiles = (
|
|
|
19
19
|
"**/.*/": false, // directory starting with a dot -> do not watch
|
|
20
20
|
"**/node_modules/": false, // node_modules directory -> do not watch
|
|
21
21
|
...sourceFileConfig,
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
const stopWatchingSourceFiles = registerDirectoryLifecycle(
|
|
24
24
|
sourceDirectoryUrl,
|
|
25
25
|
{
|
|
@@ -31,22 +31,22 @@ export const watchSourceFiles = (
|
|
|
31
31
|
callback({
|
|
32
32
|
url: new URL(relativeUrl, sourceDirectoryUrl).href,
|
|
33
33
|
event: "added",
|
|
34
|
-
})
|
|
34
|
+
});
|
|
35
35
|
},
|
|
36
36
|
updated: ({ relativeUrl }) => {
|
|
37
37
|
callback({
|
|
38
38
|
url: new URL(relativeUrl, sourceDirectoryUrl).href,
|
|
39
39
|
event: "modified",
|
|
40
|
-
})
|
|
40
|
+
});
|
|
41
41
|
},
|
|
42
42
|
removed: ({ relativeUrl }) => {
|
|
43
43
|
callback({
|
|
44
44
|
url: new URL(relativeUrl, sourceDirectoryUrl).href,
|
|
45
45
|
event: "removed",
|
|
46
|
-
})
|
|
46
|
+
});
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
|
-
)
|
|
50
|
-
stopWatchingSourceFiles.watchPatterns = watchPatterns
|
|
51
|
-
return stopWatchingSourceFiles
|
|
52
|
-
}
|
|
49
|
+
);
|
|
50
|
+
stopWatchingSourceFiles.watchPatterns = watchPatterns;
|
|
51
|
+
return stopWatchingSourceFiles;
|
|
52
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ensureWindowsDriveLetter } from "@jsenv/filesystem"
|
|
2
|
-
import { urlIsInsideOf, moveUrl } from "@jsenv/urls"
|
|
1
|
+
import { ensureWindowsDriveLetter } from "@jsenv/filesystem";
|
|
2
|
+
import { urlIsInsideOf, moveUrl } from "@jsenv/urls";
|
|
3
3
|
|
|
4
4
|
export const WEB_URL_CONVERTER = {
|
|
5
5
|
asWebUrl: (fileUrl, webServer) => {
|
|
@@ -8,21 +8,21 @@ export const WEB_URL_CONVERTER = {
|
|
|
8
8
|
url: fileUrl,
|
|
9
9
|
from: webServer.rootDirectoryUrl,
|
|
10
10
|
to: `${webServer.origin}/`,
|
|
11
|
-
})
|
|
11
|
+
});
|
|
12
12
|
}
|
|
13
|
-
const fsRootUrl = ensureWindowsDriveLetter("file:///", fileUrl)
|
|
14
|
-
return `${webServer.origin}/@fs/${fileUrl.slice(fsRootUrl.length)}
|
|
13
|
+
const fsRootUrl = ensureWindowsDriveLetter("file:///", fileUrl);
|
|
14
|
+
return `${webServer.origin}/@fs/${fileUrl.slice(fsRootUrl.length)}`;
|
|
15
15
|
},
|
|
16
16
|
asFileUrl: (webUrl, webServer) => {
|
|
17
|
-
const { pathname, search } = new URL(webUrl)
|
|
17
|
+
const { pathname, search } = new URL(webUrl);
|
|
18
18
|
if (pathname.startsWith("/@fs/")) {
|
|
19
|
-
const fsRootRelativeUrl = pathname.slice("/@fs/".length)
|
|
20
|
-
return `file:///${fsRootRelativeUrl}${search}
|
|
19
|
+
const fsRootRelativeUrl = pathname.slice("/@fs/".length);
|
|
20
|
+
return `file:///${fsRootRelativeUrl}${search}`;
|
|
21
21
|
}
|
|
22
22
|
return moveUrl({
|
|
23
23
|
url: webUrl,
|
|
24
24
|
from: `${webServer.origin}/`,
|
|
25
25
|
to: webServer.rootDirectoryUrl,
|
|
26
|
-
})
|
|
26
|
+
});
|
|
27
27
|
},
|
|
28
|
-
}
|
|
28
|
+
};
|