@vite-hub/workspace 0.0.4 → 0.1.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.
Files changed (127) hide show
  1. package/README.md +225 -58
  2. package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  3. package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  7. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  8. package/dist/blob-database.d.ts +521 -0
  9. package/dist/blob-database.js +601 -0
  10. package/dist/cloudflare.d.ts +5 -6
  11. package/dist/cloudflare.js +1 -1
  12. package/dist/config-B7dmzDX3.js +1112 -0
  13. package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
  14. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  15. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  16. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  17. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  18. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  19. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  20. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  21. package/dist/file-C0_aPWSS.js +26 -0
  22. package/dist/file-metadata-CxDy-E2H.js +58 -0
  23. package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
  24. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  25. package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
  26. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  27. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  28. package/dist/glob--XcLlcml.js +22 -0
  29. package/dist/glob--kNYDbfU.js +30 -0
  30. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  31. package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
  32. package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
  33. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  34. package/dist/hosted-vercel-blob.d.ts +5 -6
  35. package/dist/hosted-vercel-blob.js +1 -1
  36. package/dist/hosted.d.ts +6 -7
  37. package/dist/hosted.js +1 -1
  38. package/dist/index.d.ts +57 -36
  39. package/dist/index.js +56 -56
  40. package/dist/inspect-BoObD2cJ.js +167 -0
  41. package/dist/internal/path.d.ts +2 -0
  42. package/dist/internal/path.js +2 -0
  43. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  44. package/dist/loader.d.ts +5 -6
  45. package/dist/loader.js +3 -2
  46. package/dist/mcp-resources-BREFCmtn.js +39 -0
  47. package/dist/memory-BbwOqDXl.js +248 -0
  48. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  49. package/dist/mountx.d.ts +4 -6
  50. package/dist/mountx.js +10 -8
  51. package/dist/nitro.d.ts +1 -1
  52. package/dist/nitro.js +1 -1
  53. package/dist/nuxt.d.ts +13 -12
  54. package/dist/nuxt.js +4 -8
  55. package/dist/operations-BcpWr41m.js +159 -0
  56. package/dist/operations-CGqY1XeG.js +965 -0
  57. package/dist/operations-DnOwKsJT.d.ts +136 -0
  58. package/dist/operations.d.ts +53 -0
  59. package/dist/operations.js +2 -0
  60. package/dist/path-CNAwN7pw.js +114 -0
  61. package/dist/path-DrSIenjj.js +59 -0
  62. package/dist/path-zHxQUbqa.d.ts +9 -0
  63. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  64. package/dist/provider-kXjfli9u.js +1457 -0
  65. package/dist/providers/github/store.d.ts +3 -5
  66. package/dist/providers/github/store.js +1 -1
  67. package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
  68. package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
  69. package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
  70. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
  71. package/dist/runtime/assets.d.ts +3 -5
  72. package/dist/runtime/assets.js +7 -6
  73. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  74. package/dist/runtime/empty-registry.d.ts +1 -2
  75. package/dist/runtime/state.d.ts +3 -3
  76. package/dist/runtime/state.js +6 -6
  77. package/dist/runtime/workspace.d.ts +1 -1
  78. package/dist/runtime/workspace.js +1 -1
  79. package/dist/runtime.d.ts +51 -17
  80. package/dist/runtime.js +320 -60
  81. package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
  82. package/dist/server-BNQ-Nbjj.js +290 -0
  83. package/dist/server.d.ts +22 -34
  84. package/dist/server.js +2 -328
  85. package/dist/shared-DalXdP0i.js +2158 -0
  86. package/dist/source-metadata.d.ts +6 -7
  87. package/dist/source-metadata.js +7 -7
  88. package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
  89. package/dist/store-CXgmu-uw.js +1729 -0
  90. package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
  91. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  92. package/dist/test.d.ts +1 -1
  93. package/dist/test.js +1 -1
  94. package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
  95. package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
  96. package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
  97. package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
  98. package/dist/utils-Blrh4N2n.js +545 -0
  99. package/dist/vite-BEvgU2GY.js +20909 -0
  100. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  101. package/dist/vite.d.ts +2 -2
  102. package/dist/vite.js +2 -2
  103. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  104. package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
  105. package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
  106. package/package.json +89 -55
  107. package/dist/collections/client.d.ts +0 -39
  108. package/dist/collections/client.js +0 -137
  109. package/dist/collections.d.ts +0 -59
  110. package/dist/collections.js +0 -159
  111. package/dist/config-Bc3c4Su1.js +0 -7904
  112. package/dist/config-CHLLWklZ.js +0 -36
  113. package/dist/file-Bc1X7pco.js +0 -23
  114. package/dist/glob-CEZKeZFC.js +0 -18
  115. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  116. package/dist/lifecycle-LrL3sA4n.js +0 -316
  117. package/dist/metadata-target-B0tOmVW7.js +0 -717
  118. package/dist/path-Cp59koVz.js +0 -139
  119. package/dist/provider-B1yLjCJJ.js +0 -746
  120. package/dist/publish.d.ts +0 -35
  121. package/dist/publish.js +0 -112
  122. package/dist/runtime-options-BsPSv5O7.js +0 -13
  123. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  124. package/dist/shared-DTR1Hhma.js +0 -331
  125. package/dist/store-Dt_Jyys3.js +0 -608
  126. package/dist/vite-BptCrpv2.js +0 -4526
  127. package/dist/vite-CtA9guIM.d.ts +0 -66
@@ -1,9 +1,11 @@
1
- import { _ as workspaceError, f as sha256, n as contentStreamToBytes } from "./path-Cp59koVz.js";
2
- import { a as normalizeWorkspaceSources, n as createSourceContext, s as sourceMountContainsPath, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
3
- import { c as workspaceSourceSyncStateEquals, o as readWorkspaceSourceSyncState, s as sourceSyncMetaKey } from "./workspace-Dq08Yn72.js";
4
- import { m as normalizeSourceItemPath } from "./metadata-target-B0tOmVW7.js";
1
+ import { s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { f as sha256, n as contentStreamToBytes } from "./path-CNAwN7pw.js";
3
+ import { a as normalizeWorkspaceSources, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config-B7dmzDX3.js";
4
+ import { d as sourceSyncPathClaims, f as workspaceSourceSyncStateEquals, l as readWorkspaceSourceSyncState, u as sourceSyncMetaKey } from "./workspace-6pxkOuxr.js";
5
+ import { C as withWorkspaceStoreMutation, E as normalizeSourceFileMetadata, S as sourceMountOwnsPath, T as normalizeMetadataValue, w as normalizeSourceItemPath, x as createWorkspaceSourceMountAuthority } from "./metadata-target-DZEZQGHA.js";
5
6
  //#region src/sources/sync.ts
6
7
  const sourceSyncLocks = /* @__PURE__ */ new Map();
8
+ const sourceSyncGrants = createWorkspaceSourceMountAuthority("Source Sync");
7
9
  function zeroCounts() {
8
10
  return {
9
11
  added: 0,
@@ -51,7 +53,10 @@ function selectedSyncSources(definition, options) {
51
53
  if (options.sources === "all") return sources;
52
54
  return [...new Set(options.sources)].map((key) => {
53
55
  const source = sources.find((item) => item.key === key);
54
- if (!source) throw workspaceError(normalizeWorkspaceSources(definition.sources).some((item) => item.key === key) ? `[vitehub] Workspace source ${JSON.stringify(key)} is not configured for Source Sync. Add sync: true to the source binding.` : `[vitehub] Workspace source ${JSON.stringify(key)} does not exist.`);
56
+ if (!source) {
57
+ const defined = normalizeWorkspaceSources(definition.sources).some((item) => item.key === key);
58
+ throw workspaceError(defined ? `[vitehub] Workspace source ${JSON.stringify(key)} is not configured for Source Sync. Add sync: true to the source binding.` : `[vitehub] Workspace source ${JSON.stringify(key)} does not exist.`);
59
+ }
55
60
  return source;
56
61
  });
57
62
  }
@@ -68,7 +73,7 @@ async function shouldRemoveStalePath(store, path, metadata) {
68
73
  async function planSourceSync(definition, store, source) {
69
74
  const ctx = createSourceContext(definition, source);
70
75
  const [previousState, configHash, items] = await Promise.all([
71
- store.getMeta?.(sourceSyncMetaKey(source.key)).then(readWorkspaceSourceSyncState),
76
+ store.getMeta?.(sourceSyncMetaKey(source.key, definition.name)).then(readWorkspaceSourceSyncState),
72
77
  sourceConfigHash(source),
73
78
  getSourceItems(source, ctx)
74
79
  ]);
@@ -81,9 +86,14 @@ async function planSourceSync(definition, store, source) {
81
86
  if (nextPaths[path]) throw workspaceError(`[vitehub] Workspace Source Sync produced duplicate path: ${path}.`);
82
87
  const content = await contentFromItem(item);
83
88
  const digest = await sha256(content);
89
+ const metadata = normalizeSourceFileMetadata({
90
+ ...normalizeSourceFileMetadata(item.metadata || {}),
91
+ source: source.key,
92
+ sourcePath
93
+ });
84
94
  const existing = await store.readFile(path);
85
- const existingDigest = existing ? await sha256(existing.content) : void 0;
86
- const status = existing ? existingDigest === digest ? "unchanged" : "updated" : "added";
95
+ const unchanged = (existing ? await sha256(existing.content) : void 0) === digest && existing?.mediaType === item.mediaType && JSON.stringify(normalizeMetadataValue(existing?.metadata)) === JSON.stringify(normalizeMetadataValue(metadata));
96
+ const status = existing ? unchanged ? "unchanged" : "updated" : "added";
87
97
  countPath(counts, status);
88
98
  paths.push({
89
99
  path,
@@ -93,22 +103,23 @@ async function planSourceSync(definition, store, source) {
93
103
  nextPaths[path] = {
94
104
  digest,
95
105
  mediaType: item.mediaType,
106
+ mountPath: source.mountPath,
96
107
  sourcePath
97
108
  };
98
109
  files.push({
99
110
  path,
100
111
  content,
101
112
  mediaType: item.mediaType,
102
- metadata: {
103
- ...item.metadata,
104
- source: source.key,
105
- sourcePath
106
- }
113
+ metadata
107
114
  });
108
115
  }
109
116
  const removals = [];
110
- if (source.sync && source.sync.stale === "remove" && previousState) for (const [path, metadata] of Object.entries(previousState.paths)) {
117
+ if (source.sync && source.sync.stale === "remove" && previousState) for (const path of Object.keys(previousState.paths)) {
111
118
  if (nextPaths[path]) continue;
119
+ const claims = sourceSyncPathClaims(previousState, path);
120
+ const metadata = claims.find((claim) => claim.mountPath === source.mountPath);
121
+ if (!metadata || claims.length > 1) continue;
122
+ if (!sourceMountOwnsPath(source, path)) continue;
112
123
  if (!await shouldRemoveStalePath(store, path, metadata)) continue;
113
124
  const removal = {
114
125
  path,
@@ -119,28 +130,46 @@ async function planSourceSync(definition, store, source) {
119
130
  paths.push(removal);
120
131
  countPath(counts, "removed");
121
132
  }
122
- const nextState = {
123
- configHash,
124
- mountPath: source.mountPath,
125
- paths: nextPaths,
126
- source: source.key
127
- };
128
133
  return {
129
134
  counts,
130
135
  files,
131
- nextState,
136
+ nextState: {
137
+ configHash,
138
+ mountPath: source.mountPath,
139
+ paths: nextPaths,
140
+ source: source.key
141
+ },
132
142
  paths,
133
143
  removals,
134
144
  source,
135
- stateChanged: !workspaceSourceSyncStateEquals(previousState, nextState)
145
+ definitionName: definition.name
136
146
  };
137
147
  }
138
148
  async function applySourceSyncPlan(store, plan) {
139
- if (plan.source.mountPath) await store.mkdir(plan.source.mountPath, { recursive: true });
140
- for (const file of plan.files) await store.writeFile(file.path, file);
141
- for (const removal of plan.removals) await store.rm(removal.path, { force: true });
142
- await pruneEmptySourceDirectories(store, plan.source, plan.removals);
143
- if (plan.stateChanged) await store.setMeta?.(sourceSyncMetaKey(plan.source.key), plan.nextState);
149
+ const sourceStore = sourceSyncGrants.store(sourceSyncGrants.grant(plan.source), store);
150
+ const current = await store.getMeta?.(sourceSyncMetaKey(plan.source.key, plan.definitionName)).then(readWorkspaceSourceSyncState);
151
+ if (plan.source.mountPath) await sourceStore.mkdir(plan.source.mountPath, { recursive: true });
152
+ for (const file of plan.files) await sourceStore.writeFile(file.path, file);
153
+ for (const removal of plan.removals) await sourceStore.rm(removal.path, { force: true });
154
+ await pruneEmptySourceDirectories(sourceStore, plan.source, plan.removals);
155
+ const paths = {};
156
+ const claims = {};
157
+ for (const path of /* @__PURE__ */ new Set([...Object.keys(current?.paths ?? {}), ...Object.keys(plan.nextState.paths)])) {
158
+ const retained = current?.paths[path] ? sourceSyncPathClaims(current, path).filter((claim) => claim.mountPath !== plan.source.mountPath).map((claim) => ({ ...claim })) : [];
159
+ const next = plan.nextState.paths[path];
160
+ if (next) retained.push(next);
161
+ if (retained.length === 0) continue;
162
+ const digest = next?.digest ?? current.paths[path].digest;
163
+ for (const claim of retained) claim.digest = digest;
164
+ paths[path] = retained[retained.length - 1];
165
+ if (retained.length > 1) claims[path] = retained.sort((left, right) => left.mountPath.localeCompare(right.mountPath));
166
+ }
167
+ const nextState = {
168
+ ...plan.nextState,
169
+ paths
170
+ };
171
+ if (Object.keys(claims).length) nextState.claims = claims;
172
+ if (!workspaceSourceSyncStateEquals(current, nextState)) await store.setMeta?.(sourceSyncMetaKey(plan.source.key, plan.definitionName), nextState);
144
173
  }
145
174
  async function pruneEmptySourceDirectories(store, source, removals) {
146
175
  const directories = /* @__PURE__ */ new Set();
@@ -173,15 +202,10 @@ function statusFromPlan(plan, details) {
173
202
  status: "ready"
174
203
  };
175
204
  }
176
- async function snapshotSyncedWorkspace(definition, store, options) {
177
- if (!(!!options.snapshot || !!options.publish)) return;
205
+ async function snapshotSyncedWorkspace(store, options) {
206
+ if (!options.snapshot) return;
178
207
  const snapshotOptions = typeof options.snapshot === "object" ? options.snapshot : {};
179
- const snapshot = await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
180
- if (options.publish) {
181
- const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
182
- await publishWorkspaceSnapshot(definition, store, snapshot);
183
- }
184
- return snapshot;
208
+ return await store.snapshot(normalizeSnapshotOptions(snapshotOptions));
185
209
  }
186
210
  function normalizeSnapshotOptions(options) {
187
211
  if (!options || typeof options !== "object") return { name: "source-sync" };
@@ -203,7 +227,6 @@ async function syncWorkspaceSourcesUnlocked(definition, store, options, sources,
203
227
  }
204
228
  if (statuses.some((status) => status.status === "error") && !options.publishPartial) return {
205
229
  durationMs: Date.now() - started,
206
- published: false,
207
230
  sources: [...statuses, ...plans.map((plan) => ({
208
231
  counts: plan.counts,
209
232
  mountPath: plan.source.mountPath,
@@ -216,10 +239,9 @@ async function syncWorkspaceSourcesUnlocked(definition, store, options, sources,
216
239
  for (const plan of plans) await applySourceSyncPlan(store, plan);
217
240
  const planStatuses = plans.map((plan) => statusFromPlan(plan, options.details));
218
241
  const resultSources = [...statuses, ...planStatuses];
219
- const snapshot = resultStatus(resultSources) === "ready" || options.publishPartial && planStatuses.length > 0 ? await snapshotSyncedWorkspace(definition, store, options) : void 0;
242
+ const snapshot = resultStatus(resultSources) === "ready" || options.publishPartial && planStatuses.length > 0 ? await snapshotSyncedWorkspace(store, options) : void 0;
220
243
  return {
221
244
  durationMs: Date.now() - started,
222
- published: !!options.publish && !!snapshot,
223
245
  snapshot,
224
246
  sources: resultSources,
225
247
  status: resultStatus(resultSources)
@@ -232,7 +254,6 @@ async function syncWorkspaceSources(definition, store, options) {
232
254
  const sources = selectedSyncSources(definition, options);
233
255
  if (sources.length === 0) return {
234
256
  durationMs: 0,
235
- published: false,
236
257
  sources: [],
237
258
  status: "skipped"
238
259
  };
@@ -253,12 +274,11 @@ async function syncWorkspaceSources(definition, store, options) {
253
274
  }
254
275
  if (runnableSources.length === 0) return {
255
276
  durationMs: Date.now() - started,
256
- published: false,
257
277
  sources: statuses,
258
278
  status: resultStatus(statuses)
259
279
  };
260
280
  const lockKeys = runnableSources.map((source) => sourceLockKey(definition, source)).sort();
261
- const promise = syncWorkspaceSourcesUnlocked(definition, store, options, runnableSources, statuses, started);
281
+ const promise = withWorkspaceStoreMutation(store, () => syncWorkspaceSourcesUnlocked(definition, store, options, runnableSources, statuses, started));
262
282
  for (const key of lockKeys) sourceSyncLocks.set(key, promise);
263
283
  try {
264
284
  return await promise;
@@ -0,0 +1,125 @@
1
+ import { F as NotFoundError, pt as mapConcurrent } from "./shared-DalXdP0i.js";
2
+ //#region ../forge/dist/templates-Bn8a-pd2-D9DhJEVD.js
3
+ /** Where GitHub looks for a pull request template and the legacy issue template, in its order of precedence. */
4
+ const LOCATIONS = [
5
+ ".github",
6
+ "",
7
+ "docs"
8
+ ];
9
+ const ISSUE_TEMPLATE = /\.(?:md|ya?ml)$/i;
10
+ const ISSUE_FORM = /\.ya?ml$/i;
11
+ const CHOOSER_CONFIG = /^config\.ya?ml$/i;
12
+ const CONTENTS_OWNER = /\/repos\/([^/]+)\/[^/]+\/contents(?:[/?]|$)/;
13
+ /** No REST endpoint for templates, and GraphQL's `issueTemplates` skips issue forms, so this walks the folders GitHub reads. */
14
+ async function readTemplates(repo, kinds, reader) {
15
+ const root = await rootOf(repo, reader);
16
+ const own = await templatesOf(repo, root.entries, kinds, reader);
17
+ const missing = kinds.filter((kind) => kind === "issue" ? !own.ownsIssues : !own.templates.some((template) => template.kind === kind));
18
+ if (!missing.length || repo.name.toLowerCase() === ".github") return own.templates;
19
+ const source = {
20
+ forge: repo.forge,
21
+ instance: repo.instance,
22
+ owner: root.owner,
23
+ name: ".github"
24
+ };
25
+ const fallback = await fallbackOf(source, missing, reader);
26
+ return [...own.templates, ...fallback.map((template) => ({
27
+ ...template,
28
+ source
29
+ }))];
30
+ }
31
+ /** The root of the default branch, and the owner the repository lives under now, which differs from `repo.owner` after a transfer. */
32
+ async function rootOf(repo, reader) {
33
+ try {
34
+ const entries = await reader.list(repo, "");
35
+ const owner = entries.map((entry) => entry.url && CONTENTS_OWNER.exec(new URL(entry.url).pathname)?.[1]).find(Boolean);
36
+ return {
37
+ entries,
38
+ owner: owner ? decodeURIComponent(owner) : repo.owner
39
+ };
40
+ } catch (error) {
41
+ if (!(error instanceof NotFoundError)) throw error;
42
+ return {
43
+ entries: [],
44
+ owner: (await reader.repository(repo)).owner?.login ?? repo.owner
45
+ };
46
+ }
47
+ }
48
+ /** The owner's `.github` repository serves defaults only while it is public, or internal in an enterprise. */
49
+ async function fallbackOf(source, kinds, reader) {
50
+ let detail;
51
+ try {
52
+ detail = await reader.repository(source);
53
+ } catch (error) {
54
+ if (error instanceof NotFoundError) return [];
55
+ throw error;
56
+ }
57
+ if (detail.visibility ? detail.visibility === "private" : detail.private) return [];
58
+ return (await templatesOf(source, await orEmpty(reader.list(source, "")), kinds, reader)).templates;
59
+ }
60
+ /** A chooser `config.yml` alone still makes issue templates the repository's own, while any other file there doesn't. */
61
+ async function templatesOf(repo, root, kinds, reader) {
62
+ const locations = await Promise.all(LOCATIONS.map((directory) => !directory ? root : root.some((entry) => entry.type === "dir" && entry.name === directory) ? orEmpty(reader.list(repo, directory)) : []));
63
+ const folder = async (entries, name) => {
64
+ const found = entries.find((entry) => entry.type === "dir" && entry.name.toLowerCase() === name);
65
+ return found ? (await orEmpty(reader.list(repo, found.path))).filter((entry) => entry.type === "file") : [];
66
+ };
67
+ const [issueFiles, pullFiles] = await Promise.all([kinds.includes("issue") ? folder(locations[0], "issue_template") : [], kinds.includes("pull_request") ? folder(locations.flat(), "pull_request_template") : []]);
68
+ const found = [];
69
+ let ownsIssues = false;
70
+ if (kinds.includes("issue")) {
71
+ const templates = issueFiles.filter((entry) => ISSUE_TEMPLATE.test(entry.name) && !CHOOSER_CONFIG.test(entry.name));
72
+ const legacy = firstFile(locations, "issue_template");
73
+ if (templates.length) {
74
+ const forms = templates.filter((entry) => ISSUE_FORM.test(entry.name));
75
+ found.push(...forms.map((entry) => ({
76
+ kind: "issue",
77
+ format: "form",
78
+ entry
79
+ })), ...templates.filter((entry) => !forms.includes(entry)).map((entry) => ({
80
+ kind: "issue",
81
+ format: "markdown",
82
+ entry
83
+ })));
84
+ } else if (legacy) found.push({
85
+ kind: "issue",
86
+ format: "markdown",
87
+ entry: legacy
88
+ });
89
+ ownsIssues = templates.length > 0 || issueFiles.some((entry) => CHOOSER_CONFIG.test(entry.name)) || legacy !== void 0;
90
+ }
91
+ if (kinds.includes("pull_request")) {
92
+ const single = firstFile(locations, "pull_request_template");
93
+ found.push(...[...single ? [single] : [], ...pullFiles].map((entry) => ({
94
+ kind: "pull_request",
95
+ format: "markdown",
96
+ entry
97
+ })));
98
+ }
99
+ return {
100
+ templates: await mapConcurrent(found, 4, async ({ kind, format, entry }) => ({
101
+ kind,
102
+ name: entry.name,
103
+ path: entry.path,
104
+ format,
105
+ body: await reader.read(repo, entry.path),
106
+ raw: entry
107
+ })),
108
+ ownsIssues
109
+ };
110
+ }
111
+ /** The first file named `name`, with any extension and in any case, across the locations in their order. */
112
+ function firstFile(locations, name) {
113
+ return locations.flat().find((entry) => entry.type === "file" && entry.name.toLowerCase().replace(/\.[^.]*$/, "") === name);
114
+ }
115
+ /** A listing of a directory that may not exist, or of a repository that is empty. */
116
+ async function orEmpty(listing) {
117
+ try {
118
+ return await listing;
119
+ } catch (error) {
120
+ if (error instanceof NotFoundError) return [];
121
+ throw error;
122
+ }
123
+ }
124
+ //#endregion
125
+ export { readTemplates };
package/dist/test.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as registerWorkspace } from "./registry-Uj6IVxes.js";
1
+ import { n as registerWorkspace } from "./registry-Cg1TJVVZ.js";
2
2
  export { registerWorkspace };
package/dist/test.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as registerWorkspace } from "./registry-D3yzt8HQ.js";
1
+ import { n as registerWorkspace } from "./registry-Bp-8UUfG.js";
2
2
  export { registerWorkspace };
@@ -1,6 +1,6 @@
1
- import { t as __commonJSMin } from "./chunk-2rV9d50f.js";
2
- import { a as require_token_error, i as require_dist, r as require_token_util } from "./hosted-vercel-blob-d6C8ND5j.js";
3
- //#region ../../node_modules/.pnpm/@vercel+oidc@3.8.2/node_modules/@vercel/oidc/dist/token.js
1
+ import { t as __commonJSMin } from "./rolldown-runtime-B4iAMlE-.js";
2
+ import { a as require_token_error, i as require_dist, r as require_token_util } from "./hosted-vercel-blob-DKntsHaf.js";
3
+ //#region ../../node_modules/.pnpm/@vercel+oidc@3.8.10/node_modules/@vercel/oidc/dist/token.js
4
4
  var require_token = /* @__PURE__ */ __commonJSMin(((exports, module) => {
5
5
  var __defProp = Object.defineProperty;
6
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;