Skip to content

Commit

Permalink
fix(core): fix ignore logic and un-expose the functions from devkit (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jun 11, 2022
1 parent 3de1cb6 commit 0fd3281
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 58 deletions.
42 changes: 0 additions & 42 deletions docs/generated/devkit/index.md
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
@@ -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
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
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
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

1 comment on commit 0fd3281

@vercel
Copy link

@vercel vercel bot commented on 0fd3281 Jun 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.