File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 44 *
55 * Usage: node scripts/count-async-functions.mjs
66 */
7+ import { readFileSync } from 'node:fs' ;
78import { Project , SyntaxKind } from 'ts-morph' ;
89
10+ function getSourcePathsFromPackageJson ( ) {
11+ const packageJsonPath = new URL ( '../../package.json' , import . meta. url ) ;
12+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) ;
13+ const paths = packageJson . countAsyncSourcePaths ;
14+
15+ if ( Array . isArray ( paths ) && paths . length > 0 && paths . every ( p => typeof p === 'string' ) ) {
16+ return paths ;
17+ }
18+
19+ throw new Error ( 'package.json must define a non-empty string array "countAsyncSourcePaths"' ) ;
20+ }
21+
922const project = new Project ( {
1023 compilerOptions : {
1124 allowJs : true ,
@@ -14,14 +27,7 @@ const project = new Project({
1427 skipAddingFilesFromTsConfig : true ,
1528} ) ;
1629
17- project . addSourceFilesAtPaths ( [
18- 'lib/**/*.js' ,
19- 'index.js' ,
20- 'dataserver.js' ,
21- 'mdserver.js' ,
22- 'managementAgent.js' ,
23- 'bin/**/*.js'
24- ] ) ;
30+ project . addSourceFilesAtPaths ( getSourcePathsFromPackageJson ( ) ) ;
2531
2632let asyncFunctions = 0 ;
2733let totalFunctions = 0 ;
Original file line number Diff line number Diff line change 8888 "jsonwebtoken" : " ^9.0.0" ,
8989 "nan" : " v2.22.0"
9090 },
91+ "countAsyncSourcePaths" : [
92+ " lib/**/*.js" ,
93+ " index.js" ,
94+ " dataserver.js" ,
95+ " mdserver.js" ,
96+ " managementAgent.js" ,
97+ " bin/**/*.js"
98+ ],
9199 "mocha" : {
92100 "recursive" : true ,
93101 "timeout" : 40000
You can’t perform that action at this time.
0 commit comments