@@ -146,12 +146,13 @@ function withoutExtension(str: string, ext: string): string {
146146/** Returns a map from filename (path relative to `directory`) to the SourceFile we parsed for it. */
147147export function allReferencedFiles (
148148 entryFilenames : ReadonlyArray < string > , fs : FS , packageName : string , baseDirectory : string ,
149- ) : { types : Map < string , ts . SourceFile > , tests : Map < string , ts . SourceFile > } {
149+ ) : { types : Map < string , ts . SourceFile > , tests : Map < string , ts . SourceFile > , hasNonRelativeReference : boolean } {
150150 const seenReferences = new Set < string > ( ) ;
151151 const types = new Map < string , ts . SourceFile > ( ) ;
152152 const tests = new Map < string , ts . SourceFile > ( ) ;
153+ let hasNonRelativeReference = false ;
153154 entryFilenames . forEach ( text => recur ( { text, exact : true } ) ) ;
154- return { types, tests } ;
155+ return { types, tests, hasNonRelativeReference } ;
155156
156157 function recur ( { text, exact } : Reference ) : void {
157158 if ( seenReferences . has ( text ) ) {
@@ -168,13 +169,14 @@ export function allReferencedFiles(
168169 tests . set ( resolvedFilename , src ) ;
169170 }
170171
171- const refs = findReferencedFiles (
172+ const { refs, hasNonRelativeReference : result } = findReferencedFiles (
172173 src ,
173174 packageName ,
174175 path . dirname ( resolvedFilename ) ,
175176 normalizeSlashes ( path . relative ( baseDirectory , fs . debugPath ( ) ) ) ,
176177 ) ;
177178 refs . forEach ( recur ) ;
179+ hasNonRelativeReference = hasNonRelativeReference || result ;
178180 }
179181 }
180182
@@ -210,6 +212,7 @@ interface Reference {
210212 */
211213function findReferencedFiles ( src : ts . SourceFile , packageName : string , subDirectory : string , baseDirectory : string ) {
212214 const refs : Reference [ ] = [ ] ;
215+ let hasNonRelativeReference = false ;
213216
214217 for ( const ref of src . referencedFiles ) {
215218 // Any <reference path="foo"> is assumed to be local
@@ -232,7 +235,7 @@ function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirecto
232235 addReference ( { text : convertToRelativeReference ( ref ) , exact : false } ) ;
233236 }
234237 }
235- return refs ;
238+ return { refs, hasNonRelativeReference } ;
236239
237240 function addReference ( ref : Reference ) : void {
238241 // `path.normalize` may add windows slashes
@@ -256,6 +259,7 @@ function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirecto
256259
257260 /** boring/foo -> ./foo when subDirectory === '.'; ../foo when it's === 'x'; ../../foo when it's 'x/y' */
258261 function convertToRelativeReference ( name : string ) {
262+ hasNonRelativeReference = true ;
259263 const relative = "." + "/.." . repeat ( subDirectory === "." ? 0 : subDirectory . split ( "/" ) . length ) ;
260264 return relative + name . slice ( packageName . length ) ;
261265 }
0 commit comments