knip 5.36.3 → 5.36.5

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.
Files changed (40) hide show
  1. package/dist/ConfigurationChief.d.ts +1 -0
  2. package/dist/ProjectPrincipal.js +10 -1
  3. package/dist/WorkspaceWorker.js +7 -7
  4. package/dist/binaries/bash-parser.js +4 -1
  5. package/dist/binaries/plugins.js +1 -1
  6. package/dist/cli.js +6 -5
  7. package/dist/index.js +21 -20
  8. package/dist/plugins/changesets/index.d.ts +1 -0
  9. package/dist/plugins/changesets/index.js +2 -0
  10. package/dist/plugins/commitizen/index.d.ts +1 -0
  11. package/dist/plugins/commitizen/index.js +2 -0
  12. package/dist/plugins/github-actions/index.d.ts +1 -0
  13. package/dist/plugins/github-actions/index.js +2 -0
  14. package/dist/plugins/glob/index.d.ts +12 -0
  15. package/dist/plugins/glob/index.js +11 -0
  16. package/dist/plugins/husky/index.d.ts +1 -0
  17. package/dist/plugins/husky/index.js +2 -0
  18. package/dist/plugins/index.d.ts +17 -0
  19. package/dist/plugins/index.js +2 -0
  20. package/dist/plugins/semantic-release/index.d.ts +1 -0
  21. package/dist/plugins/semantic-release/index.js +2 -0
  22. package/dist/plugins/travis/index.d.ts +1 -0
  23. package/dist/plugins/travis/index.js +2 -0
  24. package/dist/types/PluginNames.d.ts +2 -2
  25. package/dist/types/PluginNames.js +1 -0
  26. package/dist/types/config.d.ts +1 -0
  27. package/dist/util/fs.d.ts +0 -1
  28. package/dist/util/fs.js +0 -2
  29. package/dist/util/glob-core.d.ts +2 -1
  30. package/dist/util/glob-core.js +31 -20
  31. package/dist/util/glob.d.ts +3 -1
  32. package/dist/util/glob.js +8 -7
  33. package/dist/util/log.d.ts +2 -0
  34. package/dist/util/log.js +7 -0
  35. package/dist/util/package-json.js +1 -1
  36. package/dist/util/plugin.d.ts +0 -1
  37. package/dist/util/plugin.js +0 -1
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +1 -1
@@ -154,6 +154,7 @@ export declare class ConfigurationChief {
154
154
  xo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
155
155
  yorkie?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
156
156
  drizzle?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
157
+ glob?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
157
158
  entry: string[];
158
159
  project: string[];
159
160
  paths: any;
@@ -234,7 +234,16 @@ export class ProjectPrincipal {
234
234
  return false;
235
235
  const externalRefs = referencedSymbols
236
236
  .flatMap(refs => refs.references)
237
- .filter(ref => !ref.isDefinition && ref.fileName !== filePath);
237
+ .filter(ref => !ref.isDefinition && ref.fileName !== filePath)
238
+ .filter(ref => {
239
+ const sourceFile = this.backend.program?.getSourceFile(ref.fileName);
240
+ if (!sourceFile)
241
+ return true;
242
+ const node = ts.getTokenAtPosition(sourceFile, ref.textSpan.start);
243
+ if (!node?.parent?.parent?.parent)
244
+ return true;
245
+ return !(ts.isExportSpecifier(node.parent) && node.parent.parent.parent.moduleSpecifier);
246
+ });
238
247
  return externalRefs.length > 0;
239
248
  }
240
249
  reconcileCache(graph) {
@@ -54,6 +54,8 @@ export class WorkspaceWorker {
54
54
  for (const [pluginName, plugin] of PluginEntries) {
55
55
  if (this.config[pluginName] === false)
56
56
  continue;
57
+ if (this.cwd !== this.dir && plugin.isRootOnly)
58
+ continue;
57
59
  if (this.config[pluginName]) {
58
60
  this.enabledPluginsMap[pluginName] = true;
59
61
  continue;
@@ -65,10 +67,7 @@ export class WorkspaceWorker {
65
67
  this.enabledPluginsMap[pluginName] = true;
66
68
  }
67
69
  }
68
- const enabledPlugins = getKeysByValue(this.enabledPluginsMap, true);
69
- const enabledPluginTitles = enabledPlugins.map(name => Plugins[name].title);
70
- debugLogObject(this.name, 'Enabled plugins', enabledPluginTitles);
71
- return enabledPlugins;
70
+ return getKeysByValue(this.enabledPluginsMap, true);
72
71
  }
73
72
  getConfigForPlugin(pluginName) {
74
73
  const config = this.config[pluginName];
@@ -207,13 +206,12 @@ export class WorkspaceWorker {
207
206
  const config = this.getConfigForPlugin(pluginName);
208
207
  if (!config)
209
208
  return;
210
- const configFilePaths = await _glob({ patterns, cwd: baseScriptOptions.rootCwd, dir: cwd, gitignore: false });
209
+ const label = 'config file';
210
+ const configFilePaths = await _glob({ patterns, cwd: rootCwd, dir: cwd, gitignore: false, label });
211
211
  const remainingConfigFilePaths = configFilePaths.filter(filePath => !this.allConfigFilePaths.has(filePath));
212
212
  for (const f of remainingConfigFilePaths)
213
213
  if (basename(f) !== 'package.json')
214
214
  this.allConfigFilePaths.add(f);
215
- if (configFilePaths.length > 0)
216
- debugLogArray([name, plugin.title], 'config file paths', configFilePaths);
217
215
  const options = {
218
216
  ...baseScriptOptions,
219
217
  config,
@@ -275,6 +273,8 @@ export class WorkspaceWorker {
275
273
  addInput(id, containingFilePath);
276
274
  }
277
275
  };
276
+ const enabledPluginTitles = this.enabledPlugins.map(name => Plugins[name].title);
277
+ debugLogObject(this.name, 'Enabled plugins', enabledPluginTitles);
278
278
  for (const pluginName of this.enabledPlugins) {
279
279
  const patterns = [...this.getConfigurationFilePatterns(pluginName), ...(configFiles.get(pluginName) ?? [])];
280
280
  configFiles.delete(pluginName);
@@ -1,5 +1,5 @@
1
1
  import parse, {} from '../../vendor/bash-parser/index.js';
2
- import { pluginArgsMap } from '../plugins.js';
2
+ import { Plugins, pluginArgsMap } from '../plugins.js';
3
3
  import { debugLogObject } from '../util/debug.js';
4
4
  import { toBinary, toDeferResolve } from '../util/input.js';
5
5
  import { extractBinary } from '../util/modules.js';
@@ -57,6 +57,9 @@ export const getDependenciesFromScript = (script, options) => {
57
57
  const command = script.replace(new RegExp(`.*${text ?? binary}(\\s--\\s)?`), '');
58
58
  return [toBinary(binary), ...getDependenciesFromScript(command, options)];
59
59
  }
60
+ if (binary in Plugins) {
61
+ return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
62
+ }
60
63
  if (options.knownBinsOnly && !text?.startsWith('.'))
61
64
  return [];
62
65
  return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
@@ -27,7 +27,7 @@ export const resolve = (binary, _args, options) => {
27
27
  },
28
28
  });
29
29
  const positionals = [];
30
- if (opts.positional) {
30
+ if (opts.positional && parsed._[0]) {
31
31
  const id = parsed._[0];
32
32
  if (isGlobLike(id))
33
33
  positionals.push(toEntry(id));
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
- import picocolors from 'picocolors';
2
1
  import prettyMilliseconds from 'pretty-ms';
3
2
  import { main } from './index.js';
4
3
  import { perfObserver } from './util/Performance.js';
5
4
  import parsedArgValues, { helpText } from './util/cli-arguments.js';
6
5
  import { getKnownError, hasCause, isConfigurationError, isKnownError } from './util/errors.js';
6
+ import { logError, logWarning } from './util/log.js';
7
7
  import { cwd, join, toPosix } from './util/path.js';
8
8
  import { runPreprocessors, runReporters } from './util/reporter.js';
9
9
  import { splitTags } from './util/tag.js';
@@ -78,8 +78,10 @@ const run = async () => {
78
78
  perfObserver.reset();
79
79
  }
80
80
  if (experimentalTags.length > 0) {
81
- const prefix = `${picocolors.yellow('DEPRECATION WARNING:')}`;
82
- console.warn(`\n${prefix} --experimental-tags is deprecated, please start using --tags instead`);
81
+ logWarning('DEPRECATION WARNING', '--experimental-tags is deprecated, please start using --tags instead');
82
+ }
83
+ if (isIsolateWorkspaces && report.classMembers) {
84
+ logWarning('WARNING', 'Class members are not tracked when using the --isolate-workspaces flag');
83
85
  }
84
86
  if (!noExitCode && totalErrorCount > Number(maxIssues)) {
85
87
  process.exit(1);
@@ -89,8 +91,7 @@ const run = async () => {
89
91
  process.exitCode = 2;
90
92
  if (!isDebug && error instanceof Error && isKnownError(error)) {
91
93
  const knownError = getKnownError(error);
92
- const prefix = `${picocolors.red('ERROR:')}`;
93
- console.error(`${prefix} ${knownError.message}`);
94
+ logError('ERROR', knownError.message);
94
95
  if (hasCause(knownError))
95
96
  console.error('Reason:', knownError.cause.message);
96
97
  if (isConfigurationError(knownError))
package/dist/index.js CHANGED
@@ -106,14 +106,15 @@ export const main = async (unresolvedConfiguration) => {
106
106
  });
107
107
  await worker.init();
108
108
  const deps = new Set();
109
- debugLogArray(name, 'Definition paths', definitionPaths);
110
- for (const id of definitionPaths)
111
- deps.add(toProductionEntry(id, { containingFilePath: tsConfigFilePath }));
109
+ if (definitionPaths.length > 0) {
110
+ debugLogArray(name, 'Definition paths', definitionPaths);
111
+ for (const id of definitionPaths)
112
+ deps.add(toProductionEntry(id, { containingFilePath: tsConfigFilePath }));
113
+ }
112
114
  const ignore = worker.getIgnorePatterns();
113
115
  const sharedGlobOptions = { cwd, dir, gitignore };
114
116
  collector.addIgnorePatterns(ignore.map(pattern => join(cwd, pattern)));
115
117
  const entryPathsFromManifest = await getEntryPathsFromManifest(manifest, { ...sharedGlobOptions, ignore });
116
- debugLogArray(name, 'Entry paths in package.json', entryPathsFromManifest);
117
118
  for (const id of entryPathsFromManifest.map(id => toProductionEntry(id)))
118
119
  deps.add(id);
119
120
  const dependenciesFromPlugins = await worker.findDependenciesByPlugins();
@@ -154,56 +155,56 @@ export const main = async (unresolvedConfiguration) => {
154
155
  if (isProduction) {
155
156
  const negatedEntryPatterns = Array.from(entryFilePatterns).map(negate);
156
157
  {
158
+ const label = 'entry';
157
159
  const patterns = worker.getProductionEntryFilePatterns(negatedEntryPatterns);
158
- const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false });
159
- debugLogArray(name, 'Entry paths', workspaceEntryPaths);
160
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false, label });
160
161
  principal.addEntryPaths(workspaceEntryPaths);
161
162
  }
162
163
  {
164
+ const label = 'production plugin entry';
163
165
  const patterns = Array.from(productionEntryFilePatterns);
164
- const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
165
- debugLogArray(name, 'Production plugin entry paths', pluginWorkspaceEntryPaths);
166
+ const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, label });
166
167
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
167
168
  }
168
169
  {
170
+ const label = 'project';
169
171
  const patterns = worker.getProductionProjectFilePatterns(negatedEntryPatterns);
170
- const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
171
- debugLogArray(name, 'Project paths', workspaceProjectPaths);
172
+ const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns, label });
172
173
  for (const projectPath of workspaceProjectPaths)
173
174
  principal.addProjectPath(projectPath);
174
175
  }
175
176
  }
176
177
  else {
177
178
  {
179
+ const label = 'entry';
178
180
  const patterns = worker.getEntryFilePatterns();
179
- const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false });
180
- debugLogArray(name, 'Entry paths', workspaceEntryPaths);
181
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false, label });
181
182
  principal.addEntryPaths(workspaceEntryPaths);
182
183
  }
183
184
  {
185
+ const label = 'project';
184
186
  const patterns = worker.getProjectFilePatterns([...productionEntryFilePatterns]);
185
- const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
186
- debugLogArray(name, 'Project paths', workspaceProjectPaths);
187
+ const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns, label });
187
188
  for (const projectPath of workspaceProjectPaths)
188
189
  principal.addProjectPath(projectPath);
189
190
  }
190
191
  {
192
+ const label = 'plugin entry';
191
193
  const patterns = worker.getPluginEntryFilePatterns([...entryFilePatterns, ...productionEntryFilePatterns]);
192
- const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
193
- debugLogArray(name, 'Plugin entry paths', pluginWorkspaceEntryPaths);
194
+ const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, label });
194
195
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
195
196
  }
196
197
  {
198
+ const label = 'plugin project';
197
199
  const patterns = worker.getPluginProjectFilePatterns();
198
- const pluginWorkspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
199
- debugLogArray(name, 'Plugin project paths', pluginWorkspaceProjectPaths);
200
+ const pluginWorkspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns, label });
200
201
  for (const projectPath of pluginWorkspaceProjectPaths)
201
202
  principal.addProjectPath(projectPath);
202
203
  }
203
204
  {
205
+ const label = 'plugin configuration';
204
206
  const patterns = worker.getPluginConfigPatterns();
205
- const configurationEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
206
- debugLogArray(name, 'Plugin configuration paths', configurationEntryPaths);
207
+ const configurationEntryPaths = await _glob({ ...sharedGlobOptions, patterns, label });
207
208
  principal.addEntryPaths(configurationEntryPaths, { skipExportsAnalysis: true });
208
209
  }
209
210
  }
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  title: string;
5
5
  enablers: string[];
6
6
  isEnabled: IsPluginEnabled;
7
+ isRootOnly: true;
7
8
  config: string[];
8
9
  resolveConfig: ResolveConfig<ChangesetsConfig>;
9
10
  };
@@ -3,6 +3,7 @@ import { hasDependency } from '../../util/plugin.js';
3
3
  const title = 'Changesets';
4
4
  const enablers = ['@changesets/cli'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const isRootOnly = true;
6
7
  const config = ['.changeset/config.json'];
7
8
  const resolveConfig = config => {
8
9
  return (Array.isArray(config.changelog)
@@ -15,6 +16,7 @@ export default {
15
16
  title,
16
17
  enablers,
17
18
  isEnabled,
19
+ isRootOnly,
18
20
  config,
19
21
  resolveConfig,
20
22
  };
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  title: string;
5
5
  enablers: string[];
6
6
  isEnabled: IsPluginEnabled;
7
+ isRootOnly: true;
7
8
  packageJsonPath: string;
8
9
  config: string[];
9
10
  resolveConfig: ResolveConfig<CommitizenConfig>;
@@ -3,6 +3,7 @@ import { hasDependency } from '../../util/plugin.js';
3
3
  const title = 'Commitizen';
4
4
  const enablers = ['commitizen'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const isRootOnly = true;
6
7
  const packageJsonPath = 'config.commitizen';
7
8
  const config = ['.czrc', '.cz.json', 'package.json'];
8
9
  const resolveConfig = config => {
@@ -12,6 +13,7 @@ export default {
12
13
  title,
13
14
  enablers,
14
15
  isEnabled,
16
+ isRootOnly,
15
17
  packageJsonPath,
16
18
  config,
17
19
  resolveConfig,
@@ -3,6 +3,7 @@ declare const _default: {
3
3
  title: string;
4
4
  enablers: string;
5
5
  isEnabled: IsPluginEnabled;
6
+ isRootOnly: true;
6
7
  config: string[];
7
8
  resolveConfig: ResolveConfig;
8
9
  };
@@ -5,6 +5,7 @@ import { join, relative } from '../../util/path.js';
5
5
  const title = 'GitHub Actions';
6
6
  const enablers = 'This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.';
7
7
  const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.{yml,yaml}'] }));
8
+ const isRootOnly = true;
8
9
  const config = ['.github/workflows/*.{yml,yaml}', '.github/**/action.{yml,yaml}'];
9
10
  const isString = (value) => typeof value === 'string';
10
11
  const resolveConfig = async (config, options) => {
@@ -41,6 +42,7 @@ export default {
41
42
  title,
42
43
  enablers,
43
44
  isEnabled,
45
+ isRootOnly,
44
46
  config,
45
47
  resolveConfig,
46
48
  };
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ title: string;
3
+ args: {
4
+ binaries: string[];
5
+ positional: boolean;
6
+ alias: {
7
+ cmd: string[];
8
+ };
9
+ fromArgs: string[];
10
+ };
11
+ };
12
+ export default _default;
@@ -0,0 +1,11 @@
1
+ const title = 'glob';
2
+ const args = {
3
+ binaries: ['glob'],
4
+ positional: true,
5
+ alias: { cmd: ['c'] },
6
+ fromArgs: ['cmd'],
7
+ };
8
+ export default {
9
+ title,
10
+ args,
11
+ };
@@ -3,6 +3,7 @@ declare const _default: {
3
3
  title: string;
4
4
  enablers: string[];
5
5
  isEnabled: IsPluginEnabled;
6
+ isRootOnly: true;
6
7
  config: string[];
7
8
  resolveConfig: ResolveConfig;
8
9
  };
@@ -4,6 +4,7 @@ import { hasDependency } from '../../util/plugin.js';
4
4
  const title = 'husky';
5
5
  const enablers = ['husky'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
+ const isRootOnly = true;
7
8
  const gitHookPaths = getGitHookPaths('.husky', false);
8
9
  const config = [...gitHookPaths, 'package.json'];
9
10
  const resolveConfig = (script, options) => {
@@ -22,6 +23,7 @@ export default {
22
23
  title,
23
24
  enablers,
24
25
  isEnabled,
26
+ isRootOnly,
25
27
  config,
26
28
  resolveConfig,
27
29
  };
@@ -50,6 +50,7 @@ export declare const Plugins: {
50
50
  title: string;
51
51
  enablers: string[];
52
52
  isEnabled: import("../types/config.js").IsPluginEnabled;
53
+ isRootOnly: true;
53
54
  config: string[];
54
55
  resolveConfig: import("../types/config.js").ResolveConfig<import("./changesets/types.js").ChangesetsConfig>;
55
56
  };
@@ -57,6 +58,7 @@ export declare const Plugins: {
57
58
  title: string;
58
59
  enablers: string[];
59
60
  isEnabled: import("../types/config.js").IsPluginEnabled;
61
+ isRootOnly: true;
60
62
  packageJsonPath: string;
61
63
  config: string[];
62
64
  resolveConfig: import("../types/config.js").ResolveConfig<import("./commitizen/types.js").CommitizenConfig>;
@@ -136,9 +138,21 @@ export declare const Plugins: {
136
138
  title: string;
137
139
  enablers: string;
138
140
  isEnabled: import("../types/config.js").IsPluginEnabled;
141
+ isRootOnly: true;
139
142
  config: string[];
140
143
  resolveConfig: import("../types/config.js").ResolveConfig;
141
144
  };
145
+ glob: {
146
+ title: string;
147
+ args: {
148
+ binaries: string[];
149
+ positional: boolean;
150
+ alias: {
151
+ cmd: string[];
152
+ };
153
+ fromArgs: string[];
154
+ };
155
+ };
142
156
  'graphql-codegen': {
143
157
  title: string;
144
158
  enablers: (string | RegExp)[];
@@ -151,6 +165,7 @@ export declare const Plugins: {
151
165
  title: string;
152
166
  enablers: string[];
153
167
  isEnabled: import("../types/config.js").IsPluginEnabled;
168
+ isRootOnly: true;
154
169
  config: string[];
155
170
  resolveConfig: import("../types/config.js").ResolveConfig;
156
171
  };
@@ -447,6 +462,7 @@ export declare const Plugins: {
447
462
  title: string;
448
463
  enablers: string[];
449
464
  isEnabled: import("../types/config.js").IsPluginEnabled;
465
+ isRootOnly: true;
450
466
  packageJsonPath: string;
451
467
  config: string[];
452
468
  resolveConfig: import("../types/config.js").ResolveConfig<import("./semantic-release/types.js").SemanticReleaseConfig>;
@@ -518,6 +534,7 @@ export declare const Plugins: {
518
534
  title: string;
519
535
  enablers: string;
520
536
  isEnabled: import("../types/config.js").IsPluginEnabled;
537
+ isRootOnly: true;
521
538
  config: string[];
522
539
  resolveConfig: import("../types/config.js").ResolveConfig;
523
540
  };
@@ -16,6 +16,7 @@ import { default as eleventy } from './eleventy/index.js';
16
16
  import { default as eslint } from './eslint/index.js';
17
17
  import { default as gatsby } from './gatsby/index.js';
18
18
  import { default as githubActions } from './github-actions/index.js';
19
+ import { default as glob } from './glob/index.js';
19
20
  import { default as graphqlCodegen } from './graphql-codegen/index.js';
20
21
  import { default as husky } from './husky/index.js';
21
22
  import { default as jest } from './jest/index.js';
@@ -101,6 +102,7 @@ export const Plugins = {
101
102
  eslint,
102
103
  gatsby,
103
104
  'github-actions': githubActions,
105
+ glob,
104
106
  'graphql-codegen': graphqlCodegen,
105
107
  husky,
106
108
  jest,
@@ -4,6 +4,7 @@ declare const _default: {
4
4
  title: string;
5
5
  enablers: string[];
6
6
  isEnabled: IsPluginEnabled;
7
+ isRootOnly: true;
7
8
  packageJsonPath: string;
8
9
  config: string[];
9
10
  resolveConfig: ResolveConfig<SemanticReleaseConfig>;
@@ -4,6 +4,7 @@ import { hasDependency } from '../../util/plugin.js';
4
4
  const title = 'Semantic Release';
5
5
  const enablers = ['semantic-release'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
+ const isRootOnly = true;
7
8
  const packageJsonPath = 'release';
8
9
  const config = ['package.json', ...toCosmiconfig('release')];
9
10
  const resolveConfig = config => {
@@ -14,6 +15,7 @@ export default {
14
15
  title,
15
16
  enablers,
16
17
  isEnabled,
18
+ isRootOnly,
17
19
  packageJsonPath,
18
20
  config,
19
21
  resolveConfig,
@@ -3,6 +3,7 @@ declare const _default: {
3
3
  title: string;
4
4
  enablers: string;
5
5
  isEnabled: IsPluginEnabled;
6
+ isRootOnly: true;
6
7
  config: string[];
7
8
  resolveConfig: ResolveConfig;
8
9
  };
@@ -2,6 +2,7 @@ import { _glob } from '../../util/glob.js';
2
2
  const title = 'Travis CI';
3
3
  const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';
4
4
  const isEnabled = async ({ cwd }) => (await _glob({ cwd, patterns: ['.travis.yml'] })).length > 0;
5
+ const isRootOnly = true;
5
6
  const config = ['.travis.yml'];
6
7
  const resolveConfig = async (config, options) => {
7
8
  if (!config)
@@ -16,6 +17,7 @@ export default {
16
17
  title,
17
18
  enablers,
18
19
  isEnabled,
20
+ isRootOnly,
19
21
  config,
20
22
  resolveConfig,
21
23
  };
@@ -1,2 +1,2 @@
1
- export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'gatsby' | 'github-actions' | 'graphql-codegen' | 'husky' | 'jest' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'node-test-runner' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yorkie';
2
- export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dotenv", "drizzle", "eleventy", "eslint", "gatsby", "github-actions", "graphql-codegen", "husky", "jest", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "node-test-runner", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "postcss", "preconstruct", "prettier", "react-cosmos", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yorkie"];
1
+ export type PluginName = 'angular' | 'astro' | 'ava' | 'babel' | 'c8' | 'capacitor' | 'changesets' | 'commitizen' | 'commitlint' | 'cspell' | 'cucumber' | 'cypress' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'gatsby' | 'github-actions' | 'glob' | 'graphql-codegen' | 'husky' | 'jest' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mocha' | 'moonrepo' | 'msw' | 'nest' | 'netlify' | 'next' | 'node' | 'node-test-runner' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'postcss' | 'preconstruct' | 'prettier' | 'react-cosmos' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rspack' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'syncpack' | 'tailwind' | 'travis' | 'ts-node' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yorkie';
2
+ export declare const pluginNames: readonly ["angular", "astro", "ava", "babel", "c8", "capacitor", "changesets", "commitizen", "commitlint", "cspell", "cucumber", "cypress", "dotenv", "drizzle", "eleventy", "eslint", "gatsby", "github-actions", "glob", "graphql-codegen", "husky", "jest", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mocha", "moonrepo", "msw", "nest", "netlify", "next", "node", "node-test-runner", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "playwright", "playwright-ct", "playwright-test", "postcss", "preconstruct", "prettier", "react-cosmos", "release-it", "remark", "remix", "rollup", "rsbuild", "rspack", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "storybook", "stryker", "stylelint", "svelte", "syncpack", "tailwind", "travis", "ts-node", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yorkie"];
@@ -17,6 +17,7 @@ export const pluginNames = [
17
17
  'eslint',
18
18
  'gatsby',
19
19
  'github-actions',
20
+ 'glob',
20
21
  'graphql-codegen',
21
22
  'husky',
22
23
  'jest',
@@ -96,6 +96,7 @@ export interface Plugin {
96
96
  packageJsonPath?: string | ((manifest: PackageJson) => string);
97
97
  enablers?: IgnorePatterns | string;
98
98
  isEnabled?: IsPluginEnabled;
99
+ isRootOnly?: boolean;
99
100
  config?: string[];
100
101
  entry?: string[];
101
102
  production?: string[];
package/dist/util/fs.d.ts CHANGED
@@ -7,4 +7,3 @@ export declare const loadYAML: (filePath: string) => Promise<unknown>;
7
7
  export declare const loadTOML: (filePath: string) => Promise<Record<string, import("smol-toml").TomlPrimitive>>;
8
8
  export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
9
9
  export declare const parseYAML: (contents: string) => unknown;
10
- export declare const _loadJSON: (filePath: string) => Promise<any>;
package/dist/util/fs.js CHANGED
@@ -3,7 +3,6 @@ import { readFile } from 'node:fs/promises';
3
3
  import yaml from 'js-yaml';
4
4
  import { parse as parseTOML } from 'smol-toml';
5
5
  import stripJsonComments from 'strip-json-comments';
6
- import { timerify } from './Performance.js';
7
6
  import { LoaderError } from './errors.js';
8
7
  import { join } from './path.js';
9
8
  export const isDirectory = (filePath) => {
@@ -58,4 +57,3 @@ export const parseJSON = async (filePath, contents) => {
58
57
  export const parseYAML = (contents) => {
59
58
  return yaml.load(contents);
60
59
  };
61
- export const _loadJSON = timerify(loadJSON);
@@ -7,6 +7,7 @@ type GlobOptions = {
7
7
  readonly gitignore: boolean;
8
8
  readonly cwd: string;
9
9
  readonly dir: string;
10
+ label?: string;
10
11
  } & FastGlobOptionsWithoutCwd;
11
12
  type FastGlobOptionsWithoutCwd = Pick<FastGlobOptions, 'onlyDirectories' | 'ignore' | 'absolute' | 'dot'>;
12
13
  export declare const convertGitignoreToPicomatchIgnorePatterns: (pattern: string) => {
@@ -22,6 +23,6 @@ export declare const findAndParseGitignores: (cwd: string) => Promise<{
22
23
  ignores: Set<string>;
23
24
  unignores: string[];
24
25
  }>;
25
- export declare function globby(patterns: string | string[], options: GlobOptions): Promise<string[]>;
26
+ export declare function glob(patterns: string | string[], options: GlobOptions): Promise<string[]>;
26
27
  export declare function getGitIgnoredHandler(options: Options): Promise<(path: string) => boolean>;
27
28
  export {};
@@ -5,12 +5,14 @@ import fg, {} from 'fast-glob';
5
5
  import picomatch from 'picomatch';
6
6
  import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
7
7
  import { timerify } from './Performance.js';
8
+ import { compact } from './array.js';
8
9
  import { debugLogObject } from './debug.js';
9
10
  import { isFile } from './fs.js';
10
11
  import { dirname, join, relative, toPosix } from './path.js';
11
12
  const walk = promisify(_walk);
12
13
  const _picomatch = timerify(picomatch);
13
- const cachedIgnores = new Map();
14
+ const cachedGitIgnores = new Map();
15
+ const cachedGlobIgnores = new Map();
14
16
  export const convertGitignoreToPicomatchIgnorePatterns = (pattern) => {
15
17
  const negated = pattern[0] === '!';
16
18
  if (negated)
@@ -126,14 +128,14 @@ export const findAndParseGitignores = async (cwd) => {
126
128
  }
127
129
  }
128
130
  const cacheDir = ancestor ? cwd : dir;
129
- const cacheForDir = cachedIgnores.get(cwd);
131
+ const cacheForDir = cachedGitIgnores.get(cwd);
130
132
  if (ancestor && cacheForDir) {
131
133
  for (const pattern of dirIgnores)
132
134
  cacheForDir?.ignores.add(pattern);
133
135
  cacheForDir.unignores = Array.from(new Set([...cacheForDir.unignores, ...dirUnignores]));
134
136
  }
135
137
  else {
136
- cachedIgnores.set(cacheDir, { ignores: dirIgnores, unignores: Array.from(dirUnignores) });
138
+ cachedGitIgnores.set(cacheDir, { ignores: dirIgnores, unignores: Array.from(dirUnignores) });
137
139
  }
138
140
  for (const pattern of dirIgnores)
139
141
  matchers.add(_picomatch(pattern, pmOptions));
@@ -153,36 +155,45 @@ export const findAndParseGitignores = async (cwd) => {
153
155
  entryFilter: timerify(entryFilter),
154
156
  deepFilter: timerify(deepFilter),
155
157
  });
156
- debugLogObject('*', 'Parsed gitignore files', { gitignoreFiles, ignores, unignores });
158
+ debugLogObject('*', 'Parsed gitignore files', { gitignoreFiles });
157
159
  return { gitignoreFiles, ignores, unignores };
158
160
  };
159
161
  const _parseFindGitignores = timerify(findAndParseGitignores);
160
- export async function globby(patterns, options) {
162
+ export async function glob(patterns, options) {
161
163
  if (Array.isArray(patterns) && patterns.length === 0)
162
164
  return [];
163
- const ignore = options.gitignore && Array.isArray(options.ignore) ? [...options.ignore] : [];
165
+ const canCache = options.label && options.gitignore;
166
+ const willCache = canCache && !cachedGlobIgnores.has(options.dir);
167
+ const cachedIgnores = canCache && cachedGlobIgnores.get(options.dir);
168
+ const _ignore = options.gitignore && Array.isArray(options.ignore) ? [...options.ignore] : [];
164
169
  if (options.gitignore) {
165
- let dir = options.dir;
166
- let prev;
167
- while (dir) {
168
- const cacheForDir = cachedIgnores.get(dir);
169
- if (cacheForDir) {
170
- ignore.push(...cacheForDir.ignores);
170
+ if (willCache) {
171
+ let dir = options.dir;
172
+ let prev;
173
+ while (dir) {
174
+ const cacheForDir = cachedGitIgnores.get(dir);
175
+ if (cacheForDir) {
176
+ _ignore.push(...cacheForDir.ignores);
177
+ }
178
+ dir = dirname((prev = dir));
179
+ if (prev === dir || dir === '.')
180
+ break;
171
181
  }
172
- dir = dirname((prev = dir));
173
- if (prev === dir || dir === '.')
174
- break;
175
182
  }
176
183
  }
177
184
  else {
178
- ignore.push(...GLOBAL_IGNORE_PATTERNS);
185
+ _ignore.push(...GLOBAL_IGNORE_PATTERNS);
179
186
  }
180
- const fgOptions = Object.assign(options, { ignore });
181
- debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...fgOptions });
182
- return fg.glob(patterns, fgOptions);
187
+ const ignore = cachedIgnores || compact(_ignore);
188
+ const { dir, label, ...fgOptions } = { ...options, ignore };
189
+ const paths = await fg.glob(patterns, fgOptions);
190
+ debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, label ? `Finding ${label} paths` : 'Finding paths', () => ({ patterns, ...fgOptions, ignore: cachedIgnores ? `identical to ${dir} ↑` : ignore, paths }));
191
+ if (willCache)
192
+ cachedGlobIgnores.set(options.dir, ignore);
193
+ return paths;
183
194
  }
184
195
  export async function getGitIgnoredHandler(options) {
185
- cachedIgnores.clear();
196
+ cachedGitIgnores.clear();
186
197
  if (options.gitignore === false)
187
198
  return () => false;
188
199
  const gitignore = await _parseFindGitignores(options.cwd);
@@ -3,12 +3,14 @@ interface GlobOptions {
3
3
  dir?: string;
4
4
  patterns: string[];
5
5
  gitignore?: boolean;
6
+ name?: boolean;
7
+ label?: string;
6
8
  }
7
9
  export declare const prependDirToPattern: (dir: string, pattern: string) => string;
8
10
  export declare const negate: (pattern: string) => string;
9
11
  export declare const hasProductionSuffix: (pattern: string) => boolean;
10
12
  export declare const hasNoProductionSuffix: (pattern: string) => boolean;
11
- export declare const _glob: ({ cwd, dir, patterns, gitignore }: GlobOptions) => Promise<string[]>;
13
+ export declare const _glob: ({ cwd, dir, patterns, gitignore, label }: GlobOptions) => Promise<string[]>;
12
14
  export declare const _firstGlob: ({ cwd, patterns }: GlobOptions) => Promise<string | Buffer | undefined>;
13
15
  export declare const _dirGlob: ({ cwd, patterns, gitignore }: GlobOptions) => Promise<string[]>;
14
16
  export {};
package/dist/util/glob.js CHANGED
@@ -2,12 +2,12 @@ import fg from 'fast-glob';
2
2
  import { GLOBAL_IGNORE_PATTERNS } from '../constants.js';
3
3
  import { timerify } from './Performance.js';
4
4
  import { compact } from './array.js';
5
- import { globby } from './glob-core.js';
5
+ import { glob } from './glob-core.js';
6
6
  import { isAbsolute, join, relative } from './path.js';
7
+ const prepend = (pattern, relativePath) => isAbsolute(pattern.replace(/^!/, '')) ? pattern : prependDirToPattern(relativePath, pattern);
7
8
  const prependDirToPatterns = (cwd, dir, patterns) => {
8
9
  const relativePath = relative(cwd, dir);
9
- const prepend = (pattern) => isAbsolute(pattern.replace(/^!/, '')) ? pattern : prependDirToPattern(relativePath, pattern);
10
- return compact([patterns].flat().map(prepend).map(removeProductionSuffix)).sort(negatedLast);
10
+ return compact([patterns].flat().map(p => removeProductionSuffix(prepend(p, relativePath)))).sort(negatedLast);
11
11
  };
12
12
  const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
13
13
  const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
@@ -19,18 +19,19 @@ export const prependDirToPattern = (dir, pattern) => {
19
19
  export const negate = (pattern) => pattern.replace(/^!?/, '!');
20
20
  export const hasProductionSuffix = (pattern) => pattern.endsWith('!');
21
21
  export const hasNoProductionSuffix = (pattern) => !pattern.endsWith('!');
22
- const glob = async ({ cwd, dir = cwd, patterns, gitignore = true }) => {
22
+ const defaultGlob = async ({ cwd, dir = cwd, patterns, gitignore = true, label }) => {
23
23
  if (patterns.length === 0)
24
24
  return [];
25
25
  const globPatterns = prependDirToPatterns(cwd, dir, patterns);
26
26
  if (globPatterns[0].startsWith('!'))
27
27
  return [];
28
- return globby(globPatterns, {
28
+ return glob(globPatterns, {
29
29
  cwd,
30
30
  dir,
31
31
  gitignore,
32
32
  absolute: true,
33
33
  dot: true,
34
+ label,
34
35
  });
35
36
  };
36
37
  const firstGlob = async ({ cwd, patterns }) => {
@@ -39,12 +40,12 @@ const firstGlob = async ({ cwd, patterns }) => {
39
40
  return entry;
40
41
  }
41
42
  };
42
- const dirGlob = async ({ cwd, patterns, gitignore = true }) => globby(patterns, {
43
+ const dirGlob = async ({ cwd, patterns, gitignore = true }) => glob(patterns, {
43
44
  cwd,
44
45
  dir: cwd,
45
46
  onlyDirectories: true,
46
47
  gitignore,
47
48
  });
48
- export const _glob = timerify(glob);
49
+ export const _glob = timerify(defaultGlob);
49
50
  export const _firstGlob = timerify(firstGlob);
50
51
  export const _dirGlob = timerify(dirGlob);
@@ -0,0 +1,2 @@
1
+ export declare const logWarning: (prefix: string, message: string) => void;
2
+ export declare const logError: (prefix: string, message: string) => void;
@@ -0,0 +1,7 @@
1
+ import picocolors from 'picocolors';
2
+ export const logWarning = (prefix, message) => {
3
+ console.warn(`${picocolors.yellow(prefix)}: ${message}`);
4
+ };
5
+ export const logError = (prefix, message) => {
6
+ console.error(`${picocolors.red(prefix)}: ${message}`);
7
+ };
@@ -54,5 +54,5 @@ export const getEntryPathsFromManifest = (manifest, sharedGlobOptions) => {
54
54
  entryPaths.add(types);
55
55
  if (typeof typings === 'string')
56
56
  entryPaths.add(typings);
57
- return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
57
+ return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths), label: 'package.json entry' });
58
58
  };
@@ -1,4 +1,3 @@
1
- export { _loadJSON as loadJSON } from './fs.js';
2
1
  export { _load as load } from './loader.js';
3
2
  import type { Plugin, PluginOptions, RawPluginConfiguration } from '../types/config.js';
4
3
  import { type Input } from './input.js';
@@ -1,4 +1,3 @@
1
- export { _loadJSON as loadJSON } from './fs.js';
2
1
  export { _load as load } from './loader.js';
3
2
  import { arrayify } from './array.js';
4
3
  import { toEntry, toProductionEntry } from './input.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.36.3";
1
+ export declare const version = "5.36.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.36.3';
1
+ export const version = '5.36.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.36.3",
3
+ "version": "5.36.5",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {