@wordpress/docgen 2.57.0 → 3.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
 
@@ -45,7 +45,7 @@ This command will generate a file named `entry-point-api.md` containing all the
45
45
 
46
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.
47
47
 
48
- Without it, `@wordpress/docgen` runs with the default option. In other words, it cannot parse JSX or other advanced syntaxes.
48
+ JSX and TypeScript are supported without a Babel configuration. TypeScript parsing follows the `.ts`, `.tsx`, `.mts`, and `.cts` file extensions. Use a Babel configuration for other syntax extensions.
49
49
 
50
50
  ## Examples
51
51
 
package/lib/engine.js CHANGED
@@ -2,7 +2,18 @@ const babel = require( '@babel/core' );
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 config = babel.loadPartialConfig( { filename } );
6
+ const isTypeScript = /\.[cm]?tsx?$/.test( filename );
7
+ const supportsJSX = ! isTypeScript || filename.endsWith( '.tsx' );
8
+ const parserOpts = config?.hasFilesystemConfig()
9
+ ? config.options.parserOpts
10
+ : {
11
+ plugins: [
12
+ ...( isTypeScript ? [ 'typescript' ] : [] ),
13
+ ...( supportsJSX ? [ 'jsx' ] : [] ),
14
+ ],
15
+ };
16
+ return babel.parse( source, { filename, parserOpts } ).program;
6
17
  };
7
18
 
8
19
  const getExportTokens = ( ast ) =>
@@ -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": "3.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",
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "12441e2520c78b2254a792a8cba40c34110be060"
51
+ "gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
52
52
  }