Skip to content

Commit 6cbb47e

Browse files
committed
Add comments
1 parent 795f731 commit 6cbb47e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/ci-test/check-paths.ts

+22
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import { existsSync } from 'fs';
2020
import { resolve } from 'path';
2121
import { projectRoot as root } from '../utils';
2222

23+
/**
24+
* Top level fields in package.json that may point to entry point and
25+
* typings files.
26+
*/
2327
const TOP_LEVEL_FIELDS = [
2428
'main',
2529
'browser',
@@ -40,6 +44,10 @@ interface Result {
4044
}
4145
const results: Result[] = [];
4246

47+
/**
48+
* Get paths to packages. Only check the ones we actually
49+
* publish (packages/*).
50+
*/
4351
function getPaths(): Promise<string[]> {
4452
return new Promise((resolve, reject) => {
4553
glob('packages/*', (err, paths) => {
@@ -49,6 +57,9 @@ function getPaths(): Promise<string[]> {
4957
});
5058
}
5159

60+
/**
61+
* Recursively check `exports` field in package.json.
62+
*/
5263
function checkExports(
5364
pkgName: string,
5465
pkgRoot: string,
@@ -81,10 +92,15 @@ function checkExports(
8192

8293
async function main() {
8394
const paths = await getPaths();
95+
8496
for (const path of paths) {
8597
const pkgRoot = `${root}/${path}`;
8698
if (existsSync(`${pkgRoot}/package.json`)) {
8799
const pkg = require(`${pkgRoot}/package.json`);
100+
101+
/**
102+
* Check top level fields.
103+
*/
88104
for (const field of TOP_LEVEL_FIELDS) {
89105
if (pkg[field]) {
90106
const filePath = resolve(pkgRoot, pkg[field]);
@@ -100,6 +116,9 @@ async function main() {
100116
results.push(result);
101117
}
102118
}
119+
/**
120+
* Check all levels of exports field.
121+
*/
103122
if (pkg.exports) {
104123
checkExports(pkg.name, pkgRoot, '', pkg.exports);
105124
}
@@ -118,6 +137,9 @@ async function main() {
118137
}
119138
}
120139

140+
/**
141+
* Fail CI if any missing paths found.
142+
*/
121143
if (missingPaths) {
122144
process.exit(1);
123145
}

0 commit comments

Comments
 (0)