@wordpress/docgen 3.0.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
@@ -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
- 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.
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 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
- const config = babel.loadPartialConfig( { filename } );
6
5
  const isTypeScript = /\.[cm]?tsx?$/.test( filename );
7
6
  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;
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 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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/docgen",
3
- "version": "3.0.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",
@@ -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": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
51
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
52
52
  }