@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.
- package/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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)
|
|
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
|
|
86
|
-
const status = existing ?
|
|
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
|
|
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
|
-
|
|
145
|
+
definitionName: definition.name
|
|
136
146
|
};
|
|
137
147
|
}
|
|
138
148
|
async function applySourceSyncPlan(store, plan) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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(
|
|
177
|
-
if (!
|
|
205
|
+
async function snapshotSyncedWorkspace(store, options) {
|
|
206
|
+
if (!options.snapshot) return;
|
|
178
207
|
const snapshotOptions = typeof options.snapshot === "object" ? options.snapshot : {};
|
|
179
|
-
|
|
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(
|
|
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-
|
|
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-
|
|
1
|
+
import { n as registerWorkspace } from "./registry-Bp-8UUfG.js";
|
|
2
2
|
export { registerWorkspace };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as __commonJSMin } from "./
|
|
2
|
-
import { a as require_token_error, i as require_dist, r as require_token_util } from "./hosted-vercel-blob-
|
|
3
|
-
//#region ../../node_modules/.pnpm/@vercel+oidc@3.8.
|
|
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;
|