2024-03-22 13:08:26 +01:00
import { readdirSync , statSync } from 'fs' ;
import { join } from 'path' ;
const PROJECT _DIR = process . argv [ 2 ] ? ? '.' ;
const MAX _PATH _LENGTH = process . argv [ 3 ] ? ? 140 ;
const IS _CI = process . env . CI === 'true' ;
2024-03-22 14:03:02 +01:00
const IS _AZURE _PIPELINES = process . env . TF _BUILD === 'true' ;
2024-03-22 13:08:26 +01:00
const IS _GITHUB _ACTIONS = process . env . GITHUB _ACTIONS === 'true' ;
const FILE _PATH _COLOR = '\x1b[36m%s\x1b[0m' ;
console . log ( ` Checking path length in ${ PROJECT _DIR } for paths exceeding ${ MAX _PATH _LENGTH } ... ` ) ;
console . log ( 'CI detected:' , IS _CI ) ;
console . log ( '\n-----------------------------------' ) ;
console . log ( 'Results:' ) ;
console . log ( '-----------------------------------\n' ) ;
function checkPathLength ( dir ) {
const files = readdirSync ( dir ) ;
files . forEach ( file => {
const filePath = join ( dir , file ) ;
if ( filePath . length > MAX _PATH _LENGTH ) {
if ( IS _CI ) {
2024-03-22 13:19:02 +01:00
//process.exitCode = 1; // TODO: Uncomment this line to fail the build
2024-03-22 13:08:26 +01:00
}
if ( IS _AZURE _PIPELINES ) {
2024-03-22 13:49:53 +01:00
console . error ( ` ##vso[task.logissue type=warning;sourcepath= ${ filePath } ;]Path exceeds maximum length of ${ MAX _PATH _LENGTH } characters: ${ filePath } with ${ filePath . length } characters ` ) ;
2024-03-22 13:08:26 +01:00
} else if ( IS _GITHUB _ACTIONS ) {
2024-03-22 14:01:42 +01:00
console . error ( ` ::warning file= ${ filePath } ,title=Path exceeds ${ MAX _PATH _LENGTH } characters::Paths should not be longer than ${ MAX _PATH _LENGTH } characters to support WIN32 systems. The file ${ filePath } exceeds that with ${ filePath . length - MAX _PATH _LENGTH } characters. ` ) ;
2024-03-22 13:08:26 +01:00
} else {
2024-03-22 13:47:40 +01:00
console . error ( ` Path exceeds maximum length of ${ MAX _PATH _LENGTH } characters: ${ FILE _PATH _COLOR } ` , filePath , filePath . length - MAX _PATH _LENGTH ) ;
2024-03-22 13:08:26 +01:00
}
}
if ( statSync ( filePath ) . isDirectory ( ) ) {
checkPathLength ( filePath , MAX _PATH _LENGTH ) ;
}
} ) ;
}
checkPathLength ( PROJECT _DIR , MAX _PATH _LENGTH ) ;