@@ -20,6 +20,10 @@ import { existsSync } from 'fs';
20
20
import { resolve } from 'path' ;
21
21
import { projectRoot as root } from '../utils' ;
22
22
23
+ /**
24
+ * Top level fields in package.json that may point to entry point and
25
+ * typings files.
26
+ */
23
27
const TOP_LEVEL_FIELDS = [
24
28
'main' ,
25
29
'browser' ,
@@ -40,6 +44,10 @@ interface Result {
40
44
}
41
45
const results : Result [ ] = [ ] ;
42
46
47
+ /**
48
+ * Get paths to packages. Only check the ones we actually
49
+ * publish (packages/*).
50
+ */
43
51
function getPaths ( ) : Promise < string [ ] > {
44
52
return new Promise ( ( resolve , reject ) => {
45
53
glob ( 'packages/*' , ( err , paths ) => {
@@ -49,6 +57,9 @@ function getPaths(): Promise<string[]> {
49
57
} ) ;
50
58
}
51
59
60
+ /**
61
+ * Recursively check `exports` field in package.json.
62
+ */
52
63
function checkExports (
53
64
pkgName : string ,
54
65
pkgRoot : string ,
@@ -81,10 +92,15 @@ function checkExports(
81
92
82
93
async function main ( ) {
83
94
const paths = await getPaths ( ) ;
95
+
84
96
for ( const path of paths ) {
85
97
const pkgRoot = `${ root } /${ path } ` ;
86
98
if ( existsSync ( `${ pkgRoot } /package.json` ) ) {
87
99
const pkg = require ( `${ pkgRoot } /package.json` ) ;
100
+
101
+ /**
102
+ * Check top level fields.
103
+ */
88
104
for ( const field of TOP_LEVEL_FIELDS ) {
89
105
if ( pkg [ field ] ) {
90
106
const filePath = resolve ( pkgRoot , pkg [ field ] ) ;
@@ -100,6 +116,9 @@ async function main() {
100
116
results . push ( result ) ;
101
117
}
102
118
}
119
+ /**
120
+ * Check all levels of exports field.
121
+ */
103
122
if ( pkg . exports ) {
104
123
checkExports ( pkg . name , pkgRoot , '' , pkg . exports ) ;
105
124
}
@@ -118,6 +137,9 @@ async function main() {
118
137
}
119
138
}
120
139
140
+ /**
141
+ * Fail CI if any missing paths found.
142
+ */
121
143
if ( missingPaths ) {
122
144
process . exit ( 1 ) ;
123
145
}
0 commit comments