@@ -11,6 +11,21 @@ const printModes = ["info", "warn", "error", "success", "debug"] as const;
1111export type Fn < T = void > = ( ...values : any [ ] ) => T ;
1212export type ModeMap < T > = { [ k in typeof printModes [ number ] ] : T } ;
1313
14+ // Compute the base directory of the dev-tool command package
15+ // We must do this specially for the printer module because using
16+ // the package resolution function from the utils/resolveProject
17+ // module would create a difficult circular dependency.
18+ const DEV_TOOL_PATH = ( ( ) => {
19+ const directoryFragment = path . sep + "dev-tool" + path . sep ;
20+ const parts = __dirname . split ( directoryFragment ) ;
21+ // There might be "/dev-tool/" somewhere higher in the path, so
22+ // we will slice the end off of this array and re-join with "/dev-tool/"
23+ // to get the full directory part
24+ const baseDirectoryParts = parts . slice ( 0 , - 1 ) ;
25+ // Adding path.sep at the end makes the debug output a little cleaner by removing a leading "/"
26+ return path . resolve ( baseDirectoryParts . join ( directoryFragment ) + directoryFragment ) + path . sep ;
27+ } ) ( ) ;
28+
1429/**
1530 * The interface that describes the Printer produced by {@link createPrinter}
1631 */
@@ -99,11 +114,9 @@ const finalLogger: ModeMap<Fn> = {
99114 debug ( ...values : string [ ] ) {
100115 if ( process . env . DEBUG ) {
101116 const caller = getCaller ( ) ;
102- const fileName = caller
103- ?. getFileName ( )
104- ?. split ( path . join ( "azure-sdk-for-js" , "common" , "tools" , "dev-tool" ) ) ;
117+ const fileName = caller ?. getFileName ( ) ?. split ( DEV_TOOL_PATH ) ?. [ 1 ] ;
105118 const callerInfo = `(@ ${ fileName ? fileName : "<unknown>" } #${ caller ?. getFunctionName ( ) ??
106- "<unknown >" } :${ caller ?. getLineNumber ( ) } :${ caller ?. getColumnNumber ( ) } )`;
119+ "<anonymous >" } :${ caller ?. getLineNumber ( ) } :${ caller ?. getColumnNumber ( ) } )`;
107120 backend . error ( values [ 0 ] , colors . debug ( callerInfo ) , ...values . slice ( 1 ) ) ;
108121 }
109122 } ,
0 commit comments