knip 6.14.2 → 6.16.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 (111) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +32 -0
  4. package/dist/ConfigurationChief.js +9 -11
  5. package/dist/DependencyDeputy.d.ts +0 -4
  6. package/dist/DependencyDeputy.js +4 -16
  7. package/dist/IssueCollector.d.ts +1 -0
  8. package/dist/IssueCollector.js +10 -20
  9. package/dist/IssueFixer.js +10 -15
  10. package/dist/ProjectPrincipal.d.ts +2 -3
  11. package/dist/ProjectPrincipal.js +13 -21
  12. package/dist/WorkspaceWorker.js +6 -1
  13. package/dist/binaries/fallback.js +1 -1
  14. package/dist/binaries/plugins.js +1 -1
  15. package/dist/binaries/resolvers/bun.js +1 -1
  16. package/dist/binaries/resolvers/bunx.js +1 -1
  17. package/dist/binaries/resolvers/npm.js +1 -1
  18. package/dist/binaries/resolvers/npx.js +1 -1
  19. package/dist/binaries/resolvers/pnpm.js +1 -1
  20. package/dist/binaries/resolvers/pnpx.js +1 -1
  21. package/dist/binaries/resolvers/yarn.js +1 -1
  22. package/dist/binaries/util.d.ts +1 -2
  23. package/dist/binaries/util.js +1 -1
  24. package/dist/cli.js +3 -1
  25. package/dist/compilers/compilers.d.ts +3 -0
  26. package/dist/compilers/compilers.js +9 -13
  27. package/dist/compilers/index.d.ts +52 -0
  28. package/dist/compilers/scss.js +9 -3
  29. package/dist/graph/analyze.js +15 -8
  30. package/dist/graph/build.js +3 -5
  31. package/dist/manifest/index.js +11 -14
  32. package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
  33. package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
  34. package/dist/plugins/bun/index.js +1 -1
  35. package/dist/plugins/catalyst/index.d.ts +3 -0
  36. package/dist/plugins/catalyst/index.js +16 -0
  37. package/dist/plugins/execa/visitors/execa.js +4 -17
  38. package/dist/plugins/fast/index.d.ts +3 -0
  39. package/dist/plugins/fast/index.js +16 -0
  40. package/dist/plugins/index.d.ts +5 -0
  41. package/dist/plugins/index.js +10 -0
  42. package/dist/plugins/lit/index.d.ts +3 -0
  43. package/dist/plugins/lit/index.js +25 -0
  44. package/dist/plugins/nano-spawn/index.d.ts +3 -0
  45. package/dist/plugins/nano-spawn/index.js +15 -0
  46. package/dist/plugins/nano-spawn/visitors/nano-spawn.d.ts +2 -0
  47. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +12 -0
  48. package/dist/plugins/orval/index.d.ts +3 -0
  49. package/dist/plugins/orval/index.js +16 -0
  50. package/dist/plugins/orval/resolveFromAST.d.ts +2 -0
  51. package/dist/plugins/orval/resolveFromAST.js +11 -0
  52. package/dist/plugins/orval/types.d.ts +9 -0
  53. package/dist/plugins/orval/types.js +1 -0
  54. package/dist/plugins/relay/index.js +1 -1
  55. package/dist/plugins/stencil/index.js +17 -1
  56. package/dist/plugins/sveltejs-package/helpers.js +1 -1
  57. package/dist/plugins/vite/helpers.js +23 -6
  58. package/dist/plugins/webdriver-io/index.js +3 -3
  59. package/dist/plugins/webdriver-io/types.d.ts +5 -1
  60. package/dist/reporters/github-actions.d.ts +1 -1
  61. package/dist/reporters/github-actions.js +19 -1
  62. package/dist/reporters/index.d.ts +1 -1
  63. package/dist/reporters/symbols.js +2 -1
  64. package/dist/reporters/trace.d.ts +3 -1
  65. package/dist/reporters/trace.js +48 -16
  66. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  67. package/dist/reporters/util/configuration-hints.js +3 -2
  68. package/dist/schema/configuration.d.ts +83 -1
  69. package/dist/schema/configuration.js +2 -0
  70. package/dist/schema/plugins.d.ts +25 -0
  71. package/dist/schema/plugins.js +5 -0
  72. package/dist/types/PluginNames.d.ts +2 -2
  73. package/dist/types/PluginNames.js +5 -0
  74. package/dist/types/args.d.ts +1 -1
  75. package/dist/types/config.d.ts +2 -0
  76. package/dist/types/issues.d.ts +1 -0
  77. package/dist/types/module-graph.d.ts +1 -0
  78. package/dist/types/project.d.ts +0 -1
  79. package/dist/typescript/ast-helpers.js +21 -20
  80. package/dist/typescript/ast-nodes.d.ts +1 -0
  81. package/dist/typescript/ast-nodes.js +19 -0
  82. package/dist/typescript/get-imports-and-exports.js +18 -2
  83. package/dist/typescript/resolve-module-names.d.ts +6 -2
  84. package/dist/typescript/resolve-module-names.js +20 -29
  85. package/dist/typescript/visitors/calls.d.ts +3 -2
  86. package/dist/typescript/visitors/calls.js +88 -16
  87. package/dist/typescript/visitors/exports.js +12 -0
  88. package/dist/typescript/visitors/walk.d.ts +7 -0
  89. package/dist/typescript/visitors/walk.js +43 -1
  90. package/dist/util/Performance.d.ts +13 -28
  91. package/dist/util/Performance.js +41 -72
  92. package/dist/util/cli-arguments.d.ts +3 -1
  93. package/dist/util/cli-arguments.js +4 -0
  94. package/dist/util/create-options.d.ts +53 -0
  95. package/dist/util/create-options.js +2 -1
  96. package/dist/util/disk-cache.d.ts +1 -0
  97. package/dist/util/disk-cache.js +8 -0
  98. package/dist/util/gitignore-cache.js +5 -11
  99. package/dist/util/glob-cache.js +2 -8
  100. package/dist/util/glob-core.js +4 -7
  101. package/dist/util/jiti.js +1 -0
  102. package/dist/util/load-tsconfig.js +0 -3
  103. package/dist/util/parse-args.d.ts +14 -0
  104. package/dist/util/parse-args.js +112 -0
  105. package/dist/util/trace.js +1 -1
  106. package/dist/version.d.ts +1 -1
  107. package/dist/version.js +1 -1
  108. package/package.json +3 -6
  109. package/schema.json +73 -43
  110. package/dist/util/math.d.ts +0 -6
  111. package/dist/util/math.js +0 -11
@@ -4,6 +4,7 @@ export declare class CacheConsultant<T> {
4
4
  private cache;
5
5
  getFileDescriptor: (filePath: string) => FileDescriptor<T>;
6
6
  reconcile: () => void;
7
+ removeEntry: (filePath: string) => void;
7
8
  constructor(name: string, options: MainOptions);
8
9
  getCachedFile(filePath: string): T | undefined;
9
10
  }
@@ -6,6 +6,7 @@ export class CacheConsultant {
6
6
  cache;
7
7
  getFileDescriptor = () => dummyFileDescriptor;
8
8
  reconcile = () => { };
9
+ removeEntry = () => { };
9
10
  constructor(name, options) {
10
11
  if (!options.isCache)
11
12
  return;
@@ -13,6 +14,7 @@ export class CacheConsultant {
13
14
  this.cache = new FileEntryCache(cacheName, options.cacheLocation);
14
15
  this.getFileDescriptor = timerify(this.cache.getFileDescriptor.bind(this.cache));
15
16
  this.reconcile = timerify(this.cache.reconcile.bind(this.cache));
17
+ this.removeEntry = timerify(this.cache.removeEntry.bind(this.cache));
16
18
  }
17
19
  getCachedFile(filePath) {
18
20
  if (!this.cache)
@@ -112,6 +112,11 @@ export declare class ConfigurationChief {
112
112
  entry?: string | string[] | undefined;
113
113
  project?: string | string[] | undefined;
114
114
  } | undefined;
115
+ catalyst?: string | boolean | string[] | {
116
+ config?: string | string[] | undefined;
117
+ entry?: string | string[] | undefined;
118
+ project?: string | string[] | undefined;
119
+ } | undefined;
115
120
  changelogen?: string | boolean | string[] | {
116
121
  config?: string | string[] | undefined;
117
122
  entry?: string | string[] | undefined;
@@ -212,6 +217,11 @@ export declare class ConfigurationChief {
212
217
  entry?: string | string[] | undefined;
213
218
  project?: string | string[] | undefined;
214
219
  } | undefined;
220
+ fast?: string | boolean | string[] | {
221
+ config?: string | string[] | undefined;
222
+ entry?: string | string[] | undefined;
223
+ project?: string | string[] | undefined;
224
+ } | undefined;
215
225
  gatsby?: string | boolean | string[] | {
216
226
  config?: string | string[] | undefined;
217
227
  entry?: string | string[] | undefined;
@@ -287,6 +297,11 @@ export declare class ConfigurationChief {
287
297
  entry?: string | string[] | undefined;
288
298
  project?: string | string[] | undefined;
289
299
  } | undefined;
300
+ lit?: string | boolean | string[] | {
301
+ config?: string | string[] | undefined;
302
+ entry?: string | string[] | undefined;
303
+ project?: string | string[] | undefined;
304
+ } | undefined;
290
305
  'lockfile-lint'?: string | boolean | string[] | {
291
306
  config?: string | string[] | undefined;
292
307
  entry?: string | string[] | undefined;
@@ -332,6 +347,11 @@ export declare class ConfigurationChief {
332
347
  entry?: string | string[] | undefined;
333
348
  project?: string | string[] | undefined;
334
349
  } | undefined;
350
+ 'nano-spawn'?: string | boolean | string[] | {
351
+ config?: string | string[] | undefined;
352
+ entry?: string | string[] | undefined;
353
+ project?: string | string[] | undefined;
354
+ } | undefined;
335
355
  'nano-staged'?: string | boolean | string[] | {
336
356
  config?: string | string[] | undefined;
337
357
  entry?: string | string[] | undefined;
@@ -412,6 +432,11 @@ export declare class ConfigurationChief {
412
432
  entry?: string | string[] | undefined;
413
433
  project?: string | string[] | undefined;
414
434
  } | undefined;
435
+ orval?: string | boolean | string[] | {
436
+ config?: string | string[] | undefined;
437
+ entry?: string | string[] | undefined;
438
+ project?: string | string[] | undefined;
439
+ } | undefined;
415
440
  oxfmt?: string | boolean | string[] | {
416
441
  config?: string | string[] | undefined;
417
442
  entry?: string | string[] | undefined;
@@ -816,6 +841,7 @@ export declare class ConfigurationChief {
816
841
  ignoreDependencies?: (string | RegExp)[] | undefined;
817
842
  ignoreMembers?: (string | RegExp)[] | undefined;
818
843
  ignoreUnresolved?: (string | RegExp)[] | undefined;
844
+ ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
819
845
  includeEntryExports?: boolean | undefined;
820
846
  };
821
847
  getIgnores(workspaceName: string): {
@@ -829,6 +855,7 @@ export declare class ConfigurationChief {
829
855
  paths: Record<string, string[]>;
830
856
  ignore: string[];
831
857
  ignoreFiles: string[];
858
+ ignoreExportsUsedInFile: Record<string, boolean | undefined> | import("./types/config.ts").IgnoreExportsUsedInFile;
832
859
  isIncludeEntryExports: boolean;
833
860
  angular?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
834
861
  astro?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -841,6 +868,7 @@ export declare class ConfigurationChief {
841
868
  bun?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
842
869
  c8?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
843
870
  capacitor?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
871
+ catalyst?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
844
872
  changelogen?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
845
873
  changelogithub?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
846
874
  changesets?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -861,6 +889,7 @@ export declare class ConfigurationChief {
861
889
  execa?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
862
890
  expo?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
863
891
  "expressive-code"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
892
+ fast?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
864
893
  gatsby?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
865
894
  "github-action"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
866
895
  "github-actions"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -876,6 +905,7 @@ export declare class ConfigurationChief {
876
905
  lefthook?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
877
906
  "lint-staged"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
878
907
  linthtml?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
908
+ lit?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
879
909
  "lockfile-lint"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
880
910
  "lost-pixel"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
881
911
  markdownlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -885,6 +915,7 @@ export declare class ConfigurationChief {
885
915
  mocha?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
886
916
  moonrepo?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
887
917
  msw?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
918
+ "nano-spawn"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
888
919
  "nano-staged"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
889
920
  nest?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
890
921
  netlify?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -901,6 +932,7 @@ export declare class ConfigurationChief {
901
932
  nyc?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
902
933
  oclif?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
903
934
  "openapi-ts"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
935
+ orval?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
904
936
  oxfmt?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
905
937
  oxlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
906
938
  "panda-css"?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -8,7 +8,6 @@ import { _dirGlob, removeProductionSuffix } from './util/glob.js';
8
8
  import { graphSequencer } from './util/graph-sequencer.js';
9
9
  import mapWorkspaces from './util/map-workspaces.js';
10
10
  import { join, relative } from './util/path.js';
11
- import { timerify } from './util/Performance.js';
12
11
  import { normalizePluginConfig } from './util/plugin.js';
13
12
  import { toRegexOrString } from './util/regex.js';
14
13
  import { ELLIPSIS } from './util/string.js';
@@ -76,7 +75,7 @@ export class ConfigurationChief {
76
75
  this.workspaces = options.workspaces;
77
76
  this.rawConfig = options.parsedConfig;
78
77
  this.config = this.normalize(options.parsedConfig ?? {});
79
- this.findWorkspaceByFilePath = timerify(this.findWorkspaceByFilePath.bind(this), 'findWorkspaceByFilePath');
78
+ this.findWorkspaceByFilePath = this.findWorkspaceByFilePath.bind(this);
80
79
  }
81
80
  getConfigurationHints() {
82
81
  const hints = [];
@@ -269,9 +268,7 @@ export class ConfigurationChief {
269
268
  return this.availableWorkspaceNames.filter(workspaceName => workspaceName !== name && (name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(prefix)));
270
269
  }
271
270
  getIgnoredWorkspacesFor(name) {
272
- return this.ignoredWorkspacePatterns
273
- .filter(workspaceName => workspaceName !== name)
274
- .filter(workspaceName => name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name));
271
+ return this.ignoredWorkspacePatterns.filter(workspaceName => workspaceName !== name && (name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name)));
275
272
  }
276
273
  createIgnoredWorkspaceMatcher(name, dir) {
277
274
  const ignoredWorkspaces = this.getIgnoredWorkspacesFor(name);
@@ -305,12 +302,12 @@ export class ConfigurationChief {
305
302
  }
306
303
  getWorkspaceConfig(workspaceName) {
307
304
  const key = this.getConfigKeyForWorkspace(workspaceName);
305
+ if (!key)
306
+ return {};
308
307
  const workspaces = this.rawConfig?.workspaces ?? {};
309
- return ((key
310
- ? key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces)
311
- ? this.rawConfig
312
- : workspaces[key]
313
- : {}) ?? {});
308
+ if (key === ROOT_WORKSPACE_NAME && !(ROOT_WORKSPACE_NAME in workspaces))
309
+ return this.rawConfig ?? {};
310
+ return workspaces[key] ?? {};
314
311
  }
315
312
  getIgnores(workspaceName) {
316
313
  const workspaceConfig = this.getWorkspaceConfig(workspaceName);
@@ -335,6 +332,7 @@ export class ConfigurationChief {
335
332
  const paths = workspaceConfig.paths ?? {};
336
333
  const ignore = arrayify(workspaceConfig.ignore);
337
334
  const ignoreFiles = arrayify(workspaceConfig.ignoreFiles);
335
+ const ignoreExportsUsedInFile = workspaceConfig.ignoreExportsUsedInFile ?? this.config.ignoreExportsUsedInFile;
338
336
  const isIncludeEntryExports = workspaceConfig.includeEntryExports ?? this.config.isIncludeEntryExports;
339
337
  const plugins = {};
340
338
  for (const [pluginName, pluginConfig] of Object.entries(this.config.rootPluginConfigs)) {
@@ -346,7 +344,7 @@ export class ConfigurationChief {
346
344
  plugins[pluginName] = normalizePluginConfig(pluginConfig);
347
345
  }
348
346
  }
349
- return { entry, project, paths, ignore, ignoreFiles, isIncludeEntryExports, ...plugins };
347
+ return { entry, project, paths, ignore, ignoreFiles, ignoreExportsUsedInFile, isIncludeEntryExports, ...plugins };
350
348
  }
351
349
  findWorkspaceByFilePath(filePath) {
352
350
  if (this.workspaceByFileCache.has(filePath))
@@ -49,10 +49,6 @@ export declare class DependencyDeputy {
49
49
  getDevDependencies(workspaceName: string): DependencyArray;
50
50
  private dependencyCache;
51
51
  getDependencies(workspaceName: string): DependencySet;
52
- setInstalledBinaries(workspaceName: string, installedBinaries: Map<string, Set<string>>): void;
53
- getInstalledBinaries(workspaceName: string): InstalledBinaries | undefined;
54
- setHasTypesIncluded(workspaceName: string, hasTypesIncluded: Set<string>): void;
55
- getHasTypesIncluded(workspaceName: string): Set<string> | undefined;
56
52
  addReferencedDependency(workspaceName: string, packageName: string): void;
57
53
  addReferencedBinary(workspaceName: string, binaryName: string): void;
58
54
  setHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
@@ -48,8 +48,8 @@ export class DependencyDeputy {
48
48
  cwd,
49
49
  });
50
50
  this.setHostDependencies(name, hostDependencies);
51
- this.setInstalledBinaries(name, installedBinaries);
52
- this.setHasTypesIncluded(name, hasTypesIncluded);
51
+ this.installedBinaries.set(name, installedBinaries);
52
+ this.hasTypesIncluded.set(name, hasTypesIncluded);
53
53
  }
54
54
  const ignoreDependencies = id.flatMap(id => filterIsProduction(id, this.isProduction)).map(toRegexOrString);
55
55
  const ignoreBinaries = ib.flatMap(ib => filterIsProduction(ib, this.isProduction)).map(toRegexOrString);
@@ -100,18 +100,6 @@ export class DependencyDeputy {
100
100
  this.dependencyCache.set(workspaceName, deps);
101
101
  return deps;
102
102
  }
103
- setInstalledBinaries(workspaceName, installedBinaries) {
104
- this.installedBinaries.set(workspaceName, installedBinaries);
105
- }
106
- getInstalledBinaries(workspaceName) {
107
- return this.installedBinaries.get(workspaceName);
108
- }
109
- setHasTypesIncluded(workspaceName, hasTypesIncluded) {
110
- this.hasTypesIncluded.set(workspaceName, hasTypesIncluded);
111
- }
112
- getHasTypesIncluded(workspaceName) {
113
- return this.hasTypesIncluded.get(workspaceName);
114
- }
115
103
  addReferencedDependency(workspaceName, packageName) {
116
104
  if (!this.referencedDependencies.has(workspaceName)) {
117
105
  this.referencedDependencies.set(workspaceName, new Set());
@@ -182,7 +170,7 @@ export class DependencyDeputy {
182
170
  this.addReferencedBinary(workspace.name, binaryName);
183
171
  const workspaceNames = this.isStrict ? [workspace.name] : [workspace.name, ...[...workspace.ancestors].reverse()];
184
172
  for (const name of workspaceNames) {
185
- const binaries = this.getInstalledBinaries(name);
173
+ const binaries = this.installedBinaries.get(name);
186
174
  if (binaries?.has(binaryName)) {
187
175
  const dependencies = binaries.get(binaryName);
188
176
  if (dependencies?.size) {
@@ -210,7 +198,7 @@ export class DependencyDeputy {
210
198
  const optionalPeerDependencyIssues = [];
211
199
  for (const [workspace, { manifestPath: filePath, manifestStr }] of this._manifests) {
212
200
  const referencedDependencies = this.referencedDependencies.get(workspace);
213
- const hasTypesIncluded = this.getHasTypesIncluded(workspace);
201
+ const hasTypesIncluded = this.hasTypesIncluded.get(workspace);
214
202
  const peeker = new PackagePeeker(manifestStr);
215
203
  const isReferencedDependency = (dependency, visited = new Set()) => {
216
204
  if (referencedDependencies?.has(dependency))
@@ -22,6 +22,7 @@ export declare class IssueCollector {
22
22
  private unusedIgnoreFilesPatterns;
23
23
  constructor(options: MainOptions);
24
24
  setWorkspaceFilter(workspaceFilePathFilter: WorkspaceFilePathFilter | undefined): void;
25
+ private collectIgnorePatterns;
25
26
  addIgnorePatterns(entries: {
26
27
  pattern: string;
27
28
  id: string;
@@ -40,37 +40,27 @@ export class IssueCollector {
40
40
  if (workspaceFilePathFilter)
41
41
  this.workspaceFilter = workspaceFilePathFilter;
42
42
  }
43
- addIgnorePatterns(entries) {
43
+ collectIgnorePatterns(entries, patterns, unused, type) {
44
44
  for (const entry of entries) {
45
- this.ignorePatterns.add(entry.pattern);
45
+ patterns.add(entry.pattern);
46
46
  if (!this.isTrackUnusedIgnorePatterns)
47
47
  continue;
48
48
  if (entry.pattern.startsWith('!'))
49
49
  continue;
50
- if (this.unusedIgnorePatterns.has(entry.pattern))
50
+ if (unused.has(entry.pattern))
51
51
  continue;
52
- this.unusedIgnorePatterns.set(entry.pattern, {
53
- hint: { type: 'ignore', identifier: entry.id, workspaceName: entry.workspaceName },
52
+ unused.set(entry.pattern, {
53
+ hint: { type, identifier: entry.id, workspaceName: entry.workspaceName },
54
54
  isMatch: picomatch(entry.pattern, { dot: true }),
55
55
  });
56
56
  }
57
- this.isMatch = createMatcher(this.ignorePatterns);
57
+ return createMatcher(patterns);
58
+ }
59
+ addIgnorePatterns(entries) {
60
+ this.isMatch = this.collectIgnorePatterns(entries, this.ignorePatterns, this.unusedIgnorePatterns, 'ignore');
58
61
  }
59
62
  addIgnoreFilesPatterns(entries) {
60
- for (const entry of entries) {
61
- this.ignoreFilesPatterns.add(entry.pattern);
62
- if (!this.isTrackUnusedIgnorePatterns)
63
- continue;
64
- if (entry.pattern.startsWith('!'))
65
- continue;
66
- if (this.unusedIgnoreFilesPatterns.has(entry.pattern))
67
- continue;
68
- this.unusedIgnoreFilesPatterns.set(entry.pattern, {
69
- hint: { type: 'ignoreFiles', identifier: entry.id, workspaceName: entry.workspaceName },
70
- isMatch: picomatch(entry.pattern, { dot: true }),
71
- });
72
- }
73
- this.isFileMatch = createMatcher(this.ignoreFilesPatterns);
63
+ this.isFileMatch = this.collectIgnorePatterns(entries, this.ignoreFilesPatterns, this.unusedIgnoreFilesPatterns, 'ignoreFiles');
74
64
  }
75
65
  markUsedPatterns(filePath, unused) {
76
66
  if (unused.size === 0)
@@ -100,22 +100,17 @@ class IssueFixer {
100
100
  for (const filePath of filePaths) {
101
101
  const absFilePath = join(this.options.cwd, filePath);
102
102
  const pkg = await load(absFilePath);
103
- if (filePath in issues.dependencies) {
104
- for (const dependency of Object.keys(issues.dependencies[filePath])) {
105
- if (pkg.dependencies) {
106
- delete pkg.dependencies[dependency];
107
- issues.dependencies[filePath][dependency].isFixed = true;
108
- }
103
+ const removeDependencies = (key) => {
104
+ const deps = pkg[key];
105
+ if (!deps || !(filePath in issues[key]))
106
+ return;
107
+ for (const dependency of Object.keys(issues[key][filePath])) {
108
+ delete deps[dependency];
109
+ issues[key][filePath][dependency].isFixed = true;
109
110
  }
110
- }
111
- if (filePath in issues.devDependencies) {
112
- for (const dependency of Object.keys(issues.devDependencies[filePath])) {
113
- if (pkg.devDependencies) {
114
- delete pkg.devDependencies[dependency];
115
- issues.devDependencies[filePath][dependency].isFixed = true;
116
- }
117
- }
118
- }
111
+ };
112
+ removeDependencies('dependencies');
113
+ removeDependencies('devDependencies');
119
114
  await save(absFilePath, pkg);
120
115
  touchedFiles.add(absFilePath);
121
116
  }
@@ -15,10 +15,10 @@ export declare class ProjectPrincipal {
15
15
  pluginCtx: PluginVisitorContext;
16
16
  pluginVisitorObjects: PluginVisitorObject[];
17
17
  private _visitor;
18
+ private _localRefsVisitor;
18
19
  syncCompilers: SyncCompilers;
19
20
  asyncCompilers: AsyncCompilers;
20
21
  private paths;
21
- private rootDirs;
22
22
  private extensions;
23
23
  cache: CacheConsultant<FileNode>;
24
24
  toSourceFilePath: ToSourceFilePath;
@@ -30,8 +30,7 @@ export declare class ProjectPrincipal {
30
30
  private onPathAdded;
31
31
  constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler);
32
32
  addCompilers(compilers: [SyncCompilers, AsyncCompilers]): void;
33
- addPaths(paths: Paths, basePath: string): void;
34
- addRootDirs(rootDirs: string[]): void;
33
+ addPaths(paths: Paths, basePath: string, scope: string): void;
35
34
  init(): void;
36
35
  readFile(filePath: string): string;
37
36
  private hasAcceptedExtension;
@@ -21,13 +21,14 @@ export class ProjectPrincipal {
21
21
  sourceText: '',
22
22
  addScript: () => { },
23
23
  addImport: () => { },
24
+ markExportRegistered: () => { },
24
25
  };
25
26
  pluginVisitorObjects = [];
26
27
  _visitor;
28
+ _localRefsVisitor;
27
29
  syncCompilers = new Map();
28
30
  asyncCompilers = new Map();
29
- paths = {};
30
- rootDirs = [];
31
+ paths = new Map();
31
32
  extensions = new Set(DEFAULT_EXTENSIONS);
32
33
  cache;
33
34
  toSourceFilePath;
@@ -61,24 +62,15 @@ export class ProjectPrincipal {
61
62
  }
62
63
  }
63
64
  }
64
- addPaths(paths, basePath) {
65
+ addPaths(paths, basePath, scope) {
65
66
  if (!paths)
66
67
  return;
68
+ const scoped = this.paths.get(scope) ?? {};
67
69
  for (const key in paths) {
68
70
  const prefixes = paths[key].map(prefix => toAbsolute(prefix, basePath));
69
- if (key in this.paths) {
70
- this.paths[key] = compact([...this.paths[key], ...prefixes]);
71
- }
72
- else {
73
- this.paths[key] = prefixes;
74
- }
75
- }
76
- }
77
- addRootDirs(rootDirs) {
78
- for (const dir of rootDirs) {
79
- if (!this.rootDirs.includes(dir))
80
- this.rootDirs.push(dir);
71
+ scoped[key] = key in scoped ? compact([...scoped[key], ...prefixes]) : prefixes;
81
72
  }
73
+ this.paths.set(scope, scoped);
82
74
  }
83
75
  init() {
84
76
  this.extensions = new Set([
@@ -86,9 +78,8 @@ export class ProjectPrincipal {
86
78
  ...getCompilerExtensions([this.syncCompilers, this.asyncCompilers]),
87
79
  ]);
88
80
  const customCompilerExtensions = getCompilerExtensions([this.syncCompilers, this.asyncCompilers]);
89
- const pathsOrUndefined = Object.keys(this.paths).length > 0 ? this.paths : undefined;
90
- const rootDirsOrUndefined = this.rootDirs.length > 1 ? this.rootDirs : undefined;
91
- this.resolveModule = createCustomModuleResolver({ paths: pathsOrUndefined, rootDirs: rootDirsOrUndefined }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports);
81
+ const scopedPaths = this.paths.size > 0 ? Array.from(this.paths, ([scope, paths]) => ({ scope, paths })) : undefined;
82
+ this.resolveModule = createCustomModuleResolver({ scopedPaths }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspaceManifestImports);
92
83
  }
93
84
  readFile(filePath) {
94
85
  return this.fileManager.readFile(filePath);
@@ -223,9 +214,10 @@ export class ProjectPrincipal {
223
214
  options = { ...options, isFixExports: false, isFixTypes: false };
224
215
  }
225
216
  }
226
- if (!this._visitor)
227
- this._visitor = buildVisitor(this.pluginVisitorObjects, !!ignoreExportsUsedInFile);
228
- return _getImportsAndExports(filePath, sourceText, this.resolveModule, options, ignoreExportsUsedInFile, skipExports, this._visitor, this.pluginVisitorObjects.length > 0 ? this.pluginCtx : undefined, parseResult);
217
+ const visitor = ignoreExportsUsedInFile
218
+ ? (this._localRefsVisitor ??= buildVisitor(this.pluginVisitorObjects, true))
219
+ : (this._visitor ??= buildVisitor(this.pluginVisitorObjects, false));
220
+ return _getImportsAndExports(filePath, sourceText, this.resolveModule, options, ignoreExportsUsedInFile, skipExports, visitor, this.pluginVisitorObjects.length > 0 ? this.pluginCtx : undefined, parseResult);
229
221
  }
230
222
  invalidateFile(filePath) {
231
223
  this.fileManager.invalidate(filePath);
@@ -322,6 +322,7 @@ export class WorkspaceWorker {
322
322
  configFileName: basename(configFilePath),
323
323
  };
324
324
  const cache = {};
325
+ let hasLoadConfigError = false;
325
326
  const key = `${wsName}:${pluginName}`;
326
327
  if (plugin.resolveConfig && !seen.get(key)?.has(configFilePath)) {
327
328
  if (parsed && isExternalReExportsOnly(parsed)) {
@@ -345,6 +346,7 @@ export class WorkspaceWorker {
345
346
  catch (error) {
346
347
  if (!(error instanceof Error))
347
348
  throw error;
349
+ hasLoadConfigError = true;
348
350
  const relPath = toRelative(configFilePath, this.options.cwd);
349
351
  const cause = formatCauseMessage(error, this.options.cwd);
350
352
  logError(`Error loading ${relPath} (${cause})`);
@@ -364,7 +366,10 @@ export class WorkspaceWorker {
364
366
  inputs.push(toEntry(configFilePath));
365
367
  storeConfigFilePath(pluginName, toConfig(pluginName, configFilePath));
366
368
  cache.configFile = toEntry(configFilePath);
367
- if (fd?.changed && fd.meta && !seen.get(key)?.has(configFilePath)) {
369
+ if (hasLoadConfigError) {
370
+ this.cache.removeEntry(configFilePath);
371
+ }
372
+ else if (fd?.changed && fd.meta && !seen.get(key)?.has(configFilePath)) {
368
373
  fd.meta.data = cache;
369
374
  }
370
375
  if (!seen.has(key))
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../util/parse-args.js';
2
2
  import { compact } from '../util/array.js';
3
3
  import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
4
4
  import { isValidBinary } from '../util/modules.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../util/parse-args.js';
2
2
  import { pluginArgsMap } from '../plugins.js';
3
3
  import { compact } from '../util/array.js';
4
4
  import { toBinary, toConfig, toDeferResolve, toDeferResolveEntry, toEntry } from '../util/input.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toEntry } from '../../util/input.js';
3
3
  import { isAbsolute, join } from '../../util/path.js';
4
4
  import { _resolveSync } from '../../util/resolve.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  export const resolve = (_binary, args, options) => {
3
3
  const { fromArgs, manifest } = options;
4
4
  const parsed = parseArgs(args, { '--': true });
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { isInternal } from '../../util/path.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toBinary } from '../../util/input.js';
3
3
  import { isValidBinary } from '../../util/modules.js';
4
4
  import { resolveDlx } from './pnpx.js';
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  export const resolveDlx = (args, options) => {
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../../util/parse-args.js';
2
2
  import { isBinary, isDependency, toBinary, toDependency } from '../../util/input.js';
3
3
  import { stripVersionFromSpecifier } from '../../util/modules.js';
4
4
  import { join } from '../../util/path.js';
@@ -1,3 +1,2 @@
1
- import parseArgs from 'minimist';
2
1
  export declare const argsFrom: (args: string[], from: string) => string[];
3
- export declare const parseNodeArgs: (args: string[]) => parseArgs.ParsedArgs;
2
+ export declare const parseNodeArgs: (args: string[]) => import("../util/parse-args.ts").ParsedArgs;
@@ -1,4 +1,4 @@
1
- import parseArgs from 'minimist';
1
+ import parseArgs from '../util/parse-args.js';
2
2
  export const argsFrom = (args, from) => args.slice(args.indexOf(from));
3
3
  export const parseNodeArgs = (args) => parseArgs(args, {
4
4
  string: ['r'],
package/dist/cli.js CHANGED
@@ -50,6 +50,7 @@ const main = async () => {
50
50
  isProduction: options.isProduction,
51
51
  isShowProgress: options.isShowProgress,
52
52
  isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
53
+ isTreatTagHintsAsErrors: options.isTreatTagHintsAsErrors,
53
54
  maxShowIssues: args['max-show-issues'] ? Number(args['max-show-issues']) : undefined,
54
55
  options: args['reporter-options'] ?? '',
55
56
  preprocessorOptions: args['preprocessor-options'] ?? '',
@@ -75,7 +76,8 @@ const main = async () => {
75
76
  }
76
77
  if (!args['no-exit-code'] &&
77
78
  (totalErrorCount > Number(args['max-issues'] ?? 0) ||
78
- (!options.isDisableConfigHints && options.isTreatConfigHintsAsErrors && configurationHints.length > 0))) {
79
+ (!options.isDisableConfigHints && options.isTreatConfigHintsAsErrors && configurationHints.length > 0) ||
80
+ (!options.isDisableTagHints && options.isTreatTagHintsAsErrors && tagHints.size > 0))) {
79
81
  process.exitCode = 1;
80
82
  return;
81
83
  }
@@ -1,6 +1,9 @@
1
1
  import type { CompilerSync } from './types.ts';
2
2
  export declare const fencedCodeBlockMatcher: RegExp;
3
3
  export declare const inlineCodeMatcher: RegExp;
4
+ export declare const scriptExtractor: RegExp;
5
+ export declare const blockCommentMatcher: RegExp;
6
+ export declare const lineCommentMatcher: RegExp;
4
7
  export declare const importMatcher: RegExp;
5
8
  export declare const importsWithinScripts: CompilerSync;
6
9
  export declare const scriptBodies: CompilerSync;
@@ -1,27 +1,23 @@
1
1
  export const fencedCodeBlockMatcher = /```[\s\S]*?```/g;
2
2
  export const inlineCodeMatcher = /`[^`]+`/g;
3
- const scriptExtractor = /<script\b(?:[^>"']|"[^"]*"|'[^']*')*>([\s\S]*?)<\/script>/gm;
4
- const blockCommentMatcher = /\/\*[\s\S]*?\*\//g;
5
- const lineCommentMatcher = /^[ \t]*\/\/.*$/gm;
3
+ export const scriptExtractor = /<script\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/script>/gi;
4
+ export const blockCommentMatcher = /\/\*[\s\S]*?\*\//g;
5
+ export const lineCommentMatcher = /^[ \t]*\/\/.*$/gm;
6
6
  export const importMatcher = /import(?:\s*\(\s*['"][^'"]+['"][^)]*\)|(?!\s*\()[^'"]+['"][^'"]+['"])/g;
7
7
  export const importsWithinScripts = (text) => {
8
8
  const scripts = [];
9
- let scriptMatch;
10
- while ((scriptMatch = scriptExtractor.exec(text))) {
11
- const body = scriptMatch[1].replace(blockCommentMatcher, '').replace(lineCommentMatcher, '');
12
- for (const importMatch of body.matchAll(importMatcher)) {
9
+ for (const [, , scriptBody] of text.matchAll(scriptExtractor)) {
10
+ const body = scriptBody.replace(blockCommentMatcher, '').replace(lineCommentMatcher, '');
11
+ for (const importMatch of body.matchAll(importMatcher))
13
12
  scripts.push(importMatch);
14
- }
15
13
  }
16
14
  return scripts.join(';\n');
17
15
  };
18
- const scriptBodyExtractor = /<script\b(?:[^>"']|"[^"]*"|'[^']*')*>(?<body>[\s\S]*?)<\/script>/gm;
19
16
  export const scriptBodies = (text) => {
20
17
  const scripts = [];
21
- let scriptMatch;
22
- while ((scriptMatch = scriptBodyExtractor.exec(text))) {
23
- if (scriptMatch.groups?.body)
24
- scripts.push(scriptMatch.groups.body);
18
+ for (const [, , body] of text.matchAll(scriptExtractor)) {
19
+ if (body)
20
+ scripts.push(body);
25
21
  }
26
22
  return scripts.join(';\n');
27
23
  };