@vite-hub/source 0.0.1 → 0.0.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/README.md +32 -0
- package/dist/index.d.ts +166 -15
- package/dist/index.js +1096 -10
- package/package.json +37 -33
- package/dist/chunk-pbuEa-1d.js +0 -13
- package/dist/custom-CMmjCoru.d.ts +0 -6
- package/dist/file-D8j_HGST.d.ts +0 -20
- package/dist/github-Dp-ghUUj.js +0 -266
- package/dist/glob-B_tSBNmd.d.ts +0 -15
- package/dist/index-ChHHP4I8.d.ts +0 -17
- package/dist/markdown-IpYjHOyM.d.ts +0 -7
- package/dist/path-C0L1l0Fw.js +0 -47
- package/dist/sources/custom.d.ts +0 -2
- package/dist/sources/custom.js +0 -6
- package/dist/sources/file.d.ts +0 -2
- package/dist/sources/file.js +0 -53
- package/dist/sources/github.d.ts +0 -2
- package/dist/sources/github.js +0 -2
- package/dist/sources/glob.d.ts +0 -2
- package/dist/sources/glob.js +0 -103
- package/dist/sources/index.d.ts +0 -12
- package/dist/sources/index.js +0 -16
- package/dist/sources/markdown.d.ts +0 -2
- package/dist/sources/markdown.js +0 -10
- package/dist/types-DgWwkKHY.d.ts +0 -72
package/package.json
CHANGED
|
@@ -1,59 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/source",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Typed source retrieval primitives for ViteHub.",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"content",
|
|
7
|
+
"files",
|
|
8
|
+
"github",
|
|
9
|
+
"source",
|
|
10
|
+
"vitehub"
|
|
11
|
+
],
|
|
7
12
|
"homepage": "https://github.com/vite-hub/vitehub#readme",
|
|
13
|
+
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
8
16
|
"repository": {
|
|
9
17
|
"type": "git",
|
|
10
18
|
"url": "git+https://github.com/vite-hub/vitehub.git",
|
|
11
19
|
"directory": "packages/source"
|
|
12
20
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"source",
|
|
17
|
-
"content",
|
|
18
|
-
"github",
|
|
19
|
-
"files"
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"package.json"
|
|
20
24
|
],
|
|
21
|
-
"sideEffects": false,
|
|
22
25
|
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
23
27
|
"types": "./dist/index.d.ts",
|
|
24
28
|
"exports": {
|
|
25
|
-
".":
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"./sources/github": "./dist/sources/github.js",
|
|
30
|
-
"./sources/glob": "./dist/sources/glob.js",
|
|
31
|
-
"./sources/markdown": "./dist/sources/markdown.js",
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
32
33
|
"./package.json": "./package.json"
|
|
33
34
|
},
|
|
34
|
-
"files": [
|
|
35
|
-
"dist",
|
|
36
|
-
"package.json"
|
|
37
|
-
],
|
|
38
35
|
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
37
|
+
"effect": "4.0.0-beta.99",
|
|
39
38
|
"mrmime": "^2.0.1",
|
|
40
|
-
"ocache": "^0.1.
|
|
39
|
+
"ocache": "^0.1.5",
|
|
41
40
|
"pathe": "^2.0.3",
|
|
42
|
-
"picomatch": "^4.0.
|
|
43
|
-
"tinyglobby": "^0.2.
|
|
41
|
+
"picomatch": "^4.0.5",
|
|
42
|
+
"tinyglobby": "^0.2.17",
|
|
43
|
+
"@vite-hub/runtime": "0.0.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^24.13.3",
|
|
47
47
|
"@types/picomatch": "^4.0.3",
|
|
48
|
-
"publint": "^0.3.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"vitest": "^4.1.4"
|
|
48
|
+
"publint": "^0.3.21",
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
|
+
"vite-plus": "^0.1.24",
|
|
51
|
+
"vitest": "^4.1.4",
|
|
52
|
+
"@vite-hub/internal": "0.0.1"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=24.0.0"
|
|
52
56
|
},
|
|
53
57
|
"scripts": {
|
|
54
|
-
"build": "
|
|
55
|
-
"dev": "
|
|
58
|
+
"build": "vp pack",
|
|
59
|
+
"dev": "vp pack --watch",
|
|
56
60
|
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
57
|
-
"test": "
|
|
61
|
+
"test": "vp run -t @vite-hub/source#build && vp test"
|
|
58
62
|
}
|
|
59
63
|
}
|
package/dist/chunk-pbuEa-1d.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|
package/dist/file-D8j_HGST.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { a as SourceContent, r as Source } from "./types-DgWwkKHY.js";
|
|
2
|
-
|
|
3
|
-
//#region src/sources/file.d.ts
|
|
4
|
-
interface FileSourcePathOptions<TKey extends string = string> {
|
|
5
|
-
path: string;
|
|
6
|
-
workspacePath?: TKey;
|
|
7
|
-
content?: never;
|
|
8
|
-
mediaType?: string;
|
|
9
|
-
}
|
|
10
|
-
interface FileSourceInlineOptions<TKey extends string = string> {
|
|
11
|
-
workspacePath: TKey;
|
|
12
|
-
content: SourceContent;
|
|
13
|
-
mediaType?: string;
|
|
14
|
-
path?: never;
|
|
15
|
-
}
|
|
16
|
-
type FileSourceOptions<TKey extends string = string> = FileSourcePathOptions<TKey> | FileSourceInlineOptions<TKey>;
|
|
17
|
-
type FileSourceInput<TKey extends string = string> = FileSourceOptions<TKey> | TKey;
|
|
18
|
-
declare function file<const TKey extends string = string>(input: FileSourceInput<TKey>): Source<TKey>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { file as i, FileSourceOptions as n, FileSourcePathOptions as r, FileSourceInlineOptions as t };
|
package/dist/github-Dp-ghUUj.js
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { a as SourceError, i as normalizeSourcePath, n as matchesAny } from "./path-C0L1l0Fw.js";
|
|
2
|
-
import { defineCachedFunction } from "ocache";
|
|
3
|
-
import { Buffer } from "node:buffer";
|
|
4
|
-
import { gunzipSync } from "node:zlib";
|
|
5
|
-
//#region src/sources/github/archive.ts
|
|
6
|
-
function parseGitHubArchive(bytes) {
|
|
7
|
-
const tar = gunzipSync(bytes);
|
|
8
|
-
const files = [];
|
|
9
|
-
let offset = 0;
|
|
10
|
-
let paxPath;
|
|
11
|
-
while (offset + 512 <= tar.length) {
|
|
12
|
-
const header = tar.subarray(offset, offset + 512);
|
|
13
|
-
if (header.every((byte) => byte === 0)) break;
|
|
14
|
-
const name = readTarString(header, 0, 100);
|
|
15
|
-
const prefix = readTarString(header, 345, 155);
|
|
16
|
-
const path = paxPath || [prefix, name].filter(Boolean).join("/");
|
|
17
|
-
const size = Number.parseInt(readTarString(header, 124, 12).trim() || "0", 8) || 0;
|
|
18
|
-
const type = String.fromCharCode(header[156] || 0);
|
|
19
|
-
const contentStart = offset + 512;
|
|
20
|
-
const contentEnd = contentStart + size;
|
|
21
|
-
const content = tar.subarray(contentStart, contentEnd);
|
|
22
|
-
if (type === "x") paxPath = readPaxPath(content);
|
|
23
|
-
else {
|
|
24
|
-
if (type === "0" || type === "\0") {
|
|
25
|
-
const entryPath = stripArchiveRoot(path);
|
|
26
|
-
if (entryPath) files.push({
|
|
27
|
-
content: new Uint8Array(content),
|
|
28
|
-
path: entryPath
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
paxPath = void 0;
|
|
32
|
-
}
|
|
33
|
-
offset = contentStart + Math.ceil(size / 512) * 512;
|
|
34
|
-
}
|
|
35
|
-
return files;
|
|
36
|
-
}
|
|
37
|
-
function readTarString(buffer, offset, length) {
|
|
38
|
-
const slice = buffer.subarray(offset, offset + length);
|
|
39
|
-
const end = slice.indexOf(0);
|
|
40
|
-
return Buffer.from(end === -1 ? slice : slice.subarray(0, end)).toString("utf8");
|
|
41
|
-
}
|
|
42
|
-
function readPaxPath(content) {
|
|
43
|
-
let index = 0;
|
|
44
|
-
while (index < content.length) {
|
|
45
|
-
let space = index;
|
|
46
|
-
while (space < content.length && content[space] !== 32) space++;
|
|
47
|
-
if (space >= content.length) return;
|
|
48
|
-
const length = Number.parseInt(Buffer.from(content.subarray(index, space)).toString("ascii"), 10);
|
|
49
|
-
if (!Number.isFinite(length) || length <= 0 || index + length > content.length) return;
|
|
50
|
-
const record = content.subarray(space + 1, index + length - 1);
|
|
51
|
-
const equals = record.indexOf(61);
|
|
52
|
-
if (equals !== -1 && Buffer.from(record.subarray(0, equals)).toString("utf8") === "path") return Buffer.from(record.subarray(equals + 1)).toString("utf8");
|
|
53
|
-
index += length;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function stripArchiveRoot(path) {
|
|
57
|
-
const slash = path.indexOf("/");
|
|
58
|
-
if (slash === -1) return;
|
|
59
|
-
return normalizeSourcePath(path.slice(slash + 1));
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/sources/github/cache.ts
|
|
63
|
-
function normalizeGitHubCache(options) {
|
|
64
|
-
if (options.cache === false) return;
|
|
65
|
-
if (options.cache && typeof options.cache === "object") return { maxAge: options.cache.maxAge };
|
|
66
|
-
}
|
|
67
|
-
function createGitHubCacheKey(input) {
|
|
68
|
-
return [
|
|
69
|
-
input.kind,
|
|
70
|
-
input.repo,
|
|
71
|
-
input.ref,
|
|
72
|
-
input.root,
|
|
73
|
-
normalizePatternCacheKey(input.include),
|
|
74
|
-
normalizePatternCacheKey(input.exclude),
|
|
75
|
-
input.token,
|
|
76
|
-
input.key || ""
|
|
77
|
-
].join(":");
|
|
78
|
-
}
|
|
79
|
-
function normalizePatternCacheKey(value) {
|
|
80
|
-
if (!value) return "";
|
|
81
|
-
return Array.isArray(value) ? value.join(",") : value;
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/sources/github/client.ts
|
|
85
|
-
async function requestGitHubJson(input) {
|
|
86
|
-
const response = await fetch(input.url, { headers: {
|
|
87
|
-
accept: "application/vnd.github+json",
|
|
88
|
-
...input.token ? { authorization: `Bearer ${input.token}` } : {},
|
|
89
|
-
"user-agent": "vitehub-source",
|
|
90
|
-
"x-github-api-version": "2022-11-28"
|
|
91
|
-
} });
|
|
92
|
-
if (!response.ok) {
|
|
93
|
-
if (response.status === 404) throw new SourceError(`[vitehub] source.github(${JSON.stringify(input.repo)}) could not access the repository or ref ${JSON.stringify(input.ref)}. Check that the repo exists, the ref exists, and auth can access it.`);
|
|
94
|
-
throw new SourceError(`[vitehub] source.github(${JSON.stringify(input.repo)}) request failed with ${response.status} for ${input.url}.`);
|
|
95
|
-
}
|
|
96
|
-
return await response.json();
|
|
97
|
-
}
|
|
98
|
-
async function fetchGitHubArchive(input) {
|
|
99
|
-
const response = await fetch(`https://codeload.github.com/${input.repo}/tar.gz/${encodeURIComponent(input.ref)}`, { headers: {
|
|
100
|
-
...input.token ? { authorization: `Bearer ${input.token}` } : {},
|
|
101
|
-
"user-agent": "vitehub-source"
|
|
102
|
-
} });
|
|
103
|
-
if (!response.ok) {
|
|
104
|
-
if (response.status === 404) throw new SourceError(`[vitehub] source.github(${JSON.stringify(input.repo)}) could not access the repository or ref ${JSON.stringify(input.ref)}. Check that the repo exists and the ref exists.`);
|
|
105
|
-
throw new SourceError(`[vitehub] source.github(${JSON.stringify(input.repo)}) archive request failed with ${response.status}.`);
|
|
106
|
-
}
|
|
107
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/sources/github/index.ts
|
|
111
|
-
function normalizeGitHubRoot(path = "") {
|
|
112
|
-
return normalizeSourcePath(path).split("/").filter((part) => part && part !== ".").join("/");
|
|
113
|
-
}
|
|
114
|
-
function github(options) {
|
|
115
|
-
const configuredRef = options.ref;
|
|
116
|
-
const root = normalizeGitHubRoot(options.root || "");
|
|
117
|
-
let auth;
|
|
118
|
-
const providerCache = normalizeGitHubCache(options);
|
|
119
|
-
function resolveAuth() {
|
|
120
|
-
const token = typeof options.auth === "function" ? options.auth() : options.auth;
|
|
121
|
-
return typeof token === "string" && token.length > 0 ? token : void 0;
|
|
122
|
-
}
|
|
123
|
-
function refreshAuth() {
|
|
124
|
-
const nextAuth = resolveAuth();
|
|
125
|
-
if (nextAuth !== auth) auth = nextAuth;
|
|
126
|
-
return auth;
|
|
127
|
-
}
|
|
128
|
-
function keyForRepoPath(path) {
|
|
129
|
-
const normalized = normalizeSourcePath(path);
|
|
130
|
-
if (!root) return normalized;
|
|
131
|
-
if (!normalized.startsWith(`${root}/`)) return void 0;
|
|
132
|
-
return normalized.slice(root.length + 1);
|
|
133
|
-
}
|
|
134
|
-
function shouldInclude(key) {
|
|
135
|
-
if (options.include && !matchesAny(key, options.include)) return false;
|
|
136
|
-
if (options.exclude && matchesAny(key, options.exclude)) return false;
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
async function resolveRef(token = auth) {
|
|
140
|
-
if (configuredRef) return configuredRef;
|
|
141
|
-
try {
|
|
142
|
-
const defaultBranch = (await requestGitHubJson({
|
|
143
|
-
ref: "default",
|
|
144
|
-
repo: options.repo,
|
|
145
|
-
token,
|
|
146
|
-
url: `https://api.github.com/repos/${options.repo}`
|
|
147
|
-
})).default_branch || "main";
|
|
148
|
-
return (await requestGitHubJson({
|
|
149
|
-
ref: defaultBranch,
|
|
150
|
-
repo: options.repo,
|
|
151
|
-
token,
|
|
152
|
-
url: `https://api.github.com/repos/${options.repo}/commits/${encodeURIComponent(defaultBranch)}`
|
|
153
|
-
})).sha || defaultBranch;
|
|
154
|
-
} catch (error) {
|
|
155
|
-
if (shouldResolveMainFallback(error)) return "main";
|
|
156
|
-
throw error;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function shouldResolveMainFallback(error) {
|
|
160
|
-
return error instanceof SourceError && error.message.includes(" request failed with 403 ");
|
|
161
|
-
}
|
|
162
|
-
const cachedResolveRef = providerCache ? defineCachedFunction(async (token) => await resolveRef(token), {
|
|
163
|
-
...providerCache,
|
|
164
|
-
getKey: (token) => cacheKey("ref", token || ""),
|
|
165
|
-
name: "github-source-ref"
|
|
166
|
-
}) : async (token) => await resolveRef(token);
|
|
167
|
-
async function getRef(token = refreshAuth()) {
|
|
168
|
-
return await cachedResolveRef(token);
|
|
169
|
-
}
|
|
170
|
-
async function loadArchiveFiles(token = auth) {
|
|
171
|
-
const ref = await getRef(token);
|
|
172
|
-
return parseGitHubArchive(await fetchGitHubArchive({
|
|
173
|
-
ref,
|
|
174
|
-
repo: options.repo,
|
|
175
|
-
token
|
|
176
|
-
})).map((entry) => {
|
|
177
|
-
const key = keyForRepoPath(entry.path);
|
|
178
|
-
if (!key || !shouldInclude(key)) return void 0;
|
|
179
|
-
return {
|
|
180
|
-
content: entry.content,
|
|
181
|
-
key,
|
|
182
|
-
path: key,
|
|
183
|
-
sha: ref
|
|
184
|
-
};
|
|
185
|
-
}).filter((file) => Boolean(file));
|
|
186
|
-
}
|
|
187
|
-
async function loadFiles(token = auth) {
|
|
188
|
-
return await loadArchiveFiles(token);
|
|
189
|
-
}
|
|
190
|
-
const cachedLoadFiles = providerCache ? defineCachedFunction(async (token) => await loadFiles(token), {
|
|
191
|
-
...providerCache,
|
|
192
|
-
getKey: (token) => cacheKey("archive", token || ""),
|
|
193
|
-
name: "github-source-archive"
|
|
194
|
-
}) : async (token) => await loadFiles(token);
|
|
195
|
-
function getFiles(token = refreshAuth()) {
|
|
196
|
-
return cachedLoadFiles(token);
|
|
197
|
-
}
|
|
198
|
-
function fetchContent(key, file) {
|
|
199
|
-
if (file.content) return Promise.resolve(file.content);
|
|
200
|
-
throw new SourceError(`[vitehub] source.github(${JSON.stringify(options.repo)}) did not include archive content for ${JSON.stringify(key)}.`);
|
|
201
|
-
}
|
|
202
|
-
function cacheKey(kind, token, key = "") {
|
|
203
|
-
return createGitHubCacheKey({
|
|
204
|
-
exclude: options.exclude,
|
|
205
|
-
include: options.include,
|
|
206
|
-
key,
|
|
207
|
-
kind,
|
|
208
|
-
ref: configuredRef || "default",
|
|
209
|
-
repo: options.repo,
|
|
210
|
-
root,
|
|
211
|
-
token
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
cache: options.cache,
|
|
216
|
-
fingerprint: {
|
|
217
|
-
exclude: options.exclude,
|
|
218
|
-
include: options.include,
|
|
219
|
-
ref: configuredRef || "default",
|
|
220
|
-
repo: options.repo,
|
|
221
|
-
root
|
|
222
|
-
},
|
|
223
|
-
name: "github",
|
|
224
|
-
async getKeys() {
|
|
225
|
-
return (await getFiles()).map((file) => file.key);
|
|
226
|
-
},
|
|
227
|
-
async getItems() {
|
|
228
|
-
const token = refreshAuth();
|
|
229
|
-
const ref = await getRef(token);
|
|
230
|
-
return await Promise.all((await getFiles(token)).map(async (file) => ({
|
|
231
|
-
key: file.key,
|
|
232
|
-
path: file.path,
|
|
233
|
-
content: await fetchContent(file.key, file),
|
|
234
|
-
metadata: {
|
|
235
|
-
ref,
|
|
236
|
-
sha: file.sha
|
|
237
|
-
}
|
|
238
|
-
})));
|
|
239
|
-
},
|
|
240
|
-
async getMeta(key) {
|
|
241
|
-
const token = refreshAuth();
|
|
242
|
-
const file = (await getFiles(token)).find((file) => file.key === key);
|
|
243
|
-
if (!file) return;
|
|
244
|
-
return {
|
|
245
|
-
ref: await getRef(token),
|
|
246
|
-
sha: file.sha
|
|
247
|
-
};
|
|
248
|
-
},
|
|
249
|
-
async getItem(key) {
|
|
250
|
-
const token = refreshAuth();
|
|
251
|
-
const file = (await getFiles(token)).find((file) => file.key === key);
|
|
252
|
-
if (!file) throw new SourceError(`[vitehub] source.github(${JSON.stringify(options.repo)}) could not find ${JSON.stringify(key)}.`);
|
|
253
|
-
return {
|
|
254
|
-
key,
|
|
255
|
-
path: file.path,
|
|
256
|
-
content: await fetchContent(key, file),
|
|
257
|
-
metadata: {
|
|
258
|
-
ref: await getRef(token),
|
|
259
|
-
sha: file.sha
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
//#endregion
|
|
266
|
-
export { github as t };
|
package/dist/glob-B_tSBNmd.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { r as Source } from "./types-DgWwkKHY.js";
|
|
2
|
-
|
|
3
|
-
//#region src/sources/glob.d.ts
|
|
4
|
-
interface GlobSourceOptions {
|
|
5
|
-
cwd?: string;
|
|
6
|
-
dot?: boolean;
|
|
7
|
-
followSymlinks?: boolean;
|
|
8
|
-
include: string | string[];
|
|
9
|
-
ignore?: string | string[];
|
|
10
|
-
keyCache?: boolean;
|
|
11
|
-
prefix?: string;
|
|
12
|
-
}
|
|
13
|
-
declare function glob<const TKey extends string = string>(options: GlobSourceOptions): Source<TKey>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { glob as n, GlobSourceOptions as t };
|
package/dist/index-ChHHP4I8.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { i as SourceCacheOptions, r as Source } from "./types-DgWwkKHY.js";
|
|
2
|
-
|
|
3
|
-
//#region src/sources/github/types.d.ts
|
|
4
|
-
interface GitHubSourceOptions {
|
|
5
|
-
repo: string;
|
|
6
|
-
ref?: string;
|
|
7
|
-
root?: string;
|
|
8
|
-
auth?: string | (() => string | undefined);
|
|
9
|
-
include?: string | string[];
|
|
10
|
-
exclude?: string | string[];
|
|
11
|
-
cache?: false | SourceCacheOptions;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/sources/github/index.d.ts
|
|
15
|
-
declare function github<const TKey extends string = string>(options: GitHubSourceOptions): Source<TKey>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { GitHubSourceOptions as n, github as t };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { r as Source } from "./types-DgWwkKHY.js";
|
|
2
|
-
import { n as FileSourceOptions } from "./file-D8j_HGST.js";
|
|
3
|
-
|
|
4
|
-
//#region src/sources/markdown.d.ts
|
|
5
|
-
declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): Source<TKey>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { markdown as t };
|
package/dist/path-C0L1l0Fw.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import picomatch from "picomatch";
|
|
2
|
-
import { isAbsolute } from "pathe";
|
|
3
|
-
//#region src/core/errors.ts
|
|
4
|
-
var SourceError = class extends Error {
|
|
5
|
-
constructor(message, options) {
|
|
6
|
-
super(message, options);
|
|
7
|
-
this.name = "SourceError";
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var SourceNotFoundError = class extends SourceError {
|
|
11
|
-
constructor(name) {
|
|
12
|
-
super(`[vitehub] Source "${name}" is not registered.`);
|
|
13
|
-
this.name = "SourceNotFoundError";
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
var SourcePathError = class extends SourceError {
|
|
17
|
-
constructor(path) {
|
|
18
|
-
super(`[vitehub] Source path escapes the source root: ${JSON.stringify(path)}.`);
|
|
19
|
-
this.name = "SourcePathError";
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/core/path.ts
|
|
24
|
-
function normalizeSourcePath(path = "") {
|
|
25
|
-
return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
26
|
-
}
|
|
27
|
-
function normalizeSafeSourcePath(path = "", options = {}) {
|
|
28
|
-
const raw = path.replace(/\\/g, "/");
|
|
29
|
-
const normalized = normalizeSourcePath(path);
|
|
30
|
-
const parts = normalized.split("/").filter(Boolean);
|
|
31
|
-
if (!options.allowEmpty && !normalized) throw new SourcePathError(path);
|
|
32
|
-
if (isAbsolute(raw) || parts.some((part) => part === "." || part === "..")) throw new SourcePathError(path);
|
|
33
|
-
if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw new SourcePathError(path);
|
|
34
|
-
return normalized;
|
|
35
|
-
}
|
|
36
|
-
function matchesAny(path, patterns) {
|
|
37
|
-
if (!patterns) return true;
|
|
38
|
-
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
39
|
-
const normalizedPath = normalizeSourcePath(path);
|
|
40
|
-
return picomatch.isMatch(normalizedPath, list.map((pattern) => normalizeSourcePath(pattern)), { dot: true });
|
|
41
|
-
}
|
|
42
|
-
function decodeSourceContent(content, options) {
|
|
43
|
-
if (options?.encoding === "binary") return typeof content === "string" ? new TextEncoder().encode(content) : content;
|
|
44
|
-
return typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { SourceError as a, normalizeSourcePath as i, matchesAny as n, SourceNotFoundError as o, normalizeSafeSourcePath as r, SourcePathError as s, decodeSourceContent as t };
|
package/dist/sources/custom.d.ts
DELETED
package/dist/sources/custom.js
DELETED
package/dist/sources/file.d.ts
DELETED
package/dist/sources/file.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { a as SourceError, i as normalizeSourcePath, r as normalizeSafeSourcePath } from "../path-C0L1l0Fw.js";
|
|
2
|
-
import { lookup } from "mrmime";
|
|
3
|
-
//#region src/sources/file.ts
|
|
4
|
-
function basename(path) {
|
|
5
|
-
return path.replace(/\\/g, "/").split("/").filter(Boolean).pop() || path;
|
|
6
|
-
}
|
|
7
|
-
function normalizeFileSourceOptions(input) {
|
|
8
|
-
return typeof input === "string" ? { path: input } : input;
|
|
9
|
-
}
|
|
10
|
-
function sourceKey(options) {
|
|
11
|
-
if (options.workspacePath) return normalizeSourcePath(options.workspacePath);
|
|
12
|
-
if ("path" in options && options.path) return normalizeSourcePath(basename(normalizeSafeSourcePath(options.path)));
|
|
13
|
-
throw new TypeError("[vitehub] source.file requires a path or workspacePath.");
|
|
14
|
-
}
|
|
15
|
-
function resolveSourceRoot(ctx) {
|
|
16
|
-
return ctx.sourceRootDir || ctx.rootDir;
|
|
17
|
-
}
|
|
18
|
-
async function readSourceFile(options, ctx) {
|
|
19
|
-
if (!("path" in options) || !options.path) throw new TypeError("[vitehub] source.file requires path when content is not provided.");
|
|
20
|
-
const { readFile } = await import("node:fs/promises");
|
|
21
|
-
const { resolve } = await import("node:path");
|
|
22
|
-
return new Uint8Array(await readFile(resolve(resolveSourceRoot(ctx), normalizeSafeSourcePath(options.path))));
|
|
23
|
-
}
|
|
24
|
-
function file(input) {
|
|
25
|
-
const options = normalizeFileSourceOptions(input);
|
|
26
|
-
const key = sourceKey(options);
|
|
27
|
-
const mediaType = options.mediaType || lookup(key);
|
|
28
|
-
return {
|
|
29
|
-
name: "file",
|
|
30
|
-
async getKeys() {
|
|
31
|
-
return [key];
|
|
32
|
-
},
|
|
33
|
-
async getMeta(requestedKey, ctx) {
|
|
34
|
-
if (requestedKey !== key) return;
|
|
35
|
-
if (!("path" in options) || !options.path) return;
|
|
36
|
-
const { stat } = await import("node:fs/promises");
|
|
37
|
-
const { resolve } = await import("node:path");
|
|
38
|
-
const info = await stat(resolve(resolveSourceRoot(ctx), normalizeSafeSourcePath(options.path)));
|
|
39
|
-
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
40
|
-
},
|
|
41
|
-
async getItem(requestedKey, ctx) {
|
|
42
|
-
if (requestedKey !== key) throw new SourceError(`[vitehub] source.file could not find ${JSON.stringify(requestedKey)}.`);
|
|
43
|
-
return {
|
|
44
|
-
key,
|
|
45
|
-
path: key,
|
|
46
|
-
content: typeof options.content === "undefined" ? await readSourceFile(options, ctx) : options.content,
|
|
47
|
-
mediaType
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { file };
|
package/dist/sources/github.d.ts
DELETED
package/dist/sources/github.js
DELETED
package/dist/sources/glob.d.ts
DELETED