@doc-kit/core 0.0.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,106 @@
1
1
  # @doc-kit/core
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1023](https://github.com/nodejs/doc-kit/pull/1023) [`27a412a`](https://github.com/nodejs/doc-kit/commit/27a412ac35ab06e977b03b559e6525c0c5c5356c) Thanks [@btea](https://github.com/btea)! - Fix empty paragraphs in API docs when a typed parameter list contains trailing non-parameter items
8
+
9
+ When a loose markdown list in the API docs starts with typed parameters (e.g. `actual`, `expected`, `Returns`) but also contains plain prose bullets (e.g. algorithm complexity notes), the entire list was previously treated as a parameter signature table. The non-parameter items had no name or type, causing them to render as empty `<section>` blocks on the built site.
10
+
11
+ The fix splits the list at the first non-parameter item: typed items become the `FunctionSignature` table, and the remaining items render as regular markdown content.
12
+
13
+ - [#1045](https://github.com/nodejs/doc-kit/pull/1045) [`4a22c85`](https://github.com/nodejs/doc-kit/commit/4a22c85dca917f52c773aba084191da7c622687e) Thanks [@avivkeller](https://github.com/avivkeller)! - MDX nodes in the HTML-string pipelines are now dropped, and do not crash.
14
+
15
+ - [#1049](https://github.com/nodejs/doc-kit/pull/1049) [`8cc1fd0`](https://github.com/nodejs/doc-kit/commit/8cc1fd010ac38b16dd3c9bcd422c0ce0e5eb483d) Thanks [@avivkeller](https://github.com/avivkeller)! - Render markdown summaries as markup instead of as their source
16
+
17
+ ## 1.0.0
18
+
19
+ ### Major Changes
20
+
21
+ - [#961](https://github.com/nodejs/doc-kit/pull/961) [`c334823`](https://github.com/nodejs/doc-kit/commit/c334823a1ee7c1dc4642fa1b0dad90912de22f17) Thanks [@avivkeller](https://github.com/avivkeller)! - The doc-kit engine and CLI, previously published together as
22
+ `@node-core/doc-kit`, are now published as two packages: `@doc-kit/core`
23
+ (the engine) and `@doc-kit/cli` (the `doc-kit` command-line interface).
24
+ The `@node-core/doc-kit` name now contains only the Node.js-specific
25
+ generators (`api-links`, `addon-verify`, and `man-page`).
26
+
27
+ - [#960](https://github.com/nodejs/doc-kit/pull/960) [`c734403`](https://github.com/nodejs/doc-kit/commit/c7344034d83dd5858250a5cc386fbe729f07ede0) Thanks [@avivkeller](https://github.com/avivkeller)! - The legacy-format generators (`legacy-html`, `legacy-html-all`,
28
+ `legacy-json`, and `legacy-json-all`) now live in the new
29
+ `@node-core/doc-kit-legacy` package and are loaded via import specifiers such
30
+ as `@node-core/doc-kit-legacy/legacy-html`. The corresponding
31
+ `@doc-kit/core/*` package exports have been removed. The CLI shorthand
32
+ names are unchanged.
33
+
34
+ - [#961](https://github.com/nodejs/doc-kit/pull/961) [`c334823`](https://github.com/nodejs/doc-kit/commit/c334823a1ee7c1dc4642fa1b0dad90912de22f17) Thanks [@avivkeller](https://github.com/avivkeller)! - The Node.js-specific generators (`api-links`, `addon-verify`, and
35
+ `man-page`) now live in the `@node-core/doc-kit` package and are loaded
36
+ via import specifiers such as `@node-core/doc-kit/man-page`. The
37
+ corresponding package exports have been removed from the doc-kit engine.
38
+ The CLI shorthand names are unchanged.
39
+
40
+ - [#959](https://github.com/nodejs/doc-kit/pull/959) [`ca36039`](https://github.com/nodejs/doc-kit/commit/ca3603916bee58fb80c1ea3a2e0023c13903fc63) Thanks [@avivkeller](https://github.com/avivkeller)! - The React/JSX-based generators (`html` — previously `web` —, `jsx-ast`,
41
+ `llms-txt`, `sitemap`, and `orama-db`) now live in the new
42
+ `@doc-kit/generator-react` package and are loaded via import specifiers such as
43
+ `@doc-kit/generator-react/html`. The corresponding `@doc-kit/core/*`
44
+ package exports have been removed. The `web` generator is renamed to `html`:
45
+ the CLI shorthand `web` keeps working as a deprecated alias, but the
46
+ configuration key is now `html` instead of `web`.
47
+
48
+ ### Minor Changes
49
+
50
+ - [#939](https://github.com/nodejs/doc-kit/pull/939) [`7bd1b5b`](https://github.com/nodejs/doc-kit/commit/7bd1b5b15ba2a444bd9e746fb36236030919b273) Thanks [@avivkeller](https://github.com/avivkeller)! - Discover and load configuration files with `cosmiconfig`.
51
+
52
+ - [#911](https://github.com/nodejs/doc-kit/pull/911) [`ada6540`](https://github.com/nodejs/doc-kit/commit/ada6540fe6c2c32cfa254187c159941b245ebf80) Thanks [@avivkeller](https://github.com/avivkeller)! - Add banner opt-out
53
+
54
+ - [#958](https://github.com/nodejs/doc-kit/pull/958) [`0bd347d`](https://github.com/nodejs/doc-kit/commit/0bd347da847e21c2501732c0acbdee7db1b0f8f1) Thanks [@avivkeller](https://github.com/avivkeller)! - Generators are now loaded dynamically by import specifier instead of a static
55
+ registry. `--target` accepts either a built-in shorthand name (`web`,
56
+ `legacy-html`, …) or any import specifier resolving to a generator module
57
+ (e.g. `some-package/generator` or `./my-generator.mjs`), and a generator's
58
+ `dependsOn` is now a full import specifier. This lays the groundwork for
59
+ splitting the built-in generators into separate packages and enables
60
+ third-party generator packages.
61
+
62
+ - [#937](https://github.com/nodejs/doc-kit/pull/937) [`43a09f7`](https://github.com/nodejs/doc-kit/commit/43a09f7ae9cdd4a1863e98b067abcf104e8937f2) Thanks [@avivkeller](https://github.com/avivkeller)! - Make the `web` generator bundler-neutral through a custom adapter contract,
63
+ with Vite 8.1 provided as the default adapter.
64
+
65
+ ### Patch Changes
66
+
67
+ - [#964](https://github.com/nodejs/doc-kit/pull/964) [`96e1c26`](https://github.com/nodejs/doc-kit/commit/96e1c26482098aec1753d5fb1aeacb607f7e097f) Thanks [@avivkeller](https://github.com/avivkeller)! - Add `web.navigation`, which supplies the sidebar groups (`navigation.sidebar`)
68
+ and the navigation bar items (`navigation.navbar`) from configuration.
69
+
70
+ - [#955](https://github.com/nodejs/doc-kit/pull/955) [`b80958f`](https://github.com/nodejs/doc-kit/commit/b80958ff53dd2388d33ce8ed282b14a67d3374f0) Thanks [@avivkeller](https://github.com/avivkeller)! - Close Orama search when the target link is on the same page
71
+
72
+ - [#968](https://github.com/nodejs/doc-kit/pull/968) [`d3306a2`](https://github.com/nodejs/doc-kit/commit/d3306a20bf913d2c83739215bc5692434ceef166) Thanks [@pimterry](https://github.com/pimterry)! - Resolve unions and arrays of display-name types (`{HTTP/2 Headers Object | vm.Module}`, `{HTTP/2 Headers Object[]}`), and stop capturing prose such as `U+007B ({), and U+007D (}).` as a type annotation.
73
+
74
+ - [#889](https://github.com/nodejs/doc-kit/pull/889) [`68751af`](https://github.com/nodejs/doc-kit/commit/68751af17a45cc0c8e76d36308fb1be3f1dec4af) Thanks [@bmuenzenmeyer](https://github.com/bmuenzenmeyer)! - Fix `relative()` URL resolution when the target path is a prefix of the current
75
+ page's path (e.g. `/generators` from `/generators/web`): the target's final
76
+ segment was consumed as a common directory, producing `.` instead of
77
+ `../generators`. Unreachable in flat page layouts; surfaced by sites with
78
+ nested input directories.
79
+
80
+ - [#945](https://github.com/nodejs/doc-kit/pull/945) [`70b7526`](https://github.com/nodejs/doc-kit/commit/70b75269e9d0ed6b199c217bb268de96e65645c9) Thanks [@avivkeller](https://github.com/avivkeller)! - Moved the package into a `packages/core` workspace.
81
+
82
+ - [#1002](https://github.com/nodejs/doc-kit/pull/1002) [`740b613`](https://github.com/nodejs/doc-kit/commit/740b613ded7326eada843c34809ea128c6a9d7b5) Thanks [@avivkeller](https://github.com/avivkeller)! - Defaults are now project-neutral instead of Node.js-specific
83
+
84
+ - [#946](https://github.com/nodejs/doc-kit/pull/946) [`9ab2840`](https://github.com/nodejs/doc-kit/commit/9ab2840559d2f04a6db6b29bbf6c6d470a1dde0b) Thanks [@btea](https://github.com/btea)! - Fix missing spaces in the riscv64 multithreading warning message, which
85
+ previously concatenated as "failures whenallocating" and "spaceon riscv64".
86
+
87
+ - [#933](https://github.com/nodejs/doc-kit/pull/933) [`b73b704`](https://github.com/nodejs/doc-kit/commit/b73b70474a2c499c1be315ebf2595e6932124e19) Thanks [@vsolano9](https://github.com/vsolano9)! - Use short `DEP` codes for deprecation heading anchors.
88
+
89
+ - [#942](https://github.com/nodejs/doc-kit/pull/942) [`cef45ca`](https://github.com/nodejs/doc-kit/commit/cef45caf14cba83c77c373f59cee7f33f9f3df9b) Thanks [@btea](https://github.com/btea)! - Space union separators in type annotation values (`{string|URL}` is now rendered as `string | URL`).
90
+
91
+ - [#934](https://github.com/nodejs/doc-kit/pull/934) [`e6f1769`](https://github.com/nodejs/doc-kit/commit/e6f176958f6323d054dc86c4437accc9340e6914) Thanks [@avivkeller](https://github.com/avivkeller)! - Switches `oxc-parser` for `@swc/wasm`, since `oxc-parser` does not provide the needed bindings.
92
+
93
+ - [#919](https://github.com/nodejs/doc-kit/pull/919) [`d0f0de0`](https://github.com/nodejs/doc-kit/commit/d0f0de069e9061b6684269b412029bdd3dd288ba) Thanks [@MFA-G](https://github.com/MFA-G)! - Preserve deprecation codes in generated table-of-contents labels.
94
+
95
+ - [#963](https://github.com/nodejs/doc-kit/pull/963) [`2f9defe`](https://github.com/nodejs/doc-kit/commit/2f9defe49cac2d0e95c6fb213075291509a50a5f) Thanks [@btea](https://github.com/btea)! - Sync the URL hash when following same-page search hits
96
+
97
+ - [#955](https://github.com/nodejs/doc-kit/pull/955) [`b80958f`](https://github.com/nodejs/doc-kit/commit/b80958ff53dd2388d33ce8ed282b14a67d3374f0) Thanks [@avivkeller](https://github.com/avivkeller)! - Render markdown `code` snippets in the sidebar
98
+
99
+ - Updated dependencies [[`1da2390`](https://github.com/nodejs/doc-kit/commit/1da239076622e792145a38d2045dee404c3ad75f), [`c734403`](https://github.com/nodejs/doc-kit/commit/c7344034d83dd5858250a5cc386fbe729f07ede0), [`4bafb28`](https://github.com/nodejs/doc-kit/commit/4bafb287eda25dc07be9525e16aa6bfc63ebad1d), [`c334823`](https://github.com/nodejs/doc-kit/commit/c334823a1ee7c1dc4642fa1b0dad90912de22f17), [`740b613`](https://github.com/nodejs/doc-kit/commit/740b613ded7326eada843c34809ea128c6a9d7b5), [`740b613`](https://github.com/nodejs/doc-kit/commit/740b613ded7326eada843c34809ea128c6a9d7b5), [`43673d1`](https://github.com/nodejs/doc-kit/commit/43673d1785642cd26a3c6b5406a34d9eea42c68d), [`bfa8f0e`](https://github.com/nodejs/doc-kit/commit/bfa8f0e3bb49cba6bcbe780a61caf3e785bcb23b), [`ca36039`](https://github.com/nodejs/doc-kit/commit/ca3603916bee58fb80c1ea3a2e0023c13903fc63)]:
100
+ - @doc-kit/generator-react@0.1.0
101
+ - @node-core/doc-kit-legacy@1.0.0
102
+ - @node-core/doc-kit@2.0.0
103
+
3
104
  ## 1.4.3
4
105
 
5
106
  ### Patch Changes
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@doc-kit/core",
3
3
  "type": "module",
4
- "version": "0.0.0",
4
+ "version": "1.0.1",
5
5
  "description": "The doc-kit engine: the pipeline and shared APIs that power the doc-kit generators and CLI",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/nodejs/doc-kit.git",
9
9
  "directory": "packages/core"
10
10
  },
11
+ "license": "MIT",
11
12
  "main": "./src/generators.mjs",
12
13
  "exports": {
13
14
  ".": "./src/generators.mjs",
@@ -18,7 +19,19 @@
18
19
  "./package.json": "./package.json",
19
20
  "./shiki.config.mjs": "./shiki.config.mjs",
20
21
  "./src/*": "./src/*",
21
- "./*": "./src/*"
22
+ "./*": [
23
+ "./src/*",
24
+ "./src/*.d.ts"
25
+ ]
26
+ },
27
+ "imports": {
28
+ "#generators/*": "./src/generators/*",
29
+ "#logger/*": "./src/logger/*",
30
+ "#parsers/*": [
31
+ "./src/parsers/*",
32
+ "./src/parsers/*.d.ts"
33
+ ],
34
+ "#utils/*": "./src/utils/*"
22
35
  },
23
36
  "files": [
24
37
  "src",
@@ -64,9 +77,9 @@
64
77
  "hast-util-to-string": "^3.0.1"
65
78
  },
66
79
  "peerDependencies": {
67
- "@node-core/doc-kit": "1.4.3",
68
- "@node-core/doc-kit-legacy": "0.0.0",
69
- "@doc-kit/generator-react": "0.0.0"
80
+ "@node-core/doc-kit": ">=2.0.0",
81
+ "@node-core/doc-kit-legacy": ">=1.0.0",
82
+ "@doc-kit/generator-react": ">=0.1.0"
70
83
  },
71
84
  "peerDependenciesMeta": {
72
85
  "@node-core/doc-kit": {
@@ -7,11 +7,12 @@ import globParent from 'glob-parent';
7
7
  import { globSync } from 'tinyglobby';
8
8
  import { parse as parseYaml } from 'yaml';
9
9
 
10
+ import getConfig from '#utils/configuration/index.mjs';
11
+ import { withExt } from '#utils/file.mjs';
12
+ import { QUERIES } from '#utils/queries/index.mjs';
13
+ import { getRemark as remark, getRemarkMdx } from '#utils/remark.mjs';
14
+
10
15
  import { STABILITY_INDEX_URL } from './constants.mjs';
11
- import getConfig from '../../utils/configuration/index.mjs';
12
- import { withExt } from '../../utils/file.mjs';
13
- import { QUERIES } from '../../utils/queries/index.mjs';
14
- import { getRemark as remark, getRemarkMdx } from '../../utils/remark.mjs';
15
16
 
16
17
  /**
17
18
  * Determines whether a file should be parsed as MDX. A `.mdx` extension opts in
@@ -6,7 +6,7 @@ import { extname } from 'node:path';
6
6
  import { parse } from 'acorn';
7
7
  import { globSync } from 'tinyglobby';
8
8
 
9
- import getConfig from '../../utils/configuration/index.mjs';
9
+ import getConfig from '#utils/configuration/index.mjs';
10
10
 
11
11
  /**
12
12
  * Process a chunk of JavaScript files in a worker thread.
@@ -4,9 +4,9 @@ import { join } from 'node:path';
4
4
 
5
5
  import { remove } from 'unist-util-remove';
6
6
 
7
- import getConfig from '../../utils/configuration/index.mjs';
8
- import { writeFile } from '../../utils/file.mjs';
9
- import { UNIST } from '../../utils/queries/index.mjs';
7
+ import getConfig from '#utils/configuration/index.mjs';
8
+ import { writeFile } from '#utils/file.mjs';
9
+ import { UNIST } from '#utils/queries/index.mjs';
10
10
 
11
11
  /**
12
12
  * Generates the simplified JSON version of the API docs
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ import getConfig from '#utils/configuration/index.mjs';
4
+ import { loadFromURL } from '#utils/loaders.mjs';
5
+
3
6
  import { parseApiDoc } from './utils/parse.mjs';
4
- import getConfig from '../../utils/configuration/index.mjs';
5
- import { loadFromURL } from '../../utils/loaders.mjs';
6
7
 
7
8
  /**
8
9
  * Process a chunk of API doc files in a worker thread.
@@ -9,6 +9,15 @@ import { remove } from 'unist-util-remove';
9
9
  import { selectAll } from 'unist-util-select';
10
10
  import { SKIP, visit } from 'unist-util-visit';
11
11
 
12
+ import {
13
+ DEPRECATION_HEADING_REGEX,
14
+ IGNORE_STABILITY_STEMS,
15
+ } from '#generators/metadata/constants.mjs';
16
+ import { UNIST } from '#utils/queries/index.mjs';
17
+ import { getRemark as remark } from '#utils/remark.mjs';
18
+ import { relative } from '#utils/url.mjs';
19
+
20
+ import { resolveTypeAnnotations } from './resolveTypes.mjs';
12
21
  import createNodeSlugger from './slugger.mjs';
13
22
  import { transformNodeToHeading } from './transformers.mjs';
14
23
  import {
@@ -18,14 +27,6 @@ import {
18
27
  visitTextWithUnixManualNode,
19
28
  visitYAML,
20
29
  } from './visitors.mjs';
21
- import { UNIST } from '../../../utils/queries/index.mjs';
22
- import { getRemark as remark } from '../../../utils/remark.mjs';
23
- import { relative } from '../../../utils/url.mjs';
24
- import {
25
- DEPRECATION_HEADING_REGEX,
26
- IGNORE_STABILITY_STEMS,
27
- } from '../constants.mjs';
28
- import { resolveTypeAnnotations } from './resolveTypes.mjs';
29
30
 
30
31
  /**
31
32
  * This generator generates a flattened list of metadata entries from a API doc
@@ -87,7 +88,7 @@ export const parseApiDoc = ({ path, tree, mdx = false }, typeMap) => {
87
88
  // Handles the normalisation URLs that reference to API doc files with .md extension
88
89
  visit(tree, UNIST.isMarkdownUrl, node => visitMarkdownLink(node));
89
90
 
90
- // If the document has no headings but it has content, we add a fake heading to the top
91
+ // If the document has no headings but it has content, we add a fake heading to the top, it will not be rendered
91
92
  if (headingNodes.length === 0 && tree.children.length > 0) {
92
93
  tree.children.unshift(createTree('heading', { depth: 1 }, []));
93
94
  }
@@ -1,9 +1,10 @@
1
1
  import { parseSync } from '@swc/wasm';
2
2
  import { visit } from 'unist-util-visit';
3
3
 
4
+ import logger from '#logger/index.mjs';
5
+ import { walk } from '#utils/swc.mjs';
6
+
4
7
  import { lookupTypeName, resolveTypeReference } from './transformers.mjs';
5
- import logger from '../../../logger/index.mjs';
6
- import { walk } from '../../../utils/swc.mjs';
7
8
 
8
9
  // `null` is a keyword kind in SWC, unlike most parsers which treat it as a literal type
9
10
  const KEYWORDS = new Set([
@@ -2,7 +2,7 @@
2
2
 
3
3
  import GitHubSlugger, { slug as defaultSlugFn } from 'github-slugger';
4
4
 
5
- import { DOC_API_SLUGS_REPLACEMENTS } from '../constants.mjs';
5
+ import { DOC_API_SLUGS_REPLACEMENTS } from '#generators/metadata/constants.mjs';
6
6
 
7
7
  /**
8
8
  * Creates a modified version of the GitHub Slugger
@@ -2,11 +2,12 @@ import {
2
2
  DOC_MAN_BASE_URL,
3
3
  DOC_API_HEADING_TYPES,
4
4
  MODULE_QUALIFIED_NAME,
5
- } from '../constants.mjs';
5
+ } from '#generators/metadata/constants.mjs';
6
+ import BUILTIN_TYPE_MAP from '#generators/metadata/maps/builtin.json' with { type: 'json' };
7
+ import MDN_TYPE_MAP from '#generators/metadata/maps/mdn.json' with { type: 'json' };
8
+ import { transformNodesToString } from '#utils/unist.mjs';
9
+
6
10
  import { slug } from './slugger.mjs';
7
- import { transformNodesToString } from '../../../utils/unist.mjs';
8
- import BUILTIN_TYPE_MAP from '../maps/builtin.json' with { type: 'json' };
9
- import MDN_TYPE_MAP from '../maps/mdn.json' with { type: 'json' };
10
11
 
11
12
  /**
12
13
  * @param {string} text The inner text
@@ -2,11 +2,12 @@
2
2
 
3
3
  import { SKIP } from 'unist-util-visit';
4
4
 
5
+ import { QUERIES } from '#utils/queries/index.mjs';
6
+ import { getRemark as remark } from '#utils/remark.mjs';
7
+ import { transformNodesToString } from '#utils/unist.mjs';
8
+
5
9
  import { transformUnixManualToLink } from './transformers.mjs';
6
10
  import { extractYamlContent, parseYAMLIntoMetadata } from './yaml.mjs';
7
- import { QUERIES } from '../../../utils/queries/index.mjs';
8
- import { getRemark as remark } from '../../../utils/remark.mjs';
9
- import { transformNodesToString } from '../../../utils/unist.mjs';
10
11
 
11
12
  /**
12
13
  * Updates a Markdown link into a HTML link for API docs
@@ -2,7 +2,7 @@
2
2
 
3
3
  import yaml from 'yaml';
4
4
 
5
- import { QUERIES } from '../../../utils/queries/index.mjs';
5
+ import { QUERIES } from '#utils/queries/index.mjs';
6
6
 
7
7
  /**
8
8
  * Extracts raw YAML content from a node
@@ -2,8 +2,8 @@
2
2
 
3
3
  import { styleText } from 'node:util';
4
4
 
5
- import { prettifyLevel } from '../utils/colors.mjs';
6
- import { prettifyTimestamp } from '../utils/time.mjs';
5
+ import { prettifyLevel } from '#logger/utils/colors.mjs';
6
+ import { prettifyTimestamp } from '#logger/utils/time.mjs';
7
7
 
8
8
  /**
9
9
  * Logs a formatted message to stdout for human-friendly CLI output.
@@ -2,9 +2,9 @@
2
2
 
3
3
  import { debug, notice, warning, error } from '@actions/core';
4
4
 
5
- import { LogLevel } from '../constants.mjs';
6
- import { prettifyLevel } from '../utils/colors.mjs';
7
- import { prettifyTimestamp } from '../utils/time.mjs';
5
+ import { LogLevel } from '#logger/constants.mjs';
6
+ import { prettifyLevel } from '#logger/utils/colors.mjs';
7
+ import { prettifyTimestamp } from '#logger/utils/time.mjs';
8
8
 
9
9
  const actions = {
10
10
  [LogLevel.debug]: debug,
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { styleText } from 'node:util';
4
4
 
5
- import { levelTags, levelToColorMap } from '../constants.mjs';
5
+ import { levelTags, levelToColorMap } from '#logger/constants.mjs';
6
6
 
7
7
  /**
8
8
  * Returns a styled, uppercase log level tag for CLI output with color mapping
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { coerce } from 'semver';
4
4
 
5
- import { loadFromURL } from '../utils/loaders.mjs';
5
+ import { loadFromURL } from '#utils/loaders.mjs';
6
6
 
7
7
  // A ReGeX for retrieving Node.js version headers from the CHANGELOG.md
8
8
  const NODE_VERSIONS_REGEX = /\* \[Node\.js ([0-9.]+)\]\S+ (.*)\r?\n/g;
@@ -1,5 +1,5 @@
1
- import { loadGenerator } from '../generators/loader.mjs';
2
- import { setConfig } from '../utils/configuration/index.mjs';
1
+ import { loadGenerator } from '#generators/loader.mjs';
2
+ import { setConfig } from '#utils/configuration/index.mjs';
3
3
 
4
4
  /**
5
5
  * Processes a chunk of items using the specified generator's processChunk method.
@@ -1,6 +1,6 @@
1
1
  import Piscina from 'piscina';
2
2
 
3
- import logger from '../logger/index.mjs';
3
+ import logger from '#logger/index.mjs';
4
4
 
5
5
  const poolLogger = logger.child('WorkerPool');
6
6
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import logger from '../logger/index.mjs';
3
+ import logger from '#logger/index.mjs';
4
4
 
5
5
  const parallelLogger = logger.child('parallel');
6
6
 
@@ -11,12 +11,12 @@ import { coerce } from 'semver';
11
11
  import {
12
12
  loadGenerators,
13
13
  resolveGeneratorSpecifier,
14
- } from '../../generators/loader.mjs';
15
- import logger from '../../logger/index.mjs';
16
- import { parseChangelog, parseIndex } from '../../parsers/markdown.mjs';
17
- import { enforceArray } from '../array.mjs';
18
- import { leftHandAssign } from '../generators.mjs';
19
- import { deepMerge } from '../misc.mjs';
14
+ } from '#generators/loader.mjs';
15
+ import logger from '#logger/index.mjs';
16
+ import { parseChangelog, parseIndex } from '#parsers/markdown.mjs';
17
+ import { enforceArray } from '#utils/array.mjs';
18
+ import { leftHandAssign } from '#utils/generators.mjs';
19
+ import { deepMerge } from '#utils/misc.mjs';
20
20
 
21
21
  const configExplorer = cosmiconfig('doc-kit');
22
22
 
@@ -1,5 +1,5 @@
1
1
  import type { SemVer } from 'semver';
2
- import type { ReleaseEntry } from '../../parsers/types';
2
+ import type { ReleaseEntry } from '#parsers/types';
3
3
 
4
4
  export type Configuration = {
5
5
  global: GlobalConfiguration;
@@ -2,6 +2,36 @@
2
2
 
3
3
  import { coerce, major } from 'semver';
4
4
 
5
+ import { transformNodeToString } from './unist.mjs';
6
+
7
+ /**
8
+ * Retrieves the description of a given API doc entry. It first checks whether
9
+ * the entry has a llm_description property. If not, it extracts the first
10
+ * paragraph from the entry's content.
11
+ *
12
+ * @param {import('../generators/metadata/types').MetadataEntry} entry
13
+ * @returns {string}
14
+ */
15
+ export const getEntryDescription = entry => {
16
+ if (entry.llm_description) {
17
+ return entry.llm_description.trim();
18
+ }
19
+
20
+ const descriptionNode = entry.content.children.find(
21
+ child => child.type === 'paragraph'
22
+ );
23
+
24
+ if (!descriptionNode) {
25
+ return '';
26
+ }
27
+
28
+ return (
29
+ transformNodeToString(descriptionNode)
30
+ // Remove newlines and extra spaces
31
+ .replace(/[\r\n]+/g, '')
32
+ );
33
+ };
34
+
5
35
  /**
6
36
  * Groups all the API metadata nodes by module (`api` property) so that we can process each different file
7
37
  * based on the module it belongs to.
@@ -0,0 +1,82 @@
1
+ 'use strict';
2
+
3
+ import rehypeStringify from 'rehype-stringify';
4
+ import remarkParse from 'remark-parse';
5
+ import remarkRehype from 'remark-rehype';
6
+ import { unified } from 'unified';
7
+ import { u as createTree } from 'unist-builder';
8
+ import { SKIP, visit } from 'unist-util-visit';
9
+
10
+ import { lazy } from './misc.mjs';
11
+
12
+ /**
13
+ * Renders a `root` as just its children, since content placed directly on one
14
+ * is otherwise rendered with a line break between each node, which surfaces as
15
+ * stray whitespace.
16
+ *
17
+ * @param {import('mdast-util-to-hast').State} state
18
+ * @param {import('unist').Parent} node
19
+ */
20
+ const inlineRoot = (state, node) => ({
21
+ type: 'root',
22
+ children: state.all(node),
23
+ });
24
+
25
+ /**
26
+ * Retrieves an instance of Remark configured to parse plain markdown, without
27
+ * the extensions that only apply to whole documents.
28
+ */
29
+ const getInlineParser = lazy(() => unified().use(remarkParse));
30
+
31
+ /**
32
+ * Retrieves an instance of Remark configured to render inline nodes as an HTML
33
+ * string. Raw HTML is dropped rather than passed through, since the result is
34
+ * inserted into the page as-is.
35
+ */
36
+ const getInlineRenderer = lazy(() =>
37
+ unified()
38
+ .use(remarkRehype, { handlers: { root: inlineRoot } })
39
+ .use(rehypeStringify)
40
+ );
41
+
42
+ /**
43
+ * Parses a single line of markdown (a change description, a summary, ...) into
44
+ * the inline nodes it is made of.
45
+ *
46
+ * @param {string} markdown - The markdown to parse.
47
+ * @param {boolean} [dropLinks] - Replace links with their text? Anchors cannot
48
+ * nest, so content rendered inside a link must not contain one.
49
+ * @returns {Array<import('mdast').PhrasingContent>} The parsed nodes.
50
+ */
51
+ export const parseInline = (markdown, dropLinks = false) => {
52
+ const tree = getInlineParser().parse(markdown);
53
+
54
+ if (dropLinks) {
55
+ visit(tree, 'link', (node, index, parent) => {
56
+ parent.children.splice(index, 1, ...node.children);
57
+
58
+ return [SKIP, index];
59
+ });
60
+ }
61
+
62
+ const [first] = tree.children;
63
+
64
+ // A single line of prose parses into one paragraph, which is dropped so the
65
+ // nodes can be rendered inline
66
+ return tree.children.length === 1 && first.type === 'paragraph'
67
+ ? first.children
68
+ : tree.children;
69
+ };
70
+
71
+ /**
72
+ * Renders inline nodes as an HTML string, for the places that hand rendered
73
+ * markup to a component through a data channel rather than as an AST.
74
+ *
75
+ * @param {Array<import('mdast').PhrasingContent>} nodes - The nodes to render.
76
+ * @returns {string} The rendered HTML.
77
+ */
78
+ export const renderAsHTML = nodes => {
79
+ const renderer = getInlineRenderer();
80
+
81
+ return renderer.stringify(renderer.runSync(createTree('root', nodes)));
82
+ };
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- import { transformNodesToString } from '../unist.mjs';
4
- import { isTypedList } from './utils.mjs';
3
+ import { transformNodesToString } from '#utils/unist.mjs';
4
+
5
+ import { isTypedListItem, isTypedList } from './utils.mjs';
5
6
 
6
7
  // This defines the actual REGEX Queries
7
8
  export const QUERIES = {
@@ -71,6 +72,12 @@ export const UNIST = {
71
72
  */
72
73
  isLooselyTypedList: list => Boolean(isTypedList(list)),
73
74
 
75
+ /**
76
+ * @param {import('@types/mdast').ListItem} item
77
+ * @returns {boolean}
78
+ */
79
+ isTypedListItem,
80
+
74
81
  /**
75
82
  * @param {import('@types/mdast').List} list
76
83
  * @returns {boolean}
@@ -2,20 +2,17 @@ import { VALID_JAVASCRIPT_PROPERTY } from './constants.mjs';
2
2
  import { QUERIES } from './index.mjs';
3
3
 
4
4
  /**
5
- * @param {import('@types/mdast').List} list
5
+ * Inspects the first phrasing node of a paragraph and returns how confidently
6
+ * it looks like the start of a typed parameter.
7
+ *
8
+ * @param {import('@types/mdast').PhrasingContent | undefined} firstNode
6
9
  * @returns {0 | 1 | 2} confidence
7
10
  *
8
- * 0: This is not a typed list
9
- * 1: This is a loosely typed list
10
- * 2: This is a strongly typed list
11
+ * 0: Not a typed parameter
12
+ * 1: Loosely typed (inlineCode + valid property name)
13
+ * 2: Strongly typed (typed list starter or direct type annotation)
11
14
  */
12
- export const isTypedList = list => {
13
- if (!list || list.type !== 'list') {
14
- return 0;
15
- }
16
-
17
- const firstNode = list.children?.[0]?.children?.[0]?.children[0];
18
-
15
+ const getTypedConfidence = firstNode => {
19
16
  if (!firstNode) {
20
17
  return 0;
21
18
  }
@@ -43,3 +40,30 @@ export const isTypedList = list => {
43
40
 
44
41
  return 0;
45
42
  };
43
+
44
+ /**
45
+ * Checks whether a single list item looks like a typed parameter — i.e. it
46
+ * starts with a property name (`inlineCode`), a Returns/Extends/Type prefix,
47
+ * or a direct type annotation.
48
+ *
49
+ * @param {import('@types/mdast').ListItem} item
50
+ * @returns {boolean}
51
+ */
52
+ export const isTypedListItem = item =>
53
+ Boolean(getTypedConfidence(item?.children?.[0]?.children?.[0]));
54
+
55
+ /**
56
+ * @param {import('@types/mdast').List} list
57
+ * @returns {0 | 1 | 2} confidence
58
+ *
59
+ * 0: This is not a typed list
60
+ * 1: This is a loosely typed list
61
+ * 2: This is a strongly typed list
62
+ */
63
+ export const isTypedList = list => {
64
+ if (!list || list.type !== 'list') {
65
+ return 0;
66
+ }
67
+
68
+ return getTypedConfidence(list.children?.[0]?.children?.[0]?.children?.[0]);
69
+ };
@@ -13,18 +13,33 @@ import { lazy } from './misc.mjs';
13
13
  import { typeAnnotationToHast } from './type-annotations/hast.mjs';
14
14
  import remarkTypeAnnotations from './type-annotations/remark.mjs';
15
15
 
16
- // MDX node types that may appear in trees parsed by `getRemarkMdx`; the
17
- // rehype pipelines pass them through untouched.
18
- const passThrough = [
19
- 'element',
20
- 'mdxJsxTextElement',
21
- 'mdxJsxFlowElement',
22
- 'mdxJsxAttribute',
23
- 'mdxJsxAttributeValueExpression',
24
- 'mdxFlowExpression',
25
- 'mdxTextExpression',
26
- 'mdxjsEsm',
27
- ];
16
+ // Nodes the rehype pipelines pass through untouched.
17
+ const passThrough = ['element'];
18
+
19
+ /**
20
+ * Renders an MDX JSX element as just its children, so the surrounding prose
21
+ * still renders in HTML-string output.
22
+ *
23
+ * @param {import('mdast-util-to-hast').State} state
24
+ * @param {import('unist').Parent} node
25
+ */
26
+ const mdxElementToChildren = (state, node) => state.all(node);
27
+
28
+ /**
29
+ * Drops a node from HTML-string output.
30
+ */
31
+ const dropNode = () => undefined;
32
+
33
+ // The HTML-string pipelines cannot render MDX nodes (rendering those is the
34
+ // React generators' job): JSX elements degrade to their children so the
35
+ // surrounding prose still renders, and expressions/ESM are dropped.
36
+ const mdxToHastHandlers = {
37
+ mdxJsxTextElement: mdxElementToChildren,
38
+ mdxJsxFlowElement: mdxElementToChildren,
39
+ mdxFlowExpression: dropNode,
40
+ mdxTextExpression: dropNode,
41
+ mdxjsEsm: dropNode,
42
+ };
28
43
 
29
44
  /**
30
45
  * Retrieves an instance of Remark configured to parse GFM (GitHub Flavored Markdown)
@@ -64,7 +79,7 @@ export const getRemarkRehype = lazy(() =>
64
79
  .use(remarkRehype, {
65
80
  allowDangerousHtml: true,
66
81
  passThrough,
67
- handlers: { typeAnnotation: typeAnnotationToHast },
82
+ handlers: { typeAnnotation: typeAnnotationToHast, ...mdxToHastHandlers },
68
83
  })
69
84
  // We allow dangerous HTML to be passed through, since we have HTML within our Markdown
70
85
  // and we trust the sources of the Markdown files
@@ -86,7 +101,7 @@ export const getRemarkRehypeWithShiki = lazy(() =>
86
101
  allowDangerousHtml: true,
87
102
  passThrough,
88
103
  // legacy-html gets the minimal (unhighlighted) type rendering
89
- handlers: { typeAnnotation: typeAnnotationToHast },
104
+ handlers: { typeAnnotation: typeAnnotationToHast, ...mdxToHastHandlers },
90
105
  })
91
106
  // This is a custom ad-hoc within the Shiki Rehype plugin, used to highlight code
92
107
  // and transform them into HAST nodes
@@ -1,12 +1,13 @@
1
+ import { leftHandAssign } from '#utils/generators.mjs';
2
+ import { QUERIES, UNIST } from '#utils/queries/index.mjs';
3
+ import { transformNodesToString } from '#utils/unist.mjs';
4
+
1
5
  import {
2
6
  DEFAULT_EXPRESSION,
3
7
  LEADING_HYPHEN,
4
8
  NAME_EXPRESSION,
5
9
  } from './constants.mjs';
6
10
  import parseSignature from './parseSignature.mjs';
7
- import { leftHandAssign } from '../generators.mjs';
8
- import { QUERIES, UNIST } from '../queries/index.mjs';
9
- import { transformNodesToString } from '../unist.mjs';
10
11
 
11
12
  /**
12
13
  * Extracts and removes a specific pattern from a text string while storing the result in a key of the `current` object.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import { highlighter } from '../highlighter.mjs';
3
+ import { highlighter } from '#utils/highlighter.mjs';
4
4
 
5
5
  const [lightTheme, darkTheme] = highlighter.shiki.getLoadedThemes();
6
6