@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.
@@ -1,14 +1,14 @@
1
- import { TwoslashTypesCache } from '@shikijs/twoslash';
1
+ import { TwoslashTypesCache } from "@shikijs/twoslash";
2
2
 
3
+ //#region src/cache-fs.d.ts
3
4
  interface FileSystemTypeResultCacheOptions {
4
- /**
5
- * The directory to store the cache files.
6
- *
7
- * @default '.vitepress/cache/twoslash'
8
- */
9
- dir?: string;
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 'node:crypto';
2
- import { writeFileSync, existsSync, readFileSync, mkdirSync } from 'node:fs';
3
- import { resolve, join } from 'node:path';
4
- import process from 'node:process';
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
- const dir = resolve(process.cwd(), options.dir ?? ".vitepress/cache/twoslash");
8
- return {
9
- init() {
10
- mkdirSync(dir, { recursive: true });
11
- },
12
- read(code) {
13
- const hash = createHash("SHA256").update(code).digest("hex").slice(0, 12);
14
- const filePath = join(dir, `${hash}.json`);
15
- if (!existsSync(filePath)) {
16
- return null;
17
- }
18
- return JSON.parse(readFileSync(filePath, { encoding: "utf-8" }));
19
- },
20
- write(code, data) {
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
- export { createFileSystemTypesCache };
24
+ //#endregion
25
+ export { createFileSystemTypesCache };
@@ -1,13 +1,11 @@
1
- import { UserConfig } from 'vitepress';
2
- import { V as VitePressPluginTwoslashOptions } from '../shared/vitepress-twoslash.CBxCru0j.mjs';
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
- path: string;
9
- from: number;
10
- to: number;
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
- * Injects source map data into the markdown source.
22
- * @param code markdown source
23
- * @param injects map of inject positions to source maps
24
- * @returns markdown source with injected source maps
25
- */
26
- injectToMarkdown: (code: string, path: string) => string;
27
- /**
28
- * Extract source map from fence code snippet.
29
- * @param code fence code snippet
30
- * @returns extracted code and source map
31
- */
32
- extractFromFence: (code: string) => {
33
- code: string;
34
- sourceMap: MarkdownFenceSourceMap | null;
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
- sourceMapper?: MarkdownFencesSourceMapper;
40
- sourceMapCodec?: MarkdownFenceSourceMapCodec;
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, { sourceMapper, sourceMapCodec, }?: TwoslashInlineCacheOptions): (config: UserConfig) => UserConfig;
46
-
47
- export { createTwoslashWithInlineCache };
48
- export type { TwoslashInlineCacheOptions };
44
+ declare function createTwoslashWithInlineCache(twoslashOptions?: VitePressPluginTwoslashOptions, {
45
+ sourceMapper,
46
+ sourceMapCodec
47
+ }?: TwoslashInlineCacheOptions): (config: UserConfig) => UserConfig;
48
+ //#endregion
49
+ export { TwoslashInlineCacheOptions, createTwoslashWithInlineCache };