@@ -7,6 +7,15 @@ const { spawnSync } = require('child_process');
77const repositoryRootPath = path . resolve ( __dirname , '..' ) ;
88const patchesDirectoryPath = path . join ( repositoryRootPath , 'patches' ) ;
99
10+ // Detect CI environment
11+ const isCI = process . env . CI === 'true' ||
12+ process . env . GITHUB_ACTIONS === 'true' ||
13+ process . env . CIRCLECI === 'true' ||
14+ process . env . TRAVIS === 'true' ||
15+ process . env . BUILDKITE === 'true' ||
16+ process . env . GITLAB_CI === 'true' ||
17+ process . env . JENKINS_URL !== undefined ;
18+
1019function directoryContainsPatchFiles ( directoryPath ) {
1120 try {
1221 if ( ! fs . existsSync ( directoryPath ) ) return false ;
@@ -27,29 +36,92 @@ function directoryContainsPatchFiles(directoryPath) {
2736}
2837
2938function isExecutableAvailableOnPath ( executableName ) {
30- const whichCommand = process . platform === 'win32' ? 'where' : 'command -v' ;
31- const whichResult = spawnSync ( whichCommand , [ executableName ] , { shell : true , stdio : 'ignore' } ) ;
32- return whichResult . status === 0 ;
39+ // Try multiple methods to check if executable is available
40+ const commands = process . platform === 'win32'
41+ ? [ 'where' , 'where.exe' ]
42+ : [ 'command -v' , 'which' , '/usr/bin/which' ] ;
43+
44+ for ( const command of commands ) {
45+ try {
46+ const whichResult = spawnSync ( command , [ executableName ] , {
47+ shell : true ,
48+ stdio : 'ignore' ,
49+ timeout : 5000 // 5 second timeout
50+ } ) ;
51+ if ( whichResult . status === 0 ) {
52+ return true ;
53+ }
54+ } catch ( error ) {
55+ // Continue to next command
56+ continue ;
57+ }
58+ }
59+ return false ;
3360}
3461
62+ // Early exit conditions
3563if ( ! fs . existsSync ( patchesDirectoryPath ) ) {
36- console . log ( 'patch-package: patches directory not found, skipping' ) ;
64+ if ( isCI ) {
65+ console . log ( 'patch-package: patches directory not found, skipping (CI mode)' ) ;
66+ } else {
67+ console . log ( 'patch-package: patches directory not found, skipping' ) ;
68+ }
3769 process . exit ( 0 ) ;
3870}
3971
4072if ( ! directoryContainsPatchFiles ( patchesDirectoryPath ) ) {
41- console . log ( 'patch-package: no patches found, skipping' ) ;
73+ if ( isCI ) {
74+ console . log ( 'patch-package: no patches found, skipping (CI mode)' ) ;
75+ } else {
76+ console . log ( 'patch-package: no patches found, skipping' ) ;
77+ }
4278 process . exit ( 0 ) ;
4379}
4480
81+ // Check if patch-package is available
4582if ( ! isExecutableAvailableOnPath ( 'patch-package' ) ) {
46- console . log ( 'patch-package not installed, skipping' ) ;
83+ if ( isCI ) {
84+ console . log ( 'patch-package not installed, skipping (CI mode)' ) ;
85+ } else {
86+ console . log ( 'patch-package not installed, skipping' ) ;
87+ }
4788 process . exit ( 0 ) ;
4889}
4990
50- const patchRun = spawnSync ( 'patch-package' , { shell : true , stdio : 'inherit' } ) ;
51- if ( patchRun . status !== 0 ) {
52- process . exit ( patchRun . status || 1 ) ;
91+ // Run patch-package with better error handling
92+ try {
93+ const patchRun = spawnSync ( 'patch-package' , {
94+ shell : true ,
95+ stdio : isCI ? 'pipe' : 'inherit' ,
96+ timeout : 30000 // 30 second timeout
97+ } ) ;
98+
99+ if ( patchRun . status !== 0 ) {
100+ if ( isCI ) {
101+ console . log ( 'patch-package: failed to apply patches (CI mode)' ) ;
102+ console . log ( 'stdout:' , patchRun . stdout ?. toString ( ) ) ;
103+ console . log ( 'stderr:' , patchRun . stderr ?. toString ( ) ) ;
104+ // In CI, don't fail the entire build for patch issues
105+ console . log ( 'Continuing build despite patch failures...' ) ;
106+ process . exit ( 0 ) ;
107+ } else {
108+ console . error ( 'patch-package failed with exit code:' , patchRun . status ) ;
109+ process . exit ( patchRun . status || 1 ) ;
110+ }
111+ } else {
112+ if ( isCI ) {
113+ console . log ( 'patch-package: patches applied successfully (CI mode)' ) ;
114+ }
115+ }
116+ } catch ( error ) {
117+ if ( isCI ) {
118+ console . log ( 'patch-package: error during execution (CI mode):' , error . message ) ;
119+ console . log ( 'Continuing build despite patch errors...' ) ;
120+ process . exit ( 0 ) ;
121+ } else {
122+ console . error ( 'patch-package error:' , error . message ) ;
123+ process . exit ( 1 ) ;
124+ }
53125}
54126
55127process . exit ( 0 ) ;
0 commit comments