@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
package/dist/build/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseHtml, injectHtmlNodeAsEarlyAsPossible, createHtmlNode, stringifyHtmlAst, applyBabelPlugins, generateUrlForInlineContent, parseJsWithAcorn, visitHtmlNodes, analyzeScriptNode, getHtmlNodeText, getHtmlNodeAttribute, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeAttributes, setHtmlNodeText, parseCssUrls, getHtmlNodeAttributePosition, parseSrcSet, removeHtmlNodeText, parseJsUrls, getUrlForContentInsideJs, analyzeLinkNode, injectJsenvScript, findHtmlNode, removeHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
|
|
2
|
-
import { lookupPackageDirectory$1 as lookupPackageDirectory, registerDirectoryLifecycle$1 as registerDirectoryLifecycle, urlToRelativeUrl$1 as urlToRelativeUrl, createDetailedMessage$1 as createDetailedMessage, stringifyUrlSite$1 as stringifyUrlSite, generateContentFrame$1 as generateContentFrame, validateResponseIntegrity$1 as validateResponseIntegrity, urlIsInsideOf$1 as urlIsInsideOf, ensureWindowsDriveLetter$1 as ensureWindowsDriveLetter, setUrlFilename$1 as setUrlFilename, moveUrl$1 as moveUrl, getCallerPosition$1 as getCallerPosition, urlToBasename$1 as urlToBasename, urlToExtension$1 as urlToExtension, asSpecifierWithoutSearch$1 as asSpecifierWithoutSearch, asUrlWithoutSearch$1 as asUrlWithoutSearch, injectQueryParamsIntoSpecifier$1 as injectQueryParamsIntoSpecifier, bufferToEtag$1 as bufferToEtag, isFileSystemPath$1 as isFileSystemPath, urlToPathname$1 as urlToPathname, setUrlBasename$1 as setUrlBasename, urlToFileSystemPath$1 as urlToFileSystemPath, writeFileSync$1 as writeFileSync, createLogger$1 as createLogger, URL_META$1 as URL_META, normalizeUrl$1 as normalizeUrl, ANSI$1 as ANSI, CONTENT_TYPE$1 as CONTENT_TYPE, distributePercentages, humanizeFileSize, urlToFilename$1 as urlToFilename, DATA_URL$1 as DATA_URL, normalizeImportMap$1 as normalizeImportMap, composeTwoImportMaps$1 as composeTwoImportMaps, resolveImport$1 as resolveImport, JS_QUOTES$1 as JS_QUOTES, readCustomConditionsFromProcessArgs$1 as readCustomConditionsFromProcessArgs,
|
|
2
|
+
import { lookupPackageDirectory$1 as lookupPackageDirectory, registerDirectoryLifecycle$1 as registerDirectoryLifecycle, urlToRelativeUrl$1 as urlToRelativeUrl, createDetailedMessage$1 as createDetailedMessage, stringifyUrlSite$1 as stringifyUrlSite, generateContentFrame$1 as generateContentFrame, validateResponseIntegrity$1 as validateResponseIntegrity, urlIsInsideOf$1 as urlIsInsideOf, ensureWindowsDriveLetter$1 as ensureWindowsDriveLetter, setUrlFilename$1 as setUrlFilename, moveUrl$1 as moveUrl, getCallerPosition$1 as getCallerPosition, urlToBasename$1 as urlToBasename, urlToExtension$1 as urlToExtension, asSpecifierWithoutSearch$1 as asSpecifierWithoutSearch, asUrlWithoutSearch$1 as asUrlWithoutSearch, injectQueryParamsIntoSpecifier$1 as injectQueryParamsIntoSpecifier, bufferToEtag$1 as bufferToEtag, isFileSystemPath$1 as isFileSystemPath, urlToPathname$1 as urlToPathname, setUrlBasename$1 as setUrlBasename, urlToFileSystemPath$1 as urlToFileSystemPath, writeFileSync$1 as writeFileSync, createLogger$1 as createLogger, URL_META$1 as URL_META, applyNodeEsmResolution$1 as applyNodeEsmResolution, normalizeUrl$1 as normalizeUrl, ANSI$1 as ANSI, CONTENT_TYPE$1 as CONTENT_TYPE, distributePercentages, humanizeFileSize, urlToFilename$1 as urlToFilename, DATA_URL$1 as DATA_URL, normalizeImportMap$1 as normalizeImportMap, composeTwoImportMaps$1 as composeTwoImportMaps, resolveImport$1 as resolveImport, JS_QUOTES$1 as JS_QUOTES, readCustomConditionsFromProcessArgs$1 as readCustomConditionsFromProcessArgs, defaultLookupPackageScope$1 as defaultLookupPackageScope, defaultReadPackageJson$1 as defaultReadPackageJson, readEntryStatSync$1 as readEntryStatSync, ensurePathnameTrailingSlash$1 as ensurePathnameTrailingSlash, comparePathnames$1 as comparePathnames, applyFileSystemMagicResolution$1 as applyFileSystemMagicResolution, getExtensionsToTry$1 as getExtensionsToTry, setUrlExtension$1 as setUrlExtension, jsenvPluginTranspilation$1 as jsenvPluginTranspilation, UNICODE, escapeRegexpSpecialChars, injectQueryParamIntoSpecifierWithoutEncoding, renderUrlOrRelativeUrlFilename, assertAndNormalizeDirectoryUrl$1 as assertAndNormalizeDirectoryUrl, Abort, raceProcessTeardownEvents, jsenvPluginBundling, jsenvPluginMinification, ensureEmptyDirectory, jsenvPluginJsModuleFallback, clearDirectorySync, createTaskLog$1 as createTaskLog } from "../jsenv_core_packages.js";
|
|
3
3
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
4
4
|
import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -8,10 +8,10 @@ import { performance } from "node:perf_hooks";
|
|
|
8
8
|
import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
|
|
9
9
|
import { WebSocketResponse, pickContentType } from "@jsenv/server";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
|
+
import "string-width";
|
|
11
12
|
import "node:process";
|
|
12
13
|
import "node:os";
|
|
13
14
|
import "node:tty";
|
|
14
|
-
import "string-width";
|
|
15
15
|
import "node:path";
|
|
16
16
|
import "node:module";
|
|
17
17
|
import "@jsenv/js-module-fallback";
|
|
@@ -2655,6 +2655,9 @@ const createKitchen = ({
|
|
|
2655
2655
|
}) => {
|
|
2656
2656
|
const logger = createLogger({ logLevel });
|
|
2657
2657
|
|
|
2658
|
+
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
2659
|
+
const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
|
|
2660
|
+
|
|
2658
2661
|
const kitchen = {
|
|
2659
2662
|
context: {
|
|
2660
2663
|
...initialContext,
|
|
@@ -2674,6 +2677,14 @@ const createKitchen = ({
|
|
|
2674
2677
|
sourcemaps,
|
|
2675
2678
|
outDirectoryUrl,
|
|
2676
2679
|
},
|
|
2680
|
+
resolve: (specifier, importer) => {
|
|
2681
|
+
const { url, packageDirectoryUrl, packageJson } = applyNodeEsmResolution({
|
|
2682
|
+
conditions: packageConditions,
|
|
2683
|
+
parentUrl: importer,
|
|
2684
|
+
specifier,
|
|
2685
|
+
});
|
|
2686
|
+
return { url, packageDirectoryUrl, packageJson };
|
|
2687
|
+
},
|
|
2677
2688
|
graph: null,
|
|
2678
2689
|
urlInfoTransformer: null,
|
|
2679
2690
|
pluginController: null,
|
|
@@ -9847,6 +9858,74 @@ const jsenvPluginLineBreakNormalization = () => {
|
|
|
9847
9858
|
};
|
|
9848
9859
|
};
|
|
9849
9860
|
|
|
9861
|
+
const jsenvPluginMappings = (mappings) => {
|
|
9862
|
+
if (!mappings || Object.keys(mappings).length === 0) {
|
|
9863
|
+
return [];
|
|
9864
|
+
}
|
|
9865
|
+
|
|
9866
|
+
const mappingResolvedMap = new Map();
|
|
9867
|
+
return {
|
|
9868
|
+
name: "jsenv:mappings",
|
|
9869
|
+
appliesDuring: "build",
|
|
9870
|
+
init: (context) => {
|
|
9871
|
+
const kitchen = context.kitchen;
|
|
9872
|
+
const sourceDirectoryUrl = context.rootDirectoryUrl;
|
|
9873
|
+
for (const key of Object.keys(mappings)) {
|
|
9874
|
+
const value = mappings[key];
|
|
9875
|
+
const keyResolved = kitchen.resolve(key, sourceDirectoryUrl);
|
|
9876
|
+
const valueResolved = kitchen.resolve(value, sourceDirectoryUrl);
|
|
9877
|
+
mappingResolvedMap.set(keyResolved.url, valueResolved.url);
|
|
9878
|
+
}
|
|
9879
|
+
},
|
|
9880
|
+
redirectReference: (reference) => {
|
|
9881
|
+
for (const [key, value] of mappingResolvedMap) {
|
|
9882
|
+
const matchResult = URL_META.applyPatternMatching({
|
|
9883
|
+
pattern: key,
|
|
9884
|
+
url: reference.url,
|
|
9885
|
+
});
|
|
9886
|
+
if (!matchResult.matched) {
|
|
9887
|
+
continue;
|
|
9888
|
+
}
|
|
9889
|
+
if (!value.includes("*")) {
|
|
9890
|
+
return value;
|
|
9891
|
+
}
|
|
9892
|
+
const { matchGroups } = matchResult;
|
|
9893
|
+
const parts = value.split("*");
|
|
9894
|
+
let newUrl = "";
|
|
9895
|
+
let index = 0;
|
|
9896
|
+
for (const part of parts) {
|
|
9897
|
+
newUrl += `${part}`;
|
|
9898
|
+
if (index < parts.length - 1) {
|
|
9899
|
+
newUrl += matchGroups[index];
|
|
9900
|
+
}
|
|
9901
|
+
index++;
|
|
9902
|
+
}
|
|
9903
|
+
return newUrl;
|
|
9904
|
+
}
|
|
9905
|
+
return null;
|
|
9906
|
+
},
|
|
9907
|
+
};
|
|
9908
|
+
};
|
|
9909
|
+
|
|
9910
|
+
// import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
9911
|
+
// const plugin = jsenvPluginMappings({
|
|
9912
|
+
// "emoji-regex/index.js": "emoji-regex/index.mjs",
|
|
9913
|
+
// });
|
|
9914
|
+
// plugin.init({
|
|
9915
|
+
// rootDirectoryUrl: import.meta.resolve("./"),
|
|
9916
|
+
// kitchen: {
|
|
9917
|
+
// resolve: (specifier, importer) => {
|
|
9918
|
+
// return applyNodeEsmResolution({
|
|
9919
|
+
// parentUrl: importer,
|
|
9920
|
+
// specifier,
|
|
9921
|
+
// });
|
|
9922
|
+
// },
|
|
9923
|
+
// },
|
|
9924
|
+
// });
|
|
9925
|
+
// plugin.redirectReference({
|
|
9926
|
+
// url: import.meta.resolve("emoji-regex/index.js"),
|
|
9927
|
+
// });
|
|
9928
|
+
|
|
9850
9929
|
const jsenvPluginSubbuilds = (
|
|
9851
9930
|
subBuildParamsArray,
|
|
9852
9931
|
{ parentBuildParams, onCustomBuildDirectory, buildStart },
|
|
@@ -9985,6 +10064,7 @@ const build = async ({
|
|
|
9985
10064
|
base = getDefaultBase(runtimeCompat),
|
|
9986
10065
|
ignore,
|
|
9987
10066
|
|
|
10067
|
+
mappings,
|
|
9988
10068
|
subbuilds = [],
|
|
9989
10069
|
plugins = [],
|
|
9990
10070
|
referenceAnalysis = {},
|
|
@@ -10182,6 +10262,7 @@ build ${entryPointKeys.length} entry points`);
|
|
|
10182
10262
|
let subbuildResults = [];
|
|
10183
10263
|
|
|
10184
10264
|
const rawPluginStore = createPluginStore([
|
|
10265
|
+
...(mappings ? [jsenvPluginMappings(mappings)] : []),
|
|
10185
10266
|
...jsenvPluginSubbuilds(subbuilds, {
|
|
10186
10267
|
parentBuildParams: {
|
|
10187
10268
|
sourceDirectoryUrl,
|