Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nx): add ability to ignore files from affected commands #1585

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/angular/fundamentals/monorepos-automation.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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