knip 2.30.1 → 2.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ConfigurationChief.d.ts +2 -0
- package/dist/ConfigurationChief.js +57 -61
- package/dist/ConfigurationValidator.d.ts +321 -321
- package/dist/ConfigurationValidator.js +1 -1
- package/dist/WorkspaceWorker.js +11 -6
- package/dist/index.js +8 -2
- package/dist/types/config.d.ts +3 -2
- package/dist/util/compilers.d.ts +80 -80
- package/dist/util/plugin.d.ts +1 -1
- package/dist/util/plugin.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -27,6 +27,7 @@ export declare class ConfigurationChief {
|
|
|
27
27
|
enabledWorkspaces: Workspace[];
|
|
28
28
|
localWorkspaces: Set<string>;
|
|
29
29
|
resolvedConfigFilePath?: string;
|
|
30
|
+
rawConfig?: any;
|
|
30
31
|
constructor({ cwd, isProduction }: ConfigurationManagerOptions);
|
|
31
32
|
init(): Promise<void>;
|
|
32
33
|
getCompilers(): [SyncCompilers, AsyncCompilers];
|
|
@@ -36,6 +37,7 @@ export declare class ConfigurationChief {
|
|
|
36
37
|
private getListedWorkspaces;
|
|
37
38
|
private getIgnoredWorkspacePatterns;
|
|
38
39
|
private getManifestWorkspaces;
|
|
40
|
+
private getConfiguredWorkspaceKeys;
|
|
39
41
|
private getAdditionalWorkspaceNames;
|
|
40
42
|
private getAvailableWorkspaceNames;
|
|
41
43
|
private getEnabledWorkspaces;
|
|
@@ -41,9 +41,8 @@ const defaultConfig = {
|
|
|
41
41
|
ignoreWorkspaces: [],
|
|
42
42
|
syncCompilers: new Map(),
|
|
43
43
|
asyncCompilers: new Map(),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
44
|
+
defaultWorkspaceConfig: getDefaultWorkspaceConfig(),
|
|
45
|
+
rootPluginConfigs: {},
|
|
47
46
|
};
|
|
48
47
|
const PLUGIN_NAMES = Object.keys(plugins);
|
|
49
48
|
export class ConfigurationChief {
|
|
@@ -60,6 +59,7 @@ export class ConfigurationChief {
|
|
|
60
59
|
enabledWorkspaces = [];
|
|
61
60
|
localWorkspaces = new Set();
|
|
62
61
|
resolvedConfigFilePath;
|
|
62
|
+
rawConfig;
|
|
63
63
|
constructor({ cwd, isProduction }) {
|
|
64
64
|
this.cwd = cwd;
|
|
65
65
|
this.isProduction = isProduction;
|
|
@@ -86,11 +86,9 @@ export class ConfigurationChief {
|
|
|
86
86
|
if (rawConfigArg && !this.resolvedConfigFilePath && !manifest.knip) {
|
|
87
87
|
throw new ConfigurationError(`Unable to find ${rawConfigArg} or package.json#knip`);
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.config = this.normalize(parsedConfig);
|
|
93
|
-
}
|
|
89
|
+
this.rawConfig = this.resolvedConfigFilePath ? await _load(this.resolvedConfigFilePath) : manifest.knip;
|
|
90
|
+
const parsedConfig = this.rawConfig ? ConfigurationValidator.parse(partitionCompilers(this.rawConfig)) : {};
|
|
91
|
+
this.config = this.normalize(parsedConfig);
|
|
94
92
|
await this.setWorkspaces();
|
|
95
93
|
}
|
|
96
94
|
getCompilers() {
|
|
@@ -99,58 +97,25 @@ export class ConfigurationChief {
|
|
|
99
97
|
getRules() {
|
|
100
98
|
return this.config.rules;
|
|
101
99
|
}
|
|
102
|
-
normalize(
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const ignoreBinaries = rawLocalConfig.ignoreBinaries ?? [];
|
|
113
|
-
const ignoreExportsUsedInFile = rawLocalConfig.ignoreExportsUsedInFile ?? false;
|
|
114
|
-
const ignoreDependencies = rawLocalConfig.ignoreDependencies ?? [];
|
|
115
|
-
const ignoreWorkspaces = rawLocalConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
|
|
116
|
-
const { syncCompilers, asyncCompilers } = rawLocalConfig;
|
|
100
|
+
normalize(rawConfig) {
|
|
101
|
+
const rules = { ...defaultRules, ...rawConfig.rules };
|
|
102
|
+
const include = rawConfig.include ?? defaultConfig.include;
|
|
103
|
+
const exclude = rawConfig.exclude ?? defaultConfig.exclude;
|
|
104
|
+
const ignore = arrayify(rawConfig.ignore ?? defaultConfig.ignore);
|
|
105
|
+
const ignoreBinaries = rawConfig.ignoreBinaries ?? [];
|
|
106
|
+
const ignoreExportsUsedInFile = rawConfig.ignoreExportsUsedInFile ?? false;
|
|
107
|
+
const ignoreDependencies = rawConfig.ignoreDependencies ?? [];
|
|
108
|
+
const ignoreWorkspaces = rawConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
|
|
109
|
+
const { syncCompilers, asyncCompilers } = rawConfig;
|
|
117
110
|
const extensions = [...Object.keys(syncCompilers ?? {}), ...Object.keys(asyncCompilers ?? {})];
|
|
118
111
|
const defaultWorkspaceConfig = getDefaultWorkspaceConfig(extensions);
|
|
119
112
|
const rootPluginConfigs = {};
|
|
120
|
-
for (const [name, pluginConfig] of Object.entries(
|
|
113
|
+
for (const [name, pluginConfig] of Object.entries(rawConfig)) {
|
|
121
114
|
const pluginName = toCamelCase(name);
|
|
122
115
|
if (PLUGIN_NAMES.includes(pluginName)) {
|
|
123
116
|
rootPluginConfigs[pluginName] = normalizePluginConfig(pluginConfig);
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
|
-
const workspaces = Object.entries(initialWorkspaces)
|
|
127
|
-
.filter(([workspaceName]) => !ignoreWorkspaces.includes(workspaceName))
|
|
128
|
-
.reduce((workspaces, workspace) => {
|
|
129
|
-
const [workspaceName, workspaceConfig] = workspace;
|
|
130
|
-
const entry = workspaceConfig.entry ? arrayify(workspaceConfig.entry) : defaultWorkspaceConfig.entry;
|
|
131
|
-
const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : defaultWorkspaceConfig.project;
|
|
132
|
-
const paths = workspaceConfig.paths ?? defaultWorkspaceConfig.paths;
|
|
133
|
-
workspaces[workspaceName] = {
|
|
134
|
-
entry,
|
|
135
|
-
project,
|
|
136
|
-
paths,
|
|
137
|
-
ignore: arrayify(workspaceConfig.ignore),
|
|
138
|
-
ignoreBinaries: arrayify(workspaceConfig.ignoreBinaries),
|
|
139
|
-
ignoreDependencies: arrayify(workspaceConfig.ignoreDependencies),
|
|
140
|
-
};
|
|
141
|
-
for (const [name, pluginConfig] of Object.entries(rootPluginConfigs)) {
|
|
142
|
-
const pluginName = toCamelCase(name);
|
|
143
|
-
if (pluginConfig)
|
|
144
|
-
workspaces[workspaceName][pluginName] = pluginConfig;
|
|
145
|
-
}
|
|
146
|
-
for (const [name, pluginConfig] of Object.entries(workspaceConfig)) {
|
|
147
|
-
const pluginName = toCamelCase(name);
|
|
148
|
-
if (PLUGIN_NAMES.includes(pluginName)) {
|
|
149
|
-
workspaces[workspaceName][pluginName] = normalizePluginConfig(pluginConfig);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return workspaces;
|
|
153
|
-
}, {});
|
|
154
119
|
return {
|
|
155
120
|
rules,
|
|
156
121
|
include,
|
|
@@ -162,7 +127,8 @@ export class ConfigurationChief {
|
|
|
162
127
|
ignoreWorkspaces,
|
|
163
128
|
syncCompilers: new Map(Object.entries(syncCompilers ?? {})),
|
|
164
129
|
asyncCompilers: new Map(Object.entries(asyncCompilers ?? {})),
|
|
165
|
-
|
|
130
|
+
rootPluginConfigs,
|
|
131
|
+
defaultWorkspaceConfig,
|
|
166
132
|
};
|
|
167
133
|
}
|
|
168
134
|
async setWorkspaces() {
|
|
@@ -197,14 +163,21 @@ export class ConfigurationChief {
|
|
|
197
163
|
});
|
|
198
164
|
const manifestWorkspaces = new Map();
|
|
199
165
|
for (const [pkgName, dir] of workspaces.entries()) {
|
|
200
|
-
manifestWorkspaces.set(relative(this.cwd, dir), pkgName);
|
|
166
|
+
manifestWorkspaces.set(relative(this.cwd, dir) || ROOT_WORKSPACE_NAME, pkgName);
|
|
201
167
|
}
|
|
202
168
|
return manifestWorkspaces;
|
|
203
169
|
}
|
|
170
|
+
getConfiguredWorkspaceKeys() {
|
|
171
|
+
const initialWorkspaces = this.rawConfig?.workspaces
|
|
172
|
+
? Object.keys(this.rawConfig.workspaces)
|
|
173
|
+
: [ROOT_WORKSPACE_NAME];
|
|
174
|
+
const ignoreWorkspaces = this.rawConfig?.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
|
|
175
|
+
return initialWorkspaces.filter(workspaceName => !ignoreWorkspaces.includes(workspaceName));
|
|
176
|
+
}
|
|
204
177
|
async getAdditionalWorkspaceNames() {
|
|
205
|
-
const
|
|
206
|
-
const patterns =
|
|
207
|
-
const dirs =
|
|
178
|
+
const workspaceKeys = this.getConfiguredWorkspaceKeys();
|
|
179
|
+
const patterns = workspaceKeys.filter(key => key.includes('*'));
|
|
180
|
+
const dirs = workspaceKeys.filter(key => !key.includes('*'));
|
|
208
181
|
const globbedDirs = await _dirGlob({ patterns, cwd: this.cwd });
|
|
209
182
|
return new Set([...dirs, ...globbedDirs].filter(name => name !== ROOT_WORKSPACE_NAME &&
|
|
210
183
|
!this.manifestWorkspaces.has(name) &&
|
|
@@ -260,16 +233,39 @@ export class ConfigurationChief {
|
|
|
260
233
|
.map(workspaceName => `!${workspaceName}`);
|
|
261
234
|
}
|
|
262
235
|
getConfigKeyForWorkspace(workspaceName) {
|
|
263
|
-
return
|
|
236
|
+
return this.getConfiguredWorkspaceKeys()
|
|
264
237
|
.sort(byPathDepth)
|
|
265
238
|
.reverse()
|
|
266
239
|
.find(pattern => micromatch.isMatch(workspaceName, pattern));
|
|
267
240
|
}
|
|
268
241
|
getConfigForWorkspace(workspaceName) {
|
|
269
242
|
const key = this.getConfigKeyForWorkspace(workspaceName);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
243
|
+
const defaultConfig = this.config.defaultWorkspaceConfig;
|
|
244
|
+
const workspaces = this.rawConfig?.workspaces ?? {};
|
|
245
|
+
const workspaceConfig = (key
|
|
246
|
+
? key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces)
|
|
247
|
+
? this.rawConfig
|
|
248
|
+
: workspaces[key]
|
|
249
|
+
: {}) ?? {};
|
|
250
|
+
const entry = workspaceConfig.entry ? arrayify(workspaceConfig.entry) : defaultConfig.entry;
|
|
251
|
+
const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : defaultConfig.project;
|
|
252
|
+
const paths = workspaceConfig.paths ?? defaultConfig.paths;
|
|
253
|
+
const ignore = arrayify(workspaceConfig.ignore);
|
|
254
|
+
const ignoreBinaries = arrayify(workspaceConfig.ignoreBinaries);
|
|
255
|
+
const ignoreDependencies = arrayify(workspaceConfig.ignoreDependencies);
|
|
256
|
+
const plugins = {};
|
|
257
|
+
for (const [name, pluginConfig] of Object.entries(this.config.rootPluginConfigs)) {
|
|
258
|
+
const pluginName = toCamelCase(name);
|
|
259
|
+
if (typeof pluginConfig !== 'undefined')
|
|
260
|
+
plugins[pluginName] = pluginConfig;
|
|
261
|
+
}
|
|
262
|
+
for (const [name, pluginConfig] of Object.entries(workspaceConfig)) {
|
|
263
|
+
const pluginName = toCamelCase(name);
|
|
264
|
+
if (PLUGIN_NAMES.includes(pluginName)) {
|
|
265
|
+
plugins[pluginName] = normalizePluginConfig(pluginConfig);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return { entry, project, paths, ignore, ignoreBinaries, ignoreDependencies, ...plugins };
|
|
273
269
|
}
|
|
274
270
|
getIssueTypesToReport() {
|
|
275
271
|
const cliArgs = { include, exclude, dependencies, exports };
|