evolit 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evolit",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A convention-driven application framework for LitSX and web components.",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@4.10.3",
@@ -41,6 +41,8 @@ const DEVELOPMENT_SHARED_VENDOR_SPECIFIERS = [
41
41
  const browserSpecifierFilePathCache = new Map();
42
42
  const packageRootCache = new Map();
43
43
  const sharedRuntimeBuildCache = new Map();
44
+ const sharedRuntimeBuildQueues = new Map();
45
+ const sharedVendorSpecifierRegistry = new Map();
44
46
  const clientVendorSpecifierCache = new Map();
45
47
  const clientModuleMetadataCache = new Map();
46
48
 
@@ -50,6 +52,8 @@ export function resetDevelopmentAssetCaches(projectRoot) {
50
52
 
51
53
  for (const cache of [
52
54
  sharedRuntimeBuildCache,
55
+ sharedRuntimeBuildQueues,
56
+ sharedVendorSpecifierRegistry,
53
57
  clientVendorSpecifierCache,
54
58
  clientModuleMetadataCache,
55
59
  ]) {
@@ -469,6 +473,58 @@ export async function collectSharedVendorSpecifiers(
469
473
  ])].sort();
470
474
  }
471
475
 
476
+ async function groupDevelopmentVendorSpecifiers(projectRoot, additionalEntrySpecifiers) {
477
+ const baseSpecifiers = new Set([
478
+ ...SHARED_VENDOR_SPECIFIERS,
479
+ ...DEVELOPMENT_SHARED_VENDOR_SPECIFIERS,
480
+ ]);
481
+ const basePackageNames = new Set(
482
+ [...baseSpecifiers]
483
+ .map((specifier) => parsePackageSpecifier(specifier)?.packageName)
484
+ .filter(Boolean),
485
+ );
486
+ const packageGroups = new Map();
487
+
488
+ for (const specifier of additionalEntrySpecifiers) {
489
+ if (baseSpecifiers.has(specifier)) continue;
490
+ const parsedSpecifier = parsePackageSpecifier(specifier);
491
+ if (!parsedSpecifier) continue;
492
+ if (basePackageNames.has(parsedSpecifier.packageName)) {
493
+ baseSpecifiers.add(specifier);
494
+ continue;
495
+ }
496
+
497
+ const { packageRoot, packageJson } = await resolvePackageRoot(parsedSpecifier.packageName, {
498
+ projectRoot,
499
+ });
500
+ const realPackageRoot = await fs.realpath(packageRoot);
501
+ let group = packageGroups.get(realPackageRoot);
502
+ if (!group) {
503
+ const portablePackageRoot = path.relative(projectRoot, realPackageRoot)
504
+ .split(path.sep)
505
+ .join("/");
506
+ const groupIdentity = [
507
+ parsedSpecifier.packageName,
508
+ packageJson.version ?? "0.0.0",
509
+ portablePackageRoot,
510
+ ].join("\0");
511
+ group = {
512
+ vendorGroup: `vendor-${crypto.createHash("sha1").update(groupIdentity).digest("hex").slice(0, 10)}`,
513
+ specifiers: [],
514
+ };
515
+ packageGroups.set(realPackageRoot, group);
516
+ }
517
+ group.specifiers.push(specifier);
518
+ }
519
+
520
+ return {
521
+ baseSpecifiers: [...baseSpecifiers].sort(),
522
+ packageGroups: [...packageGroups.values()]
523
+ .map((group) => ({ ...group, specifiers: [...new Set(group.specifiers)].sort() }))
524
+ .sort((left, right) => left.vendorGroup.localeCompare(right.vendorGroup)),
525
+ };
526
+ }
527
+
472
528
  async function createSharedRuntimeInputEntries(projectRoot, entriesRoot, specifiers) {
473
529
  await fs.rm(entriesRoot, { recursive: true, force: true });
474
530
  await ensureDirectory(entriesRoot);
@@ -662,28 +718,35 @@ export async function buildSharedVendorRuntime(
662
718
  mode = "development",
663
719
  options = {},
664
720
  ) {
665
- const additionalEntrySpecifiers = [...new Set(
721
+ let additionalEntrySpecifiers = [...new Set(
666
722
  Array.isArray(options.additionalEntrySpecifiers)
667
723
  ? options.additionalEntrySpecifiers.filter((specifier) => isBareSpecifier(specifier))
668
724
  : [],
669
725
  )].sort();
726
+ if (!options.vendorGroup) {
727
+ const registryKey = `${path.resolve(projectRoot)}::${mode}::vendors`;
728
+ const knownSpecifiers = sharedVendorSpecifierRegistry.get(registryKey) ?? new Set();
729
+ additionalEntrySpecifiers.forEach((specifier) => knownSpecifiers.add(specifier));
730
+ sharedVendorSpecifierRegistry.set(registryKey, knownSpecifiers);
731
+ additionalEntrySpecifiers = [...knownSpecifiers].sort();
732
+ }
670
733
  if (mode === "development" && !options.vendorGroup) {
734
+ const developmentGroups = await groupDevelopmentVendorSpecifiers(
735
+ projectRoot,
736
+ additionalEntrySpecifiers,
737
+ );
671
738
  const baseRuntime = await buildSharedVendorRuntime(projectRoot, mode, {
672
739
  ...options,
673
- additionalEntrySpecifiers: [],
740
+ additionalEntrySpecifiers: developmentGroups.baseSpecifiers,
674
741
  vendorGroup: "base",
675
- includeBase: true,
742
+ includeBase: false,
676
743
  });
677
744
  const additionalRuntimes = await Promise.all(
678
- additionalEntrySpecifiers
679
- .filter((specifier) => ![
680
- ...SHARED_VENDOR_SPECIFIERS,
681
- ...DEVELOPMENT_SHARED_VENDOR_SPECIFIERS,
682
- ].includes(specifier))
683
- .map((specifier) => buildSharedVendorRuntime(projectRoot, mode, {
745
+ developmentGroups.packageGroups
746
+ .map((group) => buildSharedVendorRuntime(projectRoot, mode, {
684
747
  ...options,
685
- additionalEntrySpecifiers: [specifier],
686
- vendorGroup: `vendor-${crypto.createHash("sha1").update(specifier).digest("hex").slice(0, 10)}`,
748
+ additionalEntrySpecifiers: group.specifiers,
749
+ vendorGroup: group.vendorGroup,
687
750
  includeBase: false,
688
751
  })),
689
752
  );
@@ -703,7 +766,9 @@ export async function buildSharedVendorRuntime(
703
766
  return sharedRuntimeBuildCache.get(cacheKey);
704
767
  }
705
768
 
706
- const pendingBuild = (async () => {
769
+ const queueKey = `${path.resolve(projectRoot)}::${mode}::${vendorGroup ?? "all"}`;
770
+ const previousBuild = sharedRuntimeBuildQueues.get(queueKey) ?? Promise.resolve();
771
+ const pendingBuild = previousBuild.catch(() => {}).then(async () => {
707
772
  const sharedRootBase = getSharedOutputRoot(projectRoot, mode);
708
773
  const sharedRoot = vendorGroup ? path.join(sharedRootBase, vendorGroup) : sharedRootBase;
709
774
  const entriesRoot = path.join(
@@ -794,7 +859,13 @@ export async function buildSharedVendorRuntime(
794
859
  } finally {
795
860
  await bundle.close();
796
861
  }
797
- })();
862
+ });
863
+ sharedRuntimeBuildQueues.set(queueKey, pendingBuild);
864
+ void pendingBuild.finally(() => {
865
+ if (sharedRuntimeBuildQueues.get(queueKey) === pendingBuild) {
866
+ sharedRuntimeBuildQueues.delete(queueKey);
867
+ }
868
+ }).catch(() => {});
798
869
 
799
870
  sharedRuntimeBuildCache.set(cacheKey, pendingBuild);
800
871