@@ -20,6 +20,10 @@ import { existsSync } from 'fs';
2020import { resolve } from 'path' ;
2121import { 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+ */
2327const TOP_LEVEL_FIELDS = [
2428 'main' ,
2529 'browser' ,
@@ -40,6 +44,10 @@ interface Result {
4044}
4145const results : Result [ ] = [ ] ;
4246
47+ /**
48+ * Get paths to packages. Only check the ones we actually
49+ * publish (packages/*).
50+ */
4351function 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+ */
5263function checkExports (
5364 pkgName : string ,
5465 pkgRoot : string ,
@@ -81,10 +92,15 @@ function checkExports(
8192
8293async 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