@cudoment/cudoc 0.1.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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/ast.d.ts +2 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +2 -0
- package/dist/ast.js.map +1 -0
- package/dist/embed.d.ts +5 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +5 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/core/ast/guards.d.ts +13 -0
- package/dist/internal/core/ast/guards.d.ts.map +1 -0
- package/dist/internal/core/ast/guards.js +21 -0
- package/dist/internal/core/ast/guards.js.map +1 -0
- package/dist/internal/core/ast/index.d.ts +6 -0
- package/dist/internal/core/ast/index.d.ts.map +1 -0
- package/dist/internal/core/ast/index.js +4 -0
- package/dist/internal/core/ast/index.js.map +1 -0
- package/dist/internal/core/ast/types.d.ts +49 -0
- package/dist/internal/core/ast/types.d.ts.map +1 -0
- package/dist/internal/core/ast/types.js +25 -0
- package/dist/internal/core/ast/types.js.map +1 -0
- package/dist/internal/core/ast/validate.d.ts +16 -0
- package/dist/internal/core/ast/validate.d.ts.map +1 -0
- package/dist/internal/core/ast/validate.js +90 -0
- package/dist/internal/core/ast/validate.js.map +1 -0
- package/dist/internal/core/index.d.ts +9 -0
- package/dist/internal/core/index.d.ts.map +1 -0
- package/dist/internal/core/index.js +7 -0
- package/dist/internal/core/index.js.map +1 -0
- package/dist/internal/core/mdx/index.d.ts +2 -0
- package/dist/internal/core/mdx/index.d.ts.map +1 -0
- package/dist/internal/core/mdx/index.js +2 -0
- package/dist/internal/core/mdx/index.js.map +1 -0
- package/dist/internal/core/mdx/jsx.d.ts +25 -0
- package/dist/internal/core/mdx/jsx.d.ts.map +1 -0
- package/dist/internal/core/mdx/jsx.js +43 -0
- package/dist/internal/core/mdx/jsx.js.map +1 -0
- package/dist/internal/core/query/index.d.ts +7 -0
- package/dist/internal/core/query/index.d.ts.map +1 -0
- package/dist/internal/core/query/index.js +4 -0
- package/dist/internal/core/query/index.js.map +1 -0
- package/dist/internal/core/query/nodes.d.ts +61 -0
- package/dist/internal/core/query/nodes.d.ts.map +1 -0
- package/dist/internal/core/query/nodes.js +151 -0
- package/dist/internal/core/query/nodes.js.map +1 -0
- package/dist/internal/core/query/sections.d.ts +72 -0
- package/dist/internal/core/query/sections.d.ts.map +1 -0
- package/dist/internal/core/query/sections.js +178 -0
- package/dist/internal/core/query/sections.js.map +1 -0
- package/dist/internal/core/query/tables.d.ts +32 -0
- package/dist/internal/core/query/tables.d.ts.map +1 -0
- package/dist/internal/core/query/tables.js +46 -0
- package/dist/internal/core/query/tables.js.map +1 -0
- package/dist/internal/core/selectors.d.ts +41 -0
- package/dist/internal/core/selectors.d.ts.map +1 -0
- package/dist/internal/core/selectors.js +87 -0
- package/dist/internal/core/selectors.js.map +1 -0
- package/dist/internal/core/syntax/delimiters.d.ts +45 -0
- package/dist/internal/core/syntax/delimiters.d.ts.map +1 -0
- package/dist/internal/core/syntax/delimiters.js +81 -0
- package/dist/internal/core/syntax/delimiters.js.map +1 -0
- package/dist/internal/core/syntax/heading-metadata.d.ts +59 -0
- package/dist/internal/core/syntax/heading-metadata.d.ts.map +1 -0
- package/dist/internal/core/syntax/heading-metadata.js +178 -0
- package/dist/internal/core/syntax/heading-metadata.js.map +1 -0
- package/dist/internal/core/syntax/index.d.ts +5 -0
- package/dist/internal/core/syntax/index.d.ts.map +1 -0
- package/dist/internal/core/syntax/index.js +3 -0
- package/dist/internal/core/syntax/index.js.map +1 -0
- package/dist/internal/core/walk.d.ts +40 -0
- package/dist/internal/core/walk.d.ts.map +1 -0
- package/dist/internal/core/walk.js +53 -0
- package/dist/internal/core/walk.js.map +1 -0
- package/dist/mdx.d.ts +2 -0
- package/dist/mdx.d.ts.map +1 -0
- package/dist/mdx.js +2 -0
- package/dist/mdx.js.map +1 -0
- package/dist/node/export-ast.d.ts +52 -0
- package/dist/node/export-ast.d.ts.map +1 -0
- package/dist/node/export-ast.js +117 -0
- package/dist/node/export-ast.js.map +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/load-ast-file.d.ts +9 -0
- package/dist/node/load-ast-file.d.ts.map +1 -0
- package/dist/node/load-ast-file.js +32 -0
- package/dist/node/load-ast-file.js.map +1 -0
- package/dist/node/load-ast.d.ts +11 -0
- package/dist/node/load-ast.d.ts.map +1 -0
- package/dist/node/load-ast.js +17 -0
- package/dist/node/load-ast.js.map +1 -0
- package/dist/node/paths.d.ts +31 -0
- package/dist/node/paths.d.ts.map +1 -0
- package/dist/node/paths.js +54 -0
- package/dist/node/paths.js.map +1 -0
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +2 -0
- package/dist/query.js.map +1 -0
- package/dist/syntax.d.ts +2 -0
- package/dist/syntax.d.ts.map +1 -0
- package/dist/syntax.js +2 -0
- package/dist/syntax.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes the compiled AST of each document to JSON.
|
|
3
|
+
*
|
|
4
|
+
* The tree comes from the host's real compilation rather than a second parse.
|
|
5
|
+
* Re-parsing MDX to reproduce it would drift, because the MDX compiler applies
|
|
6
|
+
* its own transforms before user plugins ever run.
|
|
7
|
+
*/
|
|
8
|
+
import type { Transformer } from "unified";
|
|
9
|
+
import type { Root } from "mdast";
|
|
10
|
+
import { resolveAstVersion } from "../internal/core/index.js";
|
|
11
|
+
import type { AstVersionOptions, ValidateAstOptions } from "../internal/core/index.js";
|
|
12
|
+
import { type PathOptions, type ResolvedPathOptions } from "./paths.js";
|
|
13
|
+
type AstNode = Record<string, unknown>;
|
|
14
|
+
/** Properties dropped from stored JSON: neither survives a round trip usefully. */
|
|
15
|
+
export declare const DEFAULT_STRIPPED_PROPERTIES: string[];
|
|
16
|
+
/** Node types dropped entirely. ESM export nodes carry no document content. */
|
|
17
|
+
export declare const DEFAULT_DROPPED_NODE_TYPES: string[];
|
|
18
|
+
export type ExportAstOptions = PathOptions & {
|
|
19
|
+
/** Properties removed from every node. */
|
|
20
|
+
strip?: string[];
|
|
21
|
+
/** Node types removed together with their subtree. */
|
|
22
|
+
dropNodeTypes?: string[];
|
|
23
|
+
/** Where the schema version is written, and what it is. */
|
|
24
|
+
version?: AstVersionOptions;
|
|
25
|
+
/** Validate the contract before writing. On by default. */
|
|
26
|
+
validate?: boolean;
|
|
27
|
+
/** Cell element names to validate when layout rules use custom components. */
|
|
28
|
+
tableCellElement?: ValidateAstOptions["tableCellElement"];
|
|
29
|
+
/**
|
|
30
|
+
* Sink for the serialized document. Defaults to an atomic file write.
|
|
31
|
+
* Intended for programmatic use; a config passed through a bundler cannot
|
|
32
|
+
* carry a function.
|
|
33
|
+
*/
|
|
34
|
+
write?: (filePath: string, contents: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export type ExportAstContext = {
|
|
37
|
+
pathOptions: ResolvedPathOptions;
|
|
38
|
+
strip: Set<string>;
|
|
39
|
+
dropNodeTypes: Set<string>;
|
|
40
|
+
version: ReturnType<typeof resolveAstVersion>;
|
|
41
|
+
validate: boolean;
|
|
42
|
+
tableCellElement: ValidateAstOptions["tableCellElement"];
|
|
43
|
+
write: (filePath: string, contents: string) => void;
|
|
44
|
+
};
|
|
45
|
+
export declare const resolveExportAstOptions: (options?: ExportAstOptions) => ExportAstContext;
|
|
46
|
+
/** Strips properties and drops node types in a single pass. */
|
|
47
|
+
export declare const projectTree: (node: unknown, context: ExportAstContext) => unknown;
|
|
48
|
+
/** Builds the object written for one document, without touching the disk. */
|
|
49
|
+
export declare const buildExportedAst: (tree: unknown, context: ExportAstContext) => AstNode;
|
|
50
|
+
declare const exportAst: (options?: ExportAstOptions) => Transformer<Root, Root>;
|
|
51
|
+
export default exportAst;
|
|
52
|
+
//# sourceMappingURL=export-ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-ast.d.ts","sourceRoot":"","sources":["../../src/node/export-ast.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EACL,iBAAiB,EAElB,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAA;AAEnB,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEtC,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,UAAyB,CAAA;AAEjE,+EAA+E;AAC/E,eAAO,MAAM,0BAA0B,UAAe,CAAA;AAEtD,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC3C,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;IACzD;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACrD,CAAA;AAgCD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,mBAAmB,CAAA;IAChC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,OAAO,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;IAC7C,QAAQ,EAAE,OAAO,CAAA;IACjB,gBAAgB,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;IACxD,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACpD,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,UAAS,gBAAqB,KAC7B,gBAQD,CAAA;AAEF,+DAA+D;AAC/D,eAAO,MAAM,WAAW,GACtB,MAAM,OAAO,EACb,SAAS,gBAAgB,KACxB,OAsBF,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,GAC3B,MAAM,OAAO,EACb,SAAS,gBAAgB,KACxB,OAyBF,CAAA;AAED,QAAA,MAAM,SAAS,GACZ,UAAS,gBAAqB,KAAG,WAAW,CAAC,IAAI,EAAE,IAAI,CAoBvD,CAAA;AAEH,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes the compiled AST of each document to JSON.
|
|
3
|
+
*
|
|
4
|
+
* The tree comes from the host's real compilation rather than a second parse.
|
|
5
|
+
* Re-parsing MDX to reproduce it would drift, because the MDX compiler applies
|
|
6
|
+
* its own transforms before user plugins ever run.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import crypto from "node:crypto";
|
|
11
|
+
import { resolveAstVersion, validateAstContract, } from "../internal/core/index.js";
|
|
12
|
+
import { getOutputPath, resolvePathOptions, } from "./paths.js";
|
|
13
|
+
/** Properties dropped from stored JSON: neither survives a round trip usefully. */
|
|
14
|
+
export const DEFAULT_STRIPPED_PROPERTIES = ["position", "estree"];
|
|
15
|
+
/** Node types dropped entirely. ESM export nodes carry no document content. */
|
|
16
|
+
export const DEFAULT_DROPPED_NODE_TYPES = ["mdxjsEsm"];
|
|
17
|
+
const writeJsonAtomically = (outputFile, contents) => {
|
|
18
|
+
const temporaryFile = path.join(path.dirname(outputFile), `.${path.basename(outputFile)}.${process.pid}.${crypto.randomUUID()}.tmp`);
|
|
19
|
+
let operationFailed = false;
|
|
20
|
+
try {
|
|
21
|
+
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
22
|
+
fs.writeFileSync(temporaryFile, contents, "utf-8");
|
|
23
|
+
fs.renameSync(temporaryFile, outputFile);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
operationFailed = true;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (fs.existsSync(temporaryFile)) {
|
|
31
|
+
try {
|
|
32
|
+
fs.unlinkSync(temporaryFile);
|
|
33
|
+
}
|
|
34
|
+
catch (cleanupError) {
|
|
35
|
+
// A cleanup failure must not mask the original error.
|
|
36
|
+
if (!operationFailed)
|
|
37
|
+
throw cleanupError;
|
|
38
|
+
console.error(`cudoc: failed to remove temporary file ${temporaryFile}`, cleanupError);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export const resolveExportAstOptions = (options = {}) => ({
|
|
44
|
+
pathOptions: resolvePathOptions(options),
|
|
45
|
+
strip: new Set(options.strip ?? DEFAULT_STRIPPED_PROPERTIES),
|
|
46
|
+
dropNodeTypes: new Set(options.dropNodeTypes ?? DEFAULT_DROPPED_NODE_TYPES),
|
|
47
|
+
version: resolveAstVersion(options.version),
|
|
48
|
+
validate: options.validate !== false,
|
|
49
|
+
tableCellElement: options.tableCellElement,
|
|
50
|
+
write: options.write ?? writeJsonAtomically,
|
|
51
|
+
});
|
|
52
|
+
/** Strips properties and drops node types in a single pass. */
|
|
53
|
+
export const projectTree = (node, context) => {
|
|
54
|
+
if (!node || typeof node !== "object")
|
|
55
|
+
return node;
|
|
56
|
+
if (Array.isArray(node)) {
|
|
57
|
+
return node.flatMap((child) => {
|
|
58
|
+
const projected = projectTree(child, context);
|
|
59
|
+
return projected === undefined ? [] : [projected];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const type = node.type;
|
|
63
|
+
if (typeof type === "string" && context.dropNodeTypes.has(type)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const result = {};
|
|
67
|
+
for (const [key, value] of Object.entries(node)) {
|
|
68
|
+
if (context.strip.has(key))
|
|
69
|
+
continue;
|
|
70
|
+
const projected = projectTree(value, context);
|
|
71
|
+
if (projected !== undefined)
|
|
72
|
+
result[key] = projected;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
/** Builds the object written for one document, without touching the disk. */
|
|
77
|
+
export const buildExportedAst = (tree, context) => {
|
|
78
|
+
const projected = projectTree(tree, context);
|
|
79
|
+
if (!projected || typeof projected !== "object") {
|
|
80
|
+
throw new Error("cudoc: the AST root did not survive projection");
|
|
81
|
+
}
|
|
82
|
+
const exportTree = projected;
|
|
83
|
+
const currentData = exportTree.data && typeof exportTree.data === "object"
|
|
84
|
+
? exportTree.data
|
|
85
|
+
: {};
|
|
86
|
+
exportTree.data = {
|
|
87
|
+
...currentData,
|
|
88
|
+
[context.version.field]: context.version.value,
|
|
89
|
+
};
|
|
90
|
+
if (context.validate) {
|
|
91
|
+
validateAstContract(exportTree, {
|
|
92
|
+
requireVersion: true,
|
|
93
|
+
version: context.version,
|
|
94
|
+
tableCellElement: context.tableCellElement,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return exportTree;
|
|
98
|
+
};
|
|
99
|
+
const exportAst = (options = {}) => (tree, file) => {
|
|
100
|
+
const context = resolveExportAstOptions(options);
|
|
101
|
+
const outputFile = file.path
|
|
102
|
+
? getOutputPath(file.path, context.pathOptions)
|
|
103
|
+
: null;
|
|
104
|
+
if (!outputFile)
|
|
105
|
+
return tree;
|
|
106
|
+
try {
|
|
107
|
+
const exportTree = buildExportedAst(tree, context);
|
|
108
|
+
context.write(outputFile, JSON.stringify(exportTree));
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(`cudoc: failed to export ${file.path}:`, error instanceof Error ? error.message : String(error));
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
return tree;
|
|
115
|
+
};
|
|
116
|
+
export default exportAst;
|
|
117
|
+
//# sourceMappingURL=export-ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export-ast.js","sourceRoot":"","sources":["../../src/node/export-ast.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,MAAM,MAAM,aAAa,CAAA;AAIhC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAKlC,OAAO,EACL,aAAa,EACb,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AAInB,mFAAmF;AACnF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;AAEjE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,UAAU,CAAC,CAAA;AAqBtD,MAAM,mBAAmB,GAAG,CAAC,UAAkB,EAAE,QAAgB,EAAE,EAAE;IACnE,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAC7B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,MAAM,CAC1E,CAAA;IAED,IAAI,eAAe,GAAG,KAAK,CAAA;IAC3B,IAAI,CAAC;QACH,EAAE,CAAC,S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AC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CACX,2BAA2B,IAAI,CAAC,IAAI,GAAG,EACvC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAA;QACD,MAAM,KAAK,CAAA;IACb,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAEH,eAAe,SAAS,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default, default as exportAst, buildExportedAst, projectTree, resolveExportAstOptions, DEFAULT_DROPPED_NODE_TYPES, DEFAULT_STRIPPED_PROPERTIES, } from "./export-ast.js";
|
|
2
|
+
export type { ExportAstContext, ExportAstOptions } from "./export-ast.js";
|
|
3
|
+
export { loadAst, loadAstFile } from "./load-ast.js";
|
|
4
|
+
export type { LoadAstOptions } from "./load-ast.js";
|
|
5
|
+
export { getOutputPath, getRelativeOutputPath, resolvePathOptions, DEFAULT_EXTENSIONS, DEFAULT_OUTPUT_ROOT, DEFAULT_SOURCE_ROOT, } from "./paths.js";
|
|
6
|
+
export type { PathOptions, ResolvedPathOptions } from "./paths.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,OAAO,IAAI,SAAS,EACpB,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACpD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default, default as exportAst, buildExportedAst, projectTree, resolveExportAstOptions, DEFAULT_DROPPED_NODE_TYPES, DEFAULT_STRIPPED_PROPERTIES, } from "./export-ast.js";
|
|
2
|
+
export { loadAst, loadAstFile } from "./load-ast.js";
|
|
3
|
+
export { getOutputPath, getRelativeOutputPath, resolvePathOptions, DEFAULT_EXTENSIONS, DEFAULT_OUTPUT_ROOT, DEFAULT_SOURCE_ROOT, } from "./paths.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,OAAO,IAAI,SAAS,EACpB,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AstVersionOptions, ExportedCudocAstRoot, ValidateAstOptions } from "../internal/core/index.js";
|
|
2
|
+
export type LoadAstOptions = {
|
|
3
|
+
version?: AstVersionOptions;
|
|
4
|
+
validate?: boolean;
|
|
5
|
+
tableCellElement?: ValidateAstOptions["tableCellElement"];
|
|
6
|
+
};
|
|
7
|
+
/** Loads and validates one stored document. */
|
|
8
|
+
export declare const loadAstFile: (filePath: string, { version, validate, tableCellElement }?: LoadAstOptions) => ExportedCudocAstRoot;
|
|
9
|
+
//# sourceMappingURL=load-ast-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-ast-file.d.ts","sourceRoot":"","sources":["../../src/node/load-ast-file.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gBAAgB,CAAC,EAAE,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;CAC1D,CAAA;AAED,+CAA+C;AAC/C,eAAO,MAAM,WAAW,GACtB,UAAU,MAAM,EAChB,0CAAgD,cAAmB,KAClE,oBA+BF,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** File loading without the build-time output path helpers. */
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { resolveAstVersion, validateAstContract, } from "../internal/core/index.js";
|
|
4
|
+
/** Loads and validates one stored document. */
|
|
5
|
+
export const loadAstFile = (filePath, { version, validate = true, tableCellElement } = {}) => {
|
|
6
|
+
let fileContent;
|
|
7
|
+
try {
|
|
8
|
+
fileContent = fs.readFileSync(filePath, "utf-8");
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error?.code === "ENOENT") {
|
|
12
|
+
throw new Error(`cudoc: stored AST not found: ${filePath}`);
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = JSON.parse(fileContent);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error(`cudoc: stored AST is not valid JSON (${error instanceof Error ? error.message : String(error)}): ${filePath}`);
|
|
22
|
+
}
|
|
23
|
+
if (validate) {
|
|
24
|
+
validateAstContract(parsed, {
|
|
25
|
+
requireVersion: true,
|
|
26
|
+
version: resolveAstVersion(version),
|
|
27
|
+
tableCellElement,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return parsed;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=load-ast-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-ast-file.js","sourceRoot":"","sources":["../../src/node/load-ast-file.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAalC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,QAAgB,EAChB,EAAE,OAAO,EAAE,QAAQ,GAAG,IAAI,EAAE,gBAAgB,KAAqB,EAAE,EAC7C,EAAE;IACxB,IAAI,WAAmB,CAAA;IACvB,IAAI,CAAC;QACH,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA2C,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAA;QAC7D,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;IAED,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,wCACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,MAAM,QAAQ,EAAE,CACjB,CAAA;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,mBAAmB,CAAC,MAAM,EAAE;YAC1B,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC;YACnC,gBAAgB;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAA8B,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExportedCudocAstRoot } from "../internal/core/index.js";
|
|
2
|
+
import { type PathOptions } from "./paths.js";
|
|
3
|
+
import { type LoadAstOptions } from "./load-ast-file.js";
|
|
4
|
+
export { loadAstFile } from "./load-ast-file.js";
|
|
5
|
+
export type { LoadAstOptions } from "./load-ast-file.js";
|
|
6
|
+
/**
|
|
7
|
+
* Loads the document stored for a source-relative document path, such as
|
|
8
|
+
* `en/app-setting/app`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const loadAst: (documentPath: string, options?: LoadAstOptions & PathOptions) => ExportedCudocAstRoot;
|
|
11
|
+
//# sourceMappingURL=load-ast.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-ast.d.ts","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD;;;GAGG;AACH,eAAO,MAAM,OAAO,GAClB,cAAc,MAAM,EACpB,UAAS,cAAc,GAAG,WAAgB,KACzC,oBAWF,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Source-relative document lookup, built on the file loader. */
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolvePathOptions, } from "./paths.js";
|
|
4
|
+
import { loadAstFile } from "./load-ast-file.js";
|
|
5
|
+
export { loadAstFile } from "./load-ast-file.js";
|
|
6
|
+
/**
|
|
7
|
+
* Loads the document stored for a source-relative document path, such as
|
|
8
|
+
* `en/app-setting/app`.
|
|
9
|
+
*/
|
|
10
|
+
export const loadAst = (documentPath, options = {}) => {
|
|
11
|
+
const pathOptions = resolvePathOptions(options);
|
|
12
|
+
const projectRoot = pathOptions.cwd ?? process.cwd();
|
|
13
|
+
const normalized = documentPath.replace(/^[/\\]+/, "").replace(/\.json$/i, "");
|
|
14
|
+
const filePath = path.join(projectRoot, pathOptions.outDir, `${normalized}.json`);
|
|
15
|
+
return loadAstFile(filePath, options);
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=load-ast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-ast.js","sourceRoot":"","sources":["../../src/node/load-ast.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EACL,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAuB,MAAM,oBAAoB,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,YAAoB,EACpB,UAAwC,EAAE,EACpB,EAAE;IACxB,MAAM,WAAW,GAAwB,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACpE,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IACpD,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAC9E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,WAAW,EACX,WAAW,CAAC,MAAM,EAClB,GAAG,UAAU,OAAO,CACrB,CAAA;IAED,OAAO,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a source document path onto its output path.
|
|
3
|
+
*
|
|
4
|
+
* The mapping is described with a source root and an output root rather than a
|
|
5
|
+
* glob, so it stays serializable and needs no matcher dependency.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_SOURCE_ROOT = "docs";
|
|
8
|
+
export declare const DEFAULT_OUTPUT_ROOT = ".cudoc/ast";
|
|
9
|
+
export declare const DEFAULT_EXTENSIONS: string[];
|
|
10
|
+
export type PathOptions = {
|
|
11
|
+
/** Directory holding the documents, relative to `cwd`. */
|
|
12
|
+
sourceRoot?: string;
|
|
13
|
+
/** Directory the JSON is written to, relative to `cwd`. */
|
|
14
|
+
outDir?: string;
|
|
15
|
+
/** Source extensions that are exported. Compared case-insensitively. */
|
|
16
|
+
extensions?: string[];
|
|
17
|
+
/** Project root. Defaults to `process.cwd()` at call time. */
|
|
18
|
+
cwd?: string;
|
|
19
|
+
};
|
|
20
|
+
export type ResolvedPathOptions = Required<Omit<PathOptions, "cwd">> & {
|
|
21
|
+
cwd: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
export declare const resolvePathOptions: (options?: PathOptions) => ResolvedPathOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The path of the output file relative to `outDir`, or `null` when the source
|
|
26
|
+
* is outside the source root or is not an exported extension.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getRelativeOutputPath: (sourceFilePath: string, options: ResolvedPathOptions) => string | null;
|
|
29
|
+
/** The absolute output path, or `null` when the source is not exported. */
|
|
30
|
+
export declare const getOutputPath: (sourceFilePath: string, options: ResolvedPathOptions) => string | null;
|
|
31
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/node/paths.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,mBAAmB,SAAS,CAAA;AACzC,eAAO,MAAM,mBAAmB,eAAe,CAAA;AAC/C,eAAO,MAAM,kBAAkB,UAAW,CAAA;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wEAAwE;IACxE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,8DAA8D;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,GAAG;IACrE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CACxB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,UAAS,WAAgB,KACxB,mBAoBF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,gBAAgB,MAAM,EACtB,SAAS,mBAAmB,KAC3B,MAAM,GAAG,IAoBX,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,aAAa,GACxB,gBAAgB,MAAM,EACtB,SAAS,mBAAmB,KAC3B,MAAM,GAAG,IAMX,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps a source document path onto its output path.
|
|
3
|
+
*
|
|
4
|
+
* The mapping is described with a source root and an output root rather than a
|
|
5
|
+
* glob, so it stays serializable and needs no matcher dependency.
|
|
6
|
+
*/
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
export const DEFAULT_SOURCE_ROOT = "docs";
|
|
9
|
+
export const DEFAULT_OUTPUT_ROOT = ".cudoc/ast";
|
|
10
|
+
export const DEFAULT_EXTENSIONS = [".mdx"];
|
|
11
|
+
export const resolvePathOptions = (options = {}) => {
|
|
12
|
+
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
13
|
+
if (!Array.isArray(extensions) ||
|
|
14
|
+
extensions.length === 0 ||
|
|
15
|
+
!extensions.every((value) => typeof value === "string" && value.startsWith("."))) {
|
|
16
|
+
throw new TypeError('extensions must be a non-empty array of strings starting with "."');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
sourceRoot: options.sourceRoot ?? DEFAULT_SOURCE_ROOT,
|
|
20
|
+
outDir: options.outDir ?? DEFAULT_OUTPUT_ROOT,
|
|
21
|
+
extensions: extensions.map((value) => value.toLowerCase()),
|
|
22
|
+
cwd: options.cwd,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The path of the output file relative to `outDir`, or `null` when the source
|
|
27
|
+
* is outside the source root or is not an exported extension.
|
|
28
|
+
*/
|
|
29
|
+
export const getRelativeOutputPath = (sourceFilePath, options) => {
|
|
30
|
+
const projectRoot = options.cwd ?? process.cwd();
|
|
31
|
+
const sourceRoot = path.resolve(projectRoot, options.sourceRoot);
|
|
32
|
+
const resolvedSource = path.resolve(projectRoot, sourceFilePath);
|
|
33
|
+
const relativeSource = path.relative(sourceRoot, resolvedSource);
|
|
34
|
+
const outsideSourceRoot = relativeSource === "" ||
|
|
35
|
+
relativeSource === ".." ||
|
|
36
|
+
relativeSource.startsWith(`..${path.sep}`) ||
|
|
37
|
+
path.isAbsolute(relativeSource);
|
|
38
|
+
if (outsideSourceRoot)
|
|
39
|
+
return null;
|
|
40
|
+
if (!options.extensions.includes(path.extname(relativeSource).toLowerCase())) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const parsed = path.parse(relativeSource);
|
|
44
|
+
return path.join(parsed.dir, `${parsed.name}.json`);
|
|
45
|
+
};
|
|
46
|
+
/** The absolute output path, or `null` when the source is not exported. */
|
|
47
|
+
export const getOutputPath = (sourceFilePath, options) => {
|
|
48
|
+
const relativeOutputPath = getRelativeOutputPath(sourceFilePath, options);
|
|
49
|
+
if (!relativeOutputPath)
|
|
50
|
+
return null;
|
|
51
|
+
const projectRoot = options.cwd ?? process.cwd();
|
|
52
|
+
return path.join(projectRoot, options.outDir, relativeOutputPath);
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/node/paths.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAA;AACzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAA;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAA;AAiB1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,UAAuB,EAAE,EACJ,EAAE;IACvB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAA;IAC3D,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAC1B,UAAU,CAAC,MAAM,KAAK,CAAC;QACvB,CAAC,UAAU,CAAC,KAAK,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAC9D,EACD,CAAC;QACD,MAAM,IAAI,SAAS,CACjB,mEAAmE,CACpE,CAAA;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,mBAAmB;QACrD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,mBAAmB;QAC7C,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAC1D,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAA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WAAW,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;IAChD,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;AACnE,CAAC,CAAA"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA"}
|
package/dist/syntax.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA"}
|
package/dist/syntax.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cudoment/cudoc",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable document ASTs: validation, queries, export and loading for cross-document embedding.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cudoc",
|
|
7
|
+
"mdast",
|
|
8
|
+
"mdx",
|
|
9
|
+
"markdown",
|
|
10
|
+
"ast",
|
|
11
|
+
"documentation"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/cudoment/cudoc/tree/main/packages/cudoc#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/cudoment/cudoc/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/cudoment/cudoc.git",
|
|
20
|
+
"directory": "packages/cudoc"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "cudoment",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./ast": {
|
|
36
|
+
"types": "./dist/ast.d.ts",
|
|
37
|
+
"default": "./dist/ast.js"
|
|
38
|
+
},
|
|
39
|
+
"./syntax": {
|
|
40
|
+
"types": "./dist/syntax.d.ts",
|
|
41
|
+
"default": "./dist/syntax.js"
|
|
42
|
+
},
|
|
43
|
+
"./mdx": {
|
|
44
|
+
"types": "./dist/mdx.d.ts",
|
|
45
|
+
"default": "./dist/mdx.js"
|
|
46
|
+
},
|
|
47
|
+
"./query": {
|
|
48
|
+
"types": "./dist/query.d.ts",
|
|
49
|
+
"default": "./dist/query.js"
|
|
50
|
+
},
|
|
51
|
+
"./embed": {
|
|
52
|
+
"types": "./dist/embed.d.ts",
|
|
53
|
+
"default": "./dist/embed.js"
|
|
54
|
+
},
|
|
55
|
+
"./node/export-ast": {
|
|
56
|
+
"types": "./dist/node/export-ast.d.ts",
|
|
57
|
+
"default": "./dist/node/export-ast.js"
|
|
58
|
+
},
|
|
59
|
+
"./node/load-ast-file": {
|
|
60
|
+
"types": "./dist/node/load-ast-file.d.ts",
|
|
61
|
+
"default": "./dist/node/load-ast-file.js"
|
|
62
|
+
},
|
|
63
|
+
"./node/paths": {
|
|
64
|
+
"types": "./dist/node/paths.d.ts",
|
|
65
|
+
"default": "./dist/node/paths.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist",
|
|
70
|
+
"README.md",
|
|
71
|
+
"LICENSE"
|
|
72
|
+
],
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=20"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "tsc --build",
|
|
78
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
79
|
+
},
|
|
80
|
+
"dependencies": {
|
|
81
|
+
"mdast-util-mdx-jsx": "^3.2.0",
|
|
82
|
+
"unist-util-visit": "^5.0.0",
|
|
83
|
+
"unified": "^11.0.5",
|
|
84
|
+
"vfile": "^6.0.3"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@types/mdast": "^4.0.4"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"@types/mdast": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|