@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebSocketResponse, pickContentType, ServerEvents, jsenvServiceCORS, jsenvAccessControlAllowedHeaders, composeTwoResponses, serveDirectory, jsenvServiceErrorHandler, startServer } from "@jsenv/server";
|
|
2
2
|
import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js";
|
|
3
|
-
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, RUNTIME_COMPAT, normalizeUrl, ANSI, CONTENT_TYPE, errorToHTML, DATA_URL, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, defaultLookupPackageScope, defaultReadPackageJson, readCustomConditionsFromProcessArgs, readEntryStatSync, urlToFilename, ensurePathnameTrailingSlash, compareFileUrls, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, memoizeByFirstArgument, assertAndNormalizeDirectoryUrl, createTaskLog, readPackageAtOrNull } from "
|
|
3
|
+
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, RUNTIME_COMPAT, normalizeUrl, ANSI, CONTENT_TYPE, errorToHTML, DATA_URL, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, defaultLookupPackageScope, defaultReadPackageJson, readCustomConditionsFromProcessArgs, readEntryStatSync, urlToFilename, ensurePathnameTrailingSlash, compareFileUrls, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, memoizeByFirstArgument, assertAndNormalizeDirectoryUrl, createTaskLog, readPackageAtOrNull } from "./jsenv_core_packages.js";
|
|
4
4
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { generateSourcemapFileUrl, createMagicSource, composeTwoSourcemaps, generateSourcemapDataUrl, SOURCEMAP } from "@jsenv/sourcemap";
|
|
@@ -10,7 +10,7 @@ import { jsenvPluginSupervisor } from "@jsenv/plugin-supervisor";
|
|
|
10
10
|
import { jsenvPluginTranspilation } from "@jsenv/plugin-transpilation";
|
|
11
11
|
import { randomUUID } from "node:crypto";
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
|
-
import "
|
|
13
|
+
import "./jsenv_core_node_modules.js";
|
|
14
14
|
import "node:process";
|
|
15
15
|
import "node:os";
|
|
16
16
|
import "node:tty";
|
|
@@ -5374,28 +5374,63 @@ const createBuildPackageConditions = (
|
|
|
5374
5374
|
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
5375
5375
|
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
5376
5376
|
const processArgConditions = readCustomConditionsFromProcessArgs();
|
|
5377
|
-
const
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5377
|
+
const devResolver = (specifier, importer) => {
|
|
5378
|
+
if (isBareSpecifier(specifier)) {
|
|
5379
|
+
const { url } = applyNodeEsmResolution({
|
|
5380
|
+
specifier,
|
|
5381
|
+
parentUrl: importer,
|
|
5382
|
+
});
|
|
5383
|
+
return !url.includes("/node_modules/");
|
|
5384
|
+
}
|
|
5385
|
+
return !importer.includes("/node_modules/");
|
|
5386
|
+
};
|
|
5387
|
+
|
|
5388
|
+
const conditionDefaultResolvers = {
|
|
5389
|
+
"dev:*": devResolver,
|
|
5390
|
+
"development": devResolver,
|
|
5391
|
+
"node": nodeRuntimeEnabled,
|
|
5392
|
+
"browser": !nodeRuntimeEnabled,
|
|
5393
|
+
"import": true,
|
|
5394
|
+
};
|
|
5395
|
+
const conditionResolvers = {
|
|
5396
|
+
...conditionDefaultResolvers,
|
|
5397
|
+
};
|
|
5398
|
+
|
|
5399
|
+
let wildcardToRemoveSet = new Set();
|
|
5400
|
+
const addCustomResolver = (condition, customResolver) => {
|
|
5401
|
+
for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
|
|
5402
|
+
if (conditionCandidate.includes("*")) {
|
|
5403
|
+
const conditionRegex = new RegExp(
|
|
5404
|
+
`^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
|
|
5405
|
+
);
|
|
5406
|
+
if (conditionRegex.test(condition)) {
|
|
5407
|
+
const existingResolver =
|
|
5408
|
+
conditionDefaultResolvers[conditionCandidate];
|
|
5409
|
+
wildcardToRemoveSet.add(conditionCandidate);
|
|
5410
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
5411
|
+
existingResolver,
|
|
5412
|
+
customResolver,
|
|
5413
|
+
);
|
|
5414
|
+
return;
|
|
5415
|
+
}
|
|
5390
5416
|
}
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5417
|
+
}
|
|
5418
|
+
const existingResolver = conditionDefaultResolvers[condition];
|
|
5419
|
+
if (existingResolver) {
|
|
5420
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
5421
|
+
existingResolver,
|
|
5422
|
+
customResolver,
|
|
5423
|
+
);
|
|
5424
|
+
return;
|
|
5425
|
+
}
|
|
5426
|
+
conditionResolvers[condition] = customResolver;
|
|
5396
5427
|
};
|
|
5397
|
-
|
|
5398
|
-
|
|
5428
|
+
|
|
5429
|
+
for (const processArgCondition of processArgConditions) {
|
|
5430
|
+
addCustomResolver(processArgCondition, true);
|
|
5431
|
+
}
|
|
5432
|
+
for (const customCondition of Object.keys(packageConditions)) {
|
|
5433
|
+
const value = packageConditions[customCondition];
|
|
5399
5434
|
let customResolver;
|
|
5400
5435
|
if (typeof value === "object") {
|
|
5401
5436
|
const associations = URL_META.resolveAssociations(
|
|
@@ -5438,29 +5473,25 @@ const createBuildPackageConditions = (
|
|
|
5438
5473
|
} else if (typeof value === "function") {
|
|
5439
5474
|
customResolver = value;
|
|
5440
5475
|
} else {
|
|
5441
|
-
customResolver =
|
|
5442
|
-
}
|
|
5443
|
-
const existing = packageConditionResolvers[condition];
|
|
5444
|
-
if (existing) {
|
|
5445
|
-
packageConditionResolvers[condition] = (...args) => {
|
|
5446
|
-
const customResult = customResolver(...args);
|
|
5447
|
-
return customResult === undefined ? existing(...args) : customResult;
|
|
5448
|
-
};
|
|
5449
|
-
} else {
|
|
5450
|
-
packageConditionResolvers[condition] = customResolver;
|
|
5476
|
+
customResolver = value;
|
|
5451
5477
|
}
|
|
5478
|
+
addCustomResolver(customCondition, customResolver);
|
|
5452
5479
|
}
|
|
5453
5480
|
|
|
5481
|
+
for (const wildcardToRemove of wildcardToRemoveSet) {
|
|
5482
|
+
delete conditionResolvers[wildcardToRemove];
|
|
5483
|
+
}
|
|
5484
|
+
|
|
5485
|
+
const conditionCandidateArray = Object.keys(conditionResolvers);
|
|
5454
5486
|
return (specifier, importer) => {
|
|
5455
5487
|
const conditions = [];
|
|
5456
|
-
for (const conditionCandidate of
|
|
5457
|
-
const
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
if (packageConditionResolver(specifier, importer)) {
|
|
5488
|
+
for (const conditionCandidate of conditionCandidateArray) {
|
|
5489
|
+
const conditionResolver = conditionResolvers[conditionCandidate];
|
|
5490
|
+
if (typeof conditionResolver === "function") {
|
|
5491
|
+
if (conditionResolver(specifier, importer)) {
|
|
5461
5492
|
conditions.push(conditionCandidate);
|
|
5462
5493
|
}
|
|
5463
|
-
} else if (
|
|
5494
|
+
} else if (conditionResolver) {
|
|
5464
5495
|
conditions.push(conditionCandidate);
|
|
5465
5496
|
}
|
|
5466
5497
|
}
|
|
@@ -5468,6 +5499,22 @@ const createBuildPackageConditions = (
|
|
|
5468
5499
|
};
|
|
5469
5500
|
};
|
|
5470
5501
|
|
|
5502
|
+
const combineTwoPackageConditionResolvers = (first, second) => {
|
|
5503
|
+
if (typeof second !== "function") {
|
|
5504
|
+
return second;
|
|
5505
|
+
}
|
|
5506
|
+
return (...args) => {
|
|
5507
|
+
const secondResult = second(...args);
|
|
5508
|
+
if (secondResult !== undefined) {
|
|
5509
|
+
return secondResult;
|
|
5510
|
+
}
|
|
5511
|
+
if (typeof first === "function") {
|
|
5512
|
+
return first(...args);
|
|
5513
|
+
}
|
|
5514
|
+
return first;
|
|
5515
|
+
};
|
|
5516
|
+
};
|
|
5517
|
+
|
|
5471
5518
|
const addRelationshipWithPackageJson = ({
|
|
5472
5519
|
reference,
|
|
5473
5520
|
packageJsonUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "40.
|
|
3
|
+
"version": "40.5.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"import": {
|
|
25
|
-
"
|
|
25
|
+
"dev:jsenv": "./src/main.js",
|
|
26
26
|
"default": "./dist/jsenv_core.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
@@ -51,14 +51,13 @@
|
|
|
51
51
|
"./src/kitchen/client/inline_content.js",
|
|
52
52
|
"./dist/client/new_stylesheet/new_stylesheet.js",
|
|
53
53
|
"./dist/client/inline_content/inline_content.js",
|
|
54
|
-
"./dist/client/directory_listing/jsenv_core_node_modules.js"
|
|
55
|
-
"./dist/jsenv_core_node_modules.js"
|
|
54
|
+
"./dist/client/directory_listing/jsenv_core_node_modules.js"
|
|
56
55
|
],
|
|
57
56
|
"scripts": {
|
|
58
57
|
"eslint": "npx eslint .",
|
|
59
|
-
"test": "node --conditions=
|
|
58
|
+
"test": "node --conditions=dev:jsenv ./scripts/test/test.mjs",
|
|
60
59
|
"test:packages": "npm run test -- ./packages/",
|
|
61
|
-
"build": "node --conditions=
|
|
60
|
+
"build": "node --conditions=dev:jsenv ./scripts/build/build.mjs",
|
|
62
61
|
"build:packages": "npm run build --workspaces --if-present --conditions=developement",
|
|
63
62
|
"monorepo:sync_packages_versions": "node ./scripts/monorepo/sync_packages_versions.mjs",
|
|
64
63
|
"monorepo:publish": "node ./scripts/monorepo/publish_packages.mjs",
|
|
@@ -71,23 +70,23 @@
|
|
|
71
70
|
"test:snapshot_clear": "npx @jsenv/filesystem clear **/tests/**/side_effects/",
|
|
72
71
|
"test:ci": "CI=1 npm run test",
|
|
73
72
|
"test:packages:ci": "CI=1 npm run workspace:test",
|
|
74
|
-
"test:only_dev_server_errors": "node --conditions=
|
|
75
|
-
"dev": "node --watch --conditions=
|
|
76
|
-
"dev:route-inspector": "node --watch --conditions=
|
|
73
|
+
"test:only_dev_server_errors": "node --conditions=dev:jsenv ./tests/dev_server/errors/dev_errors_snapshots.test.mjs",
|
|
74
|
+
"dev": "node --watch --conditions=dev:jsenv ./scripts/dev/dev.mjs",
|
|
75
|
+
"dev:route-inspector": "node --watch --conditions=dev:jsenv ./packages/independent/backend/server/tests/route_inspector/start_server.js",
|
|
77
76
|
"playwright:install": "npx playwright install-deps && npx playwright install",
|
|
78
77
|
"https:setup": "npx @jsenv/https-local setup",
|
|
79
78
|
"prepublishOnly": "npm run build"
|
|
80
79
|
},
|
|
81
80
|
"dependencies": {
|
|
82
81
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
83
|
-
"@jsenv/ast": "6.6.
|
|
84
|
-
"@jsenv/js-module-fallback": "1.4.
|
|
85
|
-
"@jsenv/plugin-bundling": "2.9.
|
|
82
|
+
"@jsenv/ast": "6.6.11",
|
|
83
|
+
"@jsenv/js-module-fallback": "1.4.9",
|
|
84
|
+
"@jsenv/plugin-bundling": "2.9.5",
|
|
86
85
|
"@jsenv/plugin-minification": "1.6.3",
|
|
87
|
-
"@jsenv/plugin-supervisor": "1.6.
|
|
88
|
-
"@jsenv/plugin-transpilation": "1.5.
|
|
89
|
-
"@jsenv/sourcemap": "1.3.
|
|
90
|
-
"@jsenv/server": "16.1.
|
|
86
|
+
"@jsenv/plugin-supervisor": "1.6.15",
|
|
87
|
+
"@jsenv/plugin-transpilation": "1.5.16",
|
|
88
|
+
"@jsenv/sourcemap": "1.3.7",
|
|
89
|
+
"@jsenv/server": "16.1.2"
|
|
91
90
|
},
|
|
92
91
|
"devDependencies": {
|
|
93
92
|
"@babel/plugin-syntax-decorators": "7.25.9",
|
|
@@ -129,4 +128,4 @@
|
|
|
129
128
|
"prettier-plugin-organize-imports": "4.1.0",
|
|
130
129
|
"strip-ansi": "7.1.0"
|
|
131
130
|
}
|
|
132
|
-
}
|
|
131
|
+
}
|
package/src/build/build.js
CHANGED
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
urlIsInsideOf,
|
|
56
56
|
urlToBasename,
|
|
57
57
|
urlToExtension,
|
|
58
|
+
urlToFilename,
|
|
58
59
|
urlToRelativeUrl,
|
|
59
60
|
} from "@jsenv/urls";
|
|
60
61
|
import { memoryUsage as processMemoryUsage } from "node:process";
|
|
@@ -170,7 +171,12 @@ export const build = async ({
|
|
|
170
171
|
let runtimeType;
|
|
171
172
|
{
|
|
172
173
|
if (isBareSpecifier(key)) {
|
|
173
|
-
const packageConditions = [
|
|
174
|
+
const packageConditions = [
|
|
175
|
+
"development",
|
|
176
|
+
"dev:*",
|
|
177
|
+
"node",
|
|
178
|
+
"import",
|
|
179
|
+
];
|
|
174
180
|
try {
|
|
175
181
|
const { url, type } = applyNodeEsmResolution({
|
|
176
182
|
conditions: packageConditions,
|
|
@@ -347,7 +353,42 @@ export const build = async ({
|
|
|
347
353
|
{ sourceUrlToLog, buildUrlToLog },
|
|
348
354
|
) => {
|
|
349
355
|
let content = "";
|
|
350
|
-
|
|
356
|
+
|
|
357
|
+
const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
|
|
358
|
+
const fileUrl = new URL(fileRelativeUrl, rootPackageDirectoryUrl);
|
|
359
|
+
const packageDirectoryUrl = lookupPackageDirectory(fileUrl);
|
|
360
|
+
if (
|
|
361
|
+
!packageDirectoryUrl ||
|
|
362
|
+
packageDirectoryUrl === rootPackageDirectoryUrl
|
|
363
|
+
) {
|
|
364
|
+
return ANSI.color(fileRelativeUrl, color);
|
|
365
|
+
}
|
|
366
|
+
const parentDirectoryUrl = new URL("../", packageDirectoryUrl).href;
|
|
367
|
+
const beforePackageDirectoryName = urlToRelativeUrl(
|
|
368
|
+
parentDirectoryUrl,
|
|
369
|
+
rootPackageDirectoryUrl,
|
|
370
|
+
);
|
|
371
|
+
const packageDirectoryName = urlToFilename(packageDirectoryUrl);
|
|
372
|
+
const afterPackageDirectoryUrl = urlToRelativeUrl(
|
|
373
|
+
fileUrl,
|
|
374
|
+
packageDirectoryUrl,
|
|
375
|
+
);
|
|
376
|
+
const beforePackageNameStylized = ANSI.color(
|
|
377
|
+
beforePackageDirectoryName,
|
|
378
|
+
color,
|
|
379
|
+
);
|
|
380
|
+
const packageNameStylized = ANSI.color(
|
|
381
|
+
ANSI.effect(packageDirectoryName, ANSI.UNDERLINE),
|
|
382
|
+
color,
|
|
383
|
+
);
|
|
384
|
+
const afterPackageNameStylized = ANSI.color(
|
|
385
|
+
`/${afterPackageDirectoryUrl}`,
|
|
386
|
+
color,
|
|
387
|
+
);
|
|
388
|
+
return `${beforePackageNameStylized}${packageNameStylized}${afterPackageNameStylized}`;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
content += `${UNICODE.OK} ${applyColorOnFileRelativeUrl(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${applyColorOnFileRelativeUrl(buildUrlToLog, "")}`;
|
|
351
392
|
// content += " ";
|
|
352
393
|
// content += ANSI.color("(", ANSI.GREY);
|
|
353
394
|
// content += ANSI.color(
|
|
@@ -62,7 +62,6 @@ export const createBuildSpecifierManager = ({
|
|
|
62
62
|
buildUrl = generateSourcemapFileUrl(parentBuildUrl);
|
|
63
63
|
reference.generatedSpecifier = buildUrl;
|
|
64
64
|
} else {
|
|
65
|
-
const url = reference.generatedUrl;
|
|
66
65
|
const rawUrlInfo = rawKitchen.graph.getUrlInfo(reference.url);
|
|
67
66
|
let urlInfo;
|
|
68
67
|
if (rawUrlInfo) {
|
|
@@ -72,6 +71,7 @@ export const createBuildSpecifierManager = ({
|
|
|
72
71
|
buildUrlInfo.subtype = reference.expectedSubtype;
|
|
73
72
|
urlInfo = buildUrlInfo;
|
|
74
73
|
}
|
|
74
|
+
const url = reference.generatedUrl;
|
|
75
75
|
buildUrl = buildUrlsGenerator.generate(url, {
|
|
76
76
|
urlInfo,
|
|
77
77
|
ownerUrlInfo: reference.ownerUrlInfo,
|
|
@@ -249,7 +249,7 @@ export const createBuildSpecifierManager = ({
|
|
|
249
249
|
js_classic: undefined, // TODO: add comment to explain who is using this
|
|
250
250
|
entry_point: undefined,
|
|
251
251
|
dynamic_import: undefined,
|
|
252
|
-
dynamic_import_id: undefined,
|
|
252
|
+
// dynamic_import_id: undefined,
|
|
253
253
|
};
|
|
254
254
|
},
|
|
255
255
|
formatReference: (reference) => {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// import { ANSI } from "@jsenv/humanize";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
injectQueryParams,
|
|
4
|
+
urlIsInsideOf,
|
|
5
|
+
urlToFilename,
|
|
6
|
+
urlToRelativeUrl,
|
|
7
|
+
} from "@jsenv/urls";
|
|
3
8
|
|
|
4
9
|
export const createBuildUrlsGenerator = ({
|
|
5
10
|
// logger,
|
|
@@ -32,6 +37,20 @@ export const createBuildUrlsGenerator = ({
|
|
|
32
37
|
return buildUrlFromMap;
|
|
33
38
|
}
|
|
34
39
|
if (urlIsInsideOf(url, buildDirectoryUrl)) {
|
|
40
|
+
if (ownerUrlInfo.searchParams.has("dynamic_import_id")) {
|
|
41
|
+
const ownerDirectoryPath = determineDirectoryPath({
|
|
42
|
+
sourceDirectoryUrl,
|
|
43
|
+
assetsDirectory,
|
|
44
|
+
urlInfo: ownerUrlInfo,
|
|
45
|
+
});
|
|
46
|
+
const buildRelativeUrl = urlToRelativeUrl(url, buildDirectoryUrl);
|
|
47
|
+
let buildUrl = `${buildDirectoryUrl}${ownerDirectoryPath}${buildRelativeUrl}`;
|
|
48
|
+
buildUrl = injectQueryParams(buildUrl, {
|
|
49
|
+
dynamic_import_id: undefined,
|
|
50
|
+
});
|
|
51
|
+
associateBuildUrl(url, buildUrl);
|
|
52
|
+
return buildUrl;
|
|
53
|
+
}
|
|
35
54
|
associateBuildUrl(url, url);
|
|
36
55
|
return url;
|
|
37
56
|
}
|
|
@@ -52,7 +71,8 @@ export const createBuildUrlsGenerator = ({
|
|
|
52
71
|
} else {
|
|
53
72
|
directoryPath = urlToRelativeUrl(url, sourceDirectoryUrl);
|
|
54
73
|
}
|
|
55
|
-
const
|
|
74
|
+
const urlObject = new URL(url);
|
|
75
|
+
const { search } = urlObject;
|
|
56
76
|
const buildUrl = `${buildDirectoryUrl}${directoryPath}${search}`;
|
|
57
77
|
associateBuildUrl(url, buildUrl);
|
|
58
78
|
return buildUrl;
|
|
@@ -70,6 +90,7 @@ export const createBuildUrlsGenerator = ({
|
|
|
70
90
|
nameSetPerDirectoryMap.set(directoryPath, nameSet);
|
|
71
91
|
}
|
|
72
92
|
const urlObject = new URL(url);
|
|
93
|
+
injectQueryParams(urlObject, { dynamic_import_id: undefined });
|
|
73
94
|
let { search, hash } = urlObject;
|
|
74
95
|
let urlName = getUrlName(url, urlInfo);
|
|
75
96
|
let [basename, extension] = splitFileExtension(urlName);
|
|
@@ -116,7 +137,7 @@ const determineDirectoryPath = ({
|
|
|
116
137
|
sourceDirectoryUrl,
|
|
117
138
|
assetsDirectory,
|
|
118
139
|
urlInfo,
|
|
119
|
-
ownerUrlInfo,
|
|
140
|
+
ownerUrlInfo = urlInfo.firstReference.ownerUrlInfo,
|
|
120
141
|
}) => {
|
|
121
142
|
if (urlInfo.dirnameHint) {
|
|
122
143
|
return urlInfo.dirnameHint;
|
|
@@ -128,13 +149,29 @@ const determineDirectoryPath = ({
|
|
|
128
149
|
const parentDirectoryPath = determineDirectoryPath({
|
|
129
150
|
sourceDirectoryUrl,
|
|
130
151
|
assetsDirectory,
|
|
131
|
-
urlInfo: ownerUrlInfo
|
|
152
|
+
urlInfo: ownerUrlInfo,
|
|
132
153
|
});
|
|
133
154
|
return parentDirectoryPath;
|
|
134
155
|
}
|
|
135
156
|
const dynamicImportId = urlInfo.searchParams.get("dynamic_import_id");
|
|
136
157
|
if (dynamicImportId) {
|
|
137
|
-
|
|
158
|
+
const ancestorImportIds = [];
|
|
159
|
+
let ancestorUrlInfo = ownerUrlInfo;
|
|
160
|
+
let currentImportId = dynamicImportId;
|
|
161
|
+
while (ancestorUrlInfo) {
|
|
162
|
+
const ancestorDynamicImportId =
|
|
163
|
+
ancestorUrlInfo.searchParams.get("dynamic_import_id");
|
|
164
|
+
if (!ancestorDynamicImportId) {
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
if (ancestorDynamicImportId !== currentImportId) {
|
|
168
|
+
ancestorImportIds.push(ancestorDynamicImportId);
|
|
169
|
+
currentImportId = ancestorDynamicImportId;
|
|
170
|
+
}
|
|
171
|
+
ancestorUrlInfo = ancestorUrlInfo.firstReference?.ownerUrlInfo;
|
|
172
|
+
}
|
|
173
|
+
const importIdPath = [...ancestorImportIds, dynamicImportId].join("/");
|
|
174
|
+
return `${assetsDirectory}${importIdPath}/`;
|
|
138
175
|
}
|
|
139
176
|
if (urlInfo.isEntryPoint && !urlInfo.isDynamicEntryPoint) {
|
|
140
177
|
return "";
|
|
@@ -126,28 +126,63 @@ const createBuildPackageConditions = (
|
|
|
126
126
|
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
127
127
|
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
128
128
|
const processArgConditions = readCustomConditionsFromProcessArgs();
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
const devResolver = (specifier, importer) => {
|
|
130
|
+
if (isBareSpecifier(specifier)) {
|
|
131
|
+
const { url } = applyNodeEsmResolution({
|
|
132
|
+
specifier,
|
|
133
|
+
parentUrl: importer,
|
|
134
|
+
});
|
|
135
|
+
return !url.includes("/node_modules/");
|
|
136
|
+
}
|
|
137
|
+
return !importer.includes("/node_modules/");
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const conditionDefaultResolvers = {
|
|
141
|
+
"dev:*": devResolver,
|
|
142
|
+
"development": devResolver,
|
|
143
|
+
"node": nodeRuntimeEnabled,
|
|
144
|
+
"browser": !nodeRuntimeEnabled,
|
|
145
|
+
"import": true,
|
|
146
|
+
};
|
|
147
|
+
const conditionResolvers = {
|
|
148
|
+
...conditionDefaultResolvers,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
let wildcardToRemoveSet = new Set();
|
|
152
|
+
const addCustomResolver = (condition, customResolver) => {
|
|
153
|
+
for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
|
|
154
|
+
if (conditionCandidate.includes("*")) {
|
|
155
|
+
const conditionRegex = new RegExp(
|
|
156
|
+
`^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
|
|
157
|
+
);
|
|
158
|
+
if (conditionRegex.test(condition)) {
|
|
159
|
+
const existingResolver =
|
|
160
|
+
conditionDefaultResolvers[conditionCandidate];
|
|
161
|
+
wildcardToRemoveSet.add(conditionCandidate);
|
|
162
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
163
|
+
existingResolver,
|
|
164
|
+
customResolver,
|
|
165
|
+
);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
142
168
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
169
|
+
}
|
|
170
|
+
const existingResolver = conditionDefaultResolvers[condition];
|
|
171
|
+
if (existingResolver) {
|
|
172
|
+
conditionResolvers[condition] = combineTwoPackageConditionResolvers(
|
|
173
|
+
existingResolver,
|
|
174
|
+
customResolver,
|
|
175
|
+
);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
conditionResolvers[condition] = customResolver;
|
|
148
179
|
};
|
|
149
|
-
|
|
150
|
-
|
|
180
|
+
|
|
181
|
+
for (const processArgCondition of processArgConditions) {
|
|
182
|
+
addCustomResolver(processArgCondition, true);
|
|
183
|
+
}
|
|
184
|
+
for (const customCondition of Object.keys(packageConditions)) {
|
|
185
|
+
const value = packageConditions[customCondition];
|
|
151
186
|
let customResolver;
|
|
152
187
|
if (typeof value === "object") {
|
|
153
188
|
const associations = URL_META.resolveAssociations(
|
|
@@ -190,29 +225,25 @@ const createBuildPackageConditions = (
|
|
|
190
225
|
} else if (typeof value === "function") {
|
|
191
226
|
customResolver = value;
|
|
192
227
|
} else {
|
|
193
|
-
customResolver =
|
|
194
|
-
}
|
|
195
|
-
const existing = packageConditionResolvers[condition];
|
|
196
|
-
if (existing) {
|
|
197
|
-
packageConditionResolvers[condition] = (...args) => {
|
|
198
|
-
const customResult = customResolver(...args);
|
|
199
|
-
return customResult === undefined ? existing(...args) : customResult;
|
|
200
|
-
};
|
|
201
|
-
} else {
|
|
202
|
-
packageConditionResolvers[condition] = customResolver;
|
|
228
|
+
customResolver = value;
|
|
203
229
|
}
|
|
230
|
+
addCustomResolver(customCondition, customResolver);
|
|
204
231
|
}
|
|
205
232
|
|
|
233
|
+
for (const wildcardToRemove of wildcardToRemoveSet) {
|
|
234
|
+
delete conditionResolvers[wildcardToRemove];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const conditionCandidateArray = Object.keys(conditionResolvers);
|
|
206
238
|
return (specifier, importer) => {
|
|
207
239
|
const conditions = [];
|
|
208
|
-
for (const conditionCandidate of
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (packageConditionResolver(specifier, importer)) {
|
|
240
|
+
for (const conditionCandidate of conditionCandidateArray) {
|
|
241
|
+
const conditionResolver = conditionResolvers[conditionCandidate];
|
|
242
|
+
if (typeof conditionResolver === "function") {
|
|
243
|
+
if (conditionResolver(specifier, importer)) {
|
|
213
244
|
conditions.push(conditionCandidate);
|
|
214
245
|
}
|
|
215
|
-
} else if (
|
|
246
|
+
} else if (conditionResolver) {
|
|
216
247
|
conditions.push(conditionCandidate);
|
|
217
248
|
}
|
|
218
249
|
}
|
|
@@ -220,6 +251,22 @@ const createBuildPackageConditions = (
|
|
|
220
251
|
};
|
|
221
252
|
};
|
|
222
253
|
|
|
254
|
+
const combineTwoPackageConditionResolvers = (first, second) => {
|
|
255
|
+
if (typeof second !== "function") {
|
|
256
|
+
return second;
|
|
257
|
+
}
|
|
258
|
+
return (...args) => {
|
|
259
|
+
const secondResult = second(...args);
|
|
260
|
+
if (secondResult !== undefined) {
|
|
261
|
+
return secondResult;
|
|
262
|
+
}
|
|
263
|
+
if (typeof first === "function") {
|
|
264
|
+
return first(...args);
|
|
265
|
+
}
|
|
266
|
+
return first;
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
|
|
223
270
|
const addRelationshipWithPackageJson = ({
|
|
224
271
|
reference,
|
|
225
272
|
packageJsonUrl,
|