Skip to content

Commit 496534d

Browse files
vsavkinFrozenPandaz
authored andcommittedAug 13, 2020
fix(misc): workspace-lint should respect nested gitignores
1 parent 1777f5b commit 496534d

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed
 

Diff for: ‎packages/workspace/src/command-line/lint.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
onlyWorkspaceProjects,
44
} from '../core/project-graph';
55
import { WorkspaceIntegrityChecks } from './workspace-integrity-checks';
6-
import * as path from 'path';
7-
import { appRootPath } from '../utils/app-root';
8-
import { allFilesInDir } from '../core/file-utils';
6+
import { readWorkspaceFiles, workspaceLayout } from '../core/file-utils';
97
import { output } from '../utils/output';
8+
import * as path from 'path';
109

1110
export function workspaceLint() {
1211
const graph = onlyWorkspaceProjects(createProjectGraph());
@@ -25,8 +24,11 @@ export function workspaceLint() {
2524
}
2625

2726
function readAllFilesFromAppsAndLibs() {
28-
return [
29-
...allFilesInDir(`${appRootPath}/apps`).map((f) => f.file),
30-
...allFilesInDir(`${appRootPath}/libs`).map((f) => f.file),
31-
].filter((f) => !path.basename(f).startsWith('.'));
27+
const wl = workspaceLayout();
28+
return readWorkspaceFiles()
29+
.map((f) => f.file)
30+
.filter(
31+
(f) => f.startsWith(`${wl.appsDir}/`) || f.startsWith(`${wl.libsDir}/`)
32+
)
33+
.filter((f) => !path.basename(f).startsWith('.'));
3234
}

Diff for: ‎packages/workspace/src/core/file-utils.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ export function readNxJson(): NxJson {
194194
return config;
195195
}
196196

197+
export function workspaceLayout(): { appsDir: string; libsDir: string } {
198+
const nxJson = readNxJson();
199+
const appsDir =
200+
(nxJson.workspaceLayout && nxJson.workspaceLayout.appsDir) || 'apps';
201+
const libsDir =
202+
(nxJson.workspaceLayout && nxJson.workspaceLayout.libsDir) || 'libs';
203+
return { appsDir, libsDir };
204+
}
205+
197206
// TODO: Make this list extensible
198207
export function rootWorkspaceFileNames(): string[] {
199208
return [`package.json`, workspaceFileName(), `nx.json`, `tsconfig.json`];
@@ -227,12 +236,11 @@ export function readWorkspaceFiles(): FileData[] {
227236
// Add known workspace files and directories
228237
files.push(...allFilesInDir(appRootPath, false));
229238
files.push(...allFilesInDir(`${appRootPath}/tools`));
230-
231-
// Add files for workspace projects
232-
Object.keys(workspaceJson.projects).forEach((projectName) => {
233-
const project = workspaceJson.projects[projectName];
234-
files.push(...allFilesInDir(`${appRootPath}/${project.root}`));
235-
});
239+
const wl = workspaceLayout();
240+
files.push(...allFilesInDir(`${appRootPath}/${wl.appsDir}`));
241+
if (wl.appsDir !== wl.libsDir) {
242+
files.push(...allFilesInDir(`${appRootPath}/${wl.libsDir}`));
243+
}
236244
performance.mark('read workspace files:end');
237245
performance.measure(
238246
'read workspace files',

0 commit comments

Comments
 (0)
Please sign in to comment.