@triflare/fx 2.3.0-alpha.1 → 2.3.0-alpha.3

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/src/vendor.js CHANGED
@@ -116,6 +116,19 @@ function looksLikeLockEntry(value) {
116
116
  );
117
117
  }
118
118
 
119
+ /** Normalize marketplace provenance recorded in the lock. */
120
+ function normalizeMarketplaceLock(value) {
121
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
122
+ const name = value.package ?? value.spec;
123
+ if (typeof name !== "string" || typeof value.version !== "string")
124
+ return null;
125
+ return {
126
+ package: name,
127
+ version: value.version,
128
+ ref: typeof value.ref === "string" ? value.ref : "latest",
129
+ };
130
+ }
131
+
119
132
  /** Normalize legacy lock-entry spellings into the current shape. */
120
133
  function normalizeLockEntry(name, raw) {
121
134
  const file = raw.file ?? raw.vendored ?? raw.vendorFile ?? raw.vendor_path;
@@ -137,6 +150,7 @@ function normalizeLockEntry(name, raw) {
137
150
  volatile: raw.volatile != null ? Boolean(raw.volatile) : undefined,
138
151
  etag: raw.etag ?? null,
139
152
  lastModified: raw.lastModified ?? raw.last_modified ?? null,
153
+ marketplace: normalizeMarketplaceLock(raw.marketplace),
140
154
  };
141
155
  }
142
156
 
@@ -205,6 +219,8 @@ export function writeLock(configDir, lock) {
205
219
  };
206
220
  if (entry.etag) clean.etag = entry.etag;
207
221
  if (entry.lastModified) clean.lastModified = entry.lastModified;
222
+ const marketplace = normalizeMarketplaceLock(entry.marketplace);
223
+ if (marketplace) clean.marketplace = marketplace;
208
224
  out.extensions[name] = clean;
209
225
  }
210
226
  writeFileAtomic(file, `${JSON.stringify(out, null, 2)}\n`);
@@ -482,7 +498,7 @@ function writeVendorFile(
482
498
  function lockEntryForInstall(name, entry, file, buffer, extra = {}) {
483
499
  return {
484
500
  name,
485
- source: entry.source,
501
+ source: extra.source ?? entry.source,
486
502
  file: posix(file),
487
503
  sha256: sha256(buffer),
488
504
  fetched: new Date().toISOString(),
@@ -491,6 +507,7 @@ function lockEntryForInstall(name, entry, file, buffer, extra = {}) {
491
507
  volatile: Boolean(entry.volatile),
492
508
  etag: extra.etag ?? null,
493
509
  lastModified: extra.lastModified ?? null,
510
+ marketplace: normalizeMarketplaceLock(extra.marketplace),
494
511
  };
495
512
  }
496
513
 
@@ -507,6 +524,8 @@ function lockEntryForInstall(name, entry, file, buffer, extra = {}) {
507
524
  * @param {typeof fetch} [options.fetchImpl]
508
525
  * @param {boolean} [options.unsandboxed]
509
526
  * @param {boolean} [options.volatile]
527
+ * @param {{buffer: Buffer, etag?: string|null, lastModified?: string|null}} [options.prefetched]
528
+ * @param {{package: string, version: string, ref: string}} [options.marketplace]
510
529
  * @returns {Promise<{entry: object, lockEntry: object, file: string}>}
511
530
  */
512
531
  export async function installVendorEntry({
@@ -519,6 +538,8 @@ export async function installVendorEntry({
519
538
  fetchImpl,
520
539
  unsandboxed,
521
540
  volatile,
541
+ prefetched,
542
+ marketplace,
522
543
  }) {
523
544
  const dir = vendorDir
524
545
  ? path.resolve(configDir, vendorDir)
@@ -533,13 +554,21 @@ export async function installVendorEntry({
533
554
  volatile == null ? entry.volatile || undefined : Boolean(volatile);
534
555
 
535
556
  let buffer;
536
- let extra = {};
537
- if (entry.remote) {
557
+ let extra;
558
+ if (prefetched) {
559
+ buffer = prefetched.buffer;
560
+ extra = {
561
+ etag: prefetched.etag,
562
+ lastModified: prefetched.lastModified,
563
+ marketplace,
564
+ };
565
+ } else if (entry.remote) {
538
566
  const read = await readEntrySource(entry, configDir, fetchImpl);
539
567
  buffer = read.buffer;
540
- extra = read.extra;
568
+ extra = { ...read.extra, marketplace };
541
569
  } else {
542
570
  buffer = readLocalSource(entry, configDir).buffer;
571
+ extra = { marketplace };
543
572
  }
544
573
  const stored = storedContent(entry, buffer);
545
574
 
@@ -616,6 +645,7 @@ export async function installVendor({ configDir, config, fetchImpl } = {}) {
616
645
  entry,
617
646
  file,
618
647
  stored,
648
+ { marketplace: previous?.marketplace },
619
649
  );
620
650
  results.push({
621
651
  name: entry.name,
@@ -653,6 +683,7 @@ export async function installVendor({ configDir, config, fetchImpl } = {}) {
653
683
  entry,
654
684
  file,
655
685
  buffer,
686
+ { marketplace: previous?.marketplace },
656
687
  );
657
688
  }
658
689
  results.push({ name: entry.name, file, status: "verified" });
@@ -682,7 +713,7 @@ export async function installVendor({ configDir, config, fetchImpl } = {}) {
682
713
  entry,
683
714
  file,
684
715
  read.buffer,
685
- read.extra,
716
+ { ...read.extra, marketplace: previous?.marketplace },
686
717
  );
687
718
  results.push({ name: entry.name, file, status: "fetched" });
688
719
  }
@@ -702,13 +733,19 @@ export async function installVendor({ configDir, config, fetchImpl } = {}) {
702
733
  /**
703
734
  * Re-fetch remote entries (or re-copy local ones) and update the lock.
704
735
  * Returns the changed entries and a textual diff for each.
736
+ *
737
+ * `resolveEntry` may return a freshly resolved source for an entry (used by
738
+ * `vendor update` to re-resolve Marketplace dist-tags). When its download URL
739
+ * differs from `fx.yml`, the config is updated too.
705
740
  */
706
741
  export async function updateVendor({
742
+ configPath,
707
743
  configDir,
708
744
  config,
709
745
  name,
710
746
  fetchImpl,
711
747
  write = true,
748
+ resolveEntry,
712
749
  } = {}) {
713
750
  const entries = config?.vendor || [];
714
751
  const dirName = config?.vendorDir || DEFAULT_VENDOR_DIR;
@@ -734,9 +771,23 @@ export async function updateVendor({
734
771
  const existed = fs.existsSync(absolute);
735
772
  const before = existed ? fs.readFileSync(absolute) : Buffer.alloc(0);
736
773
 
774
+ const resolved =
775
+ typeof resolveEntry === "function"
776
+ ? await resolveEntry(entry, lockEntry)
777
+ : null;
737
778
  let after;
738
779
  let extra = {};
739
- if (entry.local || entry.data) {
780
+ let source = entry.source;
781
+ let marketplace =
782
+ entry.source === lockEntry?.source
783
+ ? (lockEntry?.marketplace ?? null)
784
+ : null;
785
+ if (resolved) {
786
+ after = resolved.buffer;
787
+ extra = { etag: resolved.etag, lastModified: resolved.lastModified };
788
+ source = resolved.downloadUrl;
789
+ marketplace = resolved.marketplace;
790
+ } else if (entry.local || entry.data) {
740
791
  after = storedContent(entry, readLocalSource(entry, configDir).buffer);
741
792
  } else {
742
793
  const read = await readEntrySource(entry, configDir, fetchImpl);
@@ -745,12 +796,19 @@ export async function updateVendor({
745
796
  }
746
797
 
747
798
  const different = !after.equals(before);
748
- const sourceChanged = lockEntry?.source !== entry.source;
799
+ const versionChanged =
800
+ (marketplace?.version ?? null) !==
801
+ (lockEntry?.marketplace?.version ?? null);
802
+ const sourceChanged =
803
+ lockEntry?.source !== source || entry.source !== source || versionChanged;
749
804
  results.push({
750
805
  name: entry.name,
751
806
  file,
752
807
  changed: different,
753
808
  sourceChanged,
809
+ versionChanged,
810
+ version: marketplace?.version ?? null,
811
+ previousVersion: lockEntry?.marketplace?.version ?? null,
754
812
  diff: different
755
813
  ? formatDiff(before.toString("utf8"), after.toString("utf8"), file)
756
814
  : "",
@@ -765,6 +823,8 @@ export async function updateVendor({
765
823
  before,
766
824
  after,
767
825
  extra,
826
+ source,
827
+ marketplace,
768
828
  different,
769
829
  lockEntry,
770
830
  });
@@ -772,6 +832,9 @@ export async function updateVendor({
772
832
 
773
833
  if (write && pending.length > 0) {
774
834
  const backups = new Map();
835
+ const configBefore = configPath
836
+ ? fs.readFileSync(configPath, "utf8")
837
+ : null;
775
838
  try {
776
839
  for (const item of pending) {
777
840
  if (!item.different) continue;
@@ -783,13 +846,29 @@ export async function updateVendor({
783
846
  allowOverwrite: Boolean(item.lockEntry),
784
847
  });
785
848
  }
849
+ const configChanges = pending.filter(
850
+ (item) => item.source !== item.entry.source,
851
+ );
852
+ if (configChanges.length > 0 && !configPath)
853
+ throw new VendorError(
854
+ `Cannot update ${configChanges[0].entry.name}: no config file was provided`,
855
+ );
856
+ for (const item of configChanges)
857
+ addVendorEntry(configPath, item.entry.name, item.source, {
858
+ unsandboxed: item.entry.unsandboxed,
859
+ volatile: item.entry.volatile,
860
+ });
786
861
  for (const item of pending)
787
862
  lock.extensions[item.entry.name] = lockEntryForInstall(
788
863
  item.entry.name,
789
864
  item.entry,
790
865
  item.file,
791
866
  item.after,
792
- item.extra,
867
+ {
868
+ ...item.extra,
869
+ source: item.source,
870
+ marketplace: item.marketplace,
871
+ },
793
872
  );
794
873
  writeLock(configDir, lock);
795
874
  } catch (error) {
@@ -797,11 +876,12 @@ export async function updateVendor({
797
876
  if (backup.existed) fs.writeFileSync(absolute, backup.buffer);
798
877
  else fs.rmSync(absolute, { force: true });
799
878
  }
879
+ if (configBefore != null) fs.writeFileSync(configPath, configBefore);
800
880
  throw error;
801
881
  }
802
882
  }
803
883
 
804
- return { entries: results, warnings, changed, lock };
884
+ return { entries: results, warnings, changed, updated: pending.length, lock };
805
885
  }
806
886
 
807
887
  /**
@@ -894,8 +974,16 @@ export function verifyVendor({ configDir, config } = {}) {
894
974
  /**
895
975
  * Compare upstream sources with `fx.lock` without writing anything.
896
976
  * ETag/Last-Modified are sent when the lock has them.
977
+ *
978
+ * `resolveEntry` may return a freshly resolved source (used by
979
+ * `vendor outdated` to compare Marketplace dist-tags).
897
980
  */
898
- export async function outdatedVendor({ configDir, config, fetchImpl } = {}) {
981
+ export async function outdatedVendor({
982
+ configDir,
983
+ config,
984
+ fetchImpl,
985
+ resolveEntry,
986
+ } = {}) {
899
987
  const entries = config?.vendor || [];
900
988
  const dirName = config?.vendorDir || DEFAULT_VENDOR_DIR;
901
989
  const vendorDir = path.resolve(configDir, dirName);
@@ -929,6 +1017,29 @@ export async function outdatedVendor({ configDir, config, fetchImpl } = {}) {
929
1017
  }
930
1018
 
931
1019
  try {
1020
+ const resolved =
1021
+ typeof resolveEntry === "function"
1022
+ ? await resolveEntry(entry, lockEntry)
1023
+ : null;
1024
+ if (resolved) {
1025
+ const sameVersion =
1026
+ lockEntry?.marketplace?.version === resolved.marketplace?.version;
1027
+ results.push({
1028
+ name: entry.name,
1029
+ file,
1030
+ status:
1031
+ sameVersion &&
1032
+ entry.source === lockEntry?.source &&
1033
+ lockEntry?.source === resolved.downloadUrl &&
1034
+ lockEntry?.sha256 === resolved.sha256
1035
+ ? "current"
1036
+ : "outdated",
1037
+ version: resolved.marketplace?.version ?? resolved.version ?? null,
1038
+ previousVersion: lockEntry?.marketplace?.version ?? null,
1039
+ });
1040
+ continue;
1041
+ }
1042
+
932
1043
  const sameSource = lockEntry?.source === entry.source;
933
1044
  const fetched = await fetchVendorSource(entry.source, {
934
1045
  fetchImpl,
@@ -1051,6 +1162,7 @@ export async function loadVendorExtensions({
1051
1162
  entry,
1052
1163
  file,
1053
1164
  stored,
1165
+ { marketplace: lockEntry?.marketplace },
1054
1166
  );
1055
1167
  lockChanged.value = true;
1056
1168
  }
@@ -1081,6 +1193,7 @@ export async function loadVendorExtensions({
1081
1193
  entry,
1082
1194
  file,
1083
1195
  buffer,
1196
+ { marketplace: lockEntry?.marketplace },
1084
1197
  );
1085
1198
  lockChanged.value = true;
1086
1199
  }
@@ -1108,7 +1221,7 @@ export async function loadVendorExtensions({
1108
1221
  entry,
1109
1222
  file,
1110
1223
  buffer,
1111
- read.extra,
1224
+ { ...read.extra, marketplace: lockEntry?.marketplace },
1112
1225
  );
1113
1226
  lockChanged.value = true;
1114
1227
  }
@@ -2,5 +2,5 @@
2
2
  "name": "@penguinmod/packager",
3
3
  "version": "1.9.2",
4
4
  "commit": "53f868b85ec21d2edab9ce00fd2d709da93da6d6",
5
- "builtAt": "2026-11-26T05:48:41.391Z"
5
+ "builtAt": "2026-11-26T20:37:42.083Z"
6
6
  }
@@ -3,5 +3,5 @@
3
3
  "version": "0.2.0",
4
4
  "commit": "3822f284c8cda2c3a0a5c6dd928221dd9ff2cee1",
5
5
  "inputHash": "bb8f99fcce9f4ecdc563f11df5a0510dcc94c25d256c6931c7f1f113e0a1998b",
6
- "builtAt": "2026-11-26T05:49:36.222Z"
6
+ "builtAt": "2026-11-26T20:38:40.469Z"
7
7
  }