@driftsys/markspec 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.
- package/README.md +32 -8
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +43 -0
- package/esm/compiler/mod.d.ts.map +1 -0
- package/esm/compiler/mod.js +163 -0
- package/esm/compiler/schema.d.ts +38 -0
- package/esm/compiler/schema.d.ts.map +1 -0
- package/esm/compiler/schema.js +44 -0
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +48 -0
- package/esm/config/mod.d.ts.map +1 -0
- package/esm/config/mod.js +243 -0
- package/esm/formatter/mod.d.ts +65 -0
- package/esm/formatter/mod.d.ts.map +1 -0
- package/esm/formatter/mod.js +306 -0
- package/esm/mod.d.ts +19 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +18 -0
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +381 -0
- package/esm/model/mod.d.ts.map +1 -0
- package/esm/model/mod.js +73 -0
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +48 -0
- package/esm/parser/attributes.d.ts.map +1 -0
- package/esm/parser/attributes.js +131 -0
- package/esm/parser/captions.d.ts +25 -0
- package/esm/parser/captions.d.ts.map +1 -0
- package/esm/parser/captions.js +148 -0
- package/esm/parser/directives.d.ts +29 -0
- package/esm/parser/directives.d.ts.map +1 -0
- package/esm/parser/directives.js +88 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.d.ts +22 -0
- package/esm/parser/grammars.d.ts.map +1 -0
- package/esm/parser/grammars.js +70 -0
- package/esm/parser/markdown.d.ts +32 -0
- package/esm/parser/markdown.d.ts.map +1 -0
- package/esm/parser/markdown.js +225 -0
- package/esm/parser/mod.d.ts +73 -0
- package/esm/parser/mod.d.ts.map +1 -0
- package/esm/parser/mod.js +89 -0
- package/esm/parser/references.d.ts +24 -0
- package/esm/parser/references.d.ts.map +1 -0
- package/esm/parser/references.js +71 -0
- package/esm/parser/remark.d.ts +9 -0
- package/esm/parser/remark.d.ts.map +1 -0
- package/esm/parser/remark.js +11 -0
- package/esm/parser/source.d.ts +33 -0
- package/esm/parser/source.d.ts.map +1 -0
- package/esm/parser/source.js +192 -0
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +830 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +23 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +14 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.d.ts +31 -0
- package/esm/reporter/mod.d.ts.map +1 -0
- package/esm/reporter/mod.js +173 -0
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +44 -0
- package/esm/validator/mod.d.ts.map +1 -0
- package/esm/validator/mod.js +214 -0
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +8 -1
- package/script/_dnt.polyfills.d.ts +101 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +130 -0
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +43 -0
- package/script/compiler/mod.d.ts.map +1 -0
- package/script/compiler/mod.js +169 -0
- package/script/compiler/schema.d.ts +38 -0
- package/script/compiler/schema.d.ts.map +1 -0
- package/script/compiler/schema.js +47 -0
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +48 -0
- package/script/config/mod.d.ts.map +1 -0
- package/script/config/mod.js +250 -0
- package/script/formatter/mod.d.ts +65 -0
- package/script/formatter/mod.d.ts.map +1 -0
- package/script/formatter/mod.js +313 -0
- package/script/mod.d.ts +19 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +65 -2
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +381 -0
- package/script/model/mod.d.ts.map +1 -0
- package/script/model/mod.js +83 -0
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +48 -0
- package/script/parser/attributes.d.ts.map +1 -0
- package/script/parser/attributes.js +137 -0
- package/script/parser/captions.d.ts +25 -0
- package/script/parser/captions.d.ts.map +1 -0
- package/script/parser/captions.js +151 -0
- package/script/parser/directives.d.ts +29 -0
- package/script/parser/directives.d.ts.map +1 -0
- package/script/parser/directives.js +91 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.d.ts +22 -0
- package/script/parser/grammars.d.ts.map +1 -0
- package/script/parser/grammars.js +77 -0
- package/script/parser/markdown.d.ts +32 -0
- package/script/parser/markdown.d.ts.map +1 -0
- package/script/parser/markdown.js +228 -0
- package/script/parser/mod.d.ts +73 -0
- package/script/parser/mod.d.ts.map +1 -0
- package/script/parser/mod.js +101 -0
- package/script/parser/references.d.ts +24 -0
- package/script/parser/references.d.ts.map +1 -0
- package/script/parser/references.js +74 -0
- package/script/parser/remark.d.ts +9 -0
- package/script/parser/remark.d.ts.map +1 -0
- package/script/parser/remark.js +17 -0
- package/script/parser/source.d.ts +33 -0
- package/script/parser/source.d.ts.map +1 -0
- package/script/parser/source.js +198 -0
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +833 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +23 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +31 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.d.ts +31 -0
- package/script/reporter/mod.d.ts.map +1 -0
- package/script/reporter/mod.js +176 -0
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +44 -0
- package/script/validator/mod.d.ts.map +1 -0
- package/script/validator/mod.js +231 -0
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- package/script/validator/value_types.js +129 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/source
|
|
3
|
+
*
|
|
4
|
+
* Source-code doc-comment parser. Extracts MarkSpec entry blocks from doc
|
|
5
|
+
* comments in Rust, Kotlin, C, C++, and Java source files. Delegates parsed
|
|
6
|
+
* content to the markdown parser for entry extraction.
|
|
7
|
+
*/
|
|
8
|
+
import Parser from "web-tree-sitter";
|
|
9
|
+
import { parseMarkdown } from "./markdown.js";
|
|
10
|
+
/**
|
|
11
|
+
* Parse a source file and return entries extracted from doc comments.
|
|
12
|
+
*
|
|
13
|
+
* Uses tree-sitter to parse the source, walks the AST to find doc comment
|
|
14
|
+
* nodes, strips comment prefixes, and delegates to the markdown parser for
|
|
15
|
+
* entry extraction. Doc comments that don't contain entry blocks are ignored.
|
|
16
|
+
*
|
|
17
|
+
* @param content - Source file text
|
|
18
|
+
* @param options - Parse options (language grammar, file path)
|
|
19
|
+
*/
|
|
20
|
+
export function parseSource(content, options) {
|
|
21
|
+
const file = options.file ?? "<unknown>";
|
|
22
|
+
const parser = new Parser();
|
|
23
|
+
parser.setLanguage(options.language);
|
|
24
|
+
const tree = parser.parse(content);
|
|
25
|
+
const blocks = [];
|
|
26
|
+
walkForDocComments(tree.rootNode, blocks);
|
|
27
|
+
const entries = [];
|
|
28
|
+
for (const block of blocks) {
|
|
29
|
+
const markdown = wrapAsListItem(block.lines);
|
|
30
|
+
const parsed = parseMarkdown(markdown, { file });
|
|
31
|
+
for (const entry of parsed) {
|
|
32
|
+
const location = {
|
|
33
|
+
file,
|
|
34
|
+
line: block.startLine,
|
|
35
|
+
column: block.startColumn,
|
|
36
|
+
};
|
|
37
|
+
entries.push({
|
|
38
|
+
...entry,
|
|
39
|
+
source: "doc-comment",
|
|
40
|
+
location,
|
|
41
|
+
properties: {
|
|
42
|
+
file: {
|
|
43
|
+
path: file,
|
|
44
|
+
line: block.startLine,
|
|
45
|
+
column: block.startColumn,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
tree.delete();
|
|
52
|
+
parser.delete();
|
|
53
|
+
return { entries };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Recursively walk the tree-sitter AST and collect doc comment blocks.
|
|
57
|
+
*
|
|
58
|
+
* At each level, consecutive `line_comment` nodes with
|
|
59
|
+
* `outer_doc_comment_marker` are grouped into a single block.
|
|
60
|
+
* `block_comment` nodes starting with `/**` become individual blocks.
|
|
61
|
+
* Non-comment children are recursed into so that doc comments inside
|
|
62
|
+
* `mod`, `impl`, and other nested scopes are discovered.
|
|
63
|
+
*/
|
|
64
|
+
function walkForDocComments(node, blocks) {
|
|
65
|
+
let currentLines = [];
|
|
66
|
+
let currentStartLine = 0;
|
|
67
|
+
let currentStartColumn = 0;
|
|
68
|
+
let lastRow = -2;
|
|
69
|
+
function flushLineBlock() {
|
|
70
|
+
if (currentLines.length > 0) {
|
|
71
|
+
blocks.push({
|
|
72
|
+
lines: currentLines,
|
|
73
|
+
startLine: currentStartLine,
|
|
74
|
+
startColumn: currentStartColumn,
|
|
75
|
+
});
|
|
76
|
+
currentLines = [];
|
|
77
|
+
lastRow = -2;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
81
|
+
const child = node.child(i);
|
|
82
|
+
if (child.type === "line_comment" && isOuterDocComment(child)) {
|
|
83
|
+
const row = child.startPosition.row;
|
|
84
|
+
// Not consecutive — flush previous block
|
|
85
|
+
if (currentLines.length > 0 && row !== lastRow + 1) {
|
|
86
|
+
flushLineBlock();
|
|
87
|
+
}
|
|
88
|
+
if (currentLines.length === 0) {
|
|
89
|
+
currentStartLine = row + 1; // 1-based
|
|
90
|
+
currentStartColumn = child.startPosition.column + 1; // 1-based
|
|
91
|
+
}
|
|
92
|
+
currentLines.push(stripLineCommentPrefix(child));
|
|
93
|
+
lastRow = row;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (child.type === "block_comment" && child.text.startsWith("/**")) {
|
|
97
|
+
flushLineBlock();
|
|
98
|
+
blocks.push({
|
|
99
|
+
lines: stripBlockCommentPrefix(child.text),
|
|
100
|
+
startLine: child.startPosition.row + 1,
|
|
101
|
+
startColumn: child.startPosition.column + 1,
|
|
102
|
+
});
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// Non-comment node — flush pending line comments, then recurse.
|
|
106
|
+
flushLineBlock();
|
|
107
|
+
if (child.childCount > 0) {
|
|
108
|
+
walkForDocComments(child, blocks);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
flushLineBlock();
|
|
112
|
+
}
|
|
113
|
+
/** Check if a line_comment node is a `///` outer doc comment. */
|
|
114
|
+
function isOuterDocComment(node) {
|
|
115
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
116
|
+
if (node.child(i).type === "outer_doc_comment_marker")
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Strip the `///` prefix from a line comment node.
|
|
123
|
+
* Uses the `doc_comment` child if available, otherwise strips manually.
|
|
124
|
+
*/
|
|
125
|
+
function stripLineCommentPrefix(node) {
|
|
126
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
127
|
+
const child = node.child(i);
|
|
128
|
+
if (child.type === "doc_comment") {
|
|
129
|
+
let text = child.text.replace(/\n$/, "");
|
|
130
|
+
// Strip one leading space (convention: `/// text`)
|
|
131
|
+
if (text.startsWith(" "))
|
|
132
|
+
text = text.slice(1);
|
|
133
|
+
return text;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Fallback: manual prefix stripping
|
|
137
|
+
const text = node.text.replace(/\n$/, "");
|
|
138
|
+
if (text.startsWith("/// "))
|
|
139
|
+
return text.slice(4);
|
|
140
|
+
if (text.startsWith("///"))
|
|
141
|
+
return text.slice(3);
|
|
142
|
+
return text;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Strip block comment delimiters and leading ` * ` prefixes.
|
|
146
|
+
* Returns cleaned lines.
|
|
147
|
+
*/
|
|
148
|
+
function stripBlockCommentPrefix(text) {
|
|
149
|
+
const rawLines = text.split("\n");
|
|
150
|
+
const result = [];
|
|
151
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
152
|
+
const trimmed = rawLines[i].trim();
|
|
153
|
+
// Skip opening `/**` line (may have content after it)
|
|
154
|
+
if (i === 0) {
|
|
155
|
+
const afterOpening = trimmed.slice(3).trim();
|
|
156
|
+
if (afterOpening && afterOpening !== "/") {
|
|
157
|
+
result.push(afterOpening);
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// Skip closing `*/`
|
|
162
|
+
if (i === rawLines.length - 1 && trimmed === "*/") {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
// Strip leading ` * ` or ` *`
|
|
166
|
+
if (trimmed.startsWith("* ")) {
|
|
167
|
+
result.push(trimmed.slice(2));
|
|
168
|
+
}
|
|
169
|
+
else if (trimmed === "*") {
|
|
170
|
+
result.push("");
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
result.push(trimmed);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Wrap cleaned doc comment lines as a Markdown list item so the
|
|
180
|
+
* existing `parseMarkdown()` can extract entries.
|
|
181
|
+
*
|
|
182
|
+
* Doc comments use `[DISPLAY_ID] Title` without the `- ` bullet.
|
|
183
|
+
* This wraps to `- [DISPLAY_ID] Title\n\n body...` which parseMarkdown
|
|
184
|
+
* recognizes as an entry block.
|
|
185
|
+
*/
|
|
186
|
+
function wrapAsListItem(lines) {
|
|
187
|
+
if (lines.length === 0)
|
|
188
|
+
return "";
|
|
189
|
+
const first = `- ${lines[0]}`;
|
|
190
|
+
const rest = lines.slice(1).map((line) => line === "" ? "" : ` ${line}`);
|
|
191
|
+
return [first, ...rest].join("\n");
|
|
192
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/cache
|
|
3
|
+
*
|
|
4
|
+
* XDG-compliant cache directory resolution for profile storage.
|
|
5
|
+
* Profiles fetched from git or npm are cached globally so they can
|
|
6
|
+
* be shared across projects.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Environment variables consulted for cache directory resolution.
|
|
10
|
+
* Injectable for testing — production code passes `Deno.env.toObject()`.
|
|
11
|
+
*/
|
|
12
|
+
export interface CacheEnv {
|
|
13
|
+
readonly XDG_CACHE_HOME?: string;
|
|
14
|
+
readonly HOME?: string;
|
|
15
|
+
readonly LOCALAPPDATA?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the global markspec cache directory (XDG-compliant).
|
|
19
|
+
*
|
|
20
|
+
* - `$XDG_CACHE_HOME/markspec` if set (any platform)
|
|
21
|
+
* - macOS: `~/Library/Caches/markspec`
|
|
22
|
+
* - Windows: `%LOCALAPPDATA%/markspec/cache`
|
|
23
|
+
* - Linux/other: `~/.cache/markspec`
|
|
24
|
+
*
|
|
25
|
+
* @param env - Environment variables (injectable for tests)
|
|
26
|
+
* @param platform - OS platform string (injectable for tests; defaults to `Deno.build.os`)
|
|
27
|
+
*/
|
|
28
|
+
export declare function cacheDir(env?: CacheEnv, platform?: string): string;
|
|
29
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/profile/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACtB,GAAG,CAAC,EAAE,QAAQ,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAsBR"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/cache
|
|
3
|
+
*
|
|
4
|
+
* XDG-compliant cache directory resolution for profile storage.
|
|
5
|
+
* Profiles fetched from git or npm are cached globally so they can
|
|
6
|
+
* be shared across projects.
|
|
7
|
+
*/
|
|
8
|
+
import { join } from "@std/path";
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the global markspec cache directory (XDG-compliant).
|
|
11
|
+
*
|
|
12
|
+
* - `$XDG_CACHE_HOME/markspec` if set (any platform)
|
|
13
|
+
* - macOS: `~/Library/Caches/markspec`
|
|
14
|
+
* - Windows: `%LOCALAPPDATA%/markspec/cache`
|
|
15
|
+
* - Linux/other: `~/.cache/markspec`
|
|
16
|
+
*
|
|
17
|
+
* @param env - Environment variables (injectable for tests)
|
|
18
|
+
* @param platform - OS platform string (injectable for tests; defaults to `Deno.build.os`)
|
|
19
|
+
*/
|
|
20
|
+
export function cacheDir(env, platform) {
|
|
21
|
+
const e = env ?? envFromDeno();
|
|
22
|
+
const os = platform ?? Deno.build.os;
|
|
23
|
+
if (e.XDG_CACHE_HOME) {
|
|
24
|
+
return join(e.XDG_CACHE_HOME, "markspec");
|
|
25
|
+
}
|
|
26
|
+
if (os === "darwin") {
|
|
27
|
+
const home = e.HOME ?? "/tmp";
|
|
28
|
+
return join(home, "Library", "Caches", "markspec");
|
|
29
|
+
}
|
|
30
|
+
if (os === "windows") {
|
|
31
|
+
const localAppData = e.LOCALAPPDATA ??
|
|
32
|
+
join(e.HOME ?? "C:\\Users\\default", "AppData", "Local");
|
|
33
|
+
return join(localAppData, "markspec", "cache");
|
|
34
|
+
}
|
|
35
|
+
// Linux and others — XDG default
|
|
36
|
+
const home = e.HOME ?? "/tmp";
|
|
37
|
+
return join(home, ".cache", "markspec");
|
|
38
|
+
}
|
|
39
|
+
function envFromDeno() {
|
|
40
|
+
return {
|
|
41
|
+
XDG_CACHE_HOME: Deno.env.get("XDG_CACHE_HOME"),
|
|
42
|
+
HOME: Deno.env.get("HOME"),
|
|
43
|
+
LOCALAPPDATA: Deno.env.get("LOCALAPPDATA"),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/chain
|
|
3
|
+
*
|
|
4
|
+
* Profile chain loader. Walks the `extends:` pointer from a leaf specifier
|
|
5
|
+
* up to the root, producing a multi-tier {@linkcode ProfileChain} ordered
|
|
6
|
+
* root → leaf.
|
|
7
|
+
*
|
|
8
|
+
* Supports both local and git specifiers, with cycle + depth detection. Git
|
|
9
|
+
* specifiers route through {@linkcode resolveGitSpecifier} (per-project
|
|
10
|
+
* shallow+sparse clone cache); local specifiers route through
|
|
11
|
+
* {@linkcode resolveLocalSpecifier}. The chain's {@linkcode EffectiveProfile}
|
|
12
|
+
* is produced by {@linkcode mergeChain}.
|
|
13
|
+
*/
|
|
14
|
+
import type { ReadFile } from "../config/mod.js";
|
|
15
|
+
import type { Diagnostic, ProfileChain, ProfileSpecifier } from "../model/mod.js";
|
|
16
|
+
import type { AppendFile, RunGit } from "./git-cache.js";
|
|
17
|
+
/** Result of loading a profile chain. */
|
|
18
|
+
export interface LoadChainResult {
|
|
19
|
+
readonly chain: ProfileChain | null;
|
|
20
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
21
|
+
}
|
|
22
|
+
/** Options accepted by {@linkcode loadChain}. */
|
|
23
|
+
export interface LoadChainOptions {
|
|
24
|
+
readonly runGit?: RunGit;
|
|
25
|
+
readonly appendFile?: AppendFile;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load a profile chain from a specifier, walking the `extends:` pointer up
|
|
29
|
+
* to the root. The returned chain's tiers are ordered root → leaf, so
|
|
30
|
+
* `tiers[0]` is the ultimate ancestor and `tiers[last]` is the leaf
|
|
31
|
+
* specified by the caller.
|
|
32
|
+
*
|
|
33
|
+
* @param specifier - The leaf specifier (from `.markspec.yaml`)
|
|
34
|
+
* @param contextDir - Directory the specifier was declared in (for local
|
|
35
|
+
* path resolution)
|
|
36
|
+
* @param projectRoot - Absolute path of the project root (used to locate
|
|
37
|
+
* the `.markspec/cache/` directory for git specifiers)
|
|
38
|
+
* @param readFile - File reader abstraction
|
|
39
|
+
* @param opts - Injectable runners for git-cache operations (optional)
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadChain(specifier: ProfileSpecifier, contextDir: string, projectRoot: string, readFile: ReadFile, opts?: LoadChainOptions): Promise<LoadChainResult>;
|
|
42
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/profile/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,UAAU,EAGV,YAAY,EACZ,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAYzD,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAC7B,SAAS,EAAE,gBAAgB,EAC3B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,eAAe,CAAC,CA+G1B"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/chain
|
|
3
|
+
*
|
|
4
|
+
* Profile chain loader. Walks the `extends:` pointer from a leaf specifier
|
|
5
|
+
* up to the root, producing a multi-tier {@linkcode ProfileChain} ordered
|
|
6
|
+
* root → leaf.
|
|
7
|
+
*
|
|
8
|
+
* Supports both local and git specifiers, with cycle + depth detection. Git
|
|
9
|
+
* specifiers route through {@linkcode resolveGitSpecifier} (per-project
|
|
10
|
+
* shallow+sparse clone cache); local specifiers route through
|
|
11
|
+
* {@linkcode resolveLocalSpecifier}. The chain's {@linkcode EffectiveProfile}
|
|
12
|
+
* is produced by {@linkcode mergeChain}.
|
|
13
|
+
*/
|
|
14
|
+
import { resolve as resolvePath } from "@std/path";
|
|
15
|
+
import { parseManifest } from "./manifest.js";
|
|
16
|
+
import { mergeChain } from "./merge.js";
|
|
17
|
+
import { resolveGitSpecifier, resolveLocalSpecifier, } from "./resolver.js";
|
|
18
|
+
/** Maximum number of tiers allowed in an `extends:` chain. */
|
|
19
|
+
const MAX_CHAIN_DEPTH = 20;
|
|
20
|
+
/**
|
|
21
|
+
* Load a profile chain from a specifier, walking the `extends:` pointer up
|
|
22
|
+
* to the root. The returned chain's tiers are ordered root → leaf, so
|
|
23
|
+
* `tiers[0]` is the ultimate ancestor and `tiers[last]` is the leaf
|
|
24
|
+
* specified by the caller.
|
|
25
|
+
*
|
|
26
|
+
* @param specifier - The leaf specifier (from `.markspec.yaml`)
|
|
27
|
+
* @param contextDir - Directory the specifier was declared in (for local
|
|
28
|
+
* path resolution)
|
|
29
|
+
* @param projectRoot - Absolute path of the project root (used to locate
|
|
30
|
+
* the `.markspec/cache/` directory for git specifiers)
|
|
31
|
+
* @param readFile - File reader abstraction
|
|
32
|
+
* @param opts - Injectable runners for git-cache operations (optional)
|
|
33
|
+
*/
|
|
34
|
+
export async function loadChain(specifier, contextDir, projectRoot, readFile, opts = {}) {
|
|
35
|
+
const diagnostics = [];
|
|
36
|
+
// Walk extends: chain. Accumulate tiers leaf-first, reverse at the end.
|
|
37
|
+
const tiersLeafFirst = [];
|
|
38
|
+
const visited = new Set(); // canonical specifier key
|
|
39
|
+
let cursorSpec = specifier;
|
|
40
|
+
let cursorDir = contextDir;
|
|
41
|
+
while (cursorSpec !== undefined) {
|
|
42
|
+
const key = specifierKey(cursorSpec, cursorDir);
|
|
43
|
+
if (visited.has(key)) {
|
|
44
|
+
diagnostics.push({
|
|
45
|
+
code: "PROFILE-LOAD-004",
|
|
46
|
+
severity: "error",
|
|
47
|
+
message: `profile extends: cycle detected at ${stringifySpec(cursorSpec)} ` +
|
|
48
|
+
`(already visited in this chain)`,
|
|
49
|
+
location: { file: "<specifier>", line: 1, column: 1 },
|
|
50
|
+
});
|
|
51
|
+
return { chain: null, diagnostics };
|
|
52
|
+
}
|
|
53
|
+
visited.add(key);
|
|
54
|
+
if (tiersLeafFirst.length >= MAX_CHAIN_DEPTH) {
|
|
55
|
+
diagnostics.push({
|
|
56
|
+
code: "PROFILE-LOAD-005",
|
|
57
|
+
severity: "error",
|
|
58
|
+
message: `profile extends: chain exceeds maximum depth (${MAX_CHAIN_DEPTH})`,
|
|
59
|
+
location: { file: "<specifier>", line: 1, column: 1 },
|
|
60
|
+
});
|
|
61
|
+
return { chain: null, diagnostics };
|
|
62
|
+
}
|
|
63
|
+
let resolved;
|
|
64
|
+
if (cursorSpec.kind === "git") {
|
|
65
|
+
resolved = await resolveGitSpecifier(cursorSpec, projectRoot, readFile, diagnostics, { runGit: opts.runGit, appendFile: opts.appendFile });
|
|
66
|
+
}
|
|
67
|
+
else if (cursorSpec.kind === "npm") {
|
|
68
|
+
const { resolveNpmSpecifier } = await import("./npm.js");
|
|
69
|
+
const { cacheDir: cacheDirFn } = await import("./cache.js");
|
|
70
|
+
resolved = await resolveNpmSpecifier(cursorSpec, diagnostics, {
|
|
71
|
+
cacheRoot: cacheDirFn(),
|
|
72
|
+
readFile,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
resolved = await resolveLocalSpecifier(cursorSpec, cursorDir, readFile, diagnostics);
|
|
77
|
+
}
|
|
78
|
+
if (!resolved) {
|
|
79
|
+
return { chain: null, diagnostics };
|
|
80
|
+
}
|
|
81
|
+
const parsed = parseManifest(resolved.rawYaml, resolved.sourcePath);
|
|
82
|
+
diagnostics.push(...parsed.diagnostics);
|
|
83
|
+
if (!parsed.manifest) {
|
|
84
|
+
return { chain: null, diagnostics };
|
|
85
|
+
}
|
|
86
|
+
const tier = {
|
|
87
|
+
id: parsed.manifest.id,
|
|
88
|
+
version: parsed.manifest.version,
|
|
89
|
+
specifier: cursorSpec,
|
|
90
|
+
manifest: parsed.manifest,
|
|
91
|
+
sourcePath: resolved.sourcePath,
|
|
92
|
+
baseDir: resolved.baseDir,
|
|
93
|
+
};
|
|
94
|
+
tiersLeafFirst.push(tier);
|
|
95
|
+
// Advance cursor to the parent, if any.
|
|
96
|
+
if (parsed.manifest.extends !== undefined) {
|
|
97
|
+
cursorSpec = parsed.manifest.extends;
|
|
98
|
+
cursorDir = resolved.baseDir;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
cursorSpec = undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Reverse so tiers[0] = root parent, tiers[last] = leaf child.
|
|
105
|
+
const tiers = tiersLeafFirst.reverse();
|
|
106
|
+
// Build a temporary chain shape to feed into mergeChain. It reads only
|
|
107
|
+
// .tiers; the placeholder effective is ignored by merge.
|
|
108
|
+
const stubChain = {
|
|
109
|
+
tiers,
|
|
110
|
+
effective: buildPlaceholderEffective(tiers),
|
|
111
|
+
};
|
|
112
|
+
const mergeResult = mergeChain(stubChain);
|
|
113
|
+
diagnostics.push(...mergeResult.diagnostics);
|
|
114
|
+
if (!mergeResult.effective) {
|
|
115
|
+
return { chain: null, diagnostics };
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
chain: { tiers, effective: mergeResult.effective },
|
|
119
|
+
diagnostics,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Canonical cycle-detection key for a resolved specifier. Two specifiers that
|
|
124
|
+
* resolve to the same tier are canonicalized to the same key:
|
|
125
|
+
*
|
|
126
|
+
* - Local specifiers key on the absolute resolved directory (after
|
|
127
|
+
* normalization of `.` / `..`).
|
|
128
|
+
* - Git specifiers key on `(repo, tag, subpath)`, which is what the git cache
|
|
129
|
+
* itself uses — two specifiers that hit the same cache entry are the same
|
|
130
|
+
* tier.
|
|
131
|
+
*
|
|
132
|
+
* Note: this does NOT canonicalize symlinks for local specifiers. Two
|
|
133
|
+
* different symlinked paths pointing at the same profile will only be caught
|
|
134
|
+
* by MAX_CHAIN_DEPTH, which emits PROFILE-LOAD-005 instead of
|
|
135
|
+
* PROFILE-LOAD-004. Acceptable for v1 since `Deno.realPath` would require an
|
|
136
|
+
* additional I/O round-trip and a filesystem shim for the test mock reader.
|
|
137
|
+
*/
|
|
138
|
+
function specifierKey(spec, contextDir) {
|
|
139
|
+
if (spec.kind === "local") {
|
|
140
|
+
return `local:${resolvePath(contextDir, spec.path)}`;
|
|
141
|
+
}
|
|
142
|
+
if (spec.kind === "git") {
|
|
143
|
+
return `git:${spec.repo}#${spec.tag}|${spec.subpath ?? ""}`;
|
|
144
|
+
}
|
|
145
|
+
if (spec.kind === "npm") {
|
|
146
|
+
const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
|
|
147
|
+
return `npm:${pkg}@${spec.range}`;
|
|
148
|
+
}
|
|
149
|
+
const _exhaustive = spec;
|
|
150
|
+
throw new Error(`Unknown specifier kind`);
|
|
151
|
+
}
|
|
152
|
+
/** Human-readable one-liner for a specifier (used in diagnostic messages). */
|
|
153
|
+
function stringifySpec(spec) {
|
|
154
|
+
if (spec.kind === "local") {
|
|
155
|
+
return spec.path;
|
|
156
|
+
}
|
|
157
|
+
if (spec.kind === "git") {
|
|
158
|
+
return `git+${spec.repo}#${spec.tag}`;
|
|
159
|
+
}
|
|
160
|
+
if (spec.kind === "npm") {
|
|
161
|
+
const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
|
|
162
|
+
return `npm:${pkg}@${spec.range}`;
|
|
163
|
+
}
|
|
164
|
+
const _exhaustive = spec;
|
|
165
|
+
throw new Error(`Unknown specifier kind`);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Build a placeholder EffectiveProfile used only as a stub input when
|
|
169
|
+
* constructing the {@linkcode ProfileChain} shape we hand to
|
|
170
|
+
* {@linkcode mergeChain}. `mergeChain` reads only `.tiers`, so the stub
|
|
171
|
+
* contents are irrelevant.
|
|
172
|
+
*/
|
|
173
|
+
function buildPlaceholderEffective(tiers) {
|
|
174
|
+
const leafOrigin = tiers[tiers.length - 1]?.id ?? "<unknown>";
|
|
175
|
+
return {
|
|
176
|
+
required: { value: [], origin: leafOrigin },
|
|
177
|
+
attributes: new Map(),
|
|
178
|
+
labels: { value: [], origin: leafOrigin },
|
|
179
|
+
colors: new Map(),
|
|
180
|
+
identified: {
|
|
181
|
+
required: { value: [], origin: leafOrigin },
|
|
182
|
+
attributes: new Map(),
|
|
183
|
+
traceability: new Map(),
|
|
184
|
+
},
|
|
185
|
+
referenced: {
|
|
186
|
+
required: { value: [], origin: leafOrigin },
|
|
187
|
+
attributes: new Map(),
|
|
188
|
+
traceability: new Map(),
|
|
189
|
+
},
|
|
190
|
+
types: new Map(),
|
|
191
|
+
documents: { types: new Map(), frontMatter: new Map() },
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/git-cache
|
|
3
|
+
*
|
|
4
|
+
* Cache + `git` CLI infrastructure for git-specifier resolution.
|
|
5
|
+
*
|
|
6
|
+
* The cache lives under `<project-root>/.markspec/cache/<sha>/` where `<sha>`
|
|
7
|
+
* is the sha256 of a canonical `(host, repo, subpath, tag)` tuple. Because
|
|
8
|
+
* the spec requires tag-only specifiers and tags are (by convention)
|
|
9
|
+
* immutable, cached content never needs refresh: either the cache directory
|
|
10
|
+
* exists and contains `markspec.yaml`, or we clone afresh.
|
|
11
|
+
*/
|
|
12
|
+
/** Components of a git specifier that contribute to the cache key. */
|
|
13
|
+
export interface GitCacheKeyInput {
|
|
14
|
+
readonly repo: string;
|
|
15
|
+
readonly subpath: string | undefined;
|
|
16
|
+
readonly tag: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Stable sha256 hex digest of the canonical `(repo, subpath, tag)` tuple.
|
|
20
|
+
* Same inputs → same digest, always.
|
|
21
|
+
*/
|
|
22
|
+
export declare function computeCacheKey(input: GitCacheKeyInput): Promise<string>;
|
|
23
|
+
/** Resolved paths for a cache-backed specifier. */
|
|
24
|
+
export interface CacheLocation {
|
|
25
|
+
/** sha256 hex key for the specifier. */
|
|
26
|
+
readonly key: string;
|
|
27
|
+
/** Absolute cache directory — where the clone lives (top-level repo). */
|
|
28
|
+
readonly dir: string;
|
|
29
|
+
/** Absolute path of the `markspec.yaml` the resolver needs to read. */
|
|
30
|
+
readonly manifestPath: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compute the cache location for a git specifier relative to a project root.
|
|
34
|
+
*/
|
|
35
|
+
export declare function computeCacheLocation(projectRoot: string, input: GitCacheKeyInput): Promise<CacheLocation>;
|
|
36
|
+
/** Result of running a git subcommand — captures exit code + output streams. */
|
|
37
|
+
export interface RunGitResult {
|
|
38
|
+
readonly code: number;
|
|
39
|
+
readonly stdout: string;
|
|
40
|
+
readonly stderr: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Inject this into the resolver to stub git invocations in unit tests.
|
|
44
|
+
* Production code uses {@linkcode defaultRunGit}.
|
|
45
|
+
*/
|
|
46
|
+
export type RunGit = (args: readonly string[], cwd?: string) => Promise<RunGitResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Default implementation backed by `Deno.Command("git", …)`. Captures stdout
|
|
49
|
+
* and stderr; never throws for nonzero exit — callers inspect `result.code`.
|
|
50
|
+
*
|
|
51
|
+
* Requires `--allow-run=git` at the Deno CLI level.
|
|
52
|
+
*/
|
|
53
|
+
export declare const defaultRunGit: RunGit;
|
|
54
|
+
/** Injectable appender for {@linkcode ensureCacheGitignored}. */
|
|
55
|
+
export type AppendFile = (path: string, content: string) => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Idempotently add `.markspec/cache/` to the project's `.gitignore` if that
|
|
58
|
+
* file exists. No-op when `.gitignore` is absent.
|
|
59
|
+
*
|
|
60
|
+
* Treats `.markspec/`, `.markspec/cache`, and `.markspec/cache/` as already
|
|
61
|
+
* ignored (broadest pattern wins).
|
|
62
|
+
*
|
|
63
|
+
* @param projectRoot - Absolute path containing the `.gitignore`
|
|
64
|
+
* @param readFile - Abstraction matching `core/config/mod.ts` `ReadFile`
|
|
65
|
+
* @param appendFile - Abstraction that appends a string to a file
|
|
66
|
+
*/
|
|
67
|
+
export declare function ensureCacheGitignored(projectRoot: string, readFile: (path: string) => Promise<string | undefined>, appendFile: AppendFile): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Default `AppendFile` backed by `Deno.writeTextFile` with `{ append: true }`.
|
|
70
|
+
* Requires `--allow-write`.
|
|
71
|
+
*/
|
|
72
|
+
export declare const defaultAppendFile: AppendFile;
|
|
73
|
+
//# sourceMappingURL=git-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-cache.d.ts","sourceRoot":"","sources":["../../src/profile/git-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CACnB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,CAAC,EAAE,MAAM,KACT,OAAO,CAAC,YAAY,CAAC,CAAC;AAI3B;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,MAa3B,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,EACvD,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,UAE/B,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/git-cache
|
|
3
|
+
*
|
|
4
|
+
* Cache + `git` CLI infrastructure for git-specifier resolution.
|
|
5
|
+
*
|
|
6
|
+
* The cache lives under `<project-root>/.markspec/cache/<sha>/` where `<sha>`
|
|
7
|
+
* is the sha256 of a canonical `(host, repo, subpath, tag)` tuple. Because
|
|
8
|
+
* the spec requires tag-only specifiers and tags are (by convention)
|
|
9
|
+
* immutable, cached content never needs refresh: either the cache directory
|
|
10
|
+
* exists and contains `markspec.yaml`, or we clone afresh.
|
|
11
|
+
*/
|
|
12
|
+
import { join } from "@std/path";
|
|
13
|
+
/**
|
|
14
|
+
* Stable sha256 hex digest of the canonical `(repo, subpath, tag)` tuple.
|
|
15
|
+
* Same inputs → same digest, always.
|
|
16
|
+
*/
|
|
17
|
+
export async function computeCacheKey(input) {
|
|
18
|
+
const canonical = JSON.stringify([
|
|
19
|
+
input.repo,
|
|
20
|
+
input.subpath ?? "",
|
|
21
|
+
input.tag,
|
|
22
|
+
]);
|
|
23
|
+
const bytes = new TextEncoder().encode(canonical);
|
|
24
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
25
|
+
return [...new Uint8Array(digest)]
|
|
26
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
27
|
+
.join("");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compute the cache location for a git specifier relative to a project root.
|
|
31
|
+
*/
|
|
32
|
+
export async function computeCacheLocation(projectRoot, input) {
|
|
33
|
+
const key = await computeCacheKey(input);
|
|
34
|
+
const dir = join(projectRoot, ".markspec", "cache", key);
|
|
35
|
+
const manifestPath = input.subpath !== undefined
|
|
36
|
+
? join(dir, input.subpath, "markspec.yaml")
|
|
37
|
+
: join(dir, "markspec.yaml");
|
|
38
|
+
return { key, dir, manifestPath };
|
|
39
|
+
}
|
|
40
|
+
const textDecoder = new TextDecoder();
|
|
41
|
+
/**
|
|
42
|
+
* Default implementation backed by `Deno.Command("git", …)`. Captures stdout
|
|
43
|
+
* and stderr; never throws for nonzero exit — callers inspect `result.code`.
|
|
44
|
+
*
|
|
45
|
+
* Requires `--allow-run=git` at the Deno CLI level.
|
|
46
|
+
*/
|
|
47
|
+
export const defaultRunGit = async (args, cwd) => {
|
|
48
|
+
const cmd = new Deno.Command("git", {
|
|
49
|
+
args: [...args],
|
|
50
|
+
cwd,
|
|
51
|
+
stdout: "piped",
|
|
52
|
+
stderr: "piped",
|
|
53
|
+
});
|
|
54
|
+
const { code, stdout, stderr } = await cmd.output();
|
|
55
|
+
return {
|
|
56
|
+
code,
|
|
57
|
+
stdout: textDecoder.decode(stdout),
|
|
58
|
+
stderr: textDecoder.decode(stderr),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Idempotently add `.markspec/cache/` to the project's `.gitignore` if that
|
|
63
|
+
* file exists. No-op when `.gitignore` is absent.
|
|
64
|
+
*
|
|
65
|
+
* Treats `.markspec/`, `.markspec/cache`, and `.markspec/cache/` as already
|
|
66
|
+
* ignored (broadest pattern wins).
|
|
67
|
+
*
|
|
68
|
+
* @param projectRoot - Absolute path containing the `.gitignore`
|
|
69
|
+
* @param readFile - Abstraction matching `core/config/mod.ts` `ReadFile`
|
|
70
|
+
* @param appendFile - Abstraction that appends a string to a file
|
|
71
|
+
*/
|
|
72
|
+
export async function ensureCacheGitignored(projectRoot, readFile, appendFile) {
|
|
73
|
+
const gitignorePath = join(projectRoot, ".gitignore");
|
|
74
|
+
const current = await readFile(gitignorePath);
|
|
75
|
+
if (current === undefined) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Treat any of these patterns as "already ignored" and skip.
|
|
79
|
+
const lines = current.split("\n").map((l) => l.trim());
|
|
80
|
+
const ignored = lines.some((l) => l === ".markspec/" ||
|
|
81
|
+
l === ".markspec/cache/" ||
|
|
82
|
+
l === ".markspec/cache");
|
|
83
|
+
if (ignored) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const needsLeadingNewline = current.length > 0 && !current.endsWith("\n");
|
|
87
|
+
const content = (needsLeadingNewline ? "\n" : "") + ".markspec/cache/\n";
|
|
88
|
+
await appendFile(gitignorePath, content);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Default `AppendFile` backed by `Deno.writeTextFile` with `{ append: true }`.
|
|
92
|
+
* Requires `--allow-write`.
|
|
93
|
+
*/
|
|
94
|
+
export const defaultAppendFile = async (path, content) => {
|
|
95
|
+
await Deno.writeTextFile(path, content, { append: true });
|
|
96
|
+
};
|