Skip to content

Commit b0913ac

Browse files
committedNov 28, 2023
Add --isolate-workspaces flag (undocumented)
1 parent 0321a8d commit b0913ac

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed
 

‎packages/knip/src/PrincipalFactory.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type PrincipalOptions = {
1616
compilers: [SyncCompilers, AsyncCompilers];
1717
pkgName: string;
1818
isGitIgnored: GlobbyFilterFunction;
19+
isIsolateWorkspaces: boolean;
1920
};
2021

2122
const mapToAbsolutePaths = (paths: NonNullable<Paths>, cwd: string): Paths =>
@@ -42,10 +43,10 @@ export class PrincipalFactory {
4243
principals: Principals = new Set();
4344

4445
public getPrincipal(options: PrincipalOptions) {
45-
const { cwd, compilerOptions, paths, pkgName } = options;
46+
const { cwd, compilerOptions, paths, pkgName, isIsolateWorkspaces } = options;
4647
options.compilerOptions = mergePaths(cwd, compilerOptions, paths);
4748
const principal = this.findReusablePrincipal(compilerOptions);
48-
if (principal) {
49+
if (!isIsolateWorkspaces && principal) {
4950
this.linkPrincipal(principal, cwd, compilerOptions, pkgName);
5051
return principal.principal;
5152
} else {

‎packages/knip/src/cli.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
'no-gitignore': isNoGitIgnore = false,
1919
'no-progress': isNoProgress = false,
2020
'include-entry-exports': isIncludeEntryExports = false,
21+
'isolate-workspaces': isIsolateWorkspaces = false,
2122
performance: isObservePerf = false,
2223
production: isProduction = false,
2324
'reporter-options': reporterOptions = '',
@@ -52,6 +53,7 @@ const run = async () => {
5253
isStrict,
5354
isShowProgress,
5455
isIncludeEntryExports,
56+
isIsolateWorkspaces,
5557
});
5658

5759
const initialData: ReporterOptions = {

‎packages/knip/src/index.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ export type { RawConfiguration as KnipConfig } from './types/config.js';
3636
export type { Preprocessor, Reporter, ReporterOptions } from './types/issues.js';
3737

3838
export const main = async (unresolvedConfiguration: CommandLineOptions) => {
39-
const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isShowProgress, isIncludeEntryExports } =
40-
unresolvedConfiguration;
39+
const {
40+
cwd,
41+
tsConfigFile,
42+
gitignore,
43+
isStrict,
44+
isProduction,
45+
isShowProgress,
46+
isIncludeEntryExports,
47+
isIsolateWorkspaces,
48+
} = unresolvedConfiguration;
4149

4250
debugLogObject('*', 'Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
4351

@@ -130,7 +138,15 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
130138

131139
const { compilerOptions, definitionPaths } = await loadTSConfig(join(dir, tsConfigFile ?? 'tsconfig.json'));
132140

133-
const principal = factory.getPrincipal({ cwd: dir, paths, compilerOptions, compilers, pkgName, isGitIgnored });
141+
const principal = factory.getPrincipal({
142+
cwd: dir,
143+
paths,
144+
compilerOptions,
145+
compilers,
146+
pkgName,
147+
isGitIgnored,
148+
isIsolateWorkspaces,
149+
});
134150

135151
const worker = new WorkspaceWorker({
136152
name,

‎packages/knip/src/types/cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface CommandLineOptions {
66
isProduction: boolean;
77
isShowProgress: boolean;
88
isIncludeEntryExports: boolean;
9+
isIsolateWorkspaces: boolean;
910
}

‎packages/knip/src/util/cli-arguments.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Options:
1717
--dependencies Shortcut for --include dependencies,unlisted,unresolved
1818
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
1919
--include-entry-exports Include entry files when reporting unused exports
20+
--isolate-workspaces Isolated workspaces in monorepo
2021
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
2122
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
2223
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
@@ -56,6 +57,7 @@ try {
5657
'ignore-internal': { type: 'boolean' },
5758
include: { type: 'string', multiple: true },
5859
'include-entry-exports': { type: 'boolean' },
60+
'isolate-workspaces': { type: 'boolean' },
5961
'max-issues': { type: 'string' },
6062
'no-config-hints': { type: 'boolean' },
6163
'no-exit-code': { type: 'boolean' },

‎packages/knip/test/helpers/baseArguments.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const baseArguments = {
55
isProduction: false,
66
isShowProgress: false,
77
isIncludeEntryExports: false,
8+
isIsolateWorkspaces: false,
89
};
910

1011
export default baseArguments;

0 commit comments

Comments
 (0)
Please sign in to comment.