Skip to content

Commit

Permalink
Fixes update-readme script (#15679)
Browse files Browse the repository at this point in the history
This PR does two things:

- Fixes #15626 and #15680 by making the script synchronous. In #15200 we missed the fact that to fill tokens within the same file we need to execute docgen synchronously, otherwise, the last token process will overwrite the first.

- Updates our espree dependency to 4.0.0. When error reporting was back, we uncovered that introducing short Fragment syntax in #15120 caused docgen to fail. The reason is that the espree version we used didn't support that. This fixes it by upgrading it to one that does. A couple of restrictions:

    - espree uses acorn-jsx to power JSX parsing.
    - acorn-jsx@4.1.0 added support for JSX fragment short syntax (patched in 4.1.1).
    - espree@4.0.0 added acorn-jsx@4.1.1. We should use this at a minimum.
    - espree@4.1.0 added acorn@6 and acorn-jsx@5 for parsing. This caused an error I couldn't identify the source.
    - espree@5.0.0 removed support for the attachComment. We use this for collocating the JSDoc comment with the proper export statement. Without this, we can't migrate to espree@5.0.0.
  • Loading branch information
nosolosw authored May 16, 2019
1 parent 304b490 commit ed630e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
19 changes: 9 additions & 10 deletions bin/update-readmes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node

const { join } = require( 'path' );
const { promisify } = require( 'util' );
const spawn = promisify( require( 'child_process' ).spawn );
const spawnSync = require( 'child_process' ).spawnSync;

const packages = [
'a11y',
Expand Down Expand Up @@ -39,15 +38,17 @@ const packages = [
'wordcount',
];

Promise.all( packages.map( ( entry ) => {
packages.forEach( ( entry ) => {
if ( ! Array.isArray( entry ) ) {
entry = [ entry, { 'Autogenerated API docs': 'src/index.js' } ];
}

const [ packageName, targets ] = entry;

return Promise.all( Object.entries( targets ).map( async ( [ token, path ] ) => {
const { status, stderr } = await spawn(
Object.entries( targets ).forEach( ( [ token, path ] ) => {
// Each target operates over the same file, so it needs to be processed synchronously,
// as to make sure the processes don't overwrite each other.
const { status, stderr } = spawnSync(
join( __dirname, '..', 'node_modules', '.bin', 'docgen' ),
[
join( 'packages', packageName, path ),
Expand All @@ -60,10 +61,8 @@ Promise.all( packages.map( ( entry ) => {
);

if ( status !== 0 ) {
throw stderr.toString();
process.stderr.write( `${ packageName } ${ stderr.toString() }\n` );
process.exit( 1 );
}
} ) );
} ) ).catch( ( error ) => {
process.stderr.write( `${ error }\n` );
process.exit( 1 );
} );
} );
26 changes: 9 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"doctrine": "2.1.0",
"enzyme": "3.9.0",
"eslint-plugin-jest": "21.5.0",
"espree": "3.5.4",
"espree": "4.0.0",
"fbjs": "0.8.17",
"glob": "7.1.2",
"husky": "0.14.3",
Expand Down

0 comments on commit ed630e8

Please sign in to comment.