@shikijs/vitepress-twoslash 3.22.0 → 4.0.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/dist/cache-fs.d.mts +10 -10
- package/dist/cache-fs.mjs +21 -25
- package/dist/cache-inline/index.d.mts +32 -31
- package/dist/cache-inline/index.mjs +298 -314
- package/dist/client.d.mts +6 -6
- package/dist/client.mjs +84 -88
- package/dist/index.d.mts +5 -8
- package/dist/index.mjs +170 -210
- package/dist/types-CKSDIC5E.d.mts +34 -0
- package/package.json +11 -8
- package/dist/shared/vitepress-twoslash.CBxCru0j.d.mts +0 -33
package/dist/cache-fs.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { TwoslashTypesCache } from
|
|
1
|
+
import { TwoslashTypesCache } from "@shikijs/twoslash";
|
|
2
2
|
|
|
3
|
+
//#region src/cache-fs.d.ts
|
|
3
4
|
interface FileSystemTypeResultCacheOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The directory to store the cache files.
|
|
7
|
+
*
|
|
8
|
+
* @default '.vitepress/cache/twoslash'
|
|
9
|
+
*/
|
|
10
|
+
dir?: string;
|
|
10
11
|
}
|
|
11
12
|
declare function createFileSystemTypesCache(options?: FileSystemTypeResultCacheOptions): TwoslashTypesCache;
|
|
12
|
-
|
|
13
|
-
export { createFileSystemTypesCache };
|
|
14
|
-
export type { FileSystemTypeResultCacheOptions };
|
|
13
|
+
//#endregion
|
|
14
|
+
export { FileSystemTypeResultCacheOptions, createFileSystemTypesCache };
|
package/dist/cache-fs.mjs
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import { createHash } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import process from
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
5
|
|
|
6
|
+
//#region src/cache-fs.ts
|
|
6
7
|
function createFileSystemTypesCache(options = {}) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const hash = createHash("SHA256").update(code).digest("hex").slice(0, 12);
|
|
22
|
-
const filePath = join(dir, `${hash}.json`);
|
|
23
|
-
const json = JSON.stringify(data);
|
|
24
|
-
writeFileSync(filePath, json, { encoding: "utf-8" });
|
|
25
|
-
}
|
|
26
|
-
};
|
|
8
|
+
const dir = resolve(process.cwd(), options.dir ?? ".vitepress/cache/twoslash");
|
|
9
|
+
return {
|
|
10
|
+
init() {
|
|
11
|
+
mkdirSync(dir, { recursive: true });
|
|
12
|
+
},
|
|
13
|
+
read(code) {
|
|
14
|
+
const filePath = join(dir, `${createHash("SHA256").update(code).digest("hex").slice(0, 12)}.json`);
|
|
15
|
+
if (!existsSync(filePath)) return null;
|
|
16
|
+
return JSON.parse(readFileSync(filePath, { encoding: "utf-8" }));
|
|
17
|
+
},
|
|
18
|
+
write(code, data) {
|
|
19
|
+
writeFileSync(join(dir, `${createHash("SHA256").update(code).digest("hex").slice(0, 12)}.json`), JSON.stringify(data), { encoding: "utf-8" });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createFileSystemTypesCache };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import '@shikijs/twoslash/core';
|
|
4
|
-
import 'twoslash-vue';
|
|
5
|
-
import '@shikijs/twoslash';
|
|
1
|
+
import { t as VitePressPluginTwoslashOptions } from "../types-CKSDIC5E.mjs";
|
|
2
|
+
import { UserConfig } from "vitepress";
|
|
6
3
|
|
|
4
|
+
//#region src/cache-inline/markdown-fence.d.ts
|
|
7
5
|
interface MarkdownFenceSourceMap {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
path: string;
|
|
7
|
+
from: number;
|
|
8
|
+
to: number;
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* Maps markdown code to its source map positions.
|
|
@@ -17,32 +15,35 @@ interface MarkdownFenceSourceMap {
|
|
|
17
15
|
*/
|
|
18
16
|
type MarkdownFencesSourceMapper = (code: string, path: string) => Map<number, MarkdownFenceSourceMap>;
|
|
19
17
|
interface MarkdownFenceSourceMapCodec {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Injects source map data into the markdown source.
|
|
20
|
+
* @param code markdown source
|
|
21
|
+
* @param path markdown file path
|
|
22
|
+
* @returns markdown source with injected source maps
|
|
23
|
+
*/
|
|
24
|
+
injectToMarkdown: (code: string, path: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Extract source map from fence code snippet.
|
|
27
|
+
* @param code fence code snippet
|
|
28
|
+
* @returns extracted code and source map
|
|
29
|
+
*/
|
|
30
|
+
extractFromFence: (code: string) => {
|
|
31
|
+
code: string;
|
|
32
|
+
sourceMap: MarkdownFenceSourceMap | null;
|
|
33
|
+
};
|
|
36
34
|
}
|
|
37
|
-
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/cache-inline/index.d.ts
|
|
38
37
|
interface TwoslashInlineCacheOptions {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
sourceMapper?: MarkdownFencesSourceMapper;
|
|
39
|
+
sourceMapCodec?: MarkdownFenceSourceMapCodec;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* @experimental This API is experimental and may be changed in the future.
|
|
44
43
|
*/
|
|
45
|
-
declare function createTwoslashWithInlineCache(twoslashOptions?: VitePressPluginTwoslashOptions, {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
declare function createTwoslashWithInlineCache(twoslashOptions?: VitePressPluginTwoslashOptions, {
|
|
45
|
+
sourceMapper,
|
|
46
|
+
sourceMapCodec
|
|
47
|
+
}?: TwoslashInlineCacheOptions): (config: UserConfig) => UserConfig;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { TwoslashInlineCacheOptions, createTwoslashWithInlineCache };
|