Skip to content

Commit 8e5ad67

Browse files
committed
✨ add count array source path from package.json
Issue: CLDSRV-860
1 parent c4d81e1 commit 8e5ad67

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

.github/scripts/count-async-functions.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@
44
*
55
* Usage: node scripts/count-async-functions.mjs
66
*/
7+
import { readFileSync } from 'node:fs';
78
import { 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+
922
const 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

2632
let asyncFunctions = 0;
2733
let totalFunctions = 0;

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
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

0 commit comments

Comments
 (0)