1
1
import { FileReplacement } from '@nx/angular-rspack-compiler' ;
2
2
import {
3
+ normalizePath ,
3
4
readCachedProjectGraph ,
4
5
type ProjectGraphProjectNode ,
5
6
} from '@nx/devkit' ;
@@ -14,10 +15,6 @@ import {
14
15
relative ,
15
16
resolve ,
16
17
} from 'node:path' ;
17
- import {
18
- createProjectRootMappings ,
19
- findProjectForPath ,
20
- } from 'nx/src/project-graph/utils/find-project-for-path' ;
21
18
import type {
22
19
AngularRspackPluginOptions ,
23
20
AssetElement ,
@@ -523,3 +520,44 @@ function getProject(root: string): ProjectGraphProjectNode | undefined {
523
520
524
521
return projectGraph . nodes [ projectName ] ;
525
522
}
523
+
524
+ function createProjectRootMappings (
525
+ nodes : Record < string , ProjectGraphProjectNode >
526
+ ) : Map < string , string > {
527
+ const projectRootMappings = new Map < string , string > ( ) ;
528
+ for ( const projectName of Object . keys ( nodes ) ) {
529
+ const root = nodes [ projectName ] . data . root ;
530
+
531
+ projectRootMappings . set ( normalizeProjectRoot ( root ) , projectName ) ;
532
+ }
533
+ return projectRootMappings ;
534
+ }
535
+
536
+ function findProjectForPath (
537
+ filePath : string ,
538
+ projectRootMap : Map < string , string >
539
+ ) : string | undefined {
540
+ /**
541
+ * Project Mappings are in UNIX-style file paths
542
+ * Windows may pass Win-style file paths
543
+ * Ensure filePath is in UNIX-style
544
+ */
545
+ let currentPath = normalizePath ( filePath ) ;
546
+ for (
547
+ ;
548
+ currentPath != dirname ( currentPath ) ;
549
+ currentPath = dirname ( currentPath )
550
+ ) {
551
+ const p = projectRootMap . get ( currentPath ) ;
552
+ if ( p ) {
553
+ return p ;
554
+ }
555
+ }
556
+
557
+ return projectRootMap . get ( currentPath ) ;
558
+ }
559
+
560
+ function normalizeProjectRoot ( root : string ) {
561
+ root = root === '' ? '.' : root ;
562
+ return root && root . endsWith ( '/' ) ? root . substring ( 0 , root . length - 1 ) : root ;
563
+ }
0 commit comments