-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nx): exclude files from outside the project root when linting
- Loading branch information
1 parent
1748ac9
commit 2f27cc2
Showing
18 changed files
with
195 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"schematics": {} | ||
"schematics": { | ||
"update-8.2.0": { | ||
"version": "8.2.0-beta.1", | ||
"description": "Add exclusions to lint config", | ||
"factory": "./src/migrations/update-8-2-0/update-8-2-0" | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/workspace/src/migrations/update-8-2-0/update-8-2-0.spec.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { callRule, runMigration } from '../../utils/testing'; | ||
import { | ||
readJsonInTree, | ||
updateJsonInTree | ||
} from '@nrwl/workspace/src/utils/ast-utils'; | ||
|
||
describe('Update 8.2.0', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = createEmptyWorkspace(Tree.empty()); | ||
tree = await callRule( | ||
updateJsonInTree('angular.json', json => { | ||
json.projects['my-app'] = { | ||
root: 'my-app', | ||
architect: { | ||
lint: { | ||
builder: '@angular-devkit/build-angular:tslint', | ||
options: { | ||
tsConfig: ['my-app/tsconfig.json'], | ||
exclude: ['**/node_modules/**'] | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return json; | ||
}), | ||
tree | ||
); | ||
}); | ||
|
||
it('should add exclusions for files other than the project root', async () => { | ||
const result = await runMigration('update-8.2.0', {}, tree); | ||
const angularJson = readJsonInTree(tree, 'angular.json'); | ||
const project = angularJson.projects['my-app']; | ||
expect(project.architect.lint).toEqual({ | ||
builder: '@angular-devkit/build-angular:tslint', | ||
options: { | ||
tsConfig: ['my-app/tsconfig.json'], | ||
exclude: ['**/node_modules/**', '!my-app/**'] | ||
} | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/workspace/src/migrations/update-8-2-0/update-8-2-0.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { updateWorkspace } from '../../utils/workspace'; | ||
import { join, JsonArray, normalize } from '@angular-devkit/core'; | ||
|
||
const addExcludes = updateWorkspace(workspace => { | ||
workspace.projects.forEach(project => { | ||
project.targets.forEach(target => { | ||
if (target.builder !== '@angular-devkit/build-angular:tslint') { | ||
return; | ||
} | ||
const exceptRootGlob = '!' + join(normalize(project.root), '**'); | ||
|
||
if (!target.options.exclude) { | ||
target.options.exclude = []; | ||
} | ||
|
||
if (!(target.options.exclude as JsonArray).includes(exceptRootGlob)) { | ||
(target.options.exclude as JsonArray).push(exceptRootGlob); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
export default function() { | ||
return addExcludes; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import { join } from 'path'; | ||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { Rule, Tree } from '@angular-devkit/schematics'; | ||
|
||
const testRunner = new SchematicTestRunner( | ||
'@nrwl/workspace', | ||
join(__dirname, '../../collection.json') | ||
); | ||
|
||
const migrationTestRunner = new SchematicTestRunner( | ||
'@nrwl/workspace/migrations', | ||
join(__dirname, '../../migrations.json') | ||
); | ||
|
||
export function runSchematic(schematicName: string, options: any, tree: Tree) { | ||
return testRunner.runSchematicAsync(schematicName, options, tree).toPromise(); | ||
} | ||
|
||
export function callRule(rule: Rule, tree: Tree) { | ||
return testRunner.callRule(rule, tree).toPromise(); | ||
} | ||
|
||
export function runMigration(migrationName: string, options: any, tree: Tree) { | ||
return migrationTestRunner | ||
.runSchematicAsync(migrationName, options, tree) | ||
.toPromise(); | ||
} |