1- import { readFileSync } from "node:fs" ;
1+ import { existsSync , readdirSync , readFileSync } from "node:fs" ;
2+ import { join } from "node:path" ;
23
34interface PackageJson {
45 version ?: unknown ;
@@ -9,6 +10,7 @@ interface ReleaseSanityInput {
910 packageJson : PackageJson ;
1011 changelog : string ;
1112 githubRef ?: string ;
13+ distFiles ?: string [ ] ;
1214}
1315
1416export function checkReleaseSanity ( input : ReleaseSanityInput ) : string [ ] {
@@ -39,9 +41,24 @@ export function checkReleaseSanity(input: ReleaseSanityInput): string[] {
3941 }
4042 }
4143
44+ for ( const file of input . distFiles ?? [ ] ) {
45+ if ( isForbiddenDistArtifact ( file ) ) {
46+ errors . push ( `dist must not include test-only artifact ${ file } .` ) ;
47+ }
48+ }
49+
4250 return errors ;
4351}
4452
53+ function isForbiddenDistArtifact ( file : string ) : boolean {
54+ return (
55+ file . endsWith ( ".test.js" ) ||
56+ file === "server/test-harness.js" ||
57+ file === "coverage-threshold.js" ||
58+ file === "release-sanity.js"
59+ ) ;
60+ }
61+
4562function escapeRegExp ( value : string ) : string {
4663 return value . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
4764}
@@ -55,6 +72,7 @@ function runReleaseSanityCli(): void {
5572 packageJson : readPackageJson ( ) ,
5673 changelog : readFileSync ( "CHANGELOG.md" , "utf8" ) ,
5774 githubRef : process . env . GITHUB_REF ,
75+ distFiles : listDistFiles ( ) ,
5876 } ) ;
5977
6078 if ( errors . length > 0 ) {
@@ -67,6 +85,25 @@ function runReleaseSanityCli(): void {
6785 console . log ( "Release sanity OK" ) ;
6886}
6987
88+ function listDistFiles ( ) : string [ ] {
89+ if ( ! existsSync ( "dist" ) ) return [ ] ;
90+
91+ const files : string [ ] = [ ] ;
92+ const walk = ( dir : string , prefix = "" ) : void => {
93+ for ( const entry of readdirSync ( dir , { withFileTypes : true } ) ) {
94+ const relative = prefix ? `${ prefix } /${ entry . name } ` : entry . name ;
95+ if ( entry . isDirectory ( ) ) {
96+ walk ( join ( dir , entry . name ) , relative ) ;
97+ } else {
98+ files . push ( relative ) ;
99+ }
100+ }
101+ } ;
102+
103+ walk ( "dist" ) ;
104+ return files ;
105+ }
106+
70107if ( import . meta. main ) {
71108 runReleaseSanityCli ( ) ;
72109}
0 commit comments