@datalackey/update-markdown-toc 1.1.12 → 1.2.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/README.md CHANGED
@@ -32,7 +32,7 @@
32
32
  - [Design Goals and Philosophy](#design-goals-and-philosophy)
33
33
  - [Packaging, Publishing, and Inter-relationship with Other Plugins](#packaging-publishing-and-inter-relationship-with-other-plugins)
34
34
  - [Known Limitations](#known-limitations)
35
- - [Guidelines For Project Contributors](#guidelines-for-project-contributors)
35
+ - [Contributing and Releasing](#contributing-and-releasing)
36
36
  <!-- TOC:END -->
37
37
 
38
38
 
@@ -40,14 +40,14 @@
40
40
 
41
41
  A Node.js command-line **documentation helper** which automatically:
42
42
 
43
- - generates Table of Contents (TOC) blocks for Markdown files
43
+ - generates Table of Contents (TOC) blocks for Markdown files (using GitHub's Markdown renderer)
44
44
  - operates on either a single file, or recursively finds all `*.md` files from a root path
45
45
  - regenerates TOCs from headings, targeting only regions explicitly marked with [TOC markers](#toc-markers)
46
46
  - avoids gratuitous reformatting or changes of any kind outside of regions marked by the aforementioned [TOC markers](#toc-markers)
47
47
  - avoids updating files when the generated TOC is already correct
48
48
  - provides a `--check` mode which flags Markdown files with stale TOCs (intended for CI)
49
- - generates TOC links with GitHub’s Markdown renderer.
50
-
49
+ - validates intra-document links (i.e., those between Markdown docs in the repo (including #fragments, image paths)
50
+ - validates external HTTP/HTTPS links, with configurable timeout
51
51
 
52
52
 
53
53
  ## Why not Some Other Markdown TOC Generator ?
@@ -355,7 +355,7 @@ The intended workflow is:
355
355
  This package is one component of a small ecosystem of JavaScript tooling plugins maintained as individual npm packages in this repository.
356
356
  The versioning and release of these packages is governed by a coordinated release policy, and
357
357
  the packages adhere to common design and architectural principles policies
358
- that are more completely described [here](../README.md).
358
+ that are more completely described [here](../../README.md).
359
359
 
360
360
  ## Known Limitations
361
361
 
@@ -369,7 +369,9 @@ In practice this affects only headings with inline code, bold, or italic syntax.
369
369
  Plain-text headings are unaffected. A fix to unify both paths is planned for a
370
370
  future release.
371
371
 
372
- ## Guidelines For Project Contributors
372
+ ## Contributing and Releasing
373
373
 
374
- Contributors to the project should consult [this document](docs/CONTRIBUTING.md)
374
+ For development setup, build workflow, and release procedures (including how to
375
+ trigger a publish via Changesets), see
376
+ [CONTRIBUTING.md](../docs/CONTRIBUTING.md).
375
377
 
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { runCli } from "@datalackey/tooling-core"
4
- import { TocFileProcessor } from "../dist/engine/TocFileProcessor.js"
5
- import { descriptor } from "../dist/cli/descriptor.js"
3
+ import { runCli } from "@datalackey/tooling-core";
4
+ import { TocFileProcessor } from "../dist/engine/TocFileProcessor.js";
5
+ import { descriptor } from "../dist/cli/descriptor.js";
6
6
 
7
7
  await runCli({
8
8
  descriptor: descriptor,
9
- processor: new TocFileProcessor()
10
- })
9
+ processor: new TocFileProcessor(),
10
+ });
@@ -0,0 +1,2 @@
1
+ import type { RunConfig } from "@datalackey/tooling-core";
2
+ export type TocRunConfig = RunConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,3 @@
1
- import type { RunConfig } from "@datalackey/tooling-core";
2
1
  import type { PluginDescriptor } from "@datalackey/tooling-core";
3
- export declare const descriptor: PluginDescriptor<RunConfig>;
2
+ import type { TocRunConfig } from "./TocRunConfig.js";
3
+ export declare const descriptor: PluginDescriptor<TocRunConfig>;
@@ -1,4 +1,4 @@
1
- import { parseBooleanOption, parseNumberOption } from "@datalackey/tooling-core";
1
+ import { parseBooleanOption, parseNumberOption, runLinkValidation, } from "@datalackey/tooling-core";
2
2
  const DEFAULT_LINK_TIMEOUT_MS = 3000;
3
3
  export const descriptor = {
4
4
  name: "update-markdown-toc",
@@ -6,24 +6,24 @@ export const descriptor = {
6
6
  options: [
7
7
  {
8
8
  flag: "--no-external-link-check",
9
- description: "Skip external link validation in check mode"
9
+ description: "Skip external link validation in check mode",
10
10
  },
11
11
  {
12
12
  flag: "-n",
13
- description: "Skip external link validation in check mode (short form)"
13
+ description: "Skip external link validation in check mode (short form)",
14
14
  },
15
15
  {
16
16
  flag: "--link-timeout-ms",
17
17
  description: "Timeout in milliseconds for external link requests (default: 3000)",
18
18
  requiresValue: true,
19
- valueName: "ms"
19
+ valueName: "ms",
20
20
  },
21
21
  {
22
22
  flag: "-l",
23
23
  description: "Timeout in milliseconds for external link requests (short form)",
24
24
  requiresValue: true,
25
- valueName: "ms"
26
- }
25
+ valueName: "ms",
26
+ },
27
27
  ],
28
28
  parseOptions(standard, passthrough) {
29
29
  const noExternalCheck = parseBooleanOption("--no-external-link-check", passthrough) ||
@@ -33,8 +33,18 @@ export const descriptor = {
33
33
  DEFAULT_LINK_TIMEOUT_MS;
34
34
  return {
35
35
  ...standard,
36
- validateExternalLinks: noExternalCheck ? false : standard.validateExternalLinks,
37
- linkTimeoutMs: timeoutMs
36
+ validateExternalLinks: noExternalCheck ? false : true,
37
+ linkTimeoutMs: timeoutMs,
38
38
  };
39
- }
39
+ },
40
+ async afterRun(files, config) {
41
+ if (config.runMode !== "check") {
42
+ return;
43
+ }
44
+ await runLinkValidation(files, {
45
+ ...config,
46
+ validateExternalLinks: config.validateExternalLinks,
47
+ linkTimeoutMs: config.linkTimeoutMs,
48
+ });
49
+ },
40
50
  };
@@ -1,5 +1,5 @@
1
- import type { FileProcessor } from "@datalackey/tooling-core";
1
+ import type { FileProcessor, ProcessingStatus } from "@datalackey/tooling-core";
2
2
  import type { RunConfig } from "@datalackey/tooling-core";
3
3
  export declare class TocFileProcessor implements FileProcessor<RunConfig> {
4
- process(filePath: string, config: RunConfig): import("@datalackey/tooling-core").ProcessingStatus;
4
+ process(filePath: string, config: RunConfig): ProcessingStatus;
5
5
  }
@@ -18,9 +18,7 @@ export function generateTOC(content) {
18
18
  const endIndex = content.indexOf(END);
19
19
  const before = content.slice(0, startIndex);
20
20
  const after = content.slice(endIndex + END.length);
21
- const contentWithoutTOC = before.replace(/\s*$/, "") +
22
- lineEnding +
23
- after.replace(/^\s*/, "");
21
+ const contentWithoutTOC = before.replace(/\s*$/, "") + lineEnding + after.replace(/^\s*/, "");
24
22
  const lines = contentWithoutTOC.split(lineEnding);
25
23
  const headings = [];
26
24
  const slugger = new GithubSlugger();
@@ -41,8 +39,6 @@ export function generateTOC(content) {
41
39
  const indent = " ".repeat(h.level - minLevel);
42
40
  return `${indent}- [${h.title}](#${h.anchor})`;
43
41
  });
44
- const tocBlock = lineEnding +
45
- tocLines.join(lineEnding) +
46
- lineEnding;
42
+ const tocBlock = lineEnding + tocLines.join(lineEnding) + lineEnding;
47
43
  return before + START + tocBlock + END + after;
48
44
  }
@@ -29,8 +29,8 @@ export function processFile(filePath, config) {
29
29
  return "unchanged";
30
30
  }
31
31
  if (config.runMode === "check") {
32
- debugLog(config, `processFile: stale filePath=${absolutePath}`);
33
- return "stale";
32
+ debugLog(config, `processFile: needsUpdate filePath=${absolutePath}`);
33
+ return "needsUpdate";
34
34
  }
35
35
  fs.writeFileSync(filePath, updated, "utf8");
36
36
  debugLog(config, `processFile: updated filePath=${absolutePath}`);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@datalackey/update-markdown-toc",
3
- "version": "1.1.12",
3
+ "version": "1.2.1",
4
4
  "description": "Auto-generate Table of Contents for a Markdown file (or files, recursively from a top level folder)",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "private": false,
8
8
  "scripts": {
9
9
  "build": "tsc -p tsconfig.json",
10
- "test": "bash scripts/run-all-tests.sh"
10
+ "test": "npx vitest run --config vitest.config.ts && bash scripts/run-all-tests.sh"
11
11
  },
12
12
  "bin": {
13
13
  "update-markdown-toc": "./bin/update-markdown-toc.js"
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/node": "^18.19.130",
53
- "jest": "^30.2.0",
54
- "typescript": "^5.9.3"
53
+ "typescript": "^5.9.3",
54
+ "vitest": "^1.0.0"
55
55
  }
56
56
  }