Skip to content

Commit

Permalink
feat(nx): check .nxignore for globs to add to ignored files in affected
Browse files Browse the repository at this point in the history
Add ability to ignore files from the affected check using .nxignore files

Implement #895
  • Loading branch information
wesleygrimes authored and vsavkin committed Aug 29, 2019
1 parent cfc1eaa commit 929aeb7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/angular/fundamentals/monorepos-automation.md
Expand Up @@ -341,6 +341,8 @@ The `tags` array is used to impose constraints on the dependency graph. Read mor

Nx uses its advanced code analysis to construct a dependency graph of all applications and libraries. Some dependencies, however, cannot be determined statically. You can use the `implicitDependencies` array to list the dependencies that cannot be determined statically.

> Note: Glob patterns in the `.gitignore` and `.nxignore` files are ignored during affected commands by default.
## Summary

With Nx, you can use effective development practices pioneered at Google:
Expand Down
7 changes: 7 additions & 0 deletions docs/shared/monorepo-affected.md
Expand Up @@ -189,3 +189,10 @@ You can also specify dependencies between projects. For instance, if `admin-e2e`
}
}
```

### Ignoring Additional Files from Affected Commands

Nx provides two methods to exclude additional glob patterns (files and folders) from `affected:*` commands.

- Glob patterns defined in your `.gitignore` file are ignored.
- Glob patterns defined in an optional `.nxignore` file are ignored.
2 changes: 2 additions & 0 deletions docs/web/fundamentals/monorepos-automation.md
Expand Up @@ -342,6 +342,8 @@ The `tags` array is used to impose constraints on the dependency graph. Read mor

Nx uses its advanced code analysis to construct a dependency graph of all applications and libraries. Some dependencies, however, cannot be determined statically. You can use the `implicitDependencies` array to list the dependencies that cannot be determined statically.

> Note: Glob patterns in the `.gitignore` and `.nxignore` files are ignored during affected commands by default.
## Summary

With Nx, you can use effective development practices pioneered at Google:
Expand Down
16 changes: 11 additions & 5 deletions packages/workspace/src/command-line/shared.ts
Expand Up @@ -43,8 +43,14 @@ function readFileIfExisting(path: string) {
return fs.existsSync(path) ? fs.readFileSync(path, 'UTF-8').toString() : '';
}

const ig = ignore();
ig.add(readFileIfExisting(`${appRootPath}/.gitignore`));
function getIgnoredGlobs() {
const ig = ignore();

ig.add(readFileIfExisting(`${appRootPath}/.gitignore`));
ig.add(readFileIfExisting(`${appRootPath}/.nxignore`));

return ig;
}

export function printArgsWarning(options: YargsAffectedOptions) {
const { files, uncommitted, untracked, base, head, all } = options;
Expand Down Expand Up @@ -441,16 +447,16 @@ export function getProjectRoots(projectNames: string[]): string[] {
export function allFilesInDir(
dirName: string
): { file: string; mtime: number }[] {
// Ignore .gitignored files
if (ig.ignores(path.relative(appRootPath, dirName))) {
const ignoredGlobs = getIgnoredGlobs();
if (ignoredGlobs.ignores(path.relative(appRootPath, dirName))) {
return [];
}

let res = [];
try {
fs.readdirSync(dirName).forEach(c => {
const child = path.join(dirName, c);
if (ig.ignores(path.relative(appRootPath, child))) {
if (ignoredGlobs.ignores(path.relative(appRootPath, child))) {
return;
}
try {
Expand Down

0 comments on commit 929aeb7

Please sign in to comment.