@jsenv/core 40.0.8 → 40.0.9
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/build/build.js +83 -2
- package/dist/jsenv_core.js +2 -0
- package/dist/jsenv_core_packages.js +10404 -10390
- package/dist/start_build_server/start_build_server.js +2 -2
- package/dist/start_dev_server/start_dev_server.js +13 -2
- package/package.json +5 -5
- package/src/build/build.js +3 -0
- package/src/build/jsenv_plugin_mappings.js +69 -0
- package/src/kitchen/kitchen.js +12 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { assertAndNormalizeDirectoryUrl$2 as assertAndNormalizeDirectoryUrl, createLogger$2 as createLogger, Abort$1 as Abort, raceProcessTeardownEvents$1 as raceProcessTeardownEvents, createTaskLog$2 as createTaskLog, urlToExtension$2 as urlToExtension, urlToPathname$2 as urlToPathname } from "../jsenv_core_packages.js";
|
|
2
2
|
import { startServer, jsenvServiceCORS, jsenvServiceErrorHandler, jsenvAccessControlAllowedHeaders, createFileSystemFetch } from "@jsenv/server";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
+
import "string-width";
|
|
4
5
|
import "node:process";
|
|
5
6
|
import "node:os";
|
|
6
7
|
import "node:tty";
|
|
7
|
-
import "string-width";
|
|
8
8
|
import "node:path";
|
|
9
9
|
import "node:crypto";
|
|
10
|
+
import "node:url";
|
|
10
11
|
import "@jsenv/ast";
|
|
11
12
|
import "@jsenv/sourcemap";
|
|
12
|
-
import "node:url";
|
|
13
13
|
import "node:module";
|
|
14
14
|
import "@jsenv/js-module-fallback";
|
|
15
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, moveUrl, urlIsInsideOf, ensureWindowsDriveLetter, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, setUrlFilename, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, normalizeUrl, ANSI, CONTENT_TYPE, DATA_URL, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, readCustomConditionsFromProcessArgs,
|
|
1
|
+
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, moveUrl, urlIsInsideOf, ensureWindowsDriveLetter, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, setUrlFilename, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, normalizeUrl, ANSI, CONTENT_TYPE, DATA_URL, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, readCustomConditionsFromProcessArgs, defaultLookupPackageScope, defaultReadPackageJson, readEntryStatSync, urlToFilename, ensurePathnameTrailingSlash, comparePathnames, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, jsenvPluginTranspilation, memoizeByFirstArgument, assertAndNormalizeDirectoryUrl, createTaskLog } from "../jsenv_core_packages.js";
|
|
2
2
|
import { WebSocketResponse, pickContentType, ServerEvents, jsenvServiceCORS, jsenvAccessControlAllowedHeaders, composeTwoResponses, serveDirectory, jsenvServiceErrorHandler, startServer } from "@jsenv/server";
|
|
3
3
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js";
|
|
4
4
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
@@ -9,10 +9,10 @@ import { parseHtml, injectHtmlNodeAsEarlyAsPossible, createHtmlNode, stringifyHt
|
|
|
9
9
|
import { performance } from "node:perf_hooks";
|
|
10
10
|
import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
|
|
11
11
|
import { createRequire } from "node:module";
|
|
12
|
+
import "string-width";
|
|
12
13
|
import "node:process";
|
|
13
14
|
import "node:os";
|
|
14
15
|
import "node:tty";
|
|
15
|
-
import "string-width";
|
|
16
16
|
import "node:path";
|
|
17
17
|
import "node:crypto";
|
|
18
18
|
import "@jsenv/js-module-fallback";
|
|
@@ -2696,6 +2696,9 @@ const createKitchen = ({
|
|
|
2696
2696
|
}) => {
|
|
2697
2697
|
const logger = createLogger({ logLevel });
|
|
2698
2698
|
|
|
2699
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
2700
|
+
const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
|
|
2701
|
+
|
|
2699
2702
|
const kitchen = {
|
|
2700
2703
|
context: {
|
|
2701
2704
|
...initialContext,
|
|
@@ -2715,6 +2718,14 @@ const createKitchen = ({
|
|
|
2715
2718
|
sourcemaps,
|
|
2716
2719
|
outDirectoryUrl,
|
|
2717
2720
|
},
|
|
2721
|
+
resolve: (specifier, importer) => {
|
|
2722
|
+
const { url, packageDirectoryUrl, packageJson } = applyNodeEsmResolution({
|
|
2723
|
+
conditions: packageConditions,
|
|
2724
|
+
parentUrl: importer,
|
|
2725
|
+
specifier,
|
|
2726
|
+
});
|
|
2727
|
+
return { url, packageDirectoryUrl, packageJson };
|
|
2728
|
+
},
|
|
2718
2729
|
graph: null,
|
|
2719
2730
|
urlInfoTransformer: null,
|
|
2720
2731
|
pluginController: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "40.0.
|
|
3
|
+
"version": "40.0.9",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -79,20 +79,20 @@
|
|
|
79
79
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
80
80
|
"@jsenv/abort": "4.3.1",
|
|
81
81
|
"@jsenv/ast": "6.6.6",
|
|
82
|
-
"@jsenv/filesystem": "4.14.
|
|
82
|
+
"@jsenv/filesystem": "4.14.5",
|
|
83
83
|
"@jsenv/humanize": "1.3.1",
|
|
84
84
|
"@jsenv/importmap": "1.2.2",
|
|
85
85
|
"@jsenv/integrity": "0.0.2",
|
|
86
86
|
"@jsenv/js-module-fallback": "1.4.4",
|
|
87
87
|
"@jsenv/node-esm-resolution": "1.1.0",
|
|
88
|
-
"@jsenv/plugin-bundling": "2.8.
|
|
88
|
+
"@jsenv/plugin-bundling": "2.8.6",
|
|
89
89
|
"@jsenv/plugin-minification": "1.6.2",
|
|
90
90
|
"@jsenv/plugin-supervisor": "1.6.11",
|
|
91
91
|
"@jsenv/plugin-transpilation": "1.5.7",
|
|
92
92
|
"@jsenv/runtime-compat": "1.3.4",
|
|
93
|
-
"@jsenv/server": "16.0.
|
|
93
|
+
"@jsenv/server": "16.0.5",
|
|
94
94
|
"@jsenv/sourcemap": "1.3.3",
|
|
95
|
-
"@jsenv/url-meta": "8.5.
|
|
95
|
+
"@jsenv/url-meta": "8.5.6",
|
|
96
96
|
"@jsenv/urls": "2.7.0",
|
|
97
97
|
"@jsenv/utils": "2.2.1",
|
|
98
98
|
"string-width": "7.2.0"
|
package/src/build/build.js
CHANGED
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
} from "./build_params.js";
|
|
51
51
|
import { createBuildSpecifierManager } from "./build_specifier_manager.js";
|
|
52
52
|
import { jsenvPluginLineBreakNormalization } from "./jsenv_plugin_line_break_normalization.js";
|
|
53
|
+
import { jsenvPluginMappings } from "./jsenv_plugin_mappings.js";
|
|
53
54
|
import { jsenvPluginSubbuilds } from "./jsenv_plugin_subbuilds.js";
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -99,6 +100,7 @@ export const build = async ({
|
|
|
99
100
|
base = getDefaultBase(runtimeCompat),
|
|
100
101
|
ignore,
|
|
101
102
|
|
|
103
|
+
mappings,
|
|
102
104
|
subbuilds = [],
|
|
103
105
|
plugins = [],
|
|
104
106
|
referenceAnalysis = {},
|
|
@@ -298,6 +300,7 @@ build ${entryPointKeys.length} entry points`);
|
|
|
298
300
|
let subbuildResults = [];
|
|
299
301
|
|
|
300
302
|
const rawPluginStore = createPluginStore([
|
|
303
|
+
...(mappings ? [jsenvPluginMappings(mappings)] : []),
|
|
301
304
|
...jsenvPluginSubbuilds(subbuilds, {
|
|
302
305
|
parentBuildParams: {
|
|
303
306
|
sourceDirectoryUrl,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { URL_META } from "@jsenv/url-meta";
|
|
2
|
+
|
|
3
|
+
export const jsenvPluginMappings = (mappings) => {
|
|
4
|
+
if (!mappings || Object.keys(mappings).length === 0) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const mappingResolvedMap = new Map();
|
|
9
|
+
return {
|
|
10
|
+
name: "jsenv:mappings",
|
|
11
|
+
appliesDuring: "build",
|
|
12
|
+
init: (context) => {
|
|
13
|
+
const kitchen = context.kitchen;
|
|
14
|
+
const sourceDirectoryUrl = context.rootDirectoryUrl;
|
|
15
|
+
for (const key of Object.keys(mappings)) {
|
|
16
|
+
const value = mappings[key];
|
|
17
|
+
const keyResolved = kitchen.resolve(key, sourceDirectoryUrl);
|
|
18
|
+
const valueResolved = kitchen.resolve(value, sourceDirectoryUrl);
|
|
19
|
+
mappingResolvedMap.set(keyResolved.url, valueResolved.url);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
redirectReference: (reference) => {
|
|
23
|
+
for (const [key, value] of mappingResolvedMap) {
|
|
24
|
+
const matchResult = URL_META.applyPatternMatching({
|
|
25
|
+
pattern: key,
|
|
26
|
+
url: reference.url,
|
|
27
|
+
});
|
|
28
|
+
if (!matchResult.matched) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!value.includes("*")) {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
const { matchGroups } = matchResult;
|
|
35
|
+
const parts = value.split("*");
|
|
36
|
+
let newUrl = "";
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (const part of parts) {
|
|
39
|
+
newUrl += `${part}`;
|
|
40
|
+
if (index < parts.length - 1) {
|
|
41
|
+
newUrl += matchGroups[index];
|
|
42
|
+
}
|
|
43
|
+
index++;
|
|
44
|
+
}
|
|
45
|
+
return newUrl;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
53
|
+
// const plugin = jsenvPluginMappings({
|
|
54
|
+
// "emoji-regex/index.js": "emoji-regex/index.mjs",
|
|
55
|
+
// });
|
|
56
|
+
// plugin.init({
|
|
57
|
+
// rootDirectoryUrl: import.meta.resolve("./"),
|
|
58
|
+
// kitchen: {
|
|
59
|
+
// resolve: (specifier, importer) => {
|
|
60
|
+
// return applyNodeEsmResolution({
|
|
61
|
+
// parentUrl: importer,
|
|
62
|
+
// specifier,
|
|
63
|
+
// });
|
|
64
|
+
// },
|
|
65
|
+
// },
|
|
66
|
+
// });
|
|
67
|
+
// plugin.redirectReference({
|
|
68
|
+
// url: import.meta.resolve("emoji-regex/index.js"),
|
|
69
|
+
// });
|
package/src/kitchen/kitchen.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ANSI, createDetailedMessage, createLogger } from "@jsenv/humanize";
|
|
2
|
+
import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
2
3
|
import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
|
|
3
4
|
import { URL_META } from "@jsenv/url-meta";
|
|
4
5
|
import { normalizeUrl } from "@jsenv/urls";
|
|
@@ -51,6 +52,9 @@ export const createKitchen = ({
|
|
|
51
52
|
}) => {
|
|
52
53
|
const logger = createLogger({ logLevel });
|
|
53
54
|
|
|
55
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
56
|
+
const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
|
|
57
|
+
|
|
54
58
|
const kitchen = {
|
|
55
59
|
context: {
|
|
56
60
|
...initialContext,
|
|
@@ -70,6 +74,14 @@ export const createKitchen = ({
|
|
|
70
74
|
sourcemaps,
|
|
71
75
|
outDirectoryUrl,
|
|
72
76
|
},
|
|
77
|
+
resolve: (specifier, importer) => {
|
|
78
|
+
const { url, packageDirectoryUrl, packageJson } = applyNodeEsmResolution({
|
|
79
|
+
conditions: packageConditions,
|
|
80
|
+
parentUrl: importer,
|
|
81
|
+
specifier,
|
|
82
|
+
});
|
|
83
|
+
return { url, packageDirectoryUrl, packageJson };
|
|
84
|
+
},
|
|
73
85
|
graph: null,
|
|
74
86
|
urlInfoTransformer: null,
|
|
75
87
|
pluginController: null,
|