knip 0.0.0-angular.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 (326) hide show
  1. package/README.md +907 -0
  2. package/dist/ConfigurationChief.d.ts +53 -0
  3. package/dist/ConfigurationChief.js +297 -0
  4. package/dist/ConfigurationValidator.d.ts +2325 -0
  5. package/dist/ConfigurationValidator.js +119 -0
  6. package/dist/ConsoleStreamer.d.ts +12 -0
  7. package/dist/ConsoleStreamer.js +34 -0
  8. package/dist/DependencyDeputy.d.ts +64 -0
  9. package/dist/DependencyDeputy.js +254 -0
  10. package/dist/IssueCollector.d.ts +27 -0
  11. package/dist/IssueCollector.js +52 -0
  12. package/dist/PrincipalFactory.d.ts +25 -0
  13. package/dist/PrincipalFactory.js +56 -0
  14. package/dist/ProjectPrincipal.d.ts +64 -0
  15. package/dist/ProjectPrincipal.js +197 -0
  16. package/dist/WorkspaceWorker.d.ts +56 -0
  17. package/dist/WorkspaceWorker.js +244 -0
  18. package/dist/binaries/bash-parser.d.ts +6 -0
  19. package/dist/binaries/bash-parser.js +58 -0
  20. package/dist/binaries/index.d.ts +2 -0
  21. package/dist/binaries/index.js +18 -0
  22. package/dist/binaries/resolvers/c8.d.ts +2 -0
  23. package/dist/binaries/resolvers/c8.js +10 -0
  24. package/dist/binaries/resolvers/dotenv.d.ts +2 -0
  25. package/dist/binaries/resolvers/dotenv.js +6 -0
  26. package/dist/binaries/resolvers/fallback.d.ts +2 -0
  27. package/dist/binaries/resolvers/fallback.js +22 -0
  28. package/dist/binaries/resolvers/index.d.ts +8 -0
  29. package/dist/binaries/resolvers/index.js +8 -0
  30. package/dist/binaries/resolvers/node.d.ts +2 -0
  31. package/dist/binaries/resolvers/node.js +10 -0
  32. package/dist/binaries/resolvers/nodemon.d.ts +2 -0
  33. package/dist/binaries/resolvers/nodemon.js +15 -0
  34. package/dist/binaries/resolvers/npx.d.ts +2 -0
  35. package/dist/binaries/resolvers/npx.js +20 -0
  36. package/dist/binaries/resolvers/pnpm.d.ts +2 -0
  37. package/dist/binaries/resolvers/pnpm.js +63 -0
  38. package/dist/binaries/resolvers/rollup.d.ts +2 -0
  39. package/dist/binaries/resolvers/rollup.js +11 -0
  40. package/dist/binaries/resolvers/yarn.d.ts +2 -0
  41. package/dist/binaries/resolvers/yarn.js +48 -0
  42. package/dist/binaries/types.d.ts +15 -0
  43. package/dist/binaries/types.js +1 -0
  44. package/dist/binaries/util.d.ts +8 -0
  45. package/dist/binaries/util.js +33 -0
  46. package/dist/cli.d.ts +2 -0
  47. package/dist/cli.js +72 -0
  48. package/dist/constants.d.ts +12 -0
  49. package/dist/constants.js +90 -0
  50. package/dist/index.d.ts +10 -0
  51. package/dist/index.js +334 -0
  52. package/dist/issues/initializers.d.ts +4 -0
  53. package/dist/issues/initializers.js +11 -0
  54. package/dist/manifest/helpers.d.ts +7 -0
  55. package/dist/manifest/helpers.js +16 -0
  56. package/dist/manifest/index.d.ts +16 -0
  57. package/dist/manifest/index.js +56 -0
  58. package/dist/plugins/_template/index.d.ts +9 -0
  59. package/dist/plugins/_template/index.js +14 -0
  60. package/dist/plugins/_template/types.d.ts +3 -0
  61. package/dist/plugins/_template/types.js +1 -0
  62. package/dist/plugins/angular/index.d.ts +6 -0
  63. package/dist/plugins/angular/index.js +36 -0
  64. package/dist/plugins/angular/types.d.ts +745 -0
  65. package/dist/plugins/angular/types.js +1 -0
  66. package/dist/plugins/ava/index.d.ts +7 -0
  67. package/dist/plugins/ava/index.js +20 -0
  68. package/dist/plugins/ava/types.d.ts +4 -0
  69. package/dist/plugins/ava/types.js +1 -0
  70. package/dist/plugins/babel/helpers.d.ts +15 -0
  71. package/dist/plugins/babel/helpers.js +34 -0
  72. package/dist/plugins/babel/index.d.ts +8 -0
  73. package/dist/plugins/babel/index.js +30 -0
  74. package/dist/plugins/babel/types.d.ts +9 -0
  75. package/dist/plugins/babel/types.js +1 -0
  76. package/dist/plugins/capacitor/index.d.ts +6 -0
  77. package/dist/plugins/capacitor/index.js +11 -0
  78. package/dist/plugins/capacitor/types.d.ts +3 -0
  79. package/dist/plugins/capacitor/types.js +1 -0
  80. package/dist/plugins/changesets/index.d.ts +6 -0
  81. package/dist/plugins/changesets/index.js +15 -0
  82. package/dist/plugins/commitizen/index.d.ts +6 -0
  83. package/dist/plugins/commitizen/index.js +14 -0
  84. package/dist/plugins/commitizen/types.d.ts +3 -0
  85. package/dist/plugins/commitizen/types.js +1 -0
  86. package/dist/plugins/commitlint/index.d.ts +6 -0
  87. package/dist/plugins/commitlint/index.js +18 -0
  88. package/dist/plugins/cspell/index.d.ts +6 -0
  89. package/dist/plugins/cspell/index.js +17 -0
  90. package/dist/plugins/cspell/types.d.ts +3 -0
  91. package/dist/plugins/cspell/types.js +1 -0
  92. package/dist/plugins/cypress/index.d.ts +5 -0
  93. package/dist/plugins/cypress/index.js +10 -0
  94. package/dist/plugins/eslint/fallback.d.ts +1 -0
  95. package/dist/plugins/eslint/fallback.js +13 -0
  96. package/dist/plugins/eslint/helpers.d.ts +14 -0
  97. package/dist/plugins/eslint/helpers.js +83 -0
  98. package/dist/plugins/eslint/index.d.ts +7 -0
  99. package/dist/plugins/eslint/index.js +15 -0
  100. package/dist/plugins/eslint/types.d.ts +27 -0
  101. package/dist/plugins/eslint/types.js +1 -0
  102. package/dist/plugins/gatsby/index.d.ts +7 -0
  103. package/dist/plugins/gatsby/index.js +30 -0
  104. package/dist/plugins/gatsby/types.d.ts +15 -0
  105. package/dist/plugins/gatsby/types.js +1 -0
  106. package/dist/plugins/github-actions/index.d.ts +6 -0
  107. package/dist/plugins/github-actions/index.js +21 -0
  108. package/dist/plugins/husky/index.d.ts +6 -0
  109. package/dist/plugins/husky/index.js +19 -0
  110. package/dist/plugins/index.d.ts +41 -0
  111. package/dist/plugins/index.js +41 -0
  112. package/dist/plugins/jest/index.d.ts +7 -0
  113. package/dist/plugins/jest/index.js +68 -0
  114. package/dist/plugins/lefthook/index.d.ts +6 -0
  115. package/dist/plugins/lefthook/index.js +28 -0
  116. package/dist/plugins/lint-staged/index.d.ts +6 -0
  117. package/dist/plugins/lint-staged/index.js +32 -0
  118. package/dist/plugins/lint-staged/types.d.ts +5 -0
  119. package/dist/plugins/lint-staged/types.js +1 -0
  120. package/dist/plugins/markdownlint/helpers.d.ts +1 -0
  121. package/dist/plugins/markdownlint/helpers.js +6 -0
  122. package/dist/plugins/markdownlint/index.d.ts +6 -0
  123. package/dist/plugins/markdownlint/index.js +19 -0
  124. package/dist/plugins/markdownlint/types.d.ts +3 -0
  125. package/dist/plugins/markdownlint/types.js +1 -0
  126. package/dist/plugins/mocha/index.d.ts +6 -0
  127. package/dist/plugins/mocha/index.js +15 -0
  128. package/dist/plugins/next/index.d.ts +6 -0
  129. package/dist/plugins/next/index.js +11 -0
  130. package/dist/plugins/npm-package-json-lint/index.d.ts +6 -0
  131. package/dist/plugins/npm-package-json-lint/index.js +13 -0
  132. package/dist/plugins/npm-package-json-lint/types.d.ts +3 -0
  133. package/dist/plugins/npm-package-json-lint/types.js +1 -0
  134. package/dist/plugins/nx/index.d.ts +6 -0
  135. package/dist/plugins/nx/index.js +24 -0
  136. package/dist/plugins/nx/types.d.ts +11 -0
  137. package/dist/plugins/nx/types.js +1 -0
  138. package/dist/plugins/nyc/index.d.ts +6 -0
  139. package/dist/plugins/nyc/index.js +11 -0
  140. package/dist/plugins/playwright/index.d.ts +5 -0
  141. package/dist/plugins/playwright/index.js +5 -0
  142. package/dist/plugins/postcss/index.d.ts +6 -0
  143. package/dist/plugins/postcss/index.js +23 -0
  144. package/dist/plugins/postcss/types.d.ts +3 -0
  145. package/dist/plugins/postcss/types.js +1 -0
  146. package/dist/plugins/prettier/index.d.ts +6 -0
  147. package/dist/plugins/prettier/index.js +20 -0
  148. package/dist/plugins/release-it/index.d.ts +6 -0
  149. package/dist/plugins/release-it/index.js +30 -0
  150. package/dist/plugins/release-it/types.d.ts +10 -0
  151. package/dist/plugins/release-it/types.js +1 -0
  152. package/dist/plugins/remark/index.d.ts +6 -0
  153. package/dist/plugins/remark/index.js +18 -0
  154. package/dist/plugins/remix/index.d.ts +6 -0
  155. package/dist/plugins/remix/index.js +11 -0
  156. package/dist/plugins/rollup/index.d.ts +5 -0
  157. package/dist/plugins/rollup/index.js +5 -0
  158. package/dist/plugins/semantic-release/index.d.ts +6 -0
  159. package/dist/plugins/semantic-release/index.js +17 -0
  160. package/dist/plugins/semantic-release/types.d.ts +3 -0
  161. package/dist/plugins/semantic-release/types.js +1 -0
  162. package/dist/plugins/sentry/index.d.ts +5 -0
  163. package/dist/plugins/sentry/index.js +5 -0
  164. package/dist/plugins/storybook/index.d.ts +8 -0
  165. package/dist/plugins/storybook/index.js +19 -0
  166. package/dist/plugins/storybook/types.d.ts +11 -0
  167. package/dist/plugins/storybook/types.js +1 -0
  168. package/dist/plugins/stryker/index.d.ts +6 -0
  169. package/dist/plugins/stryker/index.js +17 -0
  170. package/dist/plugins/stryker/types.d.ts +5 -0
  171. package/dist/plugins/stryker/types.js +1 -0
  172. package/dist/plugins/stylelint/index.d.ts +6 -0
  173. package/dist/plugins/stylelint/index.js +22 -0
  174. package/dist/plugins/stylelint/types.d.ts +4 -0
  175. package/dist/plugins/stylelint/types.js +1 -0
  176. package/dist/plugins/svelte/index.d.ts +7 -0
  177. package/dist/plugins/svelte/index.js +9 -0
  178. package/dist/plugins/tailwind/index.d.ts +5 -0
  179. package/dist/plugins/tailwind/index.js +5 -0
  180. package/dist/plugins/typedoc/index.d.ts +6 -0
  181. package/dist/plugins/typedoc/index.js +22 -0
  182. package/dist/plugins/typedoc/types.d.ts +3 -0
  183. package/dist/plugins/typedoc/types.js +1 -0
  184. package/dist/plugins/typescript/index.d.ts +7 -0
  185. package/dist/plugins/typescript/index.js +42 -0
  186. package/dist/plugins/vite/index.d.ts +6 -0
  187. package/dist/plugins/vite/index.js +12 -0
  188. package/dist/plugins/vite/types.d.ts +4 -0
  189. package/dist/plugins/vite/types.js +1 -0
  190. package/dist/plugins/vitest/helpers.d.ts +6 -0
  191. package/dist/plugins/vitest/helpers.js +22 -0
  192. package/dist/plugins/vitest/index.d.ts +9 -0
  193. package/dist/plugins/vitest/index.js +25 -0
  194. package/dist/plugins/vitest/types.d.ts +11 -0
  195. package/dist/plugins/vitest/types.js +1 -0
  196. package/dist/plugins/webpack/index.d.ts +6 -0
  197. package/dist/plugins/webpack/index.js +82 -0
  198. package/dist/plugins/webpack/types.d.ts +10 -0
  199. package/dist/plugins/webpack/types.js +1 -0
  200. package/dist/reporters/codeowners.d.ts +3 -0
  201. package/dist/reporters/codeowners.js +62 -0
  202. package/dist/reporters/compact.d.ts +3 -0
  203. package/dist/reporters/compact.js +36 -0
  204. package/dist/reporters/index.d.ts +7 -0
  205. package/dist/reporters/index.js +10 -0
  206. package/dist/reporters/json.d.ts +3 -0
  207. package/dist/reporters/json.js +67 -0
  208. package/dist/reporters/symbols.d.ts +3 -0
  209. package/dist/reporters/symbols.js +54 -0
  210. package/dist/reporters/util.d.ts +15 -0
  211. package/dist/reporters/util.js +17 -0
  212. package/dist/types/cli.d.ts +10 -0
  213. package/dist/types/cli.js +1 -0
  214. package/dist/types/compilers.d.ts +6 -0
  215. package/dist/types/compilers.js +1 -0
  216. package/dist/types/config.d.ts +39 -0
  217. package/dist/types/config.js +3 -0
  218. package/dist/types/exports.d.ts +20 -0
  219. package/dist/types/exports.js +1 -0
  220. package/dist/types/imports.d.ts +13 -0
  221. package/dist/types/imports.js +1 -0
  222. package/dist/types/issues.d.ts +62 -0
  223. package/dist/types/issues.js +10 -0
  224. package/dist/types/plugins.d.ts +19 -0
  225. package/dist/types/plugins.js +1 -0
  226. package/dist/types/workspace.d.ts +17 -0
  227. package/dist/types/workspace.js +1 -0
  228. package/dist/typescript/SourceFile.d.ts +18 -0
  229. package/dist/typescript/SourceFile.js +1 -0
  230. package/dist/typescript/SourceFileManager.d.ts +13 -0
  231. package/dist/typescript/SourceFileManager.js +57 -0
  232. package/dist/typescript/ast-helpers.d.ts +27 -0
  233. package/dist/typescript/ast-helpers.js +101 -0
  234. package/dist/typescript/createHosts.d.ts +15 -0
  235. package/dist/typescript/createHosts.js +39 -0
  236. package/dist/typescript/getImportsAndExports.d.ts +29 -0
  237. package/dist/typescript/getImportsAndExports.js +159 -0
  238. package/dist/typescript/resolveModuleNames.d.ts +2 -0
  239. package/dist/typescript/resolveModuleNames.js +27 -0
  240. package/dist/typescript/sys.d.ts +35 -0
  241. package/dist/typescript/sys.js +16 -0
  242. package/dist/typescript/utils.d.ts +2 -0
  243. package/dist/typescript/utils.js +9 -0
  244. package/dist/typescript/visitors/exports/exportAssignment.d.ts +3 -0
  245. package/dist/typescript/visitors/exports/exportAssignment.js +9 -0
  246. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +3 -0
  247. package/dist/typescript/visitors/exports/exportDeclaration.js +13 -0
  248. package/dist/typescript/visitors/exports/exportKeyword.d.ts +3 -0
  249. package/dist/typescript/visitors/exports/exportKeyword.js +77 -0
  250. package/dist/typescript/visitors/exports/index.d.ts +3 -0
  251. package/dist/typescript/visitors/exports/index.js +7 -0
  252. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +3 -0
  253. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +31 -0
  254. package/dist/typescript/visitors/helpers.d.ts +4 -0
  255. package/dist/typescript/visitors/helpers.js +10 -0
  256. package/dist/typescript/visitors/imports/importCall.d.ts +3 -0
  257. package/dist/typescript/visitors/imports/importCall.js +11 -0
  258. package/dist/typescript/visitors/imports/importDeclaration.d.ts +3 -0
  259. package/dist/typescript/visitors/imports/importDeclaration.js +32 -0
  260. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +3 -0
  261. package/dist/typescript/visitors/imports/importEqualsDeclaration.js +11 -0
  262. package/dist/typescript/visitors/imports/index.d.ts +3 -0
  263. package/dist/typescript/visitors/imports/index.js +18 -0
  264. package/dist/typescript/visitors/imports/jsDocType.d.ts +3 -0
  265. package/dist/typescript/visitors/imports/jsDocType.js +11 -0
  266. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +3 -0
  267. package/dist/typescript/visitors/imports/reExportDeclaration.js +21 -0
  268. package/dist/typescript/visitors/imports/requireCall.d.ts +3 -0
  269. package/dist/typescript/visitors/imports/requireCall.js +45 -0
  270. package/dist/typescript/visitors/imports/requireResolveCall.d.ts +3 -0
  271. package/dist/typescript/visitors/imports/requireResolveCall.js +12 -0
  272. package/dist/typescript/visitors/index.d.ts +10 -0
  273. package/dist/typescript/visitors/index.js +16 -0
  274. package/dist/typescript/visitors/scripts/execa.d.ts +3 -0
  275. package/dist/typescript/visitors/scripts/execa.js +18 -0
  276. package/dist/typescript/visitors/scripts/index.d.ts +3 -0
  277. package/dist/typescript/visitors/scripts/index.js +5 -0
  278. package/dist/typescript/visitors/scripts/zx.d.ts +3 -0
  279. package/dist/typescript/visitors/scripts/zx.js +8 -0
  280. package/dist/util/Performance.d.ts +23 -0
  281. package/dist/util/Performance.js +80 -0
  282. package/dist/util/array.d.ts +2 -0
  283. package/dist/util/array.js +2 -0
  284. package/dist/util/cli-arguments.d.ts +28 -0
  285. package/dist/util/cli-arguments.js +83 -0
  286. package/dist/util/compilers.d.ts +426 -0
  287. package/dist/util/compilers.js +20 -0
  288. package/dist/util/debug.d.ts +3 -0
  289. package/dist/util/debug.js +34 -0
  290. package/dist/util/errors.d.ts +12 -0
  291. package/dist/util/errors.js +14 -0
  292. package/dist/util/fs.d.ts +7 -0
  293. package/dist/util/fs.js +42 -0
  294. package/dist/util/get-included-issue-types.d.ts +16 -0
  295. package/dist/util/get-included-issue-types.js +37 -0
  296. package/dist/util/git.d.ts +1 -0
  297. package/dist/util/git.js +20 -0
  298. package/dist/util/glob.d.ts +19 -0
  299. package/dist/util/glob.js +59 -0
  300. package/dist/util/loader.d.ts +1 -0
  301. package/dist/util/loader.js +31 -0
  302. package/dist/util/map.d.ts +1 -0
  303. package/dist/util/map.js +6 -0
  304. package/dist/util/modules.d.ts +8 -0
  305. package/dist/util/modules.js +52 -0
  306. package/dist/util/object.d.ts +3 -0
  307. package/dist/util/object.js +37 -0
  308. package/dist/util/path.d.ts +11 -0
  309. package/dist/util/path.js +13 -0
  310. package/dist/util/plugin.d.ts +3 -0
  311. package/dist/util/plugin.js +14 -0
  312. package/dist/util/register.d.ts +1 -0
  313. package/dist/util/register.js +14 -0
  314. package/dist/util/reporter.d.ts +3 -0
  315. package/dist/util/reporter.js +16 -0
  316. package/dist/util/require.d.ts +5 -0
  317. package/dist/util/require.js +34 -0
  318. package/dist/util/tsconfig-loader.d.ts +2 -0
  319. package/dist/util/tsconfig-loader.js +11 -0
  320. package/dist/util/workspace.d.ts +1 -0
  321. package/dist/util/workspace.js +11 -0
  322. package/dist/version.d.ts +1 -0
  323. package/dist/version.js +1 -0
  324. package/license +12 -0
  325. package/package.json +150 -0
  326. package/schema.json +403 -0
@@ -0,0 +1,64 @@
1
+ import { isGitIgnoredSync } from 'globby';
2
+ import ts from 'typescript';
3
+ import { SourceFileManager } from './typescript/SourceFileManager.js';
4
+ import type { SyncCompilers, AsyncCompilers } from './types/compilers.js';
5
+ import type { ExportItem, ExportItemMember } from './types/exports.js';
6
+ type ProjectPrincipalOptions = {
7
+ compilerOptions: ts.CompilerOptions;
8
+ cwd: string;
9
+ compilers: [SyncCompilers, AsyncCompilers];
10
+ };
11
+ export declare class ProjectPrincipal {
12
+ entryPaths: Set<string>;
13
+ projectPaths: Set<string>;
14
+ skipExportsAnalysis: Set<string>;
15
+ isGitIgnored: ReturnType<typeof isGitIgnoredSync>;
16
+ cwd: string;
17
+ compilerOptions: ts.CompilerOptions;
18
+ extensions: Set<string>;
19
+ syncCompilers: SyncCompilers;
20
+ asyncCompilers: AsyncCompilers;
21
+ backend: {
22
+ fileManager: SourceFileManager;
23
+ compilerHost: ts.CompilerHost;
24
+ languageServiceHost: ts.LanguageServiceHost;
25
+ lsFindReferences: ts.LanguageService['findReferences'];
26
+ program?: ts.Program;
27
+ };
28
+ constructor({ compilerOptions, cwd, compilers }: ProjectPrincipalOptions);
29
+ private createProgram;
30
+ private hasAcceptedExtension;
31
+ addEntryPath(filePath: string, options?: {
32
+ skipExportsAnalysis: boolean;
33
+ }): void;
34
+ addEntryPaths(filePaths: Set<string> | string[], options?: {
35
+ skipExportsAnalysis: boolean;
36
+ }): void;
37
+ addProjectPath(filePath: string): void;
38
+ runAsyncCompilers(): Promise<void>;
39
+ getUsedResolvedFiles(): string[];
40
+ private getProgramSourceFiles;
41
+ getUnreferencedFiles(): string[];
42
+ analyzeSourceFile(filePath: string, { skipTypeOnly }: {
43
+ skipTypeOnly: boolean;
44
+ }): {
45
+ imports: {
46
+ internal: import("./types/imports.js").Imports;
47
+ unresolved: Set<string>;
48
+ external: Set<string>;
49
+ };
50
+ exports: {
51
+ exported: import("./types/exports.js").ExportItems;
52
+ duplicate: string[][];
53
+ };
54
+ scripts: Set<string>;
55
+ };
56
+ private resolveModule;
57
+ getHasReferences(filePath: string, exportedItem: ExportItem): {
58
+ external: boolean;
59
+ internal: boolean;
60
+ };
61
+ findUnusedMembers(filePath: string, members: ExportItemMember[]): string[];
62
+ private findReferences;
63
+ }
64
+ export {};
@@ -0,0 +1,197 @@
1
+ import { isGitIgnoredSync } from 'globby';
2
+ import ts from 'typescript';
3
+ import { DEFAULT_EXTENSIONS } from './constants.js';
4
+ import { IGNORED_FILE_EXTENSIONS } from './constants.js';
5
+ import { getJSDocTags, isInModuleBlock } from './typescript/ast-helpers.js';
6
+ import { createHosts } from './typescript/createHosts.js';
7
+ import { getImportsAndExports } from './typescript/getImportsAndExports.js';
8
+ import { SourceFileManager } from './typescript/SourceFileManager.js';
9
+ import { isMaybePackageName } from './util/modules.js';
10
+ import { dirname, extname, isInNodeModules, join } from './util/path.js';
11
+ import { timerify } from './util/Performance.js';
12
+ const baseCompilerOptions = {
13
+ allowJs: true,
14
+ jsx: ts.JsxEmit.Preserve,
15
+ jsxImportSource: undefined,
16
+ allowSyntheticDefaultImports: true,
17
+ esModuleInterop: true,
18
+ skipDefaultLibCheck: true,
19
+ skipLibCheck: true,
20
+ lib: [],
21
+ target: ts.ScriptTarget.Latest,
22
+ module: ts.ModuleKind.CommonJS,
23
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
24
+ };
25
+ const tsCreateProgram = timerify(ts.createProgram);
26
+ export class ProjectPrincipal {
27
+ entryPaths = new Set();
28
+ projectPaths = new Set();
29
+ skipExportsAnalysis = new Set();
30
+ isGitIgnored;
31
+ cwd;
32
+ compilerOptions;
33
+ extensions;
34
+ syncCompilers;
35
+ asyncCompilers;
36
+ backend;
37
+ constructor({ compilerOptions, cwd, compilers }) {
38
+ this.cwd = cwd;
39
+ this.isGitIgnored = isGitIgnoredSync({ cwd });
40
+ this.compilerOptions = {
41
+ ...compilerOptions,
42
+ ...baseCompilerOptions,
43
+ allowNonTsExtensions: [...compilers].flat().length > 0,
44
+ };
45
+ const [syncCompilers, asyncCompilers] = compilers;
46
+ this.extensions = new Set([...DEFAULT_EXTENSIONS, ...syncCompilers.keys(), ...asyncCompilers.keys()]);
47
+ this.syncCompilers = syncCompilers;
48
+ this.asyncCompilers = asyncCompilers;
49
+ const { fileManager, compilerHost, languageServiceHost } = createHosts({
50
+ cwd: this.cwd,
51
+ compilerOptions: this.compilerOptions,
52
+ entryPaths: this.entryPaths,
53
+ compilers: [this.syncCompilers, this.asyncCompilers],
54
+ });
55
+ const languageService = ts.createLanguageService(languageServiceHost, ts.createDocumentRegistry());
56
+ const lsFindReferences = timerify(languageService?.findReferences);
57
+ this.backend = {
58
+ fileManager,
59
+ compilerHost,
60
+ languageServiceHost,
61
+ lsFindReferences,
62
+ };
63
+ }
64
+ createProgram() {
65
+ this.backend.program = tsCreateProgram(Array.from(this.entryPaths), this.compilerOptions, this.backend.compilerHost, this.backend.program);
66
+ const typeChecker = timerify(this.backend.program.getTypeChecker);
67
+ typeChecker();
68
+ }
69
+ hasAcceptedExtension(filePath) {
70
+ return this.extensions.has(extname(filePath));
71
+ }
72
+ addEntryPath(filePath, options) {
73
+ if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
74
+ this.entryPaths.add(filePath);
75
+ this.projectPaths.add(filePath);
76
+ if (options?.skipExportsAnalysis)
77
+ this.skipExportsAnalysis.add(filePath);
78
+ }
79
+ }
80
+ addEntryPaths(filePaths, options) {
81
+ filePaths.forEach(filePath => this.addEntryPath(filePath, options));
82
+ }
83
+ addProjectPath(filePath) {
84
+ if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
85
+ this.projectPaths.add(filePath);
86
+ }
87
+ }
88
+ async runAsyncCompilers() {
89
+ const add = timerify(this.backend.fileManager.compileAndAddSourceFile.bind(this.backend.fileManager));
90
+ const extensions = Array.from(this.asyncCompilers.keys());
91
+ const files = Array.from(this.projectPaths).filter(filePath => extensions.includes(extname(filePath)));
92
+ for (const filePath of files) {
93
+ await add(filePath);
94
+ }
95
+ }
96
+ getUsedResolvedFiles() {
97
+ this.createProgram();
98
+ const sourceFiles = this.getProgramSourceFiles();
99
+ return Array.from(this.projectPaths).filter(filePath => sourceFiles.has(filePath));
100
+ }
101
+ getProgramSourceFiles() {
102
+ const programSourceFiles = this.backend.program?.getSourceFiles().map(sourceFile => sourceFile.fileName);
103
+ return new Set(programSourceFiles);
104
+ }
105
+ getUnreferencedFiles() {
106
+ const sourceFiles = this.getProgramSourceFiles();
107
+ return Array.from(this.projectPaths).filter(filePath => !sourceFiles.has(filePath));
108
+ }
109
+ analyzeSourceFile(filePath, { skipTypeOnly }) {
110
+ const sourceFile = this.backend.program?.getSourceFile(filePath);
111
+ if (!sourceFile)
112
+ throw new Error(`Unable to find ${filePath}`);
113
+ const skipExports = this.skipExportsAnalysis.has(filePath);
114
+ const { imports, exports, scripts } = getImportsAndExports(sourceFile, { skipTypeOnly, skipExports });
115
+ const { internal, unresolved, external } = imports;
116
+ const unresolvedImports = new Set();
117
+ unresolved.forEach(specifier => {
118
+ if (specifier.startsWith('http')) {
119
+ return;
120
+ }
121
+ const resolvedModule = this.resolveModule(specifier, filePath);
122
+ if (resolvedModule) {
123
+ if (resolvedModule.isExternalLibraryImport) {
124
+ external.add(specifier);
125
+ }
126
+ else {
127
+ this.addEntryPath(resolvedModule.resolvedFileName, { skipExportsAnalysis: true });
128
+ }
129
+ }
130
+ else {
131
+ const sanitizedSpecifier = specifier.replace(/^([?!|-]+)?([^!?]+).*/, '$2');
132
+ if (isMaybePackageName(sanitizedSpecifier)) {
133
+ external.add(sanitizedSpecifier);
134
+ }
135
+ else {
136
+ const isIgnored = this.isGitIgnored(join(dirname(filePath), sanitizedSpecifier));
137
+ if (!isIgnored) {
138
+ const ext = extname(sanitizedSpecifier);
139
+ if (!ext || (ext !== '.json' && !IGNORED_FILE_EXTENSIONS.includes(ext))) {
140
+ unresolvedImports.add(specifier);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ });
146
+ return {
147
+ imports: {
148
+ internal,
149
+ unresolved: unresolvedImports,
150
+ external,
151
+ },
152
+ exports,
153
+ scripts,
154
+ };
155
+ }
156
+ resolveModule(specifier, filePath = specifier) {
157
+ const module = ts.resolveModuleName(specifier, filePath, this.compilerOptions, this.backend.languageServiceHost);
158
+ return module?.resolvedModule;
159
+ }
160
+ getHasReferences(filePath, exportedItem) {
161
+ const hasReferences = { external: false, internal: false };
162
+ const symbolReferences = this.findReferences(filePath, exportedItem.pos).flatMap(f => f.references);
163
+ for (const reference of symbolReferences) {
164
+ if (reference.fileName === filePath) {
165
+ if (!reference.isDefinition) {
166
+ hasReferences.internal = true;
167
+ }
168
+ }
169
+ else {
170
+ hasReferences.external = true;
171
+ }
172
+ }
173
+ if (!hasReferences.external && hasReferences.internal) {
174
+ hasReferences.external = isInModuleBlock(exportedItem.node);
175
+ }
176
+ return hasReferences;
177
+ }
178
+ findUnusedMembers(filePath, members) {
179
+ return members
180
+ .filter(member => {
181
+ if (getJSDocTags(member.node).includes('@public'))
182
+ return false;
183
+ const referencedSymbols = this.findReferences(filePath, member.pos);
184
+ const files = referencedSymbols
185
+ .flatMap(refs => refs.references)
186
+ .filter(ref => !ref.isDefinition)
187
+ .map(ref => ref.fileName);
188
+ const internalRefs = files.filter(f => f === filePath);
189
+ const externalRefs = files.filter(f => f !== filePath);
190
+ return externalRefs.length === 0 && internalRefs.length === 0;
191
+ })
192
+ .map(member => member.identifier);
193
+ }
194
+ findReferences(filePath, pos) {
195
+ return this.backend.lsFindReferences(filePath, pos) ?? [];
196
+ }
197
+ }
@@ -0,0 +1,56 @@
1
+ import type { Configuration, PluginName, WorkspaceConfiguration } from './types/config.js';
2
+ import type { PackageJsonWithPlugins } from './types/plugins.js';
3
+ import type { InstalledBinaries, PeerDependencies } from './types/workspace.js';
4
+ type WorkspaceManagerOptions = {
5
+ name: string;
6
+ dir: string;
7
+ cwd: string;
8
+ config: WorkspaceConfiguration;
9
+ manifest: PackageJsonWithPlugins;
10
+ rootIgnore: Configuration['ignore'];
11
+ negatedWorkspacePatterns: string[];
12
+ enabledPluginsInAncestors: string[];
13
+ isProduction: boolean;
14
+ isStrict: boolean;
15
+ };
16
+ type ReferencedDependencies = Set<[string, string]>;
17
+ export declare class WorkspaceWorker {
18
+ name: string;
19
+ dir: string;
20
+ cwd: string;
21
+ config: WorkspaceConfiguration;
22
+ manifest: PackageJsonWithPlugins;
23
+ isProduction: boolean;
24
+ isStrict: boolean;
25
+ rootIgnore: Configuration['ignore'];
26
+ negatedWorkspacePatterns: string[];
27
+ enabledPluginsInAncestors: string[];
28
+ enabled: Record<PluginName, boolean>;
29
+ enabledPlugins: PluginName[];
30
+ referencedDependencies: ReferencedDependencies;
31
+ peerDependencies: PeerDependencies;
32
+ installedBinaries: InstalledBinaries;
33
+ constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
34
+ init(): Promise<void>;
35
+ private setEnabledPlugins;
36
+ private initReferencedDependencies;
37
+ private getConfigForPlugin;
38
+ getEntryFilePatterns(): string[];
39
+ getProjectFilePatterns(): string[];
40
+ getPluginEntryFilePatterns(isIncludeProductionEntryFiles?: boolean): string[];
41
+ getPluginProjectFilePatterns(): string[];
42
+ getPluginConfigPatterns(): string[];
43
+ getProductionEntryFilePatterns(): string[];
44
+ getProductionProjectFilePatterns(): string[];
45
+ getProductionPluginEntryFilePatterns(): string[];
46
+ private getConfigurationFilePatterns;
47
+ getIgnorePatterns(): string[];
48
+ private findDependenciesByPlugins;
49
+ findAllDependencies(): Promise<{
50
+ peerDependencies: PeerDependencies;
51
+ installedBinaries: InstalledBinaries;
52
+ referencedDependencies: ReferencedDependencies;
53
+ enabledPlugins: ("angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
54
+ }>;
55
+ }
56
+ export {};
@@ -0,0 +1,244 @@
1
+ import { TEST_FILE_PATTERNS } from './constants.js';
2
+ import * as npm from './manifest/index.js';
3
+ import * as plugins from './plugins/index.js';
4
+ import { debugLogArray, debugLogObject } from './util/debug.js';
5
+ import { _pureGlob, negate, hasProductionSuffix, hasNoProductionSuffix, prependDirToPattern } from './util/glob.js';
6
+ import { getKeysByValue } from './util/object.js';
7
+ import { join, toPosix } from './util/path.js';
8
+ const negatedTestFilePatterns = TEST_FILE_PATTERNS.map(negate);
9
+ export class WorkspaceWorker {
10
+ name;
11
+ dir;
12
+ cwd;
13
+ config;
14
+ manifest;
15
+ isProduction;
16
+ isStrict;
17
+ rootIgnore;
18
+ negatedWorkspacePatterns = [];
19
+ enabledPluginsInAncestors;
20
+ enabled;
21
+ enabledPlugins = [];
22
+ referencedDependencies = new Set();
23
+ peerDependencies = new Map();
24
+ installedBinaries = new Map();
25
+ constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
26
+ this.name = name;
27
+ this.dir = dir;
28
+ this.cwd = cwd;
29
+ this.config = config;
30
+ this.manifest = manifest;
31
+ this.isProduction = isProduction;
32
+ this.isStrict = isStrict;
33
+ this.rootIgnore = rootIgnore;
34
+ this.negatedWorkspacePatterns = negatedWorkspacePatterns;
35
+ this.enabledPluginsInAncestors = enabledPluginsInAncestors;
36
+ this.enabled = Object.keys(plugins).reduce((enabled, pluginName) => ({ ...enabled, [pluginName]: false }), {});
37
+ }
38
+ async init() {
39
+ await this.setEnabledPlugins();
40
+ await this.initReferencedDependencies();
41
+ }
42
+ async setEnabledPlugins() {
43
+ const manifest = this.manifest;
44
+ const deps = Object.keys(manifest.dependencies ?? {});
45
+ const devDeps = Object.keys(manifest.devDependencies ?? {});
46
+ const dependencies = new Set([...deps, ...devDeps]);
47
+ const pluginEntries = Object.entries(plugins);
48
+ for (const [pluginName, plugin] of pluginEntries) {
49
+ if (this.config[pluginName] === false)
50
+ continue;
51
+ const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
52
+ if (isEnabledInAncestor ||
53
+ (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies, config: this.config }))) {
54
+ this.enabled[pluginName] = true;
55
+ }
56
+ }
57
+ this.enabledPlugins = getKeysByValue(this.enabled, true);
58
+ const enabledPluginNames = this.enabledPlugins.map(name => plugins[name].NAME);
59
+ debugLogObject(`Enabled plugins (${this.name})`, enabledPluginNames);
60
+ }
61
+ async initReferencedDependencies() {
62
+ const { dependencies, peerDependencies, installedBinaries } = await npm.findDependencies({
63
+ manifest: this.manifest,
64
+ isProduction: this.isProduction,
65
+ isStrict: this.isStrict,
66
+ dir: this.dir,
67
+ cwd: this.cwd,
68
+ });
69
+ const filePath = join(this.dir, 'package.json');
70
+ dependencies.forEach(dependency => this.referencedDependencies.add([filePath, dependency]));
71
+ this.peerDependencies = peerDependencies;
72
+ this.installedBinaries = installedBinaries;
73
+ }
74
+ getConfigForPlugin(pluginName) {
75
+ return this.config[pluginName] ?? { config: null, entry: null, project: null };
76
+ }
77
+ getEntryFilePatterns() {
78
+ const { entry } = this.config;
79
+ if (entry.length === 0)
80
+ return [];
81
+ return [entry, TEST_FILE_PATTERNS, this.negatedWorkspacePatterns].flat();
82
+ }
83
+ getProjectFilePatterns() {
84
+ const { project } = this.config;
85
+ if (project.length === 0)
86
+ return [];
87
+ const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
88
+ const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
89
+ const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
90
+ return [
91
+ project,
92
+ negatedPluginConfigPatterns,
93
+ negatedPluginEntryFilePatterns,
94
+ negatedPluginProjectFilePatterns,
95
+ TEST_FILE_PATTERNS,
96
+ this.negatedWorkspacePatterns,
97
+ ].flat();
98
+ }
99
+ getPluginEntryFilePatterns(isIncludeProductionEntryFiles = true) {
100
+ const patterns = [];
101
+ for (const [pluginName, plugin] of Object.entries(plugins)) {
102
+ const pluginConfig = this.getConfigForPlugin(pluginName);
103
+ if (this.enabled[pluginName] && pluginConfig) {
104
+ const { entry } = pluginConfig;
105
+ const defaultEntryFiles = 'ENTRY_FILE_PATTERNS' in plugin ? plugin.ENTRY_FILE_PATTERNS : [];
106
+ patterns.push(...(entry ?? defaultEntryFiles));
107
+ if (isIncludeProductionEntryFiles) {
108
+ const entry = 'PRODUCTION_ENTRY_FILE_PATTERNS' in plugin ? plugin.PRODUCTION_ENTRY_FILE_PATTERNS : [];
109
+ patterns.push(...entry);
110
+ }
111
+ }
112
+ }
113
+ return [patterns, this.negatedWorkspacePatterns].flat();
114
+ }
115
+ getPluginProjectFilePatterns() {
116
+ const patterns = [];
117
+ for (const [pluginName, plugin] of Object.entries(plugins)) {
118
+ const pluginConfig = this.getConfigForPlugin(pluginName);
119
+ if (this.enabled[pluginName] && pluginConfig) {
120
+ const { entry, project } = pluginConfig;
121
+ patterns.push(...(project ??
122
+ entry ??
123
+ ('PROJECT_FILE_PATTERNS' in plugin
124
+ ? plugin.PROJECT_FILE_PATTERNS
125
+ : 'ENTRY_FILE_PATTERNS' in plugin
126
+ ? plugin.ENTRY_FILE_PATTERNS
127
+ : [])));
128
+ }
129
+ }
130
+ return [patterns, this.negatedWorkspacePatterns].flat();
131
+ }
132
+ getPluginConfigPatterns() {
133
+ const patterns = [];
134
+ for (const [pluginName, plugin] of Object.entries(plugins)) {
135
+ const pluginConfig = this.getConfigForPlugin(pluginName);
136
+ if (this.enabled[pluginName] && pluginConfig) {
137
+ const { config } = pluginConfig;
138
+ const defaultConfigFiles = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
139
+ patterns.push(...(config ?? defaultConfigFiles));
140
+ }
141
+ }
142
+ return patterns;
143
+ }
144
+ getProductionEntryFilePatterns() {
145
+ const entry = this.config.entry.filter(hasProductionSuffix);
146
+ if (entry.length === 0)
147
+ return [];
148
+ const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
149
+ return [entry, negatedEntryFiles, negatedTestFilePatterns, this.negatedWorkspacePatterns].flat();
150
+ }
151
+ getProductionProjectFilePatterns() {
152
+ const project = this.config.project;
153
+ if (project.length === 0)
154
+ return this.getProductionEntryFilePatterns();
155
+ const _project = this.config.project.map(pattern => {
156
+ if (!pattern.endsWith('!') && !pattern.startsWith('!'))
157
+ return negate(pattern);
158
+ return pattern;
159
+ });
160
+ const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
161
+ const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
162
+ const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
163
+ const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
164
+ return [
165
+ _project,
166
+ negatedEntryFiles,
167
+ negatedPluginConfigPatterns,
168
+ negatedPluginEntryFilePatterns,
169
+ negatedPluginProjectFilePatterns,
170
+ negatedTestFilePatterns,
171
+ this.negatedWorkspacePatterns,
172
+ ].flat();
173
+ }
174
+ getProductionPluginEntryFilePatterns() {
175
+ const patterns = [];
176
+ for (const [pluginName, plugin] of Object.entries(plugins)) {
177
+ const pluginConfig = this.getConfigForPlugin(pluginName);
178
+ if (this.enabled[pluginName] && pluginConfig) {
179
+ if ('PRODUCTION_ENTRY_FILE_PATTERNS' in plugin) {
180
+ patterns.push(...(pluginConfig.entry ?? plugin.PRODUCTION_ENTRY_FILE_PATTERNS));
181
+ }
182
+ }
183
+ }
184
+ if (patterns.length === 0)
185
+ return [];
186
+ return [patterns.flat(), negatedTestFilePatterns].flat();
187
+ }
188
+ getConfigurationFilePatterns(pluginName) {
189
+ const plugin = plugins[pluginName];
190
+ const pluginConfig = this.getConfigForPlugin(pluginName);
191
+ if (pluginConfig) {
192
+ const defaultConfig = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
193
+ return pluginConfig.config ?? defaultConfig;
194
+ }
195
+ return [];
196
+ }
197
+ getIgnorePatterns() {
198
+ return [...this.rootIgnore, ...this.config.ignore.map(pattern => prependDirToPattern(this.name, pattern))];
199
+ }
200
+ async findDependenciesByPlugins() {
201
+ const cwd = this.dir;
202
+ const ignore = this.getIgnorePatterns();
203
+ for (const [pluginName, plugin] of Object.entries(plugins)) {
204
+ const isIncludePlugin = this.isProduction ? `PRODUCTION_ENTRY_FILE_PATTERNS` in plugin : true;
205
+ if (this.enabled[pluginName] && isIncludePlugin) {
206
+ const hasDependencyFinder = 'findDependencies' in plugin && typeof plugin.findDependencies === 'function';
207
+ if (hasDependencyFinder) {
208
+ const pluginConfig = this.getConfigForPlugin(pluginName);
209
+ if (!pluginConfig)
210
+ continue;
211
+ const patterns = this.getConfigurationFilePatterns(pluginName);
212
+ const configFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
213
+ debugLogArray(`Found ${plugin.NAME} config file paths`, configFilePaths);
214
+ if (configFilePaths.length === 0)
215
+ continue;
216
+ const pluginDependencies = new Set();
217
+ for (const configFilePath of configFilePaths) {
218
+ const dependencies = await plugin.findDependencies(configFilePath, {
219
+ cwd,
220
+ manifest: this.manifest,
221
+ config: pluginConfig,
222
+ isProduction: this.isProduction,
223
+ });
224
+ dependencies.map(toPosix).forEach(specifier => {
225
+ pluginDependencies.add(specifier);
226
+ this.referencedDependencies.add([configFilePath, specifier]);
227
+ });
228
+ dependencies.forEach(dependency => pluginDependencies.add(dependency));
229
+ }
230
+ debugLogArray(`Dependencies referenced in ${plugin.NAME}`, pluginDependencies);
231
+ }
232
+ }
233
+ }
234
+ }
235
+ async findAllDependencies() {
236
+ await this.findDependenciesByPlugins();
237
+ return {
238
+ peerDependencies: this.peerDependencies,
239
+ installedBinaries: this.installedBinaries,
240
+ referencedDependencies: this.referencedDependencies,
241
+ enabledPlugins: this.enabledPlugins,
242
+ };
243
+ }
244
+ }
@@ -0,0 +1,6 @@
1
+ import type { PackageJson } from '@npmcli/package-json';
2
+ export declare const getBinariesFromScript: (script: string, { cwd, manifest, knownGlobalsOnly }: {
3
+ cwd: string;
4
+ manifest: PackageJson;
5
+ knownGlobalsOnly?: boolean | undefined;
6
+ }) => string[];
@@ -0,0 +1,58 @@
1
+ import parse from '@ericcornelissen/bash-parser';
2
+ import { debugLogObject } from '../util/debug.js';
3
+ import * as FallbackResolver from './resolvers/fallback.js';
4
+ import * as KnownResolvers from './resolvers/index.js';
5
+ import { stripBinaryPath } from './util.js';
6
+ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly = false }) => {
7
+ if (!script)
8
+ return [];
9
+ const fromArgs = (args) => getBinariesFromScript(args.filter(arg => arg !== '--').join(' '), { cwd, manifest });
10
+ const getBinariesFromNodes = (nodes) => nodes.flatMap(node => {
11
+ switch (node.type) {
12
+ case 'Command': {
13
+ const binary = node.name?.text ? stripBinaryPath(node.name.text) : node.name?.text;
14
+ const commandExpansions = node.prefix?.flatMap(prefix => prefix.expansion?.filter(expansion => expansion.type === 'CommandExpansion') ?? []) ?? [];
15
+ if (commandExpansions.length > 0) {
16
+ return commandExpansions.flatMap(expansion => getBinariesFromNodes(expansion.commandAST.commands)) ?? [];
17
+ }
18
+ if (!binary || binary === '.' || binary === 'source' || binary === '[')
19
+ return [];
20
+ if (binary.startsWith('-') || binary.startsWith('"') || binary.startsWith('..'))
21
+ return [];
22
+ if (['bun', 'deno'].includes(binary))
23
+ return [];
24
+ const args = node.suffix?.map(arg => arg.text) ?? [];
25
+ if (['!', 'test'].includes(binary))
26
+ return fromArgs(args);
27
+ if (binary in KnownResolvers) {
28
+ return KnownResolvers[binary].resolve(binary, args, { cwd, manifest, fromArgs });
29
+ }
30
+ if (knownGlobalsOnly)
31
+ return [];
32
+ return FallbackResolver.resolve(binary, args, { cwd, manifest, fromArgs });
33
+ }
34
+ case 'LogicalExpression':
35
+ return getBinariesFromNodes([node.left, node.right]);
36
+ case 'If':
37
+ return getBinariesFromNodes([node.clause, node.then, ...(node.else ? [node.else] : [])]);
38
+ case 'For':
39
+ return getBinariesFromNodes(node.do.commands);
40
+ case 'CompoundList':
41
+ return getBinariesFromNodes(node.commands);
42
+ case 'Pipeline':
43
+ return getBinariesFromNodes(node.commands);
44
+ case 'Function':
45
+ return getBinariesFromNodes(node.body.commands);
46
+ default:
47
+ return [];
48
+ }
49
+ });
50
+ try {
51
+ const parsed = parse(script);
52
+ return parsed?.commands ? getBinariesFromNodes(parsed.commands) : [];
53
+ }
54
+ catch (error) {
55
+ debugLogObject('Bash parser error', error);
56
+ return [];
57
+ }
58
+ };
@@ -0,0 +1,2 @@
1
+ import type { GetDependenciesFromScripts } from './types.js';
2
+ export declare const _getDependenciesFromScripts: GetDependenciesFromScripts;
@@ -0,0 +1,18 @@
1
+ import { compact } from '../util/array.js';
2
+ import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
3
+ import { isInternal } from '../util/path.js';
4
+ import { timerify } from '../util/Performance.js';
5
+ import { getBinariesFromScript } from './bash-parser.js';
6
+ import { isBinary } from './util.js';
7
+ const defaultCwd = process.cwd();
8
+ const getDependenciesFromScripts = (npmScripts, options = {}) => {
9
+ const { cwd = defaultCwd, manifest = {}, knownGlobalsOnly = false } = options;
10
+ const scripts = typeof npmScripts === 'string' ? [npmScripts] : [...npmScripts];
11
+ const results = scripts.flatMap(script => getBinariesFromScript(script, { cwd, manifest, knownGlobalsOnly }));
12
+ return compact(results.map(identifier => {
13
+ if (isBinary(identifier) || isInternal(identifier))
14
+ return identifier;
15
+ return getPackageNameFromModuleSpecifier(identifier);
16
+ }));
17
+ };
18
+ export const _getDependenciesFromScripts = timerify(getDependenciesFromScripts);
@@ -0,0 +1,2 @@
1
+ import type { Resolver } from '../types.js';
2
+ export declare const resolve: Resolver;
@@ -0,0 +1,10 @@
1
+ import parseArgs from 'minimist';
2
+ import { toBinary, argsFrom } from '../util.js';
3
+ export const resolve = (binary, args, { fromArgs }) => {
4
+ const parsed = parseArgs(args, {
5
+ boolean: ['all', 'check-coverage', 'clean', 'exclude-after-remap', 'per-file', 'skip-full'],
6
+ });
7
+ parsed._ = parsed._.filter(a => a !== 'check-coverage');
8
+ const rest = argsFrom(args, parsed._[0]);
9
+ return [toBinary(binary), ...fromArgs(rest)];
10
+ };
@@ -0,0 +1,2 @@
1
+ import type { Resolver } from '../types.js';
2
+ export declare const resolve: Resolver;