Created
January 17, 2023 09:55
-
-
Save juristr/3f93cc7f1cc056ff6301d4c9b79febb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
formatFiles, | |
getProjects, | |
logger, | |
Tree, | |
updateProjectConfiguration | |
} from '@nrwl/devkit'; | |
/** | |
* Angular Material relies on the projects to have either a build target | |
* with a tsconfig or alternatively a test target with a tsconfig. | |
* Details here: https://github.com/angular/components/blob/9107ac078b6aadd5c1a57dc31a9d57d5d1736cfd/src/cdk/schematics/ng-update/devkit-migration-rule.ts#L82-L89 | |
* | |
* Nx libs usually don't have build configs (unless they're buildable or publishable) and the according | |
* test targets don't need a reference to a tsconfig file, which is why Nx doesn't add it to the angular.json targets. | |
* This however causes Angular Material migrations to not run properly. This generator | |
* fixes the angular.json, adding a tsconfig to the test target if it doesn't exist. | |
*/ | |
export default async function (host: Tree, schema: any) { | |
const projects = getProjects(host); | |
projects.forEach((config, key) => { | |
if (config.targets['test']?.options) { | |
const tsConfig = config.targets['test'].options.tsConfig; | |
if (!tsConfig) { | |
config.targets[ | |
'test' | |
].options.tsConfig = `${config.root}/tsconfig.spec.json`; | |
updateProjectConfiguration(host, key, config); | |
logger.info(`Migrated ${key}`); | |
} | |
} | |
}); | |
await formatFiles(host); | |
} |
@craigsh oh yeah that's totally possible. this is a quick script I pulled out of my notes :). Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to check that config.targets is defined: