angulartypescriptangular-cliangular-workspace-configuration

How can I prevent cross-project in Angular workspace?


Let's say I have a project with a given structure:

projects
|-app1
|-app2
|-common
node_modules
pakcage.json
tsconfig.json
angular.json
... (rest of the root files)

Now in a files in app1 I can put something like this: import { Repository } from '../../../app2/src/app/query/repository'; Even though it works (builds properly), I would like to avoid such imports in case e.g. at some time one of the project is moved to separate repo and generally to preserve clean project structure.

Is there any way to instruct angular/typescript to throw an error during serve/build, that cross -project imports are not allowed?


Solution

  • Found a solution for that - it's import-blacklist property in tslint.json. In my scenario it looks like:

    {
      "extends": "../../tslint.json",
      "rules": {
        "no-output-native": false,
        "import-blacklist": [true,
          [".*the-other-project.*"]
        ]
      }
    }