1- const glob = require ( 'glob' ) ;
1+ const fastGlob = require ( 'fast- glob' ) ;
22const path = require ( 'path' ) ;
33const fs = require ( 'fs' ) ;
44const yaml = require ( 'js-yaml' ) ;
5- const minimatch = require ( 'minimatch' ) ;
5+ const { minimatch } = require ( 'minimatch' ) ;
66const {
77 parse,
88 stringify,
@@ -41,19 +41,7 @@ const getAllPackageJsons = async (workspaces, cwd) => {
4141 } ) ;
4242
4343 return Promise . all (
44- workspaceGlobs . map (
45- ( workspace ) =>
46- new Promise ( ( resolve , reject ) => {
47- glob ( `${ workspace } /${ PACKAGE_JSON } ` , { cwd } , ( error , files ) => {
48- if ( error ) {
49- reject ( error ) ;
50- }
51- resolve ( files ) ;
52- } ) ;
53- } ) ,
54-
55- [ ]
56- )
44+ workspaceGlobs . map ( ( workspace ) => fastGlob ( `${ workspace } /${ PACKAGE_JSON } ` , { cwd, onlyFiles : true } ) )
5745 )
5846 . then ( ( allPackages ) =>
5947 allPackages . reduce (
@@ -216,7 +204,7 @@ const updateTsConfig = (
216204 if ( createPathMappings )
217205 assert . deepEqual ( JSON . parse ( JSON . stringify ( config ?. compilerOptions ?. paths ?? { } ) ) , paths ) ;
218206 isEqual = true ;
219- } catch ( e ) {
207+ } catch {
220208 // ignore me
221209 }
222210 if ( ! isEqual ) {
@@ -243,7 +231,7 @@ const updateTsConfig = (
243231 } catch ( error ) {
244232 console . error ( `could not read ${ tsconfigFilePath } ` , error ) ;
245233 if ( strict )
246- throw new Error ( 'Expect always a tsconfig.json in the package directory while running in strict mode' )
234+ throw new Error ( 'Expect always a tsconfig.json in the package directory while running in strict mode' , { cause : error } )
247235 }
248236} ;
249237
@@ -269,7 +257,6 @@ const execute = async ({
269257 ...configurable
270258} ) => {
271259 let changesCount = 0 ;
272- // eslint-disable-next-line no-console
273260 console . log ( 'updating tsconfigs' ) ;
274261 const packageJson = require ( path . join ( cwd , PACKAGE_JSON ) ) ;
275262
@@ -336,10 +323,11 @@ const execute = async ({
336323 console . log ( 'packagesMap' , packagesMap ) ;
337324 }
338325
339- let rootReferences = [ ] ;
340- let rootPaths = [ ] ;
341326 let tsconfigMap = { }
342327 let jsconfigMap = { }
328+ const referencesMap = { }
329+ const referencedPackageNames = new Set ( )
330+ const rootReferenceCandidates = [ ]
343331 packagesMap . forEach ( ( packageEntry , packageName ) => {
344332 const detectedConfig = detectTSConfig ( packageEntry . packageDir , configName , packageEntry . hasTsEntry && createTsConfig , cwd )
345333
@@ -379,18 +367,20 @@ const execute = async ({
379367 const detectedConfig = tsconfigMap [ packageName ] ?. detectedConfig
380368
381369 if ( detectedConfig ) {
382- rootReferences . push ( {
370+ rootReferenceCandidates . push ( ensurePosixPathStyle ( {
383371 name : packageName ,
384372 path : path . join ( path . relative ( cwd , packageEntry . packageDir ) , detectedConfig !== TSCONFIG_JSON ? detectedConfig : '' ) ,
385373 folder : path . relative ( cwd , packageEntry . packageDir ) ,
386- } ) ;
374+ } ) ) ;
387375 const references = ( getReferencesFromDependencies (
388376 configName ,
389377 packageEntry ,
390378 packageName ,
391379 packagesMap ,
392380 verbose
393381 ) || [ ] ) . map ( ensurePosixPathStyle ) ;
382+ referencesMap [ packageName ] = references
383+ references . forEach ( ( { name } ) => referencedPackageNames . add ( name ) )
394384
395385 const paths = getPathsFromReferences ( references , tsconfigMap , jsconfigMap , ignorePathMappings )
396386
@@ -411,19 +401,13 @@ const execute = async ({
411401 } else {
412402 const detectedJsConfig = jsconfigMap [ packageName ] ?. detectedConfig
413403 if ( ! detectedJsConfig ) {
414- // eslint-disable-next-line no-console
415404 console . log ( `NO ${ configName === TSCONFIG_JSON ? configName : `${ configName } nor ${ TSCONFIG_JSON } ` } for ${ packageName } ` ) ;
416405 }
417- rootPaths . push ( {
418- name : packageName ,
419- path : path . relative ( cwd , packageEntry . packageDir ) ,
420- folder : path . relative ( cwd , packageEntry . packageDir ) ,
421- } ) ;
422406 }
423407 } ) ;
424408
425- rootReferences = ( rootReferences || [ ] ) . map ( ensurePosixPathStyle ) ;
426- rootPaths = getPathsFromReferences ( ( rootReferences || [ ] ) . map ( ensurePosixPathStyle ) , tsconfigMap , { } , ignorePathMappings )
409+ const rootReferences = rootReferenceCandidates . filter ( ( { name } ) => ! referencedPackageNames . has ( name ) ) ;
410+ const rootPaths = getPathsFromReferences ( rootReferences , tsconfigMap , { } , ignorePathMappings )
427411
428412 if ( verbose ) {
429413 console . log ( 'rootReferences' , rootReferences ) ;
0 commit comments