Skip to content

Commit

Permalink
Don't complain about ignoredWorkspaces without a package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 30, 2023
1 parent ecee44b commit 42dbfce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/knip/fixtures/workspaces-ignored/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"ignoreWorkspaces": [
"packages/c",
"packages/d*",
"packages/f"
"packages/f",
"packages/g"
]
}
}
Empty file.
11 changes: 7 additions & 4 deletions packages/knip/src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { arrayify } from './util/array.js';
import parsedArgValues from './util/cli-arguments.js';
import { partitionCompilers } from './util/compilers.js';
import { ConfigurationError, LoaderError } from './util/errors.js';
import { findFile, loadJSON } from './util/fs.js';
import { findFile, isDirectory, isFile, loadJSON } from './util/fs.js';
import { getIncludedIssueTypes } from './util/get-included-issue-types.js';
import { _dirGlob } from './util/glob.js';
import { _load } from './util/loader.js';
Expand Down Expand Up @@ -468,8 +468,11 @@ export class ConfigurationChief {
public getUnusedIgnoredWorkspaces() {
const ignoredWorkspaceNames = this.config.ignoreWorkspaces;
const workspaceNames = [...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames];
return ignoredWorkspaceNames.filter(
ignoredWorkspaceName => !workspaceNames.some(name => micromatch.isMatch(name, ignoredWorkspaceName))
);
return ignoredWorkspaceNames
.filter(ignoredWorkspaceName => !workspaceNames.some(name => micromatch.isMatch(name, ignoredWorkspaceName)))
.filter(ignoredWorkspaceName => {
const dir = join(this.cwd, ignoredWorkspaceName);
return !isDirectory(dir) || isFile(join(dir, 'package.json'));
});
}
}
5 changes: 5 additions & 0 deletions packages/knip/src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import stripJsonComments from 'strip-json-comments';
import { LoaderError } from './errors.js';
import { dirname, join } from './path.js';

export const isDirectory = (filePath: string) => {
const stat = statSync(filePath, { throwIfNoEntry: false });
return stat !== undefined && stat.isDirectory();
};

export const isFile = (filePath: string) => {
const stat = statSync(filePath, { throwIfNoEntry: false });
return stat !== undefined && stat.isFile();
Expand Down

0 comments on commit 42dbfce

Please sign in to comment.