knip 5.2.0 → 5.2.2

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.
@@ -67,7 +67,7 @@ export declare class ConfigurationChief {
67
67
  ignoreBinaries: (string | RegExp)[];
68
68
  ignoreDependencies: (string | RegExp)[];
69
69
  };
70
- getConfigForWorkspace(workspaceName: string, extensions: string[]): {
70
+ getConfigForWorkspace(workspaceName: string, extensions?: string[]): {
71
71
  astro?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
72
72
  svelte?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
73
73
  vue?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -275,7 +275,7 @@ export class ConfigurationChief {
275
275
  name,
276
276
  pkgName,
277
277
  dir,
278
- config: this.getConfigForWorkspace(name, DEFAULT_EXTENSIONS),
278
+ config: this.getConfigForWorkspace(name),
279
279
  ancestors: this.availableWorkspaceNames.reduce(getAncestors(name), []),
280
280
  manifestPath: join(dir, 'package.json'),
281
281
  };
@@ -46,8 +46,8 @@ export class IssueFixer {
46
46
  if (exportPositions.length > 0) {
47
47
  const sourceFileText = exportPositions.reduce((text, [start, end]) => text.substring(0, start) + text.substring(end), await readFile(filePath, 'utf-8'));
48
48
  const withoutEmptyReExports = sourceFileText
49
- .replaceAll(/export \{[ ,]+\} from ('|")[^'"]+('|");?\n?/g, '')
50
- .replaceAll(/export \{[ ,]+\};?\n?/g, '');
49
+ .replaceAll(/export \{[ ,]+\} from ('|")[^'"]+('|");?\r?\n?/g, '')
50
+ .replaceAll(/export \{[ ,]+\};?\r?\n?/g, '');
51
51
  await writeFile(filePath, withoutEmptyReExports);
52
52
  }
53
53
  }
package/dist/constants.js CHANGED
@@ -53,6 +53,7 @@ export const IGNORED_DEPENDENCIES = new Set(['knip', 'typescript']);
53
53
  export const IGNORED_RUNTIME_DEPENDENCIES = new Set(['bun']);
54
54
  export const FOREIGN_FILE_EXTENSIONS = new Set([
55
55
  '.avif',
56
+ '.css',
56
57
  '.eot',
57
58
  '.gif',
58
59
  '.html',
package/dist/index.js CHANGED
@@ -434,7 +434,7 @@ export const main = async (unresolvedConfiguration) => {
434
434
  if (getReExportingEntryFile(importsForExport, identifier))
435
435
  continue;
436
436
  }
437
- exportLookupLog(-1, `Looking up export ${identifier} from`, filePath);
437
+ exportLookupLog(-1, `Looking up ${identifier} export from`, filePath);
438
438
  if (isIdentifierReferenced(filePath, identifier, importsForExport)) {
439
439
  if (exportedItem.type === 'enum') {
440
440
  exportedItem.members?.forEach(member => {
@@ -7,8 +7,9 @@ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
7
  const config = ['package.json'];
8
8
  const entry = ['mockServiceWorker.js'];
9
9
  const resolveEntryPaths = async (localConfig) => {
10
- const workerDirectory = localConfig?.workerDirectory ?? '.';
11
- return entry.map(pattern => toEntryPattern(join(workerDirectory, pattern)));
10
+ const workerDirectory = localConfig?.workerDirectory;
11
+ const dir = workerDirectory ? [workerDirectory].flat()[0] : '.';
12
+ return entry.map(pattern => toEntryPattern(join(dir, pattern)));
12
13
  };
13
14
  export default {
14
15
  title,
@@ -21,6 +21,8 @@ export class SourceFileManager {
21
21
  return sourceFile;
22
22
  }
23
23
  getSourceFile(filePath) {
24
+ if (this.sourceFileCache.has(filePath))
25
+ return this.sourceFileCache.get(filePath);
24
26
  const ext = extname(filePath);
25
27
  const compiler = this.syncCompilers.get(ext);
26
28
  if (FOREIGN_FILE_EXTENSIONS.has(ext) && !compiler)
@@ -30,8 +32,6 @@ export class SourceFileManager {
30
32
  return undefined;
31
33
  return this.createSourceFile(filePath, '');
32
34
  }
33
- if (this.sourceFileCache.has(filePath))
34
- return this.sourceFileCache.get(filePath);
35
35
  const contents = ts.sys.readFile(filePath);
36
36
  if (typeof contents !== 'string') {
37
37
  if (isInternal(filePath))
@@ -92,20 +92,22 @@ export default visit(() => true, (node, { isFixExports, isFixTypes }) => {
92
92
  };
93
93
  }
94
94
  if (ts.isTypeAliasDeclaration(node)) {
95
+ const identifier = defaultKeyword ? 'default' : node.name.getText();
95
96
  const fix = isFixTypes ? [exportKeyword.getStart(), exportKeyword.getEnd() + 1] : undefined;
96
97
  return {
97
98
  node,
98
- identifier: node.name.getText(),
99
+ identifier,
99
100
  type: SymbolType.TYPE,
100
101
  pos: node.name.getStart(),
101
102
  fix,
102
103
  };
103
104
  }
104
105
  if (ts.isInterfaceDeclaration(node)) {
106
+ const identifier = defaultKeyword ? 'default' : node.name.getText();
105
107
  const fix = isFixTypes ? [exportKeyword.getStart(), exportKeyword.getEnd() + 1] : undefined;
106
108
  return {
107
109
  node,
108
- identifier: node.name.getText(),
110
+ identifier,
109
111
  type: SymbolType.INTERFACE,
110
112
  pos: node.name.getStart(),
111
113
  fix,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.2.0";
1
+ export declare const version = "5.2.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.2.0';
1
+ export const version = '5.2.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {