@jsenv/core 40.3.3 → 40.5.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/dist/build/build.js +166 -47
- package/dist/build/jsenv_core_node_modules.js +709 -0
- package/dist/{jsenv_core_packages.js → build/jsenv_core_packages.js} +9716 -17415
- package/dist/start_build_server/jsenv_core_node_modules.js +685 -0
- package/dist/start_build_server/jsenv_core_packages.js +1550 -0
- package/dist/start_build_server/start_build_server.js +2 -4
- package/dist/start_dev_server/jsenv_core_node_modules.js +685 -0
- package/dist/start_dev_server/jsenv_core_packages.js +6208 -0
- package/dist/start_dev_server/start_dev_server.js +85 -38
- package/package.json +16 -17
- package/src/build/build.js +43 -2
- package/src/build/build_specifier_manager.js +2 -2
- package/src/build/build_urls_generator.js +42 -5
- package/src/plugins/resolution_node_esm/node_esm_resolver.js +83 -36
- package/dist/jsenv_core_node_modules.js +0 -2069
- /package/dist/{browserslist_index → build/browserslist_index}/browserslist_index.js +0 -0
package/dist/build/build.js
CHANGED
|
@@ -4,18 +4,18 @@ import { jsenvPluginMinification } from "@jsenv/plugin-minification";
|
|
|
4
4
|
import { jsenvPluginTranspilation, jsenvPluginJsModuleFallback } from "@jsenv/plugin-transpilation";
|
|
5
5
|
import { memoryUsage } from "node:process";
|
|
6
6
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
7
|
-
import { lookupPackageDirectory
|
|
7
|
+
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, urlIsInsideOf, ensureWindowsDriveLetter, setUrlFilename, moveUrl, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, RUNTIME_COMPAT, normalizeUrl, ANSI, CONTENT_TYPE, urlToFilename, DATA_URL, errorToHTML, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, defaultLookupPackageScope, defaultReadPackageJson, readCustomConditionsFromProcessArgs, readEntryStatSync, ensurePathnameTrailingSlash, compareFileUrls, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, renderDetails, humanizeDuration, humanizeFileSize, renderTable, renderBigSection, distributePercentages, humanizeMemory, comparePathnames, UNICODE, escapeRegexpSpecialChars, injectQueryParamIntoSpecifierWithoutEncoding, renderUrlOrRelativeUrlFilename, injectQueryParams, assertAndNormalizeDirectoryUrl, Abort, raceProcessTeardownEvents, startMonitoringCpuUsage, startMonitoringMemoryUsage, createLookupPackageDirectory, readPackageAtOrNull, inferRuntimeCompatFromClosestPackage, browserDefaultRuntimeCompat, nodeDefaultRuntimeCompat, clearDirectorySync, createTaskLog, ensureEmptyDirectory, updateJsonFileSync, createDynamicLog } from "./jsenv_core_packages.js";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
9
|
import { generateSourcemapFileUrl, createMagicSource, composeTwoSourcemaps, generateSourcemapDataUrl, SOURCEMAP } from "@jsenv/sourcemap";
|
|
10
10
|
import { performance } from "node:perf_hooks";
|
|
11
11
|
import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
|
|
12
12
|
import { WebSocketResponse, pickContentType } from "@jsenv/server";
|
|
13
13
|
import { randomUUID, createHash } from "node:crypto";
|
|
14
|
-
import "
|
|
14
|
+
import "./jsenv_core_node_modules.js";
|
|
15
15
|
import "node:os";
|
|
16
16
|
import "node:tty";
|
|
17
|
-
import "node:util";
|
|
18
17
|
import "node:path";
|
|
18
|
+
import "node:util";
|
|
19
19
|
|
|
20
20
|
const getDirectoryWatchPatterns = (
|
|
21
21
|
directoryUrl,
|
|
@@ -5669,28 +5669,63 @@ const createBuildPackageConditions = (
|
|
|
5669
5669
|
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
5670
5670
|
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
5671
5671
|
const processArgConditions = readCustomConditionsFromProcessArgs();
|
|
5672
|
-
const
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5672
|
+
const devResolver = (specifier, importer) => {
|
|
5673
|
+
if (isBareSpecifier$1(specifier)) {
|
|
5674
|
+
const { url } = applyNodeEsmResolution({
|
|
5675
|
+
specifier,
|
|
5676
|
+
parentUrl: importer,
|
|
5677
|
+
});
|
|
5678
|
+
return !url.includes("/node_modules/");
|
|
5679
|
+
}
|
|
5680
|
+
return !importer.includes("/node_modules/");
|
|
5681
|
+
};
|
|
5682
|
+
|
|
5683
|
+
const conditionDefaultResolvers = {
|
|
5684
|
+
"dev:*": devResolver,
|
|
5685
|
+
"development": devResolver,
|
|
5686
|
+
"node": nodeRuntimeEnabled,
|
|
5687
|
+
"browser": !nodeRuntimeEnabled,
|
|
5688
|
+
"import": true,
|
|
5689
|
+
};
|
|
5690
|
+
const conditionResolvers = {
|
|
5691
|
+
...conditionDefaultResolvers,
|
|
5692
|
+
};
|
|
5693
|
+
|
|
5694
|
+
let wildcardToRemoveSet = new Set();
|
|
5695
|
+
const addCustomResolver = (condition, customResolver) => {
|
|
5696
|
+
for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
|
|
5697
|
+
if (conditionCandidate.includes("*")) {
|
|
5698
|
+
const conditionRegex = new RegExp(
|
|
5699
|
+
`^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
|
|
5700
|
+
);
|
|
5701
|
+
if (conditionRegex.test(condition)) {
|
|
5702
|
+
const existingResolver =
|
|
5703
|
+
conditionDefaultResolvers[conditionCandidate];
|
|
5704
|
+
wildcardToRemoveSet.add(conditionCandidate);
|
|
5705
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
5706
|
+
existingResolver,
|
|
5707
|
+
customResolver,
|
|
5708
|
+
);
|
|
5709
|
+
return;
|
|
5710
|
+
}
|
|
5685
5711
|
}
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5712
|
+
}
|
|
5713
|
+
const existingResolver = conditionDefaultResolvers[condition];
|
|
5714
|
+
if (existingResolver) {
|
|
5715
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
5716
|
+
existingResolver,
|
|
5717
|
+
customResolver,
|
|
5718
|
+
);
|
|
5719
|
+
return;
|
|
5720
|
+
}
|
|
5721
|
+
conditionResolvers[condition] = customResolver;
|
|
5691
5722
|
};
|
|
5692
|
-
|
|
5693
|
-
|
|
5723
|
+
|
|
5724
|
+
for (const processArgCondition of processArgConditions) {
|
|
5725
|
+
addCustomResolver(processArgCondition, true);
|
|
5726
|
+
}
|
|
5727
|
+
for (const customCondition of Object.keys(packageConditions)) {
|
|
5728
|
+
const value = packageConditions[customCondition];
|
|
5694
5729
|
let customResolver;
|
|
5695
5730
|
if (typeof value === "object") {
|
|
5696
5731
|
const associations = URL_META.resolveAssociations(
|
|
@@ -5733,29 +5768,25 @@ const createBuildPackageConditions = (
|
|
|
5733
5768
|
} else if (typeof value === "function") {
|
|
5734
5769
|
customResolver = value;
|
|
5735
5770
|
} else {
|
|
5736
|
-
customResolver =
|
|
5737
|
-
}
|
|
5738
|
-
const existing = packageConditionResolvers[condition];
|
|
5739
|
-
if (existing) {
|
|
5740
|
-
packageConditionResolvers[condition] = (...args) => {
|
|
5741
|
-
const customResult = customResolver(...args);
|
|
5742
|
-
return customResult === undefined ? existing(...args) : customResult;
|
|
5743
|
-
};
|
|
5744
|
-
} else {
|
|
5745
|
-
packageConditionResolvers[condition] = customResolver;
|
|
5771
|
+
customResolver = value;
|
|
5746
5772
|
}
|
|
5773
|
+
addCustomResolver(customCondition, customResolver);
|
|
5774
|
+
}
|
|
5775
|
+
|
|
5776
|
+
for (const wildcardToRemove of wildcardToRemoveSet) {
|
|
5777
|
+
delete conditionResolvers[wildcardToRemove];
|
|
5747
5778
|
}
|
|
5748
5779
|
|
|
5780
|
+
const conditionCandidateArray = Object.keys(conditionResolvers);
|
|
5749
5781
|
return (specifier, importer) => {
|
|
5750
5782
|
const conditions = [];
|
|
5751
|
-
for (const conditionCandidate of
|
|
5752
|
-
const
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
if (packageConditionResolver(specifier, importer)) {
|
|
5783
|
+
for (const conditionCandidate of conditionCandidateArray) {
|
|
5784
|
+
const conditionResolver = conditionResolvers[conditionCandidate];
|
|
5785
|
+
if (typeof conditionResolver === "function") {
|
|
5786
|
+
if (conditionResolver(specifier, importer)) {
|
|
5756
5787
|
conditions.push(conditionCandidate);
|
|
5757
5788
|
}
|
|
5758
|
-
} else if (
|
|
5789
|
+
} else if (conditionResolver) {
|
|
5759
5790
|
conditions.push(conditionCandidate);
|
|
5760
5791
|
}
|
|
5761
5792
|
}
|
|
@@ -5763,6 +5794,22 @@ const createBuildPackageConditions = (
|
|
|
5763
5794
|
};
|
|
5764
5795
|
};
|
|
5765
5796
|
|
|
5797
|
+
const combineTwoPackageConditionResolvers = (first, second) => {
|
|
5798
|
+
if (typeof second !== "function") {
|
|
5799
|
+
return second;
|
|
5800
|
+
}
|
|
5801
|
+
return (...args) => {
|
|
5802
|
+
const secondResult = second(...args);
|
|
5803
|
+
if (secondResult !== undefined) {
|
|
5804
|
+
return secondResult;
|
|
5805
|
+
}
|
|
5806
|
+
if (typeof first === "function") {
|
|
5807
|
+
return first(...args);
|
|
5808
|
+
}
|
|
5809
|
+
return first;
|
|
5810
|
+
};
|
|
5811
|
+
};
|
|
5812
|
+
|
|
5766
5813
|
const addRelationshipWithPackageJson = ({
|
|
5767
5814
|
reference,
|
|
5768
5815
|
packageJsonUrl,
|
|
@@ -9020,7 +9067,6 @@ const createBuildSpecifierManager = ({
|
|
|
9020
9067
|
buildUrl = generateSourcemapFileUrl(parentBuildUrl);
|
|
9021
9068
|
reference.generatedSpecifier = buildUrl;
|
|
9022
9069
|
} else {
|
|
9023
|
-
const url = reference.generatedUrl;
|
|
9024
9070
|
const rawUrlInfo = rawKitchen.graph.getUrlInfo(reference.url);
|
|
9025
9071
|
let urlInfo;
|
|
9026
9072
|
if (rawUrlInfo) {
|
|
@@ -9030,6 +9076,7 @@ const createBuildSpecifierManager = ({
|
|
|
9030
9076
|
buildUrlInfo.subtype = reference.expectedSubtype;
|
|
9031
9077
|
urlInfo = buildUrlInfo;
|
|
9032
9078
|
}
|
|
9079
|
+
const url = reference.generatedUrl;
|
|
9033
9080
|
buildUrl = buildUrlsGenerator.generate(url, {
|
|
9034
9081
|
urlInfo,
|
|
9035
9082
|
ownerUrlInfo: reference.ownerUrlInfo,
|
|
@@ -9207,7 +9254,7 @@ const createBuildSpecifierManager = ({
|
|
|
9207
9254
|
js_classic: undefined, // TODO: add comment to explain who is using this
|
|
9208
9255
|
entry_point: undefined,
|
|
9209
9256
|
dynamic_import: undefined,
|
|
9210
|
-
dynamic_import_id: undefined,
|
|
9257
|
+
// dynamic_import_id: undefined,
|
|
9211
9258
|
};
|
|
9212
9259
|
},
|
|
9213
9260
|
formatReference: (reference) => {
|
|
@@ -10349,6 +10396,20 @@ const createBuildUrlsGenerator = ({
|
|
|
10349
10396
|
return buildUrlFromMap;
|
|
10350
10397
|
}
|
|
10351
10398
|
if (urlIsInsideOf(url, buildDirectoryUrl)) {
|
|
10399
|
+
if (ownerUrlInfo.searchParams.has("dynamic_import_id")) {
|
|
10400
|
+
const ownerDirectoryPath = determineDirectoryPath({
|
|
10401
|
+
sourceDirectoryUrl,
|
|
10402
|
+
assetsDirectory,
|
|
10403
|
+
urlInfo: ownerUrlInfo,
|
|
10404
|
+
});
|
|
10405
|
+
const buildRelativeUrl = urlToRelativeUrl(url, buildDirectoryUrl);
|
|
10406
|
+
let buildUrl = `${buildDirectoryUrl}${ownerDirectoryPath}${buildRelativeUrl}`;
|
|
10407
|
+
buildUrl = injectQueryParams(buildUrl, {
|
|
10408
|
+
dynamic_import_id: undefined,
|
|
10409
|
+
});
|
|
10410
|
+
associateBuildUrl(url, buildUrl);
|
|
10411
|
+
return buildUrl;
|
|
10412
|
+
}
|
|
10352
10413
|
associateBuildUrl(url, url);
|
|
10353
10414
|
return url;
|
|
10354
10415
|
}
|
|
@@ -10369,7 +10430,8 @@ const createBuildUrlsGenerator = ({
|
|
|
10369
10430
|
} else {
|
|
10370
10431
|
directoryPath = urlToRelativeUrl(url, sourceDirectoryUrl);
|
|
10371
10432
|
}
|
|
10372
|
-
const
|
|
10433
|
+
const urlObject = new URL(url);
|
|
10434
|
+
const { search } = urlObject;
|
|
10373
10435
|
const buildUrl = `${buildDirectoryUrl}${directoryPath}${search}`;
|
|
10374
10436
|
associateBuildUrl(url, buildUrl);
|
|
10375
10437
|
return buildUrl;
|
|
@@ -10387,6 +10449,7 @@ const createBuildUrlsGenerator = ({
|
|
|
10387
10449
|
nameSetPerDirectoryMap.set(directoryPath, nameSet);
|
|
10388
10450
|
}
|
|
10389
10451
|
const urlObject = new URL(url);
|
|
10452
|
+
injectQueryParams(urlObject, { dynamic_import_id: undefined });
|
|
10390
10453
|
let { search, hash } = urlObject;
|
|
10391
10454
|
let urlName = getUrlName(url, urlInfo);
|
|
10392
10455
|
let [basename, extension] = splitFileExtension(urlName);
|
|
@@ -10433,7 +10496,7 @@ const determineDirectoryPath = ({
|
|
|
10433
10496
|
sourceDirectoryUrl,
|
|
10434
10497
|
assetsDirectory,
|
|
10435
10498
|
urlInfo,
|
|
10436
|
-
ownerUrlInfo,
|
|
10499
|
+
ownerUrlInfo = urlInfo.firstReference.ownerUrlInfo,
|
|
10437
10500
|
}) => {
|
|
10438
10501
|
if (urlInfo.dirnameHint) {
|
|
10439
10502
|
return urlInfo.dirnameHint;
|
|
@@ -10445,13 +10508,29 @@ const determineDirectoryPath = ({
|
|
|
10445
10508
|
const parentDirectoryPath = determineDirectoryPath({
|
|
10446
10509
|
sourceDirectoryUrl,
|
|
10447
10510
|
assetsDirectory,
|
|
10448
|
-
urlInfo: ownerUrlInfo
|
|
10511
|
+
urlInfo: ownerUrlInfo,
|
|
10449
10512
|
});
|
|
10450
10513
|
return parentDirectoryPath;
|
|
10451
10514
|
}
|
|
10452
10515
|
const dynamicImportId = urlInfo.searchParams.get("dynamic_import_id");
|
|
10453
10516
|
if (dynamicImportId) {
|
|
10454
|
-
|
|
10517
|
+
const ancestorImportIds = [];
|
|
10518
|
+
let ancestorUrlInfo = ownerUrlInfo;
|
|
10519
|
+
let currentImportId = dynamicImportId;
|
|
10520
|
+
while (ancestorUrlInfo) {
|
|
10521
|
+
const ancestorDynamicImportId =
|
|
10522
|
+
ancestorUrlInfo.searchParams.get("dynamic_import_id");
|
|
10523
|
+
if (!ancestorDynamicImportId) {
|
|
10524
|
+
break;
|
|
10525
|
+
}
|
|
10526
|
+
if (ancestorDynamicImportId !== currentImportId) {
|
|
10527
|
+
ancestorImportIds.push(ancestorDynamicImportId);
|
|
10528
|
+
currentImportId = ancestorDynamicImportId;
|
|
10529
|
+
}
|
|
10530
|
+
ancestorUrlInfo = ancestorUrlInfo.firstReference?.ownerUrlInfo;
|
|
10531
|
+
}
|
|
10532
|
+
const importIdPath = [...ancestorImportIds, dynamicImportId].join("/");
|
|
10533
|
+
return `${assetsDirectory}${importIdPath}/`;
|
|
10455
10534
|
}
|
|
10456
10535
|
if (urlInfo.isEntryPoint && !urlInfo.isDynamicEntryPoint) {
|
|
10457
10536
|
return "";
|
|
@@ -10694,7 +10773,12 @@ const build = async ({
|
|
|
10694
10773
|
let runtimeType;
|
|
10695
10774
|
{
|
|
10696
10775
|
if (isBareSpecifier(key)) {
|
|
10697
|
-
const packageConditions = [
|
|
10776
|
+
const packageConditions = [
|
|
10777
|
+
"development",
|
|
10778
|
+
"dev:*",
|
|
10779
|
+
"node",
|
|
10780
|
+
"import",
|
|
10781
|
+
];
|
|
10698
10782
|
try {
|
|
10699
10783
|
const { url, type } = applyNodeEsmResolution({
|
|
10700
10784
|
conditions: packageConditions,
|
|
@@ -10870,7 +10954,42 @@ const build = async ({
|
|
|
10870
10954
|
{ sourceUrlToLog, buildUrlToLog },
|
|
10871
10955
|
) => {
|
|
10872
10956
|
let content = "";
|
|
10873
|
-
|
|
10957
|
+
|
|
10958
|
+
const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
|
|
10959
|
+
const fileUrl = new URL(fileRelativeUrl, rootPackageDirectoryUrl);
|
|
10960
|
+
const packageDirectoryUrl = lookupPackageDirectory(fileUrl);
|
|
10961
|
+
if (
|
|
10962
|
+
!packageDirectoryUrl ||
|
|
10963
|
+
packageDirectoryUrl === rootPackageDirectoryUrl
|
|
10964
|
+
) {
|
|
10965
|
+
return ANSI.color(fileRelativeUrl, color);
|
|
10966
|
+
}
|
|
10967
|
+
const parentDirectoryUrl = new URL("../", packageDirectoryUrl).href;
|
|
10968
|
+
const beforePackageDirectoryName = urlToRelativeUrl(
|
|
10969
|
+
parentDirectoryUrl,
|
|
10970
|
+
rootPackageDirectoryUrl,
|
|
10971
|
+
);
|
|
10972
|
+
const packageDirectoryName = urlToFilename(packageDirectoryUrl);
|
|
10973
|
+
const afterPackageDirectoryUrl = urlToRelativeUrl(
|
|
10974
|
+
fileUrl,
|
|
10975
|
+
packageDirectoryUrl,
|
|
10976
|
+
);
|
|
10977
|
+
const beforePackageNameStylized = ANSI.color(
|
|
10978
|
+
beforePackageDirectoryName,
|
|
10979
|
+
color,
|
|
10980
|
+
);
|
|
10981
|
+
const packageNameStylized = ANSI.color(
|
|
10982
|
+
ANSI.effect(packageDirectoryName, ANSI.UNDERLINE),
|
|
10983
|
+
color,
|
|
10984
|
+
);
|
|
10985
|
+
const afterPackageNameStylized = ANSI.color(
|
|
10986
|
+
`/${afterPackageDirectoryUrl}`,
|
|
10987
|
+
color,
|
|
10988
|
+
);
|
|
10989
|
+
return `${beforePackageNameStylized}${packageNameStylized}${afterPackageNameStylized}`;
|
|
10990
|
+
};
|
|
10991
|
+
|
|
10992
|
+
content += `${UNICODE.OK} ${applyColorOnFileRelativeUrl(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${applyColorOnFileRelativeUrl(buildUrlToLog, "")}`;
|
|
10874
10993
|
// content += " ";
|
|
10875
10994
|
// content += ANSI.color("(", ANSI.GREY);
|
|
10876
10995
|
// content += ANSI.color(
|