@@ -15,6 +15,8 @@ import {
15
15
uniq ,
16
16
updateFile ,
17
17
workspaceConfigName ,
18
+ setCurrentProjName ,
19
+ runCreateWorkspace ,
18
20
} from '@nrwl/e2e/utils' ;
19
21
20
22
forEachCli ( ( cli ) => {
@@ -666,6 +668,147 @@ forEachCli((cli) => {
666
668
`import { fromLibOne } from '@proj/shared/${ lib1 } /data-access';`
667
669
) ;
668
670
} ) ;
671
+
672
+ it ( 'should work for custom workspace layouts' , ( ) => {
673
+ const lib1 = uniq ( 'mylib' ) ;
674
+ const lib2 = uniq ( 'mylib' ) ;
675
+ const lib3 = uniq ( 'mylib' ) ;
676
+ newProject ( ) ;
677
+
678
+ let nxJson = readJson ( 'nx.json' ) ;
679
+ nxJson . workspaceLayout = { libsDir : 'packages' } ;
680
+ updateFile ( 'nx.json' , JSON . stringify ( nxJson ) ) ;
681
+
682
+ runCLI ( `generate @nrwl/workspace:lib ${ lib1 } /data-access` ) ;
683
+
684
+ updateFile (
685
+ `packages/${ lib1 } /data-access/src/lib/${ lib1 } -data-access.ts` ,
686
+ `export function fromLibOne() { console.log('This is completely pointless'); }`
687
+ ) ;
688
+
689
+ updateFile (
690
+ `packages/${ lib1 } /data-access/src/index.ts` ,
691
+ `export * from './lib/${ lib1 } -data-access.ts'`
692
+ ) ;
693
+
694
+ /**
695
+ * Create a library which imports a class from lib1
696
+ */
697
+
698
+ runCLI ( `generate @nrwl/workspace:lib ${ lib2 } /ui` ) ;
699
+
700
+ updateFile (
701
+ `packages/${ lib2 } /ui/src/lib/${ lib2 } -ui.ts` ,
702
+ `import { fromLibOne } from '@proj/${ lib1 } /data-access';
703
+
704
+ export const fromLibTwo = () => fromLibOne(); }`
705
+ ) ;
706
+
707
+ /**
708
+ * Create a library which has an implicit dependency on lib1
709
+ */
710
+
711
+ runCLI ( `generate @nrwl/workspace:lib ${ lib3 } ` ) ;
712
+ nxJson = JSON . parse ( readFile ( 'nx.json' ) ) as NxJson ;
713
+ nxJson . projects [ lib3 ] . implicitDependencies = [ `${ lib1 } -data-access` ] ;
714
+ updateFile ( `nx.json` , JSON . stringify ( nxJson ) ) ;
715
+
716
+ /**
717
+ * Now try to move lib1
718
+ */
719
+
720
+ const moveOutput = runCLI (
721
+ `generate @nrwl/workspace:move --project ${ lib1 } -data-access shared/${ lib1 } /data-access`
722
+ ) ;
723
+
724
+ expect ( moveOutput ) . toContain ( `DELETE packages/${ lib1 } /data-access` ) ;
725
+ expect ( exists ( `packages/${ lib1 } /data-access` ) ) . toBeFalsy ( ) ;
726
+
727
+ const newPath = `packages/shared/${ lib1 } /data-access` ;
728
+ const newName = `shared-${ lib1 } -data-access` ;
729
+
730
+ const readmePath = `${ newPath } /README.md` ;
731
+ expect ( moveOutput ) . toContain ( `CREATE ${ readmePath } ` ) ;
732
+ checkFilesExist ( readmePath ) ;
733
+
734
+ const jestConfigPath = `${ newPath } /jest.config.js` ;
735
+ expect ( moveOutput ) . toContain ( `CREATE ${ jestConfigPath } ` ) ;
736
+ checkFilesExist ( jestConfigPath ) ;
737
+ const jestConfig = readFile ( jestConfigPath ) ;
738
+ expect ( jestConfig ) . toContain ( `name: 'shared-${ lib1 } -data-access'` ) ;
739
+ expect ( jestConfig ) . toContain ( `preset: '../../../../jest.config.js'` ) ;
740
+ expect ( jestConfig ) . toContain (
741
+ `coverageDirectory: '../../../../coverage/${ newPath } '`
742
+ ) ;
743
+
744
+ const tsConfigPath = `${ newPath } /tsconfig.json` ;
745
+ expect ( moveOutput ) . toContain ( `CREATE ${ tsConfigPath } ` ) ;
746
+ checkFilesExist ( tsConfigPath ) ;
747
+
748
+ const tsConfigLibPath = `${ newPath } /tsconfig.lib.json` ;
749
+ expect ( moveOutput ) . toContain ( `CREATE ${ tsConfigLibPath } ` ) ;
750
+ checkFilesExist ( tsConfigLibPath ) ;
751
+ const tsConfigLib = readJson ( tsConfigLibPath ) ;
752
+ expect ( tsConfigLib . compilerOptions . outDir ) . toEqual (
753
+ '../../../../dist/out-tsc'
754
+ ) ;
755
+
756
+ const tsConfigSpecPath = `${ newPath } /tsconfig.spec.json` ;
757
+ expect ( moveOutput ) . toContain ( `CREATE ${ tsConfigSpecPath } ` ) ;
758
+ checkFilesExist ( tsConfigSpecPath ) ;
759
+ const tsConfigSpec = readJson ( tsConfigSpecPath ) ;
760
+ expect ( tsConfigSpec . compilerOptions . outDir ) . toEqual (
761
+ '../../../../dist/out-tsc'
762
+ ) ;
763
+
764
+ const indexPath = `${ newPath } /src/index.ts` ;
765
+ expect ( moveOutput ) . toContain ( `CREATE ${ indexPath } ` ) ;
766
+ checkFilesExist ( indexPath ) ;
767
+
768
+ const rootClassPath = `${ newPath } /src/lib/${ lib1 } -data-access.ts` ;
769
+ expect ( moveOutput ) . toContain ( `CREATE ${ rootClassPath } ` ) ;
770
+ checkFilesExist ( rootClassPath ) ;
771
+
772
+ expect ( moveOutput ) . toContain ( 'UPDATE nx.json' ) ;
773
+ nxJson = JSON . parse ( readFile ( 'nx.json' ) ) as NxJson ;
774
+ expect ( nxJson . projects [ `${ lib1 } -data-access` ] ) . toBeUndefined ( ) ;
775
+ expect ( nxJson . projects [ newName ] ) . toEqual ( {
776
+ tags : [ ] ,
777
+ } ) ;
778
+ expect ( nxJson . projects [ lib3 ] . implicitDependencies ) . toEqual ( [
779
+ `shared-${ lib1 } -data-access` ,
780
+ ] ) ;
781
+
782
+ expect ( moveOutput ) . toContain ( 'UPDATE tsconfig.base.json' ) ;
783
+ const rootTsConfig = readJson ( 'tsconfig.base.json' ) ;
784
+ expect (
785
+ rootTsConfig . compilerOptions . paths [ `@proj/${ lib1 } /data-access` ]
786
+ ) . toBeUndefined ( ) ;
787
+ expect (
788
+ rootTsConfig . compilerOptions . paths [ `@proj/shared/${ lib1 } /data-access` ]
789
+ ) . toEqual ( [ `packages/shared/${ lib1 } /data-access/src/index.ts` ] ) ;
790
+
791
+ expect ( moveOutput ) . toContain ( `UPDATE ${ workspace } .json` ) ;
792
+ const workspaceJson = readJson ( `${ workspace } .json` ) ;
793
+ expect ( workspaceJson . projects [ `${ lib1 } -data-access` ] ) . toBeUndefined ( ) ;
794
+ const project = workspaceJson . projects [ newName ] ;
795
+ expect ( project ) . toBeTruthy ( ) ;
796
+ expect ( project . root ) . toBe ( newPath ) ;
797
+ expect ( project . sourceRoot ) . toBe ( `${ newPath } /src` ) ;
798
+ expect ( project . architect . lint . options . tsConfig ) . toEqual ( [
799
+ `packages/shared/${ lib1 } /data-access/tsconfig.lib.json` ,
800
+ `packages/shared/${ lib1 } /data-access/tsconfig.spec.json` ,
801
+ ] ) ;
802
+
803
+ /**
804
+ * Check that the import in lib2 has been updated
805
+ */
806
+ const lib2FilePath = `packages/${ lib2 } /ui/src/lib/${ lib2 } -ui.ts` ;
807
+ const lib2File = readFile ( lib2FilePath ) ;
808
+ expect ( lib2File ) . toContain (
809
+ `import { fromLibOne } from '@proj/shared/${ lib1 } /data-access';`
810
+ ) ;
811
+ } ) ;
669
812
} ) ;
670
813
671
814
describe ( 'Remove Project' , ( ) => {
0 commit comments