@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.
Files changed (119) hide show
  1. package/esm/compiler/mod.d.ts +7 -0
  2. package/esm/compiler/mod.d.ts.map +1 -1
  3. package/esm/compiler/mod.js +17 -3
  4. package/esm/compiler/schema.d.ts +8 -1
  5. package/esm/compiler/schema.d.ts.map +1 -1
  6. package/esm/compiler/schema.js +8 -1
  7. package/esm/config/mod.d.ts.map +1 -1
  8. package/esm/config/mod.js +25 -0
  9. package/esm/discovery/gitignore.d.ts +40 -0
  10. package/esm/discovery/gitignore.d.ts.map +1 -0
  11. package/esm/discovery/gitignore.js +145 -0
  12. package/esm/discovery/mod.d.ts +54 -0
  13. package/esm/discovery/mod.d.ts.map +1 -0
  14. package/esm/discovery/mod.js +122 -0
  15. package/esm/formatter/dprint.d.ts +62 -0
  16. package/esm/formatter/dprint.d.ts.map +1 -0
  17. package/esm/formatter/dprint.js +83 -0
  18. package/esm/formatter/md_equiv.d.ts +24 -0
  19. package/esm/formatter/md_equiv.d.ts.map +1 -0
  20. package/esm/formatter/md_equiv.js +81 -0
  21. package/esm/formatter/mod.d.ts +25 -0
  22. package/esm/formatter/mod.d.ts.map +1 -1
  23. package/esm/formatter/mod.js +106 -6
  24. package/esm/formatter/prose.d.ts +48 -0
  25. package/esm/formatter/prose.d.ts.map +1 -0
  26. package/esm/formatter/prose.js +85 -0
  27. package/esm/mod.d.ts +10 -4
  28. package/esm/mod.d.ts.map +1 -1
  29. package/esm/mod.js +7 -2
  30. package/esm/model/mod.d.ts +25 -1
  31. package/esm/model/mod.d.ts.map +1 -1
  32. package/esm/model/mod.js +1 -0
  33. package/esm/model/profile.d.ts +34 -0
  34. package/esm/model/profile.d.ts.map +1 -1
  35. package/esm/parser/markdown.d.ts.map +1 -1
  36. package/esm/parser/markdown.js +28 -15
  37. package/esm/profile/chain.js +1 -0
  38. package/esm/profile/delivered.d.ts +27 -0
  39. package/esm/profile/delivered.d.ts.map +1 -0
  40. package/esm/profile/delivered.js +60 -0
  41. package/esm/profile/manifest.d.ts +1 -0
  42. package/esm/profile/manifest.d.ts.map +1 -1
  43. package/esm/profile/manifest.js +107 -0
  44. package/esm/profile/merge.d.ts.map +1 -1
  45. package/esm/profile/merge.js +21 -0
  46. package/esm/refs/mod.d.ts.map +1 -1
  47. package/esm/refs/mod.js +22 -0
  48. package/esm/reporter/mod.js +17 -4
  49. package/esm/self_upgrade/target.d.ts +3 -3
  50. package/esm/self_upgrade/target.d.ts.map +1 -1
  51. package/esm/self_upgrade/target.js +4 -2
  52. package/esm/validator/corpus.d.ts +25 -0
  53. package/esm/validator/corpus.d.ts.map +1 -0
  54. package/esm/validator/corpus.js +138 -0
  55. package/esm/validator/listing.d.ts.map +1 -1
  56. package/esm/validator/listing.js +4 -1
  57. package/esm/validator/mod.d.ts +2 -0
  58. package/esm/validator/mod.d.ts.map +1 -1
  59. package/esm/validator/mod.js +1 -0
  60. package/package.json +3 -1
  61. package/script/compiler/mod.d.ts +7 -0
  62. package/script/compiler/mod.d.ts.map +1 -1
  63. package/script/compiler/mod.js +16 -2
  64. package/script/compiler/schema.d.ts +8 -1
  65. package/script/compiler/schema.d.ts.map +1 -1
  66. package/script/compiler/schema.js +8 -1
  67. package/script/config/mod.d.ts.map +1 -1
  68. package/script/config/mod.js +25 -0
  69. package/script/discovery/gitignore.d.ts +40 -0
  70. package/script/discovery/gitignore.d.ts.map +1 -0
  71. package/script/discovery/gitignore.js +149 -0
  72. package/script/discovery/mod.d.ts +54 -0
  73. package/script/discovery/mod.d.ts.map +1 -0
  74. package/script/discovery/mod.js +128 -0
  75. package/script/formatter/dprint.d.ts +62 -0
  76. package/script/formatter/dprint.d.ts.map +1 -0
  77. package/script/formatter/dprint.js +120 -0
  78. package/script/formatter/md_equiv.d.ts +24 -0
  79. package/script/formatter/md_equiv.d.ts.map +1 -0
  80. package/script/formatter/md_equiv.js +87 -0
  81. package/script/formatter/mod.d.ts +25 -0
  82. package/script/formatter/mod.d.ts.map +1 -1
  83. package/script/formatter/mod.js +106 -5
  84. package/script/formatter/prose.d.ts +48 -0
  85. package/script/formatter/prose.d.ts.map +1 -0
  86. package/script/formatter/prose.js +88 -0
  87. package/script/mod.d.ts +10 -4
  88. package/script/mod.d.ts.map +1 -1
  89. package/script/mod.js +22 -3
  90. package/script/model/mod.d.ts +25 -1
  91. package/script/model/mod.d.ts.map +1 -1
  92. package/script/model/mod.js +1 -0
  93. package/script/model/profile.d.ts +34 -0
  94. package/script/model/profile.d.ts.map +1 -1
  95. package/script/parser/markdown.d.ts.map +1 -1
  96. package/script/parser/markdown.js +27 -14
  97. package/script/profile/chain.js +1 -0
  98. package/script/profile/delivered.d.ts +27 -0
  99. package/script/profile/delivered.d.ts.map +1 -0
  100. package/script/profile/delivered.js +65 -0
  101. package/script/profile/manifest.d.ts +1 -0
  102. package/script/profile/manifest.d.ts.map +1 -1
  103. package/script/profile/manifest.js +108 -1
  104. package/script/profile/merge.d.ts.map +1 -1
  105. package/script/profile/merge.js +21 -0
  106. package/script/refs/mod.d.ts.map +1 -1
  107. package/script/refs/mod.js +22 -0
  108. package/script/reporter/mod.js +17 -4
  109. package/script/self_upgrade/target.d.ts +3 -3
  110. package/script/self_upgrade/target.d.ts.map +1 -1
  111. package/script/self_upgrade/target.js +4 -2
  112. package/script/validator/corpus.d.ts +25 -0
  113. package/script/validator/corpus.d.ts.map +1 -0
  114. package/script/validator/corpus.js +142 -0
  115. package/script/validator/listing.d.ts.map +1 -1
  116. package/script/validator/listing.js +4 -1
  117. package/script/validator/mod.d.ts +2 -0
  118. package/script/validator/mod.d.ts.map +1 -1
  119. package/script/validator/mod.js +4 -1
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/discovery/gitignore
4
+ *
5
+ * Pure-TypeScript `.gitignore` pattern matcher. Implements the standard
6
+ * semantics the discovery walker needs: `#` comments, `!` negation,
7
+ * trailing-`/` directory-only patterns, leading-`/` and contains-`/`
8
+ * anchoring, `*` / `?` / `[...]` globs, and `**` cross-directory globs.
9
+ * Last matching rule wins.
10
+ *
11
+ * Per git semantics, a file inside an ignored directory cannot be
12
+ * re-included by a negation — the walker enforces this by pruning
13
+ * ignored directories without descending.
14
+ *
15
+ * No I/O, no platform APIs — Node-compatible by construction.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.parseGitignore = parseGitignore;
19
+ exports.isIgnored = isIgnored;
20
+ const REGEX_SPECIALS = /[.+^${}()|\\]/;
21
+ function escapeRegexChar(c) {
22
+ return REGEX_SPECIALS.test(c) ? `\\${c}` : c;
23
+ }
24
+ /** Translate one gitignore glob (already stripped of `!`, `/` affixes)
25
+ * into a regex source string. */
26
+ function globToRegexSource(pattern) {
27
+ let re = "";
28
+ let i = 0;
29
+ while (i < pattern.length) {
30
+ const c = pattern[i];
31
+ if (c === "*") {
32
+ // Consume the whole run of consecutive `*` so we never emit adjacent
33
+ // unbounded quantifiers (which backtrack catastrophically against a
34
+ // non-matching input). Git likewise treats consecutive `*` that are
35
+ // not a slash-delimited `**` as regular asterisks.
36
+ let stars = 0;
37
+ while (pattern[i] === "*") {
38
+ stars++;
39
+ i++;
40
+ }
41
+ if (stars >= 2 && pattern[i] === "/") {
42
+ re += "(?:[^/]+/)*"; // `**/` — zero or more whole segments
43
+ i++; // consume the `/`
44
+ }
45
+ else if (stars >= 2) {
46
+ re += ".*"; // leading/trailing/bare `**` — crosses directories
47
+ }
48
+ else {
49
+ re += "[^/]*"; // single `*` — within one path segment
50
+ }
51
+ }
52
+ else if (c === "?") {
53
+ re += "[^/]";
54
+ i++;
55
+ }
56
+ else if (c === "[") {
57
+ const end = pattern.indexOf("]", i + 1);
58
+ if (end < 0) {
59
+ re += "\\[";
60
+ i++;
61
+ }
62
+ else {
63
+ let cls = pattern.slice(i + 1, end);
64
+ if (cls.startsWith("!"))
65
+ cls = `^${cls.slice(1)}`;
66
+ re += `[${cls}]`;
67
+ i = end + 1;
68
+ }
69
+ }
70
+ else if (c === "\\" && i + 1 < pattern.length) {
71
+ re += escapeRegexChar(pattern[i + 1]);
72
+ i += 2;
73
+ }
74
+ else {
75
+ re += escapeRegexChar(c);
76
+ i++;
77
+ }
78
+ }
79
+ return re;
80
+ }
81
+ /**
82
+ * Parse `.gitignore` content into compiled rules.
83
+ *
84
+ * @param content - Raw file content (LF or CRLF).
85
+ * @param baseDir - Root-relative POSIX dir the `.gitignore` lives in
86
+ * (`""` for the root one). Patterns only match paths under it.
87
+ */
88
+ function parseGitignore(content, baseDir) {
89
+ const rules = [];
90
+ for (const rawLine of content.split("\n")) {
91
+ // Strip CR and unescaped trailing spaces (git semantics).
92
+ const line = rawLine.replace(/\r$/, "").replace(/(?<!\\) +$/, "");
93
+ if (line === "" || line.startsWith("#"))
94
+ continue;
95
+ let pattern = line;
96
+ let negated = false;
97
+ if (pattern.startsWith("!")) {
98
+ negated = true;
99
+ pattern = pattern.slice(1);
100
+ }
101
+ let dirOnly = false;
102
+ if (pattern.endsWith("/")) {
103
+ dirOnly = true;
104
+ pattern = pattern.slice(0, -1);
105
+ }
106
+ // A separator anywhere in the pattern anchors it to baseDir;
107
+ // otherwise it matches at any depth below baseDir.
108
+ const anchored = pattern.includes("/");
109
+ if (pattern.startsWith("/"))
110
+ pattern = pattern.slice(1);
111
+ if (pattern === "")
112
+ continue;
113
+ // baseDir is a literal directory prefix, so every regex metacharacter
114
+ // in it must be escaped — including `* ? [ ]`, which the pattern-body
115
+ // helpers (escapeRegexChar / globToRegexSource) deliberately leave
116
+ // unescaped so they can act as globs. A dir literally named `pkg[v2]`
117
+ // would otherwise inject a stray character class.
118
+ const prefix = baseDir === ""
119
+ ? ""
120
+ : `${baseDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`;
121
+ const depth = anchored ? "" : "(?:.*/)?";
122
+ let regex;
123
+ try {
124
+ regex = new RegExp(`^${prefix}${depth}${globToRegexSource(pattern)}$`);
125
+ }
126
+ catch {
127
+ continue; // skip a line that compiles to an invalid regex (e.g. a
128
+ // malformed character class) rather than crashing discovery
129
+ }
130
+ rules.push({ regex, negated, dirOnly });
131
+ }
132
+ return rules;
133
+ }
134
+ /**
135
+ * Test a root-relative POSIX path against compiled rules.
136
+ * Last matching rule wins; no match → not ignored.
137
+ *
138
+ * @param isDir - Directory-only rules (`build/`) match only when true.
139
+ */
140
+ function isIgnored(relPath, isDir, rules) {
141
+ let ignored = false;
142
+ for (const rule of rules) {
143
+ if (rule.dirOnly && !isDir)
144
+ continue;
145
+ if (rule.regex.test(relPath))
146
+ ignored = !rule.negated;
147
+ }
148
+ return ignored;
149
+ }
@@ -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,128 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/discovery
4
+ *
5
+ * Gitignore-aware project file discovery — the single walker every
6
+ * MarkSpec surface uses (CLI verbs, LSP indexing, lockfile entry
7
+ * collection). Yields absolute paths of MarkSpec-relevant files under a
8
+ * root, honoring (in precedence order):
9
+ *
10
+ * 1. built-in skips — hidden directories (name starts with `.`)
11
+ * 2. `.gitignore` files (root + nested, standard semantics)
12
+ * 3. caller-supplied `exclude` patterns (gitignore syntax, root-anchored)
13
+ *
14
+ * I/O is injected via {@linkcode DiscoveryIO} so the module stays
15
+ * Node-compatible; entry points supply the Deno implementation.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RELEVANT_EXTENSIONS = exports.MARKDOWN_EXTENSIONS = exports.SOURCE_EXTENSIONS = exports.parseGitignore = exports.isIgnored = void 0;
19
+ exports.discoverFiles = discoverFiles;
20
+ const path_1 = require("@std/path");
21
+ const gitignore_js_1 = require("./gitignore.js");
22
+ var gitignore_js_2 = require("./gitignore.js");
23
+ Object.defineProperty(exports, "isIgnored", { enumerable: true, get: function () { return gitignore_js_2.isIgnored; } });
24
+ Object.defineProperty(exports, "parseGitignore", { enumerable: true, get: function () { return gitignore_js_2.parseGitignore; } });
25
+ /**
26
+ * Source-file extensions the parser can extract doc-comment entries
27
+ * from (tree-sitter grammars available). Single SSOT — `lsp/context.ts`
28
+ * imports this set.
29
+ */
30
+ exports.SOURCE_EXTENSIONS = new Set([
31
+ ".rs",
32
+ ".kt",
33
+ ".kts",
34
+ ".java",
35
+ ".c",
36
+ ".h",
37
+ ".cpp",
38
+ ".cc",
39
+ ".cxx",
40
+ ".hpp",
41
+ ".hxx",
42
+ ".ts",
43
+ ".tsx",
44
+ ".jsx",
45
+ ".js",
46
+ ".mjs",
47
+ ".cjs",
48
+ ".cs",
49
+ ]);
50
+ /** Markdown only — the `fmt` scope (the formatter never rewrites source). */
51
+ exports.MARKDOWN_EXTENSIONS = new Set([".md"]);
52
+ /** Everything MarkSpec-relevant: markdown + source families. */
53
+ exports.RELEVANT_EXTENSIONS = new Set([
54
+ ...exports.MARKDOWN_EXTENSIONS,
55
+ ...exports.SOURCE_EXTENSIONS,
56
+ ]);
57
+ /**
58
+ * Directory names pruned by default, in addition to the hidden-dir skip.
59
+ * These are the common build-output / dependency directories the
60
+ * pre-`core/discovery` walkers (LSP `walkDirectory`, lockfile
61
+ * `collectEntries`) hardcoded; keeping them restores that guarantee
62
+ * independent of a consumer's `.gitignore` — otherwise a project that does
63
+ * not list them recurses into build artifacts (duplicate-ID noise, slow LSP
64
+ * indexing, spurious `MSL-L212` edge-hash entries).
65
+ *
66
+ * Unlike the hidden-dir skip these are overridable: they are applied as the
67
+ * LOWEST-precedence rule layer (before `.gitignore` and `exclude:`), so a
68
+ * negated `!target/` entry in either re-includes them under gitignore
69
+ * last-match-wins.
70
+ */
71
+ const BUILTIN_SKIP_DIRS = [
72
+ "node_modules",
73
+ "target",
74
+ "dist",
75
+ "build",
76
+ ];
77
+ /** Compiled once: the built-in skip as unanchored, directory-only gitignore
78
+ * rules (each matches a directory of that name at any depth). */
79
+ const BUILTIN_SKIP_RULES = (0, gitignore_js_1.parseGitignore)(BUILTIN_SKIP_DIRS.map((d) => `${d}/`).join("\n"), "");
80
+ /**
81
+ * Walk `root` recursively, yielding absolute paths of relevant files.
82
+ * Entries are yielded in sorted order per directory — deterministic
83
+ * output across filesystems. Unreadable directories are skipped.
84
+ */
85
+ async function* discoverFiles(root, io, options = {}) {
86
+ const extensions = options.extensions ?? exports.RELEVANT_EXTENSIONS;
87
+ const excludeRules = (0, gitignore_js_1.parseGitignore)((options.exclude ?? []).join("\n"), "");
88
+ // Built-in build-output skips are the lowest-precedence layer: `.gitignore`
89
+ // (appended per-directory in `walk`) and `exclude:` both come after, so a
90
+ // `!target/` negation in either overrides them.
91
+ yield* walk(root, "", [...BUILTIN_SKIP_RULES, ...excludeRules], io, extensions);
92
+ }
93
+ async function* walk(absDir, relDir, rules, io, extensions) {
94
+ // Nested .gitignore rules append after inherited ones — deeper rules
95
+ // win under last-match-wins.
96
+ const raw = await io.readFile((0, path_1.join)(absDir, ".gitignore"));
97
+ const active = raw !== undefined && raw.length > 0
98
+ ? [...rules, ...(0, gitignore_js_1.parseGitignore)(raw, relDir)]
99
+ : rules;
100
+ const entries = [];
101
+ try {
102
+ for await (const e of io.readDir(absDir))
103
+ entries.push(e);
104
+ }
105
+ catch {
106
+ return; // unreadable directory — a project walk must not abort
107
+ }
108
+ entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
109
+ for (const entry of entries) {
110
+ const rel = relDir === "" ? entry.name : `${relDir}/${entry.name}`;
111
+ if (entry.isDirectory) {
112
+ if (entry.name.startsWith("."))
113
+ continue; // built-in: hidden dirs
114
+ // Git semantics: paths under an ignored directory cannot be
115
+ // re-included, so pruning here is correct (and fast).
116
+ if ((0, gitignore_js_1.isIgnored)(rel, true, active))
117
+ continue;
118
+ yield* walk((0, path_1.join)(absDir, entry.name), rel, active, io, extensions);
119
+ }
120
+ else if (entry.isFile) {
121
+ if (!extensions.has((0, path_1.extname)(entry.name).toLowerCase()))
122
+ continue;
123
+ if ((0, gitignore_js_1.isIgnored)(rel, false, active))
124
+ continue;
125
+ yield (0, path_1.join)(absDir, entry.name);
126
+ }
127
+ }
128
+ }
@@ -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"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ /**
3
+ * @module formatter/dprint
4
+ *
5
+ * Loader for the embedded dprint-markdown WASM plugin (ADR-029).
6
+ * `markspec fmt` formats whole Markdown documents with one canonical,
7
+ * zero-config style; this module owns that style and the (cached)
8
+ * WASM instantiation. Dynamic imports keep the plugin off every code
9
+ * path except formatting (`fmt`, the `check` MSL-F010 drift gate, LSP
10
+ * documentFormatting).
11
+ *
12
+ * Node-compatible: `node:fs/promises` + WebAssembly only, no `Deno.*`.
13
+ *
14
+ * Packaging note: `@dprint/formatter` and `@dprint/markdown` are dynamically
15
+ * imported bare npm specifiers, and their `plugin.wasm` ships inside the npm
16
+ * package — no vendored copy in this repo. `deno compile` only embeds the
17
+ * resolved npm tree (and thus the wasm) when the compile entry point itself
18
+ * lives inside this workspace member (`packages/markspec/`); an entry point
19
+ * outside that tree can't resolve the import map at runtime. The project's
20
+ * one real compile target (`packages/markspec/main.ts`) already satisfies
21
+ * this, so it's a non-issue in production — it only bites a from-scratch
22
+ * smoke test placed elsewhere.
23
+ */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || (function () {
41
+ var ownKeys = function(o) {
42
+ ownKeys = Object.getOwnPropertyNames || function (o) {
43
+ var ar = [];
44
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
45
+ return ar;
46
+ };
47
+ return ownKeys(o);
48
+ };
49
+ return function (mod) {
50
+ if (mod && mod.__esModule) return mod;
51
+ var result = {};
52
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
53
+ __setModuleDefault(result, mod);
54
+ return result;
55
+ };
56
+ })();
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG = exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG = void 0;
59
+ exports.loadMarkdownFormatter = loadMarkdownFormatter;
60
+ /**
61
+ * The fixed MarkSpec Markdown style (ADR-029). Zero configuration by
62
+ * design — one canonical form across every project. `newLineKind` is
63
+ * "lf" because `format()` operates on a pure-LF buffer and re-applies
64
+ * the file's detected line ending on output.
65
+ */
66
+ exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG = Object.freeze({
67
+ lineWidth: 80,
68
+ newLineKind: "lf",
69
+ });
70
+ /** Plugin-level style knobs. See ADR-029 for the rationale per value.
71
+ *
72
+ * Frozen: this is the single canonical MarkSpec style, exported through the
73
+ * public barrel. Freezing stops a consumer from mutating the shared object
74
+ * after the formatter has already baked these values in at `instantiate()`
75
+ * (which would drift the entry-body width budget from the whole-document
76
+ * formatter — see `emitBodyViaAst`). */
77
+ exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG = Object.freeze({
78
+ textWrap: "always",
79
+ emphasisKind: "underscores",
80
+ strongKind: "asterisks",
81
+ unorderedListKind: "dashes",
82
+ });
83
+ let cached;
84
+ /**
85
+ * Load the dprint-markdown WASM plugin (once — subsequent calls return
86
+ * the cached instance) and return a synchronous prose formatter.
87
+ *
88
+ * A failed instantiation is NOT cached: the rejected promise is cleared
89
+ * before it propagates, so the next call retries from scratch instead of
90
+ * replaying the same failure forever. This matters for the long-lived LSP
91
+ * session, where a transient WASM-load failure must not permanently
92
+ * disable formatting for the rest of the process.
93
+ */
94
+ function loadMarkdownFormatter() {
95
+ cached ??= instantiate().catch((err) => {
96
+ cached = undefined;
97
+ throw err;
98
+ });
99
+ return cached;
100
+ }
101
+ async function instantiate() {
102
+ const { createFromBuffer } = await Promise.resolve().then(() => __importStar(require("@dprint/formatter")));
103
+ const { getPath } = await Promise.resolve().then(() => __importStar(require("@dprint/markdown")));
104
+ const { readFile } = await Promise.resolve().then(() => __importStar(require("node:fs/promises")));
105
+ const wasm = await readFile(getPath());
106
+ // `readFile` returns a Node `Buffer`, whose `buffer` property is typed
107
+ // `ArrayBufferLike` (may be a `SharedArrayBuffer`) — not assignable to
108
+ // `BufferSource`'s `ArrayBuffer`-backed view. Copy into a plain
109
+ // `Uint8Array` so the type is unambiguous; this runs once per process
110
+ // (the result is cached by `loadMarkdownFormatter`).
111
+ const formatter = createFromBuffer(Uint8Array.from(wasm));
112
+ formatter.setConfig(exports.MARKSPEC_MARKDOWN_GLOBAL_CONFIG, exports.MARKSPEC_MARKDOWN_PLUGIN_CONFIG);
113
+ return (markdown, options) => formatter.formatText({
114
+ filePath: "fragment.md",
115
+ fileText: markdown,
116
+ overrideConfig: options?.lineWidth !== undefined
117
+ ? { lineWidth: options.lineWidth }
118
+ : undefined,
119
+ });
120
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module formatter/md_equiv
3
+ *
4
+ * CommonMark-semantic Markdown equivalence — the gate for the ADR-029
5
+ * dprint pass. Two fragments are equivalent when they parse to the
6
+ * same mdast structure after eliding source `position`s and collapsing
7
+ * ASCII whitespace runs inside `text` node values. Only ASCII
8
+ * whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
9
+ * content, not wrap artifacts, and must not compare equal to a plain
10
+ * space. Soft-wrap positions,
11
+ * emphasis delimiter style (`*x*` vs `_x_`), table cell padding, and
12
+ * list marker style are presentation, not content — they compare
13
+ * equal. Hard breaks are `break` nodes in mdast, so wrap-collapsing
14
+ * cannot erase or fabricate one. Code (`code`, `inlineCode`), `html`,
15
+ * and definition `url`s stay byte-exact.
16
+ *
17
+ * DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
18
+ * inline markup). Used ONLY to accept/reject dprint output; the
19
+ * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
20
+ * not be modified.
21
+ */
22
+ /** True when `a` and `b` are the same Markdown, modulo presentation. */
23
+ export declare function markdownSemanticallyEquivalent(a: string, b: string): boolean;
24
+ //# sourceMappingURL=md_equiv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * @module formatter/md_equiv
4
+ *
5
+ * CommonMark-semantic Markdown equivalence — the gate for the ADR-029
6
+ * dprint pass. Two fragments are equivalent when they parse to the
7
+ * same mdast structure after eliding source `position`s and collapsing
8
+ * ASCII whitespace runs inside `text` node values. Only ASCII
9
+ * whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
10
+ * content, not wrap artifacts, and must not compare equal to a plain
11
+ * space. Soft-wrap positions,
12
+ * emphasis delimiter style (`*x*` vs `_x_`), table cell padding, and
13
+ * list marker style are presentation, not content — they compare
14
+ * equal. Hard breaks are `break` nodes in mdast, so wrap-collapsing
15
+ * cannot erase or fabricate one. Code (`code`, `inlineCode`), `html`,
16
+ * and definition `url`s stay byte-exact.
17
+ *
18
+ * DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
19
+ * inline markup). Used ONLY to accept/reject dprint output; the
20
+ * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
21
+ * not be modified.
22
+ */
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.markdownSemanticallyEquivalent = markdownSemanticallyEquivalent;
28
+ const unified_1 = require("unified");
29
+ const remark_parse_1 = __importDefault(require("remark-parse"));
30
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
31
+ const parser = (0, unified_1.unified)().use(remark_parse_1.default).use(remark_gfm_1.default);
32
+ /** True when `a` and `b` are the same Markdown, modulo presentation. */
33
+ function markdownSemanticallyEquivalent(a, b) {
34
+ if (a === b)
35
+ return true;
36
+ return deepEqual(normalize(parser.parse(a)), normalize(parser.parse(b)));
37
+ }
38
+ /**
39
+ * Recursively strip `position` keys and collapse ASCII whitespace runs
40
+ * in `text` node values (reflow can only introduce ASCII spaces and
41
+ * newlines; `\s` would also match NBSP and Unicode Zs spaces, letting
42
+ * a content change pass as a wrap change). Returns a plain JSON-ish
43
+ * structure for comparison; never mutates the input tree.
44
+ */
45
+ function normalize(node) {
46
+ if (Array.isArray(node))
47
+ return node.map(normalize);
48
+ if (node === null || typeof node !== "object")
49
+ return node;
50
+ const src = node;
51
+ const out = {};
52
+ for (const key of Object.keys(src).sort()) {
53
+ if (key === "position")
54
+ continue;
55
+ if (key === "value" && src.type === "text" &&
56
+ typeof src.value === "string") {
57
+ out.value = src.value.replace(/[ \t\r\n\f\v]+/g, " ");
58
+ continue;
59
+ }
60
+ out[key] = normalize(src[key]);
61
+ }
62
+ return out;
63
+ }
64
+ /** Structural deep-equality over the normalized trees. */
65
+ function deepEqual(a, b) {
66
+ if (a === b)
67
+ return true;
68
+ if (typeof a !== typeof b)
69
+ return false;
70
+ if (a === null || b === null)
71
+ return a === b;
72
+ if (Array.isArray(a) || Array.isArray(b)) {
73
+ if (!Array.isArray(a) || !Array.isArray(b))
74
+ return false;
75
+ if (a.length !== b.length)
76
+ return false;
77
+ return a.every((v, i) => deepEqual(v, b[i]));
78
+ }
79
+ if (typeof a === "object" && typeof b === "object") {
80
+ const ak = Object.keys(a);
81
+ const bk = Object.keys(b);
82
+ if (ak.length !== bk.length)
83
+ return false;
84
+ return ak.every((k) => deepEqual(a[k], b[k]));
85
+ }
86
+ return false;
87
+ }