@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 +5 -5
- package/lib/engine.js +11 -2
- package/lib/get-leading-comments.js +2 -2
- package/lib/get-type-annotation.js +2 -2
- package/lib/index.js +1 -1
- package/lib/is-symbol-ignore.js +1 -1
- package/lib/is-symbol-private.js +1 -1
- package/package.json +6 -6
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
|
|
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
|
|
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><!-- START TOKEN(my-api) --></code> and the end token <code><!-- END TOKEN(my-api) --></code>. Depends on `--to-token`.
|
|
42
42
|
- **--debug**: Run in debug mode, which outputs some intermediate files useful for debugging.
|
|
43
43
|
|
|
44
|
-
###
|
|
44
|
+
### Supported syntax
|
|
45
45
|
|
|
46
|
-
`@wordpress/docgen`
|
|
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
|
-
|
|
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
|
|
1
|
+
const { parse } = require( '@babel/parser' );
|
|
2
2
|
const getIntermediateRepresentation = require( './get-intermediate-representation' );
|
|
3
3
|
|
|
4
4
|
const getAST = ( source, filename ) => {
|
|
5
|
-
|
|
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
|
|
3
|
+
* of an AST node.
|
|
4
4
|
*
|
|
5
|
-
* @param {import('@babel/
|
|
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
|
|
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/
|
|
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
|
}
|
package/lib/is-symbol-ignore.js
CHANGED
|
@@ -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
|
|
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.
|
package/lib/is-symbol-private.js
CHANGED
|
@@ -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
|
|
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": "
|
|
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": ">=
|
|
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/
|
|
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
|
-
"
|
|
46
|
-
"vitest": "^5.0.3"
|
|
46
|
+
"vitest": "^5.0.5"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
|
|
52
52
|
}
|