From 60d451878878a9abb7ffff55ed2e98cec33d1cfb Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Thu, 30 Jul 2026 14:17:35 -0700 Subject: [PATCH 1/7] refactor(react): extract @nodejs/doc-kit-generator-react package --- .c8rc.json | 2 +- .changeset/react-kitten-package.md | 12 +++ .prettierignore | 2 +- README.md | 4 +- beta/doc-kit.config.mjs | 2 +- docs/comparators.md | 2 +- docs/generators.md | 4 +- eslint.config.mjs | 2 +- package-lock.json | 62 +++++++++---- packages/core/package.json | 30 ++----- .../src/generators/__tests__/index.test.mjs | 25 +++++- packages/core/src/generators/index.mjs | 20 +++-- .../sitemap/utils/createPageSitemapEntry.mjs | 18 ---- .../core/src/generators/web/template.html | 22 ----- packages/core/src/utils/remark.mjs | 89 +++---------------- packages/react/package.json | 57 ++++++++++++ .../web => react/src/html}/README.md | 28 +++--- .../src/html}/__tests__/generate.test.mjs | 20 ++--- .../html}/bundlers/__tests__/vite.test.mjs | 13 +-- .../web => react/src/html}/bundlers/index.mjs | 0 .../web => react/src/html}/bundlers/vite.mjs | 3 +- .../web => react/src/html}/constants.mjs | 0 .../web => react/src/html}/generate.mjs | 5 +- .../web => react/src/html}/index.mjs | 9 +- packages/react/src/html/template.html | 25 ++++++ .../web => react/src/html}/types.d.ts | 2 +- .../src/html}/ui/components/Banner.jsx | 0 .../src/html}/ui/components/CodeBox.jsx | 0 .../src/html}/ui/components/CodeTabs.jsx | 0 .../src/html}/ui/components/Layout/index.jsx | 0 .../src/html}/ui/components/MetaBar/index.jsx | 0 .../ui/components/MetaBar/index.module.css | 0 .../src/html}/ui/components/NavBar.jsx | 0 .../src/html}/ui/components/NoOp.jsx | 0 .../html}/ui/components/SearchBox/index.jsx | 0 .../ui/components/SearchBox/index.module.css | 0 .../src/html}/ui/components/SideBar/index.jsx | 0 .../ui/components/SideBar/index.module.css | 0 .../src/html}/ui/components/ThemeToggle.jsx | 0 .../src/html}/ui/hooks/useBanners.mjs | 0 .../src/html}/ui/hooks/useOrama.mjs | 0 .../src/html}/ui/hooks/useTheme.mjs | 0 .../web => react/src/html}/ui/index.css | 0 .../src/html}/ui/islands/loaders.mjs | 0 .../src/html}/ui/islands/runtime.mjs | 0 .../src/html}/ui/islands/withIsland.jsx | 0 .../web => react/src/html}/ui/package.json | 0 .../src/html}/ui/theme-script.mjs | 0 .../web => react/src/html}/ui/types.d.ts | 4 +- .../src/html}/ui/utils/relativeOrAbsolute.mjs | 2 +- .../src/html}/ui/utils/renderLabel.jsx | 0 .../src/html}/utils/__tests__/config.test.mjs | 5 +- .../html}/utils/__tests__/copying.test.mjs | 4 +- .../html}/utils/__tests__/processing.test.mjs | 11 +-- .../__tests__/relativeOrAbsolute.test.mjs | 11 +-- .../web => react/src/html}/utils/config.mjs | 10 +-- .../web => react/src/html}/utils/copying.mjs | 4 +- .../web => react/src/html}/utils/generate.mjs | 5 +- .../src/html}/utils/processing.mjs | 21 ++--- .../src/html}/utils/relativeOrAbsolute.mjs | 6 +- .../src}/jsx-ast/README.md | 0 .../src}/jsx-ast/__tests__/generate.test.mjs | 5 +- .../src}/jsx-ast/constants.mjs | 2 +- .../src}/jsx-ast/generate.mjs | 6 +- .../src}/jsx-ast/index.mjs | 0 .../src}/jsx-ast/types.d.ts | 2 +- .../src}/jsx-ast/utils/__tests__/ast.test.mjs | 0 .../utils/__tests__/buildBarProps.test.mjs | 0 .../utils/__tests__/buildContent.test.mjs | 3 +- .../utils/__tests__/overloads.test.mjs | 0 .../jsx-ast}/utils/__tests__/remark.test.mjs | 0 .../utils/__tests__/signature.test.mjs | 0 .../jsx-ast/utils/__tests__/types.test.mjs | 2 +- .../src}/jsx-ast/utils/ast.mjs | 0 .../src}/jsx-ast/utils/buildBarProps.mjs | 10 +-- .../src}/jsx-ast/utils/buildContent.mjs | 42 ++++----- .../src}/jsx-ast/utils/getSortedHeadNodes.mjs | 8 +- .../src}/jsx-ast/utils/overloads.mjs | 8 +- .../utils/plugins/__tests__/alerts.test.mjs | 0 .../plugins/__tests__/transformer.test.mjs | 0 .../src}/jsx-ast/utils/plugins/alerts.mjs | 2 +- .../jsx-ast/utils/plugins/transformer.mjs | 0 packages/react/src/jsx-ast/utils/remark.mjs | 80 +++++++++++++++++ .../src}/jsx-ast/utils/signature.mjs | 18 ++-- .../src}/jsx-ast/utils/synthetic/404.mjs | 0 .../utils/synthetic/__tests__/404.test.mjs | 0 .../utils/synthetic/__tests__/all.test.mjs | 0 .../utils/synthetic/__tests__/index.test.mjs | 0 .../synthetic/__tests__/synthetic.test.mjs | 0 .../src}/jsx-ast/utils/synthetic/all.mjs | 2 +- .../src}/jsx-ast/utils/synthetic/index.mjs | 6 +- .../jsx-ast/utils/synthetic/synthetic.mjs | 0 .../src}/jsx-ast/utils/types.mjs | 8 +- .../src}/llms-txt/README.md | 0 .../src}/llms-txt/generate.mjs | 5 +- .../src}/llms-txt/index.mjs | 0 .../src}/llms-txt/template.txt | 0 .../src}/llms-txt/types.d.ts | 2 +- .../utils/__tests__/buildApiDocLink.test.mjs | 0 .../src}/llms-txt/utils/buildApiDocLink.mjs | 10 +-- .../src}/orama-db/README.md | 0 .../src}/orama-db/constants.mjs | 0 .../src}/orama-db/generate.mjs | 8 +- .../src}/orama-db/index.mjs | 0 .../src}/orama-db/types.d.ts | 2 +- .../orama-db/utils/__tests__/title.test.mjs | 0 .../src}/orama-db/utils/title.mjs | 0 .../src}/sitemap/README.md | 0 .../src}/sitemap/entry-template.xml | 0 .../src}/sitemap/generate.mjs | 7 +- .../src}/sitemap/index.mjs | 0 .../src}/sitemap/template.xml | 0 .../src}/sitemap/types.d.ts | 2 +- .../sitemap/utils/createPageSitemapEntry.mjs | 19 ++++ scripts/build-docs-content.mjs | 8 +- scripts/vercel-build.sh | 2 +- www/doc-kit.config.mjs | 4 +- www/pages/getting-started.md | 16 ++-- www/pages/index.md | 14 +-- 119 files changed, 497 insertions(+), 347 deletions(-) create mode 100644 .changeset/react-kitten-package.md delete mode 100644 packages/core/src/generators/sitemap/utils/createPageSitemapEntry.mjs delete mode 100644 packages/core/src/generators/web/template.html create mode 100644 packages/react/package.json rename packages/{core/src/generators/web => react/src/html}/README.md (95%) rename packages/{core/src/generators/web => react/src/html}/__tests__/generate.test.mjs (93%) rename packages/{core/src/generators/web => react/src/html}/bundlers/__tests__/vite.test.mjs (94%) rename packages/{core/src/generators/web => react/src/html}/bundlers/index.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/bundlers/vite.mjs (99%) rename packages/{core/src/generators/web => react/src/html}/constants.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/generate.mjs (92%) rename packages/{core/src/generators/web => react/src/html}/index.mjs (93%) create mode 100644 packages/react/src/html/template.html rename packages/{core/src/generators/web => react/src/html}/types.d.ts (97%) rename packages/{core/src/generators/web => react/src/html}/ui/components/Banner.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/CodeBox.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/CodeTabs.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/Layout/index.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/MetaBar/index.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/MetaBar/index.module.css (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/NavBar.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/NoOp.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/SearchBox/index.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/SearchBox/index.module.css (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/SideBar/index.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/SideBar/index.module.css (100%) rename packages/{core/src/generators/web => react/src/html}/ui/components/ThemeToggle.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/hooks/useBanners.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/hooks/useOrama.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/hooks/useTheme.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/index.css (100%) rename packages/{core/src/generators/web => react/src/html}/ui/islands/loaders.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/islands/runtime.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/islands/withIsland.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/ui/package.json (100%) rename packages/{core/src/generators/web => react/src/html}/ui/theme-script.mjs (100%) rename packages/{core/src/generators/web => react/src/html}/ui/types.d.ts (89%) rename packages/{core/src/generators/web => react/src/html}/ui/utils/relativeOrAbsolute.mjs (89%) rename packages/{core/src/generators/web => react/src/html}/ui/utils/renderLabel.jsx (100%) rename packages/{core/src/generators/web => react/src/html}/utils/__tests__/config.test.mjs (97%) rename packages/{core/src/generators/web => react/src/html}/utils/__tests__/copying.test.mjs (95%) rename packages/{core/src/generators/web => react/src/html}/utils/__tests__/processing.test.mjs (96%) rename packages/{core/src/generators/web => react/src/html}/utils/__tests__/relativeOrAbsolute.test.mjs (90%) rename packages/{core/src/generators/web => react/src/html}/utils/config.mjs (90%) rename packages/{core/src/generators/web => react/src/html}/utils/copying.mjs (86%) rename packages/{core/src/generators/web => react/src/html}/utils/generate.mjs (96%) rename packages/{core/src/generators/web => react/src/html}/utils/processing.mjs (85%) rename packages/{core/src/generators/web => react/src/html}/utils/relativeOrAbsolute.mjs (69%) rename packages/{core/src/generators => react/src}/jsx-ast/README.md (100%) rename packages/{core/src/generators => react/src}/jsx-ast/__tests__/generate.test.mjs (96%) rename packages/{core/src/generators => react/src}/jsx-ast/constants.mjs (99%) rename packages/{core/src/generators => react/src}/jsx-ast/generate.mjs (91%) rename packages/{core/src/generators => react/src}/jsx-ast/index.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/types.d.ts (82%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/ast.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/buildBarProps.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/buildContent.test.mjs (95%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/overloads.test.mjs (100%) rename packages/{core/src => react/src/jsx-ast}/utils/__tests__/remark.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/signature.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/__tests__/types.test.mjs (99%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/ast.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/buildBarProps.mjs (83%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/buildContent.mjs (83%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/getSortedHeadNodes.mjs (66%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/overloads.mjs (78%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/plugins/__tests__/alerts.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/plugins/__tests__/transformer.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/plugins/alerts.mjs (97%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/plugins/transformer.mjs (100%) create mode 100644 packages/react/src/jsx-ast/utils/remark.mjs rename packages/{core/src/generators => react/src}/jsx-ast/utils/signature.mjs (83%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/404.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/__tests__/404.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/__tests__/all.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/__tests__/index.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/__tests__/synthetic.test.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/all.mjs (70%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/index.mjs (88%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/synthetic/synthetic.mjs (100%) rename packages/{core/src/generators => react/src}/jsx-ast/utils/types.mjs (90%) rename packages/{core/src/generators => react/src}/llms-txt/README.md (100%) rename packages/{core/src/generators => react/src}/llms-txt/generate.mjs (84%) rename packages/{core/src/generators => react/src}/llms-txt/index.mjs (100%) rename packages/{core/src/generators => react/src}/llms-txt/template.txt (100%) rename packages/{core/src/generators => react/src}/llms-txt/types.d.ts (66%) rename packages/{core/src/generators => react/src}/llms-txt/utils/__tests__/buildApiDocLink.test.mjs (100%) rename packages/{core/src/generators => react/src}/llms-txt/utils/buildApiDocLink.mjs (70%) rename packages/{core/src/generators => react/src}/orama-db/README.md (100%) rename packages/{core/src/generators => react/src}/orama-db/constants.mjs (100%) rename packages/{core/src/generators => react/src}/orama-db/generate.mjs (83%) rename packages/{core/src/generators => react/src}/orama-db/index.mjs (100%) rename packages/{core/src/generators => react/src}/orama-db/types.d.ts (87%) rename packages/{core/src/generators => react/src}/orama-db/utils/__tests__/title.test.mjs (100%) rename packages/{core/src/generators => react/src}/orama-db/utils/title.mjs (100%) rename packages/{core/src/generators => react/src}/sitemap/README.md (100%) rename packages/{core/src/generators => react/src}/sitemap/entry-template.xml (100%) rename packages/{core/src/generators => react/src}/sitemap/generate.mjs (86%) rename packages/{core/src/generators => react/src}/sitemap/index.mjs (100%) rename packages/{core/src/generators => react/src}/sitemap/template.xml (100%) rename packages/{core/src/generators => react/src}/sitemap/types.d.ts (81%) create mode 100644 packages/react/src/sitemap/utils/createPageSitemapEntry.mjs diff --git a/.c8rc.json b/.c8rc.json index 4ce81ec8..fbc2a9e6 100644 --- a/.c8rc.json +++ b/.c8rc.json @@ -4,7 +4,7 @@ "eslint.config.mjs", "**/fixtures", "packages/core/src/generators/legacy-html/assets", - "packages/core/src/generators/web/ui", + "packages/react/src/html/ui", "**/*.d.ts" ] } diff --git a/.changeset/react-kitten-package.md b/.changeset/react-kitten-package.md new file mode 100644 index 00000000..cf250c1c --- /dev/null +++ b/.changeset/react-kitten-package.md @@ -0,0 +1,12 @@ +--- +'@nodejs/doc-kit-generator-react': minor +'@node-core/doc-kit': major +--- + +The React/JSX-based generators (`html` — previously `web` —, `jsx-ast`, +`llms-txt`, `sitemap`, and `orama-db`) now live in the new +`@nodejs/doc-kit-generator-react` package and are loaded via import specifiers such as +`@nodejs/doc-kit-generator-react/html`. The corresponding `@node-core/doc-kit/*` +package exports have been removed. The `web` generator is renamed to `html`: +the CLI shorthand `web` keeps working as a deprecated alias, but the +configuration key is now `html` instead of `web`. diff --git a/.prettierignore b/.prettierignore index 86080826..6e8a14b1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,7 +5,7 @@ packages/core/src/generators/api-links/__tests__/fixtures/ *.snapshot # Templates -packages/core/src/generators/web/template.html +packages/react/src/html/template.html # Output out/ diff --git a/README.md b/README.md index 1bcadb89..967e4878 100644 --- a/README.md +++ b/README.md @@ -111,11 +111,11 @@ npx doc-kit generate \ ### Redesigned -To generate [our redesigned documentation pages](https://nodejs-api-docs-tooling.vercel.app), use the `web` and `orama-db` (for search) generators. +To generate [our redesigned documentation pages](https://nodejs-api-docs-tooling.vercel.app), use the `html` and `orama-db` (for search) generators. These generators live in the separate [`@nodejs/doc-kit-generator-react`](packages/react) package, which must be installed alongside this one. ```sh npx doc-kit generate \ - -t web \ + -t html \ -t orama-db \ -i "path/to/node/doc/api/*.md" \ -o out \ diff --git a/beta/doc-kit.config.mjs b/beta/doc-kit.config.mjs index 07484c9c..5edaaa29 100644 --- a/beta/doc-kit.config.mjs +++ b/beta/doc-kit.config.mjs @@ -1,5 +1,5 @@ export default { - web: { + html: { remoteConfigUrl: 'https://raw.githubusercontent.com/nodejs/doc-kit/main/beta/site.json', diff --git a/docs/comparators.md b/docs/comparators.md index 6f87f379..0046c78a 100644 --- a/docs/comparators.md +++ b/docs/comparators.md @@ -35,7 +35,7 @@ scripts/comparators/ Comparators can be reused across multiple generators. You specify which comparator to use in the workflow file using the `compare` field. For example: -- `file-size.mjs` can compare output from `web`, `legacy-html`, or any generator +- `file-size.mjs` can compare output from `html`, `legacy-html`, or any generator - `object-assertion.mjs` can compare JSON output from `legacy-json`, `json-simple`, etc. - `my-comparator.mjs` would be a custom comparator for specific needs diff --git a/docs/generators.md b/docs/generators.md index 33f02c02..a2048499 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -21,7 +21,7 @@ Raw Markdown Files ↓ [jsx-ast] - Convert to JSX AST ↓ - [web] - Generate HTML/CSS/JS bundles + [html] - Generate HTML/CSS/JS bundles ``` Each generator declares its dependency using the `dependsOn` field, allowing automatic pipeline construction. @@ -357,7 +357,7 @@ export default { description: 'Requires all input at once', - dependsOn: '@node-core/doc-kit/jsx-ast', + dependsOn: '@nodejs/doc-kit-generator-react/jsx-ast', generate, }; diff --git a/eslint.config.mjs b/eslint.config.mjs index 197acf57..9e92946a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -96,7 +96,7 @@ export default defineConfig([ { files: [ 'packages/core/src/generators/legacy-html/assets/*.js', - 'packages/core/src/generators/web/ui/**/*', + 'packages/react/src/html/ui/**/*', ], languageOptions: { globals: { diff --git a/package-lock.json b/package-lock.json index 3a8ce0c9..541a633b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1387,6 +1387,10 @@ "node": ">=20" } }, + "node_modules/@nodejs/doc-kit-generator-react": { + "resolved": "packages/react", + "link": true + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -11205,35 +11209,19 @@ "name": "@node-core/doc-kit", "version": "1.4.3", "dependencies": { - "@11ty/is-land": "^5.0.1", "@actions/core": "^3.0.0", - "@fontsource-variable/open-sans": "^5.3.0", - "@fontsource/ibm-plex-mono": "^5.3.0", - "@heroicons/react": "^2.2.0", "@node-core/rehype-shiki": "^1.4.3", - "@node-core/ui-components": "^1.7.4", - "@orama/orama": "^3.1.18", - "@orama/ui": "^1.5.4", "@swc/html-wasm": "^1.15.46", "@swc/wasm": "^1.15.46", "acorn": "^8.17.0", "commander": "^15.0.0", "cosmiconfig": "^9.0.2", "dedent": "^1.7.2", - "estree-util-to-js": "^2.0.0", "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "glob-parent": "^6.0.2", - "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", - "mdast-util-slice-markdown": "^2.0.1", "piscina": "^5.3.0", - "preact": "^10.29.7", - "preact-render-to-string": "^6.7.0", - "reading-time": "^1.5.0", - "recma-jsx": "^1.0.1", - "rehype-raw": "^7.0.0", - "rehype-recma": "^1.0.0", "rehype-stringify": "^10.0.1", "remark-gfm": "^4.0.1", "remark-mdx": "^3.1.1", @@ -11250,11 +11238,51 @@ "unist-util-remove": "^4.0.0", "unist-util-select": "^5.1.0", "unist-util-visit": "^5.1.0", - "vite": "~8.1.5", "yaml": "^2.9.0" }, "bin": { "doc-kit": "bin/cli.mjs" + }, + "peerDependencies": { + "@nodejs/doc-kit-generator-react": "^0.0.0" + }, + "peerDependenciesMeta": { + "@nodejs/doc-kit-generator-react": { + "optional": true + } + } + }, + "packages/react": { + "name": "@nodejs/doc-kit-generator-react", + "version": "0.0.0", + "dependencies": { + "@11ty/is-land": "^5.0.1", + "@fontsource-variable/open-sans": "^5.3.0", + "@fontsource/ibm-plex-mono": "^5.3.0", + "@heroicons/react": "^2.2.0", + "@node-core/doc-kit": "^1.4.3", + "@node-core/rehype-shiki": "^1.4.3", + "@node-core/ui-components": "^1.7.4", + "@orama/orama": "^3.1.18", + "@orama/ui": "^1.5.4", + "estree-util-to-js": "^2.0.0", + "hast-util-to-string": "^3.0.1", + "hastscript": "^9.0.1", + "mdast-util-slice-markdown": "^2.0.1", + "preact": "^10.29.7", + "preact-render-to-string": "^6.7.0", + "reading-time": "^1.5.0", + "recma-jsx": "^1.0.1", + "recma-stringify": "^1.0.0", + "rehype-raw": "^7.0.0", + "rehype-recma": "^1.0.0", + "remark-parse": "^11.0.0", + "remark-rehype": "^11.1.2", + "semver": "^7.8.5", + "unified": "^11.0.5", + "unist-builder": "^4.0.0", + "unist-util-visit": "^5.1.0", + "vite": "~8.1.5" } } } diff --git a/packages/core/package.json b/packages/core/package.json index dec60f50..96ffaf80 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -23,17 +23,12 @@ "./ast": "./src/generators/ast/index.mjs", "./ast-js": "./src/generators/ast-js/index.mjs", "./json-simple": "./src/generators/json-simple/index.mjs", - "./jsx-ast": "./src/generators/jsx-ast/index.mjs", "./legacy-html": "./src/generators/legacy-html/index.mjs", "./legacy-html-all": "./src/generators/legacy-html-all/index.mjs", "./legacy-json": "./src/generators/legacy-json/index.mjs", "./legacy-json-all": "./src/generators/legacy-json-all/index.mjs", - "./llms-txt": "./src/generators/llms-txt/index.mjs", "./man-page": "./src/generators/man-page/index.mjs", "./metadata": "./src/generators/metadata/index.mjs", - "./orama-db": "./src/generators/orama-db/index.mjs", - "./sitemap": "./src/generators/sitemap/index.mjs", - "./web": "./src/generators/web/index.mjs", "./package.json": "./package.json", "./shiki.config.mjs": "./shiki.config.mjs", "./src/*": "./src/*", @@ -53,35 +48,19 @@ "README.md" ], "dependencies": { - "@11ty/is-land": "^5.0.1", "@actions/core": "^3.0.0", - "@fontsource-variable/open-sans": "^5.3.0", - "@fontsource/ibm-plex-mono": "^5.3.0", - "@heroicons/react": "^2.2.0", "@node-core/rehype-shiki": "^1.4.3", - "@node-core/ui-components": "^1.7.4", - "@orama/orama": "^3.1.18", - "@orama/ui": "^1.5.4", "@swc/html-wasm": "^1.15.46", "@swc/wasm": "^1.15.46", "acorn": "^8.17.0", "commander": "^15.0.0", "cosmiconfig": "^9.0.2", "dedent": "^1.7.2", - "estree-util-to-js": "^2.0.0", "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "glob-parent": "^6.0.2", - "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", - "mdast-util-slice-markdown": "^2.0.1", "piscina": "^5.3.0", - "preact": "^10.29.7", - "preact-render-to-string": "^6.7.0", - "reading-time": "^1.5.0", - "recma-jsx": "^1.0.1", - "rehype-raw": "^7.0.0", - "rehype-recma": "^1.0.0", "rehype-stringify": "^10.0.1", "remark-gfm": "^4.0.1", "remark-mdx": "^3.1.1", @@ -98,7 +77,14 @@ "unist-util-remove": "^4.0.0", "unist-util-select": "^5.1.0", "unist-util-visit": "^5.1.0", - "vite": "~8.1.5", "yaml": "^2.9.0" + }, + "peerDependencies": { + "@nodejs/doc-kit-generator-react": "^0.0.0" + }, + "peerDependenciesMeta": { + "@nodejs/doc-kit-generator-react": { + "optional": true + } } } diff --git a/packages/core/src/generators/__tests__/index.test.mjs b/packages/core/src/generators/__tests__/index.test.mjs index cd3bfdcf..e0af8670 100644 --- a/packages/core/src/generators/__tests__/index.test.mjs +++ b/packages/core/src/generators/__tests__/index.test.mjs @@ -1,13 +1,25 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { allGenerators, publicGenerators } from '../index.mjs'; +import { + allGenerators, + deprecatedGenerators, + publicGenerators, +} from '../index.mjs'; import { loadGenerator, resolveGeneratorSpecifier } from '../loader.mjs'; const validDependencies = Object.values(allGenerators); +// Deprecated aliases intentionally have keys that differ from the +// generator's name, so they are excluded from the name-match assertions. +const currentGenerators = Object.fromEntries( + Object.entries(allGenerators).filter( + ([name]) => !(name in deprecatedGenerators) + ) +); + const loadedGenerators = await Promise.all( - Object.entries(allGenerators).map(async ([name, specifier]) => [ + Object.entries(currentGenerators).map(async ([name, specifier]) => [ name, specifier, await loadGenerator(specifier), @@ -50,6 +62,15 @@ describe('All Generators', () => { }); }); + it('should resolve deprecated aliases to loadable generators', async () => { + for (const [name, specifier] of Object.entries(deprecatedGenerators)) { + assert.equal(resolveGeneratorSpecifier(name), specifier); + + const generator = await loadGenerator(specifier); + assert.ok(generator.name, `Deprecated alias "${name}" must load`); + } + }); + it('should have ast generator as a top-level generator with no dependencies', async () => { const ast = await loadGenerator(allGenerators.ast); assert.ok(ast, 'ast generator should exist'); diff --git a/packages/core/src/generators/index.mjs b/packages/core/src/generators/index.mjs index a8b1a68f..f356169f 100644 --- a/packages/core/src/generators/index.mjs +++ b/packages/core/src/generators/index.mjs @@ -2,7 +2,7 @@ /** * Maps the shorthand names accepted by the CLI and configuration files - * (e.g. `--target web`) to the import specifiers they resolve to. + * (e.g. `--target html`) to the import specifiers they resolve to. * * Generators are loaded dynamically by specifier (see `./loader.mjs`), so this * module must not import any generator code — it is purely a lookup table. @@ -18,10 +18,10 @@ export const publicGenerators = { 'legacy-json-all': '@node-core/doc-kit/legacy-json-all', 'addon-verify': '@node-core/doc-kit/addon-verify', 'api-links': '@node-core/doc-kit/api-links', - 'orama-db': '@node-core/doc-kit/orama-db', - 'llms-txt': '@node-core/doc-kit/llms-txt', - sitemap: '@node-core/doc-kit/sitemap', - web: '@node-core/doc-kit/web', + 'orama-db': '@nodejs/doc-kit-generator-react/orama-db', + 'llms-txt': '@nodejs/doc-kit-generator-react/llms-txt', + sitemap: '@nodejs/doc-kit-generator-react/sitemap', + html: '@nodejs/doc-kit-generator-react/html', }; // These ones are special since they don't produce standard output, @@ -30,11 +30,19 @@ export const publicGenerators = { const internalGenerators = { ast: '@node-core/doc-kit/ast', metadata: '@node-core/doc-kit/metadata', - 'jsx-ast': '@node-core/doc-kit/jsx-ast', + 'jsx-ast': '@nodejs/doc-kit-generator-react/jsx-ast', 'ast-js': '@node-core/doc-kit/ast-js', }; +// Former names kept resolvable for existing invocations and config files. +// Unlike the maps above, keys here intentionally differ from the generator's +// `name` property. +export const deprecatedGenerators = { + web: '@nodejs/doc-kit-generator-react/html', +}; + export const allGenerators = { ...publicGenerators, ...internalGenerators, + ...deprecatedGenerators, }; diff --git a/packages/core/src/generators/sitemap/utils/createPageSitemapEntry.mjs b/packages/core/src/generators/sitemap/utils/createPageSitemapEntry.mjs deleted file mode 100644 index fb74faa4..00000000 --- a/packages/core/src/generators/sitemap/utils/createPageSitemapEntry.mjs +++ /dev/null @@ -1,18 +0,0 @@ -import { populate } from '../../../utils/configuration/templates.mjs'; - -/** - * Builds an API doc sitemap url. - * - * @param {import('../../metadata/types').MetadataEntry} entry - * @param {import('../../../utils/configuration/types').Configuration['sitemap']} config - * @returns {import('../types').SitemapEntry} - */ -export const createPageSitemapEntry = (entry, config, lastmod) => ({ - loc: populate(config.pageURL, { - ...config, - path: entry.path, - }), - lastmod, - changefreq: 'weekly', - priority: '0.8', -}); diff --git a/packages/core/src/generators/web/template.html b/packages/core/src/generators/web/template.html deleted file mode 100644 index e3792678..00000000 --- a/packages/core/src/generators/web/template.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - ${title} - - - - ${head} - - - - - - - -
${dehydrated}
- - - diff --git a/packages/core/src/utils/remark.mjs b/packages/core/src/utils/remark.mjs index 1aacd37a..3935b7ea 100644 --- a/packages/core/src/utils/remark.mjs +++ b/packages/core/src/utils/remark.mjs @@ -1,10 +1,5 @@ 'use strict'; -import rehypeShikiji from '@node-core/rehype-shiki/plugin'; -import recmaJsx from 'recma-jsx'; -import recmaStringify from 'recma-stringify'; -import rehypeRaw from 'rehype-raw'; -import rehypeRecma from 'rehype-recma'; import rehypeStringify from 'rehype-stringify'; import remarkGfm from 'remark-gfm'; import remarkMdx from 'remark-mdx'; @@ -12,49 +7,24 @@ import remarkParse from 'remark-parse'; import remarkRehype from 'remark-rehype'; import remarkStringify from 'remark-stringify'; import { unified } from 'unified'; -import { visit } from 'unist-util-visit'; -import syntaxHighlighter, { highlighter } from './highlighter.mjs'; +import syntaxHighlighter from './highlighter.mjs'; import { lazy } from './misc.mjs'; -import { - typeAnnotationToHast, - typeAnnotationToHighlightedHast, -} from './type-annotations/hast.mjs'; +import { typeAnnotationToHast } from './type-annotations/hast.mjs'; import remarkTypeAnnotations from './type-annotations/remark.mjs'; -import { AST_NODE_TYPES } from '../generators/jsx-ast/constants.mjs'; -import transformAlerts from '../generators/jsx-ast/utils/plugins/alerts.mjs'; -import transformElements from '../generators/jsx-ast/utils/plugins/transformer.mjs'; -const passThrough = ['element', ...Object.values(AST_NODE_TYPES.MDX)]; -const codeMetaProperty = 'codeMeta'; - -/** - * Stores fenced code metadata on properties before rehypeRaw reparses the tree. - */ -const preserveCodeMeta = () => tree => { - visit(tree, 'element', node => { - const meta = node.data?.meta; - - if (node.tagName === 'code' && typeof meta === 'string') { - node.properties ||= {}; - node.properties[codeMetaProperty] = meta; - } - }); -}; - -/** - * Restores fenced code metadata so the Shiki plugin can read displayName. - */ -const restoreCodeMeta = () => tree => { - visit(tree, 'element', node => { - const meta = node.properties?.[codeMetaProperty]; - - if (node.tagName === 'code' && typeof meta === 'string') { - node.data = { ...node.data, meta }; - delete node.properties[codeMetaProperty]; - } - }); -}; +// MDX node types that may appear in trees parsed by `getRemarkMdx`; the +// rehype pipelines pass them through untouched. +const passThrough = [ + 'element', + 'mdxJsxTextElement', + 'mdxJsxFlowElement', + 'mdxJsxAttribute', + 'mdxJsxAttributeValueExpression', + 'mdxFlowExpression', + 'mdxTextExpression', + 'mdxjsEsm', +]; /** * Retrieves an instance of Remark configured to parse GFM (GitHub Flavored Markdown) @@ -125,34 +95,3 @@ export const getRemarkRehypeWithShiki = lazy(() => // and we trust the sources of the Markdown files .use(rehypeStringify, { allowDangerousHtml: true }) ); - -const singletonShiki = await rehypeShikiji({ highlighter }); - -/** - * Retrieves an instance of Remark configured to output JSX code. - * including parsing Code Boxes with syntax highlighting - */ -export const getRemarkRecma = lazy(() => - unified() - .use(remarkParse) - .use(transformAlerts) - // We make Rehype ignore existing HTML nodes, and JSX nodes - // as these are nodes we manually created during the generation process - // We also allow dangerous HTML to be passed through, since we have HTML within our Markdown - // and we trust the sources of the Markdown files - .use(remarkRehype, { - allowDangerousHtml: true, - passThrough, - // The web pipeline gets Shiki-highlighted types with embedded links - handlers: { typeAnnotation: typeAnnotationToHighlightedHast }, - }) - .use(preserveCodeMeta) - // Any `raw` HTML in the markdown must be converted to AST in order for Recma to understand it - .use(rehypeRaw, { passThrough }) - .use(restoreCodeMeta) - .use(() => singletonShiki) - .use(transformElements) - .use(rehypeRecma) - .use(recmaJsx) - .use(recmaStringify) -); diff --git a/packages/react/package.json b/packages/react/package.json new file mode 100644 index 00000000..636b9c9e --- /dev/null +++ b/packages/react/package.json @@ -0,0 +1,57 @@ +{ + "name": "@nodejs/doc-kit-generator-react", + "type": "module", + "version": "0.0.0", + "description": "React/JSX-based generators for @node-core/doc-kit: html, jsx-ast, llms-txt, sitemap, and orama-db", + "repository": { + "type": "git", + "url": "git+https://github.com/nodejs/doc-kit.git", + "directory": "packages/react" + }, + "exports": { + "./html": "./src/html/index.mjs", + "./html/bundlers/vite": "./src/html/bundlers/vite.mjs", + "./jsx-ast": "./src/jsx-ast/index.mjs", + "./llms-txt": "./src/llms-txt/index.mjs", + "./orama-db": "./src/orama-db/index.mjs", + "./sitemap": "./src/sitemap/index.mjs", + "./package.json": "./package.json" + }, + "files": [ + "src", + "!src/**/*.test.mjs", + "!src/**/__tests__", + "CHANGELOG.md", + "LICENSE", + "README.md" + ], + "dependencies": { + "@11ty/is-land": "^5.0.1", + "@fontsource-variable/open-sans": "^5.3.0", + "@fontsource/ibm-plex-mono": "^5.3.0", + "@heroicons/react": "^2.2.0", + "@node-core/doc-kit": "^1.4.3", + "@node-core/rehype-shiki": "^1.4.3", + "@node-core/ui-components": "^1.7.4", + "@orama/orama": "^3.1.18", + "@orama/ui": "^1.5.4", + "estree-util-to-js": "^2.0.0", + "hast-util-to-string": "^3.0.1", + "hastscript": "^9.0.1", + "mdast-util-slice-markdown": "^2.0.1", + "preact": "^10.29.7", + "preact-render-to-string": "^6.7.0", + "reading-time": "^1.5.0", + "recma-jsx": "^1.0.1", + "recma-stringify": "^1.0.0", + "rehype-raw": "^7.0.0", + "rehype-recma": "^1.0.0", + "remark-parse": "^11.0.0", + "remark-rehype": "^11.1.2", + "semver": "^7.8.5", + "unified": "^11.0.5", + "unist-builder": "^4.0.0", + "unist-util-visit": "^5.1.0", + "vite": "~8.1.5" + } +} diff --git a/packages/core/src/generators/web/README.md b/packages/react/src/html/README.md similarity index 95% rename from packages/core/src/generators/web/README.md rename to packages/react/src/html/README.md index c86c521b..7f875f7a 100644 --- a/packages/core/src/generators/web/README.md +++ b/packages/react/src/html/README.md @@ -1,6 +1,6 @@ -# `web` Generator +# `html` Generator -The `web` generator transforms JSX AST entries into complete web bundles. Its +The `html` generator transforms JSX AST entries into complete web bundles. Its bundler adapter builds server-rendered HTML and client-side JavaScript, CSS, and imported assets, then writes the complete static site to `output`. Vite is the default adapter, but projects can supply an adapter for webpack or another @@ -64,7 +64,7 @@ for any project: ```js // doc-kit.config.mjs export default { - web: { + html: { head: { meta: [ { name: 'description', content: 'My project documentation' }, @@ -97,7 +97,7 @@ are optional; omit either one to keep that component's default. Sidebar items are `{ label, link }` and may nest through an `items` array of their own. A `label` is plain text, except that backticked spans render as `` (``'`fs`'``), matching how page headings are rendered. A `link` is a -page path without its extension (`/fs`, `/generators/web`): it is resolved +page path without its extension (`/fs`, `/generators/html`): it is resolved against the page being rendered, so it obeys `useAbsoluteURLs` and highlights while it is the current page. Links starting with `http://` or `https://` are used as authored. @@ -109,7 +109,7 @@ tab and mark them with an external-link icon. ```js // doc-kit.config.mjs export default { - web: { + html: { navigation: { sidebar: [ { @@ -149,7 +149,7 @@ for a particular build system. Both `render` and `build` receive `{ entries, virtualImports, config }`; `build` also receives `pages`. Entry maps use `${api}.jsx` keys, rendered server results use `api` keys, and page maps use output-relative HTML file names. `config` is -the resolved web configuration. +the resolved `html` configuration. The adapter must compile the generated Preact JSX and CSS imports and resolve the supplied theme aliases and virtual modules. The generated `#theme/config` @@ -181,7 +181,7 @@ export const createWebpackBundler = webpackOptions => ({ import { createWebpackBundler } from './webpack-bundler.mjs'; export default { - web: { + html: { bundler: createWebpackBundler({ // Project-owned webpack configuration. }), @@ -197,11 +197,11 @@ directly and pass Vite's `UserConfig` to it: ```js // doc-kit.config.mjs -import { createViteBundler } from '@node-core/doc-kit/src/generators/web/bundlers/vite.mjs'; +import { createViteBundler } from '@nodejs/doc-kit-generator-react/html/bundlers/vite'; import myVitePlugin from './my-vite-plugin.mjs'; export default { - web: { + html: { bundler: createViteBundler({ plugins: [myVitePlugin()], define: { @@ -237,7 +237,7 @@ name to `createViteBundler` when another tool needs one. The generated HTML already references the correct hashed scripts, stylesheets, imported assets, and module preloads. -Function-valued plugins and hooks are supported because the `web` generator +Function-valued plugins and hooks are supported because the `html` generator runs on the main thread and does not serialize the bundler to a worker. ### Default `imports` @@ -260,7 +260,7 @@ Override any alias in your config file to swap in a custom component: ```js // doc-kit.config.mjs export default { - web: { + html: { imports: { '#theme/Logo': './src/MyLogo.jsx', '#theme/Sidebar': './src/MySidebar.jsx', @@ -282,7 +282,7 @@ real module path: ```js // doc-kit.config.mjs export default { - web: { + html: { components: { // Shorthand — equivalent to { name: 'Hero', source: '#theme/Hero' } Hero: '#theme/Hero', @@ -321,7 +321,7 @@ There are {stats.length} APIs documented. ## `#theme/config` virtual module -The `web` generator provides a `#theme/config` virtual module that exposes pre-computed configuration as named exports. Any component (including custom overrides) can import the values it needs, and tree-shaking removes the rest. +The `html` generator provides a `#theme/config` virtual module that exposes pre-computed configuration as named exports. Any component (including custom overrides) can import the values it needs, and tree-shaking removes the rest. ```js import { project, repository, editURL } from '#theme/config'; @@ -397,7 +397,7 @@ The HTML template file (set via `templatePath`) uses JavaScript template literal - `themeScript` {string} Inline script that applies the saved theme before paint. - `root` {string} Relative or absolute path to the site root. - `metadata` {Object} Full page metadata (frontmatter, path, heading, etc.). -- `config` {Object} The resolved web generator configuration. +- `config` {Object} The resolved `html` generator configuration. - `head` {string} Pre-rendered ``/``/raw markup from the `head` config. diff --git a/packages/core/src/generators/web/__tests__/generate.test.mjs b/packages/react/src/html/__tests__/generate.test.mjs similarity index 93% rename from packages/core/src/generators/web/__tests__/generate.test.mjs rename to packages/react/src/html/__tests__/generate.test.mjs index bb052f99..0445a621 100644 --- a/packages/core/src/generators/web/__tests__/generate.test.mjs +++ b/packages/react/src/html/__tests__/generate.test.mjs @@ -4,9 +4,9 @@ import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { describe, it } from 'node:test'; +import { setConfig } from '@node-core/doc-kit/utils/configuration/index.mjs'; import { jsx, toJs } from 'estree-util-to-js'; -import { setConfig } from '../../../utils/configuration/index.mjs'; import buildContent from '../../jsx-ast/utils/buildContent.mjs'; import { buildNotFoundPage } from '../../jsx-ast/utils/synthetic/404.mjs'; import { createViteBundler } from '../bundlers/vite.mjs'; @@ -53,12 +53,12 @@ const createTestConfiguration = async context => { context.after(() => rm(output, { recursive: true, force: true })); const config = await setConfig({ - target: ['web'], + target: ['html'], output, version: 'v22.0.0', changelog: [], generators: { - web: {}, + html: {}, }, }); @@ -93,7 +93,7 @@ describe('web generate', () => { it('renders the configurable head without hardcoded defaults', async context => { const { config, output } = await createTestConfiguration(context); - config.web.head = { + config.html.head = { meta: [ { name: 'description', content: 'Custom project docs' }, { property: 'og:image', content: 'https://example.com/og.png' }, @@ -116,8 +116,8 @@ describe('web generate', () => { it('uses Vite base URLs for absolute client assets', async context => { const { config, output } = await createTestConfiguration(context); - config.web.useAbsoluteURLs = true; - config.web.baseURL = 'https://example.com/docs'; + config.html.useAbsoluteURLs = true; + config.html.baseURL = 'https://example.com/docs'; const notFoundPage = buildNotFoundPage(); const content = await buildContent(notFoundPage.entries, notFoundPage.head); @@ -130,7 +130,7 @@ describe('web generate', () => { it('applies configured Vite plugins', async context => { const { config, output } = await createTestConfiguration(context); - config.web.bundler = createViteBundler({ + config.html.bundler = createViteBundler({ plugins: [ { name: 'test-html-transform', @@ -158,7 +158,7 @@ describe('web generate', () => { const { config, output } = await createTestConfiguration(context); const calls = []; - config.web.bundler = { + config.html.bundler = { getEntryId(api) { calls.push(`entry:${api}`); return `/custom/${api}.js`; @@ -166,7 +166,7 @@ describe('web generate', () => { async render({ entries, virtualImports, config: receivedConfig }) { calls.push('server'); - assert.strictEqual(receivedConfig, config.web); + assert.strictEqual(receivedConfig, config.html); assert.ok(entries.has('fs.jsx')); assert.match(virtualImports['#theme/config'], /export const pages/); assert.match( @@ -181,7 +181,7 @@ describe('web generate', () => { async build({ entries, virtualImports, pages, config: receivedConfig }) { calls.push('client'); - assert.strictEqual(receivedConfig, config.web); + assert.strictEqual(receivedConfig, config.html); assert.ok(entries.has('fs.jsx')); assert.match( virtualImports['#theme/config'], diff --git a/packages/core/src/generators/web/bundlers/__tests__/vite.test.mjs b/packages/react/src/html/bundlers/__tests__/vite.test.mjs similarity index 94% rename from packages/core/src/generators/web/bundlers/__tests__/vite.test.mjs rename to packages/react/src/html/bundlers/__tests__/vite.test.mjs index 7ff724c6..0d8486ed 100644 --- a/packages/core/src/generators/web/bundlers/__tests__/vite.test.mjs +++ b/packages/react/src/html/bundlers/__tests__/vite.test.mjs @@ -7,7 +7,8 @@ import { describe, it } from 'node:test'; import { default as getConfig, setConfig, -} from '../../../../utils/configuration/index.mjs'; +} from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { createVirtualModulesPlugin, createViteConfig, @@ -17,12 +18,12 @@ import { const output = join(tmpdir(), 'doc-kit-vite-test-output'); await setConfig({ - target: ['web'], + target: ['html'], output, version: 'v22.0.0', changelog: [], generators: { - web: {}, + html: {}, }, }); @@ -66,7 +67,7 @@ describe('Vite configuration', () => { sources: new Map(), input, server: false, - config: getConfig('web'), + config: getConfig('html'), vite, }); @@ -97,7 +98,7 @@ describe('Vite configuration', () => { input, server: true, serverOutDir: serverOutput, - config: getConfig('web'), + config: getConfig('html'), vite, }); @@ -125,7 +126,7 @@ describe('Vite SSR temporary output', () => { ], ]), virtualImports: {}, - config: getConfig('web'), + config: getConfig('html'), vite: {}, createTemporaryDirectory: async () => temporaryDirectory, }), diff --git a/packages/core/src/generators/web/bundlers/index.mjs b/packages/react/src/html/bundlers/index.mjs similarity index 100% rename from packages/core/src/generators/web/bundlers/index.mjs rename to packages/react/src/html/bundlers/index.mjs diff --git a/packages/core/src/generators/web/bundlers/vite.mjs b/packages/react/src/html/bundlers/vite.mjs similarity index 99% rename from packages/core/src/generators/web/bundlers/vite.mjs rename to packages/react/src/html/bundlers/vite.mjs index f6edcf23..5c9c3a82 100644 --- a/packages/core/src/generators/web/bundlers/vite.mjs +++ b/packages/react/src/html/bundlers/vite.mjs @@ -3,6 +3,7 @@ import { tmpdir } from 'node:os'; import { basename, isAbsolute, join, resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; +import { minifyHTML } from '@node-core/doc-kit/utils/html-minifier.mjs'; import { build as viteBuild, defaultClientConditions, @@ -10,8 +11,6 @@ import { mergeConfig, } from 'vite'; -import { minifyHTML } from '../../../utils/html-minifier.mjs'; - const VIRTUAL_PREFIX = 'virtual:doc-kit/'; const RESOLVED_VIRTUAL_PREFIX = '\0doc-kit:'; diff --git a/packages/core/src/generators/web/constants.mjs b/packages/react/src/html/constants.mjs similarity index 100% rename from packages/core/src/generators/web/constants.mjs rename to packages/react/src/html/constants.mjs diff --git a/packages/core/src/generators/web/generate.mjs b/packages/react/src/html/generate.mjs similarity index 92% rename from packages/core/src/generators/web/generate.mjs rename to packages/react/src/html/generate.mjs index 6903f67d..09ce5cef 100644 --- a/packages/core/src/generators/web/generate.mjs +++ b/packages/react/src/html/generate.mjs @@ -2,9 +2,10 @@ import { readFile } from 'node:fs/promises'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { copyStaticAssets } from './utils/copying.mjs'; import { createCodeConverter, processBundles } from './utils/processing.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; /** * Main generation function that sends per-page JSX code to the web bundler. @@ -17,7 +18,7 @@ import getConfig from '../../utils/configuration/index.mjs'; * @type {import('./types').Generator['generate']} */ export async function generate(input) { - const config = getConfig('web'); + const config = getConfig('html'); const template = await readFile(config.templatePath, 'utf-8'); diff --git a/packages/core/src/generators/web/index.mjs b/packages/react/src/html/index.mjs similarity index 93% rename from packages/core/src/generators/web/index.mjs rename to packages/react/src/html/index.mjs index 69cfaeea..6be73932 100644 --- a/packages/core/src/generators/web/index.mjs +++ b/packages/react/src/html/index.mjs @@ -2,8 +2,9 @@ import { join } from 'node:path'; +import { GITHUB_EDIT_URL } from '@node-core/doc-kit/utils/configuration/templates.mjs'; + import { generate } from './generate.mjs'; -import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs'; /** * Web generator - transforms JSX AST entries into complete web bundles. @@ -25,14 +26,14 @@ import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs'; * @type {import('./types').Generator} */ export default { - name: 'web', + name: 'html', description: 'Generates HTML/CSS/JS bundles from JSX AST entries', - dependsOn: '@node-core/doc-kit/jsx-ast', + dependsOn: '@nodejs/doc-kit-generator-react/jsx-ast', /** - * @param {import('../../utils/configuration/types').Configuration} config + * @param {import('@node-core/doc-kit/utils/configuration/types').Configuration} config */ defaultConfiguration: config => ({ templatePath: join(import.meta.dirname, 'template.html'), diff --git a/packages/react/src/html/template.html b/packages/react/src/html/template.html new file mode 100644 index 00000000..b702d8e5 --- /dev/null +++ b/packages/react/src/html/template.html @@ -0,0 +1,25 @@ + + + + + + ${title} + + + + ${head} + + + + + + + +
${dehydrated}
+ + + diff --git a/packages/core/src/generators/web/types.d.ts b/packages/react/src/html/types.d.ts similarity index 97% rename from packages/core/src/generators/web/types.d.ts rename to packages/react/src/html/types.d.ts index e4e53d82..c701153c 100644 --- a/packages/core/src/generators/web/types.d.ts +++ b/packages/react/src/html/types.d.ts @@ -1,5 +1,5 @@ import type { JSXContent } from '../jsx-ast/utils/buildContent.mjs'; -import type { GlobalConfiguration } from '../../utils/configuration/types'; +import type { GlobalConfiguration } from '@node-core/doc-kit/utils/configuration/types'; import type SideBar from '@node-core/ui-components/Containers/Sidebar'; import type NavBar from '@node-core/ui-components/Containers/NavBar'; import type { ComponentProps } from 'preact'; diff --git a/packages/core/src/generators/web/ui/components/Banner.jsx b/packages/react/src/html/ui/components/Banner.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/Banner.jsx rename to packages/react/src/html/ui/components/Banner.jsx diff --git a/packages/core/src/generators/web/ui/components/CodeBox.jsx b/packages/react/src/html/ui/components/CodeBox.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/CodeBox.jsx rename to packages/react/src/html/ui/components/CodeBox.jsx diff --git a/packages/core/src/generators/web/ui/components/CodeTabs.jsx b/packages/react/src/html/ui/components/CodeTabs.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/CodeTabs.jsx rename to packages/react/src/html/ui/components/CodeTabs.jsx diff --git a/packages/core/src/generators/web/ui/components/Layout/index.jsx b/packages/react/src/html/ui/components/Layout/index.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/Layout/index.jsx rename to packages/react/src/html/ui/components/Layout/index.jsx diff --git a/packages/core/src/generators/web/ui/components/MetaBar/index.jsx b/packages/react/src/html/ui/components/MetaBar/index.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/MetaBar/index.jsx rename to packages/react/src/html/ui/components/MetaBar/index.jsx diff --git a/packages/core/src/generators/web/ui/components/MetaBar/index.module.css b/packages/react/src/html/ui/components/MetaBar/index.module.css similarity index 100% rename from packages/core/src/generators/web/ui/components/MetaBar/index.module.css rename to packages/react/src/html/ui/components/MetaBar/index.module.css diff --git a/packages/core/src/generators/web/ui/components/NavBar.jsx b/packages/react/src/html/ui/components/NavBar.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/NavBar.jsx rename to packages/react/src/html/ui/components/NavBar.jsx diff --git a/packages/core/src/generators/web/ui/components/NoOp.jsx b/packages/react/src/html/ui/components/NoOp.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/NoOp.jsx rename to packages/react/src/html/ui/components/NoOp.jsx diff --git a/packages/core/src/generators/web/ui/components/SearchBox/index.jsx b/packages/react/src/html/ui/components/SearchBox/index.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/SearchBox/index.jsx rename to packages/react/src/html/ui/components/SearchBox/index.jsx diff --git a/packages/core/src/generators/web/ui/components/SearchBox/index.module.css b/packages/react/src/html/ui/components/SearchBox/index.module.css similarity index 100% rename from packages/core/src/generators/web/ui/components/SearchBox/index.module.css rename to packages/react/src/html/ui/components/SearchBox/index.module.css diff --git a/packages/core/src/generators/web/ui/components/SideBar/index.jsx b/packages/react/src/html/ui/components/SideBar/index.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/SideBar/index.jsx rename to packages/react/src/html/ui/components/SideBar/index.jsx diff --git a/packages/core/src/generators/web/ui/components/SideBar/index.module.css b/packages/react/src/html/ui/components/SideBar/index.module.css similarity index 100% rename from packages/core/src/generators/web/ui/components/SideBar/index.module.css rename to packages/react/src/html/ui/components/SideBar/index.module.css diff --git a/packages/core/src/generators/web/ui/components/ThemeToggle.jsx b/packages/react/src/html/ui/components/ThemeToggle.jsx similarity index 100% rename from packages/core/src/generators/web/ui/components/ThemeToggle.jsx rename to packages/react/src/html/ui/components/ThemeToggle.jsx diff --git a/packages/core/src/generators/web/ui/hooks/useBanners.mjs b/packages/react/src/html/ui/hooks/useBanners.mjs similarity index 100% rename from packages/core/src/generators/web/ui/hooks/useBanners.mjs rename to packages/react/src/html/ui/hooks/useBanners.mjs diff --git a/packages/core/src/generators/web/ui/hooks/useOrama.mjs b/packages/react/src/html/ui/hooks/useOrama.mjs similarity index 100% rename from packages/core/src/generators/web/ui/hooks/useOrama.mjs rename to packages/react/src/html/ui/hooks/useOrama.mjs diff --git a/packages/core/src/generators/web/ui/hooks/useTheme.mjs b/packages/react/src/html/ui/hooks/useTheme.mjs similarity index 100% rename from packages/core/src/generators/web/ui/hooks/useTheme.mjs rename to packages/react/src/html/ui/hooks/useTheme.mjs diff --git a/packages/core/src/generators/web/ui/index.css b/packages/react/src/html/ui/index.css similarity index 100% rename from packages/core/src/generators/web/ui/index.css rename to packages/react/src/html/ui/index.css diff --git a/packages/core/src/generators/web/ui/islands/loaders.mjs b/packages/react/src/html/ui/islands/loaders.mjs similarity index 100% rename from packages/core/src/generators/web/ui/islands/loaders.mjs rename to packages/react/src/html/ui/islands/loaders.mjs diff --git a/packages/core/src/generators/web/ui/islands/runtime.mjs b/packages/react/src/html/ui/islands/runtime.mjs similarity index 100% rename from packages/core/src/generators/web/ui/islands/runtime.mjs rename to packages/react/src/html/ui/islands/runtime.mjs diff --git a/packages/core/src/generators/web/ui/islands/withIsland.jsx b/packages/react/src/html/ui/islands/withIsland.jsx similarity index 100% rename from packages/core/src/generators/web/ui/islands/withIsland.jsx rename to packages/react/src/html/ui/islands/withIsland.jsx diff --git a/packages/core/src/generators/web/ui/package.json b/packages/react/src/html/ui/package.json similarity index 100% rename from packages/core/src/generators/web/ui/package.json rename to packages/react/src/html/ui/package.json diff --git a/packages/core/src/generators/web/ui/theme-script.mjs b/packages/react/src/html/ui/theme-script.mjs similarity index 100% rename from packages/core/src/generators/web/ui/theme-script.mjs rename to packages/react/src/html/ui/theme-script.mjs diff --git a/packages/core/src/generators/web/ui/types.d.ts b/packages/react/src/html/ui/types.d.ts similarity index 89% rename from packages/core/src/generators/web/ui/types.d.ts rename to packages/react/src/html/ui/types.d.ts index a47e6773..b7842f9e 100644 --- a/packages/core/src/generators/web/ui/types.d.ts +++ b/packages/react/src/html/ui/types.d.ts @@ -1,5 +1,5 @@ -import { GlobalConfiguration } from '../../../utils/configuration/types'; -import { MetadataEntry } from '../../metadata/types'; +import { GlobalConfiguration } from '@node-core/doc-kit/utils/configuration/types'; +import { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; import { Configuration } from '../types'; import { SemVer } from 'semver'; diff --git a/packages/core/src/generators/web/ui/utils/relativeOrAbsolute.mjs b/packages/react/src/html/ui/utils/relativeOrAbsolute.mjs similarity index 89% rename from packages/core/src/generators/web/ui/utils/relativeOrAbsolute.mjs rename to packages/react/src/html/ui/utils/relativeOrAbsolute.mjs index e08b4876..1ec84378 100644 --- a/packages/core/src/generators/web/ui/utils/relativeOrAbsolute.mjs +++ b/packages/react/src/html/ui/utils/relativeOrAbsolute.mjs @@ -1,4 +1,4 @@ -import { relative } from '../../../../utils/url.mjs'; +import { relative } from '@node-core/doc-kit/utils/url.mjs'; import { useAbsoluteURLs, baseURL } from '#theme/config'; diff --git a/packages/core/src/generators/web/ui/utils/renderLabel.jsx b/packages/react/src/html/ui/utils/renderLabel.jsx similarity index 100% rename from packages/core/src/generators/web/ui/utils/renderLabel.jsx rename to packages/react/src/html/ui/utils/renderLabel.jsx diff --git a/packages/core/src/generators/web/utils/__tests__/config.test.mjs b/packages/react/src/html/utils/__tests__/config.test.mjs similarity index 97% rename from packages/core/src/generators/web/utils/__tests__/config.test.mjs rename to packages/react/src/html/utils/__tests__/config.test.mjs index 4a64149b..b9f3bcfa 100644 --- a/packages/core/src/generators/web/utils/__tests__/config.test.mjs +++ b/packages/react/src/html/utils/__tests__/config.test.mjs @@ -1,10 +1,9 @@ import assert from 'node:assert/strict'; import { describe, it, mock } from 'node:test'; +import { setConfig } from '@node-core/doc-kit/utils/configuration/index.mjs'; import { SemVer } from 'semver'; -import { setConfig } from '../../../../utils/configuration/index.mjs'; - mock.module('@node-core/rehype-shiki', { namedExports: { LANGS: [ @@ -25,7 +24,7 @@ await setConfig({ { version: new SemVer('22.0.0'), isLts: false, isCurrent: true }, ], generators: { - web: { + html: { title: 'Node.js', repository: 'nodejs/node', ref: 'main', diff --git a/packages/core/src/generators/web/utils/__tests__/copying.test.mjs b/packages/react/src/html/utils/__tests__/copying.test.mjs similarity index 95% rename from packages/core/src/generators/web/utils/__tests__/copying.test.mjs rename to packages/react/src/html/utils/__tests__/copying.test.mjs index 385ab714..807b9b1f 100644 --- a/packages/core/src/generators/web/utils/__tests__/copying.test.mjs +++ b/packages/react/src/html/utils/__tests__/copying.test.mjs @@ -8,7 +8,7 @@ mock.module('node:fs/promises', { }); const mockLogError = mock.fn(); -mock.module('../../../../logger/index.mjs', { +mock.module('@node-core/doc-kit/logger/index.mjs', { defaultExport: { error: mockLogError }, }); @@ -120,7 +120,7 @@ describe('copyStaticAssets', () => { const logMessage = mockLogError.mock.calls[0].arguments[0]; assert.match( logMessage, - /\[web-generator\] Failed to copy asset from protected-file to \/out\/protected-file: Permission denied/ + /\[html-generator\] Failed to copy asset from protected-file to \/out\/protected-file: Permission denied/ ); }); }); diff --git a/packages/core/src/generators/web/utils/__tests__/processing.test.mjs b/packages/react/src/html/utils/__tests__/processing.test.mjs similarity index 96% rename from packages/core/src/generators/web/utils/__tests__/processing.test.mjs rename to packages/react/src/html/utils/__tests__/processing.test.mjs index bd0b4c5b..985a49dc 100644 --- a/packages/core/src/generators/web/utils/__tests__/processing.test.mjs +++ b/packages/react/src/html/utils/__tests__/processing.test.mjs @@ -4,7 +4,8 @@ import { describe, it } from 'node:test'; import { default as getConfig, setConfig, -} from '../../../../utils/configuration/index.mjs'; +} from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { buildHead, populateWithEvaluation, @@ -12,11 +13,11 @@ import { } from '../processing.mjs'; await setConfig({ - target: ['web'], + target: ['html'], version: 'v22.0.0', changelog: [], generators: { - web: { + html: { useAbsoluteURLs: false, baseURL: 'https://nodejs.org/docs', }, @@ -97,7 +98,7 @@ describe('resolvePageRoot', () => { }); it('uses the configured base URL for synthetic pages with absolute URLs', async () => { - getConfig('web').useAbsoluteURLs = true; + getConfig('html').useAbsoluteURLs = true; const result = resolvePageRoot({ path: '/404', @@ -105,7 +106,7 @@ describe('resolvePageRoot', () => { }); assert.strictEqual(result, 'https://nodejs.org/docs/'); - getConfig('web').useAbsoluteURLs = false; + getConfig('html').useAbsoluteURLs = false; }); }); diff --git a/packages/core/src/generators/web/utils/__tests__/relativeOrAbsolute.test.mjs b/packages/react/src/html/utils/__tests__/relativeOrAbsolute.test.mjs similarity index 90% rename from packages/core/src/generators/web/utils/__tests__/relativeOrAbsolute.test.mjs rename to packages/react/src/html/utils/__tests__/relativeOrAbsolute.test.mjs index 998d22e5..e191ff3c 100644 --- a/packages/core/src/generators/web/utils/__tests__/relativeOrAbsolute.test.mjs +++ b/packages/react/src/html/utils/__tests__/relativeOrAbsolute.test.mjs @@ -4,15 +4,16 @@ import { beforeEach, describe, it } from 'node:test'; import { setConfig, default as getConfig, -} from '../../../../utils/configuration/index.mjs'; +} from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { relativeOrAbsolute } from '../relativeOrAbsolute.mjs'; await setConfig({ - target: ['web'], + target: ['html'], version: 'v22.0.0', changelog: [], generators: { - web: { + html: { useAbsoluteURLs: false, baseURL: 'https://nodejs.org/docs', }, @@ -21,7 +22,7 @@ await setConfig({ describe('relativeOrAbsolute (relative mode)', () => { beforeEach(() => { - getConfig('web').useAbsoluteURLs = false; + getConfig('html').useAbsoluteURLs = false; }); it('returns a relative path from a nested page to root', () => { @@ -47,7 +48,7 @@ describe('relativeOrAbsolute (relative mode)', () => { describe('relativeOrAbsolute (absolute mode)', () => { beforeEach(() => { - getConfig('web').useAbsoluteURLs = true; + getConfig('html').useAbsoluteURLs = true; }); it('returns an absolute URL to root', () => { diff --git a/packages/core/src/generators/web/utils/config.mjs b/packages/react/src/html/utils/config.mjs similarity index 90% rename from packages/core/src/generators/web/utils/config.mjs rename to packages/react/src/html/utils/config.mjs index 042f1fcc..b32f937a 100644 --- a/packages/core/src/generators/web/utils/config.mjs +++ b/packages/react/src/html/utils/config.mjs @@ -1,11 +1,11 @@ 'use strict'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; +import { getVersionFromSemVer } from '@node-core/doc-kit/utils/generators.mjs'; +import { omitKeys } from '@node-core/doc-kit/utils/misc.mjs'; import { LANGS } from '@node-core/rehype-shiki'; -import getConfig from '../../../utils/configuration/index.mjs'; -import { populate } from '../../../utils/configuration/templates.mjs'; -import { getVersionFromSemVer } from '../../../utils/generators.mjs'; -import { omitKeys } from '../../../utils/misc.mjs'; import { getSortedHeadNodes } from '../../jsx-ast/utils/getSortedHeadNodes.mjs'; /** @@ -74,7 +74,7 @@ export function buildLanguageDisplayNameMap() { * @returns {string} JavaScript source code string with named exports */ export default function createConfigSource(input, server = false) { - const { version: configVersion, ...config } = getConfig('web'); + const { version: configVersion, ...config } = getConfig('html'); const editURL = populate(config.editURL, { ...config, diff --git a/packages/core/src/generators/web/utils/copying.mjs b/packages/react/src/html/utils/copying.mjs similarity index 86% rename from packages/core/src/generators/web/utils/copying.mjs rename to packages/react/src/html/utils/copying.mjs index 20bd5d12..084b6414 100644 --- a/packages/core/src/generators/web/utils/copying.mjs +++ b/packages/react/src/html/utils/copying.mjs @@ -1,7 +1,7 @@ import { cp } from 'node:fs/promises'; import { join, basename } from 'node:path'; -import logger from '../../../logger/index.mjs'; +import logger from '@node-core/doc-kit/logger/index.mjs'; /** * Copies static directories/files defined in `pathsToCopy` to the output directory. @@ -28,7 +28,7 @@ export async function copyStaticAssets(config) { } catch (err) { if (err.code !== 'ENOENT') { logger.error( - `[web-generator] Failed to copy asset from ${src} to ${dest}: ${err.message}` + `[html-generator] Failed to copy asset from ${src} to ${dest}: ${err.message}` ); } } diff --git a/packages/core/src/generators/web/utils/generate.mjs b/packages/react/src/html/utils/generate.mjs similarity index 96% rename from packages/core/src/generators/web/utils/generate.mjs rename to packages/react/src/html/utils/generate.mjs index e3c13c74..0ef403df 100644 --- a/packages/core/src/generators/web/utils/generate.mjs +++ b/packages/react/src/html/utils/generate.mjs @@ -1,6 +1,7 @@ import { resolve } from 'node:path'; -import getConfig from '../../../utils/configuration/index.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { JSX_IMPORTS, ROOT } from '../constants.mjs'; /** @@ -50,7 +51,7 @@ export const createImportDeclaration = ( */ export default () => { // User-configured components (for JSX-in-MDX), merged with the built-ins. - const { components } = getConfig('web'); + const { components } = getConfig('html'); const componentImports = [ ...Object.values(JSX_IMPORTS), diff --git a/packages/core/src/generators/web/utils/processing.mjs b/packages/react/src/html/utils/processing.mjs similarity index 85% rename from packages/core/src/generators/web/utils/processing.mjs rename to packages/react/src/html/utils/processing.mjs index 73263c02..cfbfba1d 100644 --- a/packages/core/src/generators/web/utils/processing.mjs +++ b/packages/react/src/html/utils/processing.mjs @@ -1,8 +1,9 @@ +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; + import createConfigSource from './config.mjs'; import createProgramBuilder from './generate.mjs'; import { relativeOrAbsolute } from './relativeOrAbsolute.mjs'; -import getConfig from '../../../utils/configuration/index.mjs'; -import { populate } from '../../../utils/configuration/templates.mjs'; import { resolveBundler } from '../bundlers/index.mjs'; import { SPECULATION_RULES } from '../constants.mjs'; import { THEME_SCRIPT } from '../ui/theme-script.mjs'; @@ -10,7 +11,7 @@ import { THEME_SCRIPT } from '../ui/theme-script.mjs'; /** * Creates the virtual imports for one bundle target. * - * @param {Array<{ data: import('../../metadata/types').MetadataEntry }>} sidebarEntries + * @param {Array<{ data: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry }>} sidebarEntries * @param {Record} virtualImports * @param {boolean} server * @returns {Record} @@ -38,12 +39,12 @@ export const populateWithEvaluation = (template, config) => { }; /** - * @param {import('../../metadata/types').MetadataEntry} data + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} data * @returns {string} */ export const resolvePageRoot = data => { if (data.synthetic === true) { - const { baseURL, useAbsoluteURLs } = getConfig('web'); + const { baseURL, useAbsoluteURLs } = getConfig('html'); return useAbsoluteURLs ? String(baseURL).replace(/\/?$/, '/') : '/'; } @@ -91,7 +92,7 @@ export const buildHead = ({ meta = [], links = [], html = [] }) => * string upstream (in the `jsx-ast` worker), so the heavy AST never reaches * the main thread — only the code string and page metadata stream in here. * - * @returns {{ add: (item: { data: import('../../metadata/types').MetadataEntry, code: string }) => void, serverCodeMap: Map, clientCodeMap: Map }} + * @returns {{ add: (item: { data: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry, code: string }) => void, serverCodeMap: Map, clientCodeMap: Map }} */ export function createCodeConverter() { const { buildServerProgram, clientProgram } = createProgramBuilder(); @@ -103,7 +104,7 @@ export function createCodeConverter() { /** * Records the server/client programs for a single page's JSX code. * - * @param {{ data: import('../../metadata/types').MetadataEntry, code: string }} item + * @param {{ data: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry, code: string }} item */ add: ({ data, code }) => { const fileName = `${data.api}.jsx`; @@ -128,8 +129,8 @@ export function createCodeConverter() { * @param {object} params * @param {Map} params.serverCodeMap - Server-side code per page. * @param {Map} params.clientCodeMap - Client-side code per page. - * @param {Array} params.datas - Per-page metadata, in render order. - * @param {Array<{ data: import('../../metadata/types').MetadataEntry }>} params.sidebarEntries - Entries used to build the sidebar page list (real module pages only). + * @param {Array} params.datas - Per-page metadata, in render order. + * @param {Array<{ data: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry }>} params.sidebarEntries - Entries used to build the sidebar page list (real module pages only). * @param {string} params.template - The HTML template string for the output pages. */ export async function processBundles({ @@ -139,7 +140,7 @@ export async function processBundles({ sidebarEntries, template, }) { - const config = getConfig('web'); + const config = getConfig('html'); const bundler = await resolveBundler(config.bundler); const serverPages = await bundler.render({ diff --git a/packages/core/src/generators/web/utils/relativeOrAbsolute.mjs b/packages/react/src/html/utils/relativeOrAbsolute.mjs similarity index 69% rename from packages/core/src/generators/web/utils/relativeOrAbsolute.mjs rename to packages/react/src/html/utils/relativeOrAbsolute.mjs index a37be0e3..cc85803d 100644 --- a/packages/core/src/generators/web/utils/relativeOrAbsolute.mjs +++ b/packages/react/src/html/utils/relativeOrAbsolute.mjs @@ -1,5 +1,5 @@ -import getConfig from '../../../utils/configuration/index.mjs'; -import { relative } from '../../../utils/url.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { relative } from '@node-core/doc-kit/utils/url.mjs'; /** * Returns an absolute URL (based on baseURL) or a relative URL, @@ -10,7 +10,7 @@ import { relative } from '../../../utils/url.mjs'; * @returns {string} */ export const relativeOrAbsolute = (to, from) => { - const { useAbsoluteURLs, baseURL } = getConfig('web'); + const { useAbsoluteURLs, baseURL } = getConfig('html'); return useAbsoluteURLs ? new URL(`.${to}`, baseURL.replace(/\/?$/, '/')).href diff --git a/packages/core/src/generators/jsx-ast/README.md b/packages/react/src/jsx-ast/README.md similarity index 100% rename from packages/core/src/generators/jsx-ast/README.md rename to packages/react/src/jsx-ast/README.md diff --git a/packages/core/src/generators/jsx-ast/__tests__/generate.test.mjs b/packages/react/src/jsx-ast/__tests__/generate.test.mjs similarity index 96% rename from packages/core/src/generators/jsx-ast/__tests__/generate.test.mjs rename to packages/react/src/jsx-ast/__tests__/generate.test.mjs index e1f52e76..4894c7e7 100644 --- a/packages/core/src/generators/jsx-ast/__tests__/generate.test.mjs +++ b/packages/react/src/jsx-ast/__tests__/generate.test.mjs @@ -1,7 +1,10 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import getConfig, { setConfig } from '../../../utils/configuration/index.mjs'; +import getConfig, { + setConfig, +} from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { generate, processChunk } from '../generate.mjs'; const createEntry = (api, name, { stabilityIndex = '2' } = {}) => { diff --git a/packages/core/src/generators/jsx-ast/constants.mjs b/packages/react/src/jsx-ast/constants.mjs similarity index 99% rename from packages/core/src/generators/jsx-ast/constants.mjs rename to packages/react/src/jsx-ast/constants.mjs index dddad667..ffeec38c 100644 --- a/packages/core/src/generators/jsx-ast/constants.mjs +++ b/packages/react/src/jsx-ast/constants.mjs @@ -1,4 +1,4 @@ -import { JSX_IMPORTS } from '../web/constants.mjs'; +import { JSX_IMPORTS } from '../html/constants.mjs'; /** * UI classes for Node.js API stability levels diff --git a/packages/core/src/generators/jsx-ast/generate.mjs b/packages/react/src/jsx-ast/generate.mjs similarity index 91% rename from packages/core/src/generators/jsx-ast/generate.mjs rename to packages/react/src/jsx-ast/generate.mjs index 055e0efb..89f69e93 100644 --- a/packages/core/src/generators/jsx-ast/generate.mjs +++ b/packages/react/src/jsx-ast/generate.mjs @@ -1,3 +1,5 @@ +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { groupNodesByModule } from '@node-core/doc-kit/utils/generators.mjs'; import { jsx, toJs } from 'estree-util-to-js'; import buildContent from './utils/buildContent.mjs'; @@ -5,8 +7,6 @@ import { getSortedHeadNodes } from './utils/getSortedHeadNodes.mjs'; import { buildNotFoundPage } from './utils/synthetic/404.mjs'; import { buildAllPage } from './utils/synthetic/all.mjs'; import { buildIndexPage } from './utils/synthetic/index.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { groupNodesByModule } from '../../utils/generators.mjs'; /** * Builds the `{ head, entries }` page descriptors for all configured synthetic @@ -14,7 +14,7 @@ import { groupNodesByModule } from '../../utils/generators.mjs'; * runs later in a worker (via `processChunk`), so the very large synthetic * `all` page is never built on the main thread. * - * @param {Array} input + * @param {Array} input */ const buildSyntheticDescriptors = input => { const config = getConfig('jsx-ast'); diff --git a/packages/core/src/generators/jsx-ast/index.mjs b/packages/react/src/jsx-ast/index.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/index.mjs rename to packages/react/src/jsx-ast/index.mjs diff --git a/packages/core/src/generators/jsx-ast/types.d.ts b/packages/react/src/jsx-ast/types.d.ts similarity index 82% rename from packages/core/src/generators/jsx-ast/types.d.ts rename to packages/react/src/jsx-ast/types.d.ts index 672c5a4f..cffbb835 100644 --- a/packages/core/src/generators/jsx-ast/types.d.ts +++ b/packages/react/src/jsx-ast/types.d.ts @@ -1,4 +1,4 @@ -import type { MetadataEntry } from '../metadata/types'; +import type { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; import type { JSXContent } from './utils/buildContent.mjs'; export type Generator = GeneratorMetadata< diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/ast.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/ast.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/__tests__/ast.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/ast.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/buildBarProps.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/buildBarProps.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/buildContent.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/buildContent.test.mjs similarity index 95% rename from packages/core/src/generators/jsx-ast/utils/__tests__/buildContent.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/buildContent.test.mjs index afb86405..e1c21538 100644 --- a/packages/core/src/generators/jsx-ast/utils/__tests__/buildContent.test.mjs +++ b/packages/react/src/jsx-ast/utils/__tests__/buildContent.test.mjs @@ -1,7 +1,8 @@ import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; -import { setConfig } from '../../../../utils/configuration/index.mjs'; +import { setConfig } from '@node-core/doc-kit/utils/configuration/index.mjs'; + import { transformHeadingNode } from '../buildContent.mjs'; const heading = { diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/overloads.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/overloads.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/__tests__/overloads.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/overloads.test.mjs diff --git a/packages/core/src/utils/__tests__/remark.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/remark.test.mjs similarity index 100% rename from packages/core/src/utils/__tests__/remark.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/remark.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/signature.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/signature.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/__tests__/signature.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/signature.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/__tests__/types.test.mjs b/packages/react/src/jsx-ast/utils/__tests__/types.test.mjs similarity index 99% rename from packages/core/src/generators/jsx-ast/utils/__tests__/types.test.mjs rename to packages/react/src/jsx-ast/utils/__tests__/types.test.mjs index 0c4a7c3e..de963d4f 100644 --- a/packages/core/src/generators/jsx-ast/utils/__tests__/types.test.mjs +++ b/packages/react/src/jsx-ast/utils/__tests__/types.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { describe, it, mock } from 'node:test'; // Mock remark -mock.module('../../../../utils/remark.mjs', { +mock.module('../remark.mjs', { namedExports: { getRemarkRecma: () => ({ runSync: () => ({ diff --git a/packages/core/src/generators/jsx-ast/utils/ast.mjs b/packages/react/src/jsx-ast/utils/ast.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/ast.mjs rename to packages/react/src/jsx-ast/utils/ast.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/buildBarProps.mjs b/packages/react/src/jsx-ast/utils/buildBarProps.mjs similarity index 83% rename from packages/core/src/generators/jsx-ast/utils/buildBarProps.mjs rename to packages/react/src/jsx-ast/utils/buildBarProps.mjs index d535c30a..367d96ea 100644 --- a/packages/core/src/generators/jsx-ast/utils/buildBarProps.mjs +++ b/packages/react/src/jsx-ast/utils/buildBarProps.mjs @@ -12,7 +12,7 @@ const FUNCTION_HEADING_TYPES = new Set(['method', 'ctor', 'classMethod']); /** * Generate a combined plain text string from all MDAST entries for estimating reading time. * - * @param {Array} entries - API documentation entries + * @param {Array} entries - API documentation entries */ export const extractTextContent = entries => { return entries.reduce((acc, entry) => { @@ -25,7 +25,7 @@ export const extractTextContent = entries => { /** * Determines if an entry should be included in the Table of Contents. - * @param {import('../../metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry */ const shouldIncludeEntryInToC = ({ heading }) => // Only include headings with text, @@ -41,7 +41,7 @@ const shouldIncludeEntryInToC = ({ heading }) => * other headings keep their plain text, with CLI flags / env vars and leading * prefixes (i.e. `Class:`) stripped. * - * @param {import('../../metadata/types').HeadingData} data + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingData} data */ const headingLabel = data => { if (FUNCTION_HEADING_TYPES.has(data.type)) { @@ -70,7 +70,7 @@ const headingLabel = data => { /** * Extracts and formats heading information from an API documentation entry. - * @param {import('../../metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry */ const extractHeading = entry => { const data = entry.heading.data; @@ -88,7 +88,7 @@ const extractHeading = entry => { * Build the list of heading metadata for sidebar navigation. Overload headings * are dropped so each function contributes a single entry. * - * @param {Array} entries - All API metadata entries + * @param {Array} entries - All API metadata entries */ export const extractHeadings = entries => entries diff --git a/packages/core/src/generators/jsx-ast/utils/buildContent.mjs b/packages/react/src/jsx-ast/utils/buildContent.mjs similarity index 83% rename from packages/core/src/generators/jsx-ast/utils/buildContent.mjs rename to packages/react/src/jsx-ast/utils/buildContent.mjs index dd621eec..3b1ac769 100644 --- a/packages/core/src/generators/jsx-ast/utils/buildContent.mjs +++ b/packages/react/src/jsx-ast/utils/buildContent.mjs @@ -1,5 +1,13 @@ 'use strict'; +import { enforceArray } from '@node-core/doc-kit/utils/array.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { + GITHUB_BLOB_URL, + populate, +} from '@node-core/doc-kit/utils/configuration/templates.mjs'; +import { omitKeys } from '@node-core/doc-kit/utils/misc.mjs'; +import { UNIST } from '@node-core/doc-kit/utils/queries/index.mjs'; import { h as createElement } from 'hastscript'; import { slice } from 'mdast-util-slice-markdown'; import readingTime from 'reading-time'; @@ -9,9 +17,8 @@ import { SKIP, visit } from 'unist-util-visit'; import { createJSXElement } from './ast.mjs'; import { extractHeadings, extractTextContent } from './buildBarProps.mjs'; import { annotateOverloads } from './overloads.mjs'; -import { enforceArray } from '../../../utils/array.mjs'; -import { omitKeys } from '../../../utils/misc.mjs'; -import { JSX_IMPORTS } from '../../web/constants.mjs'; +import { getRemarkRecma as remark } from './remark.mjs'; +import { JSX_IMPORTS } from '../../html/constants.mjs'; import { STABILITY_LEVELS, LIFECYCLE_LABELS, @@ -27,17 +34,10 @@ import { createSignatureTable, getFullName, } from './signature.mjs'; -import getConfig from '../../../utils/configuration/index.mjs'; -import { - GITHUB_BLOB_URL, - populate, -} from '../../../utils/configuration/templates.mjs'; -import { UNIST } from '../../../utils/queries/index.mjs'; -import { getRemarkRecma as remark } from '../../../utils/remark.mjs'; /** * Processes lifecycle and change history data into a sorted array of change entries. - * @param {import('../../metadata/types').MetadataEntry} entry - The metadata entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The metadata entry */ export const gatherChangeEntries = entry => { // Lifecycle changes (e.g., added, deprecated) @@ -61,7 +61,7 @@ export const gatherChangeEntries = entry => { /** * Creates a JSX ChangeHistory element or returns null if no changes. - * @param {import('../../metadata/types').MetadataEntry} entry - The metadata entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The metadata entry */ export const createChangeElement = entry => { const changes = gatherChangeEntries(entry); @@ -128,7 +128,7 @@ export const extractHeadingContent = content => { /** * Creates a heading wrapper element with anchors, icons, and optional change history. - * @param {import('../../metadata/types').HeadingNode} content - The content node to extract text from + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} content - The content node to extract text from * @param {import('unist').Node|null} changeElement - The change history element, if available */ export const createHeadingElement = (content, changeElement) => { @@ -166,7 +166,7 @@ export const createHeadingElement = (content, changeElement) => { /** * Converts a stability note node to an AlertBox JSX element - * @param {import('../../metadata/types').StabilityNode} node - The stability node to transform + * @param {import('@node-core/doc-kit/generators/metadata/types').StabilityNode} node - The stability node to transform * @param {number} index - The index of the node in its parent's children array * @param {import('unist').Parent} parent - The parent node containing the stability node */ @@ -200,8 +200,8 @@ const getLevelFromDeprecationType = typeText => { /** * Transforms a heading node by injecting metadata, source links, and signatures. - * @param {import('../../metadata/types').MetadataEntry} entry - The API metadata entry - * @param {import('../../metadata/types').HeadingNode} node - The heading node to transform + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The API metadata entry + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} node - The heading node to transform * @param {number} index - The index of the node in its parent's children array * @param {import('unist').Parent} parent - The parent node containing the heading */ @@ -250,7 +250,7 @@ export const transformHeadingNode = async (entry, node, index, parent) => { /** * Processes a single API documentation entry's content - * @param {import('../../metadata/types').MetadataEntry} entry - The API metadata entry to process + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The API metadata entry to process */ export const processEntry = entry => { // Visit and transform stability nodes @@ -276,7 +276,7 @@ export const processEntry = entry => { /** * Builds the overall document layout tree - * @param {Array} entries - API documentation metadata entries + * @param {Array} entries - API documentation metadata entries * @param {Object} metadata - Raw page metadata from the head entry */ export const createDocumentLayout = (entries, metadata) => { @@ -295,11 +295,11 @@ export const createDocumentLayout = (entries, metadata) => { }; /** - * @typedef {import('estree').Node & { data: import('../../metadata/types').MetadataEntry }} JSXContent + * @typedef {import('estree').Node & { data: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry }} JSXContent * * Transforms API metadata entries into processed MDX content - * @param {Array} metadataEntries - API documentation metadata entries - * @param {import('../../metadata/types').MetadataEntry} head - Main API metadata entry with version information + * @param {Array} metadataEntries - API documentation metadata entries + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} head - Main API metadata entry with version information * @returns {Promise} */ const buildContent = async (metadataEntries, head) => { diff --git a/packages/core/src/generators/jsx-ast/utils/getSortedHeadNodes.mjs b/packages/react/src/jsx-ast/utils/getSortedHeadNodes.mjs similarity index 66% rename from packages/core/src/generators/jsx-ast/utils/getSortedHeadNodes.mjs rename to packages/react/src/jsx-ast/utils/getSortedHeadNodes.mjs index c0f0c54c..b28460cc 100644 --- a/packages/core/src/generators/jsx-ast/utils/getSortedHeadNodes.mjs +++ b/packages/react/src/jsx-ast/utils/getSortedHeadNodes.mjs @@ -4,8 +4,8 @@ import { OVERRIDDEN_POSITIONS } from '../constants.mjs'; /** * Sorts entries by OVERRIDDEN_POSITIONS and then heading name. - * @param {import('../../metadata/types').MetadataEntry} a - * @param {import('../../metadata/types').MetadataEntry} b + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} a + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} b * @returns {number} */ const headingSortFn = (a, b) => { @@ -29,8 +29,8 @@ const headingSortFn = (a, b) => { /** * Filters and sorts entries by OVERRIDDEN_POSITIONS and then heading name. - * @param {Array} entries - * @returns {Array} + * @param {Array} entries + * @returns {Array} */ export const getSortedHeadNodes = entries => entries.filter(node => node.heading.depth === 1).toSorted(headingSortFn); diff --git a/packages/core/src/generators/jsx-ast/utils/overloads.mjs b/packages/react/src/jsx-ast/utils/overloads.mjs similarity index 78% rename from packages/core/src/generators/jsx-ast/utils/overloads.mjs rename to packages/react/src/jsx-ast/utils/overloads.mjs index b35ad093..f6feee03 100644 --- a/packages/core/src/generators/jsx-ast/utils/overloads.mjs +++ b/packages/react/src/jsx-ast/utils/overloads.mjs @@ -8,8 +8,8 @@ const OVERLOADABLE_TYPES = new Set(['method', 'ctor', 'classMethod']); * Two headings document the same function (i.e. are overloads of one another) * when they sit at the same depth and share the same resolved name and type. * - * @param {import('../../metadata/types').HeadingNode} a - * @param {import('../../metadata/types').HeadingNode} b + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} a + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} b */ const isSameFunction = (a, b) => a.depth === b.depth && @@ -26,8 +26,8 @@ const isSameFunction = (a, b) => * rendering in full on the page. The first (most stable) heading is left as-is, * and the ToC links to its existing anchor. * - * @param {Array} entries - Page entries, in render order. - * @returns {Array} The same entries (mutated). + * @param {Array} entries - Page entries, in render order. + * @returns {Array} The same entries (mutated). */ export const annotateOverloads = entries => { for (let i = 0; i < entries.length; i++) { diff --git a/packages/core/src/generators/jsx-ast/utils/plugins/__tests__/alerts.test.mjs b/packages/react/src/jsx-ast/utils/plugins/__tests__/alerts.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/plugins/__tests__/alerts.test.mjs rename to packages/react/src/jsx-ast/utils/plugins/__tests__/alerts.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/plugins/__tests__/transformer.test.mjs b/packages/react/src/jsx-ast/utils/plugins/__tests__/transformer.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/plugins/__tests__/transformer.test.mjs rename to packages/react/src/jsx-ast/utils/plugins/__tests__/transformer.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/plugins/alerts.mjs b/packages/react/src/jsx-ast/utils/plugins/alerts.mjs similarity index 97% rename from packages/core/src/generators/jsx-ast/utils/plugins/alerts.mjs rename to packages/react/src/jsx-ast/utils/plugins/alerts.mjs index 1abe1940..4ede03e5 100644 --- a/packages/core/src/generators/jsx-ast/utils/plugins/alerts.mjs +++ b/packages/react/src/jsx-ast/utils/plugins/alerts.mjs @@ -2,7 +2,7 @@ import { SKIP, visit } from 'unist-util-visit'; -import { JSX_IMPORTS } from '../../../web/constants.mjs'; +import { JSX_IMPORTS } from '../../../html/constants.mjs'; import { ALERT_MARKER, GITHUB_ALERT_TYPES } from '../../constants.mjs'; import { createJSXElement } from '../ast.mjs'; diff --git a/packages/core/src/generators/jsx-ast/utils/plugins/transformer.mjs b/packages/react/src/jsx-ast/utils/plugins/transformer.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/plugins/transformer.mjs rename to packages/react/src/jsx-ast/utils/plugins/transformer.mjs diff --git a/packages/react/src/jsx-ast/utils/remark.mjs b/packages/react/src/jsx-ast/utils/remark.mjs new file mode 100644 index 00000000..889244f3 --- /dev/null +++ b/packages/react/src/jsx-ast/utils/remark.mjs @@ -0,0 +1,80 @@ +'use strict'; + +import { highlighter } from '@node-core/doc-kit/utils/highlighter.mjs'; +import { lazy } from '@node-core/doc-kit/utils/misc.mjs'; +import { typeAnnotationToHighlightedHast } from '@node-core/doc-kit/utils/type-annotations/hast.mjs'; +import rehypeShikiji from '@node-core/rehype-shiki/plugin'; +import recmaJsx from 'recma-jsx'; +import recmaStringify from 'recma-stringify'; +import rehypeRaw from 'rehype-raw'; +import rehypeRecma from 'rehype-recma'; +import remarkParse from 'remark-parse'; +import remarkRehype from 'remark-rehype'; +import { unified } from 'unified'; +import { visit } from 'unist-util-visit'; + +import { AST_NODE_TYPES } from '../constants.mjs'; +import transformAlerts from './plugins/alerts.mjs'; +import transformElements from './plugins/transformer.mjs'; + +const passThrough = ['element', ...Object.values(AST_NODE_TYPES.MDX)]; +const codeMetaProperty = 'codeMeta'; + +/** + * Stores fenced code metadata on properties before rehypeRaw reparses the tree. + */ +const preserveCodeMeta = () => tree => { + visit(tree, 'element', node => { + const meta = node.data?.meta; + + if (node.tagName === 'code' && typeof meta === 'string') { + node.properties ||= {}; + node.properties[codeMetaProperty] = meta; + } + }); +}; + +/** + * Restores fenced code metadata so the Shiki plugin can read displayName. + */ +const restoreCodeMeta = () => tree => { + visit(tree, 'element', node => { + const meta = node.properties?.[codeMetaProperty]; + + if (node.tagName === 'code' && typeof meta === 'string') { + node.data = { ...node.data, meta }; + delete node.properties[codeMetaProperty]; + } + }); +}; + +const singletonShiki = await rehypeShikiji({ highlighter }); + +/** + * Retrieves an instance of Remark configured to output JSX code. + * including parsing Code Boxes with syntax highlighting + */ +export const getRemarkRecma = lazy(() => + unified() + .use(remarkParse) + .use(transformAlerts) + // We make Rehype ignore existing HTML nodes, and JSX nodes + // as these are nodes we manually created during the generation process + // We also allow dangerous HTML to be passed through, since we have HTML within our Markdown + // and we trust the sources of the Markdown files + .use(remarkRehype, { + allowDangerousHtml: true, + passThrough, + // The web pipeline gets Shiki-highlighted types with embedded links + handlers: { typeAnnotation: typeAnnotationToHighlightedHast }, + }) + .use(preserveCodeMeta) + // Any `raw` HTML in the markdown must be converted to AST in order for Recma to understand it + .use(rehypeRaw, { passThrough }) + .use(restoreCodeMeta) + .use(() => singletonShiki) + .use(transformElements) + .use(rehypeRecma) + .use(recmaJsx) + .use(recmaStringify) +); diff --git a/packages/core/src/generators/jsx-ast/utils/signature.mjs b/packages/react/src/jsx-ast/utils/signature.mjs similarity index 83% rename from packages/core/src/generators/jsx-ast/utils/signature.mjs rename to packages/react/src/jsx-ast/utils/signature.mjs index f7220d02..8ffedcc4 100644 --- a/packages/core/src/generators/jsx-ast/utils/signature.mjs +++ b/packages/react/src/jsx-ast/utils/signature.mjs @@ -1,18 +1,18 @@ +import { highlighter } from '@node-core/doc-kit/utils/highlighter.mjs'; +import { UNIST } from '@node-core/doc-kit/utils/queries/index.mjs'; +import { parseListItem } from '@node-core/doc-kit/utils/signature/parseList.mjs'; +import parseSignature from '@node-core/doc-kit/utils/signature/parseSignature.mjs'; import { h as createElement } from 'hastscript'; import { createJSXElement } from './ast.mjs'; import { parseListIntoProperties } from './types.mjs'; -import { highlighter } from '../../../utils/highlighter.mjs'; -import { UNIST } from '../../../utils/queries/index.mjs'; -import { parseListItem } from '../../../utils/signature/parseList.mjs'; -import parseSignature from '../../../utils/signature/parseSignature.mjs'; -import { JSX_IMPORTS } from '../../web/constants.mjs'; +import { JSX_IMPORTS } from '../../html/constants.mjs'; /** * Generates a string representation of a function or class signature. * * @param {string} functionName - The name of the function or class. - * @param {import('../../../utils/signature/types').MethodSignature} signature - The parsed signature object. + * @param {import('@node-core/doc-kit/utils/signature/types').MethodSignature} signature - The parsed signature object. * @param {string} prefix - Optional prefix, i.e. `'new '` for constructors. */ export const generateSignature = ( @@ -52,7 +52,7 @@ export const generateSignature = ( * Creates a syntax-highlighted code block for a signature using rehype-shiki. * * @param {string} functionName - The function name to display. - * @param {import('../../../utils/signature/types').MethodSignature} signature - Signature object with parameter and return type info. + * @param {import('@node-core/doc-kit/utils/signature/types').MethodSignature} signature - Signature object with parameter and return type info. * @param {string} prefix - Optional prefix like `'new '`. */ export const createSignatureCodeBlock = (functionName, signature, prefix) => { @@ -66,7 +66,7 @@ export const createSignatureCodeBlock = (functionName, signature, prefix) => { * Infers the "real" function name from a heading node. * Useful when auto-generated headings differ from code tokens. * - * @param {import('../../metadata/types').HeadingData} heading - Metadata with name and text fields. + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingData} heading - Metadata with name and text fields. * @param {any} fallback - Fallback value if inference fails. */ export const getFullName = ({ name, text }, fallback = name) => { @@ -91,7 +91,7 @@ export const getFullName = ({ name, text }, fallback = name) => { * Mutates the `children` array by injecting the signature HAST node. * * @param {import('@types/mdast').Parent} parent - The parent MDAST node (usually a section). - * @param {import('../../metadata/types').HeadingNode} heading - The heading node with metadata. + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} heading - The heading node with metadata. * @param {number} idx - The index at which the heading occurs in `parent.children`. */ export const insertSignatureCodeBlock = ({ children }, { data }, idx) => { diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/404.mjs b/packages/react/src/jsx-ast/utils/synthetic/404.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/404.mjs rename to packages/react/src/jsx-ast/utils/synthetic/404.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/404.test.mjs b/packages/react/src/jsx-ast/utils/synthetic/__tests__/404.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/404.test.mjs rename to packages/react/src/jsx-ast/utils/synthetic/__tests__/404.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/all.test.mjs b/packages/react/src/jsx-ast/utils/synthetic/__tests__/all.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/all.test.mjs rename to packages/react/src/jsx-ast/utils/synthetic/__tests__/all.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/index.test.mjs b/packages/react/src/jsx-ast/utils/synthetic/__tests__/index.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/index.test.mjs rename to packages/react/src/jsx-ast/utils/synthetic/__tests__/index.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/synthetic.test.mjs b/packages/react/src/jsx-ast/utils/synthetic/__tests__/synthetic.test.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/__tests__/synthetic.test.mjs rename to packages/react/src/jsx-ast/utils/synthetic/__tests__/synthetic.test.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/all.mjs b/packages/react/src/jsx-ast/utils/synthetic/all.mjs similarity index 70% rename from packages/core/src/generators/jsx-ast/utils/synthetic/all.mjs rename to packages/react/src/jsx-ast/utils/synthetic/all.mjs index a25894ed..79537e4f 100644 --- a/packages/core/src/generators/jsx-ast/utils/synthetic/all.mjs +++ b/packages/react/src/jsx-ast/utils/synthetic/all.mjs @@ -5,7 +5,7 @@ import { createSyntheticHead } from './synthetic.mjs'; /** * Builds the page descriptor for `all.html` * - * @param {Array} entries + * @param {Array} entries */ export const buildAllPage = entries => ({ head: createSyntheticHead('all', 'All'), diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/index.mjs b/packages/react/src/jsx-ast/utils/synthetic/index.mjs similarity index 88% rename from packages/core/src/generators/jsx-ast/utils/synthetic/index.mjs rename to packages/react/src/jsx-ast/utils/synthetic/index.mjs index 423d11a0..f040e98b 100644 --- a/packages/core/src/generators/jsx-ast/utils/synthetic/index.mjs +++ b/packages/react/src/jsx-ast/utils/synthetic/index.mjs @@ -3,7 +3,7 @@ import { h as createElement } from 'hastscript'; import { createSyntheticHead, wrapAsEntry } from './synthetic.mjs'; -import { JSX_IMPORTS } from '../../../web/constants.mjs'; +import { JSX_IMPORTS } from '../../../html/constants.mjs'; import { createJSXElement } from '../ast.mjs'; import { getSortedHeadNodes } from '../getSortedHeadNodes.mjs'; @@ -28,7 +28,7 @@ const getStabilityBadgeKind = index => * Builds the Stability Overview table from module heads that declare a * top-level stability index, mirroring the `legacy-html-all` overview. * - * @param {Array} headEntries + * @param {Array} headEntries */ export const buildStabilityOverview = headEntries => createElement('table', [ @@ -64,7 +64,7 @@ export const buildStabilityOverview = headEntries => /** * Builds the page descriptor for `index.html` * - * @param {Array} entries + * @param {Array} entries */ export const buildIndexPage = entries => { const head = createSyntheticHead('index', 'Index'); diff --git a/packages/core/src/generators/jsx-ast/utils/synthetic/synthetic.mjs b/packages/react/src/jsx-ast/utils/synthetic/synthetic.mjs similarity index 100% rename from packages/core/src/generators/jsx-ast/utils/synthetic/synthetic.mjs rename to packages/react/src/jsx-ast/utils/synthetic/synthetic.mjs diff --git a/packages/core/src/generators/jsx-ast/utils/types.mjs b/packages/react/src/jsx-ast/utils/types.mjs similarity index 90% rename from packages/core/src/generators/jsx-ast/utils/types.mjs rename to packages/react/src/jsx-ast/utils/types.mjs index 706f7dd9..1d5867b8 100644 --- a/packages/core/src/generators/jsx-ast/utils/types.mjs +++ b/packages/react/src/jsx-ast/utils/types.mjs @@ -1,9 +1,9 @@ +import { QUERIES, UNIST } from '@node-core/doc-kit/utils/queries/index.mjs'; +import { DEFAULT_EXPRESSION } from '@node-core/doc-kit/utils/signature/constants.mjs'; +import { transformNodesToString } from '@node-core/doc-kit/utils/unist.mjs'; import { u as createTree } from 'unist-builder'; -import { QUERIES, UNIST } from '../../../utils/queries/index.mjs'; -import { getRemarkRecma as remark } from '../../../utils/remark.mjs'; -import { DEFAULT_EXPRESSION } from '../../../utils/signature/constants.mjs'; -import { transformNodesToString } from '../../../utils/unist.mjs'; +import { getRemarkRecma as remark } from './remark.mjs'; import { TRIMMABLE_PADDING_REGEX } from '../constants.mjs'; /** diff --git a/packages/core/src/generators/llms-txt/README.md b/packages/react/src/llms-txt/README.md similarity index 100% rename from packages/core/src/generators/llms-txt/README.md rename to packages/react/src/llms-txt/README.md diff --git a/packages/core/src/generators/llms-txt/generate.mjs b/packages/react/src/llms-txt/generate.mjs similarity index 84% rename from packages/core/src/generators/llms-txt/generate.mjs rename to packages/react/src/llms-txt/generate.mjs index 0610b73c..730cbcdc 100644 --- a/packages/core/src/generators/llms-txt/generate.mjs +++ b/packages/react/src/llms-txt/generate.mjs @@ -3,9 +3,10 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { writeFile } from '@node-core/doc-kit/utils/file.mjs'; + import { buildApiDocLink } from './utils/buildApiDocLink.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { writeFile } from '../../utils/file.mjs'; /** * Generates a llms.txt file diff --git a/packages/core/src/generators/llms-txt/index.mjs b/packages/react/src/llms-txt/index.mjs similarity index 100% rename from packages/core/src/generators/llms-txt/index.mjs rename to packages/react/src/llms-txt/index.mjs diff --git a/packages/core/src/generators/llms-txt/template.txt b/packages/react/src/llms-txt/template.txt similarity index 100% rename from packages/core/src/generators/llms-txt/template.txt rename to packages/react/src/llms-txt/template.txt diff --git a/packages/core/src/generators/llms-txt/types.d.ts b/packages/react/src/llms-txt/types.d.ts similarity index 66% rename from packages/core/src/generators/llms-txt/types.d.ts rename to packages/react/src/llms-txt/types.d.ts index 85c720ed..d84cf4e5 100644 --- a/packages/core/src/generators/llms-txt/types.d.ts +++ b/packages/react/src/llms-txt/types.d.ts @@ -1,4 +1,4 @@ -import { MetadataEntry } from '../metadata/types'; +import { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; export type Generator = GeneratorMetadata< { diff --git a/packages/core/src/generators/llms-txt/utils/__tests__/buildApiDocLink.test.mjs b/packages/react/src/llms-txt/utils/__tests__/buildApiDocLink.test.mjs similarity index 100% rename from packages/core/src/generators/llms-txt/utils/__tests__/buildApiDocLink.test.mjs rename to packages/react/src/llms-txt/utils/__tests__/buildApiDocLink.test.mjs diff --git a/packages/core/src/generators/llms-txt/utils/buildApiDocLink.mjs b/packages/react/src/llms-txt/utils/buildApiDocLink.mjs similarity index 70% rename from packages/core/src/generators/llms-txt/utils/buildApiDocLink.mjs rename to packages/react/src/llms-txt/utils/buildApiDocLink.mjs index 271249d0..e061d513 100644 --- a/packages/core/src/generators/llms-txt/utils/buildApiDocLink.mjs +++ b/packages/react/src/llms-txt/utils/buildApiDocLink.mjs @@ -1,12 +1,12 @@ -import { populate } from '../../../utils/configuration/templates.mjs'; -import { transformNodeToString } from '../../../utils/unist.mjs'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; +import { transformNodeToString } from '@node-core/doc-kit/utils/unist.mjs'; /** * Retrieves the description of a given API doc entry. It first checks whether * the entry has a llm_description property. If not, it extracts the first * paragraph from the entry's content. * - * @param {import('../../metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry * @returns {string} */ export const getEntryDescription = entry => { @@ -32,8 +32,8 @@ export const getEntryDescription = entry => { /** * Builds a markdown link for an API doc entry * - * @param {import('../../metadata/types').MetadataEntry} entry - * @param {import('../../../utils/configuration/types').Configuration['llms-txt']} + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/utils/configuration/types').Configuration['llms-txt']} * @returns {string} */ export const buildApiDocLink = (entry, config) => { diff --git a/packages/core/src/generators/orama-db/README.md b/packages/react/src/orama-db/README.md similarity index 100% rename from packages/core/src/generators/orama-db/README.md rename to packages/react/src/orama-db/README.md diff --git a/packages/core/src/generators/orama-db/constants.mjs b/packages/react/src/orama-db/constants.mjs similarity index 100% rename from packages/core/src/generators/orama-db/constants.mjs rename to packages/react/src/orama-db/constants.mjs diff --git a/packages/core/src/generators/orama-db/generate.mjs b/packages/react/src/orama-db/generate.mjs similarity index 83% rename from packages/core/src/generators/orama-db/generate.mjs rename to packages/react/src/orama-db/generate.mjs index e8ec639d..a7f1b663 100644 --- a/packages/core/src/generators/orama-db/generate.mjs +++ b/packages/react/src/orama-db/generate.mjs @@ -2,14 +2,14 @@ import { join } from 'node:path'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { writeFile } from '@node-core/doc-kit/utils/file.mjs'; +import { groupNodesByModule } from '@node-core/doc-kit/utils/generators.mjs'; +import { transformNodeToString } from '@node-core/doc-kit/utils/unist.mjs'; import { create, save, insertMultiple } from '@orama/orama'; import { SCHEMA } from './constants.mjs'; import { buildHierarchicalTitle } from './utils/title.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { writeFile } from '../../utils/file.mjs'; -import { groupNodesByModule } from '../../utils/generators.mjs'; -import { transformNodeToString } from '../../utils/unist.mjs'; /** * Generates the Orama database. diff --git a/packages/core/src/generators/orama-db/index.mjs b/packages/react/src/orama-db/index.mjs similarity index 100% rename from packages/core/src/generators/orama-db/index.mjs rename to packages/react/src/orama-db/index.mjs diff --git a/packages/core/src/generators/orama-db/types.d.ts b/packages/react/src/orama-db/types.d.ts similarity index 87% rename from packages/core/src/generators/orama-db/types.d.ts rename to packages/react/src/orama-db/types.d.ts index 8c8c14db..6f6fbca7 100644 --- a/packages/core/src/generators/orama-db/types.d.ts +++ b/packages/react/src/orama-db/types.d.ts @@ -1,5 +1,5 @@ import type { Orama, RawData } from '@orama/orama'; -import type { MetadataEntry } from '../metadata/types'; +import type { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; /** * Schema for the Orama database entry diff --git a/packages/core/src/generators/orama-db/utils/__tests__/title.test.mjs b/packages/react/src/orama-db/utils/__tests__/title.test.mjs similarity index 100% rename from packages/core/src/generators/orama-db/utils/__tests__/title.test.mjs rename to packages/react/src/orama-db/utils/__tests__/title.test.mjs diff --git a/packages/core/src/generators/orama-db/utils/title.mjs b/packages/react/src/orama-db/utils/title.mjs similarity index 100% rename from packages/core/src/generators/orama-db/utils/title.mjs rename to packages/react/src/orama-db/utils/title.mjs diff --git a/packages/core/src/generators/sitemap/README.md b/packages/react/src/sitemap/README.md similarity index 100% rename from packages/core/src/generators/sitemap/README.md rename to packages/react/src/sitemap/README.md diff --git a/packages/core/src/generators/sitemap/entry-template.xml b/packages/react/src/sitemap/entry-template.xml similarity index 100% rename from packages/core/src/generators/sitemap/entry-template.xml rename to packages/react/src/sitemap/entry-template.xml diff --git a/packages/core/src/generators/sitemap/generate.mjs b/packages/react/src/sitemap/generate.mjs similarity index 86% rename from packages/core/src/generators/sitemap/generate.mjs rename to packages/react/src/sitemap/generate.mjs index 9ec9786a..808c0ca0 100644 --- a/packages/core/src/generators/sitemap/generate.mjs +++ b/packages/react/src/sitemap/generate.mjs @@ -3,10 +3,11 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; +import { writeFile } from '@node-core/doc-kit/utils/file.mjs'; + import { createPageSitemapEntry } from './utils/createPageSitemapEntry.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { populate } from '../../utils/configuration/templates.mjs'; -import { writeFile } from '../../utils/file.mjs'; /** * Generates a sitemap.xml file diff --git a/packages/core/src/generators/sitemap/index.mjs b/packages/react/src/sitemap/index.mjs similarity index 100% rename from packages/core/src/generators/sitemap/index.mjs rename to packages/react/src/sitemap/index.mjs diff --git a/packages/core/src/generators/sitemap/template.xml b/packages/react/src/sitemap/template.xml similarity index 100% rename from packages/core/src/generators/sitemap/template.xml rename to packages/react/src/sitemap/template.xml diff --git a/packages/core/src/generators/sitemap/types.d.ts b/packages/react/src/sitemap/types.d.ts similarity index 81% rename from packages/core/src/generators/sitemap/types.d.ts rename to packages/react/src/sitemap/types.d.ts index abad2fd1..569fec49 100644 --- a/packages/core/src/generators/sitemap/types.d.ts +++ b/packages/react/src/sitemap/types.d.ts @@ -1,4 +1,4 @@ -import type { MetadataEntry } from '../metadata/types'; +import type { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; export interface SitemapEntry { loc: string; diff --git a/packages/react/src/sitemap/utils/createPageSitemapEntry.mjs b/packages/react/src/sitemap/utils/createPageSitemapEntry.mjs new file mode 100644 index 00000000..eabfa69b --- /dev/null +++ b/packages/react/src/sitemap/utils/createPageSitemapEntry.mjs @@ -0,0 +1,19 @@ +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; + +/** + * Builds an API doc sitemap url. + * + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/utils/configuration/types').Configuration['sitemap']} config + * @param {string} lastmod - Last-modified date as `YYYY-MM-DD` + * @returns {import('../types').SitemapEntry} + */ +export const createPageSitemapEntry = (entry, config, lastmod) => ({ + loc: populate(config.pageURL, { + ...config, + path: entry.path, + }), + lastmod, + changefreq: 'weekly', + priority: '0.8', +}); diff --git a/scripts/build-docs-content.mjs b/scripts/build-docs-content.mjs index 07442da1..836a5e0c 100644 --- a/scripts/build-docs-content.mjs +++ b/scripts/build-docs-content.mjs @@ -6,11 +6,11 @@ // www/pages/*.md authored narrative pages, copied verbatim // docs/*.md the existing reference docs // packages/core/src/generators/*/README.md -// per-generator config reference, written to +// packages/*/src/*/README.md per-generator config reference, written to // `generators/.md` // // `www/content/` is a build artifact and is gitignored. Run this before -// invoking the `web` generator against it. +// invoking the `html` generator against it. import { glob, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; import { basename, dirname, join } from 'node:path'; @@ -25,6 +25,10 @@ const SOURCES = [ pattern: 'packages/core/src/generators/*/README.md', rename: file => `generators/${basename(dirname(file))}.md`, }, + { + pattern: 'packages/*/src/*/README.md', + rename: file => `generators/${basename(dirname(file))}.md`, + }, ]; /** diff --git a/scripts/vercel-build.sh b/scripts/vercel-build.sh index a9f5fd9a..5940b71f 100755 --- a/scripts/vercel-build.sh +++ b/scripts/vercel-build.sh @@ -9,7 +9,7 @@ node packages/core/bin/cli.mjs generate \ -t orama-db \ -t legacy-json \ -t llms-txt \ - -t web \ + -t html \ -i "./node/doc/api/*.md" \ --ignore "./node/doc/api/quic.md" \ -o "./out" \ diff --git a/www/doc-kit.config.mjs b/www/doc-kit.config.mjs index 017c440a..1dfb8cd6 100644 --- a/www/doc-kit.config.mjs +++ b/www/doc-kit.config.mjs @@ -28,7 +28,7 @@ const DESCRIPTION = /** @type {import('../packages/core/src/utils/configuration/types').Configuration} */ export default { - target: ['orama-db', 'legacy-json', 'web'], + target: ['orama-db', 'legacy-json', 'html'], global: { // `www/content/` is assembled by `scripts/build-docs-content.mjs`. @@ -55,7 +55,7 @@ export default { generateIndexPage: false, }, - web: { + html: { project: 'doc-kit', title: '{project} documentation', diff --git a/www/pages/getting-started.md b/www/pages/getting-started.md index a687ebca..8c8e3b64 100644 --- a/www/pages/getting-started.md +++ b/www/pages/getting-started.md @@ -48,12 +48,12 @@ that's fully customizable via [a configuration file][]. ## Render the modern site -The `web` target produces the server-rendered, client-hydrated site that +The `html` target produces the server-rendered, client-hydrated site that [nodejs.org](https://nodejs.org) uses — and that this site is built with: ```bash npx doc-kit generate \ - -t web \ + -t html \ -i "docs/*.md" \ -o out ``` @@ -61,12 +61,12 @@ npx doc-kit generate \ Pair it with `orama-db` to add search: ```bash -npx doc-kit generate -t web -t orama-db -i "docs/*.md" -o out +npx doc-kit generate -t html -t orama-db -i "docs/*.md" -o out ``` ## Preview it locally -The `web` output uses import maps and client-side hydration, so it must be +The `html` output uses import maps and client-side hydration, so it must be served over HTTP — opening the files directly with `file://` will not work. Any static server will do the trick; for example: @@ -78,9 +78,9 @@ Then open the printed URL (usually ). The `legacy-html-all` output from earlier has no such requirement — `out/all.html` opens straight from disk. -## Customize the `web` generator output +## Customize the `html` generator output -The power of the `web` generator comes from its customization hooks. Let's walk +The power of the `html` generator comes from its customization hooks. Let's walk through a couple quick changes. Create a `doc-kit.config.mjs` file at the root of the project. @@ -90,7 +90,7 @@ import { join } from 'node:path'; /** @type {import('@node-core/doc-kit/src/utils/configuration/types').Configuration} */ export default { - web: { + html: { project: 'My Project', // Project name used in page titles and the version selector remoteConfigUrl: '', // Suppress the Node.js default that sets the top banner based on Node.js news. head: { @@ -130,7 +130,7 @@ experience, preserving core functionality. - Explore [Configuration](./configuration.html) — consider moving your `-t` target flags into a `doc-kit.config.mjs` file. -- [Further customize the `web` generator](./generators/web.html) — give it a +- [Further customize the `html` generator](./generators/html.html) — give it a custom sidenav or footer. - [Read the full input specification](./specification.html) — the full Markdown contract. diff --git a/www/pages/index.md b/www/pages/index.md index 9a193e54..7ee686d5 100644 --- a/www/pages/index.md +++ b/www/pages/index.md @@ -4,7 +4,7 @@ documentation. It's the documentation toolchain behind the Node.js API reference, found at https://nodejs.org/docs/latest/api/. This site is built by `doc-kit`, from its own repository. The pages you are reading were produced by -the `web` generator. +the `html` generator. > 📣 `doc-kit` is in beta. We'd like feedback within the > [issue log](https://github.com/nodejs/doc-kit/issues) or by visiting the @@ -24,7 +24,7 @@ Raw Markdown Files │ [metadata] extract structured API metadata │ - ├─► [jsx-ast] ─► [web] server-rendered site + ├─► [jsx-ast] ─► [html] server-rendered site ├─► [legacy-html] ─► …-all classic HTML ├─► [legacy-json] ─► …-all JSON ├─► [json-simple] simplified JSON @@ -39,7 +39,7 @@ Only some of these are things you ask for by name. `ast`, `metadata`, and them, and they are not valid `-t` targets. Everything in the fan-out below `metadata` is a target you can pass to `-t`, and passing several at once reuses the one shared parse rather than repeating it. The full list is in the -[generators reference](./generators/web.html). +[generators reference](./generators/html.html). ## The input contract @@ -65,7 +65,7 @@ See [the specification](./specification.html) for the full input format. A couple places `doc-kit` is already in use. Feel free to PR yours. - - `legacy-json` -- - `web` -- - `web` -- - `web` -- - `web` +- - `html` +- - `html` +- - `html` +- - `html` From 747189189b9d8a430a013311fdcfb84d29326e93 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Thu, 30 Jul 2026 14:21:39 -0700 Subject: [PATCH 2/7] refactor(legacy): extract @nodejs/doc-kit-generator-legacy package --- .c8rc.json | 2 +- .changeset/legacy-kitten-package.md | 11 ++++ eslint.config.mjs | 2 +- package-lock.json | 18 +++++++ packages/core/package.json | 8 +-- packages/core/src/generators/index.mjs | 8 +-- .../src/utils/__tests__/generators.test.mjs | 44 --------------- packages/core/src/utils/generators.mjs | 52 ------------------ .../core/src/utils/signature/parseList.mjs | 2 +- packages/legacy/package.json | 32 +++++++++++ .../src}/legacy-html-all/README.md | 0 .../src}/legacy-html-all/generate.mjs | 7 +-- .../src}/legacy-html-all/index.mjs | 2 +- .../src}/legacy-html-all/types.d.ts | 0 .../src}/legacy-html/README.md | 0 .../src}/legacy-html/assets/api.js | 0 .../src}/legacy-html/assets/js-flavor-cjs.svg | 0 .../src}/legacy-html/assets/js-flavor-esm.svg | 0 .../src}/legacy-html/assets/style.css | 0 .../src}/legacy-html/generate.mjs | 11 ++-- .../src}/legacy-html/index.mjs | 3 +- .../src}/legacy-html/template.html | 0 .../src}/legacy-html/types.d.ts | 2 +- .../utils/__tests__/buildContent.test.mjs | 3 +- .../utils/__tests__/slugger.test.mjs | 0 .../src}/legacy-html/utils/buildContent.mjs | 26 ++++----- .../src}/legacy-html/utils/buildDropdowns.mjs | 8 +-- .../legacy-html/utils/buildExtraContent.mjs | 6 +-- .../utils/replaceTemplateValues.mjs | 5 +- .../src}/legacy-html/utils/slugger.mjs | 2 +- .../legacy-html/utils/tableOfContents.mjs | 8 +-- .../src}/legacy-json-all/README.md | 0 .../src}/legacy-json-all/generate.mjs | 5 +- .../src}/legacy-json-all/index.mjs | 2 +- .../src}/legacy-json-all/types.d.ts | 0 .../src}/legacy-json/README.md | 0 .../src}/legacy-json/constants.mjs | 0 .../src}/legacy-json/generate.mjs | 8 +-- .../src}/legacy-json/index.mjs | 0 .../src}/legacy-json/types.d.ts | 4 +- .../utils/__tests__/buildHierarchy.test.mjs | 0 .../utils/__tests__/buildSection.test.mjs | 0 .../src}/legacy-json/utils/buildHierarchy.mjs | 4 +- .../src}/legacy-json/utils/buildSection.mjs | 23 ++++---- .../src/utils/__tests__/legacyToJSON.test.mjs | 47 ++++++++++++++++ packages/legacy/src/utils/legacyToJSON.mjs | 53 +++++++++++++++++++ 46 files changed, 241 insertions(+), 167 deletions(-) create mode 100644 .changeset/legacy-kitten-package.md create mode 100644 packages/legacy/package.json rename packages/{core/src/generators => legacy/src}/legacy-html-all/README.md (100%) rename packages/{core/src/generators => legacy/src}/legacy-html-all/generate.mjs (90%) rename packages/{core/src/generators => legacy/src}/legacy-html-all/index.mjs (93%) rename packages/{core/src/generators => legacy/src}/legacy-html-all/types.d.ts (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/README.md (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/assets/api.js (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/assets/js-flavor-cjs.svg (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/assets/js-flavor-esm.svg (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/assets/style.css (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/generate.mjs (90%) rename packages/{core/src/generators => legacy/src}/legacy-html/index.mjs (92%) rename packages/{core/src/generators => legacy/src}/legacy-html/template.html (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/types.d.ts (86%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/__tests__/buildContent.test.mjs (93%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/__tests__/slugger.test.mjs (100%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/buildContent.mjs (88%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/buildDropdowns.mjs (90%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/buildExtraContent.mjs (78%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/replaceTemplateValues.mjs (88%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/slugger.mjs (90%) rename packages/{core/src/generators => legacy/src}/legacy-html/utils/tableOfContents.mjs (80%) rename packages/{core/src/generators => legacy/src}/legacy-json-all/README.md (100%) rename packages/{core/src/generators => legacy/src}/legacy-json-all/generate.mjs (93%) rename packages/{core/src/generators => legacy/src}/legacy-json-all/index.mjs (88%) rename packages/{core/src/generators => legacy/src}/legacy-json-all/types.d.ts (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/README.md (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/constants.mjs (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/generate.mjs (86%) rename packages/{core/src/generators => legacy/src}/legacy-json/index.mjs (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/types.d.ts (96%) rename packages/{core/src/generators => legacy/src}/legacy-json/utils/__tests__/buildHierarchy.test.mjs (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/utils/__tests__/buildSection.test.mjs (100%) rename packages/{core/src/generators => legacy/src}/legacy-json/utils/buildHierarchy.mjs (91%) rename packages/{core/src/generators => legacy/src}/legacy-json/utils/buildSection.mjs (83%) create mode 100644 packages/legacy/src/utils/__tests__/legacyToJSON.test.mjs create mode 100644 packages/legacy/src/utils/legacyToJSON.mjs diff --git a/.c8rc.json b/.c8rc.json index fbc2a9e6..49031d7d 100644 --- a/.c8rc.json +++ b/.c8rc.json @@ -3,7 +3,7 @@ "exclude": [ "eslint.config.mjs", "**/fixtures", - "packages/core/src/generators/legacy-html/assets", + "packages/legacy/src/legacy-html/assets", "packages/react/src/html/ui", "**/*.d.ts" ] diff --git a/.changeset/legacy-kitten-package.md b/.changeset/legacy-kitten-package.md new file mode 100644 index 00000000..55d49a31 --- /dev/null +++ b/.changeset/legacy-kitten-package.md @@ -0,0 +1,11 @@ +--- +'@nodejs/doc-kit-generator-legacy': major +'@node-core/doc-kit': major +--- + +The legacy-format generators (`legacy-html`, `legacy-html-all`, +`legacy-json`, and `legacy-json-all`) now live in the new +`@nodejs/doc-kit-generator-legacy` package and are loaded via import specifiers such +as `@nodejs/doc-kit-generator-legacy/legacy-html`. The corresponding +`@node-core/doc-kit/*` package exports have been removed. The CLI shorthand +names are unchanged. diff --git a/eslint.config.mjs b/eslint.config.mjs index 9e92946a..f8dceaa5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -95,7 +95,7 @@ export default defineConfig([ }, { files: [ - 'packages/core/src/generators/legacy-html/assets/*.js', + 'packages/legacy/src/legacy-html/assets/*.js', 'packages/react/src/html/ui/**/*', ], languageOptions: { diff --git a/package-lock.json b/package-lock.json index 541a633b..71e043ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1387,6 +1387,10 @@ "node": ">=20" } }, + "node_modules/@nodejs/doc-kit-generator-legacy": { + "resolved": "packages/legacy", + "link": true + }, "node_modules/@nodejs/doc-kit-generator-react": { "resolved": "packages/react", "link": true @@ -11244,14 +11248,28 @@ "doc-kit": "bin/cli.mjs" }, "peerDependencies": { + "@nodejs/doc-kit-generator-legacy": "^0.0.0", "@nodejs/doc-kit-generator-react": "^0.0.0" }, "peerDependenciesMeta": { + "@nodejs/doc-kit-generator-legacy": { + "optional": true + }, "@nodejs/doc-kit-generator-react": { "optional": true } } }, + "packages/legacy": { + "name": "@nodejs/doc-kit-generator-legacy", + "version": "0.0.0", + "dependencies": { + "@node-core/doc-kit": "^1.4.3", + "hastscript": "^9.0.1", + "unist-builder": "^4.0.0", + "unist-util-visit": "^5.1.0" + } + }, "packages/react": { "name": "@nodejs/doc-kit-generator-react", "version": "0.0.0", diff --git a/packages/core/package.json b/packages/core/package.json index 96ffaf80..f1a472dc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -23,10 +23,6 @@ "./ast": "./src/generators/ast/index.mjs", "./ast-js": "./src/generators/ast-js/index.mjs", "./json-simple": "./src/generators/json-simple/index.mjs", - "./legacy-html": "./src/generators/legacy-html/index.mjs", - "./legacy-html-all": "./src/generators/legacy-html-all/index.mjs", - "./legacy-json": "./src/generators/legacy-json/index.mjs", - "./legacy-json-all": "./src/generators/legacy-json-all/index.mjs", "./man-page": "./src/generators/man-page/index.mjs", "./metadata": "./src/generators/metadata/index.mjs", "./package.json": "./package.json", @@ -80,9 +76,13 @@ "yaml": "^2.9.0" }, "peerDependencies": { + "@nodejs/doc-kit-generator-legacy": "^0.0.0", "@nodejs/doc-kit-generator-react": "^0.0.0" }, "peerDependenciesMeta": { + "@nodejs/doc-kit-generator-legacy": { + "optional": true + }, "@nodejs/doc-kit-generator-react": { "optional": true } diff --git a/packages/core/src/generators/index.mjs b/packages/core/src/generators/index.mjs index f356169f..5e421403 100644 --- a/packages/core/src/generators/index.mjs +++ b/packages/core/src/generators/index.mjs @@ -11,11 +11,11 @@ */ export const publicGenerators = { 'json-simple': '@node-core/doc-kit/json-simple', - 'legacy-html': '@node-core/doc-kit/legacy-html', - 'legacy-html-all': '@node-core/doc-kit/legacy-html-all', + 'legacy-html': '@nodejs/doc-kit-generator-legacy/legacy-html', + 'legacy-html-all': '@nodejs/doc-kit-generator-legacy/legacy-html-all', 'man-page': '@node-core/doc-kit/man-page', - 'legacy-json': '@node-core/doc-kit/legacy-json', - 'legacy-json-all': '@node-core/doc-kit/legacy-json-all', + 'legacy-json': '@nodejs/doc-kit-generator-legacy/legacy-json', + 'legacy-json-all': '@nodejs/doc-kit-generator-legacy/legacy-json-all', 'addon-verify': '@node-core/doc-kit/addon-verify', 'api-links': '@node-core/doc-kit/api-links', 'orama-db': '@nodejs/doc-kit-generator-react/orama-db', diff --git a/packages/core/src/utils/__tests__/generators.test.mjs b/packages/core/src/utils/__tests__/generators.test.mjs index cd0c48eb..d6ef025b 100644 --- a/packages/core/src/utils/__tests__/generators.test.mjs +++ b/packages/core/src/utils/__tests__/generators.test.mjs @@ -6,7 +6,6 @@ import { getVersionFromSemVer, coerceSemVer, getCompatibleVersions, - legacyToJSON, } from '../generators.mjs'; describe('groupNodesByModule', () => { @@ -80,46 +79,3 @@ describe('getCompatibleVersions', () => { assert.equal(result.length, 2); }); }); - -describe('legacyToJSON', () => { - const base = { - type: 'module', - source: 'lib/fs.js', - introduced_in: 'v0.10.0', - meta: {}, - stability: 2, - stabilityText: 'Stable', - classes: [], - methods: ['readFile'], - properties: [], - miscs: [], - modules: ['fs'], - globals: [], - }; - - it('serialises a normal section with all keys', () => { - const result = JSON.parse(legacyToJSON({ ...base, api: 'fs' })); - assert.ok('type' in result); - assert.ok('methods' in result); - assert.ok('modules' in result); - }); - - it('omits modules key for index sections', () => { - const result = JSON.parse(legacyToJSON({ ...base, api: 'index' })); - assert.ok(!('modules' in result)); - }); - - it('uses all.json key order when api is null', () => { - const result = JSON.parse(legacyToJSON({ ...base, api: null })); - // all.json only includes miscs, modules, classes, globals, methods - assert.ok('miscs' in result); - assert.ok('modules' in result); - assert.ok(!('type' in result)); - assert.ok(!('source' in result)); - }); - - it('passes extra args to JSON.stringify (e.g. indentation)', () => { - const result = legacyToJSON({ ...base, api: 'fs' }, null, 2); - assert.ok(result.includes('\n')); - }); -}); diff --git a/packages/core/src/utils/generators.mjs b/packages/core/src/utils/generators.mjs index 48430853..ea2d97df 100644 --- a/packages/core/src/utils/generators.mjs +++ b/packages/core/src/utils/generators.mjs @@ -69,55 +69,3 @@ export const getCompatibleVersions = (introduced, releases) => { */ export const leftHandAssign = (target, source) => Object.keys(source).forEach(k => k in target || (target[k] = source[k])); - -/** - * Transforms an object to JSON output consistent with the JSON version. - * @param {import('../generators/legacy-json/types').Section} section - The source object - * @param {any[]} args - * @returns {string} - The JSON output - */ -export const legacyToJSON = ( - { - api, - type, - source, - introduced_in, - meta, - stability, - stabilityText, - classes, - methods, - properties, - miscs, - modules, - globals, - }, - ...args -) => - JSON.stringify( - api == null - ? { - // all.json special order - miscs, - modules, - classes, - globals, - methods, - } - : { - type, - source, - introduced_in, - meta, - stability, - stabilityText, - classes, - methods, - properties, - miscs, - // index.json shouldn't have a `modules` key: - ...(api === 'index' ? undefined : { modules }), - globals, - }, - ...args - ); diff --git a/packages/core/src/utils/signature/parseList.mjs b/packages/core/src/utils/signature/parseList.mjs index 9839b594..a9ca2cad 100644 --- a/packages/core/src/utils/signature/parseList.mjs +++ b/packages/core/src/utils/signature/parseList.mjs @@ -85,7 +85,7 @@ export function parseListItem(child) { /** * Parses a list of nodes and updates the corresponding section object with the extracted information. * Handles different section types such as methods, properties, and events differently. - * @param {import('../../generators/legacy-json/types').Section} section + * @param {{ [key: string]: unknown }} section - The section object to populate with the parsed values * @param {import('@types/mdast').RootContent[]} nodes */ export function parseList(section, nodes) { diff --git a/packages/legacy/package.json b/packages/legacy/package.json new file mode 100644 index 00000000..73f10d76 --- /dev/null +++ b/packages/legacy/package.json @@ -0,0 +1,32 @@ +{ + "name": "@nodejs/doc-kit-generator-legacy", + "type": "module", + "version": "0.0.0", + "description": "Legacy-format generators for @node-core/doc-kit: legacy-html, legacy-html-all, legacy-json, and legacy-json-all", + "repository": { + "type": "git", + "url": "git+https://github.com/nodejs/doc-kit.git", + "directory": "packages/legacy" + }, + "exports": { + "./legacy-html": "./src/legacy-html/index.mjs", + "./legacy-html-all": "./src/legacy-html-all/index.mjs", + "./legacy-json": "./src/legacy-json/index.mjs", + "./legacy-json-all": "./src/legacy-json-all/index.mjs", + "./package.json": "./package.json" + }, + "files": [ + "src", + "!src/**/*.test.mjs", + "!src/**/__tests__", + "CHANGELOG.md", + "LICENSE", + "README.md" + ], + "dependencies": { + "@node-core/doc-kit": "^1.4.3", + "hastscript": "^9.0.1", + "unist-builder": "^4.0.0", + "unist-util-visit": "^5.1.0" + } +} diff --git a/packages/core/src/generators/legacy-html-all/README.md b/packages/legacy/src/legacy-html-all/README.md similarity index 100% rename from packages/core/src/generators/legacy-html-all/README.md rename to packages/legacy/src/legacy-html-all/README.md diff --git a/packages/core/src/generators/legacy-html-all/generate.mjs b/packages/legacy/src/legacy-html-all/generate.mjs similarity index 90% rename from packages/core/src/generators/legacy-html-all/generate.mjs rename to packages/legacy/src/legacy-html-all/generate.mjs index 1aa7bfdf..348fa23d 100644 --- a/packages/core/src/generators/legacy-html-all/generate.mjs +++ b/packages/legacy/src/legacy-html-all/generate.mjs @@ -3,9 +3,10 @@ import { readFile, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; -import getConfig from '../../utils/configuration/index.mjs'; -import { minifyHTML } from '../../utils/html-minifier.mjs'; -import { getRemarkRehype as remark } from '../../utils/remark.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { minifyHTML } from '@node-core/doc-kit/utils/html-minifier.mjs'; +import { getRemarkRehype as remark } from '@node-core/doc-kit/utils/remark.mjs'; + import { replaceTemplateValues } from '../legacy-html/utils/replaceTemplateValues.mjs'; import tableOfContents from '../legacy-html/utils/tableOfContents.mjs'; diff --git a/packages/core/src/generators/legacy-html-all/index.mjs b/packages/legacy/src/legacy-html-all/index.mjs similarity index 93% rename from packages/core/src/generators/legacy-html-all/index.mjs rename to packages/legacy/src/legacy-html-all/index.mjs index 4d6f1d35..27bb3b85 100644 --- a/packages/core/src/generators/legacy-html-all/index.mjs +++ b/packages/legacy/src/legacy-html-all/index.mjs @@ -18,7 +18,7 @@ export default { description: 'Generates the `all.html` file from the `legacy-html` generator, which includes all the modules in one single file', - dependsOn: '@node-core/doc-kit/legacy-html', + dependsOn: '@nodejs/doc-kit-generator-legacy/legacy-html', defaultConfiguration: { templatePath: legacyHtml.defaultConfiguration.templatePath, diff --git a/packages/core/src/generators/legacy-html-all/types.d.ts b/packages/legacy/src/legacy-html-all/types.d.ts similarity index 100% rename from packages/core/src/generators/legacy-html-all/types.d.ts rename to packages/legacy/src/legacy-html-all/types.d.ts diff --git a/packages/core/src/generators/legacy-html/README.md b/packages/legacy/src/legacy-html/README.md similarity index 100% rename from packages/core/src/generators/legacy-html/README.md rename to packages/legacy/src/legacy-html/README.md diff --git a/packages/core/src/generators/legacy-html/assets/api.js b/packages/legacy/src/legacy-html/assets/api.js similarity index 100% rename from packages/core/src/generators/legacy-html/assets/api.js rename to packages/legacy/src/legacy-html/assets/api.js diff --git a/packages/core/src/generators/legacy-html/assets/js-flavor-cjs.svg b/packages/legacy/src/legacy-html/assets/js-flavor-cjs.svg similarity index 100% rename from packages/core/src/generators/legacy-html/assets/js-flavor-cjs.svg rename to packages/legacy/src/legacy-html/assets/js-flavor-cjs.svg diff --git a/packages/core/src/generators/legacy-html/assets/js-flavor-esm.svg b/packages/legacy/src/legacy-html/assets/js-flavor-esm.svg similarity index 100% rename from packages/core/src/generators/legacy-html/assets/js-flavor-esm.svg rename to packages/legacy/src/legacy-html/assets/js-flavor-esm.svg diff --git a/packages/core/src/generators/legacy-html/assets/style.css b/packages/legacy/src/legacy-html/assets/style.css similarity index 100% rename from packages/core/src/generators/legacy-html/assets/style.css rename to packages/legacy/src/legacy-html/assets/style.css diff --git a/packages/core/src/generators/legacy-html/generate.mjs b/packages/legacy/src/legacy-html/generate.mjs similarity index 90% rename from packages/core/src/generators/legacy-html/generate.mjs rename to packages/legacy/src/legacy-html/generate.mjs index a4d5de62..756641a6 100644 --- a/packages/core/src/generators/legacy-html/generate.mjs +++ b/packages/legacy/src/legacy-html/generate.mjs @@ -3,14 +3,15 @@ import { readFile, cp } from 'node:fs/promises'; import { basename, join } from 'node:path'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { writeFile } from '@node-core/doc-kit/utils/file.mjs'; +import { groupNodesByModule } from '@node-core/doc-kit/utils/generators.mjs'; +import { minifyHTML } from '@node-core/doc-kit/utils/html-minifier.mjs'; +import { getRemarkRehypeWithShiki as remark } from '@node-core/doc-kit/utils/remark.mjs'; + import buildContent from './utils/buildContent.mjs'; import { replaceTemplateValues } from './utils/replaceTemplateValues.mjs'; import tableOfContents from './utils/tableOfContents.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { writeFile } from '../../utils/file.mjs'; -import { groupNodesByModule } from '../../utils/generators.mjs'; -import { minifyHTML } from '../../utils/html-minifier.mjs'; -import { getRemarkRehypeWithShiki as remark } from '../../utils/remark.mjs'; /** * Creates a heading object with the given name. diff --git a/packages/core/src/generators/legacy-html/index.mjs b/packages/legacy/src/legacy-html/index.mjs similarity index 92% rename from packages/core/src/generators/legacy-html/index.mjs rename to packages/legacy/src/legacy-html/index.mjs index 68c4ea9f..fd9ecbb1 100644 --- a/packages/core/src/generators/legacy-html/index.mjs +++ b/packages/legacy/src/legacy-html/index.mjs @@ -2,8 +2,9 @@ import { join } from 'node:path'; +import { GITHUB_EDIT_URL } from '@node-core/doc-kit/utils/configuration/templates.mjs'; + import { generate, processChunk } from './generate.mjs'; -import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs'; /** * diff --git a/packages/core/src/generators/legacy-html/template.html b/packages/legacy/src/legacy-html/template.html similarity index 100% rename from packages/core/src/generators/legacy-html/template.html rename to packages/legacy/src/legacy-html/template.html diff --git a/packages/core/src/generators/legacy-html/types.d.ts b/packages/legacy/src/legacy-html/types.d.ts similarity index 86% rename from packages/core/src/generators/legacy-html/types.d.ts rename to packages/legacy/src/legacy-html/types.d.ts index 19b2cf7d..d7c5c8fe 100644 --- a/packages/core/src/generators/legacy-html/types.d.ts +++ b/packages/legacy/src/legacy-html/types.d.ts @@ -1,4 +1,4 @@ -import type { MetadataEntry } from '../metadata/types'; +import type { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; export interface TemplateValues { api: string; diff --git a/packages/core/src/generators/legacy-html/utils/__tests__/buildContent.test.mjs b/packages/legacy/src/legacy-html/utils/__tests__/buildContent.test.mjs similarity index 93% rename from packages/core/src/generators/legacy-html/utils/__tests__/buildContent.test.mjs rename to packages/legacy/src/legacy-html/utils/__tests__/buildContent.test.mjs index ac40da98..1e21095d 100644 --- a/packages/core/src/generators/legacy-html/utils/__tests__/buildContent.test.mjs +++ b/packages/legacy/src/legacy-html/utils/__tests__/buildContent.test.mjs @@ -3,7 +3,8 @@ import assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; -import { setConfig } from '../../../../utils/configuration/index.mjs'; +import { setConfig } from '@node-core/doc-kit/utils/configuration/index.mjs'; + import buildContent from '../buildContent.mjs'; const createEntry = slug => { diff --git a/packages/core/src/generators/legacy-html/utils/__tests__/slugger.test.mjs b/packages/legacy/src/legacy-html/utils/__tests__/slugger.test.mjs similarity index 100% rename from packages/core/src/generators/legacy-html/utils/__tests__/slugger.test.mjs rename to packages/legacy/src/legacy-html/utils/__tests__/slugger.test.mjs diff --git a/packages/core/src/generators/legacy-html/utils/buildContent.mjs b/packages/legacy/src/legacy-html/utils/buildContent.mjs similarity index 88% rename from packages/core/src/generators/legacy-html/utils/buildContent.mjs rename to packages/legacy/src/legacy-html/utils/buildContent.mjs index fd643ab8..4cf2e5d7 100644 --- a/packages/core/src/generators/legacy-html/utils/buildContent.mjs +++ b/packages/legacy/src/legacy-html/utils/buildContent.mjs @@ -1,23 +1,23 @@ 'use strict'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { + GITHUB_BLOB_URL, + populate, +} from '@node-core/doc-kit/utils/configuration/templates.mjs'; +import { UNIST } from '@node-core/doc-kit/utils/queries/index.mjs'; +import { getRemarkRehypeWithShiki as remark } from '@node-core/doc-kit/utils/remark.mjs'; import { h as createElement } from 'hastscript'; import { u as createTree } from 'unist-builder'; import { SKIP, visit } from 'unist-util-visit'; import buildExtraContent from './buildExtraContent.mjs'; import { createLegacySlugger } from './slugger.mjs'; -import getConfig from '../../../utils/configuration/index.mjs'; -import { - GITHUB_BLOB_URL, - populate, -} from '../../../utils/configuration/templates.mjs'; -import { UNIST } from '../../../utils/queries/index.mjs'; -import { getRemarkRehypeWithShiki as remark } from '../../../utils/remark.mjs'; /** * Builds a Markdown heading for a given node * - * @param {import('../../metadata/types').HeadingNode} node The node to build the Markdown heading for + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} node The node to build the Markdown heading for * @param {number} index The index of the current node * @param {import('unist').Parent} parent The parent node of the current node * @returns {import('hast').Element} The HTML AST tree of the heading content @@ -54,7 +54,7 @@ const buildHeading = ({ data, children, depth }, index, parent, legacySlug) => { /** * Builds an HTML Stability element * - * @param {import('../../metadata/types').StabilityNode} node The HTML AST tree of the Stability Index content + * @param {import('@node-core/doc-kit/generators/metadata/types').StabilityNode} node The HTML AST tree of the Stability Index content * @param {number} index The index of the current node * @param {import('unist').Parent} parent The parent node of the current node */ @@ -77,7 +77,7 @@ const buildStability = ({ children, data }, index, parent) => { /** * Creates a history table row. * - * @param {import('../../metadata/types').ChangeEntry} change + * @param {import('@node-core/doc-kit/generators/metadata/types').ChangeEntry} change */ const createHistoryTableRow = ({ version: changeVersions, description }) => { const descriptionNode = remark().parse(description); @@ -94,7 +94,7 @@ const createHistoryTableRow = ({ version: changeVersions, description }) => { /** * Builds the Metadata Properties into content * - * @param {import('../../metadata/types').MetadataEntry} node The node to build the properties from + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} node The node to build the properties from * @returns {import('unist').Parent} The HTML AST tree of the properties content */ const buildMetadataElement = node => { @@ -202,8 +202,8 @@ const buildMetadataElement = node => { /** * Builds the whole content of a given node (API module) * - * @param {Array} headNodes The API metadata Nodes that are considered the "head" of each module - * @param {Array} metadataEntries The API metadata Nodes to be transformed into HTML content + * @param {Array} headNodes The API metadata Nodes that are considered the "head" of each module + * @param {Array} metadataEntries The API metadata Nodes to be transformed into HTML content */ export default (headNodes, metadataEntries) => { const getLegacySlug = createLegacySlugger(); diff --git a/packages/core/src/generators/legacy-html/utils/buildDropdowns.mjs b/packages/legacy/src/legacy-html/utils/buildDropdowns.mjs similarity index 90% rename from packages/core/src/generators/legacy-html/utils/buildDropdowns.mjs rename to packages/legacy/src/legacy-html/utils/buildDropdowns.mjs index 7a2c3be8..6e961b23 100644 --- a/packages/core/src/generators/legacy-html/utils/buildDropdowns.mjs +++ b/packages/legacy/src/legacy-html/utils/buildDropdowns.mjs @@ -1,11 +1,11 @@ 'use strict'; -import getConfig from '../../../utils/configuration/index.mjs'; -import { populate } from '../../../utils/configuration/templates.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; import { getCompatibleVersions, getVersionFromSemVer, -} from '../../../utils/generators.mjs'; +} from '@node-core/doc-kit/utils/generators.mjs'; /** * Builds the Dropdown for the current Table of Contents @@ -50,7 +50,7 @@ export const buildNavigation = navigationContents => * * @param {string} path The current API node name * @param {string} added The version the API was added - * @param {Array} versions All available Node.js releases + * @param {Array} versions All available Node.js releases */ export const buildVersions = (path, added, versions) => { const config = getConfig('legacy-html'); diff --git a/packages/core/src/generators/legacy-html/utils/buildExtraContent.mjs b/packages/legacy/src/legacy-html/utils/buildExtraContent.mjs similarity index 78% rename from packages/core/src/generators/legacy-html/utils/buildExtraContent.mjs rename to packages/legacy/src/legacy-html/utils/buildExtraContent.mjs index 6f9ef45f..6a95496d 100644 --- a/packages/core/src/generators/legacy-html/utils/buildExtraContent.mjs +++ b/packages/legacy/src/legacy-html/utils/buildExtraContent.mjs @@ -6,7 +6,7 @@ import { u as createTree } from 'unist-builder'; /** * Generates the Stability Overview table based on the API metadata nodes. * - * @param {Array} headMetadata The API metadata nodes to be used for the Stability Overview + * @param {Array} headMetadata The API metadata nodes to be used for the Stability Overview */ const buildStabilityOverview = headMetadata => { const headNodesWithStability = headMetadata.filter(entry => entry.stability); @@ -46,8 +46,8 @@ const buildStabilityOverview = headMetadata => { /** * Generates extra "special" HTML content based on extra metadata that a node may have. * - * @param {Array} headNodes The API metadata nodes to be used for the Stability Overview - * @param {import('../../metadata/types').MetadataEntry} node The current API metadata node to be transformed into HTML content + * @param {Array} headNodes The API metadata nodes to be used for the Stability Overview + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} node The current API metadata node to be transformed into HTML content * @returns {import('unist').Parent} The HTML AST tree for the extra content */ export default (headNodes, node) => { diff --git a/packages/core/src/generators/legacy-html/utils/replaceTemplateValues.mjs b/packages/legacy/src/legacy-html/utils/replaceTemplateValues.mjs similarity index 88% rename from packages/core/src/generators/legacy-html/utils/replaceTemplateValues.mjs rename to packages/legacy/src/legacy-html/utils/replaceTemplateValues.mjs index baec0754..b206f567 100644 --- a/packages/core/src/generators/legacy-html/utils/replaceTemplateValues.mjs +++ b/packages/legacy/src/legacy-html/utils/replaceTemplateValues.mjs @@ -1,5 +1,7 @@ 'use strict'; +import { populate } from '@node-core/doc-kit/utils/configuration/templates.mjs'; + import { buildToC, buildNavigation, @@ -7,13 +9,12 @@ import { buildGitHub, } from './buildDropdowns.mjs'; import tableOfContents from './tableOfContents.mjs'; -import { populate } from '../../../utils/configuration/templates.mjs'; /** * Replaces the template values in the API template with the given values. * @param {string} apiTemplate - The HTML template string * @param {import('../types').TemplateValues} values - The values to replace the template values with - * @param {import('../../../utils/configuration/types').GlobalConfiguration} config + * @param {import('@node-core/doc-kit/utils/configuration/types').GlobalConfiguration} config * @param {{ skipGitHub?: boolean; skipGtocPicker?: boolean }} [options] - Optional settings * @returns {string} The replaced template values */ diff --git a/packages/core/src/generators/legacy-html/utils/slugger.mjs b/packages/legacy/src/legacy-html/utils/slugger.mjs similarity index 90% rename from packages/core/src/generators/legacy-html/utils/slugger.mjs rename to packages/legacy/src/legacy-html/utils/slugger.mjs index 43d805cb..714b9e66 100644 --- a/packages/core/src/generators/legacy-html/utils/slugger.mjs +++ b/packages/legacy/src/legacy-html/utils/slugger.mjs @@ -1,6 +1,6 @@ 'use strict'; -import { DEPRECATION_HEADING_REGEX } from '../../metadata/constants.mjs'; +import { DEPRECATION_HEADING_REGEX } from '@node-core/doc-kit/generators/metadata/constants.mjs'; /** * Creates a stateful slugger for legacy anchor links. diff --git a/packages/core/src/generators/legacy-html/utils/tableOfContents.mjs b/packages/legacy/src/legacy-html/utils/tableOfContents.mjs similarity index 80% rename from packages/core/src/generators/legacy-html/utils/tableOfContents.mjs rename to packages/legacy/src/legacy-html/utils/tableOfContents.mjs index 6a8f86d9..c6d342ff 100644 --- a/packages/core/src/generators/legacy-html/utils/tableOfContents.mjs +++ b/packages/legacy/src/legacy-html/utils/tableOfContents.mjs @@ -8,8 +8,8 @@ * * This generates a Markdown string containing a list as the ToC for the API documentation. * - * @param {Array} entries The API metadata nodes to be used for the ToC - * @param {{ maxDepth: number; parser: (metadata: import('../../metadata/types').MetadataEntry) => string }} options The optional ToC options + * @param {Array} entries The API metadata nodes to be used for the ToC + * @param {{ maxDepth: number; parser: (metadata: import('@node-core/doc-kit/generators/metadata/types').MetadataEntry) => string }} options The optional ToC options */ const tableOfContents = (entries, options) => { // Filter out the entries that have a name property / or that have empty content @@ -33,7 +33,7 @@ const tableOfContents = (entries, options) => { /** * Builds the Label with extra metadata to be used in the ToC * - * @param {import('../../metadata/types').MetadataEntry} metadata The current node that is being parsed + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} metadata The current node that is being parsed */ tableOfContents.parseNavigationNode = ({ api, heading }) => `${heading.data.name}`; @@ -41,7 +41,7 @@ tableOfContents.parseNavigationNode = ({ api, heading }) => /** * Builds the Label with extra metadata to be used in the ToC * - * @param {import('../../metadata/types').MetadataEntry} metadata + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} metadata */ tableOfContents.parseToCNode = ({ stability, api, heading }) => { const fullSlug = `${api}.html#${heading.data.slug}`; diff --git a/packages/core/src/generators/legacy-json-all/README.md b/packages/legacy/src/legacy-json-all/README.md similarity index 100% rename from packages/core/src/generators/legacy-json-all/README.md rename to packages/legacy/src/legacy-json-all/README.md diff --git a/packages/core/src/generators/legacy-json-all/generate.mjs b/packages/legacy/src/legacy-json-all/generate.mjs similarity index 93% rename from packages/core/src/generators/legacy-json-all/generate.mjs rename to packages/legacy/src/legacy-json-all/generate.mjs index bc04f9aa..76bae144 100644 --- a/packages/core/src/generators/legacy-json-all/generate.mjs +++ b/packages/legacy/src/legacy-json-all/generate.mjs @@ -3,8 +3,9 @@ import { writeFile } from 'node:fs/promises'; import { join } from 'node:path'; -import getConfig from '../../utils/configuration/index.mjs'; -import { legacyToJSON } from '../../utils/generators.mjs'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; + +import { legacyToJSON } from '../utils/legacyToJSON.mjs'; /** * Generates the legacy JSON `all.json` file. diff --git a/packages/core/src/generators/legacy-json-all/index.mjs b/packages/legacy/src/legacy-json-all/index.mjs similarity index 88% rename from packages/core/src/generators/legacy-json-all/index.mjs rename to packages/legacy/src/legacy-json-all/index.mjs index 38af8498..e92066dd 100644 --- a/packages/core/src/generators/legacy-json-all/index.mjs +++ b/packages/legacy/src/legacy-json-all/index.mjs @@ -14,7 +14,7 @@ export default { description: 'Generates the `all.json` file from the `legacy-json` generator, which includes all the modules in one single file.', - dependsOn: '@node-core/doc-kit/legacy-json', + dependsOn: '@nodejs/doc-kit-generator-legacy/legacy-json', defaultConfiguration: { minify: false, diff --git a/packages/core/src/generators/legacy-json-all/types.d.ts b/packages/legacy/src/legacy-json-all/types.d.ts similarity index 100% rename from packages/core/src/generators/legacy-json-all/types.d.ts rename to packages/legacy/src/legacy-json-all/types.d.ts diff --git a/packages/core/src/generators/legacy-json/README.md b/packages/legacy/src/legacy-json/README.md similarity index 100% rename from packages/core/src/generators/legacy-json/README.md rename to packages/legacy/src/legacy-json/README.md diff --git a/packages/core/src/generators/legacy-json/constants.mjs b/packages/legacy/src/legacy-json/constants.mjs similarity index 100% rename from packages/core/src/generators/legacy-json/constants.mjs rename to packages/legacy/src/legacy-json/constants.mjs diff --git a/packages/core/src/generators/legacy-json/generate.mjs b/packages/legacy/src/legacy-json/generate.mjs similarity index 86% rename from packages/core/src/generators/legacy-json/generate.mjs rename to packages/legacy/src/legacy-json/generate.mjs index b19f2e5d..e13d8bde 100644 --- a/packages/core/src/generators/legacy-json/generate.mjs +++ b/packages/legacy/src/legacy-json/generate.mjs @@ -2,10 +2,12 @@ import { join } from 'node:path'; +import getConfig from '@node-core/doc-kit/utils/configuration/index.mjs'; +import { writeFile, withExt } from '@node-core/doc-kit/utils/file.mjs'; +import { groupNodesByModule } from '@node-core/doc-kit/utils/generators.mjs'; + import { createSectionBuilder } from './utils/buildSection.mjs'; -import getConfig from '../../utils/configuration/index.mjs'; -import { writeFile, withExt } from '../../utils/file.mjs'; -import { groupNodesByModule, legacyToJSON } from '../../utils/generators.mjs'; +import { legacyToJSON } from '../utils/legacyToJSON.mjs'; const buildSection = createSectionBuilder(); diff --git a/packages/core/src/generators/legacy-json/index.mjs b/packages/legacy/src/legacy-json/index.mjs similarity index 100% rename from packages/core/src/generators/legacy-json/index.mjs rename to packages/legacy/src/legacy-json/index.mjs diff --git a/packages/core/src/generators/legacy-json/types.d.ts b/packages/legacy/src/legacy-json/types.d.ts similarity index 96% rename from packages/core/src/generators/legacy-json/types.d.ts rename to packages/legacy/src/legacy-json/types.d.ts index 058ffc65..40f7580a 100644 --- a/packages/core/src/generators/legacy-json/types.d.ts +++ b/packages/legacy/src/legacy-json/types.d.ts @@ -1,6 +1,6 @@ import { ListItem } from '@types/mdast'; -import { MetadataEntry } from '../metadata/types'; -import { MethodSignature } from '../../utils/signature/types'; +import { MetadataEntry } from '@node-core/doc-kit/generators/metadata/types'; +import { MethodSignature } from '@node-core/doc-kit/utils/signature/types'; /** * A node in the entry hierarchy. diff --git a/packages/core/src/generators/legacy-json/utils/__tests__/buildHierarchy.test.mjs b/packages/legacy/src/legacy-json/utils/__tests__/buildHierarchy.test.mjs similarity index 100% rename from packages/core/src/generators/legacy-json/utils/__tests__/buildHierarchy.test.mjs rename to packages/legacy/src/legacy-json/utils/__tests__/buildHierarchy.test.mjs diff --git a/packages/core/src/generators/legacy-json/utils/__tests__/buildSection.test.mjs b/packages/legacy/src/legacy-json/utils/__tests__/buildSection.test.mjs similarity index 100% rename from packages/core/src/generators/legacy-json/utils/__tests__/buildSection.test.mjs rename to packages/legacy/src/legacy-json/utils/__tests__/buildSection.test.mjs diff --git a/packages/core/src/generators/legacy-json/utils/buildHierarchy.mjs b/packages/legacy/src/legacy-json/utils/buildHierarchy.mjs similarity index 91% rename from packages/core/src/generators/legacy-json/utils/buildHierarchy.mjs rename to packages/legacy/src/legacy-json/utils/buildHierarchy.mjs index 1b17edec..511bc11a 100644 --- a/packages/core/src/generators/legacy-json/utils/buildHierarchy.mjs +++ b/packages/legacy/src/legacy-json/utils/buildHierarchy.mjs @@ -1,7 +1,7 @@ /** * Recursively finds the most suitable parent node for a given `entry` based on heading depth. * - * @param {import('../../metadata/types').MetadataEntry} entry + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry * @param {Array} nodes * @param {number} startIdx * @returns {import('../types.d.ts').HierarchizedEntry} @@ -39,7 +39,7 @@ export function findParent(entry, nodes, startIdx) { * found by looping through entries in reverse starting at the current * index - 1. * - * @param {Array} entries + * @param {Array} entries * @returns {Array} */ export function buildHierarchy(entries) { diff --git a/packages/core/src/generators/legacy-json/utils/buildSection.mjs b/packages/legacy/src/legacy-json/utils/buildSection.mjs similarity index 83% rename from packages/core/src/generators/legacy-json/utils/buildSection.mjs rename to packages/legacy/src/legacy-json/utils/buildSection.mjs index 41b2d222..db978160 100644 --- a/packages/core/src/generators/legacy-json/utils/buildSection.mjs +++ b/packages/legacy/src/legacy-json/utils/buildSection.mjs @@ -1,8 +1,9 @@ +import { enforceArray } from '@node-core/doc-kit/utils/array.mjs'; +import { getRemarkRehype as remark } from '@node-core/doc-kit/utils/remark.mjs'; +import { parseList } from '@node-core/doc-kit/utils/signature/parseList.mjs'; +import { transformNodesToString } from '@node-core/doc-kit/utils/unist.mjs'; + import { buildHierarchy } from './buildHierarchy.mjs'; -import { enforceArray } from '../../../utils/array.mjs'; -import { getRemarkRehype as remark } from '../../../utils/remark.mjs'; -import { parseList } from '../../../utils/signature/parseList.mjs'; -import { transformNodesToString } from '../../../utils/unist.mjs'; import { SECTION_TYPE_PLURALS, UNPROMOTED_KEYS } from '../constants.mjs'; /** @@ -33,7 +34,7 @@ export const promoteMiscChildren = (section, parent) => { export const createSectionBuilder = () => { /** * Creates metadata from a metadata entry. - * @param {import('../../metadata/types').MetadataEntry} entry - The entry to create metadata from. + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The entry to create metadata from. * @returns {import('../types.d.ts').Meta | undefined} The created metadata, or undefined if all fields are empty. */ const createMeta = ({ @@ -73,8 +74,8 @@ export const createSectionBuilder = () => { /** * Creates a section from an entry and its heading. - * @param {import('../../metadata/types').MetadataEntry} entry - The AST entry. - * @param {import('../../metadata/types').HeadingNode} head - The head node of the entry. + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The AST entry. + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} head - The head node of the entry. * @returns {import('../types.d.ts').Section} The created section. */ const createSection = (entry, head) => { @@ -98,7 +99,7 @@ export const createSectionBuilder = () => { * Parses stability metadata and adds it to the section. * @param {import('../types.d.ts').Section} section - The section to update. * @param {Array} nodes - The remaining AST nodes. - * @param {import('../../metadata/types').MetadataEntry} entry - The entry providing stability information. + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} entry - The entry providing stability information. */ const parseStability = (section, nodes, { stability, content }) => { if (stability) { @@ -135,7 +136,7 @@ export const createSectionBuilder = () => { * Adds additional metadata to the section based on its type. * @param {import('../types.d.ts').Section} section - The section to update. * @param {import('../types.d.ts').Section} parent - The parent section. - * @param {import('../../metadata/types').HeadingNode} heading - The heading node of the section. + * @param {import('@node-core/doc-kit/generators/metadata/types').HeadingNode} heading - The heading node of the section. */ const addAdditionalMetadata = (section, parent, heading) => { if (!section.type || section.type === 'module') { @@ -180,8 +181,8 @@ export const createSectionBuilder = () => { /** * Builds the module section from head metadata and entries. - * @param {import('../../metadata/types').MetadataEntry} head - The head metadata entry. - * @param {Array} entries - The list of metadata entries. + * @param {import('@node-core/doc-kit/generators/metadata/types').MetadataEntry} head - The head metadata entry. + * @param {Array} entries - The list of metadata entries. * @returns {import('../types.d.ts').ModuleSection} The constructed module section. */ return (head, entries) => { diff --git a/packages/legacy/src/utils/__tests__/legacyToJSON.test.mjs b/packages/legacy/src/utils/__tests__/legacyToJSON.test.mjs new file mode 100644 index 00000000..65619717 --- /dev/null +++ b/packages/legacy/src/utils/__tests__/legacyToJSON.test.mjs @@ -0,0 +1,47 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; + +import { legacyToJSON } from '../legacyToJSON.mjs'; + +describe('legacyToJSON', () => { + const base = { + type: 'module', + source: 'lib/fs.js', + introduced_in: 'v0.10.0', + meta: {}, + stability: 2, + stabilityText: 'Stable', + classes: [], + methods: ['readFile'], + properties: [], + miscs: [], + modules: ['fs'], + globals: [], + }; + + it('serialises a normal section with all keys', () => { + const result = JSON.parse(legacyToJSON({ ...base, api: 'fs' })); + assert.ok('type' in result); + assert.ok('methods' in result); + assert.ok('modules' in result); + }); + + it('omits modules key for index sections', () => { + const result = JSON.parse(legacyToJSON({ ...base, api: 'index' })); + assert.ok(!('modules' in result)); + }); + + it('uses all.json key order when api is null', () => { + const result = JSON.parse(legacyToJSON({ ...base, api: null })); + // all.json only includes miscs, modules, classes, globals, methods + assert.ok('miscs' in result); + assert.ok('modules' in result); + assert.ok(!('type' in result)); + assert.ok(!('source' in result)); + }); + + it('passes extra args to JSON.stringify (e.g. indentation)', () => { + const result = legacyToJSON({ ...base, api: 'fs' }, null, 2); + assert.ok(result.includes('\n')); + }); +}); diff --git a/packages/legacy/src/utils/legacyToJSON.mjs b/packages/legacy/src/utils/legacyToJSON.mjs new file mode 100644 index 00000000..2b1a1f95 --- /dev/null +++ b/packages/legacy/src/utils/legacyToJSON.mjs @@ -0,0 +1,53 @@ +'use strict'; + +/** + * Transforms an object to JSON output consistent with the JSON version. + * @param {import('../legacy-json/types').Section} section - The source object + * @param {any[]} args + * @returns {string} - The JSON output + */ +export const legacyToJSON = ( + { + api, + type, + source, + introduced_in, + meta, + stability, + stabilityText, + classes, + methods, + properties, + miscs, + modules, + globals, + }, + ...args +) => + JSON.stringify( + api == null + ? { + // all.json special order + miscs, + modules, + classes, + globals, + methods, + } + : { + type, + source, + introduced_in, + meta, + stability, + stabilityText, + classes, + methods, + properties, + miscs, + // index.json shouldn't have a `modules` key: + ...(api === 'index' ? undefined : { modules }), + globals, + }, + ...args + ); From 6bf6bd3256b4c36f3626a2c6c545da6ffcb21d29 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Thu, 30 Jul 2026 14:23:49 -0700 Subject: [PATCH 3/7] refactor(node): extract @node-core/doc-kit package, move core to @nodejs/doc-kit --- .changeset/configurable-navigation.md | 2 +- .changeset/curvy-items-smile.md | 2 +- .../did-you-know-that-the-world-is-round.md | 2 +- .changeset/display-name-type-unions.md | 2 +- .changeset/doc-kit-scope-move.md | 8 +++++ .changeset/fix-relative-parent-path.md | 2 +- .changeset/legacy-kitten-package.md | 4 +-- .changeset/monorepo-layout.md | 2 +- .changeset/node-kitten-package.md | 10 ++++++ .changeset/opt-out-banners.md | 2 +- .changeset/react-kitten-package.md | 4 +-- .changeset/riscv64-warning-spacing.md | 2 +- .changeset/short-deprecation-links.md | 2 +- .changeset/spaced-union-types.md | 2 +- .changeset/specifier-generator-loading.md | 2 +- .changeset/swc.md | 2 +- .changeset/tidy-deprecations-smile.md | 2 +- .changeset/tidy-donuts-search.md | 2 +- .changeset/vite-web-generator.md | 2 +- .changeset/yes-i-did-know-that-thank-you.md | 2 +- .github/workflows/publish.yml | 4 +-- .gitignore | 2 +- .prettierignore | 2 +- CONTRIBUTING.md | 13 +++++--- README.md | 6 ++-- docs/comparators.md | 2 +- docs/configuration.md | 2 +- docs/generators.md | 18 +++++----- docs/specification.md | 2 +- eslint.config.mjs | 2 +- package-lock.json | 33 ++++++++++++++----- package.json | 2 +- packages/core/CHANGELOG.md | 2 +- packages/core/README.md | 4 +-- packages/core/bin/cli.mjs | 2 +- packages/core/package.json | 12 +++---- packages/core/src/generators/index.mjs | 8 ++--- .../core/src/generators/json-simple/index.mjs | 2 +- .../core/src/generators/metadata/index.mjs | 2 +- packages/core/src/generators/types.d.ts | 2 +- packages/legacy/package.json | 4 +-- .../legacy/src/legacy-html-all/generate.mjs | 6 ++-- packages/legacy/src/legacy-html/generate.mjs | 10 +++--- packages/legacy/src/legacy-html/index.mjs | 4 +-- packages/legacy/src/legacy-html/types.d.ts | 2 +- .../utils/__tests__/buildContent.test.mjs | 2 +- .../src/legacy-html/utils/buildContent.mjs | 20 +++++------ .../src/legacy-html/utils/buildDropdowns.mjs | 8 ++--- .../legacy-html/utils/buildExtraContent.mjs | 6 ++-- .../utils/replaceTemplateValues.mjs | 4 +-- .../legacy/src/legacy-html/utils/slugger.mjs | 2 +- .../src/legacy-html/utils/tableOfContents.mjs | 8 ++--- .../legacy/src/legacy-json-all/generate.mjs | 2 +- packages/legacy/src/legacy-json/generate.mjs | 6 ++-- packages/legacy/src/legacy-json/index.mjs | 2 +- packages/legacy/src/legacy-json/types.d.ts | 4 +-- .../src/legacy-json/utils/buildHierarchy.mjs | 4 +-- .../src/legacy-json/utils/buildSection.mjs | 22 ++++++------- packages/node/package.json | 31 +++++++++++++++++ .../src}/addon-verify/README.md | 0 .../src}/addon-verify/constants.mjs | 0 .../src}/addon-verify/generate.mjs | 4 +-- .../src}/addon-verify/index.mjs | 2 +- .../src}/addon-verify/types.d.ts | 2 +- .../utils/__tests__/generateFileList.test.mjs | 3 ++ .../utils/__tests__/section.test.mjs | 0 .../addon-verify/utils/generateFileList.mjs | 0 .../src}/addon-verify/utils/section.mjs | 0 .../src}/api-links/README.md | 0 .../api-links/__tests__/fixtures.test.mjs | 10 +++--- .../__tests__/fixtures.test.mjs.snapshot | 0 .../api-links/__tests__/fixtures/buffer.js | 0 .../api-links/__tests__/fixtures/class.js | 0 .../api-links/__tests__/fixtures/exports.js | 0 .../src}/api-links/__tests__/fixtures/mod.js | 0 .../api-links/__tests__/fixtures/prototype.js | 0 .../api-links/__tests__/fixtures/reverse.js | 0 .../src}/api-links/__tests__/fixtures/root.js | 0 .../src}/api-links/constants.mjs | 0 .../src}/api-links/generate.mjs | 7 ++-- .../src}/api-links/index.mjs | 5 +-- .../src}/api-links/types.d.ts | 0 .../utils/checkIndirectReferences.mjs | 0 .../src}/api-links/utils/extractExports.mjs | 0 .../src}/api-links/utils/findDefinitions.mjs | 0 .../src}/man-page/README.md | 0 .../src}/man-page/generate.mjs | 9 ++--- .../src}/man-page/index.mjs | 2 +- .../src}/man-page/template.1 | 2 +- .../src}/man-page/types.d.ts | 2 +- .../utils/__tests__/converter.test.mjs | 0 .../src}/man-page/utils/converter.mjs | 4 +-- packages/react/package.json | 4 +-- .../src/html/__tests__/generate.test.mjs | 2 +- .../src/html/bundlers/__tests__/vite.test.mjs | 2 +- packages/react/src/html/bundlers/vite.mjs | 2 +- packages/react/src/html/generate.mjs | 2 +- packages/react/src/html/index.mjs | 4 +-- packages/react/src/html/types.d.ts | 2 +- packages/react/src/html/ui/types.d.ts | 4 +-- .../src/html/ui/utils/relativeOrAbsolute.mjs | 2 +- .../src/html/utils/__tests__/config.test.mjs | 2 +- .../src/html/utils/__tests__/copying.test.mjs | 2 +- .../html/utils/__tests__/processing.test.mjs | 2 +- .../__tests__/relativeOrAbsolute.test.mjs | 2 +- packages/react/src/html/utils/config.mjs | 8 ++--- packages/react/src/html/utils/copying.mjs | 2 +- packages/react/src/html/utils/generate.mjs | 2 +- packages/react/src/html/utils/processing.mjs | 16 ++++----- .../src/html/utils/relativeOrAbsolute.mjs | 4 +-- .../src/jsx-ast/__tests__/generate.test.mjs | 2 +- packages/react/src/jsx-ast/generate.mjs | 6 ++-- packages/react/src/jsx-ast/index.mjs | 2 +- packages/react/src/jsx-ast/types.d.ts | 2 +- .../utils/__tests__/buildContent.test.mjs | 2 +- .../react/src/jsx-ast/utils/buildBarProps.mjs | 10 +++--- .../react/src/jsx-ast/utils/buildContent.mjs | 32 +++++++++--------- .../src/jsx-ast/utils/getSortedHeadNodes.mjs | 8 ++--- .../react/src/jsx-ast/utils/overloads.mjs | 8 ++--- packages/react/src/jsx-ast/utils/remark.mjs | 6 ++-- .../react/src/jsx-ast/utils/signature.mjs | 16 ++++----- .../react/src/jsx-ast/utils/synthetic/all.mjs | 2 +- .../src/jsx-ast/utils/synthetic/index.mjs | 4 +-- packages/react/src/jsx-ast/utils/types.mjs | 6 ++-- packages/react/src/llms-txt/generate.mjs | 4 +-- packages/react/src/llms-txt/index.mjs | 2 +- packages/react/src/llms-txt/types.d.ts | 2 +- .../src/llms-txt/utils/buildApiDocLink.mjs | 10 +++--- packages/react/src/orama-db/generate.mjs | 8 ++--- packages/react/src/orama-db/index.mjs | 2 +- packages/react/src/orama-db/types.d.ts | 2 +- packages/react/src/sitemap/generate.mjs | 6 ++-- packages/react/src/sitemap/index.mjs | 2 +- packages/react/src/sitemap/types.d.ts | 2 +- .../sitemap/utils/createPageSitemapEntry.mjs | 6 ++-- www/pages/getting-started.md | 9 +++-- 136 files changed, 342 insertions(+), 262 deletions(-) create mode 100644 .changeset/doc-kit-scope-move.md create mode 100644 .changeset/node-kitten-package.md create mode 100644 packages/node/package.json rename packages/{core/src/generators => node/src}/addon-verify/README.md (100%) rename packages/{core/src/generators => node/src}/addon-verify/constants.mjs (100%) rename packages/{core/src/generators => node/src}/addon-verify/generate.mjs (93%) rename packages/{core/src/generators => node/src}/addon-verify/index.mjs (91%) rename packages/{core/src/generators => node/src}/addon-verify/types.d.ts (59%) rename packages/{core/src/generators => node/src}/addon-verify/utils/__tests__/generateFileList.test.mjs (88%) rename packages/{core/src/generators => node/src}/addon-verify/utils/__tests__/section.test.mjs (100%) rename packages/{core/src/generators => node/src}/addon-verify/utils/generateFileList.mjs (100%) rename packages/{core/src/generators => node/src}/addon-verify/utils/section.mjs (100%) rename packages/{core/src/generators => node/src}/api-links/README.md (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures.test.mjs (80%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures.test.mjs.snapshot (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/buffer.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/class.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/exports.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/mod.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/prototype.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/reverse.js (100%) rename packages/{core/src/generators => node/src}/api-links/__tests__/fixtures/root.js (100%) rename packages/{core/src/generators => node/src}/api-links/constants.mjs (100%) rename packages/{core/src/generators => node/src}/api-links/generate.mjs (88%) rename packages/{core/src/generators => node/src}/api-links/index.mjs (86%) rename packages/{core/src/generators => node/src}/api-links/types.d.ts (100%) rename packages/{core/src/generators => node/src}/api-links/utils/checkIndirectReferences.mjs (100%) rename packages/{core/src/generators => node/src}/api-links/utils/extractExports.mjs (100%) rename packages/{core/src/generators => node/src}/api-links/utils/findDefinitions.mjs (100%) rename packages/{core/src/generators => node/src}/man-page/README.md (100%) rename packages/{core/src/generators => node/src}/man-page/generate.mjs (83%) rename packages/{core/src/generators => node/src}/man-page/index.mjs (92%) rename packages/{core/src/generators => node/src}/man-page/template.1 (95%) rename packages/{core/src/generators => node/src}/man-page/types.d.ts (74%) rename packages/{core/src/generators => node/src}/man-page/utils/__tests__/converter.test.mjs (100%) rename packages/{core/src/generators => node/src}/man-page/utils/converter.mjs (95%) diff --git a/.changeset/configurable-navigation.md b/.changeset/configurable-navigation.md index cecf529c..869cdc5e 100644 --- a/.changeset/configurable-navigation.md +++ b/.changeset/configurable-navigation.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Add `web.navigation`, which supplies the sidebar groups (`navigation.sidebar`) diff --git a/.changeset/curvy-items-smile.md b/.changeset/curvy-items-smile.md index 69111d7f..7b9492b4 100644 --- a/.changeset/curvy-items-smile.md +++ b/.changeset/curvy-items-smile.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': minor +'@nodejs/doc-kit': minor --- Discover and load configuration files with `cosmiconfig`. diff --git a/.changeset/did-you-know-that-the-world-is-round.md b/.changeset/did-you-know-that-the-world-is-round.md index 98ba0892..b890a4ab 100644 --- a/.changeset/did-you-know-that-the-world-is-round.md +++ b/.changeset/did-you-know-that-the-world-is-round.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Close Orama search when the target link is on the same page diff --git a/.changeset/display-name-type-unions.md b/.changeset/display-name-type-unions.md index 8f91f546..f4b2cdb1 100644 --- a/.changeset/display-name-type-unions.md +++ b/.changeset/display-name-type-unions.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- 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. diff --git a/.changeset/doc-kit-scope-move.md b/.changeset/doc-kit-scope-move.md new file mode 100644 index 00000000..dd10cf1a --- /dev/null +++ b/.changeset/doc-kit-scope-move.md @@ -0,0 +1,8 @@ +--- +'@nodejs/doc-kit': major +--- + +The doc-kit engine and CLI, previously published as `@node-core/doc-kit`, +are now published as `@nodejs/doc-kit`. The `@node-core/doc-kit` name now +contains only the Node.js-specific generators (`api-links`, `addon-verify`, +and `man-page`). diff --git a/.changeset/fix-relative-parent-path.md b/.changeset/fix-relative-parent-path.md index e3f7ef8e..7745c39b 100644 --- a/.changeset/fix-relative-parent-path.md +++ b/.changeset/fix-relative-parent-path.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Fix `relative()` URL resolution when the target path is a prefix of the current diff --git a/.changeset/legacy-kitten-package.md b/.changeset/legacy-kitten-package.md index 55d49a31..b38a21ca 100644 --- a/.changeset/legacy-kitten-package.md +++ b/.changeset/legacy-kitten-package.md @@ -1,11 +1,11 @@ --- '@nodejs/doc-kit-generator-legacy': major -'@node-core/doc-kit': major +'@nodejs/doc-kit': major --- The legacy-format generators (`legacy-html`, `legacy-html-all`, `legacy-json`, and `legacy-json-all`) now live in the new `@nodejs/doc-kit-generator-legacy` package and are loaded via import specifiers such as `@nodejs/doc-kit-generator-legacy/legacy-html`. The corresponding -`@node-core/doc-kit/*` package exports have been removed. The CLI shorthand +`@nodejs/doc-kit/*` package exports have been removed. The CLI shorthand names are unchanged. diff --git a/.changeset/monorepo-layout.md b/.changeset/monorepo-layout.md index 4341e42d..603f5bc6 100644 --- a/.changeset/monorepo-layout.md +++ b/.changeset/monorepo-layout.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Moved the package into a `packages/core` workspace. diff --git a/.changeset/node-kitten-package.md b/.changeset/node-kitten-package.md new file mode 100644 index 00000000..1fa974c2 --- /dev/null +++ b/.changeset/node-kitten-package.md @@ -0,0 +1,10 @@ +--- +'@node-core/doc-kit': major +'@nodejs/doc-kit': major +--- + +The Node.js-specific generators (`api-links`, `addon-verify`, and +`man-page`) now live in the `@node-core/doc-kit` package and are loaded +via import specifiers such as `@node-core/doc-kit/man-page`. The +corresponding package exports have been removed from the doc-kit engine. +The CLI shorthand names are unchanged. diff --git a/.changeset/opt-out-banners.md b/.changeset/opt-out-banners.md index 652dee33..53f9497a 100644 --- a/.changeset/opt-out-banners.md +++ b/.changeset/opt-out-banners.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': minor +'@nodejs/doc-kit': minor --- Add banner opt-out diff --git a/.changeset/react-kitten-package.md b/.changeset/react-kitten-package.md index cf250c1c..25b93ea9 100644 --- a/.changeset/react-kitten-package.md +++ b/.changeset/react-kitten-package.md @@ -1,12 +1,12 @@ --- '@nodejs/doc-kit-generator-react': minor -'@node-core/doc-kit': major +'@nodejs/doc-kit': major --- The React/JSX-based generators (`html` — previously `web` —, `jsx-ast`, `llms-txt`, `sitemap`, and `orama-db`) now live in the new `@nodejs/doc-kit-generator-react` package and are loaded via import specifiers such as -`@nodejs/doc-kit-generator-react/html`. The corresponding `@node-core/doc-kit/*` +`@nodejs/doc-kit-generator-react/html`. The corresponding `@nodejs/doc-kit/*` package exports have been removed. The `web` generator is renamed to `html`: the CLI shorthand `web` keeps working as a deprecated alias, but the configuration key is now `html` instead of `web`. diff --git a/.changeset/riscv64-warning-spacing.md b/.changeset/riscv64-warning-spacing.md index 58eff4c4..4b60d25e 100644 --- a/.changeset/riscv64-warning-spacing.md +++ b/.changeset/riscv64-warning-spacing.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Fix missing spaces in the riscv64 multithreading warning message, which diff --git a/.changeset/short-deprecation-links.md b/.changeset/short-deprecation-links.md index 8af343c4..7b38dc5c 100644 --- a/.changeset/short-deprecation-links.md +++ b/.changeset/short-deprecation-links.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Use short `DEP` codes for deprecation heading anchors. diff --git a/.changeset/spaced-union-types.md b/.changeset/spaced-union-types.md index 6c831a97..1498134d 100644 --- a/.changeset/spaced-union-types.md +++ b/.changeset/spaced-union-types.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Space union separators in type annotation values (`{string|URL}` is now rendered as `string | URL`). diff --git a/.changeset/specifier-generator-loading.md b/.changeset/specifier-generator-loading.md index 039de74a..e6ee7d58 100644 --- a/.changeset/specifier-generator-loading.md +++ b/.changeset/specifier-generator-loading.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': minor +'@nodejs/doc-kit': minor --- Generators are now loaded dynamically by import specifier instead of a static diff --git a/.changeset/swc.md b/.changeset/swc.md index 9b9a2bf2..ec6c6c6e 100644 --- a/.changeset/swc.md +++ b/.changeset/swc.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Switches `oxc-parser` for `@swc/wasm`, since `oxc-parser` does not provide the needed bindings. diff --git a/.changeset/tidy-deprecations-smile.md b/.changeset/tidy-deprecations-smile.md index d9e7c7bb..fa83f542 100644 --- a/.changeset/tidy-deprecations-smile.md +++ b/.changeset/tidy-deprecations-smile.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Preserve deprecation codes in generated table-of-contents labels. diff --git a/.changeset/tidy-donuts-search.md b/.changeset/tidy-donuts-search.md index 9c48fd61..30e045d4 100644 --- a/.changeset/tidy-donuts-search.md +++ b/.changeset/tidy-donuts-search.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Sync the URL hash when following same-page search hits diff --git a/.changeset/vite-web-generator.md b/.changeset/vite-web-generator.md index 49a47ea6..74f4838b 100644 --- a/.changeset/vite-web-generator.md +++ b/.changeset/vite-web-generator.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': minor +'@nodejs/doc-kit': minor --- Make the `web` generator bundler-neutral through a custom adapter contract, diff --git a/.changeset/yes-i-did-know-that-thank-you.md b/.changeset/yes-i-did-know-that-thank-you.md index b03124c5..370e2bef 100644 --- a/.changeset/yes-i-did-know-that-thank-you.md +++ b/.changeset/yes-i-did-know-that-thank-you.md @@ -1,5 +1,5 @@ --- -'@node-core/doc-kit': patch +'@nodejs/doc-kit': patch --- Render markdown `code` snippets in the sidebar diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 02b92068..74e7ee8a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,9 +56,9 @@ jobs: env: SLACK_COLOR: '#43853D' SLACK_ICON: https://github.com/nodejs.png?size=48 - SLACK_TITLE: ':rocket: Package Published: @node-core/doc-kit' + SLACK_TITLE: ':rocket: doc-kit Packages Published' SLACK_MESSAGE: | - :package: *Package*: `@node-core/doc-kit` () + :package: *Packages*: `nodejs/doc-kit` workspace () :bust_in_silhouette: *Published by*: ${{ github.triggering_actor }} :octocat: *Commit*: SLACK_USERNAME: nodejs-bot diff --git a/.gitignore b/.gitignore index ef3c932b..35a39e94 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ junit.xml isolate-* # Node's Source Folder -node +/node # Playwright playwright-report/ diff --git a/.prettierignore b/.prettierignore index 6e8a14b1..34ea39e2 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,7 +1,7 @@ npm-shrinkwrap.json # Tests files -packages/core/src/generators/api-links/__tests__/fixtures/ +packages/node/src/api-links/__tests__/fixtures/ *.snapshot # Templates diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b806375..faaf19da 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ -# `@node-core/doc-kit` Contributing Guide +# `@nodejs/doc-kit` Contributing Guide -Thank you for your interest in contributing to the `@node-core/doc-kit` project! We welcome contributions from everyone, and we appreciate your help in making this project better. +Thank you for your interest in contributing to the `@nodejs/doc-kit` project! We welcome contributions from everyone, and we appreciate your help in making this project better. ## Table of Contents @@ -29,7 +29,7 @@ Thank you for your interest in contributing to the `@node-core/doc-kit` project! ## Getting Started -The steps below will give you a general idea of how to prepare your local environment for the `@node-core/doc-kit` project and general steps for getting things done and landing your contribution. +The steps below will give you a general idea of how to prepare your local environment for the `@nodejs/doc-kit` project and general steps for getting things done and landing your contribution. ### Prerequisites @@ -77,7 +77,10 @@ This repository is an npm workspaces monorepo. The root package is private and holds the shared tooling (linting, formatting, tests, changesets); every published package lives under `packages/`: -- `packages/core`: [`@node-core/doc-kit`](packages/core) +- `packages/core`: [`@nodejs/doc-kit`](packages/core) — the doc-kit engine and CLI +- `packages/legacy`: [`@nodejs/doc-kit-generator-legacy`](packages/legacy) — the legacy-format generators +- `packages/node`: [`@node-core/doc-kit`](packages/node) — the Node.js-specific generators +- `packages/react`: [`@nodejs/doc-kit-generator-react`](packages/react) — the React/JSX-based generators Everything else at the root supports the repo rather than shipping to npm: `docs/` (the reference docs), `www/` (the documentation site), `scripts/` (build @@ -357,7 +360,7 @@ version in `package.json`, and writes the corresponding `CHANGELOG.md` entries. To ship a release, a maintainer merges that "Version Packages" PR. The same workflow then: -- publishes `@node-core/doc-kit` to npm (via [npm trusted publishing][] — no token required), +- publishes the workspace packages to npm (via [npm trusted publishing][] — no token required), - creates the matching `v` git tag, and - cuts a GitHub Release from the changelog. diff --git a/README.md b/README.md index 967e4878..b24f5c68 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@

- @node-core/doc-kit is a tool to generate API documentation of Node.js. See this issue for more information. + @nodejs/doc-kit is a tool to generate API documentation of Node.js. See this issue for more information.

@@ -44,7 +44,7 @@ $ node packages/core/bin/cli.mjs --help ``` ``` -Usage: @node-core/doc-kit [options] [command] +Usage: @nodejs/doc-kit [options] [command] CLI tool to generate the Node.js API documentation @@ -67,7 +67,7 @@ Running `generate` without the required values exits with an error pointing you to the help output. ``` -Usage: @node-core/doc-kit generate [options] +Usage: @nodejs/doc-kit generate [options] Generate API docs diff --git a/docs/comparators.md b/docs/comparators.md index 0046c78a..1cafcd52 100644 --- a/docs/comparators.md +++ b/docs/comparators.md @@ -1,6 +1,6 @@ # Creating Comparators -This guide explains how to create build comparison scripts for `@node-core/doc-kit`. Comparators help identify differences between documentation builds, useful for CI/CD and regression testing. +This guide explains how to create build comparison scripts for `@nodejs/doc-kit`. Comparators help identify differences between documentation builds, useful for CI/CD and regression testing. ## Comparator Concepts diff --git a/docs/configuration.md b/docs/configuration.md index eef68555..214d2857 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -39,7 +39,7 @@ export default { // Targets, alternatively supplied by command line flags. Each entry is // either a built-in shorthand name or an import specifier resolving to a // generator module (e.g. '@my-scope/my-package/my-generator'). - target: ['orama-db', 'web'], + target: ['orama-db', 'html'], global: { version: '20.0.0', minify: true, diff --git a/docs/generators.md b/docs/generators.md index a2048499..a3907501 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -1,6 +1,6 @@ # Creating Generators -This guide explains how to create new documentation generators for `@node-core/doc-kit`. +This guide explains how to create new documentation generators for `@nodejs/doc-kit`. ## Generator Concepts @@ -88,7 +88,7 @@ export default { // This generator depends on the metadata generator. Dependencies are // declared as import specifiers, so they can live in any package. - dependsOn: '@node-core/doc-kit/metadata', + dependsOn: '@nodejs/doc-kit/metadata', defaultConfiguration: { // If your generator supports a custom configuration, define the defaults here @@ -170,8 +170,8 @@ the import specifier it resolves to: ```javascript export const publicGenerators = { - 'json-simple': '@node-core/doc-kit/json-simple', - 'my-format': '@node-core/doc-kit/my-format', // Add this + 'json-simple': '@nodejs/doc-kit/json-simple', + 'my-format': '@nodejs/doc-kit/my-format', // Add this // ... other generators }; ``` @@ -199,7 +199,7 @@ export default { description: 'Processes data in parallel', - dependsOn: '@node-core/doc-kit/metadata', + dependsOn: '@nodejs/doc-kit/metadata', // Indicates this generator has a processChunk implementation hasParallelProcessor: true, @@ -296,7 +296,7 @@ export default { description: 'Streams results as they are ready', - dependsOn: '@node-core/doc-kit/metadata', + dependsOn: '@nodejs/doc-kit/metadata', hasParallelProcessor: true, @@ -403,7 +403,7 @@ export default { // This generator requires the metadata generator's output. The dependency // is an import specifier, so it may point at any installed package. - dependsOn: '@node-core/doc-kit/metadata', + dependsOn: '@nodejs/doc-kit/metadata', // ... other metadata @@ -434,7 +434,7 @@ export default { // packages/core/src/generators/metadata/index.mjs export default { name: 'metadata', - dependsOn: '@node-core/doc-kit/ast', // Depends on AST + dependsOn: '@nodejs/doc-kit/ast', // Depends on AST // Processes AST output }; @@ -442,7 +442,7 @@ export default { // packages/core/src/generators/html-generator/index.mjs export default { name: 'html-generator', - dependsOn: '@node-core/doc-kit/metadata', // Depends on metadata + dependsOn: '@nodejs/doc-kit/metadata', // Depends on metadata // Processes metadata output }; ``` diff --git a/docs/specification.md b/docs/specification.md index 1012e49f..a1f75ad5 100644 --- a/docs/specification.md +++ b/docs/specification.md @@ -5,7 +5,7 @@ **Authored By**: Aviv Keller () This document specifies the Markdown format consumed by -[`@node-core/doc-kit`][doc-kit]. It defines the structural, syntactic, and +[`@nodejs/doc-kit`][doc-kit]. It defines the structural, syntactic, and semantic rules that documents MUST follow to be correctly parsed. The format is a strict superset of [GitHub Flavored Markdown][gfm] (which itself is a strict superset of [CommonMark][commonmark]), adding conventions for API diff --git a/eslint.config.mjs b/eslint.config.mjs index f8dceaa5..5f890af3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -13,7 +13,7 @@ export default defineConfig([ ignores: [ 'www/out', 'out/', - 'packages/core/src/generators/api-links/__tests__/fixtures/', + 'packages/node/src/api-links/__tests__/fixtures/', ], }, { diff --git a/package-lock.json b/package-lock.json index 71e043ff..c03f0780 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@node-core/doc-kit-monorepo", + "name": "@nodejs/doc-kit-monorepo", "version": "1.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@node-core/doc-kit-monorepo", + "name": "@nodejs/doc-kit-monorepo", "workspaces": [ "packages/*" ], @@ -1328,7 +1328,7 @@ } }, "node_modules/@node-core/doc-kit": { - "resolved": "packages/core", + "resolved": "packages/node", "link": true }, "node_modules/@node-core/rehype-shiki": { @@ -1387,6 +1387,10 @@ "node": ">=20" } }, + "node_modules/@nodejs/doc-kit": { + "resolved": "packages/core", + "link": true + }, "node_modules/@nodejs/doc-kit-generator-legacy": { "resolved": "packages/legacy", "link": true @@ -11210,8 +11214,8 @@ } }, "packages/core": { - "name": "@node-core/doc-kit", - "version": "1.4.3", + "name": "@nodejs/doc-kit", + "version": "0.0.0", "dependencies": { "@actions/core": "^3.0.0", "@node-core/rehype-shiki": "^1.4.3", @@ -11221,7 +11225,6 @@ "commander": "^15.0.0", "cosmiconfig": "^9.0.2", "dedent": "^1.7.2", - "estree-util-visit": "^2.0.0", "github-slugger": "^2.0.0", "glob-parent": "^6.0.2", "hastscript": "^9.0.1", @@ -11248,10 +11251,14 @@ "doc-kit": "bin/cli.mjs" }, "peerDependencies": { + "@node-core/doc-kit": "^1.4.3", "@nodejs/doc-kit-generator-legacy": "^0.0.0", "@nodejs/doc-kit-generator-react": "^0.0.0" }, "peerDependenciesMeta": { + "@node-core/doc-kit": { + "optional": true + }, "@nodejs/doc-kit-generator-legacy": { "optional": true }, @@ -11264,12 +11271,22 @@ "name": "@nodejs/doc-kit-generator-legacy", "version": "0.0.0", "dependencies": { - "@node-core/doc-kit": "^1.4.3", + "@nodejs/doc-kit": "^0.0.0", "hastscript": "^9.0.1", "unist-builder": "^4.0.0", "unist-util-visit": "^5.1.0" } }, + "packages/node": { + "name": "@node-core/doc-kit", + "version": "1.4.3", + "dependencies": { + "@nodejs/doc-kit": "^0.0.0", + "dedent": "^1.7.2", + "estree-util-visit": "^2.0.0", + "unist-util-visit": "^5.1.0" + } + }, "packages/react": { "name": "@nodejs/doc-kit-generator-react", "version": "0.0.0", @@ -11278,9 +11295,9 @@ "@fontsource-variable/open-sans": "^5.3.0", "@fontsource/ibm-plex-mono": "^5.3.0", "@heroicons/react": "^2.2.0", - "@node-core/doc-kit": "^1.4.3", "@node-core/rehype-shiki": "^1.4.3", "@node-core/ui-components": "^1.7.4", + "@nodejs/doc-kit": "^0.0.0", "@orama/orama": "^3.1.18", "@orama/ui": "^1.5.4", "estree-util-to-js": "^2.0.0", diff --git a/package.json b/package.json index d868527f..5bb1e54f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@node-core/doc-kit-monorepo", + "name": "@nodejs/doc-kit-monorepo", "private": true, "type": "module", "workspaces": [ diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index d326689b..92a34618 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,4 +1,4 @@ -# @node-core/doc-kit +# @nodejs/doc-kit ## 1.4.3 diff --git a/packages/core/README.md b/packages/core/README.md index 30c43306..3e26f00a 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -1,4 +1,4 @@ -# `@node-core/doc-kit` +# `@nodejs/doc-kit` The core of doc-kit: the CLI and the generators that turn API-shaped Markdown into HTML, JSON, man pages and more. @@ -10,7 +10,7 @@ references. ## Scripts Run these from this directory, or from the repository root with -`npm run