zen-fs-config 0.3.13 → 0.3.14

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/index.js CHANGED
@@ -422,38 +422,44 @@ registerBackend("GitHub", async (options) => {
422
422
  });
423
423
  registerBackend("Gitee", async (options) => {
424
424
  const zenGitee = await import("zen-fs-gitee");
425
- const { GiteeAPI } = await import("zen-fs-gitee/dist/gitee-api.js");
426
- const originalGetTree = GiteeAPI.prototype.getTree;
427
- GiteeAPI.prototype.getTree = async function(recursive = true) {
425
+ const { GiteeFS } = zenGitee;
426
+ const origInit = GiteeFS.prototype.init;
427
+ const patched = /* @__PURE__ */ new WeakSet();
428
+ GiteeFS.prototype.init = async function() {
429
+ let firstErr;
428
430
  try {
429
- return await originalGetTree.call(this, recursive);
431
+ return await origInit.call(this);
430
432
  } catch (err) {
431
433
  if (!err.message?.includes("404") && !err.message?.includes("Tree not found")) {
432
434
  throw err;
433
435
  }
436
+ firstErr = err;
434
437
  }
435
- console.log(`[Gitee] getTree failed with branch="${this.branch}", resolving to SHA...`);
436
- const baseUrl = this.baseUrl || "https://gitee.com/api/v5";
437
- const sep = "?";
438
- const auth = `access_token=${this.token}`;
439
- const branchUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/branches/${this.branch}${sep}${auth}`;
438
+ if (patched.has(this)) throw firstErr;
439
+ patched.add(this);
440
+ console.log(`[Gitee] init failed with branch="${this.api.branch}", resolving to SHA...`);
441
+ const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
442
+ const auth = `access_token=${this.api.token}`;
443
+ const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
440
444
  const branchRes = await fetch(branchUrl);
441
- if (!branchRes.ok) throw new Error(`Gitee: branch "${this.branch}" not found (${branchRes.status})`);
445
+ if (!branchRes.ok) throw new Error(`Gitee: branch "${this.api.branch}" not found (${branchRes.status})`);
442
446
  const branchData = await branchRes.json();
443
447
  const commitSha = branchData.commit?.sha;
444
- if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.branch}"`);
445
- const commitUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/commits/${commitSha}${sep}${auth}`;
448
+ if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
449
+ const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
446
450
  const commitRes = await fetch(commitUrl);
447
451
  if (!commitRes.ok) throw new Error(`Gitee: commit ${commitSha} not found (${commitRes.status})`);
448
452
  const commitData = await commitRes.json();
449
453
  const treeSha = commitData.tree?.sha;
450
454
  if (!treeSha) throw new Error(`Gitee: could not get tree SHA from commit ${commitSha}`);
451
- console.log(`[Gitee] Resolved branch="${this.branch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
452
- const treeUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/trees/${treeSha}${sep}recursive=${recursive ? 1 : 0}&${auth}`;
453
- const treeRes = await fetch(treeUrl);
454
- if (!treeRes.ok) throw new Error(`Gitee: tree ${treeSha} not found (${treeRes.status})`);
455
- const treeData = await treeRes.json();
456
- return treeData.tree || [];
455
+ const realBranch = this.api.branch;
456
+ this.api.branch = treeSha;
457
+ console.log(`[Gitee] Resolved branch="${realBranch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
458
+ try {
459
+ return await origInit.call(this);
460
+ } finally {
461
+ this.api.branch = realBranch;
462
+ }
457
463
  };
458
464
  return wrapZenFSFileSystem({
459
465
  backend: zenGitee.Gitee,
package/dist/index.mjs CHANGED
@@ -375,38 +375,44 @@ registerBackend("GitHub", async (options) => {
375
375
  });
376
376
  registerBackend("Gitee", async (options) => {
377
377
  const zenGitee = await import("zen-fs-gitee");
378
- const { GiteeAPI } = await import("zen-fs-gitee/dist/gitee-api.js");
379
- const originalGetTree = GiteeAPI.prototype.getTree;
380
- GiteeAPI.prototype.getTree = async function(recursive = true) {
378
+ const { GiteeFS } = zenGitee;
379
+ const origInit = GiteeFS.prototype.init;
380
+ const patched = /* @__PURE__ */ new WeakSet();
381
+ GiteeFS.prototype.init = async function() {
382
+ let firstErr;
381
383
  try {
382
- return await originalGetTree.call(this, recursive);
384
+ return await origInit.call(this);
383
385
  } catch (err) {
384
386
  if (!err.message?.includes("404") && !err.message?.includes("Tree not found")) {
385
387
  throw err;
386
388
  }
389
+ firstErr = err;
387
390
  }
388
- console.log(`[Gitee] getTree failed with branch="${this.branch}", resolving to SHA...`);
389
- const baseUrl = this.baseUrl || "https://gitee.com/api/v5";
390
- const sep = "?";
391
- const auth = `access_token=${this.token}`;
392
- const branchUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/branches/${this.branch}${sep}${auth}`;
391
+ if (patched.has(this)) throw firstErr;
392
+ patched.add(this);
393
+ console.log(`[Gitee] init failed with branch="${this.api.branch}", resolving to SHA...`);
394
+ const baseUrl = this.api.baseUrl || "https://gitee.com/api/v5";
395
+ const auth = `access_token=${this.api.token}`;
396
+ const branchUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/branches/${this.api.branch}?${auth}`;
393
397
  const branchRes = await fetch(branchUrl);
394
- if (!branchRes.ok) throw new Error(`Gitee: branch "${this.branch}" not found (${branchRes.status})`);
398
+ if (!branchRes.ok) throw new Error(`Gitee: branch "${this.api.branch}" not found (${branchRes.status})`);
395
399
  const branchData = await branchRes.json();
396
400
  const commitSha = branchData.commit?.sha;
397
- if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.branch}"`);
398
- const commitUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/commits/${commitSha}${sep}${auth}`;
401
+ if (!commitSha) throw new Error(`Gitee: could not get commit SHA for branch "${this.api.branch}"`);
402
+ const commitUrl = `${baseUrl}/repos/${this.api.owner}/${this.api.repo}/git/commits/${commitSha}?${auth}`;
399
403
  const commitRes = await fetch(commitUrl);
400
404
  if (!commitRes.ok) throw new Error(`Gitee: commit ${commitSha} not found (${commitRes.status})`);
401
405
  const commitData = await commitRes.json();
402
406
  const treeSha = commitData.tree?.sha;
403
407
  if (!treeSha) throw new Error(`Gitee: could not get tree SHA from commit ${commitSha}`);
404
- console.log(`[Gitee] Resolved branch="${this.branch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
405
- const treeUrl = `${baseUrl}/repos/${this.owner}/${this.repo}/git/trees/${treeSha}${sep}recursive=${recursive ? 1 : 0}&${auth}`;
406
- const treeRes = await fetch(treeUrl);
407
- if (!treeRes.ok) throw new Error(`Gitee: tree ${treeSha} not found (${treeRes.status})`);
408
- const treeData = await treeRes.json();
409
- return treeData.tree || [];
408
+ const realBranch = this.api.branch;
409
+ this.api.branch = treeSha;
410
+ console.log(`[Gitee] Resolved branch="${realBranch}" \u2192 commit=${commitSha.slice(0, 8)} \u2192 tree=${treeSha.slice(0, 8)}`);
411
+ try {
412
+ return await origInit.call(this);
413
+ } finally {
414
+ this.api.branch = realBranch;
415
+ }
410
416
  };
411
417
  return wrapZenFSFileSystem({
412
418
  backend: zenGitee.Gitee,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",