@wordpress/docgen 3.0.0 → 4.1.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 +3 -3
- package/lib/engine.js +9 -11
- package/lib/get-leading-comments.js +2 -2
- package/lib/get-type-annotation.js +2 -2
- package/lib/index.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -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,19 +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
|
-
const config = babel.loadPartialConfig( { filename } );
|
|
6
5
|
const isTypeScript = /\.[cm]?tsx?$/.test( filename );
|
|
7
6
|
const supportsJSX = ! isTypeScript || filename.endsWith( '.tsx' );
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return babel.parse( source, { filename, parserOpts } ).program;
|
|
7
|
+
return parse( source, {
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
sourceFilename: filename,
|
|
10
|
+
plugins: [
|
|
11
|
+
...( isTypeScript ? [ 'typescript' ] : [] ),
|
|
12
|
+
...( supportsJSX ? [ 'jsx' ] : [] ),
|
|
13
|
+
],
|
|
14
|
+
} ).program;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/docgen",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.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",
|
|
@@ -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.1.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
52
52
|
}
|