refactor: migrate bin/api-docs to tools/api-docs as workspace @wordpress/api-docs-generator#77019
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR migrates the API docs generator from bin/api-docs into a dedicated workspace package at tools/api-docs (@wordpress/api-docs-generator) to make dependencies explicit and avoid relying on root-level devDependencies as workspace isolation tightens.
Changes:
- Adds a new workspace package (
tools/api-docs) with its ownpackage.jsonandtsconfig.json. - Updates root
package.jsondocs scripts to run via the new workspace and registerstools/api-docsin the workspaces list. - Refactors/extends API docs generation scripts (API ref, blocks, components, theme ref) to work from the new location.
Reviewed changes
Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/api-docs/update-api-docs.js | Refactors docgen invocation and formatting step for the new workspace location. |
| tools/api-docs/tsconfig.json | Adds workspace-local TS config extending the repo base config. |
| tools/api-docs/package.json | Introduces the new private workspace package and its tool dependencies/scripts. |
| tools/api-docs/gen-theme-reference.mjs | Adds explicit lint suppression for console.error on failure path. |
| tools/api-docs/gen-components-docs/markdown/props.mjs | Adds markdown generation for component props sections. |
| tools/api-docs/gen-components-docs/markdown/index.mjs | Adds markdown document assembly via json2md. |
| tools/api-docs/gen-components-docs/index.mjs | Updates component-doc generation paths to be workspace-root aware. |
| tools/api-docs/gen-components-docs/get-tags-from-storybook.mjs | Updates Babel parsing configuration and anchors parsing to repo root. |
| tools/api-docs/gen-components-docs/get-subcomponent-descriptions.mjs | Updates Babel parsing configuration and anchors parsing to repo root. |
| tools/api-docs/gen-block-lib-list.js | Adds core block docs generation script under the new workspace. |
| tools/api-docs/are-api-docs-unstaged.js | Minor refactor/reorder of imports while moving script to new location. |
| package.json | Points docs:* scripts to the new workspace and adds tools/api-docs to workspaces. |
| package-lock.json | Updates lockfile for the new workspace package and dependency relocation. |
Comments suppressed due to low confidence (1)
tools/api-docs/update-api-docs.js:243
execa(join(__dirname, '..', '..', 'node_modules', '.bin', 'docgen'), …)executes the unix shim directly. On Windows the executable is typicallydocgen.cmd, so this path may fail now thatshell: truewas removed. Prefer invokingdocgenviaexeca('docgen', …, { cwd: ROOT_DIR, preferLocal: true })ornpm exec docgen …so npm resolves the correct platform-specific binary.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
manzoorwanijk
left a comment
There was a problem hiding this comment.
Apart from what Copilot suggested. I have some additional suggestions and questions.
There was a problem hiding this comment.
Since there is no TS file in this workspace, do we need this config and its reference in the root tsconfig?
There was a problem hiding this comment.
#72973 - Many of these tools can later be converted to TypeScript when we use Node v24 with native type stripping
I was following the Storybook setup and thought we could keep it as-is, since it will likely be refactored to TypeScript later.
There was a problem hiding this comment.
When that happens, we can add a tsconfig file but right now it’s unused.
There was a problem hiding this comment.
This is not addressed yet. Let us delete this file for now.
| "url": "https://github.com/WordPress/gutenberg/issues" | ||
| }, | ||
| "dependencies": { | ||
| "chalk": "4.1.1", |
There was a problem hiding this comment.
I noticed that we have multiple versions of chalk in the repo, which we can fix in a follow-up. Here, let us use the caret range.
| "chalk": "4.1.1", | |
| "chalk": "^4.1.1", |
| }, | ||
| "dependencies": { | ||
| "chalk": "4.1.1", | ||
| "execa": "4.0.2", |
There was a problem hiding this comment.
| "execa": "4.0.2", | |
| "execa": "^4.0.2", |
| "@apidevtools/json-schema-ref-parser": "11.6.4", | ||
| "@babel/core": "7.25.7", |
There was a problem hiding this comment.
| "@apidevtools/json-schema-ref-parser": "11.6.4", | |
| "@babel/core": "7.25.7", | |
| "@apidevtools/json-schema-ref-parser": "^11.6.4", | |
| "@babel/core": "^7.25.7", |
| "glob": "7.1.2", | ||
| "json2md": "2.0.1", | ||
| "react-docgen-typescript": "2.2.2" |
There was a problem hiding this comment.
| "glob": "7.1.2", | |
| "json2md": "2.0.1", | |
| "react-docgen-typescript": "2.2.2" | |
| "glob": "^7.1.2", | |
| "json2md": "^2.0.1", | |
| "react-docgen-typescript": "^2.2.2" |
| sourceType: 'module', | ||
| cwd: ROOT_DIR, | ||
| rootMode: 'upward-optional', | ||
| parserOpts: { | ||
| sourceType: 'module', | ||
| plugins: [ 'jsx', 'typescript' ], | ||
| }, |
There was a problem hiding this comment.
cwd makes sense, but why didn't we need the other options before? Do we need them now?
There was a problem hiding this comment.
Ah, earlier, before discovering the rootMode option, I added these settings to fix Babel annotation errors caused by missing config resolution.
After rootMode resolved the issue, I forgot to remove them and reused them elsewhere.
|
Thank you for working on this though. |
This file will be added later when typescript migration is needed
manzoorwanijk
left a comment
There was a problem hiding this comment.
Thank you for working on this. It looks good now.
|
Did this need to be updated too? I think the commit hooks are failing because of this. Line 247 in 5acfe09 |
What?
Part of #75041
Why?
The issue provides more context, but in short, this PR ensures the workspace package does not rely on root dependencies once dependency isolation is enforced.
How?
This PR converts the bin/api-docs into a new workspace
@wordpress/api-docs-generatorwhile still relating the functionality.Testing Instructions
run all docs:* scripts in the root package.json