knip 5.72.0 → 5.73.1

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 (35) hide show
  1. package/dist/ConfigurationChief.d.ts +12 -0
  2. package/dist/ProjectPrincipal.d.ts +2 -2
  3. package/dist/ProjectPrincipal.js +4 -4
  4. package/dist/compilers/index.d.ts +20 -0
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.js +5 -3
  7. package/dist/graph/build.js +7 -2
  8. package/dist/plugins/astro/index.js +1 -1
  9. package/dist/plugins/index.d.ts +2 -0
  10. package/dist/plugins/index.js +4 -0
  11. package/dist/plugins/next/index.js +3 -5
  12. package/dist/plugins/next/resolveFromAST.d.ts +0 -1
  13. package/dist/plugins/next/resolveFromAST.js +1 -42
  14. package/dist/plugins/next-intl/index.d.ts +3 -0
  15. package/dist/plugins/next-intl/index.js +12 -0
  16. package/dist/plugins/next-mdx/index.d.ts +3 -0
  17. package/dist/plugins/next-mdx/index.js +21 -0
  18. package/dist/plugins/next-mdx/resolveFromAST.d.ts +2 -0
  19. package/dist/plugins/next-mdx/resolveFromAST.js +43 -0
  20. package/dist/schema/configuration.d.ts +20 -0
  21. package/dist/schema/plugins.d.ts +10 -0
  22. package/dist/schema/plugins.js +2 -0
  23. package/dist/types/PluginNames.d.ts +2 -2
  24. package/dist/types/PluginNames.js +2 -0
  25. package/dist/types/module-graph.d.ts +2 -1
  26. package/dist/typescript/get-imports-and-exports.js +9 -6
  27. package/dist/typescript/visitors/dynamic-imports/requireCall.js +2 -1
  28. package/dist/util/create-options.d.ts +20 -0
  29. package/dist/util/map-workspaces.js +6 -6
  30. package/dist/util/module-graph.js +2 -1
  31. package/dist/util/modules.js +8 -4
  32. package/dist/version.d.ts +1 -1
  33. package/dist/version.js +1 -1
  34. package/package.json +1 -1
  35. package/schema.json +8 -0
@@ -327,6 +327,16 @@ export declare class ConfigurationChief {
327
327
  entry?: string | string[] | undefined;
328
328
  project?: string | string[] | undefined;
329
329
  } | undefined;
330
+ 'next-intl'?: string | boolean | string[] | {
331
+ config?: string | string[] | undefined;
332
+ entry?: string | string[] | undefined;
333
+ project?: string | string[] | undefined;
334
+ } | undefined;
335
+ 'next-mdx'?: string | boolean | string[] | {
336
+ config?: string | string[] | undefined;
337
+ entry?: string | string[] | undefined;
338
+ project?: string | string[] | undefined;
339
+ } | undefined;
330
340
  node?: string | boolean | string[] | {
331
341
  config?: string | string[] | undefined;
332
342
  entry?: string | string[] | undefined;
@@ -728,6 +738,8 @@ export declare class ConfigurationChief {
728
738
  nest?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
729
739
  netlify?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
730
740
  next?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
741
+ "next-intl"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
742
+ "next-mdx"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
731
743
  "node-modules-inspector"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
732
744
  nodemon?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
733
745
  "npm-package-json-lint"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -11,7 +11,7 @@ import type { ToSourceFilePath } from './util/to-source-path.js';
11
11
  export declare class ProjectPrincipal {
12
12
  entryPaths: Set<string>;
13
13
  projectPaths: Set<string>;
14
- nonEntryPaths: Set<string>;
14
+ programPaths: Set<string>;
15
15
  skipExportsAnalysis: Set<string>;
16
16
  cwd: string;
17
17
  compilerOptions: ts.CompilerOptions;
@@ -44,7 +44,7 @@ export declare class ProjectPrincipal {
44
44
  addEntryPaths(filePaths: Set<string> | string[], options?: {
45
45
  skipExportsAnalysis: boolean;
46
46
  }): void;
47
- addNonEntryPath(filePath: string): void;
47
+ addProgramPath(filePath: string): void;
48
48
  addProjectPath(filePath: string): void;
49
49
  deletedFiles: Set<unknown>;
50
50
  removeProjectPath(filePath: string): void;
@@ -29,7 +29,7 @@ const tsCreateProgram = timerify(ts.createProgram);
29
29
  export class ProjectPrincipal {
30
30
  entryPaths = new Set();
31
31
  projectPaths = new Set();
32
- nonEntryPaths = new Set();
32
+ programPaths = new Set();
33
33
  skipExportsAnalysis = new Set();
34
34
  cwd;
35
35
  compilerOptions;
@@ -98,7 +98,7 @@ export class ProjectPrincipal {
98
98
  this.extensions = new Set([...this.extensions, ...getCompilerExtensions(compilers)]);
99
99
  }
100
100
  createProgram() {
101
- this.backend.program = tsCreateProgram([...this.entryPaths, ...this.nonEntryPaths], this.compilerOptions, this.backend.compilerHost, this.backend.program);
101
+ this.backend.program = tsCreateProgram([...this.entryPaths, ...this.programPaths], this.compilerOptions, this.backend.compilerHost, this.backend.program);
102
102
  const typeChecker = timerify(this.backend.program.getTypeChecker);
103
103
  this.backend.typeChecker = typeChecker();
104
104
  }
@@ -117,9 +117,9 @@ export class ProjectPrincipal {
117
117
  for (const filePath of filePaths)
118
118
  this.addEntryPath(filePath, options);
119
119
  }
120
- addNonEntryPath(filePath) {
120
+ addProgramPath(filePath) {
121
121
  if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
122
- this.nonEntryPaths.add(filePath);
122
+ this.programPaths.add(filePath);
123
123
  }
124
124
  }
125
125
  addProjectPath(filePath) {
@@ -279,6 +279,16 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
279
279
  entry?: string | string[] | undefined;
280
280
  project?: string | string[] | undefined;
281
281
  } | undefined;
282
+ 'next-intl'?: string | boolean | string[] | {
283
+ config?: string | string[] | undefined;
284
+ entry?: string | string[] | undefined;
285
+ project?: string | string[] | undefined;
286
+ } | undefined;
287
+ 'next-mdx'?: string | boolean | string[] | {
288
+ config?: string | string[] | undefined;
289
+ entry?: string | string[] | undefined;
290
+ project?: string | string[] | undefined;
291
+ } | undefined;
282
292
  node?: string | boolean | string[] | {
283
293
  config?: string | string[] | undefined;
284
294
  entry?: string | string[] | undefined;
@@ -880,6 +890,16 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
880
890
  entry?: string | string[] | undefined;
881
891
  project?: string | string[] | undefined;
882
892
  } | undefined;
893
+ 'next-intl'?: string | boolean | string[] | {
894
+ config?: string | string[] | undefined;
895
+ entry?: string | string[] | undefined;
896
+ project?: string | string[] | undefined;
897
+ } | undefined;
898
+ 'next-mdx'?: string | boolean | string[] | {
899
+ config?: string | string[] | undefined;
900
+ entry?: string | string[] | undefined;
901
+ project?: string | string[] | undefined;
902
+ } | undefined;
883
903
  node?: string | boolean | string[] | {
884
904
  config?: string | string[] | undefined;
885
905
  entry?: string | string[] | undefined;
@@ -57,6 +57,7 @@ export declare const IMPORT_MODIFIERS: {
57
57
  readonly RE_EXPORT: number;
58
58
  readonly TYPE_ONLY: number;
59
59
  readonly ENTRY: number;
60
+ readonly BRIDGE: number;
60
61
  readonly OPTIONAL: number;
61
62
  readonly SIDE_EFFECTS: number;
62
63
  readonly OPAQUE: number;
package/dist/constants.js CHANGED
@@ -34,6 +34,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
34
34
  'chmod',
35
35
  'chown',
36
36
  'cksum',
37
+ 'clear',
37
38
  'cmd',
38
39
  'comm',
39
40
  'command',
@@ -216,7 +217,8 @@ export const IMPORT_MODIFIERS = {
216
217
  RE_EXPORT: 1 << 0,
217
218
  TYPE_ONLY: 1 << 1,
218
219
  ENTRY: 1 << 2,
219
- OPTIONAL: 1 << 3,
220
- SIDE_EFFECTS: 1 << 4,
221
- OPAQUE: 1 << 5,
220
+ BRIDGE: 1 << 3,
221
+ OPTIONAL: 1 << 4,
222
+ SIDE_EFFECTS: 1 << 5,
223
+ OPAQUE: 1 << 6,
222
224
  };
@@ -271,7 +271,12 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
271
271
  }
272
272
  }
273
273
  }
274
- for (const filePath of file.imports.resolved) {
274
+ for (const filePath of file.imports.programFiles) {
275
+ const isIgnored = isGitIgnored(filePath);
276
+ if (!isIgnored)
277
+ principal.addProgramPath(filePath);
278
+ }
279
+ for (const filePath of file.imports.entryFiles) {
275
280
  const isIgnored = isGitIgnored(filePath);
276
281
  if (!isIgnored)
277
282
  principal.addEntryPath(filePath, { skipExportsAnalysis: true });
@@ -283,7 +288,7 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
283
288
  file.imports.external.add({ ..._import, specifier: packageName });
284
289
  const principal = getPrincipalByFilePath(_import.filePath);
285
290
  if (principal && !isGitIgnored(_import.filePath)) {
286
- principal.addNonEntryPath(_import.filePath);
291
+ principal.addProgramPath(_import.filePath);
287
292
  }
288
293
  }
289
294
  }
@@ -16,7 +16,7 @@ const production = [
16
16
  ];
17
17
  const resolveFromAST = sourceFile => {
18
18
  const srcDir = getSrcDir(sourceFile);
19
- const setSrcDir = (entry) => entry.replace(/^`src\//, `${srcDir}/`);
19
+ const setSrcDir = (entry) => entry.replace(/^src\//, `${srcDir}/`);
20
20
  return [
21
21
  ...entry.map(setSrcDir).map(path => toEntry(path)),
22
22
  ...production.map(setSrcDir).map(path => toProductionEntry(path)),
@@ -54,6 +54,8 @@ export declare const Plugins: {
54
54
  nest: import("../types/config.js").Plugin;
55
55
  netlify: import("../types/config.js").Plugin;
56
56
  next: import("../types/config.js").Plugin;
57
+ 'next-intl': import("../types/config.js").Plugin;
58
+ 'next-mdx': import("../types/config.js").Plugin;
57
59
  node: import("../types/config.js").Plugin;
58
60
  'node-modules-inspector': import("../types/config.js").Plugin;
59
61
  nodemon: import("../types/config.js").Plugin;
@@ -53,6 +53,8 @@ import { default as nanoStaged } from './nano-staged/index.js';
53
53
  import { default as nest } from './nest/index.js';
54
54
  import { default as netlify } from './netlify/index.js';
55
55
  import { default as next } from './next/index.js';
56
+ import { default as nextIntl } from './next-intl/index.js';
57
+ import { default as nextMdx } from './next-mdx/index.js';
56
58
  import { default as node } from './node/index.js';
57
59
  import { default as nodeModulesInspector } from './node-modules-inspector/index.js';
58
60
  import { default as nodemon } from './nodemon/index.js';
@@ -174,6 +176,8 @@ export const Plugins = {
174
176
  nest,
175
177
  netlify,
176
178
  next,
179
+ 'next-intl': nextIntl,
180
+ 'next-mdx': nextMdx,
177
181
  node,
178
182
  'node-modules-inspector': nodeModulesInspector,
179
183
  nodemon,
@@ -1,6 +1,6 @@
1
- import { toDependency, toProductionEntry } from '../../util/input.js';
1
+ import { toProductionEntry } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
- import { getMdxPlugins, getPageExtensions } from './resolveFromAST.js';
3
+ import { getPageExtensions } from './resolveFromAST.js';
4
4
  const title = 'Next.js';
5
5
  const enablers = ['next'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -12,7 +12,6 @@ const productionEntryFilePatterns = [
12
12
  'app/**/sitemap.{js,ts}',
13
13
  'app/**/{icon,apple-icon}.{js,jsx,ts,tsx}',
14
14
  'app/**/{opengraph,twitter}-image.{js,jsx,ts,tsx}',
15
- 'mdx-components.{js,jsx,ts,tsx}',
16
15
  ];
17
16
  const getEntryFilePatterns = (pageExtensions = defaultPageExtensions) => {
18
17
  const patterns = [...productionEntryFilePatterns];
@@ -26,8 +25,7 @@ const resolveFromAST = sourceFile => {
26
25
  const pageExtensions = getPageExtensions(sourceFile);
27
26
  const extensions = pageExtensions.length > 0 ? pageExtensions : defaultPageExtensions;
28
27
  const patterns = getEntryFilePatterns(extensions);
29
- const mdxPlugins = getMdxPlugins(sourceFile);
30
- return [...patterns.map(id => toProductionEntry(id)), ...Array.from(mdxPlugins).map(id => toDependency(id))];
28
+ return patterns.map(id => toProductionEntry(id));
31
29
  };
32
30
  const plugin = {
33
31
  title,
@@ -1,3 +1,2 @@
1
1
  import ts from 'typescript';
2
2
  export declare const getPageExtensions: (sourceFile: ts.SourceFile) => string[];
3
- export declare const getMdxPlugins: (sourceFile: ts.SourceFile) => Set<string>;
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { getDefaultImportName, getImportMap, getPropertyValues, stripQuotes } from '../../typescript/ast-helpers.js';
2
+ import { getPropertyValues } from '../../typescript/ast-helpers.js';
3
3
  export const getPageExtensions = (sourceFile) => {
4
4
  const pageExtensions = new Set();
5
5
  function visit(node) {
@@ -13,44 +13,3 @@ export const getPageExtensions = (sourceFile) => {
13
13
  visit(sourceFile);
14
14
  return Array.from(pageExtensions);
15
15
  };
16
- const isNamedProp = (prop, name) => ts.isPropertyAssignment(prop) && prop.name.getText() === name;
17
- export const getMdxPlugins = (sourceFile) => {
18
- const plugins = new Set();
19
- const importMap = getImportMap(sourceFile);
20
- const mdxImportName = getDefaultImportName(importMap, '@next/mdx');
21
- if (!mdxImportName)
22
- return plugins;
23
- function visit(node) {
24
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === mdxImportName) {
25
- if (node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
26
- const options = node.arguments[0]?.properties.find(prop => isNamedProp(prop, 'options'));
27
- if (options && ts.isPropertyAssignment(options)) {
28
- if (ts.isObjectLiteralExpression(options.initializer)) {
29
- for (const pluginType of ['remarkPlugins', 'rehypePlugins', 'recmaPlugins']) {
30
- const props = options.initializer.properties.find(prop => isNamedProp(prop, pluginType));
31
- if (props && ts.isPropertyAssignment(props)) {
32
- if (ts.isArrayLiteralExpression(props.initializer)) {
33
- for (const element of props.initializer.elements) {
34
- if (ts.isStringLiteral(element)) {
35
- plugins.add(stripQuotes(element.text));
36
- }
37
- else if (ts.isArrayLiteralExpression(element) && element.elements.length > 0) {
38
- const firstElement = element.elements[0];
39
- if (ts.isStringLiteral(firstElement)) {
40
- plugins.add(stripQuotes(firstElement.text));
41
- }
42
- }
43
- }
44
- }
45
- }
46
- }
47
- }
48
- }
49
- }
50
- return true;
51
- }
52
- return ts.forEachChild(node, visit) ?? false;
53
- }
54
- visit(sourceFile);
55
- return plugins;
56
- };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,12 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ const title = 'next-intl';
3
+ const enablers = ['next-intl'];
4
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
+ const production = ['{src/,}i18n/request.{js,jsx,ts,tsx}'];
6
+ const plugin = {
7
+ title,
8
+ enablers,
9
+ isEnabled,
10
+ production,
11
+ };
12
+ export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,21 @@
1
+ import { toDependency, toProductionEntry } from '../../util/input.js';
2
+ import { hasDependency } from '../../util/plugin.js';
3
+ import { getMdxPlugins } from './resolveFromAST.js';
4
+ const title = 'Next.js MDX';
5
+ const enablers = ['@next/mdx'];
6
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
+ const config = ['next.config.{js,ts,cjs,mjs}'];
8
+ const production = ['{src/,}mdx-components.{js,jsx,ts,tsx}'];
9
+ const resolveFromAST = sourceFile => {
10
+ const mdxPlugins = getMdxPlugins(sourceFile);
11
+ return [...production.map(id => toProductionEntry(id)), ...Array.from(mdxPlugins).map(id => toDependency(id))];
12
+ };
13
+ const plugin = {
14
+ title,
15
+ enablers,
16
+ isEnabled,
17
+ config,
18
+ production,
19
+ resolveFromAST,
20
+ };
21
+ export default plugin;
@@ -0,0 +1,2 @@
1
+ import ts from 'typescript';
2
+ export declare const getMdxPlugins: (sourceFile: ts.SourceFile) => Set<string>;
@@ -0,0 +1,43 @@
1
+ import ts from 'typescript';
2
+ import { getDefaultImportName, getImportMap, stripQuotes } from '../../typescript/ast-helpers.js';
3
+ const isNamedProp = (prop, name) => ts.isPropertyAssignment(prop) && prop.name.getText() === name;
4
+ export const getMdxPlugins = (sourceFile) => {
5
+ const plugins = new Set();
6
+ const importMap = getImportMap(sourceFile);
7
+ const mdxImportName = getDefaultImportName(importMap, '@next/mdx');
8
+ if (!mdxImportName)
9
+ return plugins;
10
+ function visit(node) {
11
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === mdxImportName) {
12
+ if (node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
13
+ const options = node.arguments[0]?.properties.find(prop => isNamedProp(prop, 'options'));
14
+ if (options && ts.isPropertyAssignment(options)) {
15
+ if (ts.isObjectLiteralExpression(options.initializer)) {
16
+ for (const pluginType of ['remarkPlugins', 'rehypePlugins', 'recmaPlugins']) {
17
+ const props = options.initializer.properties.find(prop => isNamedProp(prop, pluginType));
18
+ if (props && ts.isPropertyAssignment(props)) {
19
+ if (ts.isArrayLiteralExpression(props.initializer)) {
20
+ for (const element of props.initializer.elements) {
21
+ if (ts.isStringLiteral(element)) {
22
+ plugins.add(stripQuotes(element.text));
23
+ }
24
+ else if (ts.isArrayLiteralExpression(element) && element.elements.length > 0) {
25
+ const firstElement = element.elements[0];
26
+ if (ts.isStringLiteral(firstElement)) {
27
+ plugins.add(stripQuotes(firstElement.text));
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ return true;
38
+ }
39
+ return ts.forEachChild(node, visit) ?? false;
40
+ }
41
+ visit(sourceFile);
42
+ return plugins;
43
+ };
@@ -277,6 +277,16 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
277
277
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
278
278
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
279
279
  }, z.core.$strip>]>>;
280
+ 'next-intl': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
281
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
282
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
283
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
284
+ }, z.core.$strip>]>>;
285
+ 'next-mdx': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
286
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
287
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
288
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
289
+ }, z.core.$strip>]>>;
280
290
  node: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
281
291
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
282
292
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -878,6 +888,16 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
878
888
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
879
889
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
880
890
  }, z.core.$strip>]>>;
891
+ 'next-intl': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
892
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
893
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
894
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
895
+ }, z.core.$strip>]>>;
896
+ 'next-mdx': z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
897
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
898
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
899
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
900
+ }, z.core.$strip>]>>;
881
901
  node: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
882
902
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
883
903
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -281,6 +281,16 @@ export declare const pluginsSchema: z.ZodMiniObject<{
281
281
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
282
282
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
283
283
  }, z.core.$strip>]>;
284
+ 'next-intl': z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
285
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
286
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
287
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
288
+ }, z.core.$strip>]>;
289
+ 'next-mdx': z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
290
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
291
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
292
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
293
+ }, z.core.$strip>]>;
284
294
  node: z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
285
295
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
286
296
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -65,6 +65,8 @@ export const pluginsSchema = z.object({
65
65
  nest: pluginSchema,
66
66
  netlify: pluginSchema,
67
67
  next: pluginSchema,
68
+ 'next-intl': pluginSchema,
69
+ 'next-mdx': pluginSchema,
68
70
  node: pluginSchema,
69
71
  'node-modules-inspector': pluginSchema,
70
72
  nodemon: pluginSchema,
@@ -1,2 +1,2 @@
1
- export type PluginName = 'angular' | 'astro' | 'astro-db' | 'ava' | 'babel' | 'biome' | 'bumpp' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'danger' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mdx' | 'mdxlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'rstest' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'svgr' | 'syncpack' | 'tailwind' | 'taskfile' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
- export declare const pluginNames: readonly ["angular", "astro", "astro-db", "ava", "babel", "biome", "bumpp", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "danger", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mdx", "mdxlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "rstest", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "svgr", "syncpack", "tailwind", "taskfile", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
1
+ export type PluginName = 'angular' | 'astro' | 'astro-db' | 'ava' | 'babel' | 'biome' | 'bumpp' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'danger' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mdx' | 'mdxlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'next-intl' | 'next-mdx' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'rstest' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'svgr' | 'syncpack' | 'tailwind' | 'taskfile' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
+ export declare const pluginNames: readonly ["angular", "astro", "astro-db", "ava", "babel", "biome", "bumpp", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "danger", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mdx", "mdxlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "next-intl", "next-mdx", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "rstest", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "svgr", "syncpack", "tailwind", "taskfile", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
@@ -54,6 +54,8 @@ export const pluginNames = [
54
54
  'nest',
55
55
  'netlify',
56
56
  'next',
57
+ 'next-intl',
58
+ 'next-mdx',
57
59
  'node',
58
60
  'node-modules-inspector',
59
61
  'nodemon',
@@ -58,7 +58,8 @@ export type FileNode = {
58
58
  internal: ImportMap;
59
59
  external: Set<Import>;
60
60
  unresolved: Set<Import>;
61
- resolved: Set<FilePath>;
61
+ programFiles: Set<FilePath>;
62
+ entryFiles: Set<FilePath>;
62
63
  imports: Imports;
63
64
  };
64
65
  exports: ExportMap;
@@ -37,7 +37,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
37
37
  const internal = new Map();
38
38
  const external = new Set();
39
39
  const unresolved = new Set();
40
- const resolved = new Set();
40
+ const programFiles = new Set();
41
+ const entryFiles = new Set();
41
42
  const imports = new Set();
42
43
  const exports = new Map();
43
44
  const aliasedExports = new Map();
@@ -132,9 +133,11 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
132
133
  if (module) {
133
134
  const filePath = module.resolvedFileName;
134
135
  if (filePath) {
135
- if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.ENTRY && !isInNodeModules(filePath)) {
136
- resolved.add(filePath);
137
- return;
136
+ if (!isInNodeModules(filePath)) {
137
+ if (opts.modifiers & IMPORT_MODIFIERS.ENTRY)
138
+ entryFiles.add(filePath);
139
+ if (opts.modifiers & IMPORT_MODIFIERS.BRIDGE)
140
+ programFiles.add(filePath);
138
141
  }
139
142
  if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
140
143
  const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
@@ -176,7 +179,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
176
179
  if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
177
180
  return;
178
181
  if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.OPTIONAL) {
179
- resolved.add(resolve(dirname(sourceFile.fileName), opts.specifier));
182
+ programFiles.add(resolve(dirname(sourceFile.fileName), opts.specifier));
180
183
  return;
181
184
  }
182
185
  const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
@@ -441,7 +444,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
441
444
  item.symbol = undefined;
442
445
  }
443
446
  return {
444
- imports: { internal, external, resolved, imports, unresolved },
447
+ imports: { internal, external, programFiles, entryFiles, imports, unresolved },
445
448
  exports,
446
449
  duplicates: [...aliasedExports.values()],
447
450
  scripts,
@@ -1,12 +1,13 @@
1
1
  import ts from 'typescript';
2
2
  import { IMPORT_MODIFIERS, IMPORT_STAR } from '../../../constants.js';
3
3
  import { findAncestor, findDescendants, isModuleExportsAccess, isRequireCall, isTopLevel } from '../../ast-helpers.js';
4
+ import { isNotJS } from '../helpers.js';
4
5
  import { importVisitor as visit } from '../index.js';
5
6
  export default visit(() => true, node => {
6
7
  if (isRequireCall(node)) {
7
8
  if (ts.isStringLiteralLike(node.arguments[0])) {
8
9
  const specifier = node.arguments[0].text;
9
- const modifiers = IMPORT_MODIFIERS.NONE;
10
+ const modifiers = isNotJS(node.getSourceFile()) ? IMPORT_MODIFIERS.BRIDGE : IMPORT_MODIFIERS.NONE;
10
11
  if (specifier) {
11
12
  const propertyAccessExpression = findAncestor(node, _node => {
12
13
  if (ts.isExpressionStatement(_node) || ts.isCallExpression(_node))
@@ -316,6 +316,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
316
316
  entry?: string | string[] | undefined;
317
317
  project?: string | string[] | undefined;
318
318
  } | undefined;
319
+ 'next-intl'?: string | boolean | string[] | {
320
+ config?: string | string[] | undefined;
321
+ entry?: string | string[] | undefined;
322
+ project?: string | string[] | undefined;
323
+ } | undefined;
324
+ 'next-mdx'?: string | boolean | string[] | {
325
+ config?: string | string[] | undefined;
326
+ entry?: string | string[] | undefined;
327
+ project?: string | string[] | undefined;
328
+ } | undefined;
319
329
  node?: string | boolean | string[] | {
320
330
  config?: string | string[] | undefined;
321
331
  entry?: string | string[] | undefined;
@@ -917,6 +927,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
917
927
  entry?: string | string[] | undefined;
918
928
  project?: string | string[] | undefined;
919
929
  } | undefined;
930
+ 'next-intl'?: string | boolean | string[] | {
931
+ config?: string | string[] | undefined;
932
+ entry?: string | string[] | undefined;
933
+ project?: string | string[] | undefined;
934
+ } | undefined;
935
+ 'next-mdx'?: string | boolean | string[] | {
936
+ config?: string | string[] | undefined;
937
+ entry?: string | string[] | undefined;
938
+ project?: string | string[] | undefined;
939
+ } | undefined;
920
940
  node?: string | boolean | string[] | {
921
941
  config?: string | string[] | undefined;
922
942
  entry?: string | string[] | undefined;
@@ -1,7 +1,6 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import fg from 'fast-glob';
3
3
  import { partition } from './array.js';
4
- import { debugLog } from './debug.js';
5
4
  import { ConfigurationError } from './errors.js';
6
5
  import { getPackageName } from './package-name.js';
7
6
  import { join } from './path.js';
@@ -11,14 +10,15 @@ export default async function mapWorkspaces(cwd, workspaces) {
11
10
  const wsPkgNames = new Set();
12
11
  if (patterns.length === 0 && negatedPatterns.length === 0)
13
12
  return [packages, wsPkgNames];
14
- const matches = await fg.glob(patterns, {
13
+ const manifestPatterns = patterns.map(p => join(p, 'package.json'));
14
+ const matches = await fg.glob(manifestPatterns, {
15
15
  cwd,
16
- onlyDirectories: true,
17
- ignore: ['**/node_modules/**', ...negatedPatterns],
16
+ ignore: ['**/node_modules/**', ...negatedPatterns.map(p => p.slice(1))],
18
17
  });
19
- for (const name of matches) {
18
+ for (const match of matches) {
19
+ const name = match === 'package.json' ? '.' : match.replace(/\/package\.json$/, '');
20
20
  const dir = join(cwd, name);
21
- const manifestPath = join(dir, 'package.json');
21
+ const manifestPath = join(cwd, match);
22
22
  try {
23
23
  const manifestStr = await readFile(manifestPath, 'utf8');
24
24
  const manifest = JSON.parse(manifestStr);
@@ -34,7 +34,8 @@ const createFileNode = () => ({
34
34
  internal: new Map(),
35
35
  external: new Set(),
36
36
  unresolved: new Set(),
37
- resolved: new Set(),
37
+ programFiles: new Set(),
38
+ entryFiles: new Set(),
38
39
  imports: new Set(),
39
40
  },
40
41
  exports: new Map(),
@@ -45,13 +45,17 @@ const CHAR_COLON = 58;
45
45
  const CHAR_HASH = 35;
46
46
  const CHAR_QUESTION = 63;
47
47
  export const sanitizeSpecifier = (specifier) => {
48
- if (isBuiltin(specifier) || isAbsolute(specifier) || specifier.startsWith(PROTOCOL_VIRTUAL))
48
+ if (isBuiltin(specifier) ||
49
+ isAbsolute(specifier) ||
50
+ specifier.charCodeAt(0) === CHAR_COLON ||
51
+ specifier.startsWith(PROTOCOL_VIRTUAL)) {
49
52
  return specifier;
53
+ }
50
54
  const len = specifier.length;
51
55
  let start = 0;
52
56
  let end = len;
53
57
  let colon = -1;
54
- let sawSlash = false;
58
+ let hasSlash = false;
55
59
  for (let i = 0; i < len; i++) {
56
60
  const ch = specifier.charCodeAt(i);
57
61
  if (i === start && (ch === CHAR_EXCLAMATION || ch === CHAR_DASH)) {
@@ -59,9 +63,9 @@ export const sanitizeSpecifier = (specifier) => {
59
63
  continue;
60
64
  }
61
65
  if (ch === CHAR_SLASH && colon === -1) {
62
- sawSlash = true;
66
+ hasSlash = true;
63
67
  }
64
- if (colon === -1 && ch === CHAR_COLON && !sawSlash) {
68
+ if (colon === -1 && ch === CHAR_COLON && !hasSlash) {
65
69
  colon = i;
66
70
  }
67
71
  if (ch === CHAR_EXCLAMATION || ch === CHAR_QUESTION || (ch === CHAR_HASH && i > start)) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.72.0";
1
+ export declare const version = "5.73.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.72.0';
1
+ export const version = '5.73.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.72.0",
3
+ "version": "5.73.1",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
package/schema.json CHANGED
@@ -554,6 +554,14 @@
554
554
  "title": "Next.js plugin configuration (https://knip.dev/reference/plugins/main)",
555
555
  "$ref": "#/definitions/plugin"
556
556
  },
557
+ "next-intl": {
558
+ "title": "next-intl plugin configuration (https://knip.dev/reference/plugins/next-intl)",
559
+ "$ref": "#/definitions/plugin"
560
+ },
561
+ "next-mdx": {
562
+ "title": "next-mdx plugin configuration (https://knip.dev/reference/plugins/next-mdx)",
563
+ "$ref": "#/definitions/plugin"
564
+ },
557
565
  "node": {
558
566
  "title": "node plugin configuration (https://knip.dev/reference/plugins/node)",
559
567
  "$ref": "#/definitions/plugin"