Skip to content

Commit

Permalink
Revert "fix(core): fix ignore logic and un-expose the functions from …
Browse files Browse the repository at this point in the history
…devkit (#10703)"

This reverts commit 0fd3281.
  • Loading branch information
FrozenPandaz committed Jun 13, 2022
1 parent e00dc75 commit bc7c8ad
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
42 changes: 42 additions & 0 deletions docs/generated/devkit/index.md
Expand Up @@ -132,6 +132,8 @@ 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 @@ -897,6 +899,46 @@ 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: 6 additions & 2 deletions packages/add-nx-to-monorepo/src/add-nx-to-monorepo.ts
@@ -1,7 +1,11 @@
#!/usr/bin/env node

import { output, readJsonFile, writeJsonFile } from '@nrwl/devkit';
import { createIgnore } from 'nx/src/utils/ignore';
import {
createIgnore,
output,
readJsonFile,
writeJsonFile,
} from '@nrwl/devkit';
import * as cp from 'child_process';
import { execSync } from 'child_process';
import * as enquirer from 'enquirer';
Expand Down
5 changes: 5 additions & 0 deletions packages/devkit/index.ts
Expand Up @@ -319,3 +319,8 @@ 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: 0 additions & 7 deletions packages/nx/src/utils/ignore.spec.ts
Expand Up @@ -53,13 +53,6 @@ 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: 4 additions & 8 deletions packages/nx/src/utils/ignore.ts
Expand Up @@ -127,15 +127,11 @@ function combineIgnorePatterns(ignoreFiles: IgnoreFile[]): string[] {

function parseIgnoreFile(file: IgnoreFile): string[] {
const base = normalizePath(path.dirname(file.path));
const patterns = file.content
.split(/\r?\n/)
.filter((line) => line && !line.startsWith('#'));

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

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

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

0 comments on commit bc7c8ad

Please sign in to comment.