knip 5.69.0 → 5.70.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 (66) hide show
  1. package/dist/CatalogCounselor.d.ts +1 -1
  2. package/dist/CatalogCounselor.js +5 -2
  3. package/dist/ConfigurationChief.d.ts +6 -0
  4. package/dist/DependencyDeputy.js +10 -3
  5. package/dist/IssueFixer.d.ts +0 -6
  6. package/dist/IssueFixer.js +37 -56
  7. package/dist/binaries/package-manager/yarn.js +1 -0
  8. package/dist/binaries/plugins.js +4 -4
  9. package/dist/compilers/index.d.ts +10 -0
  10. package/dist/compilers/index.js +2 -0
  11. package/dist/compilers/prisma.d.ts +6 -0
  12. package/dist/compilers/prisma.js +13 -0
  13. package/dist/constants.d.ts +4 -0
  14. package/dist/constants.js +4 -0
  15. package/dist/graph/analyze.d.ts +1 -1
  16. package/dist/graph/analyze.js +20 -17
  17. package/dist/graph/build.js +3 -3
  18. package/dist/index.js +1 -2
  19. package/dist/plugins/index.d.ts +1 -0
  20. package/dist/plugins/index.js +2 -0
  21. package/dist/plugins/next/index.js +4 -5
  22. package/dist/plugins/prisma/index.js +27 -5
  23. package/dist/plugins/prisma/types.d.ts +1 -0
  24. package/dist/plugins/taskfile/index.d.ts +3 -0
  25. package/dist/plugins/taskfile/index.js +111 -0
  26. package/dist/plugins/taskfile/types.d.ts +25 -0
  27. package/dist/plugins/taskfile/types.js +1 -0
  28. package/dist/plugins/vitest/helpers.d.ts +1 -1
  29. package/dist/plugins/vitest/helpers.js +1 -1
  30. package/dist/plugins/vitest/index.js +11 -4
  31. package/dist/reporters/util/configuration-hints.js +1 -1
  32. package/dist/schema/configuration.d.ts +10 -0
  33. package/dist/schema/plugins.d.ts +5 -0
  34. package/dist/schema/plugins.js +1 -0
  35. package/dist/types/PluginNames.d.ts +2 -2
  36. package/dist/types/PluginNames.js +1 -0
  37. package/dist/types/args.d.ts +4 -1
  38. package/dist/types/exports.d.ts +1 -1
  39. package/dist/types/issues.d.ts +2 -0
  40. package/dist/types/module-graph.d.ts +6 -6
  41. package/dist/typescript/ast-helpers.d.ts +10 -1
  42. package/dist/typescript/ast-helpers.js +33 -4
  43. package/dist/typescript/get-imports-and-exports.js +51 -46
  44. package/dist/typescript/pragmas/custom.d.ts +3 -0
  45. package/dist/typescript/pragmas/custom.js +25 -0
  46. package/dist/typescript/pragmas/index.d.ts +3 -0
  47. package/dist/typescript/pragmas/index.js +3 -0
  48. package/dist/typescript/pragmas/typescript.d.ts +3 -0
  49. package/dist/typescript/pragmas/typescript.js +29 -0
  50. package/dist/typescript/visitors/dynamic-imports/importCall.js +21 -9
  51. package/dist/typescript/visitors/dynamic-imports/importType.js +1 -1
  52. package/dist/typescript/visitors/exports/exportDeclaration.js +1 -1
  53. package/dist/typescript/visitors/helpers.d.ts +0 -2
  54. package/dist/typescript/visitors/helpers.js +0 -38
  55. package/dist/typescript/visitors/imports/importDeclaration.js +4 -4
  56. package/dist/typescript/visitors/imports/importEqualsDeclaration.js +1 -1
  57. package/dist/util/create-options.d.ts +10 -0
  58. package/dist/util/get-referenced-inputs.js +4 -0
  59. package/dist/util/has-strictly-ns-references.d.ts +3 -3
  60. package/dist/util/is-identifier-referenced.js +10 -10
  61. package/dist/util/module-graph.d.ts +2 -2
  62. package/dist/util/module-graph.js +22 -22
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +5 -5
  66. package/schema.json +4 -0
@@ -14,5 +14,5 @@ export declare class CatalogCounselor {
14
14
  constructor(options: MainOptions);
15
15
  private addReferencedCatalogEntry;
16
16
  addWorkspace(manifest: PackageJson): void;
17
- settleCatalogIssues(): Promise<Issue[]>;
17
+ settleCatalogIssues(options: MainOptions): Promise<Issue[]>;
18
18
  }
@@ -23,7 +23,7 @@ export class CatalogCounselor {
23
23
  for (const catalogEntryName of catalogReferences)
24
24
  this.addReferencedCatalogEntry(catalogEntryName);
25
25
  }
26
- async settleCatalogIssues() {
26
+ async settleCatalogIssues(options) {
27
27
  if (this.entries.size === 0)
28
28
  return [];
29
29
  const filePath = this.filePath;
@@ -38,7 +38,10 @@ export class CatalogCounselor {
38
38
  if (!this.referencedEntries.has(entry)) {
39
39
  const [parentSymbol, symbol] = entry.split(':');
40
40
  const pos = peeker.getLocation(parentSymbol, symbol);
41
- catalogIssues.push({ type: 'catalog', filePath, workspace, symbol, parentSymbol, ...pos });
41
+ const fixes = [];
42
+ if (options.isFix && isYaml && pos)
43
+ fixes.push([pos.line, 0, 0]);
44
+ catalogIssues.push({ type: 'catalog', filePath, workspace, symbol, parentSymbol, fixes, ...pos });
42
45
  }
43
46
  }
44
47
  }
@@ -537,6 +537,11 @@ export declare class ConfigurationChief {
537
537
  entry?: string | string[] | undefined;
538
538
  project?: string | string[] | undefined;
539
539
  } | undefined;
540
+ taskfile?: string | boolean | string[] | {
541
+ config?: string | string[] | undefined;
542
+ entry?: string | string[] | undefined;
543
+ project?: string | string[] | undefined;
544
+ } | undefined;
540
545
  travis?: string | boolean | string[] | {
541
546
  config?: string | string[] | undefined;
542
547
  entry?: string | string[] | undefined;
@@ -758,6 +763,7 @@ export declare class ConfigurationChief {
758
763
  svgo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
759
764
  syncpack?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
760
765
  tailwind?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
766
+ taskfile?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
761
767
  travis?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
762
768
  "ts-node"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
763
769
  tsdown?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -213,15 +213,22 @@ export class DependencyDeputy {
213
213
  const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency, false);
214
214
  for (const symbol of this.getProductionDependencies(workspace).filter(isNotReferencedDependency)) {
215
215
  const position = peeker.getLocation('dependencies', symbol);
216
- dependencyIssues.push({ type: 'dependencies', workspace, filePath, symbol, ...position });
216
+ dependencyIssues.push({ type: 'dependencies', workspace, filePath, symbol, fixes: [], ...position });
217
217
  }
218
218
  for (const symbol of this.getDevDependencies(workspace).filter(isNotReferencedDependency)) {
219
219
  const position = peeker.getLocation('devDependencies', symbol);
220
- devDependencyIssues.push({ type: 'devDependencies', filePath, workspace, symbol, ...position });
220
+ devDependencyIssues.push({ type: 'devDependencies', filePath, workspace, symbol, fixes: [], ...position });
221
221
  }
222
222
  for (const symbol of this.getOptionalPeerDependencies(workspace).filter(d => isReferencedDependency(d))) {
223
223
  const pos = peeker.getLocation('optionalPeerDependencies', symbol);
224
- optionalPeerDependencyIssues.push({ type: 'optionalPeerDependencies', filePath, workspace, symbol, ...pos });
224
+ optionalPeerDependencyIssues.push({
225
+ type: 'optionalPeerDependencies',
226
+ filePath,
227
+ workspace,
228
+ symbol,
229
+ fixes: [],
230
+ ...pos,
231
+ });
225
232
  }
226
233
  }
227
234
  return { dependencyIssues, devDependencyIssues, optionalPeerDependencyIssues };
@@ -1,15 +1,9 @@
1
- import type { Fix, Fixes } from './types/exports.js';
2
1
  import type { Issues } from './types/issues.js';
3
2
  import type { MainOptions } from './util/create-options.js';
4
3
  export declare class IssueFixer {
5
4
  options: MainOptions;
6
- unusedTypeNodes: Map<string, Set<Fix>>;
7
- unusedExportNodes: Map<string, Set<Fix>>;
8
5
  constructor(options: MainOptions);
9
- addUnusedTypeNode(filePath: string, fixes: Fixes | undefined): void;
10
- addUnusedExportNode(filePath: string, fixes: Fixes | undefined): void;
11
6
  fixIssues(issues: Issues): Promise<Set<string>>;
12
- private markExportIssuesFixed;
13
7
  private removeUnusedFiles;
14
8
  private removeUnusedExports;
15
9
  private removeUnusedDependencies;
@@ -1,33 +1,13 @@
1
1
  import { readFile, rm, writeFile } from 'node:fs/promises';
2
2
  import { DEFAULT_CATALOG } from './util/catalog.js';
3
3
  import { load, save } from './util/package-json.js';
4
- import { extname, join, relative } from './util/path.js';
4
+ import { extname, join } from './util/path.js';
5
5
  import { removeExport } from './util/remove-export.js';
6
6
  export class IssueFixer {
7
7
  options;
8
- unusedTypeNodes = new Map();
9
- unusedExportNodes = new Map();
10
8
  constructor(options) {
11
9
  this.options = options;
12
10
  }
13
- addUnusedTypeNode(filePath, fixes) {
14
- if (!fixes || fixes.length === 0)
15
- return;
16
- if (this.unusedTypeNodes.has(filePath))
17
- for (const fix of fixes)
18
- this.unusedTypeNodes.get(filePath)?.add(fix);
19
- else
20
- this.unusedTypeNodes.set(filePath, new Set(fixes));
21
- }
22
- addUnusedExportNode(filePath, fixes) {
23
- if (!fixes || fixes.length === 0)
24
- return;
25
- if (this.unusedExportNodes.has(filePath))
26
- for (const fix of fixes)
27
- this.unusedExportNodes.get(filePath)?.add(fix);
28
- else
29
- this.unusedExportNodes.set(filePath, new Set(fixes));
30
- }
31
11
  async fixIssues(issues) {
32
12
  const touchedFiles = new Set();
33
13
  await this.removeUnusedFiles(issues);
@@ -39,18 +19,6 @@ export class IssueFixer {
39
19
  touchedFiles.add(filePath);
40
20
  return touchedFiles;
41
21
  }
42
- markExportIssuesFixed(issues, filePath) {
43
- const relPath = relative(this.options.cwd, filePath);
44
- const types = [
45
- ...(this.options.isFixUnusedTypes ? ['types', 'nsTypes', 'classMembers', 'enumMembers'] : []),
46
- ...(this.options.isFixUnusedExports ? ['exports', 'nsExports'] : []),
47
- ];
48
- for (const type of types) {
49
- for (const id in issues[type][relPath]) {
50
- issues[type][relPath][id].isFixed = true;
51
- }
52
- }
53
- }
54
22
  async removeUnusedFiles(issues) {
55
23
  if (!this.options.isFixFiles)
56
24
  return;
@@ -61,18 +29,33 @@ export class IssueFixer {
61
29
  }
62
30
  async removeUnusedExports(issues) {
63
31
  const touchedFiles = new Set();
64
- const filePaths = new Set([...this.unusedTypeNodes.keys(), ...this.unusedExportNodes.keys()]);
65
- for (const filePath of filePaths) {
66
- const types = (this.options.isFixUnusedTypes && this.unusedTypeNodes.get(filePath)) || [];
67
- const exports = (this.options.isFixUnusedExports && this.unusedExportNodes.get(filePath)) || [];
68
- const exportPositions = [...types, ...exports]
69
- .filter((fix) => fix !== undefined)
70
- .sort((a, b) => b[0] - a[0]);
71
- if (exportPositions.length > 0) {
72
- const sourceFileText = exportPositions.reduce((text, [start, end, flags]) => removeExport({ text, start, end, flags }), await readFile(filePath, 'utf-8'));
73
- await writeFile(filePath, sourceFileText);
74
- touchedFiles.add(filePath);
75
- this.markExportIssuesFixed(issues, filePath);
32
+ const types = [
33
+ ...(this.options.isFixUnusedTypes ? ['types', 'nsTypes', 'classMembers', 'enumMembers'] : []),
34
+ ...(this.options.isFixUnusedExports ? ['exports', 'nsExports'] : []),
35
+ ];
36
+ if (types.length === 0)
37
+ return touchedFiles;
38
+ const allFixes = new Map();
39
+ for (const type of types) {
40
+ for (const [filePath, issueMap] of Object.entries(issues[type])) {
41
+ const fixes = allFixes.get(filePath) ?? [];
42
+ for (const issue of Object.values(issueMap))
43
+ fixes.push(...issue.fixes);
44
+ allFixes.set(filePath, fixes);
45
+ }
46
+ }
47
+ for (const [filePath, fixes] of allFixes) {
48
+ const absFilePath = join(this.options.cwd, filePath);
49
+ const sourceFileText = fixes
50
+ .sort((a, b) => b[0] - a[0])
51
+ .reduce((text, [start, end, flags]) => removeExport({ text, start, end, flags }), await readFile(absFilePath, 'utf-8'));
52
+ await writeFile(absFilePath, sourceFileText);
53
+ touchedFiles.add(absFilePath);
54
+ for (const type of types) {
55
+ const issueMap = issues[type]?.[filePath];
56
+ if (issueMap)
57
+ for (const issue of Object.values(issueMap))
58
+ issue.isFixed = true;
76
59
  }
77
60
  }
78
61
  return touchedFiles;
@@ -102,7 +85,7 @@ export class IssueFixer {
102
85
  }
103
86
  }
104
87
  await save(absFilePath, pkg);
105
- touchedFiles.add(filePath);
88
+ touchedFiles.add(absFilePath);
106
89
  }
107
90
  return touchedFiles;
108
91
  }
@@ -115,15 +98,13 @@ export class IssueFixer {
115
98
  if (['.yml', '.yaml'].includes(extname(filePath))) {
116
99
  const absFilePath = join(this.options.cwd, filePath);
117
100
  const fileContent = await readFile(absFilePath, 'utf-8');
118
- const remove = new Set();
119
- const isRemove = (_, i) => !remove.has(i);
120
- for (const [key, issue] of Object.entries(issues.catalog[filePath])) {
121
- if (issue.line) {
122
- remove.add(issue.line - 1);
123
- issues.catalog[filePath][key].isFixed = true;
124
- }
125
- }
126
- await writeFile(absFilePath, fileContent.split('\n').filter(isRemove).join('\n'));
101
+ const issuesForFile = Object.values(issues.catalog[filePath]);
102
+ const takeLine = (issue) => issue.fixes.map(fix => fix[0]);
103
+ const remove = new Set(issuesForFile.flatMap(takeLine));
104
+ const keep = (_, i) => !remove.has(i + 1);
105
+ await writeFile(absFilePath, fileContent.split('\n').filter(keep).join('\n'));
106
+ for (const issue of issuesForFile)
107
+ issue.isFixed = true;
127
108
  touchedFiles.add(filePath);
128
109
  }
129
110
  else {
@@ -146,7 +127,7 @@ export class IssueFixer {
146
127
  }
147
128
  }
148
129
  await save(absFilePath, pkg);
149
- touchedFiles.add(filePath);
130
+ touchedFiles.add(absFilePath);
150
131
  }
151
132
  }
152
133
  return touchedFiles;
@@ -21,6 +21,7 @@ const commands = [
21
21
  'patch-commit',
22
22
  'patch',
23
23
  'plugin',
24
+ 'publish',
24
25
  'rebuild',
25
26
  'remove',
26
27
  'search',
@@ -9,13 +9,13 @@ const isGlobLikeMatch = /(^!|[*+\\(|{^$])/;
9
9
  const isGlobLike = (value) => isGlobLikeMatch.test(value);
10
10
  const nodeLoadersArgs = { import: ['r', 'experimental-loader', 'require', 'loader'] };
11
11
  export const resolve = (binary, _args, options) => {
12
- const { fromArgs, containingFilePath } = options;
12
+ const { cwd, fromArgs, containingFilePath } = options;
13
13
  const [pluginName, pluginArgs] = pluginArgsMap.get(binary) ?? [];
14
14
  if (!pluginArgs)
15
15
  return fallbackResolve(binary, _args, options);
16
16
  const inputOpts = {};
17
- if (options.cwd && dirname(containingFilePath) !== options.cwd)
18
- Object.assign(inputOpts, { dir: options.cwd });
17
+ if (cwd && dirname(containingFilePath) !== cwd)
18
+ Object.assign(inputOpts, { dir: cwd });
19
19
  const args = typeof pluginArgs.args === 'function' ? pluginArgs.args(_args) : _args;
20
20
  const parsed = parseArgs(args, {
21
21
  string: [
@@ -58,7 +58,7 @@ export const resolve = (binary, _args, options) => {
58
58
  return parsed[id] && pluginName ? [toConfig(pluginName, fn(parsed[id]), inputOpts)] : [];
59
59
  };
60
60
  const configFilePaths = config.flatMap(mapToConfigPattern);
61
- const inputs = pluginArgs.resolveInputs?.(parsed, args) ?? [];
61
+ const inputs = pluginArgs.resolveInputs?.(parsed, { args, cwd }) ?? [];
62
62
  return [
63
63
  toBinary(binary, inputOpts),
64
64
  ...positionals,
@@ -489,6 +489,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
489
489
  entry?: string | string[] | undefined;
490
490
  project?: string | string[] | undefined;
491
491
  } | undefined;
492
+ taskfile?: string | boolean | string[] | {
493
+ config?: string | string[] | undefined;
494
+ entry?: string | string[] | undefined;
495
+ project?: string | string[] | undefined;
496
+ } | undefined;
492
497
  travis?: string | boolean | string[] | {
493
498
  config?: string | string[] | undefined;
494
499
  entry?: string | string[] | undefined;
@@ -1080,6 +1085,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1080
1085
  entry?: string | string[] | undefined;
1081
1086
  project?: string | string[] | undefined;
1082
1087
  } | undefined;
1088
+ taskfile?: string | boolean | string[] | {
1089
+ config?: string | string[] | undefined;
1090
+ entry?: string | string[] | undefined;
1091
+ project?: string | string[] | undefined;
1092
+ } | undefined;
1083
1093
  travis?: string | boolean | string[] | {
1084
1094
  config?: string | string[] | undefined;
1085
1095
  entry?: string | string[] | undefined;
@@ -1,6 +1,7 @@
1
1
  import Astro from './astro.js';
2
2
  import AstroMDX from './astro-mdx.js';
3
3
  import MDX from './mdx.js';
4
+ import Prisma from './prisma.js';
4
5
  import Svelte from './svelte.js';
5
6
  import CSS from './tailwind.js';
6
7
  import Vue from './vue.js';
@@ -31,6 +32,7 @@ const compilers = new Map([
31
32
  ['.astro', Astro],
32
33
  ['.css', CSS],
33
34
  ['.mdx', MDX],
35
+ ['.prisma', Prisma],
34
36
  ['.svelte', Svelte],
35
37
  ['.vue', Vue],
36
38
  ]);
@@ -0,0 +1,6 @@
1
+ import type { HasDependency } from './types.js';
2
+ declare const _default: {
3
+ condition: (hasDependency: HasDependency) => boolean;
4
+ compiler: (text: string) => string;
5
+ };
6
+ export default _default;
@@ -0,0 +1,13 @@
1
+ const condition = (hasDependency) => hasDependency('prisma');
2
+ const directiveMatcher = /generator\s+(?!client)\w+\s*\{\s*provider\s*=\s*"([^"]+)"[^}]*\}/g;
3
+ const compiler = (text) => {
4
+ const imports = [];
5
+ let match;
6
+ while ((match = directiveMatcher.exec(text))) {
7
+ if (match[1]) {
8
+ imports.push(`import '${match[1]}';`);
9
+ }
10
+ }
11
+ return imports.join('\n');
12
+ };
13
+ export default { condition, compiler };
@@ -50,10 +50,14 @@ export declare const FIX_FLAGS: {
50
50
  readonly EMPTY_DECLARATION: number;
51
51
  readonly WITH_NEWLINE: number;
52
52
  };
53
+ export declare const SIDE_EFFECTS = "__side-effects";
54
+ export declare const OPAQUE = "__opaque";
53
55
  export declare const IMPORT_MODIFIERS: {
54
56
  readonly NONE: 0;
55
57
  readonly RE_EXPORT: number;
56
58
  readonly TYPE_ONLY: number;
57
59
  readonly ENTRY: number;
58
60
  readonly OPTIONAL: number;
61
+ readonly SIDE_EFFECTS: number;
62
+ readonly OPAQUE: number;
59
63
  };
package/dist/constants.js CHANGED
@@ -208,10 +208,14 @@ export const FIX_FLAGS = {
208
208
  EMPTY_DECLARATION: 1 << 1,
209
209
  WITH_NEWLINE: 1 << 2,
210
210
  };
211
+ export const SIDE_EFFECTS = '__side-effects';
212
+ export const OPAQUE = '__opaque';
211
213
  export const IMPORT_MODIFIERS = {
212
214
  NONE: 0,
213
215
  RE_EXPORT: 1 << 0,
214
216
  TYPE_ONLY: 1 << 1,
215
217
  ENTRY: 1 << 2,
216
218
  OPTIONAL: 1 << 3,
219
+ SIDE_EFFECTS: 1 << 4,
220
+ OPAQUE: 1 << 5,
217
221
  };
@@ -21,5 +21,5 @@ interface AnalyzeOptions {
21
21
  unreferencedFiles: Set<string>;
22
22
  options: MainOptions;
23
23
  }
24
- export declare const analyze: ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }: AnalyzeOptions) => Promise<() => Promise<void>>;
24
+ export declare const analyze: ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, factory, graph, streamer, unreferencedFiles, options, }: AnalyzeOptions) => Promise<() => Promise<void>>;
25
25
  export {};
@@ -4,7 +4,7 @@ import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
4
4
  import { findMatch } from '../util/regex.js';
5
5
  import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from '../util/tag.js';
6
6
  import { createAndPrintTrace, printTrace } from '../util/trace.js';
7
- export const analyze = async ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }) => {
7
+ export const analyze = async ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, factory, graph, streamer, unreferencedFiles, options, }) => {
8
8
  const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
9
9
  const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
10
10
  const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths, options.isTrace);
@@ -75,7 +75,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
75
75
  if (!isReferenced) {
76
76
  if (isIgnored)
77
77
  continue;
78
- const isIssueAdded = collector.addIssue({
78
+ collector.addIssue({
79
79
  type: 'enumMembers',
80
80
  filePath,
81
81
  workspace: workspace.name,
@@ -84,9 +84,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
84
84
  pos: member.pos,
85
85
  line: member.line,
86
86
  col: member.col,
87
+ fixes: member.fix ? [member.fix] : [],
87
88
  });
88
- if (options.isFix && isIssueAdded && member.fix)
89
- fixer.addUnusedTypeNode(filePath, [member.fix]);
90
89
  }
91
90
  else if (isIgnored) {
92
91
  for (const tagName of exportedItem.jsDocTags) {
@@ -110,7 +109,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
110
109
  }
111
110
  continue;
112
111
  }
113
- const isIssueAdded = collector.addIssue({
112
+ collector.addIssue({
114
113
  type: 'classMembers',
115
114
  filePath,
116
115
  workspace: workspace.name,
@@ -119,9 +118,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
119
118
  pos: member.pos,
120
119
  line: member.line,
121
120
  col: member.col,
121
+ fixes: member.fix ? [member.fix] : [],
122
122
  });
123
- if (options.isFix && isIssueAdded && member.fix)
124
- fixer.addUnusedTypeNode(filePath, [member.fix]);
125
123
  }
126
124
  }
127
125
  continue;
@@ -138,7 +136,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
138
136
  if (!options.isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
139
137
  continue;
140
138
  const type = getType(hasStrictlyNsRefs, isType);
141
- const isIssueAdded = collector.addIssue({
139
+ collector.addIssue({
142
140
  type,
143
141
  filePath,
144
142
  workspace: workspace.name,
@@ -148,13 +146,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
148
146
  pos: exportedItem.pos,
149
147
  line: exportedItem.line,
150
148
  col: exportedItem.col,
149
+ fixes: exportedItem.fixes,
151
150
  });
152
- if (options.isFix && isIssueAdded) {
153
- if (isType)
154
- fixer.addUnusedTypeNode(filePath, exportedItem.fixes);
155
- else
156
- fixer.addUnusedExportNode(filePath, exportedItem.fixes);
157
- }
158
151
  }
159
152
  }
160
153
  }
@@ -167,7 +160,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
167
160
  for (const symbols of file.duplicates) {
168
161
  if (symbols.length > 1) {
169
162
  const symbol = symbols.map(s => s.symbol).join('|');
170
- collector.addIssue({ type: 'duplicates', filePath, workspace: ws.name, symbol, symbols });
163
+ collector.addIssue({ type: 'duplicates', filePath, workspace: ws.name, symbol, symbols, fixes: [] });
171
164
  }
172
165
  }
173
166
  }
@@ -185,13 +178,23 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
185
178
  pos: extImport.pos,
186
179
  line: extImport.line,
187
180
  col: extImport.col,
181
+ fixes: [],
188
182
  });
189
183
  }
190
184
  }
191
185
  if (file.imports?.unresolved) {
192
186
  for (const unresolvedImport of file.imports.unresolved) {
193
187
  const { specifier, pos, line, col } = unresolvedImport;
194
- collector.addIssue({ type: 'unresolved', filePath, workspace: ws.name, symbol: specifier, pos, line, col });
188
+ collector.addIssue({
189
+ type: 'unresolved',
190
+ filePath,
191
+ workspace: ws.name,
192
+ symbol: specifier,
193
+ pos,
194
+ line,
195
+ col,
196
+ fixes: [],
197
+ });
195
198
  }
196
199
  }
197
200
  }
@@ -213,7 +216,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
213
216
  for (const hint of configurationHints)
214
217
  collector.addConfigurationHint(hint);
215
218
  }
216
- const catalogIssues = await counselor.settleCatalogIssues();
219
+ const catalogIssues = await counselor.settleCatalogIssues(options);
217
220
  for (const issue of catalogIssues)
218
221
  collector.addIssue(issue);
219
222
  const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
@@ -294,10 +294,10 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
294
294
  if (!isIgnored)
295
295
  principal.addEntryPath(filePath, { skipExportsAnalysis: true });
296
296
  }
297
- for (const [import_, specifierFilePath] of file.imports.specifiers) {
298
- const packageName = getPackageNameFromModuleSpecifier(import_.specifier);
297
+ for (const [_import, specifierFilePath] of file.imports.imports) {
298
+ const packageName = getPackageNameFromModuleSpecifier(_import.specifier);
299
299
  if (packageName && isInternalWorkspace(packageName)) {
300
- file.imports.external.add({ ...import_, specifier: packageName });
300
+ file.imports.external.add({ ..._import, specifier: packageName });
301
301
  const principal = getPrincipalByFilePath(specifierFilePath);
302
302
  if (principal && !isGitIgnored(specifierFilePath)) {
303
303
  principal.addNonEntryPath(specifierFilePath);
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ import { debugLogArray, debugLogObject } from './util/debug.js';
14
14
  import { getGitIgnoredHandler } from './util/glob-core.js';
15
15
  import { getWatchHandler } from './util/watch.js';
16
16
  export const main = async (options) => {
17
- const { cwd } = options;
18
17
  debugLogObject('*', 'Unresolved configuration', options);
19
18
  debugLogObject('*', 'Included issue types', options.includedIssueTypes);
20
19
  const chief = new ConfigurationChief(options);
@@ -78,7 +77,7 @@ export const main = async (options) => {
78
77
  if (options.isFix) {
79
78
  const touchedFiles = await fixer.fixIssues(issues);
80
79
  if (options.isFormat) {
81
- const report = await formatly(Array.from(touchedFiles), { cwd });
80
+ const report = await formatly(Array.from(touchedFiles));
82
81
  if (report.ran && report.result && (report.result.runner === 'virtual' || report.result.code === 0)) {
83
82
  debugLogArray('*', `Formatted files using ${report.formatter.name} (${report.formatter.runner})`, touchedFiles);
84
83
  }
@@ -96,6 +96,7 @@ export declare const Plugins: {
96
96
  svgo: import("../types/config.js").Plugin;
97
97
  syncpack: import("../types/config.js").Plugin;
98
98
  tailwind: import("../types/config.js").Plugin;
99
+ taskfile: import("../types/config.js").Plugin;
99
100
  travis: import("../types/config.js").Plugin;
100
101
  'ts-node': import("../types/config.js").Plugin;
101
102
  tsdown: import("../types/config.js").Plugin;
@@ -95,6 +95,7 @@ import { default as svelte } from './svelte/index.js';
95
95
  import { default as svgo } from './svgo/index.js';
96
96
  import { default as syncpack } from './syncpack/index.js';
97
97
  import { default as tailwind } from './tailwind/index.js';
98
+ import { default as taskfile } from './taskfile/index.js';
98
99
  import { default as travis } from './travis/index.js';
99
100
  import { default as tsNode } from './ts-node/index.js';
100
101
  import { default as tsdown } from './tsdown/index.js';
@@ -214,6 +215,7 @@ export const Plugins = {
214
215
  svgo,
215
216
  syncpack,
216
217
  tailwind,
218
+ taskfile,
217
219
  travis,
218
220
  'ts-node': tsNode,
219
221
  tsdown,
@@ -8,9 +8,6 @@ const config = ['next.config.{js,ts,cjs,mjs}'];
8
8
  const defaultPageExtensions = ['{js,jsx,ts,tsx}'];
9
9
  const productionEntryFilePatterns = [
10
10
  '{instrumentation,instrumentation-client,middleware,proxy}.{js,ts}',
11
- 'app/global-{error,not-found}.{js,jsx,ts,tsx}',
12
- 'app/**/{error,layout,loading,not-found,page,template,default,forbidden,unauthorized}.{js,jsx,ts,tsx}',
13
- 'app/**/route.{js,jsx,ts,tsx}',
14
11
  'app/{manifest,robots}.{js,ts}',
15
12
  'app/**/sitemap.{js,ts}',
16
13
  'app/**/{icon,apple-icon}.{js,jsx,ts,tsx}',
@@ -18,8 +15,10 @@ const productionEntryFilePatterns = [
18
15
  'mdx-components.{js,jsx,ts,tsx}',
19
16
  ];
20
17
  const getEntryFilePatterns = (pageExtensions = defaultPageExtensions) => {
21
- const pages = pageExtensions.map(ext => `pages/**/*.${ext}`);
22
- const patterns = [...productionEntryFilePatterns, ...pages];
18
+ const patterns = [...productionEntryFilePatterns];
19
+ for (const ext of pageExtensions) {
20
+ patterns.push(`app/global-{error,not-found}.${ext}`, `app/**/{error,layout,loading,not-found,page,template,default,forbidden,unauthorized}.${ext}`, `app/**/route.${ext}`, `pages/**/*.${ext}`);
21
+ }
23
22
  return [...patterns, ...patterns.map(pattern => `src/${pattern}`)];
24
23
  };
25
24
  const production = getEntryFilePatterns();
@@ -1,28 +1,50 @@
1
+ import { isDirectory } from '../../util/fs.js';
2
+ import { toEntry } from '../../util/input.js';
3
+ import { join } from '../../util/path.js';
1
4
  import { hasDependency } from '../../util/plugin.js';
2
5
  const title = 'Prisma';
3
6
  const enablers = ['prisma', /^@prisma\/.*/];
4
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
+ const entry = ['prisma/schema.prisma', 'schema.prisma'];
5
9
  const config = [
6
10
  'prisma.config.{js,ts,mjs,cjs,mts,cts}',
7
11
  '.config/prisma.{js,ts,mjs,cjs,mts,cts}',
8
12
  'package.json',
9
13
  ];
14
+ const resolveSchema = (path, cwd) => {
15
+ if (!isDirectory(join(cwd, path))) {
16
+ return toEntry(path);
17
+ }
18
+ return toEntry(join(path, '**/*.prisma'));
19
+ };
10
20
  const resolveConfig = async (config, options) => {
11
- if (options.configFileName === 'package.json' && config.seed) {
12
- return options.getInputsFromScripts(config.seed);
21
+ const inputs = [];
22
+ if (config.seed) {
23
+ inputs.push(...options.getInputsFromScripts(config.seed));
24
+ }
25
+ else if (config.migrations?.seed) {
26
+ inputs.push(...options.getInputsFromScripts(config.migrations.seed));
13
27
  }
14
- if (config.migrations?.seed) {
15
- return options.getInputsFromScripts(config.migrations.seed);
28
+ if (config.schema) {
29
+ inputs.push(resolveSchema(config.schema, options.cwd));
16
30
  }
17
- return [];
31
+ return inputs;
18
32
  };
19
33
  const args = {
20
34
  config: true,
35
+ resolveInputs: (parsed, { cwd }) => {
36
+ const inputs = [];
37
+ if (parsed['schema']) {
38
+ inputs.push(resolveSchema(parsed['schema'], cwd));
39
+ }
40
+ return inputs;
41
+ },
21
42
  };
22
43
  const plugin = {
23
44
  title,
24
45
  enablers,
25
46
  isEnabled,
47
+ entry,
26
48
  config,
27
49
  args,
28
50
  resolveConfig,
@@ -3,4 +3,5 @@ export type PrismaConfig = {
3
3
  migrations?: {
4
4
  seed?: string;
5
5
  };
6
+ schema?: string;
6
7
  };
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;