@@ -34,13 +34,22 @@ async function main(
34
34
stripExportPattern : RegExp ,
35
35
typeNames : string [ ] ,
36
36
) {
37
+ /** Whether the goldenDir provided is actually pointing to a single file. */
38
+ const singleFileMode = fs . existsSync ( goldenDir ) && fs . statSync ( goldenDir ) . isFile ( ) ;
37
39
// TODO(ESM) This can be replaced with an actual ESM import when `ts_library` is
38
40
// guaranteed to be ESM-only and supports the `mts` extension.
39
41
const chalk = { red : ( v : string ) => v , yellow : ( v : string ) => v } ;
40
42
41
43
const packageJsonPath = path . join ( npmPackageDir , 'package.json' ) ;
42
44
const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) as PackageJson ;
43
45
const entryPoints = findEntryPointsWithinNpmPackage ( npmPackageDir , packageJson ) ;
46
+ if ( entryPoints . length === 0 ) {
47
+ console . error (
48
+ 'No entry points were found in the provided package for determining the API surface.' ,
49
+ ) ;
50
+ process . exitCode = 3 ;
51
+ return ;
52
+ }
44
53
const worker = new Piscina < Parameters < typeof testApiGolden > , string > ( {
45
54
filename : path . resolve ( __dirname , './test_api_report.js' ) ,
46
55
} ) ;
@@ -50,7 +59,11 @@ async function main(
50
59
// entry-point we maintain a separate golden file. These golden files are
51
60
// based on the name of the defining NodeJS exports subpath in the NPM package,
52
61
// See: https://api-extractor.com/pages/overview/demo_api_report/.
53
- const goldenName = path . join ( subpath , 'index.api.md' ) ;
62
+ let goldenName = path . join ( subpath , 'index.api.md' ) ;
63
+ // In single file mode, the subpath is the golden file.
64
+ if ( singleFileMode ) {
65
+ goldenName = subpath ;
66
+ }
54
67
const goldenFilePath = path . join ( goldenDir , goldenName ) ;
55
68
const moduleName = normalizePathToPosix ( path . join ( packageJson . name , subpath ) ) ;
56
69
@@ -105,14 +118,28 @@ async function main(
105
118
const allTestsSucceeding = results . every ( ( r ) => r === true ) ;
106
119
107
120
if ( outdatedGoldens . length ) {
108
- console . error ( chalk . red ( `The following goldens are outdated:` ) ) ;
109
- outdatedGoldens . forEach ( ( name ) => console . info ( `- ${ name } ` ) ) ;
110
- console . info ( ) ;
111
- console . info (
112
- chalk . yellow (
113
- `The goldens can be updated by running: yarn bazel run ${ process . env . TEST_TARGET } .accept` ,
114
- ) ,
115
- ) ;
121
+ console . error ( ) ;
122
+ console . error ( Array ( 80 ) . fill ( '=' ) . join ( '' ) ) ;
123
+ console . error ( `${ Array ( 35 ) . fill ( '=' ) . join ( '' ) } RESULTS ${ Array ( 36 ) . fill ( '=' ) . join ( '' ) } ` ) ;
124
+ console . error ( Array ( 80 ) . fill ( '=' ) . join ( '' ) ) ;
125
+ if ( singleFileMode ) {
126
+ console . error (
127
+ chalk . red (
128
+ `The golden is out of date and can be updated by running:\n - yarn bazel run ${ process . env . TEST_TARGET } .accept` ,
129
+ ) ,
130
+ ) ;
131
+ } else {
132
+ console . error ( chalk . red ( `The following goldens are outdated:` ) ) ;
133
+ outdatedGoldens . forEach ( ( name ) => console . info ( `- ${ name } ` ) ) ;
134
+ console . info ( ) ;
135
+ console . info (
136
+ chalk . yellow (
137
+ `The goldens can be updated by running:\n - yarn bazel run ${ process . env . TEST_TARGET } .accept` ,
138
+ ) ,
139
+ ) ;
140
+ }
141
+ console . error ( Array ( 80 ) . fill ( '=' ) . join ( '' ) ) ;
142
+ console . error ( ) ;
116
143
}
117
144
118
145
// Bazel expects `3` as exit code for failing tests.
0 commit comments