@vite-hub/source 0.1.0 → 0.3.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 (48) hide show
  1. package/README.md +83 -49
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +30 -4
  4. package/dist/{collection-B_4w_J8h.d.ts → collection-B8sgxw5-.d.ts} +52 -19
  5. package/dist/collection-C0Rvrx3p.js +297 -0
  6. package/dist/drizzle.d.ts +11 -4
  7. package/dist/drizzle.js +6 -8
  8. package/dist/error-diagnostics-ClQKdi7c.js +194 -0
  9. package/dist/github-D5S0dEZe.js +1312 -0
  10. package/dist/{glob-BmFqTvJY.js → glob-DmdMVqjx.js} +1 -2
  11. package/dist/index.d.ts +186 -55
  12. package/dist/index.js +152 -207
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/mcp.d.ts +1 -1
  15. package/dist/mcp.js +25 -140
  16. package/dist/object-CtSHeGQO.js +17 -0
  17. package/dist/{path-BS8rYm0n.js → path-DFlSryRA.js} +32 -2
  18. package/dist/root-DJNmqCEW.js +11 -0
  19. package/dist/server.d.ts +7 -244
  20. package/dist/server.js +38 -45
  21. package/dist/{types-BigOktIj.d.ts → types-Ln-FxVFn.d.ts} +6 -1
  22. package/dist/vite.d.ts +77 -10
  23. package/dist/vite.js +619 -713
  24. package/package.json +25 -47
  25. package/dist/auth-B-tX_rp0.js +0 -1426
  26. package/dist/client-BwstxtdY.js +0 -8280
  27. package/dist/collection-cursor-WzV1Jd6v.js +0 -124
  28. package/dist/error-diagnostics-X0kuFjBT.js +0 -51
  29. package/dist/file-BX0FSvgE.js +0 -60
  30. package/dist/file-DadN9dbN.d.ts +0 -19
  31. package/dist/file.d.ts +0 -2
  32. package/dist/file.js +0 -2
  33. package/dist/files.d.ts +0 -15
  34. package/dist/files.js +0 -38
  35. package/dist/github.d.ts +0 -20
  36. package/dist/github.js +0 -1332
  37. package/dist/glob.d.ts +0 -23
  38. package/dist/glob.js +0 -2
  39. package/dist/markdown.d.ts +0 -5
  40. package/dist/markdown.js +0 -10
  41. package/dist/mrmime-40h5OOIp.js +0 -448
  42. package/dist/path-DOBpV8ol.js +0 -32
  43. package/dist/sse-D9gqqNPj.js +0 -448
  44. package/dist/streamableHttp-BL-E7pl5.js +0 -509
  45. package/dist/types-CoWcW8oz.js +0 -7590
  46. package/tsconfig.vite.json +0 -6
  47. package/types/source/fallback.d.ts +0 -1
  48. package/types/source/index.d.ts +0 -1
package/dist/glob.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { t as FileSource } from "./types-BigOktIj.js";
2
- //#region src/sources/glob.d.ts
3
- interface GlobSourceOptions {
4
- cwd?: string;
5
- dot?: boolean;
6
- followSymlinks?: boolean;
7
- /** Portable glob patterns: backslashes are separators, never escapes. Use [*], [?], [[] for literals. */
8
- include: string | string[];
9
- /** Uses the same portable separator and literal syntax as include. */
10
- ignore?: string | readonly string[];
11
- keyCache?: boolean;
12
- prefix?: string;
13
- }
14
- /** A pattern such as `content/docs/**\/*.md`, or the options. */
15
- type GlobInput = string | GlobSourceOptions;
16
- /**
17
- * Project files that match a pattern, such as `glob("content/docs/**\/*.md")`. Under `vite dev` they are read from
18
- * disk, so new files show up at once. A ViteHub build bundles a call with literal options into the server, so hosts
19
- * without a file system, such as Cloudflare Workers, serve the same files.
20
- */
21
- export declare function glob(input: GlobInput): FileSource<string>;
22
- //#endregion
23
- export type { GlobInput, GlobSourceOptions };
package/dist/glob.js DELETED
@@ -1,2 +0,0 @@
1
- import { n as glob } from "./glob-BmFqTvJY.js";
2
- export { glob };
@@ -1,5 +0,0 @@
1
- import { t as FileSource } from "./types-BigOktIj.js";
2
- import { n as FileSourceOptions } from "./file-DadN9dbN.js";
3
- //#region src/sources/markdown.d.ts
4
- export declare function markdown<const TKey extends string = string>(options: FileSourceOptions<TKey>): FileSource<TKey>;
5
- //#endregion
package/dist/markdown.js DELETED
@@ -1,10 +0,0 @@
1
- import { t as file } from "./file-BX0FSvgE.js";
2
- //#region src/sources/markdown.ts
3
- function markdown(options) {
4
- return file({
5
- ...options,
6
- mediaType: Object.hasOwn(options, "mediaType") && options.mediaType ? options.mediaType : "text/markdown"
7
- });
8
- }
9
- //#endregion
10
- export { markdown };
@@ -1,448 +0,0 @@
1
- //#region ../../node_modules/.pnpm/mrmime@2.0.1/node_modules/mrmime/index.mjs
2
- const mimes = {
3
- "3g2": "video/3gpp2",
4
- "3gp": "video/3gpp",
5
- "3gpp": "video/3gpp",
6
- "3mf": "model/3mf",
7
- "aac": "audio/aac",
8
- "ac": "application/pkix-attr-cert",
9
- "adp": "audio/adpcm",
10
- "adts": "audio/aac",
11
- "ai": "application/postscript",
12
- "aml": "application/automationml-aml+xml",
13
- "amlx": "application/automationml-amlx+zip",
14
- "amr": "audio/amr",
15
- "apng": "image/apng",
16
- "appcache": "text/cache-manifest",
17
- "appinstaller": "application/appinstaller",
18
- "appx": "application/appx",
19
- "appxbundle": "application/appxbundle",
20
- "asc": "application/pgp-keys",
21
- "atom": "application/atom+xml",
22
- "atomcat": "application/atomcat+xml",
23
- "atomdeleted": "application/atomdeleted+xml",
24
- "atomsvc": "application/atomsvc+xml",
25
- "au": "audio/basic",
26
- "avci": "image/avci",
27
- "avcs": "image/avcs",
28
- "avif": "image/avif",
29
- "aw": "application/applixware",
30
- "bdoc": "application/bdoc",
31
- "bin": "application/octet-stream",
32
- "bmp": "image/bmp",
33
- "bpk": "application/octet-stream",
34
- "btf": "image/prs.btif",
35
- "btif": "image/prs.btif",
36
- "buffer": "application/octet-stream",
37
- "ccxml": "application/ccxml+xml",
38
- "cdfx": "application/cdfx+xml",
39
- "cdmia": "application/cdmi-capability",
40
- "cdmic": "application/cdmi-container",
41
- "cdmid": "application/cdmi-domain",
42
- "cdmio": "application/cdmi-object",
43
- "cdmiq": "application/cdmi-queue",
44
- "cer": "application/pkix-cert",
45
- "cgm": "image/cgm",
46
- "cjs": "application/node",
47
- "class": "application/java-vm",
48
- "coffee": "text/coffeescript",
49
- "conf": "text/plain",
50
- "cpl": "application/cpl+xml",
51
- "cpt": "application/mac-compactpro",
52
- "crl": "application/pkix-crl",
53
- "css": "text/css",
54
- "csv": "text/csv",
55
- "cu": "application/cu-seeme",
56
- "cwl": "application/cwl",
57
- "cww": "application/prs.cww",
58
- "davmount": "application/davmount+xml",
59
- "dbk": "application/docbook+xml",
60
- "deb": "application/octet-stream",
61
- "def": "text/plain",
62
- "deploy": "application/octet-stream",
63
- "dib": "image/bmp",
64
- "disposition-notification": "message/disposition-notification",
65
- "dist": "application/octet-stream",
66
- "distz": "application/octet-stream",
67
- "dll": "application/octet-stream",
68
- "dmg": "application/octet-stream",
69
- "dms": "application/octet-stream",
70
- "doc": "application/msword",
71
- "dot": "application/msword",
72
- "dpx": "image/dpx",
73
- "drle": "image/dicom-rle",
74
- "dsc": "text/prs.lines.tag",
75
- "dssc": "application/dssc+der",
76
- "dtd": "application/xml-dtd",
77
- "dump": "application/octet-stream",
78
- "dwd": "application/atsc-dwd+xml",
79
- "ear": "application/java-archive",
80
- "ecma": "application/ecmascript",
81
- "elc": "application/octet-stream",
82
- "emf": "image/emf",
83
- "eml": "message/rfc822",
84
- "emma": "application/emma+xml",
85
- "emotionml": "application/emotionml+xml",
86
- "eps": "application/postscript",
87
- "epub": "application/epub+zip",
88
- "exe": "application/octet-stream",
89
- "exi": "application/exi",
90
- "exp": "application/express",
91
- "exr": "image/aces",
92
- "ez": "application/andrew-inset",
93
- "fdf": "application/fdf",
94
- "fdt": "application/fdt+xml",
95
- "fits": "image/fits",
96
- "g3": "image/g3fax",
97
- "gbr": "application/rpki-ghostbusters",
98
- "geojson": "application/geo+json",
99
- "gif": "image/gif",
100
- "glb": "model/gltf-binary",
101
- "gltf": "model/gltf+json",
102
- "gml": "application/gml+xml",
103
- "gpx": "application/gpx+xml",
104
- "gram": "application/srgs",
105
- "grxml": "application/srgs+xml",
106
- "gxf": "application/gxf",
107
- "gz": "application/gzip",
108
- "h261": "video/h261",
109
- "h263": "video/h263",
110
- "h264": "video/h264",
111
- "heic": "image/heic",
112
- "heics": "image/heic-sequence",
113
- "heif": "image/heif",
114
- "heifs": "image/heif-sequence",
115
- "hej2": "image/hej2k",
116
- "held": "application/atsc-held+xml",
117
- "hjson": "application/hjson",
118
- "hlp": "application/winhlp",
119
- "hqx": "application/mac-binhex40",
120
- "hsj2": "image/hsj2",
121
- "htm": "text/html",
122
- "html": "text/html",
123
- "ics": "text/calendar",
124
- "ief": "image/ief",
125
- "ifb": "text/calendar",
126
- "iges": "model/iges",
127
- "igs": "model/iges",
128
- "img": "application/octet-stream",
129
- "in": "text/plain",
130
- "ini": "text/plain",
131
- "ink": "application/inkml+xml",
132
- "inkml": "application/inkml+xml",
133
- "ipfix": "application/ipfix",
134
- "iso": "application/octet-stream",
135
- "its": "application/its+xml",
136
- "jade": "text/jade",
137
- "jar": "application/java-archive",
138
- "jhc": "image/jphc",
139
- "jls": "image/jls",
140
- "jp2": "image/jp2",
141
- "jpe": "image/jpeg",
142
- "jpeg": "image/jpeg",
143
- "jpf": "image/jpx",
144
- "jpg": "image/jpeg",
145
- "jpg2": "image/jp2",
146
- "jpgm": "image/jpm",
147
- "jpgv": "video/jpeg",
148
- "jph": "image/jph",
149
- "jpm": "image/jpm",
150
- "jpx": "image/jpx",
151
- "js": "text/javascript",
152
- "json": "application/json",
153
- "json5": "application/json5",
154
- "jsonld": "application/ld+json",
155
- "jsonml": "application/jsonml+json",
156
- "jsx": "text/jsx",
157
- "jt": "model/jt",
158
- "jxl": "image/jxl",
159
- "jxr": "image/jxr",
160
- "jxra": "image/jxra",
161
- "jxrs": "image/jxrs",
162
- "jxs": "image/jxs",
163
- "jxsc": "image/jxsc",
164
- "jxsi": "image/jxsi",
165
- "jxss": "image/jxss",
166
- "kar": "audio/midi",
167
- "ktx": "image/ktx",
168
- "ktx2": "image/ktx2",
169
- "less": "text/less",
170
- "lgr": "application/lgr+xml",
171
- "list": "text/plain",
172
- "litcoffee": "text/coffeescript",
173
- "log": "text/plain",
174
- "lostxml": "application/lost+xml",
175
- "lrf": "application/octet-stream",
176
- "m1v": "video/mpeg",
177
- "m21": "application/mp21",
178
- "m2a": "audio/mpeg",
179
- "m2t": "video/mp2t",
180
- "m2ts": "video/mp2t",
181
- "m2v": "video/mpeg",
182
- "m3a": "audio/mpeg",
183
- "m4a": "audio/mp4",
184
- "m4p": "application/mp4",
185
- "m4s": "video/iso.segment",
186
- "ma": "application/mathematica",
187
- "mads": "application/mads+xml",
188
- "maei": "application/mmt-aei+xml",
189
- "man": "text/troff",
190
- "manifest": "text/cache-manifest",
191
- "map": "application/json",
192
- "mar": "application/octet-stream",
193
- "markdown": "text/markdown",
194
- "mathml": "application/mathml+xml",
195
- "mb": "application/mathematica",
196
- "mbox": "application/mbox",
197
- "md": "text/markdown",
198
- "mdx": "text/mdx",
199
- "me": "text/troff",
200
- "mesh": "model/mesh",
201
- "meta4": "application/metalink4+xml",
202
- "metalink": "application/metalink+xml",
203
- "mets": "application/mets+xml",
204
- "mft": "application/rpki-manifest",
205
- "mid": "audio/midi",
206
- "midi": "audio/midi",
207
- "mime": "message/rfc822",
208
- "mj2": "video/mj2",
209
- "mjp2": "video/mj2",
210
- "mjs": "text/javascript",
211
- "mml": "text/mathml",
212
- "mods": "application/mods+xml",
213
- "mov": "video/quicktime",
214
- "mp2": "audio/mpeg",
215
- "mp21": "application/mp21",
216
- "mp2a": "audio/mpeg",
217
- "mp3": "audio/mpeg",
218
- "mp4": "video/mp4",
219
- "mp4a": "audio/mp4",
220
- "mp4s": "application/mp4",
221
- "mp4v": "video/mp4",
222
- "mpd": "application/dash+xml",
223
- "mpe": "video/mpeg",
224
- "mpeg": "video/mpeg",
225
- "mpf": "application/media-policy-dataset+xml",
226
- "mpg": "video/mpeg",
227
- "mpg4": "video/mp4",
228
- "mpga": "audio/mpeg",
229
- "mpp": "application/dash-patch+xml",
230
- "mrc": "application/marc",
231
- "mrcx": "application/marcxml+xml",
232
- "ms": "text/troff",
233
- "mscml": "application/mediaservercontrol+xml",
234
- "msh": "model/mesh",
235
- "msi": "application/octet-stream",
236
- "msix": "application/msix",
237
- "msixbundle": "application/msixbundle",
238
- "msm": "application/octet-stream",
239
- "msp": "application/octet-stream",
240
- "mtl": "model/mtl",
241
- "mts": "video/mp2t",
242
- "musd": "application/mmt-usd+xml",
243
- "mxf": "application/mxf",
244
- "mxmf": "audio/mobile-xmf",
245
- "mxml": "application/xv+xml",
246
- "n3": "text/n3",
247
- "nb": "application/mathematica",
248
- "nq": "application/n-quads",
249
- "nt": "application/n-triples",
250
- "obj": "model/obj",
251
- "oda": "application/oda",
252
- "oga": "audio/ogg",
253
- "ogg": "audio/ogg",
254
- "ogv": "video/ogg",
255
- "ogx": "application/ogg",
256
- "omdoc": "application/omdoc+xml",
257
- "onepkg": "application/onenote",
258
- "onetmp": "application/onenote",
259
- "onetoc": "application/onenote",
260
- "onetoc2": "application/onenote",
261
- "opf": "application/oebps-package+xml",
262
- "opus": "audio/ogg",
263
- "otf": "font/otf",
264
- "owl": "application/rdf+xml",
265
- "oxps": "application/oxps",
266
- "p10": "application/pkcs10",
267
- "p7c": "application/pkcs7-mime",
268
- "p7m": "application/pkcs7-mime",
269
- "p7s": "application/pkcs7-signature",
270
- "p8": "application/pkcs8",
271
- "pdf": "application/pdf",
272
- "pfr": "application/font-tdpfr",
273
- "pgp": "application/pgp-encrypted",
274
- "pkg": "application/octet-stream",
275
- "pki": "application/pkixcmp",
276
- "pkipath": "application/pkix-pkipath",
277
- "pls": "application/pls+xml",
278
- "png": "image/png",
279
- "prc": "model/prc",
280
- "prf": "application/pics-rules",
281
- "provx": "application/provenance+xml",
282
- "ps": "application/postscript",
283
- "pskcxml": "application/pskc+xml",
284
- "pti": "image/prs.pti",
285
- "qt": "video/quicktime",
286
- "raml": "application/raml+yaml",
287
- "rapd": "application/route-apd+xml",
288
- "rdf": "application/rdf+xml",
289
- "relo": "application/p2p-overlay+xml",
290
- "rif": "application/reginfo+xml",
291
- "rl": "application/resource-lists+xml",
292
- "rld": "application/resource-lists-diff+xml",
293
- "rmi": "audio/midi",
294
- "rnc": "application/relax-ng-compact-syntax",
295
- "rng": "application/xml",
296
- "roa": "application/rpki-roa",
297
- "roff": "text/troff",
298
- "rq": "application/sparql-query",
299
- "rs": "application/rls-services+xml",
300
- "rsat": "application/atsc-rsat+xml",
301
- "rsd": "application/rsd+xml",
302
- "rsheet": "application/urc-ressheet+xml",
303
- "rss": "application/rss+xml",
304
- "rtf": "text/rtf",
305
- "rtx": "text/richtext",
306
- "rusd": "application/route-usd+xml",
307
- "s3m": "audio/s3m",
308
- "sbml": "application/sbml+xml",
309
- "scq": "application/scvp-cv-request",
310
- "scs": "application/scvp-cv-response",
311
- "sdp": "application/sdp",
312
- "senmlx": "application/senml+xml",
313
- "sensmlx": "application/sensml+xml",
314
- "ser": "application/java-serialized-object",
315
- "setpay": "application/set-payment-initiation",
316
- "setreg": "application/set-registration-initiation",
317
- "sgi": "image/sgi",
318
- "sgm": "text/sgml",
319
- "sgml": "text/sgml",
320
- "shex": "text/shex",
321
- "shf": "application/shf+xml",
322
- "shtml": "text/html",
323
- "sieve": "application/sieve",
324
- "sig": "application/pgp-signature",
325
- "sil": "audio/silk",
326
- "silo": "model/mesh",
327
- "siv": "application/sieve",
328
- "slim": "text/slim",
329
- "slm": "text/slim",
330
- "sls": "application/route-s-tsid+xml",
331
- "smi": "application/smil+xml",
332
- "smil": "application/smil+xml",
333
- "snd": "audio/basic",
334
- "so": "application/octet-stream",
335
- "spdx": "text/spdx",
336
- "spp": "application/scvp-vp-response",
337
- "spq": "application/scvp-vp-request",
338
- "spx": "audio/ogg",
339
- "sql": "application/sql",
340
- "sru": "application/sru+xml",
341
- "srx": "application/sparql-results+xml",
342
- "ssdl": "application/ssdl+xml",
343
- "ssml": "application/ssml+xml",
344
- "stk": "application/hyperstudio",
345
- "stl": "model/stl",
346
- "stpx": "model/step+xml",
347
- "stpxz": "model/step-xml+zip",
348
- "stpz": "model/step+zip",
349
- "styl": "text/stylus",
350
- "stylus": "text/stylus",
351
- "svg": "image/svg+xml",
352
- "svgz": "image/svg+xml",
353
- "swidtag": "application/swid+xml",
354
- "t": "text/troff",
355
- "t38": "image/t38",
356
- "td": "application/urc-targetdesc+xml",
357
- "tei": "application/tei+xml",
358
- "teicorpus": "application/tei+xml",
359
- "text": "text/plain",
360
- "tfi": "application/thraud+xml",
361
- "tfx": "image/tiff-fx",
362
- "tif": "image/tiff",
363
- "tiff": "image/tiff",
364
- "toml": "application/toml",
365
- "tr": "text/troff",
366
- "trig": "application/trig",
367
- "ts": "video/mp2t",
368
- "tsd": "application/timestamped-data",
369
- "tsv": "text/tab-separated-values",
370
- "ttc": "font/collection",
371
- "ttf": "font/ttf",
372
- "ttl": "text/turtle",
373
- "ttml": "application/ttml+xml",
374
- "txt": "text/plain",
375
- "u3d": "model/u3d",
376
- "u8dsn": "message/global-delivery-status",
377
- "u8hdr": "message/global-headers",
378
- "u8mdn": "message/global-disposition-notification",
379
- "u8msg": "message/global",
380
- "ubj": "application/ubjson",
381
- "uri": "text/uri-list",
382
- "uris": "text/uri-list",
383
- "urls": "text/uri-list",
384
- "vcard": "text/vcard",
385
- "vrml": "model/vrml",
386
- "vtt": "text/vtt",
387
- "vxml": "application/voicexml+xml",
388
- "war": "application/java-archive",
389
- "wasm": "application/wasm",
390
- "wav": "audio/wav",
391
- "weba": "audio/webm",
392
- "webm": "video/webm",
393
- "webmanifest": "application/manifest+json",
394
- "webp": "image/webp",
395
- "wgsl": "text/wgsl",
396
- "wgt": "application/widget",
397
- "wif": "application/watcherinfo+xml",
398
- "wmf": "image/wmf",
399
- "woff": "font/woff",
400
- "woff2": "font/woff2",
401
- "wrl": "model/vrml",
402
- "wsdl": "application/wsdl+xml",
403
- "wspolicy": "application/wspolicy+xml",
404
- "x3d": "model/x3d+xml",
405
- "x3db": "model/x3d+fastinfoset",
406
- "x3dbz": "model/x3d+binary",
407
- "x3dv": "model/x3d-vrml",
408
- "x3dvz": "model/x3d+vrml",
409
- "x3dz": "model/x3d+xml",
410
- "xaml": "application/xaml+xml",
411
- "xav": "application/xcap-att+xml",
412
- "xca": "application/xcap-caps+xml",
413
- "xcs": "application/calendar+xml",
414
- "xdf": "application/xcap-diff+xml",
415
- "xdssc": "application/dssc+xml",
416
- "xel": "application/xcap-el+xml",
417
- "xenc": "application/xenc+xml",
418
- "xer": "application/patch-ops-error+xml",
419
- "xfdf": "application/xfdf",
420
- "xht": "application/xhtml+xml",
421
- "xhtml": "application/xhtml+xml",
422
- "xhvml": "application/xv+xml",
423
- "xlf": "application/xliff+xml",
424
- "xm": "audio/xm",
425
- "xml": "text/xml",
426
- "xns": "application/xcap-ns+xml",
427
- "xop": "application/xop+xml",
428
- "xpl": "application/xproc+xml",
429
- "xsd": "application/xml",
430
- "xsf": "application/prs.xsf+xml",
431
- "xsl": "application/xml",
432
- "xslt": "application/xml",
433
- "xspf": "application/xspf+xml",
434
- "xvm": "application/xv+xml",
435
- "xvml": "application/xv+xml",
436
- "yaml": "text/yaml",
437
- "yang": "application/yang",
438
- "yin": "application/yin+xml",
439
- "yml": "text/yaml",
440
- "zip": "application/zip"
441
- };
442
- function lookup(extn) {
443
- let tmp = ("" + extn).trim().toLowerCase();
444
- let idx = tmp.lastIndexOf(".");
445
- return mimes[!~idx ? tmp : tmp.substring(++idx)];
446
- }
447
- //#endregion
448
- export { lookup as t };
@@ -1,32 +0,0 @@
1
- import { ViteHubError } from "@vite-hub/runtime";
2
- //#region src/core/errors.ts
3
- function sourceError(message, options) {
4
- return new ViteHubError("SOURCE_FAILED", message, options);
5
- }
6
- function sourceNotFoundError(name) {
7
- return new ViteHubError("SOURCE_NOT_FOUND", `[vitehub] Source "${name}" is not registered.`, { details: { name } });
8
- }
9
- function sourcePathError(path) {
10
- const publicPath = path.slice(0, 4096);
11
- return new ViteHubError("SOURCE_PATH_INVALID", `[vitehub] Source path escapes the source root: ${JSON.stringify(publicPath)}.`, { details: { path: publicPath } });
12
- }
13
- //#endregion
14
- //#region src/core/path.ts
15
- function normalizeSourcePath(path = "") {
16
- return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
17
- }
18
- function normalizeSafeSourcePath(path = "", options = {}) {
19
- const raw = path.replace(/\\/g, "/");
20
- const normalized = normalizeSourcePath(path);
21
- const parts = normalized.split("/").filter(Boolean);
22
- if (!options.allowEmpty && !normalized) throw sourcePathError(path);
23
- if (raw.startsWith("/") || /^[a-z]:/i.test(raw) || raw.includes("\0") || parts.some((part) => part === "." || part === "..")) throw sourcePathError(path);
24
- if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw sourcePathError(path);
25
- return normalized;
26
- }
27
- function decodeSourceContent(content, options) {
28
- if (options?.encoding === "binary") return typeof content === "string" ? new TextEncoder().encode(content) : content;
29
- return typeof content === "string" ? content : new TextDecoder().decode(content);
30
- }
31
- //#endregion
32
- export { sourceNotFoundError as a, sourceError as i, normalizeSafeSourcePath as n, sourcePathError as o, normalizeSourcePath as r, decodeSourceContent as t };