Skip to content

Commit 76f7e57

Browse files
authored
chore: fix ESLint errors and use types in scripts (#171)
1 parent 55d4642 commit 76f7e57

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

scripts/generate-ts-configs.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ const packagesRoot = path.join(__dirname, '..', 'packages');
1111
const fixturesRoot = path.join(__dirname, '..', 'fixtures');
1212

1313
const packageJSONMap = new Map();
14+
15+
/** @type {Map<string,string>} */
1416
const packageDirnameMap = new Map();
17+
18+
/** @type {Map<string,string>} */
1519
const internalDependencyMap = new Map();
1620

17-
const isFixture = (str) => !str.includes('api') || str.includes('fixtures');
21+
const isFixture = (/** @type {string} */ str) =>
22+
!str.includes('api') || str.includes('fixtures');
1823

1924
// collect package json for all packages
2025
packages.forEach((pkg) => {
@@ -27,6 +32,7 @@ packages.forEach((pkg) => {
2732
process.exit(1);
2833
}
2934

35+
/** @type {Record<string,string>} */
3036
const packageJSONData = JSON.parse(
3137
fs.readFileSync(packageJSONPath).toString()
3238
);
@@ -57,6 +63,8 @@ function resolveInternalDependencies(dependencies) {
5763
childDeps.push(jdep);
5864
}
5965
}
66+
67+
/** @type {Array<string>} */
6068
const resolved = childDeps.concat(dependencies);
6169
// remove all duplicated after the first appearance
6270
return resolved.filter((item, idx) => resolved.indexOf(item) === idx);
@@ -78,6 +86,7 @@ packageDirnameMap.forEach((packageDirname, packageName) => {
7886
}
7987
const overwriteMerge = (destinationArray, sourceArray) => sourceArray;
8088

89+
/** @type {Array<string>} */
8190
const internalDependencies = resolveInternalDependencies(
8291
internalDependencyMap.get(packageName)
8392
);
@@ -94,7 +103,9 @@ packageDirnameMap.forEach((packageDirname, packageName) => {
94103
emitDeclarationOnly: pkg.type === 'js' ? true : undefined
95104
},
96105
references: internalDependencies.map((dep) => {
97-
return { path: `../${packageDirnameMap.get(dep)}/tsconfig.json` };
106+
/** @type {string} */
107+
const name = packageDirnameMap.get(dep);
108+
return { path: `../${name}/tsconfig.json` };
98109
}),
99110
include: ['src'],
100111
exclude: ['lib']
@@ -117,8 +128,10 @@ const projectLevelTsconfigData = {
117128
Array.from(packageDirnameMap.keys())
118129
).map((packageName) => {
119130
const folder = isFixture(packageName) ? 'fixtures' : 'packages';
131+
/** @type {string} */
132+
const name = packageDirnameMap.get(packageName);
120133
return {
121-
path: `./${folder}/${packageDirnameMap.get(packageName)}/tsconfig.json`
134+
path: `./${folder}/${name}/tsconfig.json`
122135
};
123136
})
124137
};

scripts/runWorkspacesScripts.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import { fileURLToPath } from 'url';
44
import concurrently from 'concurrently';
55
import pc from 'picocolors';
66

7+
/**
8+
* @typedef {Object} ScriptConfig
9+
* @property {string} script
10+
* @property {number} concurrency
11+
* @property {string} folder
12+
* @property {Array<string>} filteredPackages
13+
*/
14+
15+
/**
16+
* @param {ScriptConfig} config
17+
*/
718
export function runWorkspacesScripts({
819
script,
920
concurrency,
@@ -21,9 +32,10 @@ export function runWorkspacesScripts({
2132
const pkgJsonPath = join(pkgPath, 'package.json');
2233

2334
if (fs.existsSync(pkgJsonPath)) {
35+
/** @type {{ scripts: object | undefined }} */
2436
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
2537

26-
if (pkgJson && pkgJson.scripts && pkgJson.scripts[script]) {
38+
if (pkgJson.scripts && pkgJson.scripts[script]) {
2739
packages.push(pkgPath);
2840
}
2941
}

0 commit comments

Comments
 (0)