knip 6.13.1 → 6.14.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.
Files changed (40) hide show
  1. package/dist/CacheConsultant.d.ts +3 -3
  2. package/dist/CacheConsultant.js +13 -16
  3. package/dist/ConfigurationChief.d.ts +1 -0
  4. package/dist/ConfigurationChief.js +11 -2
  5. package/dist/DependencyDeputy.d.ts +3 -0
  6. package/dist/DependencyDeputy.js +28 -8
  7. package/dist/ProjectPrincipal.d.ts +1 -0
  8. package/dist/ProjectPrincipal.js +43 -52
  9. package/dist/WorkspaceWorker.js +3 -3
  10. package/dist/cli.js +1 -1
  11. package/dist/graph/build.js +1 -0
  12. package/dist/plugins/nuxt/helpers.js +3 -3
  13. package/dist/plugins/nx/index.js +1 -3
  14. package/dist/plugins/sst/resolveFromAST.js +2 -2
  15. package/dist/run.js +7 -2
  16. package/dist/typescript/ast-helpers.js +2 -2
  17. package/dist/typescript/ast-nodes.d.ts +1 -1
  18. package/dist/typescript/ast-nodes.js +3 -1
  19. package/dist/typescript/get-imports-and-exports.js +4 -4
  20. package/dist/typescript/visitors/walk.d.ts +2 -1
  21. package/dist/typescript/visitors/walk.js +3 -1
  22. package/dist/util/Performance.d.ts +3 -1
  23. package/dist/util/Performance.js +6 -2
  24. package/dist/util/cli-arguments.d.ts +2 -1
  25. package/dist/util/cli-arguments.js +52 -50
  26. package/dist/util/disk-cache.d.ts +10 -0
  27. package/dist/util/disk-cache.js +62 -0
  28. package/dist/util/file-entry-cache.d.ts +0 -7
  29. package/dist/util/file-entry-cache.js +15 -53
  30. package/dist/util/gitignore-cache.d.ts +12 -0
  31. package/dist/util/gitignore-cache.js +77 -0
  32. package/dist/util/glob-cache.d.ts +2 -2
  33. package/dist/util/glob-cache.js +9 -57
  34. package/dist/util/glob-core.d.ts +4 -0
  35. package/dist/util/glob-core.js +14 -1
  36. package/dist/util/glob.js +12 -6
  37. package/dist/util/module-graph.js +17 -13
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +1 -1
@@ -7,6 +7,7 @@ import { GLOBAL_IGNORE_PATTERNS } from '../constants.js';
7
7
  import { compact, partition } from './array.js';
8
8
  import { debugLogObject } from './debug.js';
9
9
  import { isDirectory, isFile } from './fs.js';
10
+ import { getCachedGitignore, isGitignoreCacheEnabled, setCachedGitignore } from './gitignore-cache.js';
10
11
  import { timerify } from './Performance.js';
11
12
  import { expandIgnorePatterns, parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.js';
12
13
  import { dirname, join, relative, toPosix } from './path.js';
@@ -44,6 +45,15 @@ const findAncestorGitignoreFiles = (cwd) => {
44
45
  return gitignorePaths;
45
46
  };
46
47
  export const findAndParseGitignores = async (cwd, workspaceDirs) => {
48
+ if (isGitignoreCacheEnabled()) {
49
+ const cached = getCachedGitignore(cwd, workspaceDirs);
50
+ if (cached) {
51
+ for (const [dir, data] of cached.perDirIgnores)
52
+ cachedGitIgnores.set(dir, data);
53
+ debugLogObject('*', 'Parsed gitignore files (cached)', { gitignoreFiles: cached.gitignoreFiles });
54
+ return { gitignoreFiles: cached.gitignoreFiles, ignores: cached.ignores, unignores: cached.unignores };
55
+ }
56
+ }
47
57
  const ignores = new Set(GLOBAL_IGNORE_PATTERNS);
48
58
  const unignores = new Set();
49
59
  const gitignoreFiles = [];
@@ -171,7 +181,7 @@ export const findAndParseGitignores = async (cwd, workspaceDirs) => {
171
181
  .crawl(cwd)
172
182
  .withPromise();
173
183
  };
174
- await timerify(walkGitignores)();
184
+ await walkGitignores();
175
185
  if (unignores.size > 0) {
176
186
  const unignorePaths = new Set();
177
187
  for (const u of unignores) {
@@ -197,6 +207,9 @@ export const findAndParseGitignores = async (cwd, workspaceDirs) => {
197
207
  }
198
208
  }
199
209
  debugLogObject('*', 'Parsed gitignore files', { gitignoreFiles });
210
+ if (isGitignoreCacheEnabled()) {
211
+ setCachedGitignore(cwd, workspaceDirs, gitignoreFiles, ignores, unignores, cachedGitIgnores);
212
+ }
200
213
  return { gitignoreFiles, ignores, unignores };
201
214
  };
202
215
  const _parseFindGitignores = timerify(findAndParseGitignores);
package/dist/util/glob.js CHANGED
@@ -42,12 +42,18 @@ const defaultGlob = async ({ cwd, dir = cwd, patterns, gitignore = true, label }
42
42
  return paths;
43
43
  };
44
44
  const syncGlob = ({ cwd, patterns }) => {
45
- return globSync(patterns, {
46
- cwd,
47
- absolute: true,
48
- followSymbolicLinks: false,
49
- expandDirectories: false,
50
- });
45
+ const cacheEnabled = isGlobCacheEnabled();
46
+ const patternList = Array.isArray(patterns) ? patterns : [patterns];
47
+ const cacheKey = cacheEnabled ? computeGlobCacheKey({ patterns: patternList, cwd, dir: cwd, gitignore: false }) : '';
48
+ if (cacheEnabled) {
49
+ const cached = getCachedGlob(cacheKey);
50
+ if (cached)
51
+ return cached;
52
+ }
53
+ const paths = globSync(patterns, { cwd, absolute: true, followSymbolicLinks: false, expandDirectories: false });
54
+ if (cacheEnabled && paths.length > 0)
55
+ setCachedGlob(cacheKey, paths, cwd);
56
+ return paths;
51
57
  };
52
58
  const dirGlob = async ({ cwd, patterns, gitignore = true }) => glob(patterns, {
53
59
  cwd,
@@ -61,33 +61,37 @@ export const createImports = () => ({
61
61
  reExportNs: new Map(),
62
62
  });
63
63
  export const addValue = (map, id, value) => {
64
- if (map.has(id))
65
- map.get(id)?.add(value);
64
+ const existing = map.get(id);
65
+ if (existing)
66
+ existing.add(value);
66
67
  else
67
68
  map.set(id, new Set([value]));
68
69
  };
69
70
  export const addNsValue = (map, id, ns, value) => {
70
- if (map.has(id)) {
71
- if (map.get(id)?.has(ns))
72
- map.get(id)?.get(ns)?.add(value);
73
- else
74
- map.get(id)?.set(ns, new Set([value]));
75
- }
76
- else {
71
+ const inner = map.get(id);
72
+ if (!inner) {
77
73
  map.set(id, new Map([[ns, new Set([value])]]));
74
+ return;
78
75
  }
76
+ const set = inner.get(ns);
77
+ if (set)
78
+ set.add(value);
79
+ else
80
+ inner.set(ns, new Set([value]));
79
81
  };
80
82
  const addValues = (map, id, values) => {
81
- if (map.has(id))
83
+ const existing = map.get(id);
84
+ if (existing)
82
85
  for (const v of values)
83
- map.get(id)?.add(v);
86
+ existing.add(v);
84
87
  else
85
88
  map.set(id, values);
86
89
  };
87
90
  const addNsValues = (map, id, value) => {
88
- if (map.has(id))
91
+ const existing = map.get(id);
92
+ if (existing)
89
93
  for (const [ns, v] of value)
90
- addValues(map.get(id), ns, v);
94
+ addValues(existing, ns, v);
91
95
  else
92
96
  map.set(id, value);
93
97
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.13.1";
1
+ export declare const version = "6.14.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.13.1';
1
+ export const version = '6.14.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.13.1",
3
+ "version": "6.14.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",