@jsenv/core 40.5.2 → 40.6.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 +52 -14
- package/dist/build/jsenv_core_packages.js +110 -110
- package/dist/start_dev_server/jsenv_core_packages.js +110 -110
- package/dist/start_dev_server/start_dev_server.js +52 -14
- package/package.json +25 -22
- package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +9 -4
- package/src/plugins/resolution_node_esm/node_esm_resolver.js +43 -10
|
@@ -5349,6 +5349,23 @@ const isResponseEligibleForIntegrityValidation = (response) => {
|
|
|
5349
5349
|
return ["basic", "cors", "default"].includes(response.type);
|
|
5350
5350
|
};
|
|
5351
5351
|
|
|
5352
|
+
const assertImportMap = (value) => {
|
|
5353
|
+
if (value === null) {
|
|
5354
|
+
throw new TypeError(`an importMap must be an object, got null`);
|
|
5355
|
+
}
|
|
5356
|
+
|
|
5357
|
+
const type = typeof value;
|
|
5358
|
+
if (type !== "object") {
|
|
5359
|
+
throw new TypeError(`an importMap must be an object, received ${value}`);
|
|
5360
|
+
}
|
|
5361
|
+
|
|
5362
|
+
if (Array.isArray(value)) {
|
|
5363
|
+
throw new TypeError(
|
|
5364
|
+
`an importMap must be an object, received array ${value}`,
|
|
5365
|
+
);
|
|
5366
|
+
}
|
|
5367
|
+
};
|
|
5368
|
+
|
|
5352
5369
|
// duplicated from @jsenv/log to avoid the dependency
|
|
5353
5370
|
const createDetailedMessage = (message, details = {}) => {
|
|
5354
5371
|
let string = `${message}`;
|
|
@@ -5365,89 +5382,72 @@ const createDetailedMessage = (message, details = {}) => {
|
|
|
5365
5382
|
}`;
|
|
5366
5383
|
});
|
|
5367
5384
|
|
|
5368
|
-
return string
|
|
5385
|
+
return string;
|
|
5369
5386
|
};
|
|
5370
5387
|
|
|
5371
|
-
const
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
}
|
|
5375
|
-
|
|
5376
|
-
const type = typeof value;
|
|
5377
|
-
if (type !== "object") {
|
|
5378
|
-
throw new TypeError(`an importMap must be an object, received ${value}`)
|
|
5379
|
-
}
|
|
5388
|
+
const hasScheme = (string) => {
|
|
5389
|
+
return /^[a-zA-Z]{2,}:/.test(string);
|
|
5390
|
+
};
|
|
5380
5391
|
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5392
|
+
const pathnameToParentPathname = (pathname) => {
|
|
5393
|
+
const slashLastIndex = pathname.lastIndexOf("/");
|
|
5394
|
+
if (slashLastIndex === -1) {
|
|
5395
|
+
return "/";
|
|
5385
5396
|
}
|
|
5386
|
-
};
|
|
5387
5397
|
|
|
5388
|
-
|
|
5389
|
-
return /^[a-zA-Z]{2,}:/.test(string)
|
|
5398
|
+
return pathname.slice(0, slashLastIndex + 1);
|
|
5390
5399
|
};
|
|
5391
5400
|
|
|
5392
5401
|
const urlToScheme = (urlString) => {
|
|
5393
5402
|
const colonIndex = urlString.indexOf(":");
|
|
5394
|
-
if (colonIndex === -1) return ""
|
|
5395
|
-
return urlString.slice(0, colonIndex)
|
|
5403
|
+
if (colonIndex === -1) return "";
|
|
5404
|
+
return urlString.slice(0, colonIndex);
|
|
5405
|
+
};
|
|
5406
|
+
|
|
5407
|
+
const urlToOrigin = (urlString) => {
|
|
5408
|
+
const scheme = urlToScheme(urlString);
|
|
5409
|
+
|
|
5410
|
+
if (scheme === "file") {
|
|
5411
|
+
return "file://";
|
|
5412
|
+
}
|
|
5413
|
+
|
|
5414
|
+
if (scheme === "http" || scheme === "https") {
|
|
5415
|
+
const secondProtocolSlashIndex = scheme.length + "://".length;
|
|
5416
|
+
const pathnameSlashIndex = urlString.indexOf("/", secondProtocolSlashIndex);
|
|
5417
|
+
|
|
5418
|
+
if (pathnameSlashIndex === -1) return urlString;
|
|
5419
|
+
return urlString.slice(0, pathnameSlashIndex);
|
|
5420
|
+
}
|
|
5421
|
+
|
|
5422
|
+
return urlString.slice(0, scheme.length + 1);
|
|
5396
5423
|
};
|
|
5397
5424
|
|
|
5398
5425
|
const urlToPathname = (urlString) => {
|
|
5399
|
-
return ressourceToPathname(urlToRessource(urlString))
|
|
5426
|
+
return ressourceToPathname(urlToRessource(urlString));
|
|
5400
5427
|
};
|
|
5401
5428
|
|
|
5402
5429
|
const urlToRessource = (urlString) => {
|
|
5403
5430
|
const scheme = urlToScheme(urlString);
|
|
5404
5431
|
|
|
5405
5432
|
if (scheme === "file") {
|
|
5406
|
-
return urlString.slice("file://".length)
|
|
5433
|
+
return urlString.slice("file://".length);
|
|
5407
5434
|
}
|
|
5408
5435
|
|
|
5409
5436
|
if (scheme === "https" || scheme === "http") {
|
|
5410
5437
|
// remove origin
|
|
5411
5438
|
const afterProtocol = urlString.slice(scheme.length + "://".length);
|
|
5412
5439
|
const pathnameSlashIndex = afterProtocol.indexOf("/", "://".length);
|
|
5413
|
-
return afterProtocol.slice(pathnameSlashIndex)
|
|
5440
|
+
return afterProtocol.slice(pathnameSlashIndex);
|
|
5414
5441
|
}
|
|
5415
5442
|
|
|
5416
|
-
return urlString.slice(scheme.length + 1)
|
|
5443
|
+
return urlString.slice(scheme.length + 1);
|
|
5417
5444
|
};
|
|
5418
5445
|
|
|
5419
5446
|
const ressourceToPathname = (ressource) => {
|
|
5420
5447
|
const searchSeparatorIndex = ressource.indexOf("?");
|
|
5421
5448
|
return searchSeparatorIndex === -1
|
|
5422
5449
|
? ressource
|
|
5423
|
-
: ressource.slice(0, searchSeparatorIndex)
|
|
5424
|
-
};
|
|
5425
|
-
|
|
5426
|
-
const urlToOrigin = (urlString) => {
|
|
5427
|
-
const scheme = urlToScheme(urlString);
|
|
5428
|
-
|
|
5429
|
-
if (scheme === "file") {
|
|
5430
|
-
return "file://"
|
|
5431
|
-
}
|
|
5432
|
-
|
|
5433
|
-
if (scheme === "http" || scheme === "https") {
|
|
5434
|
-
const secondProtocolSlashIndex = scheme.length + "://".length;
|
|
5435
|
-
const pathnameSlashIndex = urlString.indexOf("/", secondProtocolSlashIndex);
|
|
5436
|
-
|
|
5437
|
-
if (pathnameSlashIndex === -1) return urlString
|
|
5438
|
-
return urlString.slice(0, pathnameSlashIndex)
|
|
5439
|
-
}
|
|
5440
|
-
|
|
5441
|
-
return urlString.slice(0, scheme.length + 1)
|
|
5442
|
-
};
|
|
5443
|
-
|
|
5444
|
-
const pathnameToParentPathname = (pathname) => {
|
|
5445
|
-
const slashLastIndex = pathname.lastIndexOf("/");
|
|
5446
|
-
if (slashLastIndex === -1) {
|
|
5447
|
-
return "/"
|
|
5448
|
-
}
|
|
5449
|
-
|
|
5450
|
-
return pathname.slice(0, slashLastIndex + 1)
|
|
5450
|
+
: ressource.slice(0, searchSeparatorIndex);
|
|
5451
5451
|
};
|
|
5452
5452
|
|
|
5453
5453
|
// could be useful: https://url.spec.whatwg.org/#url-miscellaneous
|
|
@@ -5456,29 +5456,29 @@ const pathnameToParentPathname = (pathname) => {
|
|
|
5456
5456
|
const resolveUrl = (specifier, baseUrl) => {
|
|
5457
5457
|
if (baseUrl) {
|
|
5458
5458
|
if (typeof baseUrl !== "string") {
|
|
5459
|
-
throw new TypeError(writeBaseUrlMustBeAString({ baseUrl, specifier }))
|
|
5459
|
+
throw new TypeError(writeBaseUrlMustBeAString({ baseUrl, specifier }));
|
|
5460
5460
|
}
|
|
5461
5461
|
if (!hasScheme(baseUrl)) {
|
|
5462
|
-
throw new Error(writeBaseUrlMustBeAbsolute({ baseUrl, specifier }))
|
|
5462
|
+
throw new Error(writeBaseUrlMustBeAbsolute({ baseUrl, specifier }));
|
|
5463
5463
|
}
|
|
5464
5464
|
}
|
|
5465
5465
|
|
|
5466
5466
|
if (hasScheme(specifier)) {
|
|
5467
|
-
return specifier
|
|
5467
|
+
return specifier;
|
|
5468
5468
|
}
|
|
5469
5469
|
|
|
5470
5470
|
if (!baseUrl) {
|
|
5471
|
-
throw new Error(writeBaseUrlRequired({ baseUrl, specifier }))
|
|
5471
|
+
throw new Error(writeBaseUrlRequired({ baseUrl, specifier }));
|
|
5472
5472
|
}
|
|
5473
5473
|
|
|
5474
5474
|
// scheme relative
|
|
5475
5475
|
if (specifier.slice(0, 2) === "//") {
|
|
5476
|
-
return `${urlToScheme(baseUrl)}:${specifier}
|
|
5476
|
+
return `${urlToScheme(baseUrl)}:${specifier}`;
|
|
5477
5477
|
}
|
|
5478
5478
|
|
|
5479
5479
|
// origin relative
|
|
5480
5480
|
if (specifier[0] === "/") {
|
|
5481
|
-
return `${urlToOrigin(baseUrl)}${specifier}
|
|
5481
|
+
return `${urlToOrigin(baseUrl)}${specifier}`;
|
|
5482
5482
|
}
|
|
5483
5483
|
|
|
5484
5484
|
const baseOrigin = urlToOrigin(baseUrl);
|
|
@@ -5486,13 +5486,13 @@ const resolveUrl = (specifier, baseUrl) => {
|
|
|
5486
5486
|
|
|
5487
5487
|
if (specifier === ".") {
|
|
5488
5488
|
const baseDirectoryPathname = pathnameToParentPathname(basePathname);
|
|
5489
|
-
return `${baseOrigin}${baseDirectoryPathname}
|
|
5489
|
+
return `${baseOrigin}${baseDirectoryPathname}`;
|
|
5490
5490
|
}
|
|
5491
5491
|
|
|
5492
5492
|
// pathname relative inside
|
|
5493
5493
|
if (specifier.slice(0, 2) === "./") {
|
|
5494
5494
|
const baseDirectoryPathname = pathnameToParentPathname(basePathname);
|
|
5495
|
-
return `${baseOrigin}${baseDirectoryPathname}${specifier.slice(2)}
|
|
5495
|
+
return `${baseOrigin}${baseDirectoryPathname}${specifier.slice(2)}`;
|
|
5496
5496
|
}
|
|
5497
5497
|
|
|
5498
5498
|
// pathname relative outside
|
|
@@ -5513,17 +5513,17 @@ const resolveUrl = (specifier, baseUrl) => {
|
|
|
5513
5513
|
const resolvedPathname = `${importerFolders.join(
|
|
5514
5514
|
"/",
|
|
5515
5515
|
)}/${unresolvedPathname}`;
|
|
5516
|
-
return `${baseOrigin}${resolvedPathname}
|
|
5516
|
+
return `${baseOrigin}${resolvedPathname}`;
|
|
5517
5517
|
}
|
|
5518
5518
|
|
|
5519
5519
|
// bare
|
|
5520
5520
|
if (basePathname === "") {
|
|
5521
|
-
return `${baseOrigin}/${specifier}
|
|
5521
|
+
return `${baseOrigin}/${specifier}`;
|
|
5522
5522
|
}
|
|
5523
5523
|
if (basePathname[basePathname.length] === "/") {
|
|
5524
|
-
return `${baseOrigin}${basePathname}${specifier}
|
|
5524
|
+
return `${baseOrigin}${basePathname}${specifier}`;
|
|
5525
5525
|
}
|
|
5526
|
-
return `${baseOrigin}${pathnameToParentPathname(basePathname)}${specifier}
|
|
5526
|
+
return `${baseOrigin}${pathnameToParentPathname(basePathname)}${specifier}`;
|
|
5527
5527
|
};
|
|
5528
5528
|
|
|
5529
5529
|
const writeBaseUrlMustBeAString = ({
|
|
@@ -5555,7 +5555,7 @@ ${specifier}`;
|
|
|
5555
5555
|
|
|
5556
5556
|
const tryUrlResolution = (string, url) => {
|
|
5557
5557
|
const result = resolveUrl(string, url);
|
|
5558
|
-
return hasScheme(result) ? result : null
|
|
5558
|
+
return hasScheme(result) ? result : null;
|
|
5559
5559
|
};
|
|
5560
5560
|
|
|
5561
5561
|
const resolveSpecifier = (specifier, importer) => {
|
|
@@ -5565,14 +5565,14 @@ const resolveSpecifier = (specifier, importer) => {
|
|
|
5565
5565
|
specifier.startsWith("./") ||
|
|
5566
5566
|
specifier.startsWith("../")
|
|
5567
5567
|
) {
|
|
5568
|
-
return resolveUrl(specifier, importer)
|
|
5568
|
+
return resolveUrl(specifier, importer);
|
|
5569
5569
|
}
|
|
5570
5570
|
|
|
5571
5571
|
if (hasScheme(specifier)) {
|
|
5572
|
-
return specifier
|
|
5572
|
+
return specifier;
|
|
5573
5573
|
}
|
|
5574
5574
|
|
|
5575
|
-
return null
|
|
5575
|
+
return null;
|
|
5576
5576
|
};
|
|
5577
5577
|
|
|
5578
5578
|
const applyImportMap = ({
|
|
@@ -5585,7 +5585,7 @@ const applyImportMap = ({
|
|
|
5585
5585
|
specifier,
|
|
5586
5586
|
importer,
|
|
5587
5587
|
}),
|
|
5588
|
-
)
|
|
5588
|
+
);
|
|
5589
5589
|
},
|
|
5590
5590
|
onImportMapping = () => {},
|
|
5591
5591
|
}) => {
|
|
@@ -5596,7 +5596,7 @@ const applyImportMap = ({
|
|
|
5596
5596
|
specifier,
|
|
5597
5597
|
importer,
|
|
5598
5598
|
}),
|
|
5599
|
-
)
|
|
5599
|
+
);
|
|
5600
5600
|
}
|
|
5601
5601
|
if (importer) {
|
|
5602
5602
|
if (typeof importer !== "string") {
|
|
@@ -5605,7 +5605,7 @@ const applyImportMap = ({
|
|
|
5605
5605
|
importer,
|
|
5606
5606
|
specifier,
|
|
5607
5607
|
}),
|
|
5608
|
-
)
|
|
5608
|
+
);
|
|
5609
5609
|
}
|
|
5610
5610
|
if (!hasScheme(importer)) {
|
|
5611
5611
|
throw new Error(
|
|
@@ -5613,7 +5613,7 @@ const applyImportMap = ({
|
|
|
5613
5613
|
importer,
|
|
5614
5614
|
specifier,
|
|
5615
5615
|
}),
|
|
5616
|
-
)
|
|
5616
|
+
);
|
|
5617
5617
|
}
|
|
5618
5618
|
}
|
|
5619
5619
|
|
|
@@ -5627,7 +5627,7 @@ const applyImportMap = ({
|
|
|
5627
5627
|
return (
|
|
5628
5628
|
scopeSpecifier === importer ||
|
|
5629
5629
|
specifierIsPrefixOf(scopeSpecifier, importer)
|
|
5630
|
-
)
|
|
5630
|
+
);
|
|
5631
5631
|
},
|
|
5632
5632
|
);
|
|
5633
5633
|
if (scopeSpecifierMatching) {
|
|
@@ -5639,7 +5639,7 @@ const applyImportMap = ({
|
|
|
5639
5639
|
onImportMapping,
|
|
5640
5640
|
);
|
|
5641
5641
|
if (mappingFromScopes !== null) {
|
|
5642
|
-
return mappingFromScopes
|
|
5642
|
+
return mappingFromScopes;
|
|
5643
5643
|
}
|
|
5644
5644
|
}
|
|
5645
5645
|
}
|
|
@@ -5653,15 +5653,15 @@ const applyImportMap = ({
|
|
|
5653
5653
|
onImportMapping,
|
|
5654
5654
|
);
|
|
5655
5655
|
if (mappingFromImports !== null) {
|
|
5656
|
-
return mappingFromImports
|
|
5656
|
+
return mappingFromImports;
|
|
5657
5657
|
}
|
|
5658
5658
|
}
|
|
5659
5659
|
|
|
5660
5660
|
if (specifierUrl) {
|
|
5661
|
-
return specifierUrl
|
|
5661
|
+
return specifierUrl;
|
|
5662
5662
|
}
|
|
5663
5663
|
|
|
5664
|
-
throw createBareSpecifierError({ specifier, importer })
|
|
5664
|
+
throw createBareSpecifierError({ specifier, importer });
|
|
5665
5665
|
};
|
|
5666
5666
|
|
|
5667
5667
|
const applyMappings = (
|
|
@@ -5685,7 +5685,7 @@ const applyMappings = (
|
|
|
5685
5685
|
before: specifierNormalized,
|
|
5686
5686
|
after: address,
|
|
5687
5687
|
});
|
|
5688
|
-
return address
|
|
5688
|
+
return address;
|
|
5689
5689
|
}
|
|
5690
5690
|
if (specifierIsPrefixOf(specifierCandidate, specifierNormalized)) {
|
|
5691
5691
|
const address = mappings[specifierCandidate];
|
|
@@ -5700,18 +5700,18 @@ const applyMappings = (
|
|
|
5700
5700
|
before: specifierNormalized,
|
|
5701
5701
|
after: addressFinal,
|
|
5702
5702
|
});
|
|
5703
|
-
return addressFinal
|
|
5703
|
+
return addressFinal;
|
|
5704
5704
|
}
|
|
5705
5705
|
}
|
|
5706
5706
|
|
|
5707
|
-
return null
|
|
5707
|
+
return null;
|
|
5708
5708
|
};
|
|
5709
5709
|
|
|
5710
5710
|
const specifierIsPrefixOf = (specifierHref, href) => {
|
|
5711
5711
|
return (
|
|
5712
5712
|
specifierHref[specifierHref.length - 1] === "/" &&
|
|
5713
5713
|
href.startsWith(specifierHref)
|
|
5714
|
-
)
|
|
5714
|
+
);
|
|
5715
5715
|
};
|
|
5716
5716
|
|
|
5717
5717
|
// https://github.com/systemjs/systemjs/blob/89391f92dfeac33919b0223bbf834a1f4eea5750/src/common.js#L136
|
|
@@ -5750,7 +5750,7 @@ const composeTwoImportMaps = (leftImportMap, rightImportMap) => {
|
|
|
5750
5750
|
importMap.scopes = { ...rightScopes };
|
|
5751
5751
|
}
|
|
5752
5752
|
|
|
5753
|
-
return importMap
|
|
5753
|
+
return importMap;
|
|
5754
5754
|
};
|
|
5755
5755
|
|
|
5756
5756
|
const composeTwoMappings = (leftMappings, rightMappings) => {
|
|
@@ -5759,11 +5759,11 @@ const composeTwoMappings = (leftMappings, rightMappings) => {
|
|
|
5759
5759
|
Object.keys(leftMappings).forEach((leftSpecifier) => {
|
|
5760
5760
|
if (objectHasKey(rightMappings, leftSpecifier)) {
|
|
5761
5761
|
// will be overidden
|
|
5762
|
-
return
|
|
5762
|
+
return;
|
|
5763
5763
|
}
|
|
5764
5764
|
const leftAddress = leftMappings[leftSpecifier];
|
|
5765
5765
|
const rightSpecifier = Object.keys(rightMappings).find((rightSpecifier) => {
|
|
5766
|
-
return compareAddressAndSpecifier(leftAddress, rightSpecifier)
|
|
5766
|
+
return compareAddressAndSpecifier(leftAddress, rightSpecifier);
|
|
5767
5767
|
});
|
|
5768
5768
|
mappings[leftSpecifier] = rightSpecifier
|
|
5769
5769
|
? rightMappings[rightSpecifier]
|
|
@@ -5774,7 +5774,7 @@ const composeTwoMappings = (leftMappings, rightMappings) => {
|
|
|
5774
5774
|
mappings[rightSpecifier] = rightMappings[rightSpecifier];
|
|
5775
5775
|
});
|
|
5776
5776
|
|
|
5777
|
-
return mappings
|
|
5777
|
+
return mappings;
|
|
5778
5778
|
};
|
|
5779
5779
|
|
|
5780
5780
|
const objectHasKey = (object, key) =>
|
|
@@ -5783,7 +5783,7 @@ const objectHasKey = (object, key) =>
|
|
|
5783
5783
|
const compareAddressAndSpecifier = (address, specifier) => {
|
|
5784
5784
|
const addressUrl = resolveUrl(address, "file:///");
|
|
5785
5785
|
const specifierUrl = resolveUrl(specifier, "file:///");
|
|
5786
|
-
return addressUrl === specifierUrl
|
|
5786
|
+
return addressUrl === specifierUrl;
|
|
5787
5787
|
};
|
|
5788
5788
|
|
|
5789
5789
|
const composeTwoScopes = (leftScopes, rightScopes, imports) => {
|
|
@@ -5793,14 +5793,14 @@ const composeTwoScopes = (leftScopes, rightScopes, imports) => {
|
|
|
5793
5793
|
if (objectHasKey(rightScopes, leftScopeKey)) {
|
|
5794
5794
|
// will be merged
|
|
5795
5795
|
scopes[leftScopeKey] = leftScopes[leftScopeKey];
|
|
5796
|
-
return
|
|
5796
|
+
return;
|
|
5797
5797
|
}
|
|
5798
5798
|
const topLevelSpecifier = Object.keys(imports).find(
|
|
5799
5799
|
(topLevelSpecifierCandidate) => {
|
|
5800
5800
|
return compareAddressAndSpecifier(
|
|
5801
5801
|
leftScopeKey,
|
|
5802
5802
|
topLevelSpecifierCandidate,
|
|
5803
|
-
)
|
|
5803
|
+
);
|
|
5804
5804
|
},
|
|
5805
5805
|
);
|
|
5806
5806
|
if (topLevelSpecifier) {
|
|
@@ -5823,7 +5823,7 @@ const composeTwoScopes = (leftScopes, rightScopes, imports) => {
|
|
|
5823
5823
|
}
|
|
5824
5824
|
});
|
|
5825
5825
|
|
|
5826
|
-
return scopes
|
|
5826
|
+
return scopes;
|
|
5827
5827
|
};
|
|
5828
5828
|
|
|
5829
5829
|
const sortImports = (imports) => {
|
|
@@ -5835,7 +5835,7 @@ const sortImports = (imports) => {
|
|
|
5835
5835
|
mappingsSorted[name] = imports[name];
|
|
5836
5836
|
});
|
|
5837
5837
|
|
|
5838
|
-
return mappingsSorted
|
|
5838
|
+
return mappingsSorted;
|
|
5839
5839
|
};
|
|
5840
5840
|
|
|
5841
5841
|
const sortScopes = (scopes) => {
|
|
@@ -5847,18 +5847,18 @@ const sortScopes = (scopes) => {
|
|
|
5847
5847
|
scopesSorted[scopeSpecifier] = sortImports(scopes[scopeSpecifier]);
|
|
5848
5848
|
});
|
|
5849
5849
|
|
|
5850
|
-
return scopesSorted
|
|
5850
|
+
return scopesSorted;
|
|
5851
5851
|
};
|
|
5852
5852
|
|
|
5853
5853
|
const compareLengthOrLocaleCompare = (a, b) => {
|
|
5854
|
-
return b.length - a.length || a.localeCompare(b)
|
|
5854
|
+
return b.length - a.length || a.localeCompare(b);
|
|
5855
5855
|
};
|
|
5856
5856
|
|
|
5857
5857
|
const normalizeImportMap = (importMap, baseUrl) => {
|
|
5858
5858
|
assertImportMap(importMap);
|
|
5859
5859
|
|
|
5860
5860
|
if (!isStringOrUrl(baseUrl)) {
|
|
5861
|
-
throw new TypeError(formulateBaseUrlMustBeStringOrUrl({ baseUrl }))
|
|
5861
|
+
throw new TypeError(formulateBaseUrlMustBeStringOrUrl({ baseUrl }));
|
|
5862
5862
|
}
|
|
5863
5863
|
|
|
5864
5864
|
const { imports, scopes } = importMap;
|
|
@@ -5866,19 +5866,19 @@ const normalizeImportMap = (importMap, baseUrl) => {
|
|
|
5866
5866
|
return {
|
|
5867
5867
|
imports: imports ? normalizeMappings(imports, baseUrl) : undefined,
|
|
5868
5868
|
scopes: scopes ? normalizeScopes(scopes, baseUrl) : undefined,
|
|
5869
|
-
}
|
|
5869
|
+
};
|
|
5870
5870
|
};
|
|
5871
5871
|
|
|
5872
5872
|
const isStringOrUrl = (value) => {
|
|
5873
5873
|
if (typeof value === "string") {
|
|
5874
|
-
return true
|
|
5874
|
+
return true;
|
|
5875
5875
|
}
|
|
5876
5876
|
|
|
5877
5877
|
if (typeof URL === "function" && value instanceof URL) {
|
|
5878
|
-
return true
|
|
5878
|
+
return true;
|
|
5879
5879
|
}
|
|
5880
5880
|
|
|
5881
|
-
return false
|
|
5881
|
+
return false;
|
|
5882
5882
|
};
|
|
5883
5883
|
|
|
5884
5884
|
const normalizeMappings = (mappings, baseUrl) => {
|
|
@@ -5894,7 +5894,7 @@ const normalizeMappings = (mappings, baseUrl) => {
|
|
|
5894
5894
|
specifier,
|
|
5895
5895
|
}),
|
|
5896
5896
|
);
|
|
5897
|
-
return
|
|
5897
|
+
return;
|
|
5898
5898
|
}
|
|
5899
5899
|
|
|
5900
5900
|
const specifierResolved = resolveSpecifier(specifier, baseUrl) || specifier;
|
|
@@ -5908,7 +5908,7 @@ const normalizeMappings = (mappings, baseUrl) => {
|
|
|
5908
5908
|
specifier,
|
|
5909
5909
|
}),
|
|
5910
5910
|
);
|
|
5911
|
-
return
|
|
5911
|
+
return;
|
|
5912
5912
|
}
|
|
5913
5913
|
|
|
5914
5914
|
if (specifier.endsWith("/") && !addressUrl.endsWith("/")) {
|
|
@@ -5918,12 +5918,12 @@ const normalizeMappings = (mappings, baseUrl) => {
|
|
|
5918
5918
|
specifier,
|
|
5919
5919
|
}),
|
|
5920
5920
|
);
|
|
5921
|
-
return
|
|
5921
|
+
return;
|
|
5922
5922
|
}
|
|
5923
5923
|
mappingsNormalized[specifierResolved] = addressUrl;
|
|
5924
5924
|
});
|
|
5925
5925
|
|
|
5926
|
-
return sortImports(mappingsNormalized)
|
|
5926
|
+
return sortImports(mappingsNormalized);
|
|
5927
5927
|
};
|
|
5928
5928
|
|
|
5929
5929
|
const normalizeScopes = (scopes, baseUrl) => {
|
|
@@ -5939,13 +5939,13 @@ const normalizeScopes = (scopes, baseUrl) => {
|
|
|
5939
5939
|
baseUrl,
|
|
5940
5940
|
}),
|
|
5941
5941
|
);
|
|
5942
|
-
return
|
|
5942
|
+
return;
|
|
5943
5943
|
}
|
|
5944
5944
|
const scopeValueNormalized = normalizeMappings(scopeMappings, baseUrl);
|
|
5945
5945
|
scopesNormalized[scopeUrl] = scopeValueNormalized;
|
|
5946
5946
|
});
|
|
5947
5947
|
|
|
5948
|
-
return sortScopes(scopesNormalized)
|
|
5948
|
+
return sortScopes(scopesNormalized);
|
|
5949
5949
|
};
|
|
5950
5950
|
|
|
5951
5951
|
const formulateBaseUrlMustBeStringOrUrl = ({
|
|
@@ -6003,9 +6003,9 @@ const pathnameToExtension = (pathname) => {
|
|
|
6003
6003
|
}
|
|
6004
6004
|
|
|
6005
6005
|
const dotLastIndex = pathname.lastIndexOf(".");
|
|
6006
|
-
if (dotLastIndex === -1) return ""
|
|
6006
|
+
if (dotLastIndex === -1) return "";
|
|
6007
6007
|
// if (dotLastIndex === pathname.length - 1) return ""
|
|
6008
|
-
return pathname.slice(dotLastIndex)
|
|
6008
|
+
return pathname.slice(dotLastIndex);
|
|
6009
6009
|
};
|
|
6010
6010
|
|
|
6011
6011
|
const resolveImport = ({
|
|
@@ -6033,20 +6033,20 @@ const resolveImport = ({
|
|
|
6033
6033
|
url = applyDefaultExtension({ url, importer, defaultExtension });
|
|
6034
6034
|
}
|
|
6035
6035
|
|
|
6036
|
-
return url
|
|
6036
|
+
return url;
|
|
6037
6037
|
};
|
|
6038
6038
|
|
|
6039
6039
|
const applyDefaultExtension = ({ url, importer, defaultExtension }) => {
|
|
6040
6040
|
if (urlToPathname(url).endsWith("/")) {
|
|
6041
|
-
return url
|
|
6041
|
+
return url;
|
|
6042
6042
|
}
|
|
6043
6043
|
|
|
6044
6044
|
if (typeof defaultExtension === "string") {
|
|
6045
6045
|
const extension = pathnameToExtension(url);
|
|
6046
6046
|
if (extension === "") {
|
|
6047
|
-
return `${url}${defaultExtension}
|
|
6047
|
+
return `${url}${defaultExtension}`;
|
|
6048
6048
|
}
|
|
6049
|
-
return url
|
|
6049
|
+
return url;
|
|
6050
6050
|
}
|
|
6051
6051
|
|
|
6052
6052
|
if (defaultExtension === true) {
|
|
@@ -6054,11 +6054,11 @@ const applyDefaultExtension = ({ url, importer, defaultExtension }) => {
|
|
|
6054
6054
|
if (extension === "" && importer) {
|
|
6055
6055
|
const importerPathname = urlToPathname(importer);
|
|
6056
6056
|
const importerExtension = pathnameToExtension(importerPathname);
|
|
6057
|
-
return `${url}${importerExtension}
|
|
6057
|
+
return `${url}${importerExtension}`;
|
|
6058
6058
|
}
|
|
6059
6059
|
}
|
|
6060
6060
|
|
|
6061
|
-
return url
|
|
6061
|
+
return url;
|
|
6062
6062
|
};
|
|
6063
6063
|
|
|
6064
6064
|
const isEscaped = (i, string) => {
|
|
@@ -5299,13 +5299,32 @@ const createNodeEsmResolver = ({
|
|
|
5299
5299
|
return null; // let it to jsenv_web_resolution
|
|
5300
5300
|
}
|
|
5301
5301
|
const { specifier } = reference;
|
|
5302
|
-
|
|
5303
|
-
|
|
5302
|
+
// specifiers like "#something" have a special meaning for Node.js
|
|
5303
|
+
// but can also be used in .css and .html files for example and should not be modified
|
|
5304
|
+
// by node esm resolution
|
|
5305
|
+
const webResolutionFallback =
|
|
5306
|
+
ownerUrlInfo.type !== "js_module" ||
|
|
5307
|
+
reference.type === "sourcemap_comment";
|
|
5308
|
+
const conditions = buildPackageConditions(specifier, parentUrl, {
|
|
5309
|
+
webResolutionFallback,
|
|
5310
|
+
});
|
|
5311
|
+
let resolution;
|
|
5312
|
+
const nodeEsmResolutionParams = {
|
|
5304
5313
|
conditions,
|
|
5305
5314
|
parentUrl,
|
|
5306
5315
|
specifier,
|
|
5307
5316
|
preservesSymlink,
|
|
5308
|
-
}
|
|
5317
|
+
};
|
|
5318
|
+
if (webResolutionFallback) {
|
|
5319
|
+
try {
|
|
5320
|
+
resolution = applyNodeEsmResolution(nodeEsmResolutionParams);
|
|
5321
|
+
} catch {
|
|
5322
|
+
return null; // delegate to web_resolution plugin
|
|
5323
|
+
}
|
|
5324
|
+
} else {
|
|
5325
|
+
resolution = applyNodeEsmResolution(nodeEsmResolutionParams);
|
|
5326
|
+
}
|
|
5327
|
+
const { url, type, isMain, packageDirectoryUrl } = resolution;
|
|
5309
5328
|
// try to give a more meaningful filename after build
|
|
5310
5329
|
if (isMain && packageDirectoryUrl) {
|
|
5311
5330
|
const basename = urlToBasename(url);
|
|
@@ -5374,12 +5393,26 @@ const createBuildPackageConditions = (
|
|
|
5374
5393
|
const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
5375
5394
|
// https://nodejs.org/api/esm.html#resolver-algorithm-specification
|
|
5376
5395
|
const processArgConditions = readCustomConditionsFromProcessArgs();
|
|
5377
|
-
const devResolver = (specifier, importer) => {
|
|
5396
|
+
const devResolver = (specifier, importer, { webResolutionFallback }) => {
|
|
5378
5397
|
if (isBareSpecifier(specifier)) {
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5398
|
+
let url;
|
|
5399
|
+
if (webResolutionFallback) {
|
|
5400
|
+
try {
|
|
5401
|
+
const resolution = applyNodeEsmResolution({
|
|
5402
|
+
specifier,
|
|
5403
|
+
parentUrl: importer,
|
|
5404
|
+
});
|
|
5405
|
+
url = resolution.url;
|
|
5406
|
+
} catch {
|
|
5407
|
+
url = new URL(specifier, importer).href;
|
|
5408
|
+
}
|
|
5409
|
+
} else {
|
|
5410
|
+
const resolution = applyNodeEsmResolution({
|
|
5411
|
+
specifier,
|
|
5412
|
+
parentUrl: importer,
|
|
5413
|
+
});
|
|
5414
|
+
url = resolution.url;
|
|
5415
|
+
}
|
|
5383
5416
|
return !url.includes("/node_modules/");
|
|
5384
5417
|
}
|
|
5385
5418
|
return !importer.includes("/node_modules/");
|
|
@@ -5483,12 +5516,12 @@ const createBuildPackageConditions = (
|
|
|
5483
5516
|
}
|
|
5484
5517
|
|
|
5485
5518
|
const conditionCandidateArray = Object.keys(conditionResolvers);
|
|
5486
|
-
return (specifier, importer) => {
|
|
5519
|
+
return (specifier, importer, params) => {
|
|
5487
5520
|
const conditions = [];
|
|
5488
5521
|
for (const conditionCandidate of conditionCandidateArray) {
|
|
5489
5522
|
const conditionResolver = conditionResolvers[conditionCandidate];
|
|
5490
5523
|
if (typeof conditionResolver === "function") {
|
|
5491
|
-
if (conditionResolver(specifier, importer)) {
|
|
5524
|
+
if (conditionResolver(specifier, importer, params)) {
|
|
5492
5525
|
conditions.push(conditionCandidate);
|
|
5493
5526
|
}
|
|
5494
5527
|
} else if (conditionResolver) {
|
|
@@ -5612,8 +5645,7 @@ const jsenvPluginNodeEsmResolution = (
|
|
|
5612
5645
|
if (config === true) {
|
|
5613
5646
|
resolver = nodeEsmResolverDefault;
|
|
5614
5647
|
} else if (config === false) {
|
|
5615
|
-
|
|
5616
|
-
continue;
|
|
5648
|
+
resolver = null;
|
|
5617
5649
|
} else if (typeof config === "object") {
|
|
5618
5650
|
resolver = resolverFromObject(config, { kitchenContext, urlType });
|
|
5619
5651
|
} else {
|
|
@@ -5628,6 +5660,9 @@ const jsenvPluginNodeEsmResolution = (
|
|
|
5628
5660
|
resolverMap.set(urlType, resolver);
|
|
5629
5661
|
}
|
|
5630
5662
|
}
|
|
5663
|
+
if (!anyTypeResolver) {
|
|
5664
|
+
anyTypeResolver = nodeEsmResolverDefault;
|
|
5665
|
+
}
|
|
5631
5666
|
|
|
5632
5667
|
if (!resolverMap.has("js_module")) {
|
|
5633
5668
|
resolverMap.set("js_module", nodeEsmResolverDefault);
|
|
@@ -5653,8 +5688,11 @@ const jsenvPluginNodeEsmResolution = (
|
|
|
5653
5688
|
}
|
|
5654
5689
|
const urlType = urlTypeFromReference(reference);
|
|
5655
5690
|
const resolver = resolverMap.get(urlType);
|
|
5656
|
-
if (resolver) {
|
|
5657
|
-
|
|
5691
|
+
if (resolver !== undefined) {
|
|
5692
|
+
if (typeof resolver === "function") {
|
|
5693
|
+
return resolver(reference);
|
|
5694
|
+
}
|
|
5695
|
+
return resolver;
|
|
5658
5696
|
}
|
|
5659
5697
|
if (anyTypeResolver) {
|
|
5660
5698
|
return anyTypeResolver(reference);
|