Skip to content

refactor: migrate bin/api-docs to tools/api-docs as workspace @wordpress/api-docs-generator#77019

Merged
manzoorwanijk merged 10 commits intoWordPress:trunkfrom
USERSATOSHI:try/migrate-api-docs-to-npm-workspace
Apr 9, 2026
Merged

refactor: migrate bin/api-docs to tools/api-docs as workspace @wordpress/api-docs-generator#77019
manzoorwanijk merged 10 commits intoWordPress:trunkfrom
USERSATOSHI:try/migrate-api-docs-to-npm-workspace

Conversation

@USERSATOSHI
Copy link
Copy Markdown
Contributor

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-generator while still relating the functionality.

Testing Instructions

run all docs:* scripts in the root package.json

@USERSATOSHI USERSATOSHI marked this pull request as ready for review April 3, 2026 10:42
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: USERSATOSHI <tusharbharti@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Apr 7, 2026
@manzoorwanijk manzoorwanijk requested a review from Copilot April 7, 2026 07:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 own package.json and tsconfig.json.
  • Updates root package.json docs scripts to run via the new workspace and registers tools/api-docs in 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 typically docgen.cmd, so this path may fail now that shell: true was removed. Prefer invoking docgen via execa('docgen', …, { cwd: ROOT_DIR, preferLocal: true }) or npm exec docgen … so npm resolves the correct platform-specific binary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json Outdated
Comment thread package.json Outdated
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from what Copilot suggested. I have some additional suggestions and questions.

Comment thread tools/api-docs/tsconfig.json Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no TS file in this workspace, do we need this config and its reference in the root tsconfig?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When that happens, we can add a tsconfig file but right now it’s unused.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not addressed yet. Let us delete this file for now.

Comment thread tools/api-docs/package.json Outdated
Comment thread tools/api-docs/package.json Outdated
"url": "https://github.com/WordPress/gutenberg/issues"
},
"dependencies": {
"chalk": "4.1.1",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"chalk": "4.1.1",
"chalk": "^4.1.1",

Comment thread tools/api-docs/package.json Outdated
},
"dependencies": {
"chalk": "4.1.1",
"execa": "4.0.2",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"execa": "4.0.2",
"execa": "^4.0.2",

Comment thread tools/api-docs/package.json Outdated
Comment on lines +28 to +29
"@apidevtools/json-schema-ref-parser": "11.6.4",
"@babel/core": "7.25.7",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@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",

Comment thread tools/api-docs/package.json Outdated
Comment on lines +31 to +33
"glob": "7.1.2",
"json2md": "2.0.1",
"react-docgen-typescript": "2.2.2"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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"

Comment on lines +21 to +27
sourceType: 'module',
cwd: ROOT_DIR,
rootMode: 'upward-optional',
parserOpts: {
sourceType: 'module',
plugins: [ 'jsx', 'typescript' ],
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cwd makes sense, but why didn't we need the other options before? Do we need them now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@manzoorwanijk
Copy link
Copy Markdown
Member

Thank you for working on this though.

This file will be added later when typescript migration is needed
Comment thread package.json
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. It looks good now.

@manzoorwanijk manzoorwanijk merged commit 2f07ef4 into WordPress:trunk Apr 9, 2026
40 checks passed
@github-actions github-actions bot added this to the Gutenberg 23.0 milestone Apr 9, 2026
@mirka
Copy link
Copy Markdown
Member

mirka commented Apr 9, 2026

Did this need to be updated too? I think the commit hooks are failing because of this.

"node ./bin/api-docs/are-api-docs-unstaged.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants