-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): ignored directories should never contain projects (#15242)
- Loading branch information
1 parent
2f09cf4
commit a815be5
Showing
9 changed files
with
136 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/nx/src/config/workspaces.glob-for-project-files.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TempFs } from '../utils/testing/temp-fs'; | ||
import { globForProjectFiles } from './workspaces'; | ||
|
||
describe('globForProjectFiles', () => { | ||
let fs: TempFs; | ||
beforeAll(() => { | ||
fs = new TempFs('glob-for-project-files'); | ||
}); | ||
afterAll(() => { | ||
fs.cleanup(); | ||
}); | ||
|
||
it('should not find files that are listed by .nxignore', async () => { | ||
await fs.createFile('.nxignore', `not-projects`); | ||
await fs.createFile( | ||
'not-projects/project.json', | ||
JSON.stringify({ | ||
name: 'not-project-1', | ||
}) | ||
); | ||
await fs.createFile( | ||
'projects/project.json', | ||
JSON.stringify({ | ||
name: 'project-1', | ||
}) | ||
); | ||
expect(globForProjectFiles(fs.tempDir)).not.toContain( | ||
'not-projects/project.json' | ||
); | ||
expect(globForProjectFiles(fs.tempDir)).toContain('projects/project.json'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { readFileSync } from 'fs-extra'; | ||
import ignore from 'ignore'; | ||
import { join } from 'path/posix'; | ||
import { readFileIfExisting } from './fileutils'; | ||
import { workspaceRoot } from './workspace-root'; | ||
|
||
/** | ||
* An array of glob patterns that should always be ignored. | ||
* Uses path/posix, since fast-glob requires unix paths. | ||
*/ | ||
export const ALWAYS_IGNORE = getAlwaysIgnore(); | ||
|
||
export function getIgnoredGlobs( | ||
root: string = workspaceRoot, | ||
prependRoot: boolean = true | ||
) { | ||
const files = ['.nxignore', '.gitignore']; | ||
if (prependRoot) { | ||
return [ | ||
...getAlwaysIgnore(root), | ||
...files.flatMap((f) => getIgnoredGlobsFromFile(join(root, f), root)), | ||
]; | ||
} else { | ||
return [ | ||
...getAlwaysIgnore(), | ||
...files.flatMap((f) => getIgnoredGlobsFromFile(join(root, f))), | ||
]; | ||
} | ||
} | ||
|
||
export function getAlwaysIgnore(root?: string) { | ||
const paths = ['node_modules', '**/node_modules', '.git']; | ||
return root ? paths.map((x) => join(root, x)) : paths; | ||
} | ||
|
||
export function getIgnoreObject(root: string = workspaceRoot) { | ||
const ig = ignore(); | ||
ig.add(readFileIfExisting(`${root}/.gitignore`)); | ||
ig.add(readFileIfExisting(`${root}/.nxignore`)); | ||
return ig; | ||
} | ||
|
||
function getIgnoredGlobsFromFile(file: string, root?: string): string[] { | ||
try { | ||
const results = []; | ||
const contents = readFileSync(file, 'utf-8'); | ||
const lines = contents.split('\n'); | ||
for (const line of lines) { | ||
const trimmed = line.trim(); | ||
if (!trimmed || trimmed.startsWith('#')) { | ||
continue; | ||
} else if (trimmed.startsWith('/')) { | ||
if (root) { | ||
results.push(join(root, trimmed)); | ||
} else { | ||
results.push(join('.', trimmed)); | ||
} | ||
} else { | ||
results.push(trimmed); | ||
} | ||
} | ||
return results; | ||
} catch (e) { | ||
return []; | ||
} | ||
} |
a815be5
There was a problem hiding this comment.
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-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev