chore(devkit): fix root when unit testing generators wrapped as schematics (#15506)

This commit is contained in:
James Henry 2023-03-07 22:06:24 +04:00 committed by GitHub
parent bfdd2eb5b5
commit d0c38b39e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -104,7 +104,21 @@ class DevkitTreeFromAngularDevkitTree implements Tree {
private tree, private tree,
private _root: string, private _root: string,
private skipWritingConfigInOldFormat?: boolean private skipWritingConfigInOldFormat?: boolean
) {} ) {
/**
* When using the UnitTestTree from @angular-devkit/schematics/testing, the root is just `/`.
* This causes a massive issue if `getProjects()` is used in the underlying generator because it
* causes fast-glob to be set to work on the user's entire file system.
*
* Therefore, in this case, patch the root to match what Nx Devkit does and use /virtual instead.
*/
try {
const { UnitTestTree } = require('@angular-devkit/schematics/testing');
if (tree instanceof UnitTestTree && _root === '/') {
this._root = '/virtual';
}
} catch {}
}
get root(): string { get root(): string {
return this._root; return this._root;

View File

@ -55,7 +55,12 @@ const IGNORE_MATCHES_IN_PACKAGE = {
], ],
cli: ['nx'], cli: ['nx'],
cypress: ['cypress', '@angular-devkit/schematics', '@nrwl/cypress', 'vite'], cypress: ['cypress', '@angular-devkit/schematics', '@nrwl/cypress', 'vite'],
devkit: ['@angular-devkit/architect', 'rxjs', 'webpack'], devkit: [
'@angular-devkit/architect',
'@angular-devkit/schematics',
'rxjs',
'webpack',
],
'eslint-plugin-nx': ['@angular-eslint/eslint-plugin'], 'eslint-plugin-nx': ['@angular-eslint/eslint-plugin'],
jest: [ jest: [
'jest', 'jest',