This is a simple default Nx to test refactoring.
Currently, refactoring is a pain, because the IDEs do not correctly update the import statements/index.ts files.
The screenshots below show what happens in IntelliJ IDEA 2020.1, but also VsCode is not able to handle this case.
Before refactoring we have this situation:
- a simple node-js app
- lib-a
- lib-b
The focus is on file-to-move.ts in lib-a:
- the file exports a constant
TO_MOVE - the barrel file
index.tsinlib-are-exports everything fromfile-to-move.tsso that the constantTO_MOVEis also available outside oflib-a - the
main.tsfile of the node-app imports theTO_MOVEconstant using the path@nx-refactor/lib-awhich is specified intsconfig.tx
Now we move file-to-move.ts from lib-a to lib-b.
Here is the actual refactoring in IntelliJ IDEA 2020.1:
Notes:
- the barrel file
index.tsinlib-ahas been updated and now referencesfile-to-move.tsvia a relative deep import into `lib-b``. This import is forbidden by nx - libraries must not use deep imports in to other libraries.
Expected Refactoring
This is the expected refactoring tha should happen instead:
Notes:
- the export of
file-to-move.tsmust be removed from barrel fileindex.tsinlib-a, sincefile-to-move.tsis not part of the library anymore - a new export for
file-to-move.tsmust be added to the barrel fileindex.tsinlib-b - all import statements - in this case only in
main.txmust be updated to the new path:@nx-refactor/lib-b
Additional info
- after cloning the project run
yarn install - to build the app run
nx build app - to serve the app run
nx serve app
References:


