ebdcb5776a
- publint-all: the recursive publication view uses readdirSync
{recursive} again instead of globSync('**/*') — the glob skips
dot-prefixed segments (verified empirically), but npm pack publishes
dotfiles inside included directories, so hidden exports were
reported missing and other hidden files escaped validation
- markdown.ts/verify-type-equiv: markdownFences now reports whether a
closing delimiter terminates the block (mdast silently closes an
unterminated fence at EOF), and verify-type-equiv rejects unclosed
type-equivalence fences again — the Agent Note claimed such a block
still fails at the manifest checks, but its comparisons can succeed
- Agent Note EN+ZH: record the restored rejection; rewrite the zh
Problem section into past tense to match the English side's shipped
reality; pair re-recorded
4.8 KiB
4.8 KiB
Agent Note: Consolidate gate scripts on already-present deps and builtins
Status: implemented
English | 中文
Problem
The scripts/ gates mostly used the right tools (node:fs globSync in 15+ gates, mdast/micromark in the markdown gates), but a handful of stragglers hand-rolled what a sibling gate already did with an existing dependency or builtin:
- Duplicated fence scanners.
scripts/md-fences.ts(~55 lines, consumed bydoc-typecheck.ts) andextractEquivBlocksinscripts/verify-type-equiv.ts(~39 lines) were two copies of the same regex line-scanner for fenced code blocks, whilescripts/verify-mermaid.tsalready extracted fences by visiting mdastcodenodes — andmarkdownProseLinesinscripts/markdown.tsitself parsed to mdast but then hand-tracked fence state with a second regex. The regex scanners only recognized backtick fences at column 0, so they silently disagreed with the mdast-based gates on tilde and indented fences. - Hand-rolled argv parsing.
parseOptionsinscripts/publint-all.tsand its near-identical copy inscripts/verify-built-package-invariants.mjs(~26 lines) stepped argv indexes manually, while sibling scripts (verify-runtime-closure.ts,build-exe-for-python-sdk.ts,packages/sdk/scripts/src/args.ts) already used thenode:utilparseArgsbuiltin. - Hand-rolled directory walks. Five sites re-derived nested
readdirSyncwalks thatglobSynccovers:verify-runtime-closure.ts(packages + vendor manifests),dev-web.tsdiscoverPluginDirs,verify-package-paths.tsrealPackageNames,verify-client-domain-graph.tslistSources, andpublint-all.tsaddPath(~55–65 lines total).scripts/package-invariants.tsshows the one-lineglobSynctemplate.
No new dependency was needed anywhere; every replacement is an existing devDep or a Node builtin.
Decision
- A shared mdast fence helper,
markdownFencesinscripts/markdown.ts, visitscodenodes for the language, full info string, body, and 1-based opening-fence line;doc-typecheck.tsandverify-type-equiv.tsextract fences through it.md-fences.tsand the duplicatedextractEquivBlocksscanner are deleted, andmarkdownProseLinesderives fenced lines from the parsedcodenodes' positions instead of a second regex. - Both CLIs parse argv via
parseArgs; unknown options and missing values still fail loud, withparseArgs's own error text instead of the bespoke usage strings. - The five straggler walks use
globSync. The walks incheck-workspace-constraints.tsandclean.tsstay: they need dirent-level detail to diagnose malformed trees, which glob-by-pattern cannot report.
Alternatives considered
- A new glob/walking dependency (
tinyglobby,fdir). Rejected: the builtin already won repo-wide; these were stragglers, not a gap. p-mapforpublint-all.ts's ~19-line ordered worker pool. Deliberately left out: one new devDep for one small deletion is at the edge of the dependency policy bar, and the pool's requirements (bounded workers, deterministic order, env override) are documented in the parallel-gates note. Fold it in only ifp-mapearns a second consumer.- Leaving the fence scanners. Rejected: two drifting copies of a parser beside a third correct implementation is exactly the duplication the shared
markdown.tshelper exists to prevent, and the column-0-backtick-only limitation was a latent inconsistency between sibling gates.
Consequences
- One fence parser: every markdown gate now classifies fences through mdast, so tilde, indented, and 4-backtick container fences behave identically everywhere. The docs tree contained no fence shape the regex scanners mishandled, so gate results are unchanged on the tree that landed the swap:
pnpm run doc-syncand each rewritten gate ran before and after with byte-identical output (doc-typecheckblock/opt-out counts,verify-type-equivmatch counts,publint,verify-built-package-invariants,verify-runtime-closure,verify-package-paths,verify-client-domain-graph, and both package-README prose gates). verify-type-equivstill rejects an unterminated type-equivalence fence: mdast silently closes an unterminated block at end-of-file (its comparisons could then pass), so the shared helper reports whether a closing delimiter exists and the gate errors on an unclosed block, preserving the removed scanner's rejection. Thedoc-typecheckscanner never had that error path.parseArgskeeps the last value of a duplicated option instead of erroring — a dev-tool edge case the tests don't pin, accepted in exchange for deleting the two bespoke parsers. (Strict mode still rejects a---prefixed token where a value is expected, matching the replaced parsers.)