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

fix(core): fix ignore logic and un-expose the functions from devkit #10703

Merged
merged 1 commit into from
Jun 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 0 additions & 42 deletions docs/generated/devkit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ It only uses language primitives and immutable objects
- [applyChangesToString](../../devkit/index#applychangestostring)
- [convertNxExecutor](../../devkit/index#convertnxexecutor)
- [convertNxGenerator](../../devkit/index#convertnxgenerator)
- [createIgnore](../../devkit/index#createignore)
- [createIgnoreFromTree](../../devkit/index#createignorefromtree)
- [createProjectGraphAsync](../../devkit/index#createprojectgraphasync)
- [defaultTasksRunner](../../devkit/index#defaulttasksrunner)
- [detectPackageManager](../../devkit/index#detectpackagemanager)
Expand Down Expand Up @@ -899,46 +897,6 @@ Convert an Nx Generator into an Angular Devkit Schematic.

---

### createIgnore

▸ **createIgnore**(`rootDir?`, `ignoreFiles?`): `Ignore`

Reads ignore files from the file system and returns an object which can be
used to check whether a file should be ignored.

#### Parameters

| Name | Type | Default value | Description |
| :------------ | :--------- | :--------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rootDir` | `string` | `workspaceRoot` | The directory in which to start searching for ignore files. Paths evaluated by the returned object must be relative to this directory. Defaults to the workspace root. |
| `ignoreFiles` | `string`[] | `workspaceIgnoreFiles` | The filename of ignore files to include, e.g. ".gitignore". Defaults to [".gitignore", ".nxignore"]. |

#### Returns

`Ignore`

---

### createIgnoreFromTree

▸ **createIgnoreFromTree**(`tree`, `ignoreFiles?`): `Ignore`

Reads ignore files from a Tree and returns an object which can be
used to check whether a file should be ignored.

#### Parameters

| Name | Type | Default value | Description |
| :------------ | :-------------------------------- | :--------------------- | :------------------------------------------------------------------------------------------------------------------------- |
| `tree` | [`Tree`](../../devkit/index#tree) | `undefined` | The tree in which to searching for ignore files. Paths evaluated by the returned object must be relative to the tree root. |
| `ignoreFiles` | `string`[] | `workspaceIgnoreFiles` | The filename of ignore files to include, e.g. ".gitignore". Defaults to [".gitignore", ".nxignore"]. |

#### Returns

`Ignore`

---

### createProjectGraphAsync

▸ **createProjectGraphAsync**(): `Promise`<[`ProjectGraph`](../../devkit/index#projectgraph)\>
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/devkit.json

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions packages/add-nx-to-monorepo/src/add-nx-to-monorepo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env node

import {
createIgnore,
output,
readJsonFile,
writeJsonFile,
} from '@nrwl/devkit';
import { output, readJsonFile, writeJsonFile } from '@nrwl/devkit';
import { createIgnore } from 'nx/src/utils/ignore';
import * as cp from 'child_process';
import { execSync } from 'child_process';
import * as enquirer from 'enquirer';
Expand Down
5 changes: 0 additions & 5 deletions packages/devkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,3 @@ export { Hash, Hasher } from 'nx/src/hasher/hasher';
* @category Utils
*/
export { cacheDir } from 'nx/src/utils/cache-directory';

/**
* @category Utils
*/
export { createIgnore, createIgnoreFromTree } from 'nx/src/utils/ignore';
7 changes: 7 additions & 0 deletions packages/nx/src/utils/ignore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ describe('createCombinedIgnore', () => {
expect(ignore.ignores('c')).toBe(false);
});

it('should support ignoring root directory from file at root', () => {
const ignore = createCombinedIgnore([{ path: '.ignore', content: '/b' }]);
expect(ignore.ignores('b')).toBe(true);
expect(ignore.ignores('path/to/b')).toBe(false);
expect(ignore.ignores('c')).toBe(false);
});

it('should support nested ignore file', () => {
const ignore = createCombinedIgnore([{ path: 'a/.ignore', content: 'b' }]);
expect(ignore.ignores('a/b')).toBe(true);
Expand Down
12 changes: 8 additions & 4 deletions packages/nx/src/utils/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ function combineIgnorePatterns(ignoreFiles: IgnoreFile[]): string[] {

function parseIgnoreFile(file: IgnoreFile): string[] {
const base = normalizePath(path.dirname(file.path));

return file.content
const patterns = file.content
.split(/\r?\n/)
.filter((line) => line && !line.startsWith('#'))
.map((pattern) => applyBaseToPattern(pattern, base));
.filter((line) => line && !line.startsWith('#'));

if (base === '.') {
return patterns;
}

return patterns.map((pattern) => applyBaseToPattern(pattern, base));
}

function applyBaseToPattern(pattern: string, base: string): string {
Expand Down