@@ -3,19 +3,30 @@ import { styleText } from "node:util";
33
44const color = ( format , text ) => styleText ( format , text , { validateStream : false } ) ;
55
6- const quiet = spawnSync ( "git" , [ "diff" , "--ignore-space-at-eol" , "--text" , "--quiet" , "--" , "dist/" ] , {
7- stdio : "ignore" ,
6+ const runGit = ( args , options = { } ) =>
7+ spawnSync ( "git" , args , {
8+ encoding : "utf8" ,
9+ ...options ,
10+ } ) ;
11+
12+ // Porcelain status covers tracked edits/deletes and untracked files.
13+ // --untracked-files=normal respects .gitignore (e.g. dist/**/*.d.ts).
14+ const status = runGit ( [ "status" , "--porcelain=v1" , "--untracked-files=normal" , "--" , "dist/" ] , {
15+ stdio : [ "ignore" , "pipe" , "inherit" ] ,
816} ) ;
917
10- if ( quiet . status === 0 ) {
18+ if ( status . status !== 0 ) {
19+ console . error ( color ( "red" , "Failed to inspect dist/ git status" ) ) ;
20+ process . exit ( status . status ?? 1 ) ;
21+ }
22+
23+ if ( ! status . stdout . trim ( ) ) {
1124 console . log ( color ( "green" , "dist/ is up to date" ) ) ;
1225 process . exit ( 0 ) ;
1326}
1427
15- console . log ( "\n" ) ;
1628console . error ( color ( "red" , "Detected uncommitted changes after build. See status below:" ) ) ;
17- spawnSync ( "git" , [ "diff" , "--ignore-space-at-eol" , "--text" , "--stat" , "--" , "dist/" ] , {
18- stdio : "inherit" ,
19- } ) ;
29+ runGit ( [ "status" , "--short" , "--untracked-files=normal" , "--" , "dist/" ] , { stdio : "inherit" } ) ;
30+ runGit ( [ "diff" , "--ignore-space-at-eol" , "--text" , "--stat" , "--" , "dist/" ] , { stdio : "inherit" } ) ;
2031console . error ( color ( "red" , "dist/ is out of date. Run yarn package and commit dist/" ) ) ;
2132process . exit ( 1 ) ;
0 commit comments