@wordpress/docgen 2.57.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # `docgen`
2
2
 
3
- `docgen` helps you to generate the _public API_ of your code. Given an entry point file, it outputs the ES6 export statements and their corresponding JSDoc comments in human-readable format. It also supports TypeScript via the TypeScript babel plugin.
3
+ `docgen` helps you to generate the _public API_ of your code. Given an entry point file, it outputs the ES6 export statements and their corresponding JSDoc comments in human-readable format. It also supports TypeScript.
4
4
 
5
5
  Some characteristics:
6
6
 
7
7
  - If the export statement doesn't contain any JSDoc, it'll look up for JSDoc up to the declaration.
8
8
  - It can resolve relative dependencies, either files or directories. For example, `import default from './dependency'` will find `dependency.js` or `dependency/index.js`
9
- - For TypeScript support, all types must be explicitly annotated as the TypeScript Babel plugin is unable to consume inferred types (it does not run the TS compiler, after all—it merely parses TypeScript). For example, all function return types must be explicitly annotated if they are to be documented by `docgen`.
9
+ - For TypeScript support, all types must be explicitly annotated because `docgen` parses TypeScript without running the TypeScript compiler or inferring types. For example, all function return types must be explicitly annotated if they are to be documented by `docgen`.
10
10
 
11
11
  ## Installation
12
12
 
@@ -41,11 +41,11 @@ This command will generate a file named `entry-point-api.md` containing all the
41
41
  - **--use-token** `(String)`: This options allows you to customize the string between the tokens. For example, `--use-token my-api` will look up for the start token <code>&lt;!-- START TOKEN(my-api) --&gt;</code> and the end token <code>&lt;!-- END TOKEN(my-api) --&gt;</code>. Depends on `--to-token`.
42
42
  - **--debug**: Run in debug mode, which outputs some intermediate files useful for debugging.
43
43
 
44
- ### Babel Configuration
44
+ ### Supported syntax
45
45
 
46
- `@wordpress/docgen` follows the default [project-wide configuration of Babel](https://babeljs.io/docs/en/next/config-files#project-wide-configuration). Like Babel, it will automatically search for a `babel.config.json` file, or an equivalent one using the [supported extensions](https://babeljs.io/docs/en/next/config-files#supported-file-extensions), in the project root directory.
46
+ `@wordpress/docgen` supports JavaScript, JSX, and TypeScript without configuration. TypeScript parsing follows the `.ts`, `.tsx`, `.mts`, and `.cts` file extensions. JSX is supported in JavaScript and `.tsx` files.
47
47
 
48
- Without it, `@wordpress/docgen` runs with the default option. In other words, it cannot parse JSX or other advanced syntaxes.
48
+ Project Babel configuration is not loaded. Custom Babel parser plugins are not supported. Convert sources that require them, such as Flow, to JavaScript or TypeScript before generating documentation.
49
49
 
50
50
  ## Examples
51
51
 
package/lib/engine.js CHANGED
@@ -1,8 +1,17 @@
1
- const babel = require( '@babel/core' );
1
+ const { parse } = require( '@babel/parser' );
2
2
  const getIntermediateRepresentation = require( './get-intermediate-representation' );
3
3
 
4
4
  const getAST = ( source, filename ) => {
5
- return babel.parse( source, { filename } ).program;
5
+ const isTypeScript = /\.[cm]?tsx?$/.test( filename );
6
+ const supportsJSX = ! isTypeScript || filename.endsWith( '.tsx' );
7
+ return parse( source, {
8
+ sourceType: 'module',
9
+ sourceFilename: filename,
10
+ plugins: [
11
+ ...( isTypeScript ? [ 'typescript' ] : [] ),
12
+ ...( supportsJSX ? [ 'jsx' ] : [] ),
13
+ ],
14
+ } ).program;
6
15
  };
7
16
 
8
17
  const getExportTokens = ( ast ) =>
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Function that returns the leading comment
3
- * of a Espree node.
3
+ * of an AST node.
4
4
  *
5
- * @param {import('@babel/core').Node} declaration Espree node to inspect
5
+ * @param {import('@babel/types').Node} declaration AST node to inspect
6
6
  *
7
7
  * @return {string | undefined} Leading comment or undefined if there is none.
8
8
  */
@@ -1,11 +1,11 @@
1
1
  // See https://babeljs.io/docs/en/babel-types.
2
- const { types: babelTypes } = require( '@babel/core' );
2
+ const babelTypes = require( '@babel/types' );
3
3
 
4
4
  /** @typedef {ReturnType<import('comment-parser').parse>[0]} CommentBlock */
5
5
  /** @typedef {CommentBlock['tags'][0]} CommentTag */
6
6
  /** @typedef {babelTypes.TSType} TypeAnnotation */
7
7
  /** @typedef {babelTypes.TSCallSignatureDeclaration | babelTypes.TSFunctionType | babelTypes.TSConstructSignatureDeclaration} ExtendedTypeAnnotation */
8
- /** @typedef {import('@babel/core').Node} ASTNode */
8
+ /** @typedef {import('@babel/types').Node} ASTNode */
9
9
 
10
10
  /**
11
11
  * @param {ExtendedTypeAnnotation} typeAnnotation
package/lib/index.js CHANGED
@@ -69,7 +69,7 @@ const processFile = ( rootDir, inputFile ) => {
69
69
  currentFileStack.pop();
70
70
  return result;
71
71
  } catch ( e ) {
72
- process.stderr.write( `\n${ e }` );
72
+ process.stderr.write( `\n${ inputFile }: ${ e }` );
73
73
  process.stderr.write( '\n' );
74
74
  process.exit( 1 );
75
75
  }
@@ -1,7 +1,7 @@
1
1
  const getSymbolTagsByName = require( './get-symbol-tags-by-name' );
2
2
 
3
3
  /**
4
- * Returns true if, given a symbol object, it contains a @ignore tag, or false
4
+ * Returns true if, given a symbol object, it contains a `@ignore` tag, or false
5
5
  * otherwise.
6
6
  *
7
7
  * @param {Object} symbol Symbol object.
@@ -1,7 +1,7 @@
1
1
  const getSymbolTagsByName = require( './get-symbol-tags-by-name' );
2
2
 
3
3
  /**
4
- * Returns true if, given a symbol object, it contains a @private tag, or false
4
+ * Returns true if, given a symbol object, it contains a `@private` tag, or false
5
5
  * otherwise.
6
6
  *
7
7
  * @param {Object} symbol Symbol object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/docgen",
3
- "version": "2.57.0",
3
+ "version": "4.0.0",
4
4
  "description": "Autogenerate public API documentation from exports and JSDoc comments.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/WordPress/gutenberg/issues"
21
21
  },
22
22
  "engines": {
23
- "node": ">=18.12.0"
23
+ "node": ">=22.13.0"
24
24
  },
25
25
  "files": [
26
26
  "bin",
@@ -33,7 +33,8 @@
33
33
  "docgen": "./bin/cli.js"
34
34
  },
35
35
  "dependencies": {
36
- "@babel/core": "^7.25.7",
36
+ "@babel/parser": "^7.28.6",
37
+ "@babel/types": "^7.29.7",
37
38
  "comment-parser": "^1.1.1",
38
39
  "mdast-util-inject": "^1.1.0",
39
40
  "optionator": "^0.8.2",
@@ -42,11 +43,10 @@
42
43
  "unified": "^7.1.0"
43
44
  },
44
45
  "devDependencies": {
45
- "@types/babel__core": "^7.20.5",
46
- "vitest": "^5.0.3"
46
+ "vitest": "^5.0.5"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "12441e2520c78b2254a792a8cba40c34110be060"
51
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
52
52
  }