@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/dist/sources/glob.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { a as SourceError, i as normalizeSourcePath, n as matchesAny, r as normalizeSafeSourcePath } from "../path-C0L1l0Fw.js";
|
|
2
|
-
import { glob as glob$1 } from "tinyglobby";
|
|
3
|
-
//#region src/sources/glob.ts
|
|
4
|
-
function glob(options) {
|
|
5
|
-
let snapshot;
|
|
6
|
-
let latest;
|
|
7
|
-
async function getContextKey(ctx) {
|
|
8
|
-
return resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
9
|
-
}
|
|
10
|
-
async function loadKeys(ctx) {
|
|
11
|
-
const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
12
|
-
const ignore = normalizePatterns(options.ignore);
|
|
13
|
-
return (await glob$1(options.include, {
|
|
14
|
-
cwd,
|
|
15
|
-
dot: options.dot ?? false,
|
|
16
|
-
followSymbolicLinks: options.followSymlinks ?? false,
|
|
17
|
-
ignore: [
|
|
18
|
-
"**/.git/**",
|
|
19
|
-
"**/node_modules/**",
|
|
20
|
-
...ignore
|
|
21
|
-
],
|
|
22
|
-
onlyFiles: true
|
|
23
|
-
})).map((file) => normalizeSourcePath(file)).filter((file) => matchesAny(file, options.include) && !matchesAny(file, ignore)).sort((left, right) => left.localeCompare(right));
|
|
24
|
-
}
|
|
25
|
-
async function refreshKeys(ctx) {
|
|
26
|
-
const key = await getContextKey(ctx);
|
|
27
|
-
const keys = await loadKeys(ctx);
|
|
28
|
-
latest = {
|
|
29
|
-
key,
|
|
30
|
-
keys
|
|
31
|
-
};
|
|
32
|
-
return keys;
|
|
33
|
-
}
|
|
34
|
-
async function getCachedKeys(ctx) {
|
|
35
|
-
if (options.keyCache === false) return await refreshKeys(ctx);
|
|
36
|
-
const key = await getContextKey(ctx);
|
|
37
|
-
if (!snapshot || snapshot.key !== key) snapshot = {
|
|
38
|
-
key,
|
|
39
|
-
keys: refreshKeys(ctx)
|
|
40
|
-
};
|
|
41
|
-
return await snapshot.keys;
|
|
42
|
-
}
|
|
43
|
-
async function getKnownKeys(ctx) {
|
|
44
|
-
const key = await getContextKey(ctx);
|
|
45
|
-
if (latest?.key === key) return latest.keys;
|
|
46
|
-
return await getCachedKeys(ctx);
|
|
47
|
-
}
|
|
48
|
-
async function assertKey(key, ctx) {
|
|
49
|
-
if ((await getKnownKeys(ctx)).includes(key)) return;
|
|
50
|
-
if (options.keyCache !== false) throw new SourceError(`[vitehub] source.glob could not find ${JSON.stringify(key)}.`);
|
|
51
|
-
if ((await refreshKeys(ctx)).includes(key)) return;
|
|
52
|
-
throw new SourceError(`[vitehub] source.glob could not find ${JSON.stringify(key)}.`);
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
name: "glob",
|
|
56
|
-
async prepare(ctx) {
|
|
57
|
-
snapshot = void 0;
|
|
58
|
-
await getCachedKeys(ctx);
|
|
59
|
-
},
|
|
60
|
-
getKeys(ctx) {
|
|
61
|
-
return getCachedKeys(ctx);
|
|
62
|
-
},
|
|
63
|
-
async getMeta(key, ctx) {
|
|
64
|
-
await assertKey(key, ctx);
|
|
65
|
-
const { stat } = await import("node:fs/promises");
|
|
66
|
-
const { resolve } = await import("node:path");
|
|
67
|
-
const info = await stat(resolve(await resolveCwd(resolveSourceRoot(ctx), options.cwd), key));
|
|
68
|
-
return { digest: `${info.size}:${info.mtimeMs}` };
|
|
69
|
-
},
|
|
70
|
-
async getItem(key, ctx) {
|
|
71
|
-
await assertKey(key, ctx);
|
|
72
|
-
const { readFile, stat } = await import("node:fs/promises");
|
|
73
|
-
const { resolve } = await import("node:path");
|
|
74
|
-
const cwd = await resolveCwd(resolveSourceRoot(ctx), options.cwd);
|
|
75
|
-
const prefix = normalizeSafeSourcePath(options.prefix || "", { allowEmpty: true });
|
|
76
|
-
const bytes = await readFile(resolve(cwd, key));
|
|
77
|
-
const info = await stat(resolve(cwd, key));
|
|
78
|
-
return {
|
|
79
|
-
key,
|
|
80
|
-
path: normalizeSourcePath(prefix ? `${prefix}/${key}` : key),
|
|
81
|
-
content: new Uint8Array(bytes),
|
|
82
|
-
metadata: { mtime: info.mtimeMs }
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function normalizePatterns(patterns) {
|
|
88
|
-
return Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
|
|
89
|
-
}
|
|
90
|
-
function resolveSourceRoot(ctx) {
|
|
91
|
-
return ctx.sourceRootDir || ctx.rootDir;
|
|
92
|
-
}
|
|
93
|
-
async function resolveCwd(rootDir, cwd = ".") {
|
|
94
|
-
const { realpath } = await import("node:fs/promises");
|
|
95
|
-
const { isAbsolute, relative, resolve } = await import("node:path");
|
|
96
|
-
const resolvedRoot = await realpath(resolve(rootDir));
|
|
97
|
-
const resolvedCwd = await realpath(isAbsolute(cwd) ? resolve(cwd) : resolve(resolvedRoot, cwd));
|
|
98
|
-
const rel = relative(resolvedRoot, resolvedCwd);
|
|
99
|
-
if (rel && (rel.startsWith("..") || isAbsolute(rel))) throw new SourceError(`[vitehub] source.glob cwd escapes the source root: ${JSON.stringify(cwd)}.`);
|
|
100
|
-
return resolvedCwd;
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
|
-
export { glob };
|
package/dist/sources/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { t as custom } from "../custom-CMmjCoru.js";
|
|
2
|
-
import { i as file, n as FileSourceOptions } from "../file-D8j_HGST.js";
|
|
3
|
-
import { n as GitHubSourceOptions, t as github } from "../index-ChHHP4I8.js";
|
|
4
|
-
import { n as glob, t as GlobSourceOptions } from "../glob-B_tSBNmd.js";
|
|
5
|
-
import { t as markdown } from "../markdown-IpYjHOyM.js";
|
|
6
|
-
|
|
7
|
-
//#region src/sources/index.d.ts
|
|
8
|
-
declare namespace index_d_exports {
|
|
9
|
-
export { FileSourceOptions, GitHubSourceOptions, GlobSourceOptions, custom, file, github, glob, markdown };
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { type FileSourceOptions, type GitHubSourceOptions, type GlobSourceOptions, custom, file, github, glob, markdown, index_d_exports as t };
|
package/dist/sources/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "../chunk-pbuEa-1d.js";
|
|
2
|
-
import { custom } from "./custom.js";
|
|
3
|
-
import { file } from "./file.js";
|
|
4
|
-
import { t as github } from "../github-Dp-ghUUj.js";
|
|
5
|
-
import { glob } from "./glob.js";
|
|
6
|
-
import { markdown } from "./markdown.js";
|
|
7
|
-
//#region src/sources/index.ts
|
|
8
|
-
var sources_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
-
custom: () => custom,
|
|
10
|
-
file: () => file,
|
|
11
|
-
github: () => github,
|
|
12
|
-
glob: () => glob,
|
|
13
|
-
markdown: () => markdown
|
|
14
|
-
});
|
|
15
|
-
//#endregion
|
|
16
|
-
export { custom, file, github, glob, markdown, sources_exports as t };
|
package/dist/sources/markdown.js
DELETED
package/dist/types-DgWwkKHY.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
//#region src/core/types.d.ts
|
|
2
|
-
type SourceContent = string | Uint8Array;
|
|
3
|
-
interface ReadSourceOptions {
|
|
4
|
-
encoding?: "utf8" | "binary";
|
|
5
|
-
}
|
|
6
|
-
type ReadSourceResult<TOptions extends ReadSourceOptions | undefined = undefined> = TOptions extends {
|
|
7
|
-
encoding: "binary";
|
|
8
|
-
} ? Uint8Array : string;
|
|
9
|
-
interface SourceContext {
|
|
10
|
-
rootDir: string;
|
|
11
|
-
sourceRootDir?: string;
|
|
12
|
-
source?: string;
|
|
13
|
-
workspace?: string;
|
|
14
|
-
}
|
|
15
|
-
interface SourceCacheOptions {
|
|
16
|
-
maxAge?: number;
|
|
17
|
-
}
|
|
18
|
-
interface SourceSearchQuery {
|
|
19
|
-
pattern: string;
|
|
20
|
-
cwd?: string;
|
|
21
|
-
paths?: string[];
|
|
22
|
-
regex?: boolean;
|
|
23
|
-
caseSensitive?: boolean;
|
|
24
|
-
limit?: number;
|
|
25
|
-
}
|
|
26
|
-
interface SourceSearchHit {
|
|
27
|
-
path: string;
|
|
28
|
-
line: number;
|
|
29
|
-
column: number;
|
|
30
|
-
text: string;
|
|
31
|
-
}
|
|
32
|
-
interface SourceItem<TKey extends string = string> {
|
|
33
|
-
key: TKey;
|
|
34
|
-
path?: string;
|
|
35
|
-
content?: SourceContent;
|
|
36
|
-
data?: unknown;
|
|
37
|
-
mediaType?: string;
|
|
38
|
-
metadata?: Record<string, unknown>;
|
|
39
|
-
}
|
|
40
|
-
interface Source<TKey extends string = string> {
|
|
41
|
-
name: string;
|
|
42
|
-
cache?: false | SourceCacheOptions;
|
|
43
|
-
fingerprint?: unknown;
|
|
44
|
-
prepare?(ctx: SourceContext): Promise<void>;
|
|
45
|
-
getKeys(ctx: SourceContext): Promise<TKey[]>;
|
|
46
|
-
getItem(key: TKey, ctx: SourceContext): Promise<SourceItem<TKey>>;
|
|
47
|
-
getItems?(ctx: SourceContext): Promise<SourceItem<TKey>[]>;
|
|
48
|
-
getMeta?(key: TKey, ctx: SourceContext): Promise<Record<string, unknown> | undefined>;
|
|
49
|
-
search?(query: SourceSearchQuery, ctx: SourceContext): Promise<SourceSearchHit[]>;
|
|
50
|
-
watch?: unknown[];
|
|
51
|
-
}
|
|
52
|
-
interface SourceListEntry<TKey extends string = string> {
|
|
53
|
-
key: TKey;
|
|
54
|
-
type: "file" | "directory";
|
|
55
|
-
}
|
|
56
|
-
declare global {
|
|
57
|
-
interface ViteHubSourceMap {}
|
|
58
|
-
}
|
|
59
|
-
interface SourceMap extends ViteHubSourceMap {}
|
|
60
|
-
type SourceKeyOf<TSource> = TSource extends Source<infer TKey> ? TKey : string;
|
|
61
|
-
type SourceName = [keyof ViteHubSourceMap] extends [never] ? string : Extract<keyof ViteHubSourceMap, string>;
|
|
62
|
-
type SourceKey<TName extends SourceName = SourceName> = TName extends keyof ViteHubSourceMap ? Extract<SourceKeyOf<ViteHubSourceMap[TName]>, string> : string;
|
|
63
|
-
interface SourceReader<TName extends SourceName = SourceName> {
|
|
64
|
-
keys(): Promise<SourceKey<TName>[]>;
|
|
65
|
-
get(key: SourceKey<TName>): Promise<SourceItem<SourceKey<TName>>>;
|
|
66
|
-
read<TOptions extends ReadSourceOptions | undefined = undefined>(key: SourceKey<TName>, options?: TOptions): Promise<ReadSourceResult<TOptions>>;
|
|
67
|
-
meta(key: SourceKey<TName>): Promise<Record<string, unknown> | undefined>;
|
|
68
|
-
exists(key: SourceKey<TName>): Promise<boolean>;
|
|
69
|
-
list(prefix?: SourceKey<TName> | (string & {}) | ""): Promise<SourceListEntry<SourceKey<TName>>[]>;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
export { SourceContent as a, SourceKey as c, SourceName as d, SourceReader as f, SourceCacheOptions as i, SourceListEntry as l, SourceSearchQuery as m, ReadSourceResult as n, SourceContext as o, SourceSearchHit as p, Source as r, SourceItem as s, ReadSourceOptions as t, SourceMap as u };
|