knip 5.83.1 → 5.84.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 (115) hide show
  1. package/dist/ConfigurationChief.d.ts +24 -0
  2. package/dist/IssueCollector.d.ts +15 -2
  3. package/dist/IssueCollector.js +59 -9
  4. package/dist/ProjectPrincipal.d.ts +2 -1
  5. package/dist/ProjectPrincipal.js +2 -1
  6. package/dist/WorkspaceWorker.d.ts +4 -1
  7. package/dist/WorkspaceWorker.js +69 -13
  8. package/dist/binaries/bash-parser.d.ts +0 -1
  9. package/dist/binaries/bash-parser.js +2 -3
  10. package/dist/binaries/fallback.js +1 -1
  11. package/dist/binaries/package-manager/npm.js +1 -1
  12. package/dist/binaries/package-manager/pnpm.js +3 -2
  13. package/dist/binaries/package-manager/yarn.js +1 -1
  14. package/dist/compilers/compilers.d.ts +3 -3
  15. package/dist/compilers/index.d.ts +45 -4
  16. package/dist/compilers/index.js +6 -20
  17. package/dist/compilers/scss.d.ts +2 -2
  18. package/dist/compilers/types.d.ts +6 -5
  19. package/dist/constants.js +1 -0
  20. package/dist/graph/analyze.js +3 -0
  21. package/dist/graph/build.js +29 -15
  22. package/dist/plugins/astro/compiler-mdx.d.ts +2 -0
  23. package/dist/{compilers/astro-mdx.js → plugins/astro/compiler-mdx.js} +2 -4
  24. package/dist/plugins/astro/compiler.d.ts +2 -0
  25. package/dist/{compilers/astro.js → plugins/astro/compiler.js} +2 -3
  26. package/dist/plugins/astro/index.js +10 -0
  27. package/dist/plugins/bun/index.js +14 -5
  28. package/dist/plugins/bun/types.d.ts +5 -0
  29. package/dist/plugins/bun/types.js +1 -0
  30. package/dist/plugins/convex/index.js +1 -1
  31. package/dist/plugins/dotenv/index.js +8 -1
  32. package/dist/plugins/execa/index.d.ts +3 -0
  33. package/dist/plugins/execa/index.js +15 -0
  34. package/dist/{typescript/visitors/scripts → plugins/execa/visitors}/execa.js +3 -3
  35. package/dist/plugins/index.d.ts +4 -0
  36. package/dist/plugins/index.js +8 -0
  37. package/dist/plugins/jest/index.js +2 -2
  38. package/dist/plugins/metro/index.js +8 -2
  39. package/dist/plugins/pm2/index.d.ts +3 -0
  40. package/dist/plugins/pm2/index.js +34 -0
  41. package/dist/plugins/pm2/types.d.ts +9 -0
  42. package/dist/plugins/pm2/types.js +1 -0
  43. package/dist/plugins/prettier/index.js +2 -0
  44. package/dist/plugins/prisma/compiler.d.ts +2 -0
  45. package/dist/{compilers/prisma.js → plugins/prisma/compiler.js} +1 -2
  46. package/dist/plugins/prisma/index.js +6 -0
  47. package/dist/plugins/react-native/index.d.ts +3 -0
  48. package/dist/plugins/react-native/index.js +38 -0
  49. package/dist/plugins/react-native/types.d.ts +7 -0
  50. package/dist/plugins/react-native/types.js +1 -0
  51. package/dist/plugins/svelte/compiler.d.ts +2 -0
  52. package/dist/plugins/svelte/compiler.js +3 -0
  53. package/dist/plugins/svelte/index.js +6 -0
  54. package/dist/plugins/tailwind/compiler.d.ts +2 -0
  55. package/dist/{compilers/tailwind.js → plugins/tailwind/compiler.js} +2 -3
  56. package/dist/plugins/tailwind/index.js +6 -0
  57. package/dist/plugins/typescript/index.js +2 -2
  58. package/dist/plugins/vite/index.js +5 -0
  59. package/dist/plugins/vite/visitors/importMetaGlob.d.ts +2 -0
  60. package/dist/plugins/vite/visitors/importMetaGlob.js +32 -0
  61. package/dist/plugins/vue/compiler.d.ts +2 -0
  62. package/dist/plugins/vue/compiler.js +3 -0
  63. package/dist/plugins/vue/index.js +6 -0
  64. package/dist/plugins/webpack/index.js +15 -6
  65. package/dist/plugins/webpack/visitors/requireContext.d.ts +2 -0
  66. package/dist/plugins/webpack/visitors/requireContext.js +29 -0
  67. package/dist/plugins/yarn/index.js +18 -0
  68. package/dist/plugins/zx/index.d.ts +3 -0
  69. package/dist/plugins/zx/index.js +15 -0
  70. package/dist/{typescript/visitors/scripts → plugins/zx/visitors}/zx.js +2 -2
  71. package/dist/reporters/util/configuration-hints.js +3 -0
  72. package/dist/run.d.ts +1 -1
  73. package/dist/schema/configuration.d.ts +60 -0
  74. package/dist/schema/plugins.d.ts +20 -0
  75. package/dist/schema/plugins.js +4 -0
  76. package/dist/session/session.d.ts +1 -1
  77. package/dist/types/PluginNames.d.ts +2 -2
  78. package/dist/types/PluginNames.js +4 -0
  79. package/dist/types/config.d.ts +26 -4
  80. package/dist/types/issues.d.ts +1 -1
  81. package/dist/typescript/ast-helpers.d.ts +2 -0
  82. package/dist/typescript/ast-helpers.js +44 -0
  83. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  84. package/dist/typescript/get-imports-and-exports.js +5 -5
  85. package/dist/typescript/visitors/dynamic-imports/index.d.ts +2 -1
  86. package/dist/typescript/visitors/dynamic-imports/index.js +3 -2
  87. package/dist/typescript/visitors/dynamic-imports/moduleRegister.d.ts +3 -0
  88. package/dist/typescript/visitors/dynamic-imports/moduleRegister.js +25 -0
  89. package/dist/typescript/visitors/index.d.ts +2 -0
  90. package/dist/typescript/visitors/scripts/index.d.ts +2 -1
  91. package/dist/typescript/visitors/scripts/index.js +2 -4
  92. package/dist/util/cli-arguments.d.ts +1 -1
  93. package/dist/util/cli-arguments.js +5 -3
  94. package/dist/util/create-input-handler.js +8 -4
  95. package/dist/util/create-options.d.ts +40 -0
  96. package/dist/util/jiti.d.ts +1 -5
  97. package/dist/util/jiti.js +2 -7
  98. package/dist/util/modules.d.ts +1 -0
  99. package/dist/util/modules.js +1 -0
  100. package/dist/util/watch.d.ts +1 -1
  101. package/dist/util/watch.js +9 -2
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +1 -1
  104. package/package.json +1 -1
  105. package/schema.json +19 -0
  106. package/dist/compilers/astro-mdx.d.ts +0 -6
  107. package/dist/compilers/astro.d.ts +0 -6
  108. package/dist/compilers/prisma.d.ts +0 -6
  109. package/dist/compilers/svelte.d.ts +0 -6
  110. package/dist/compilers/svelte.js +0 -4
  111. package/dist/compilers/tailwind.d.ts +0 -6
  112. package/dist/compilers/vue.d.ts +0 -6
  113. package/dist/compilers/vue.js +0 -4
  114. /package/dist/{typescript/visitors/scripts → plugins/execa/visitors}/execa.d.ts +0 -0
  115. /package/dist/{typescript/visitors/scripts → plugins/zx/visitors}/zx.d.ts +0 -0
@@ -196,6 +196,11 @@ export declare class ConfigurationChief {
196
196
  entry?: string | string[] | undefined;
197
197
  project?: string | string[] | undefined;
198
198
  } | undefined;
199
+ execa?: string | boolean | string[] | {
200
+ config?: string | string[] | undefined;
201
+ entry?: string | string[] | undefined;
202
+ project?: string | string[] | undefined;
203
+ } | undefined;
199
204
  expo?: string | boolean | string[] | {
200
205
  config?: string | string[] | undefined;
201
206
  entry?: string | string[] | undefined;
@@ -431,6 +436,11 @@ export declare class ConfigurationChief {
431
436
  entry?: string | string[] | undefined;
432
437
  project?: string | string[] | undefined;
433
438
  } | undefined;
439
+ pm2?: string | boolean | string[] | {
440
+ config?: string | string[] | undefined;
441
+ entry?: string | string[] | undefined;
442
+ project?: string | string[] | undefined;
443
+ } | undefined;
434
444
  pnpm?: string | boolean | string[] | {
435
445
  config?: string | string[] | undefined;
436
446
  entry?: string | string[] | undefined;
@@ -461,6 +471,11 @@ export declare class ConfigurationChief {
461
471
  entry?: string | string[] | undefined;
462
472
  project?: string | string[] | undefined;
463
473
  } | undefined;
474
+ 'react-native'?: string | boolean | string[] | {
475
+ config?: string | string[] | undefined;
476
+ entry?: string | string[] | undefined;
477
+ project?: string | string[] | undefined;
478
+ } | undefined;
464
479
  'react-router'?: string | boolean | string[] | {
465
480
  config?: string | string[] | undefined;
466
481
  entry?: string | string[] | undefined;
@@ -711,6 +726,11 @@ export declare class ConfigurationChief {
711
726
  entry?: string | string[] | undefined;
712
727
  project?: string | string[] | undefined;
713
728
  } | undefined;
729
+ zx?: string | boolean | string[] | {
730
+ config?: string | string[] | undefined;
731
+ entry?: string | string[] | undefined;
732
+ project?: string | string[] | undefined;
733
+ } | undefined;
714
734
  entry?: string | string[] | undefined;
715
735
  project?: string | string[] | undefined;
716
736
  paths?: Record<string, string[]> | undefined;
@@ -761,6 +781,7 @@ export declare class ConfigurationChief {
761
781
  drizzle?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
762
782
  eleventy?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
763
783
  eslint?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
784
+ execa?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
764
785
  expo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
765
786
  "expressive-code"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
766
787
  gatsby?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -806,11 +827,13 @@ export declare class ConfigurationChief {
806
827
  "playwright-ct"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
807
828
  "playwright-test"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
808
829
  plop?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
830
+ pm2?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
809
831
  postcss?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
810
832
  preconstruct?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
811
833
  prettier?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
812
834
  prisma?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
813
835
  "react-cosmos"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
836
+ "react-native"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
814
837
  "react-router"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
815
838
  relay?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
816
839
  "release-it"?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -859,6 +882,7 @@ export declare class ConfigurationChief {
859
882
  wrangler?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
860
883
  xo?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
861
884
  yorkie?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
885
+ zx?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
862
886
  entry: string[];
863
887
  project: string[];
864
888
  paths: Record<string, string[]>;
@@ -17,10 +17,22 @@ export declare class IssueCollector {
17
17
  private isMatch;
18
18
  private isFileMatch;
19
19
  private issueMatchers;
20
+ private isTrackUnusedIgnorePatterns;
21
+ private unusedIgnorePatterns;
22
+ private unusedIgnoreFilesPatterns;
20
23
  constructor(options: MainOptions);
21
24
  setWorkspaceFilter(workspaceFilePathFilter: WorkspaceFilePathFilter | undefined): void;
22
- addIgnorePatterns(patterns: string[]): void;
23
- addIgnoreFilesPatterns(patterns: string[]): void;
25
+ addIgnorePatterns(entries: {
26
+ pattern: string;
27
+ id: string;
28
+ workspaceName?: string;
29
+ }[]): void;
30
+ addIgnoreFilesPatterns(entries: {
31
+ pattern: string;
32
+ id: string;
33
+ workspaceName?: string;
34
+ }[]): void;
35
+ private markUsedPatterns;
24
36
  setIgnoreIssues(ignoreIssues?: IgnoreIssues): void;
25
37
  private shouldIgnoreIssue;
26
38
  addFileCounts({ processed, unused }: {
@@ -38,6 +50,7 @@ export declare class IssueCollector {
38
50
  tagHints: Set<TagHint>;
39
51
  configurationHints: ConfigurationHint[];
40
52
  };
53
+ getUnusedIgnorePatternHints(options: MainOptions): ConfigurationHint[];
41
54
  private retainedIssues;
42
55
  retainIssue(issue: Issue): void;
43
56
  getRetainedIssues(): Issue[];
@@ -25,27 +25,61 @@ export class IssueCollector {
25
25
  isMatch;
26
26
  isFileMatch;
27
27
  issueMatchers = new Map();
28
+ isTrackUnusedIgnorePatterns;
29
+ unusedIgnorePatterns = new Map();
30
+ unusedIgnoreFilesPatterns = new Map();
28
31
  constructor(options) {
29
32
  this.cwd = options.cwd;
30
33
  this.rules = options.rules;
31
34
  this.workspaceFilter = () => true;
32
35
  this.isMatch = () => false;
33
36
  this.isFileMatch = () => false;
37
+ this.isTrackUnusedIgnorePatterns = !options.isDisableConfigHints;
34
38
  }
35
39
  setWorkspaceFilter(workspaceFilePathFilter) {
36
40
  if (workspaceFilePathFilter)
37
41
  this.workspaceFilter = workspaceFilePathFilter;
38
42
  }
39
- addIgnorePatterns(patterns) {
40
- for (const pattern of patterns)
41
- this.ignorePatterns.add(pattern);
43
+ addIgnorePatterns(entries) {
44
+ for (const entry of entries) {
45
+ this.ignorePatterns.add(entry.pattern);
46
+ if (!this.isTrackUnusedIgnorePatterns)
47
+ continue;
48
+ if (entry.pattern.startsWith('!'))
49
+ continue;
50
+ if (this.unusedIgnorePatterns.has(entry.pattern))
51
+ continue;
52
+ this.unusedIgnorePatterns.set(entry.pattern, {
53
+ hint: { type: 'ignore', identifier: entry.id, workspaceName: entry.workspaceName },
54
+ isMatch: picomatch(entry.pattern, { dot: true }),
55
+ });
56
+ }
42
57
  this.isMatch = createMatcher(this.ignorePatterns);
43
58
  }
44
- addIgnoreFilesPatterns(patterns) {
45
- for (const pattern of patterns)
46
- this.ignoreFilesPatterns.add(pattern);
59
+ 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
+ }
47
73
  this.isFileMatch = createMatcher(this.ignoreFilesPatterns);
48
74
  }
75
+ markUsedPatterns(filePath, unused) {
76
+ if (unused.size === 0)
77
+ return;
78
+ for (const [pattern, { isMatch }] of unused) {
79
+ if (isMatch(filePath))
80
+ unused.delete(pattern);
81
+ }
82
+ }
49
83
  setIgnoreIssues(ignoreIssues) {
50
84
  if (!ignoreIssues)
51
85
  return;
@@ -78,10 +112,14 @@ export class IssueCollector {
78
112
  continue;
79
113
  if (this.referencedFiles.has(filePath))
80
114
  continue;
81
- if (this.isMatch(filePath))
115
+ if (this.isMatch(filePath)) {
116
+ this.markUsedPatterns(filePath, this.unusedIgnorePatterns);
82
117
  continue;
83
- if (this.isFileMatch(filePath))
118
+ }
119
+ if (this.isFileMatch(filePath)) {
120
+ this.markUsedPatterns(filePath, this.unusedIgnoreFilesPatterns);
84
121
  continue;
122
+ }
85
123
  if (this.shouldIgnoreIssue(filePath, 'files'))
86
124
  continue;
87
125
  this.issues.files.add(filePath);
@@ -94,8 +132,10 @@ export class IssueCollector {
94
132
  addIssue(issue) {
95
133
  if (!this.workspaceFilter(issue.filePath))
96
134
  return;
97
- if (this.isMatch(issue.filePath))
135
+ if (this.isMatch(issue.filePath)) {
136
+ this.markUsedPatterns(issue.filePath, this.unusedIgnorePatterns);
98
137
  return;
138
+ }
99
139
  if (this.shouldIgnoreIssue(issue.filePath, issue.type))
100
140
  return;
101
141
  if (this.rules[issue.type] === 'off')
@@ -133,6 +173,16 @@ export class IssueCollector {
133
173
  configurationHints: Array.from(this.configurationHints.values()),
134
174
  };
135
175
  }
176
+ getUnusedIgnorePatternHints(options) {
177
+ if (!options.isReportFiles)
178
+ return [];
179
+ const hints = [];
180
+ for (const p of this.unusedIgnorePatterns.values())
181
+ hints.push(p.hint);
182
+ for (const p of this.unusedIgnoreFilesPatterns.values())
183
+ hints.push(p.hint);
184
+ return hints;
185
+ }
136
186
  retainedIssues = [];
137
187
  retainIssue(issue) {
138
188
  this.retainedIssues.push(issue);
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import { CacheConsultant } from './CacheConsultant.js';
3
3
  import type { AsyncCompilers, SyncCompilers } from './compilers/types.js';
4
- import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile } from './types/config.js';
4
+ import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile, Visitors } from './types/config.js';
5
5
  import type { Export, ExportMember, FileNode, ModuleGraph } from './types/module-graph.js';
6
6
  import type { Paths, PrincipalOptions } from './types/project.js';
7
7
  import type { ResolveModuleNames } from './typescript/resolve-module-names.js';
@@ -13,6 +13,7 @@ export declare class ProjectPrincipal {
13
13
  projectPaths: Set<string>;
14
14
  programPaths: Set<string>;
15
15
  skipExportsAnalysis: Set<string>;
16
+ visitors: Visitors;
16
17
  cwd: string;
17
18
  compilerOptions: ts.CompilerOptions;
18
19
  extensions: Set<string>;
@@ -31,6 +31,7 @@ export class ProjectPrincipal {
31
31
  projectPaths = new Set();
32
32
  programPaths = new Set();
33
33
  skipExportsAnalysis = new Set();
34
+ visitors = { dynamicImport: [], script: [] };
34
35
  cwd;
35
36
  compilerOptions;
36
37
  extensions;
@@ -165,7 +166,7 @@ export class ProjectPrincipal {
165
166
  throw new Error(`Unable to find ${filePath}`);
166
167
  const skipExports = this.skipExportsAnalysis.has(filePath);
167
168
  const resolve = (specifier) => this.backend.resolveModuleNames([specifier], sourceFile.fileName)[0];
168
- return _getImportsAndExports(sourceFile, resolve, typeChecker, options, ignoreExportsUsedInFile, skipExports);
169
+ return _getImportsAndExports(sourceFile, resolve, typeChecker, options, ignoreExportsUsedInFile, skipExports, this.visitors);
169
170
  }
170
171
  invalidateFile(filePath) {
171
172
  this.backend.fileManager.invalidate(filePath);
@@ -1,6 +1,6 @@
1
1
  import { CacheConsultant } from './CacheConsultant.js';
2
2
  import { type Workspace } from './ConfigurationChief.js';
3
- import type { GetSourceFile, HandleInput, WorkspaceConfiguration } from './types/config.js';
3
+ import type { GetSourceFile, HandleInput, RegisterCompiler, RegisterVisitor, WorkspaceConfiguration } from './types/config.js';
4
4
  import type { ConfigurationHint } from './types/issues.js';
5
5
  import type { PluginName } from './types/PluginNames.js';
6
6
  import type { PackageJson } from './types/package-json.js';
@@ -59,7 +59,10 @@ export declare class WorkspaceWorker {
59
59
  getProductionEntryFilePatterns(negatedTestFilePatterns: string[]): string[];
60
60
  getProductionProjectFilePatterns(negatedTestFilePatterns: string[]): string[];
61
61
  private getConfigurationFilePatterns;
62
+ registerCompilers(registerCompiler: RegisterCompiler): Promise<void>;
63
+ registerVisitors(registerVisitors: RegisterVisitor): void;
62
64
  runPlugins(): Promise<Input[]>;
65
+ private filterTransitiveDependencies;
63
66
  getConfigurationHints(type: 'entry' | 'project', patterns: string[], filePaths: string[], includedPaths: Set<string>): ConfigurationHint[];
64
67
  onDispose(): void;
65
68
  }
@@ -5,13 +5,15 @@ import { isDefaultPattern } from './ConfigurationChief.js';
5
5
  import { ROOT_WORKSPACE_NAME } from './constants.js';
6
6
  import { getFilteredScripts } from './manifest/helpers.js';
7
7
  import { PluginEntries, Plugins } from './plugins.js';
8
+ import { collectStringLiterals, isExternalReExportsOnly } from './typescript/ast-helpers.js';
8
9
  import { compact } from './util/array.js';
9
10
  import { debugLogArray, debugLogObject } from './util/debug.js';
10
11
  import { _glob, hasNoProductionSuffix, hasProductionSuffix, negate } from './util/glob.js';
11
- import { isConfig, toConfig, toDebugString, toEntry, toProductionEntry, } from './util/input.js';
12
+ import { isConfig, isDeferResolve, isDependency, toConfig, toDebugString, toEntry, toProductionEntry, } from './util/input.js';
13
+ import { getPackageNameFromSpecifier } from './util/modules.js';
12
14
  import { getKeysByValue } from './util/object.js';
13
15
  import { timerify } from './util/Performance.js';
14
- import { basename, dirname, join } from './util/path.js';
16
+ import { basename, dirname, extname, isInternal, join } from './util/path.js';
15
17
  import { loadConfigForPlugin } from './util/plugin.js';
16
18
  import { ELLIPSIS } from './util/string.js';
17
19
  const nullConfig = { config: null, entry: null, project: null };
@@ -153,6 +155,26 @@ export class WorkspaceWorker {
153
155
  const pluginConfig = this.getConfigForPlugin(pluginName);
154
156
  return pluginConfig.config ?? this.getPluginConfig(plugin) ?? [];
155
157
  }
158
+ async registerCompilers(registerCompiler) {
159
+ const cwd = this.dir;
160
+ const hasDependency = (packageName) => this.dependencies.has(packageName);
161
+ for (const [pluginName, plugin] of PluginEntries) {
162
+ if (!plugin.registerCompilers)
163
+ continue;
164
+ if (this.config[pluginName] === false)
165
+ continue;
166
+ if (this.options.cwd !== this.dir && plugin.isRootOnly)
167
+ continue;
168
+ await plugin.registerCompilers({ cwd, hasDependency, registerCompiler });
169
+ }
170
+ }
171
+ registerVisitors(registerVisitors) {
172
+ for (const pluginName of this.enabledPlugins) {
173
+ const plugin = Plugins[pluginName];
174
+ if (plugin.registerVisitors)
175
+ plugin.registerVisitors({ registerVisitors });
176
+ }
177
+ }
156
178
  async runPlugins() {
157
179
  const wsName = this.name;
158
180
  const cwd = this.dir;
@@ -237,6 +259,8 @@ export class WorkspaceWorker {
237
259
  for (const id of plugin.production)
238
260
  inputs.push(toProductionEntry(id));
239
261
  }
262
+ if (typeof plugin.setup === 'function')
263
+ await plugin.setup();
240
264
  for (const configFilePath of configFilePaths) {
241
265
  const isManifest = basename(configFilePath) === 'package.json';
242
266
  const fd = isManifest ? undefined : this.cache.getFileDescriptor(configFilePath);
@@ -262,18 +286,25 @@ export class WorkspaceWorker {
262
286
  const cache = {};
263
287
  const key = `${wsName}:${pluginName}`;
264
288
  if (plugin.resolveConfig && !seen.get(key)?.has(configFilePath)) {
265
- if (typeof plugin.setup === 'function')
266
- await plugin.setup(resolveOpts);
267
- const isLoad = typeof plugin.isLoadConfig === 'function' ? plugin.isLoadConfig(resolveOpts, this.dependencies) : true;
268
- const localConfig = isLoad && (await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName));
269
- if (localConfig) {
270
- const inputs = await plugin.resolveConfig(localConfig, resolveOpts);
271
- for (const input of inputs)
272
- addInput(input, configFilePath);
273
- cache.resolveConfig = inputs;
289
+ if (extname(configFilePath) !== '.json') {
290
+ const sourceFile = this.getSourceFile(configFilePath);
291
+ if (sourceFile && isExternalReExportsOnly(sourceFile)) {
292
+ cache.resolveConfig = [];
293
+ }
294
+ }
295
+ if (!cache.resolveConfig) {
296
+ const isLoad = typeof plugin.isLoadConfig === 'function' ? plugin.isLoadConfig(resolveOpts, this.dependencies) : true;
297
+ const localConfig = isLoad && (await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName));
298
+ if (localConfig) {
299
+ const inputs = await plugin.resolveConfig(localConfig, resolveOpts);
300
+ if (plugin.isFilterTransitiveDependencies && !isManifest) {
301
+ this.filterTransitiveDependencies(inputs, configFilePath);
302
+ }
303
+ for (const input of inputs)
304
+ addInput(input, configFilePath);
305
+ cache.resolveConfig = inputs;
306
+ }
274
307
  }
275
- if (typeof plugin.teardown === 'function')
276
- await plugin.teardown(resolveOpts);
277
308
  }
278
309
  if (plugin.resolveFromAST) {
279
310
  const sourceFile = this.getSourceFile(configFilePath);
@@ -336,6 +367,31 @@ export class WorkspaceWorker {
336
367
  debugLogArray(wsName, 'Plugin dependencies', () => compact(inputs.map(input => toDebugString(input, rootCwd))));
337
368
  return inputs;
338
369
  }
370
+ filterTransitiveDependencies(inputs, configFilePath) {
371
+ const literals = new Set();
372
+ const visited = new Set();
373
+ const collect = (filePath) => {
374
+ if (visited.has(filePath))
375
+ return;
376
+ visited.add(filePath);
377
+ const sourceFile = this.getSourceFile(filePath);
378
+ if (!sourceFile)
379
+ return;
380
+ for (const literal of collectStringLiterals(sourceFile)) {
381
+ literals.add(literal);
382
+ if (isInternal(literal))
383
+ collect(join(dirname(filePath), literal));
384
+ }
385
+ };
386
+ collect(configFilePath);
387
+ for (const input of inputs) {
388
+ if (!input.optional && (isDeferResolve(input) || isDependency(input))) {
389
+ const name = getPackageNameFromSpecifier(input.specifier);
390
+ if (name && !literals.has(name))
391
+ input.optional = true;
392
+ }
393
+ }
394
+ }
339
395
  getConfigurationHints(type, patterns, filePaths, includedPaths) {
340
396
  const hints = [];
341
397
  const entries = this.config[type].filter(pattern => !pattern.startsWith('!'));
@@ -1,4 +1,3 @@
1
1
  import type { GetInputsFromScriptsOptions } from '../types/config.js';
2
2
  import { type Input } from '../util/input.js';
3
- export declare const isValidBinary: (str: string) => boolean;
4
3
  export declare const getDependenciesFromScript: (script: string, options: GetInputsFromScriptsOptions) => Input[];
@@ -2,7 +2,7 @@ import parse, {} from '../../vendor/bash-parser/index.js';
2
2
  import { Plugins, pluginArgsMap } from '../plugins.js';
3
3
  import { debugLogObject } from '../util/debug.js';
4
4
  import { toBinary, toDeferResolve } from '../util/input.js';
5
- import { extractBinary } from '../util/modules.js';
5
+ import { extractBinary, isValidBinary } from '../util/modules.js';
6
6
  import { relative } from '../util/path.js';
7
7
  import { truncate } from '../util/string.js';
8
8
  import { resolve as fallbackResolve } from './fallback.js';
@@ -12,7 +12,6 @@ import { parseNodeArgs } from './util.js';
12
12
  const spawningBinaries = ['cross-env', 'retry-cli'];
13
13
  const isExpansion = (node) => 'expansion' in node;
14
14
  const isAssignment = (node) => 'type' in node && node.type === 'AssignmentWord';
15
- export const isValidBinary = (str) => !/[*:!()]/.test(str);
16
15
  export const getDependenciesFromScript = (script, options) => {
17
16
  if (!script)
18
17
  return [];
@@ -21,8 +20,8 @@ export const getDependenciesFromScript = (script, options) => {
21
20
  return [];
22
21
  return getDependenciesFromScript(args.filter(arg => arg !== '--').join(' '), {
23
22
  ...options,
24
- ...opts,
25
23
  knownBinsOnly: false,
24
+ ...opts,
26
25
  });
27
26
  };
28
27
  const definedFunctions = new Set();
@@ -1,7 +1,7 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { compact } from '../util/array.js';
3
3
  import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
4
- import { isValidBinary } from './bash-parser.js';
4
+ import { isValidBinary } from '../util/modules.js';
5
5
  const spawningBinaries = ['cross-env', 'retry-cli'];
6
6
  const endOfCommandBinaries = ['dotenvx', 'env-cmd', 'op'];
7
7
  const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
@@ -3,7 +3,7 @@ export const resolve = (_binary, args, options) => {
3
3
  const { fromArgs, manifestScriptNames } = options;
4
4
  const parsed = parseArgs(args, { '--': true });
5
5
  const [command, script] = parsed._;
6
- const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
6
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
7
7
  if (command === 'exec')
8
8
  return _childArgs;
9
9
  if (command === 'run' && manifestScriptNames.has(script))
@@ -1,5 +1,6 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { toBinary } from '../../util/input.js';
3
+ import { isValidBinary } from '../../util/modules.js';
3
4
  import { resolveDlx } from './pnpx.js';
4
5
  const commands = [
5
6
  'add',
@@ -74,12 +75,12 @@ export const resolve = (_binary, args, options) => {
74
75
  const { manifestScriptNames, fromArgs } = options;
75
76
  if (parsed.filter && !parsed.recursive)
76
77
  return [];
77
- const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
78
+ const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
78
79
  if (command === 'exec') {
79
80
  return childInputs.length > 0 ? childInputs : fromArgs(parsed._.slice(1));
80
81
  }
81
82
  const isScript = manifestScriptNames.has(command);
82
83
  if (isScript || commands.includes(command))
83
84
  return childInputs;
84
- return command ? [toBinary(command)] : [];
85
+ return command && isValidBinary(command) ? [toBinary(command)] : [];
85
86
  };
@@ -55,7 +55,7 @@ export const resolve = (_binary, args, options) => {
55
55
  const [command, binary] = parsed._;
56
56
  if (!command && !binary)
57
57
  return [];
58
- const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
58
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--'], { knownBinsOnly: true }) : [];
59
59
  if (command === 'run') {
60
60
  if (manifestScriptNames.has(binary))
61
61
  return _childArgs;
@@ -1,8 +1,8 @@
1
- import type { SyncCompilerFn } from './types.js';
1
+ import type { CompilerSync } from './types.js';
2
2
  export declare const fencedCodeBlockMatcher: RegExp;
3
3
  export declare const inlineCodeMatcher: RegExp;
4
4
  export declare const importMatcher: RegExp;
5
- export declare const importsWithinScripts: SyncCompilerFn;
6
- export declare const scriptBodies: SyncCompilerFn;
5
+ export declare const importsWithinScripts: CompilerSync;
6
+ export declare const scriptBodies: CompilerSync;
7
7
  export declare const frontmatterMatcher: RegExp;
8
8
  export declare const importsWithinFrontmatter: (text: string, keys?: string[]) => string;
@@ -1,9 +1,10 @@
1
1
  import type { RawConfiguration } from '../types/config.js';
2
2
  import type { DependencySet } from '../types/workspace.js';
3
- import type { AsyncCompilerFn, AsyncCompilers, RawSyncCompilers, SyncCompilerFn, SyncCompilers } from './types.js';
3
+ import type { AsyncCompilers, CompilerAsync, CompilerSync, Compilers, RawSyncCompilers, SyncCompilers } from './types.js';
4
+ export declare const normalizeCompilerExtension: (ext: string) => string;
4
5
  export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
5
- syncCompilers: Record<string, true | SyncCompilerFn>;
6
- asyncCompilers: Record<string, AsyncCompilerFn>;
6
+ syncCompilers: Record<string, true | CompilerSync>;
7
+ asyncCompilers: Record<string, CompilerAsync>;
7
8
  angular?: string | boolean | string[] | {
8
9
  config?: string | string[] | undefined;
9
10
  entry?: string | string[] | undefined;
@@ -144,6 +145,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
144
145
  entry?: string | string[] | undefined;
145
146
  project?: string | string[] | undefined;
146
147
  } | undefined;
148
+ execa?: string | boolean | string[] | {
149
+ config?: string | string[] | undefined;
150
+ entry?: string | string[] | undefined;
151
+ project?: string | string[] | undefined;
152
+ } | undefined;
147
153
  expo?: string | boolean | string[] | {
148
154
  config?: string | string[] | undefined;
149
155
  entry?: string | string[] | undefined;
@@ -379,6 +385,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
379
385
  entry?: string | string[] | undefined;
380
386
  project?: string | string[] | undefined;
381
387
  } | undefined;
388
+ pm2?: string | boolean | string[] | {
389
+ config?: string | string[] | undefined;
390
+ entry?: string | string[] | undefined;
391
+ project?: string | string[] | undefined;
392
+ } | undefined;
382
393
  pnpm?: string | boolean | string[] | {
383
394
  config?: string | string[] | undefined;
384
395
  entry?: string | string[] | undefined;
@@ -409,6 +420,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
409
420
  entry?: string | string[] | undefined;
410
421
  project?: string | string[] | undefined;
411
422
  } | undefined;
423
+ 'react-native'?: string | boolean | string[] | {
424
+ config?: string | string[] | undefined;
425
+ entry?: string | string[] | undefined;
426
+ project?: string | string[] | undefined;
427
+ } | undefined;
412
428
  'react-router'?: string | boolean | string[] | {
413
429
  config?: string | string[] | undefined;
414
430
  entry?: string | string[] | undefined;
@@ -659,6 +675,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
659
675
  entry?: string | string[] | undefined;
660
676
  project?: string | string[] | undefined;
661
677
  } | undefined;
678
+ zx?: string | boolean | string[] | {
679
+ config?: string | string[] | undefined;
680
+ entry?: string | string[] | undefined;
681
+ project?: string | string[] | undefined;
682
+ } | undefined;
662
683
  workspaces?: Record<string, {
663
684
  angular?: string | boolean | string[] | {
664
685
  config?: string | string[] | undefined;
@@ -800,6 +821,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
800
821
  entry?: string | string[] | undefined;
801
822
  project?: string | string[] | undefined;
802
823
  } | undefined;
824
+ execa?: string | boolean | string[] | {
825
+ config?: string | string[] | undefined;
826
+ entry?: string | string[] | undefined;
827
+ project?: string | string[] | undefined;
828
+ } | undefined;
803
829
  expo?: string | boolean | string[] | {
804
830
  config?: string | string[] | undefined;
805
831
  entry?: string | string[] | undefined;
@@ -1035,6 +1061,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1035
1061
  entry?: string | string[] | undefined;
1036
1062
  project?: string | string[] | undefined;
1037
1063
  } | undefined;
1064
+ pm2?: string | boolean | string[] | {
1065
+ config?: string | string[] | undefined;
1066
+ entry?: string | string[] | undefined;
1067
+ project?: string | string[] | undefined;
1068
+ } | undefined;
1038
1069
  pnpm?: string | boolean | string[] | {
1039
1070
  config?: string | string[] | undefined;
1040
1071
  entry?: string | string[] | undefined;
@@ -1065,6 +1096,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1065
1096
  entry?: string | string[] | undefined;
1066
1097
  project?: string | string[] | undefined;
1067
1098
  } | undefined;
1099
+ 'react-native'?: string | boolean | string[] | {
1100
+ config?: string | string[] | undefined;
1101
+ entry?: string | string[] | undefined;
1102
+ project?: string | string[] | undefined;
1103
+ } | undefined;
1068
1104
  'react-router'?: string | boolean | string[] | {
1069
1105
  config?: string | string[] | undefined;
1070
1106
  entry?: string | string[] | undefined;
@@ -1315,6 +1351,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1315
1351
  entry?: string | string[] | undefined;
1316
1352
  project?: string | string[] | undefined;
1317
1353
  } | undefined;
1354
+ zx?: string | boolean | string[] | {
1355
+ config?: string | string[] | undefined;
1356
+ entry?: string | string[] | undefined;
1357
+ project?: string | string[] | undefined;
1358
+ } | undefined;
1318
1359
  entry?: string | string[] | undefined;
1319
1360
  project?: string | string[] | undefined;
1320
1361
  paths?: Record<string, string[]> | undefined;
@@ -1347,5 +1388,5 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
1347
1388
  tags?: string[] | undefined;
1348
1389
  treatConfigHintsAsErrors?: boolean | undefined;
1349
1390
  };
1350
- export declare const getIncludedCompilers: (syncCompilers: RawSyncCompilers, asyncCompilers: AsyncCompilers, dependencies: DependencySet) => [SyncCompilers, AsyncCompilers];
1391
+ export declare const getIncludedCompilers: (syncCompilers: RawSyncCompilers, asyncCompilers: AsyncCompilers, dependencies: DependencySet) => Compilers;
1351
1392
  export declare const getCompilerExtensions: (compilers: [SyncCompilers, AsyncCompilers]) => string[];