Skip to content

Development

m4bwav edited this page Sep 30, 2026 · 2 revisions

The repository is m4bwav/markdown-plain-link-replacer. Version 2 is TypeScript in src/, built by tsdown into an ES module and a CommonJS build, each with its declaration file, plus the command line tool dist/cli.mjs.

Layout

File What it does
src/scan-links.ts Finds what url-regex 4.1.1 matched in 1.x, in linear time.
src/find-links.ts Trims trailing punctuation and skips code, existing links, autolinks, reference definitions and HTML attributes; keeps http and https only.
src/replace-plain-links.ts The pipeline: an image check per distinct address, title lookups 100 ms apart, the replacements from the end of the text.
src/template.ts The mustache renderer, matching hogan.js 3.0.2's output, and the default template.
src/source.ts {{source}}, from tldts.
src/index.ts, src/cli.ts The entry point of both builds, and the command line tool.

Commands

npm ci
npm run build          # tsdown -> dist/
npm test               # build, then node --test: golden, unit, functional, CLI, package shape
npm run test:consumers # pack, install the tarball in a scratch project, run the ESM, CJS, type and bin fixtures
npm run test:live      # opt-in: two real pages
npm run coverage       # fails under 95% lines or 90% branches
npm run lint           # xo
npm run typecheck      # tsc --noEmit
npm run check          # publint, attw, npm pack --dry-run

Building needs Node 22.18 or later (tsdown); the built package and its tests run on Node 20 and later. npm test on a fresh export of the repository at 2.0.0 (Windows 11, Node 24.18.0, 2026-09-29) ran 400 tests in 14 suites: 396 passed, 4 skipped, none failed. No test touches the internet: every page a test requests is served by test/golden/fixture-server.cjs on 127.0.0.1.

Continuous integration

ci.yml runs lint and typecheck; the package shape and coverage; every suite against both builds on Node 20, 22, 24 and 26 on Ubuntu, and on Node 24 on Windows and macOS; and Bun and Deno jobs. live.yml holds the opt-in live test, release.yml builds, tests and stages each tagged release on npm through trusted publishing, and verify-published.yml installs the published version and checks it.

The golden files

test/golden/1.1.16.json is what the published 1.1.16 answered for 154 calls and 18 command line runs, recorded against the local fixture server. test/golden/golden.test.js holds 2.x to those answers, apart from exceptions it names one by one with their plan item. The recording, its capture script, the fixture server and the codec are never edited; Versions and upgrading shows the capture replayed against both versions.

Releases

A release follows the ritual in the repository's AGENTS.md: the CHANGELOG entry with its date, a preflight script, npm version, then a pushed tag. release.yml stages the npm publish and creates the GitHub Release; the maintainer approves the staged version on npmjs.com with two-factor authentication.

This wiki

The pages live in the wiki's own git repository (markdown-plain-link-replacer.wiki.git). Every example on them was printed by ai-docs/notes/2026-09-29-wiki-verify.mjs in the main repository, run against the published package; its output is saved beside it, and the note ai-docs/notes/2026-09-29-github-wiki.md says how to run it again for the next release.

Clone this wiki locally