@driftsys/markspec 0.8.0 → 0.10.1
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/esm/compiler/mod.d.ts +7 -0
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +17 -3
- package/esm/compiler/schema.d.ts +8 -1
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +8 -1
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +25 -0
- package/esm/discovery/gitignore.d.ts +40 -0
- package/esm/discovery/gitignore.d.ts.map +1 -0
- package/esm/discovery/gitignore.js +145 -0
- package/esm/discovery/mod.d.ts +54 -0
- package/esm/discovery/mod.d.ts.map +1 -0
- package/esm/discovery/mod.js +122 -0
- package/esm/formatter/dprint.d.ts +62 -0
- package/esm/formatter/dprint.d.ts.map +1 -0
- package/esm/formatter/dprint.js +83 -0
- package/esm/formatter/md_equiv.d.ts +24 -0
- package/esm/formatter/md_equiv.d.ts.map +1 -0
- package/esm/formatter/md_equiv.js +81 -0
- package/esm/formatter/mod.d.ts +25 -0
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +106 -6
- package/esm/formatter/prose.d.ts +48 -0
- package/esm/formatter/prose.d.ts.map +1 -0
- package/esm/formatter/prose.js +85 -0
- package/esm/mod.d.ts +10 -4
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -2
- package/esm/model/mod.d.ts +25 -1
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +1 -0
- package/esm/model/profile.d.ts +34 -0
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +28 -15
- package/esm/profile/chain.js +1 -0
- package/esm/profile/delivered.d.ts +27 -0
- package/esm/profile/delivered.d.ts.map +1 -0
- package/esm/profile/delivered.js +60 -0
- package/esm/profile/manifest.d.ts +1 -0
- package/esm/profile/manifest.d.ts.map +1 -1
- package/esm/profile/manifest.js +107 -0
- package/esm/profile/merge.d.ts.map +1 -1
- package/esm/profile/merge.js +21 -0
- package/esm/refs/mod.d.ts.map +1 -1
- package/esm/refs/mod.js +22 -0
- package/esm/reporter/mod.js +17 -4
- package/esm/self_upgrade/target.d.ts +3 -3
- package/esm/self_upgrade/target.d.ts.map +1 -1
- package/esm/self_upgrade/target.js +4 -2
- package/esm/validator/corpus.d.ts +25 -0
- package/esm/validator/corpus.d.ts.map +1 -0
- package/esm/validator/corpus.js +138 -0
- package/esm/validator/listing.d.ts.map +1 -1
- package/esm/validator/listing.js +4 -1
- package/esm/validator/mod.d.ts +2 -0
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +1 -0
- package/package.json +3 -1
- package/script/compiler/mod.d.ts +7 -0
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +16 -2
- package/script/compiler/schema.d.ts +8 -1
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +8 -1
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +25 -0
- package/script/discovery/gitignore.d.ts +40 -0
- package/script/discovery/gitignore.d.ts.map +1 -0
- package/script/discovery/gitignore.js +149 -0
- package/script/discovery/mod.d.ts +54 -0
- package/script/discovery/mod.d.ts.map +1 -0
- package/script/discovery/mod.js +128 -0
- package/script/formatter/dprint.d.ts +62 -0
- package/script/formatter/dprint.d.ts.map +1 -0
- package/script/formatter/dprint.js +120 -0
- package/script/formatter/md_equiv.d.ts +24 -0
- package/script/formatter/md_equiv.d.ts.map +1 -0
- package/script/formatter/md_equiv.js +87 -0
- package/script/formatter/mod.d.ts +25 -0
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +106 -5
- package/script/formatter/prose.d.ts +48 -0
- package/script/formatter/prose.d.ts.map +1 -0
- package/script/formatter/prose.js +88 -0
- package/script/mod.d.ts +10 -4
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +22 -3
- package/script/model/mod.d.ts +25 -1
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +1 -0
- package/script/model/profile.d.ts +34 -0
- package/script/model/profile.d.ts.map +1 -1
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +27 -14
- package/script/profile/chain.js +1 -0
- package/script/profile/delivered.d.ts +27 -0
- package/script/profile/delivered.d.ts.map +1 -0
- package/script/profile/delivered.js +65 -0
- package/script/profile/manifest.d.ts +1 -0
- package/script/profile/manifest.d.ts.map +1 -1
- package/script/profile/manifest.js +108 -1
- package/script/profile/merge.d.ts.map +1 -1
- package/script/profile/merge.js +21 -0
- package/script/refs/mod.d.ts.map +1 -1
- package/script/refs/mod.js +22 -0
- package/script/reporter/mod.js +17 -4
- package/script/self_upgrade/target.d.ts +3 -3
- package/script/self_upgrade/target.d.ts.map +1 -1
- package/script/self_upgrade/target.js +4 -2
- package/script/validator/corpus.d.ts +25 -0
- package/script/validator/corpus.d.ts.map +1 -0
- package/script/validator/corpus.js +142 -0
- package/script/validator/listing.d.ts.map +1 -1
- package/script/validator/listing.js +4 -1
- package/script/validator/mod.d.ts +2 -0
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +4 -1
package/esm/compiler/mod.d.ts
CHANGED
|
@@ -43,6 +43,13 @@ export interface CompileOptions {
|
|
|
43
43
|
* list is deduplicated and sorted for deterministic output.
|
|
44
44
|
*/
|
|
45
45
|
readonly withContributors?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Profile-delivered corpus entries (ADR-030), pre-loaded and
|
|
48
|
+
* origin-stamped by `loadDeliveredCorpus`. Injected AHEAD of project
|
|
49
|
+
* entries so first-entry-wins graph slots resolve to the corpus
|
|
50
|
+
* deterministically. Optional — absent means no corpus.
|
|
51
|
+
*/
|
|
52
|
+
readonly corpusEntries?: readonly Entry[];
|
|
46
53
|
}
|
|
47
54
|
/** Compiled project output with resolved traceability graph. */
|
|
48
55
|
export interface CompileResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK,EAEL,IAAI,EAEL,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK,EAEL,IAAI,EAEL,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAOjE,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAClB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC;QAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACjD;;;;;;;;;OASG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,CACjB,IAAI,EAAE,MAAM,KACT,OAAO,CACV;QACE,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;QACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,SAAS,CACd,CAAC;IACF;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CA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-
import { classifyEntriesStage, suppressDeclaredAttrR010, validate, } from "../validator/mod.js";
|
|
9
|
+
import { attributeCorpusDiagnostics, classifyEntriesStage, detectCorpusCollisions, suppressDeclaredAttrR010, validate, } from "../validator/mod.js";
|
|
10
10
|
import { validateTypl } from "../typl/mod.js";
|
|
11
11
|
import { buildEffectiveDisciplineRegistry } from "../profile/discipline_registry.js";
|
|
12
12
|
import { ATTR_TO_LINK_KIND } from "./constants.js";
|
|
@@ -110,7 +110,7 @@ class Semaphore {
|
|
|
110
110
|
*/
|
|
111
111
|
export async function compile(paths, options) {
|
|
112
112
|
const read = options.readFile;
|
|
113
|
-
const allEntries = [];
|
|
113
|
+
const allEntries = [...(options.corpusEntries ?? [])];
|
|
114
114
|
const parseDiagnostics = [];
|
|
115
115
|
const documents = new Map();
|
|
116
116
|
// Phase 1: Read and parse all files with bounded concurrency (16 slots).
|
|
@@ -238,11 +238,25 @@ export async function compile(paths, options) {
|
|
|
238
238
|
// diagnostics are already included in validationDiagnostics, so we discard
|
|
239
239
|
// them to avoid duplicates in the output.
|
|
240
240
|
const { registry: typeRegistry } = validateTypl([...entries.values()]);
|
|
241
|
-
|
|
241
|
+
let diagnostics = [
|
|
242
242
|
...parseDiagnostics,
|
|
243
243
|
...validationDiagnostics,
|
|
244
244
|
...linkTargetDiags,
|
|
245
245
|
];
|
|
246
|
+
// Phase 5: Corpus-aware diagnostic post-pass (ADR-030). A project entry
|
|
247
|
+
// that reuses a display ID or Id already delivered by a corpus is
|
|
248
|
+
// MSL-R014, not the generic MSL-R005/R006/I007/I008 duplicate codes —
|
|
249
|
+
// and findings located inside a corpus file are downgraded to
|
|
250
|
+
// attributed warnings so consumer builds don't go red over upstream
|
|
251
|
+
// bugs they cannot fix. No-op (and zero allocation beyond the spread
|
|
252
|
+
// above) when no corpus was injected.
|
|
253
|
+
if (options.corpusEntries && options.corpusEntries.length > 0) {
|
|
254
|
+
const collisions = detectCorpusCollisions(allEntries);
|
|
255
|
+
diagnostics = [
|
|
256
|
+
...attributeCorpusDiagnostics(diagnostics, allEntries, collisions.collidedTokens),
|
|
257
|
+
...collisions.diagnostics,
|
|
258
|
+
];
|
|
259
|
+
}
|
|
246
260
|
return {
|
|
247
261
|
entries,
|
|
248
262
|
links,
|
package/esm/compiler/schema.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* interchange.
|
|
7
7
|
*/
|
|
8
8
|
import type { CompileResult } from "./mod.js";
|
|
9
|
-
import type { Diagnostic, Entry, Link } from "../model/mod.js";
|
|
9
|
+
import type { Diagnostic, Entry, EntryOrigin, Link } from "../model/mod.js";
|
|
10
10
|
import type { RegistryBinding, RegistryTypedef } from "../typl/mod.js";
|
|
11
11
|
/**
|
|
12
12
|
* JSON-serializable form of {@linkcode Entry}.
|
|
@@ -14,9 +14,16 @@ import type { RegistryBinding, RegistryTypedef } from "../typl/mod.js";
|
|
|
14
14
|
* Identical to `Entry` except `typedAttributes` is a plain
|
|
15
15
|
* `Record<string, readonly string[]>` instead of a `ReadonlyMap` — Maps are
|
|
16
16
|
* not JSON-serializable. All other fields are passed through unchanged.
|
|
17
|
+
*
|
|
18
|
+
* `origin` (ADR-030) is restated explicitly here — rather than relying on
|
|
19
|
+
* the `Omit<Entry, ...>` passthrough — so the field-presence contract is
|
|
20
|
+
* documented at the serialization boundary: present verbatim on entries
|
|
21
|
+
* injected from a profile-delivered corpus, absent (not `null`) on
|
|
22
|
+
* project-authored entries.
|
|
17
23
|
*/
|
|
18
24
|
export type SerializedEntry = Omit<Entry, "typedAttributes"> & {
|
|
19
25
|
readonly typedAttributes?: Record<string, readonly string[]>;
|
|
26
|
+
readonly origin?: EntryOrigin;
|
|
20
27
|
};
|
|
21
28
|
/**
|
|
22
29
|
* Serialized form of the {@linkcode TypeRegistry}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/compiler/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH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S,IAAI,EAAE,CAAC,CAAC;IAClD,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,sCAAsC;IACtC,QAAQ,CAAC,YAAY,EAAE,sBAAsB,CAAC;CAC/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,GACpB,uBAAuB,CAazB;AAgBD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CA4B5D"}
|
package/esm/compiler/schema.js
CHANGED
|
@@ -57,9 +57,16 @@ export function serializeEntry(entry) {
|
|
|
57
57
|
const { sync: _sync, ...rest } = properties;
|
|
58
58
|
properties = Object.keys(rest).length > 0 ? rest : undefined;
|
|
59
59
|
}
|
|
60
|
+
// Pull `origin` (ADR-030) out of the spread so the key is entirely
|
|
61
|
+
// absent — not `origin: undefined` — on entries that did not come
|
|
62
|
+
// from a delivered corpus, matching the serialized-field-presence
|
|
63
|
+
// contract. Object rest destructuring drops the named key regardless
|
|
64
|
+
// of its value, unlike `...entry` alone.
|
|
65
|
+
const { origin, ...rest } = entry;
|
|
60
66
|
return {
|
|
61
|
-
...
|
|
67
|
+
...rest,
|
|
62
68
|
typedAttributes,
|
|
63
69
|
properties,
|
|
70
|
+
...(origin ? { origin } : {}),
|
|
64
71
|
};
|
|
65
72
|
}
|
package/esm/config/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/config/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,iD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O,CAAC,MAAM,GAAG,SAAS,CAAC,CAU7B;AAsBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,aAAa,CA+Nf;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAMD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC"}
|
package/esm/config/mod.js
CHANGED
|
@@ -225,6 +225,30 @@ export function parseProjectConfig(yaml, filePath) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
+
// exclude: optional string[] of gitignore-syntax patterns
|
|
229
|
+
let exclude = DEFAULT_PROJECT_CONFIG.exclude;
|
|
230
|
+
if (obj.exclude !== undefined && obj.exclude !== null) {
|
|
231
|
+
if (!Array.isArray(obj.exclude)) {
|
|
232
|
+
errors.push({
|
|
233
|
+
field: "exclude",
|
|
234
|
+
message: `expected array, got ${typeof obj.exclude}`,
|
|
235
|
+
line: findLineNumber(yaml, "exclude"),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
const bad = obj.exclude.findIndex((v) => typeof v !== "string" || v === "");
|
|
240
|
+
if (bad !== -1) {
|
|
241
|
+
errors.push({
|
|
242
|
+
field: `exclude[${bad}]`,
|
|
243
|
+
message: "each exclude pattern must be a non-empty string",
|
|
244
|
+
line: findLineNumber(yaml, "exclude"),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
exclude = obj.exclude;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
228
252
|
if (errors.length > 0) {
|
|
229
253
|
throw new ConfigError(filePath, errors);
|
|
230
254
|
}
|
|
@@ -235,6 +259,7 @@ export function parseProjectConfig(yaml, filePath) {
|
|
|
235
259
|
parents,
|
|
236
260
|
parentFallback,
|
|
237
261
|
captionConventions,
|
|
262
|
+
exclude,
|
|
238
263
|
};
|
|
239
264
|
}
|
|
240
265
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/discovery/gitignore
|
|
3
|
+
*
|
|
4
|
+
* Pure-TypeScript `.gitignore` pattern matcher. Implements the standard
|
|
5
|
+
* semantics the discovery walker needs: `#` comments, `!` negation,
|
|
6
|
+
* trailing-`/` directory-only patterns, leading-`/` and contains-`/`
|
|
7
|
+
* anchoring, `*` / `?` / `[...]` globs, and `**` cross-directory globs.
|
|
8
|
+
* Last matching rule wins.
|
|
9
|
+
*
|
|
10
|
+
* Per git semantics, a file inside an ignored directory cannot be
|
|
11
|
+
* re-included by a negation — the walker enforces this by pruning
|
|
12
|
+
* ignored directories without descending.
|
|
13
|
+
*
|
|
14
|
+
* No I/O, no platform APIs — Node-compatible by construction.
|
|
15
|
+
*/
|
|
16
|
+
/** One compiled gitignore rule. */
|
|
17
|
+
export interface GitignoreRule {
|
|
18
|
+
/** Matches a root-relative POSIX path (no leading slash). */
|
|
19
|
+
readonly regex: RegExp;
|
|
20
|
+
/** `!pattern` — a match un-ignores the path. */
|
|
21
|
+
readonly negated: boolean;
|
|
22
|
+
/** `pattern/` — matches directories only. */
|
|
23
|
+
readonly dirOnly: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse `.gitignore` content into compiled rules.
|
|
27
|
+
*
|
|
28
|
+
* @param content - Raw file content (LF or CRLF).
|
|
29
|
+
* @param baseDir - Root-relative POSIX dir the `.gitignore` lives in
|
|
30
|
+
* (`""` for the root one). Patterns only match paths under it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseGitignore(content: string, baseDir: string): GitignoreRule[];
|
|
33
|
+
/**
|
|
34
|
+
* Test a root-relative POSIX path against compiled rules.
|
|
35
|
+
* Last matching rule wins; no match → not ignored.
|
|
36
|
+
*
|
|
37
|
+
* @param isDir - Directory-only rules (`build/`) match only when true.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isIgnored(relPath: string, isDir: boolean, rules: readonly GitignoreRule[]): boolean;
|
|
40
|
+
//# sourceMappingURL=gitignore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitignore.d.ts","sourceRoot":"","sources":["../../src/discovery/gitignore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA0DD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,aAAa,EAAE,CAyCjB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,aAAa,EAAE,GAC9B,OAAO,CAOT"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/discovery/gitignore
|
|
3
|
+
*
|
|
4
|
+
* Pure-TypeScript `.gitignore` pattern matcher. Implements the standard
|
|
5
|
+
* semantics the discovery walker needs: `#` comments, `!` negation,
|
|
6
|
+
* trailing-`/` directory-only patterns, leading-`/` and contains-`/`
|
|
7
|
+
* anchoring, `*` / `?` / `[...]` globs, and `**` cross-directory globs.
|
|
8
|
+
* Last matching rule wins.
|
|
9
|
+
*
|
|
10
|
+
* Per git semantics, a file inside an ignored directory cannot be
|
|
11
|
+
* re-included by a negation — the walker enforces this by pruning
|
|
12
|
+
* ignored directories without descending.
|
|
13
|
+
*
|
|
14
|
+
* No I/O, no platform APIs — Node-compatible by construction.
|
|
15
|
+
*/
|
|
16
|
+
const REGEX_SPECIALS = /[.+^${}()|\\]/;
|
|
17
|
+
function escapeRegexChar(c) {
|
|
18
|
+
return REGEX_SPECIALS.test(c) ? `\\${c}` : c;
|
|
19
|
+
}
|
|
20
|
+
/** Translate one gitignore glob (already stripped of `!`, `/` affixes)
|
|
21
|
+
* into a regex source string. */
|
|
22
|
+
function globToRegexSource(pattern) {
|
|
23
|
+
let re = "";
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (i < pattern.length) {
|
|
26
|
+
const c = pattern[i];
|
|
27
|
+
if (c === "*") {
|
|
28
|
+
// Consume the whole run of consecutive `*` so we never emit adjacent
|
|
29
|
+
// unbounded quantifiers (which backtrack catastrophically against a
|
|
30
|
+
// non-matching input). Git likewise treats consecutive `*` that are
|
|
31
|
+
// not a slash-delimited `**` as regular asterisks.
|
|
32
|
+
let stars = 0;
|
|
33
|
+
while (pattern[i] === "*") {
|
|
34
|
+
stars++;
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
if (stars >= 2 && pattern[i] === "/") {
|
|
38
|
+
re += "(?:[^/]+/)*"; // `**/` — zero or more whole segments
|
|
39
|
+
i++; // consume the `/`
|
|
40
|
+
}
|
|
41
|
+
else if (stars >= 2) {
|
|
42
|
+
re += ".*"; // leading/trailing/bare `**` — crosses directories
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
re += "[^/]*"; // single `*` — within one path segment
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (c === "?") {
|
|
49
|
+
re += "[^/]";
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
else if (c === "[") {
|
|
53
|
+
const end = pattern.indexOf("]", i + 1);
|
|
54
|
+
if (end < 0) {
|
|
55
|
+
re += "\\[";
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
let cls = pattern.slice(i + 1, end);
|
|
60
|
+
if (cls.startsWith("!"))
|
|
61
|
+
cls = `^${cls.slice(1)}`;
|
|
62
|
+
re += `[${cls}]`;
|
|
63
|
+
i = end + 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (c === "\\" && i + 1 < pattern.length) {
|
|
67
|
+
re += escapeRegexChar(pattern[i + 1]);
|
|
68
|
+
i += 2;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
re += escapeRegexChar(c);
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return re;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse `.gitignore` content into compiled rules.
|
|
79
|
+
*
|
|
80
|
+
* @param content - Raw file content (LF or CRLF).
|
|
81
|
+
* @param baseDir - Root-relative POSIX dir the `.gitignore` lives in
|
|
82
|
+
* (`""` for the root one). Patterns only match paths under it.
|
|
83
|
+
*/
|
|
84
|
+
export function parseGitignore(content, baseDir) {
|
|
85
|
+
const rules = [];
|
|
86
|
+
for (const rawLine of content.split("\n")) {
|
|
87
|
+
// Strip CR and unescaped trailing spaces (git semantics).
|
|
88
|
+
const line = rawLine.replace(/\r$/, "").replace(/(?<!\\) +$/, "");
|
|
89
|
+
if (line === "" || line.startsWith("#"))
|
|
90
|
+
continue;
|
|
91
|
+
let pattern = line;
|
|
92
|
+
let negated = false;
|
|
93
|
+
if (pattern.startsWith("!")) {
|
|
94
|
+
negated = true;
|
|
95
|
+
pattern = pattern.slice(1);
|
|
96
|
+
}
|
|
97
|
+
let dirOnly = false;
|
|
98
|
+
if (pattern.endsWith("/")) {
|
|
99
|
+
dirOnly = true;
|
|
100
|
+
pattern = pattern.slice(0, -1);
|
|
101
|
+
}
|
|
102
|
+
// A separator anywhere in the pattern anchors it to baseDir;
|
|
103
|
+
// otherwise it matches at any depth below baseDir.
|
|
104
|
+
const anchored = pattern.includes("/");
|
|
105
|
+
if (pattern.startsWith("/"))
|
|
106
|
+
pattern = pattern.slice(1);
|
|
107
|
+
if (pattern === "")
|
|
108
|
+
continue;
|
|
109
|
+
// baseDir is a literal directory prefix, so every regex metacharacter
|
|
110
|
+
// in it must be escaped — including `* ? [ ]`, which the pattern-body
|
|
111
|
+
// helpers (escapeRegexChar / globToRegexSource) deliberately leave
|
|
112
|
+
// unescaped so they can act as globs. A dir literally named `pkg[v2]`
|
|
113
|
+
// would otherwise inject a stray character class.
|
|
114
|
+
const prefix = baseDir === ""
|
|
115
|
+
? ""
|
|
116
|
+
: `${baseDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`;
|
|
117
|
+
const depth = anchored ? "" : "(?:.*/)?";
|
|
118
|
+
let regex;
|
|
119
|
+
try {
|
|
120
|
+
regex = new RegExp(`^${prefix}${depth}${globToRegexSource(pattern)}$`);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
continue; // skip a line that compiles to an invalid regex (e.g. a
|
|
124
|
+
// malformed character class) rather than crashing discovery
|
|
125
|
+
}
|
|
126
|
+
rules.push({ regex, negated, dirOnly });
|
|
127
|
+
}
|
|
128
|
+
return rules;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Test a root-relative POSIX path against compiled rules.
|
|
132
|
+
* Last matching rule wins; no match → not ignored.
|
|
133
|
+
*
|
|
134
|
+
* @param isDir - Directory-only rules (`build/`) match only when true.
|
|
135
|
+
*/
|
|
136
|
+
export function isIgnored(relPath, isDir, rules) {
|
|
137
|
+
let ignored = false;
|
|
138
|
+
for (const rule of rules) {
|
|
139
|
+
if (rule.dirOnly && !isDir)
|
|
140
|
+
continue;
|
|
141
|
+
if (rule.regex.test(relPath))
|
|
142
|
+
ignored = !rule.negated;
|
|
143
|
+
}
|
|
144
|
+
return ignored;
|
|
145
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/discovery
|
|
3
|
+
*
|
|
4
|
+
* Gitignore-aware project file discovery — the single walker every
|
|
5
|
+
* MarkSpec surface uses (CLI verbs, LSP indexing, lockfile entry
|
|
6
|
+
* collection). Yields absolute paths of MarkSpec-relevant files under a
|
|
7
|
+
* root, honoring (in precedence order):
|
|
8
|
+
*
|
|
9
|
+
* 1. built-in skips — hidden directories (name starts with `.`)
|
|
10
|
+
* 2. `.gitignore` files (root + nested, standard semantics)
|
|
11
|
+
* 3. caller-supplied `exclude` patterns (gitignore syntax, root-anchored)
|
|
12
|
+
*
|
|
13
|
+
* I/O is injected via {@linkcode DiscoveryIO} so the module stays
|
|
14
|
+
* Node-compatible; entry points supply the Deno implementation.
|
|
15
|
+
*/
|
|
16
|
+
export { type GitignoreRule, isIgnored, parseGitignore } from "./gitignore.js";
|
|
17
|
+
/**
|
|
18
|
+
* Source-file extensions the parser can extract doc-comment entries
|
|
19
|
+
* from (tree-sitter grammars available). Single SSOT — `lsp/context.ts`
|
|
20
|
+
* imports this set.
|
|
21
|
+
*/
|
|
22
|
+
export declare const SOURCE_EXTENSIONS: ReadonlySet<string>;
|
|
23
|
+
/** Markdown only — the `fmt` scope (the formatter never rewrites source). */
|
|
24
|
+
export declare const MARKDOWN_EXTENSIONS: ReadonlySet<string>;
|
|
25
|
+
/** Everything MarkSpec-relevant: markdown + source families. */
|
|
26
|
+
export declare const RELEVANT_EXTENSIONS: ReadonlySet<string>;
|
|
27
|
+
/** One directory entry from {@linkcode DiscoveryIO.readDir}.
|
|
28
|
+
* Structurally compatible with `Deno.DirEntry`. */
|
|
29
|
+
export interface DiscoveryDirEntry {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly isDirectory: boolean;
|
|
32
|
+
readonly isFile: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Injected filesystem surface for the walker. */
|
|
35
|
+
export interface DiscoveryIO {
|
|
36
|
+
readDir(path: string): AsyncIterable<DiscoveryDirEntry>;
|
|
37
|
+
/** Resolves `undefined` when the file does not exist or is unreadable. */
|
|
38
|
+
readFile(path: string): Promise<string | undefined>;
|
|
39
|
+
}
|
|
40
|
+
/** Options for {@linkcode discoverFiles}. */
|
|
41
|
+
export interface DiscoverOptions {
|
|
42
|
+
/** Extension filter; defaults to {@linkcode RELEVANT_EXTENSIONS}. */
|
|
43
|
+
readonly extensions?: ReadonlySet<string>;
|
|
44
|
+
/** Extra gitignore-syntax patterns, anchored at `root` (e.g. from
|
|
45
|
+
* project.yaml `exclude:`). Applied after `.gitignore` rules. */
|
|
46
|
+
readonly exclude?: readonly string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Walk `root` recursively, yielding absolute paths of relevant files.
|
|
50
|
+
* Entries are yielded in sorted order per directory — deterministic
|
|
51
|
+
* output across filesystems. Unreadable directories are skipped.
|
|
52
|
+
*/
|
|
53
|
+
export declare function discoverFiles(root: string, io: DiscoveryIO, options?: DiscoverOptions): AsyncGenerator<string>;
|
|
54
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/discovery/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAmBhD,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAoB,CAAC;AAEzE,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAGlD,CAAC;AAEH;mDACmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACxD,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACrD;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C;qEACiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AA8BD;;;;GAIG;AACH,wBAAuB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,MAAM,CAAC,CAgBxB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/discovery
|
|
3
|
+
*
|
|
4
|
+
* Gitignore-aware project file discovery — the single walker every
|
|
5
|
+
* MarkSpec surface uses (CLI verbs, LSP indexing, lockfile entry
|
|
6
|
+
* collection). Yields absolute paths of MarkSpec-relevant files under a
|
|
7
|
+
* root, honoring (in precedence order):
|
|
8
|
+
*
|
|
9
|
+
* 1. built-in skips — hidden directories (name starts with `.`)
|
|
10
|
+
* 2. `.gitignore` files (root + nested, standard semantics)
|
|
11
|
+
* 3. caller-supplied `exclude` patterns (gitignore syntax, root-anchored)
|
|
12
|
+
*
|
|
13
|
+
* I/O is injected via {@linkcode DiscoveryIO} so the module stays
|
|
14
|
+
* Node-compatible; entry points supply the Deno implementation.
|
|
15
|
+
*/
|
|
16
|
+
import { extname, join } from "@std/path";
|
|
17
|
+
import { isIgnored, parseGitignore } from "./gitignore.js";
|
|
18
|
+
export { isIgnored, parseGitignore } from "./gitignore.js";
|
|
19
|
+
/**
|
|
20
|
+
* Source-file extensions the parser can extract doc-comment entries
|
|
21
|
+
* from (tree-sitter grammars available). Single SSOT — `lsp/context.ts`
|
|
22
|
+
* imports this set.
|
|
23
|
+
*/
|
|
24
|
+
export const SOURCE_EXTENSIONS = new Set([
|
|
25
|
+
".rs",
|
|
26
|
+
".kt",
|
|
27
|
+
".kts",
|
|
28
|
+
".java",
|
|
29
|
+
".c",
|
|
30
|
+
".h",
|
|
31
|
+
".cpp",
|
|
32
|
+
".cc",
|
|
33
|
+
".cxx",
|
|
34
|
+
".hpp",
|
|
35
|
+
".hxx",
|
|
36
|
+
".ts",
|
|
37
|
+
".tsx",
|
|
38
|
+
".jsx",
|
|
39
|
+
".js",
|
|
40
|
+
".mjs",
|
|
41
|
+
".cjs",
|
|
42
|
+
".cs",
|
|
43
|
+
]);
|
|
44
|
+
/** Markdown only — the `fmt` scope (the formatter never rewrites source). */
|
|
45
|
+
export const MARKDOWN_EXTENSIONS = new Set([".md"]);
|
|
46
|
+
/** Everything MarkSpec-relevant: markdown + source families. */
|
|
47
|
+
export const RELEVANT_EXTENSIONS = new Set([
|
|
48
|
+
...MARKDOWN_EXTENSIONS,
|
|
49
|
+
...SOURCE_EXTENSIONS,
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* Directory names pruned by default, in addition to the hidden-dir skip.
|
|
53
|
+
* These are the common build-output / dependency directories the
|
|
54
|
+
* pre-`core/discovery` walkers (LSP `walkDirectory`, lockfile
|
|
55
|
+
* `collectEntries`) hardcoded; keeping them restores that guarantee
|
|
56
|
+
* independent of a consumer's `.gitignore` — otherwise a project that does
|
|
57
|
+
* not list them recurses into build artifacts (duplicate-ID noise, slow LSP
|
|
58
|
+
* indexing, spurious `MSL-L212` edge-hash entries).
|
|
59
|
+
*
|
|
60
|
+
* Unlike the hidden-dir skip these are overridable: they are applied as the
|
|
61
|
+
* LOWEST-precedence rule layer (before `.gitignore` and `exclude:`), so a
|
|
62
|
+
* negated `!target/` entry in either re-includes them under gitignore
|
|
63
|
+
* last-match-wins.
|
|
64
|
+
*/
|
|
65
|
+
const BUILTIN_SKIP_DIRS = [
|
|
66
|
+
"node_modules",
|
|
67
|
+
"target",
|
|
68
|
+
"dist",
|
|
69
|
+
"build",
|
|
70
|
+
];
|
|
71
|
+
/** Compiled once: the built-in skip as unanchored, directory-only gitignore
|
|
72
|
+
* rules (each matches a directory of that name at any depth). */
|
|
73
|
+
const BUILTIN_SKIP_RULES = parseGitignore(BUILTIN_SKIP_DIRS.map((d) => `${d}/`).join("\n"), "");
|
|
74
|
+
/**
|
|
75
|
+
* Walk `root` recursively, yielding absolute paths of relevant files.
|
|
76
|
+
* Entries are yielded in sorted order per directory — deterministic
|
|
77
|
+
* output across filesystems. Unreadable directories are skipped.
|
|
78
|
+
*/
|
|
79
|
+
export async function* discoverFiles(root, io, options = {}) {
|
|
80
|
+
const extensions = options.extensions ?? RELEVANT_EXTENSIONS;
|
|
81
|
+
const excludeRules = parseGitignore((options.exclude ?? []).join("\n"), "");
|
|
82
|
+
// Built-in build-output skips are the lowest-precedence layer: `.gitignore`
|
|
83
|
+
// (appended per-directory in `walk`) and `exclude:` both come after, so a
|
|
84
|
+
// `!target/` negation in either overrides them.
|
|
85
|
+
yield* walk(root, "", [...BUILTIN_SKIP_RULES, ...excludeRules], io, extensions);
|
|
86
|
+
}
|
|
87
|
+
async function* walk(absDir, relDir, rules, io, extensions) {
|
|
88
|
+
// Nested .gitignore rules append after inherited ones — deeper rules
|
|
89
|
+
// win under last-match-wins.
|
|
90
|
+
const raw = await io.readFile(join(absDir, ".gitignore"));
|
|
91
|
+
const active = raw !== undefined && raw.length > 0
|
|
92
|
+
? [...rules, ...parseGitignore(raw, relDir)]
|
|
93
|
+
: rules;
|
|
94
|
+
const entries = [];
|
|
95
|
+
try {
|
|
96
|
+
for await (const e of io.readDir(absDir))
|
|
97
|
+
entries.push(e);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return; // unreadable directory — a project walk must not abort
|
|
101
|
+
}
|
|
102
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const rel = relDir === "" ? entry.name : `${relDir}/${entry.name}`;
|
|
105
|
+
if (entry.isDirectory) {
|
|
106
|
+
if (entry.name.startsWith("."))
|
|
107
|
+
continue; // built-in: hidden dirs
|
|
108
|
+
// Git semantics: paths under an ignored directory cannot be
|
|
109
|
+
// re-included, so pruning here is correct (and fast).
|
|
110
|
+
if (isIgnored(rel, true, active))
|
|
111
|
+
continue;
|
|
112
|
+
yield* walk(join(absDir, entry.name), rel, active, io, extensions);
|
|
113
|
+
}
|
|
114
|
+
else if (entry.isFile) {
|
|
115
|
+
if (!extensions.has(extname(entry.name).toLowerCase()))
|
|
116
|
+
continue;
|
|
117
|
+
if (isIgnored(rel, false, active))
|
|
118
|
+
continue;
|
|
119
|
+
yield join(absDir, entry.name);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module formatter/dprint
|
|
3
|
+
*
|
|
4
|
+
* Loader for the embedded dprint-markdown WASM plugin (ADR-029).
|
|
5
|
+
* `markspec fmt` formats whole Markdown documents with one canonical,
|
|
6
|
+
* zero-config style; this module owns that style and the (cached)
|
|
7
|
+
* WASM instantiation. Dynamic imports keep the plugin off every code
|
|
8
|
+
* path except formatting (`fmt`, the `check` MSL-F010 drift gate, LSP
|
|
9
|
+
* documentFormatting).
|
|
10
|
+
*
|
|
11
|
+
* Node-compatible: `node:fs/promises` + WebAssembly only, no `Deno.*`.
|
|
12
|
+
*
|
|
13
|
+
* Packaging note: `@dprint/formatter` and `@dprint/markdown` are dynamically
|
|
14
|
+
* imported bare npm specifiers, and their `plugin.wasm` ships inside the npm
|
|
15
|
+
* package — no vendored copy in this repo. `deno compile` only embeds the
|
|
16
|
+
* resolved npm tree (and thus the wasm) when the compile entry point itself
|
|
17
|
+
* lives inside this workspace member (`packages/markspec/`); an entry point
|
|
18
|
+
* outside that tree can't resolve the import map at runtime. The project's
|
|
19
|
+
* one real compile target (`packages/markspec/main.ts`) already satisfies
|
|
20
|
+
* this, so it's a non-issue in production — it only bites a from-scratch
|
|
21
|
+
* smoke test placed elsewhere.
|
|
22
|
+
*/
|
|
23
|
+
/** Per-call options for a {@linkcode ProseFormatter}. */
|
|
24
|
+
export interface ProseFormatOptions {
|
|
25
|
+
/** Override the effective line width for this fragment. Used by the
|
|
26
|
+
* entry-body polish: bodies are formatted dedented and re-indented
|
|
27
|
+
* afterwards, so the budget must shrink by the indent width to stay
|
|
28
|
+
* in agreement with a whole-file dprint view of the same content. */
|
|
29
|
+
readonly lineWidth?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Formats a Markdown fragment to the canonical MarkSpec style. */
|
|
32
|
+
export type ProseFormatter = (markdown: string, options?: ProseFormatOptions) => string;
|
|
33
|
+
/**
|
|
34
|
+
* The fixed MarkSpec Markdown style (ADR-029). Zero configuration by
|
|
35
|
+
* design — one canonical form across every project. `newLineKind` is
|
|
36
|
+
* "lf" because `format()` operates on a pure-LF buffer and re-applies
|
|
37
|
+
* the file's detected line ending on output.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MARKSPEC_MARKDOWN_GLOBAL_CONFIG: Readonly<{
|
|
40
|
+
lineWidth: number;
|
|
41
|
+
newLineKind: "lf";
|
|
42
|
+
}>;
|
|
43
|
+
/** Plugin-level style knobs. See ADR-029 for the rationale per value.
|
|
44
|
+
*
|
|
45
|
+
* Frozen: this is the single canonical MarkSpec style, exported through the
|
|
46
|
+
* public barrel. Freezing stops a consumer from mutating the shared object
|
|
47
|
+
* after the formatter has already baked these values in at `instantiate()`
|
|
48
|
+
* (which would drift the entry-body width budget from the whole-document
|
|
49
|
+
* formatter — see `emitBodyViaAst`). */
|
|
50
|
+
export declare const MARKSPEC_MARKDOWN_PLUGIN_CONFIG: Readonly<Record<string, unknown>>;
|
|
51
|
+
/**
|
|
52
|
+
* Load the dprint-markdown WASM plugin (once — subsequent calls return
|
|
53
|
+
* the cached instance) and return a synchronous prose formatter.
|
|
54
|
+
*
|
|
55
|
+
* A failed instantiation is NOT cached: the rejected promise is cleared
|
|
56
|
+
* before it propagates, so the next call retries from scratch instead of
|
|
57
|
+
* replaying the same failure forever. This matters for the long-lived LSP
|
|
58
|
+
* session, where a transient WASM-load failure must not permanently
|
|
59
|
+
* disable formatting for the rest of the process.
|
|
60
|
+
*/
|
|
61
|
+
export declare function loadMarkdownFormatter(): Promise<ProseFormatter>;
|
|
62
|
+
//# sourceMappingURL=dprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dprint.d.ts","sourceRoot":"","sources":["../../src/formatter/dprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yDAAyD;AACzD,MAAM,WAAW,kBAAkB;IACjC;;;yEAGqE;IACrE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,mEAAmE;AACnE,MAAM,MAAM,cAAc,GAAG,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,kBAAkB,KACzB,MAAM,CAAC;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,IAAI,CAAC;CACnB,CAGC,CAAC;AAEH;;;;;;wCAMwC;AACxC,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMvB,CAAC;AAIH;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAAC,cAAc,CAAC,CAM/D"}
|