@driftsys/markspec 0.2.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/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 +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- 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 +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +12 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +130 -22
- package/esm/mod.d.ts +10 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +5 -2
- 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 +255 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +27 -1
- 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 +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -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.js +11 -2
- package/esm/parser/markdown.d.ts +11 -4
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +85 -38
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +39 -9
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +20 -13
- 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.js +14 -27
- 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 +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- 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 +1 -1
- 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 +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- 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 +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +12 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +131 -22
- package/script/mod.d.ts +10 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -19
- 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 +255 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +34 -2
- 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 +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -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.js +11 -2
- package/script/parser/markdown.d.ts +11 -4
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +84 -37
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +41 -10
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +20 -13
- 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.js +14 -27
- 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 +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- 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,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile/chain
|
|
4
|
+
*
|
|
5
|
+
* Profile chain loader. Walks the `extends:` pointer from a leaf specifier
|
|
6
|
+
* up to the root, producing a multi-tier {@linkcode ProfileChain} ordered
|
|
7
|
+
* root → leaf.
|
|
8
|
+
*
|
|
9
|
+
* Supports both local and git specifiers, with cycle + depth detection. Git
|
|
10
|
+
* specifiers route through {@linkcode resolveGitSpecifier} (per-project
|
|
11
|
+
* shallow+sparse clone cache); local specifiers route through
|
|
12
|
+
* {@linkcode resolveLocalSpecifier}. The chain's {@linkcode EffectiveProfile}
|
|
13
|
+
* is produced by {@linkcode mergeChain}.
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.loadChain = loadChain;
|
|
50
|
+
const path_1 = require("@std/path");
|
|
51
|
+
const manifest_js_1 = require("./manifest.js");
|
|
52
|
+
const merge_js_1 = require("./merge.js");
|
|
53
|
+
const resolver_js_1 = require("./resolver.js");
|
|
54
|
+
/** Maximum number of tiers allowed in an `extends:` chain. */
|
|
55
|
+
const MAX_CHAIN_DEPTH = 20;
|
|
56
|
+
/**
|
|
57
|
+
* Load a profile chain from a specifier, walking the `extends:` pointer up
|
|
58
|
+
* to the root. The returned chain's tiers are ordered root → leaf, so
|
|
59
|
+
* `tiers[0]` is the ultimate ancestor and `tiers[last]` is the leaf
|
|
60
|
+
* specified by the caller.
|
|
61
|
+
*
|
|
62
|
+
* @param specifier - The leaf specifier (from `.markspec.yaml`)
|
|
63
|
+
* @param contextDir - Directory the specifier was declared in (for local
|
|
64
|
+
* path resolution)
|
|
65
|
+
* @param projectRoot - Absolute path of the project root (used to locate
|
|
66
|
+
* the `.markspec/cache/` directory for git specifiers)
|
|
67
|
+
* @param readFile - File reader abstraction
|
|
68
|
+
* @param opts - Injectable runners for git-cache operations (optional)
|
|
69
|
+
*/
|
|
70
|
+
async function loadChain(specifier, contextDir, projectRoot, readFile, opts = {}) {
|
|
71
|
+
const diagnostics = [];
|
|
72
|
+
// Walk extends: chain. Accumulate tiers leaf-first, reverse at the end.
|
|
73
|
+
const tiersLeafFirst = [];
|
|
74
|
+
const visited = new Set(); // canonical specifier key
|
|
75
|
+
let cursorSpec = specifier;
|
|
76
|
+
let cursorDir = contextDir;
|
|
77
|
+
while (cursorSpec !== undefined) {
|
|
78
|
+
const key = specifierKey(cursorSpec, cursorDir);
|
|
79
|
+
if (visited.has(key)) {
|
|
80
|
+
diagnostics.push({
|
|
81
|
+
code: "PROFILE-LOAD-004",
|
|
82
|
+
severity: "error",
|
|
83
|
+
message: `profile extends: cycle detected at ${stringifySpec(cursorSpec)} ` +
|
|
84
|
+
`(already visited in this chain)`,
|
|
85
|
+
location: { file: "<specifier>", line: 1, column: 1 },
|
|
86
|
+
});
|
|
87
|
+
return { chain: null, diagnostics };
|
|
88
|
+
}
|
|
89
|
+
visited.add(key);
|
|
90
|
+
if (tiersLeafFirst.length >= MAX_CHAIN_DEPTH) {
|
|
91
|
+
diagnostics.push({
|
|
92
|
+
code: "PROFILE-LOAD-005",
|
|
93
|
+
severity: "error",
|
|
94
|
+
message: `profile extends: chain exceeds maximum depth (${MAX_CHAIN_DEPTH})`,
|
|
95
|
+
location: { file: "<specifier>", line: 1, column: 1 },
|
|
96
|
+
});
|
|
97
|
+
return { chain: null, diagnostics };
|
|
98
|
+
}
|
|
99
|
+
let resolved;
|
|
100
|
+
if (cursorSpec.kind === "git") {
|
|
101
|
+
resolved = await (0, resolver_js_1.resolveGitSpecifier)(cursorSpec, projectRoot, readFile, diagnostics, { runGit: opts.runGit, appendFile: opts.appendFile });
|
|
102
|
+
}
|
|
103
|
+
else if (cursorSpec.kind === "npm") {
|
|
104
|
+
const { resolveNpmSpecifier } = await Promise.resolve().then(() => __importStar(require("./npm.js")));
|
|
105
|
+
const { cacheDir: cacheDirFn } = await Promise.resolve().then(() => __importStar(require("./cache.js")));
|
|
106
|
+
resolved = await resolveNpmSpecifier(cursorSpec, diagnostics, {
|
|
107
|
+
cacheRoot: cacheDirFn(),
|
|
108
|
+
readFile,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
resolved = await (0, resolver_js_1.resolveLocalSpecifier)(cursorSpec, cursorDir, readFile, diagnostics);
|
|
113
|
+
}
|
|
114
|
+
if (!resolved) {
|
|
115
|
+
return { chain: null, diagnostics };
|
|
116
|
+
}
|
|
117
|
+
const parsed = (0, manifest_js_1.parseManifest)(resolved.rawYaml, resolved.sourcePath);
|
|
118
|
+
diagnostics.push(...parsed.diagnostics);
|
|
119
|
+
if (!parsed.manifest) {
|
|
120
|
+
return { chain: null, diagnostics };
|
|
121
|
+
}
|
|
122
|
+
const tier = {
|
|
123
|
+
id: parsed.manifest.id,
|
|
124
|
+
version: parsed.manifest.version,
|
|
125
|
+
specifier: cursorSpec,
|
|
126
|
+
manifest: parsed.manifest,
|
|
127
|
+
sourcePath: resolved.sourcePath,
|
|
128
|
+
baseDir: resolved.baseDir,
|
|
129
|
+
};
|
|
130
|
+
tiersLeafFirst.push(tier);
|
|
131
|
+
// Advance cursor to the parent, if any.
|
|
132
|
+
if (parsed.manifest.extends !== undefined) {
|
|
133
|
+
cursorSpec = parsed.manifest.extends;
|
|
134
|
+
cursorDir = resolved.baseDir;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
cursorSpec = undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Reverse so tiers[0] = root parent, tiers[last] = leaf child.
|
|
141
|
+
const tiers = tiersLeafFirst.reverse();
|
|
142
|
+
// Build a temporary chain shape to feed into mergeChain. It reads only
|
|
143
|
+
// .tiers; the placeholder effective is ignored by merge.
|
|
144
|
+
const stubChain = {
|
|
145
|
+
tiers,
|
|
146
|
+
effective: buildPlaceholderEffective(tiers),
|
|
147
|
+
};
|
|
148
|
+
const mergeResult = (0, merge_js_1.mergeChain)(stubChain);
|
|
149
|
+
diagnostics.push(...mergeResult.diagnostics);
|
|
150
|
+
if (!mergeResult.effective) {
|
|
151
|
+
return { chain: null, diagnostics };
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
chain: { tiers, effective: mergeResult.effective },
|
|
155
|
+
diagnostics,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Canonical cycle-detection key for a resolved specifier. Two specifiers that
|
|
160
|
+
* resolve to the same tier are canonicalized to the same key:
|
|
161
|
+
*
|
|
162
|
+
* - Local specifiers key on the absolute resolved directory (after
|
|
163
|
+
* normalization of `.` / `..`).
|
|
164
|
+
* - Git specifiers key on `(repo, tag, subpath)`, which is what the git cache
|
|
165
|
+
* itself uses — two specifiers that hit the same cache entry are the same
|
|
166
|
+
* tier.
|
|
167
|
+
*
|
|
168
|
+
* Note: this does NOT canonicalize symlinks for local specifiers. Two
|
|
169
|
+
* different symlinked paths pointing at the same profile will only be caught
|
|
170
|
+
* by MAX_CHAIN_DEPTH, which emits PROFILE-LOAD-005 instead of
|
|
171
|
+
* PROFILE-LOAD-004. Acceptable for v1 since `Deno.realPath` would require an
|
|
172
|
+
* additional I/O round-trip and a filesystem shim for the test mock reader.
|
|
173
|
+
*/
|
|
174
|
+
function specifierKey(spec, contextDir) {
|
|
175
|
+
if (spec.kind === "local") {
|
|
176
|
+
return `local:${(0, path_1.resolve)(contextDir, spec.path)}`;
|
|
177
|
+
}
|
|
178
|
+
if (spec.kind === "git") {
|
|
179
|
+
return `git:${spec.repo}#${spec.tag}|${spec.subpath ?? ""}`;
|
|
180
|
+
}
|
|
181
|
+
if (spec.kind === "npm") {
|
|
182
|
+
const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
|
|
183
|
+
return `npm:${pkg}@${spec.range}`;
|
|
184
|
+
}
|
|
185
|
+
const _exhaustive = spec;
|
|
186
|
+
throw new Error(`Unknown specifier kind`);
|
|
187
|
+
}
|
|
188
|
+
/** Human-readable one-liner for a specifier (used in diagnostic messages). */
|
|
189
|
+
function stringifySpec(spec) {
|
|
190
|
+
if (spec.kind === "local") {
|
|
191
|
+
return spec.path;
|
|
192
|
+
}
|
|
193
|
+
if (spec.kind === "git") {
|
|
194
|
+
return `git+${spec.repo}#${spec.tag}`;
|
|
195
|
+
}
|
|
196
|
+
if (spec.kind === "npm") {
|
|
197
|
+
const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
|
|
198
|
+
return `npm:${pkg}@${spec.range}`;
|
|
199
|
+
}
|
|
200
|
+
const _exhaustive = spec;
|
|
201
|
+
throw new Error(`Unknown specifier kind`);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Build a placeholder EffectiveProfile used only as a stub input when
|
|
205
|
+
* constructing the {@linkcode ProfileChain} shape we hand to
|
|
206
|
+
* {@linkcode mergeChain}. `mergeChain` reads only `.tiers`, so the stub
|
|
207
|
+
* contents are irrelevant.
|
|
208
|
+
*/
|
|
209
|
+
function buildPlaceholderEffective(tiers) {
|
|
210
|
+
const leafOrigin = tiers[tiers.length - 1]?.id ?? "<unknown>";
|
|
211
|
+
return {
|
|
212
|
+
required: { value: [], origin: leafOrigin },
|
|
213
|
+
attributes: new Map(),
|
|
214
|
+
labels: { value: [], origin: leafOrigin },
|
|
215
|
+
colors: new Map(),
|
|
216
|
+
identified: {
|
|
217
|
+
required: { value: [], origin: leafOrigin },
|
|
218
|
+
attributes: new Map(),
|
|
219
|
+
traceability: new Map(),
|
|
220
|
+
},
|
|
221
|
+
referenced: {
|
|
222
|
+
required: { value: [], origin: leafOrigin },
|
|
223
|
+
attributes: new Map(),
|
|
224
|
+
traceability: new Map(),
|
|
225
|
+
},
|
|
226
|
+
types: new Map(),
|
|
227
|
+
documents: { types: new Map(), frontMatter: new Map() },
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -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,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile/git-cache
|
|
4
|
+
*
|
|
5
|
+
* Cache + `git` CLI infrastructure for git-specifier resolution.
|
|
6
|
+
*
|
|
7
|
+
* The cache lives under `<project-root>/.markspec/cache/<sha>/` where `<sha>`
|
|
8
|
+
* is the sha256 of a canonical `(host, repo, subpath, tag)` tuple. Because
|
|
9
|
+
* the spec requires tag-only specifiers and tags are (by convention)
|
|
10
|
+
* immutable, cached content never needs refresh: either the cache directory
|
|
11
|
+
* exists and contains `markspec.yaml`, or we clone afresh.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.defaultAppendFile = exports.defaultRunGit = void 0;
|
|
15
|
+
exports.computeCacheKey = computeCacheKey;
|
|
16
|
+
exports.computeCacheLocation = computeCacheLocation;
|
|
17
|
+
exports.ensureCacheGitignored = ensureCacheGitignored;
|
|
18
|
+
const path_1 = require("@std/path");
|
|
19
|
+
/**
|
|
20
|
+
* Stable sha256 hex digest of the canonical `(repo, subpath, tag)` tuple.
|
|
21
|
+
* Same inputs → same digest, always.
|
|
22
|
+
*/
|
|
23
|
+
async function computeCacheKey(input) {
|
|
24
|
+
const canonical = JSON.stringify([
|
|
25
|
+
input.repo,
|
|
26
|
+
input.subpath ?? "",
|
|
27
|
+
input.tag,
|
|
28
|
+
]);
|
|
29
|
+
const bytes = new TextEncoder().encode(canonical);
|
|
30
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
31
|
+
return [...new Uint8Array(digest)]
|
|
32
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
33
|
+
.join("");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Compute the cache location for a git specifier relative to a project root.
|
|
37
|
+
*/
|
|
38
|
+
async function computeCacheLocation(projectRoot, input) {
|
|
39
|
+
const key = await computeCacheKey(input);
|
|
40
|
+
const dir = (0, path_1.join)(projectRoot, ".markspec", "cache", key);
|
|
41
|
+
const manifestPath = input.subpath !== undefined
|
|
42
|
+
? (0, path_1.join)(dir, input.subpath, "markspec.yaml")
|
|
43
|
+
: (0, path_1.join)(dir, "markspec.yaml");
|
|
44
|
+
return { key, dir, manifestPath };
|
|
45
|
+
}
|
|
46
|
+
const textDecoder = new TextDecoder();
|
|
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
|
+
const defaultRunGit = async (args, cwd) => {
|
|
54
|
+
const cmd = new Deno.Command("git", {
|
|
55
|
+
args: [...args],
|
|
56
|
+
cwd,
|
|
57
|
+
stdout: "piped",
|
|
58
|
+
stderr: "piped",
|
|
59
|
+
});
|
|
60
|
+
const { code, stdout, stderr } = await cmd.output();
|
|
61
|
+
return {
|
|
62
|
+
code,
|
|
63
|
+
stdout: textDecoder.decode(stdout),
|
|
64
|
+
stderr: textDecoder.decode(stderr),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.defaultRunGit = defaultRunGit;
|
|
68
|
+
/**
|
|
69
|
+
* Idempotently add `.markspec/cache/` to the project's `.gitignore` if that
|
|
70
|
+
* file exists. No-op when `.gitignore` is absent.
|
|
71
|
+
*
|
|
72
|
+
* Treats `.markspec/`, `.markspec/cache`, and `.markspec/cache/` as already
|
|
73
|
+
* ignored (broadest pattern wins).
|
|
74
|
+
*
|
|
75
|
+
* @param projectRoot - Absolute path containing the `.gitignore`
|
|
76
|
+
* @param readFile - Abstraction matching `core/config/mod.ts` `ReadFile`
|
|
77
|
+
* @param appendFile - Abstraction that appends a string to a file
|
|
78
|
+
*/
|
|
79
|
+
async function ensureCacheGitignored(projectRoot, readFile, appendFile) {
|
|
80
|
+
const gitignorePath = (0, path_1.join)(projectRoot, ".gitignore");
|
|
81
|
+
const current = await readFile(gitignorePath);
|
|
82
|
+
if (current === undefined) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Treat any of these patterns as "already ignored" and skip.
|
|
86
|
+
const lines = current.split("\n").map((l) => l.trim());
|
|
87
|
+
const ignored = lines.some((l) => l === ".markspec/" ||
|
|
88
|
+
l === ".markspec/cache/" ||
|
|
89
|
+
l === ".markspec/cache");
|
|
90
|
+
if (ignored) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const needsLeadingNewline = current.length > 0 && !current.endsWith("\n");
|
|
94
|
+
const content = (needsLeadingNewline ? "\n" : "") + ".markspec/cache/\n";
|
|
95
|
+
await appendFile(gitignorePath, content);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Default `AppendFile` backed by `Deno.writeTextFile` with `{ append: true }`.
|
|
99
|
+
* Requires `--allow-write`.
|
|
100
|
+
*/
|
|
101
|
+
const defaultAppendFile = async (path, content) => {
|
|
102
|
+
await Deno.writeTextFile(path, content, { append: true });
|
|
103
|
+
};
|
|
104
|
+
exports.defaultAppendFile = defaultAppendFile;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/load
|
|
3
|
+
*
|
|
4
|
+
* The CLI-facing profile loader. Discovers `.markspec.yaml`, validates it,
|
|
5
|
+
* resolves the active profile specifier, loads the chain, and surfaces any
|
|
6
|
+
* diagnostics. Single entry point consumed by every profile-aware `markspec`
|
|
7
|
+
* subcommand.
|
|
8
|
+
*/
|
|
9
|
+
import type { ReadFile } from "../config/mod.js";
|
|
10
|
+
import type { Diagnostic, ProfileChain } from "../model/mod.js";
|
|
11
|
+
/** Result of `loadProfileForCommand`. */
|
|
12
|
+
export interface LoadProfileForCommandResult {
|
|
13
|
+
/** The active profile chain, or `null` when no profile is declared / resolvable. */
|
|
14
|
+
readonly chain: ProfileChain | null;
|
|
15
|
+
/** All diagnostics gathered during loading. */
|
|
16
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Load the active profile chain for the project at `projectRoot`.
|
|
20
|
+
*
|
|
21
|
+
* Discovery: looks for `.markspec.yaml` at the project root (sibling of
|
|
22
|
+
* `project.yaml`). Absent or empty → `chain: null` (core-only mode).
|
|
23
|
+
*
|
|
24
|
+
* v1 constraint: at most **one** content-bearing profile per project. Two or
|
|
25
|
+
* more entries in `profiles:` produces `PROFILE-LOAD-006` and no chain.
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadProfileForCommand(projectRoot: string, readFile: ReadFile): Promise<LoadProfileForCommandResult>;
|
|
28
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/profile/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGhE,yCAAyC;AACzC,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,2BAA2B,CAAC,CAuCtC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/profile/load
|
|
4
|
+
*
|
|
5
|
+
* The CLI-facing profile loader. Discovers `.markspec.yaml`, validates it,
|
|
6
|
+
* resolves the active profile specifier, loads the chain, and surfaces any
|
|
7
|
+
* diagnostics. Single entry point consumed by every profile-aware `markspec`
|
|
8
|
+
* subcommand.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.loadProfileForCommand = loadProfileForCommand;
|
|
12
|
+
const path_1 = require("@std/path");
|
|
13
|
+
const markspec_js_1 = require("../config/markspec.js");
|
|
14
|
+
const chain_js_1 = require("./chain.js");
|
|
15
|
+
/**
|
|
16
|
+
* Load the active profile chain for the project at `projectRoot`.
|
|
17
|
+
*
|
|
18
|
+
* Discovery: looks for `.markspec.yaml` at the project root (sibling of
|
|
19
|
+
* `project.yaml`). Absent or empty → `chain: null` (core-only mode).
|
|
20
|
+
*
|
|
21
|
+
* v1 constraint: at most **one** content-bearing profile per project. Two or
|
|
22
|
+
* more entries in `profiles:` produces `PROFILE-LOAD-006` and no chain.
|
|
23
|
+
*/
|
|
24
|
+
async function loadProfileForCommand(projectRoot, readFile) {
|
|
25
|
+
const diagnostics = [];
|
|
26
|
+
const rawYaml = await (0, markspec_js_1.readMarkspecYaml)(projectRoot, readFile);
|
|
27
|
+
if (rawYaml === null) {
|
|
28
|
+
return { chain: null, diagnostics };
|
|
29
|
+
}
|
|
30
|
+
const sourcePath = (0, path_1.join)(projectRoot, markspec_js_1.MARKSPEC_YAML_FILENAME);
|
|
31
|
+
const parsed = (0, markspec_js_1.parseMarkspecYaml)(rawYaml, sourcePath);
|
|
32
|
+
diagnostics.push(...parsed.diagnostics);
|
|
33
|
+
if (!parsed.config) {
|
|
34
|
+
return { chain: null, diagnostics };
|
|
35
|
+
}
|
|
36
|
+
const { profiles } = parsed.config;
|
|
37
|
+
if (profiles.length === 0) {
|
|
38
|
+
return { chain: null, diagnostics };
|
|
39
|
+
}
|
|
40
|
+
if (profiles.length > 1) {
|
|
41
|
+
diagnostics.push({
|
|
42
|
+
code: "PROFILE-LOAD-006",
|
|
43
|
+
severity: "error",
|
|
44
|
+
message: `.markspec.yaml declares ${profiles.length} profiles; ` +
|
|
45
|
+
"v1 accepts at most one content-bearing profile per project",
|
|
46
|
+
location: { file: sourcePath, line: 1, column: 1 },
|
|
47
|
+
});
|
|
48
|
+
return { chain: null, diagnostics };
|
|
49
|
+
}
|
|
50
|
+
const chainResult = await (0, chain_js_1.loadChain)(profiles[0], projectRoot, projectRoot, readFile);
|
|
51
|
+
diagnostics.push(...chainResult.diagnostics);
|
|
52
|
+
return { chain: chainResult.chain, diagnostics };
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/profile/manifest
|
|
3
|
+
*
|
|
4
|
+
* Parse a markspec.yaml manifest string into a validated ProfileManifest.
|
|
5
|
+
* Emits PROFILE-LOAD-002 for YAML parse errors and PROFILE-LOAD-003 for
|
|
6
|
+
* schema violations.
|
|
7
|
+
*/
|
|
8
|
+
import type { Diagnostic, ProfileManifest } from "../model/mod.js";
|
|
9
|
+
/** Result of parsing a profile manifest. */
|
|
10
|
+
export interface ParseManifestResult {
|
|
11
|
+
readonly manifest: ProfileManifest | null;
|
|
12
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse and validate a raw markspec.yaml string.
|
|
16
|
+
*
|
|
17
|
+
* @param rawYaml - File contents as a UTF-8 string
|
|
18
|
+
* @param sourcePath - Optional file path for diagnostic location
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseManifest(rawYaml: string, sourcePath?: string): ParseManifestResult;
|
|
21
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAwHnE,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AA4tBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CAkNrB"}
|