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
package/dist/index.js ADDED
@@ -0,0 +1,334 @@
1
+ import micromatch from 'micromatch';
2
+ import { _getDependenciesFromScripts } from './binaries/index.js';
3
+ import { fromBinary, isBinary } from './binaries/util.js';
4
+ import { ConfigurationChief } from './ConfigurationChief.js';
5
+ import { ConsoleStreamer } from './ConsoleStreamer.js';
6
+ import { ROOT_WORKSPACE_NAME } from './constants.js';
7
+ import { DependencyDeputy } from './DependencyDeputy.js';
8
+ import { IssueCollector } from './IssueCollector.js';
9
+ import { PrincipalFactory } from './PrincipalFactory.js';
10
+ import { ProjectPrincipal } from './ProjectPrincipal.js';
11
+ import { compact } from './util/array.js';
12
+ import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
13
+ import { LoaderError } from './util/errors.js';
14
+ import { findFile } from './util/fs.js';
15
+ import { _glob } from './util/glob.js';
16
+ import { getEntryPathFromManifest, getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, } from './util/modules.js';
17
+ import { dirname, isInNodeModules, join, isInternal, toAbsolute } from './util/path.js';
18
+ import { _resolveSpecifier, _tryResolve } from './util/require.js';
19
+ import { _require } from './util/require.js';
20
+ import { loadTSConfig as loadCompilerOptions } from './util/tsconfig-loader.js';
21
+ import { WorkspaceWorker } from './WorkspaceWorker.js';
22
+ export const main = async (unresolvedConfiguration) => {
23
+ const { cwd, tsConfigFile, gitignore, isStrict, isProduction, isIgnoreInternal, isShowProgress, isIncludeEntryExports, } = unresolvedConfiguration;
24
+ debugLogObject('Unresolved configuration (from CLI arguments)', unresolvedConfiguration);
25
+ const chief = new ConfigurationChief({ cwd, isProduction });
26
+ const deputy = new DependencyDeputy({ isStrict });
27
+ const factory = new PrincipalFactory();
28
+ const streamer = new ConsoleStreamer({ isEnabled: isShowProgress });
29
+ streamer.cast('Reading workspace configuration(s)...');
30
+ await chief.init();
31
+ const compilers = chief.getCompilers();
32
+ const workspaces = chief.getWorkspaces();
33
+ const report = chief.getIssueTypesToReport();
34
+ const rules = chief.getRules();
35
+ const isReportDependencies = report.dependencies || report.unlisted || report.unresolved;
36
+ const isReportValues = report.exports || report.nsExports || report.classMembers;
37
+ const isReportTypes = report.types || report.nsTypes || report.enumMembers;
38
+ const collector = new IssueCollector({ cwd, rules });
39
+ const enabledPluginsStore = new Map();
40
+ deputy.addIgnored(chief.config.ignoreBinaries, chief.config.ignoreDependencies);
41
+ debugLogObject('Included workspaces', workspaces);
42
+ const handleReferencedDependency = ({ specifier, containingFilePath, principal, workspace, }) => {
43
+ if (isInternal(specifier)) {
44
+ const absSpecifier = toAbsolute(specifier, dirname(containingFilePath));
45
+ const filePath = _tryResolve(absSpecifier, containingFilePath);
46
+ if (filePath) {
47
+ const ignorePatterns = workspace.config.ignore.map(pattern => join(dirname(containingFilePath), pattern));
48
+ const isIgnored = micromatch.isMatch(filePath, ignorePatterns);
49
+ if (!isIgnored)
50
+ principal.addEntryPath(filePath);
51
+ }
52
+ else {
53
+ collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
54
+ }
55
+ }
56
+ else {
57
+ if (isBinary(specifier)) {
58
+ const binaryName = fromBinary(specifier);
59
+ const isHandled = deputy.maybeAddReferencedBinary(workspace, binaryName);
60
+ if (!isHandled)
61
+ collector.addIssue({ type: 'binaries', filePath: containingFilePath, symbol: binaryName });
62
+ }
63
+ else {
64
+ const packageName = isInNodeModules(specifier)
65
+ ? getPackageNameFromFilePath(specifier)
66
+ : getPackageNameFromModuleSpecifier(specifier);
67
+ const isHandled = packageName && deputy.maybeAddReferencedExternalDependency(workspace, packageName);
68
+ if (!isHandled)
69
+ collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
70
+ if (packageName && specifier !== packageName) {
71
+ const otherWorkspace = chief.findWorkspaceByPackageName(packageName);
72
+ if (otherWorkspace) {
73
+ const filePath = _resolveSpecifier(otherWorkspace.dir, specifier);
74
+ if (filePath) {
75
+ principal.addEntryPath(filePath, { skipExportsAnalysis: true });
76
+ }
77
+ else {
78
+ collector.addIssue({ type: 'unresolved', filePath: containingFilePath, symbol: specifier });
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ };
85
+ for (const workspace of workspaces) {
86
+ const { name, dir, config, ancestors } = workspace;
87
+ const { paths, ignoreDependencies, ignoreBinaries } = config;
88
+ const isRoot = name === ROOT_WORKSPACE_NAME;
89
+ streamer.cast(`Analyzing workspace (${name})...`);
90
+ const manifestPath = isRoot ? chief.manifestPath : findFile(dir, 'package.json');
91
+ const manifest = isRoot ? chief.manifest : manifestPath && _require(manifestPath);
92
+ if (!manifestPath || !manifest)
93
+ throw new LoaderError(`Unable to load package.json for ${name}`);
94
+ deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries });
95
+ const compilerOptions = await loadCompilerOptions(join(dir, tsConfigFile ?? 'tsconfig.json'));
96
+ const principal = factory.getPrincipal({ cwd: dir, paths, compilerOptions, compilers });
97
+ const worker = new WorkspaceWorker({
98
+ name,
99
+ dir,
100
+ cwd,
101
+ config,
102
+ manifest,
103
+ isProduction,
104
+ isStrict,
105
+ rootIgnore: chief.config.ignore,
106
+ negatedWorkspacePatterns: chief.getNegatedWorkspacePatterns(name),
107
+ enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
108
+ });
109
+ await worker.init();
110
+ const sharedGlobOptions = { cwd, workingDir: dir, gitignore, ignore: worker.getIgnorePatterns() };
111
+ const entryPathsFromManifest = await getEntryPathFromManifest(cwd, dir, manifest);
112
+ debugLogArray(`Found entry paths from manifest (${name})`, entryPathsFromManifest);
113
+ principal.addEntryPaths(entryPathsFromManifest);
114
+ if (isProduction) {
115
+ {
116
+ const patterns = worker.getProductionEntryFilePatterns();
117
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
118
+ debugLogArray(`Found entry paths (${name})`, workspaceEntryPaths);
119
+ principal.addEntryPaths(workspaceEntryPaths);
120
+ }
121
+ {
122
+ const patterns = worker.getProductionPluginEntryFilePatterns();
123
+ const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
124
+ debugLogArray(`Found production plugin entry paths (${name})`, pluginWorkspaceEntryPaths);
125
+ principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
126
+ }
127
+ {
128
+ const patterns = worker.getProductionProjectFilePatterns();
129
+ const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
130
+ debugLogArray(`Found project paths (${name})`, workspaceProjectPaths);
131
+ workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
132
+ }
133
+ }
134
+ else {
135
+ {
136
+ const patterns = worker.getEntryFilePatterns();
137
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
138
+ debugLogArray(`Found entry paths (${name})`, workspaceEntryPaths);
139
+ principal.addEntryPaths(workspaceEntryPaths);
140
+ }
141
+ {
142
+ const patterns = worker.getProjectFilePatterns();
143
+ const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
144
+ debugLogArray(`Found project paths (${name})`, workspaceProjectPaths);
145
+ workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
146
+ }
147
+ {
148
+ const patterns = worker.getPluginEntryFilePatterns();
149
+ const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
150
+ debugLogArray(`Found plugin entry paths (${name})`, pluginWorkspaceEntryPaths);
151
+ principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
152
+ }
153
+ {
154
+ const patterns = worker.getPluginProjectFilePatterns();
155
+ const pluginWorkspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
156
+ debugLogArray(`Found plugin project paths (${name})`, pluginWorkspaceProjectPaths);
157
+ pluginWorkspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
158
+ }
159
+ {
160
+ const patterns = compact(worker.getPluginConfigPatterns());
161
+ const configurationEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
162
+ debugLogArray(`Found plugin configuration paths (${name})`, configurationEntryPaths);
163
+ principal.addEntryPaths(configurationEntryPaths, { skipExportsAnalysis: true });
164
+ }
165
+ }
166
+ if (chief.resolvedConfigFilePath)
167
+ principal.addEntryPath(chief.resolvedConfigFilePath, { skipExportsAnalysis: true });
168
+ const dependencies = await worker.findAllDependencies();
169
+ const { referencedDependencies, peerDependencies, installedBinaries, enabledPlugins } = dependencies;
170
+ deputy.addPeerDependencies(name, peerDependencies);
171
+ deputy.setInstalledBinaries(name, installedBinaries);
172
+ enabledPluginsStore.set(name, enabledPlugins);
173
+ referencedDependencies.forEach(([containingFilePath, specifier]) => {
174
+ handleReferencedDependency({ specifier, containingFilePath, principal, workspace });
175
+ });
176
+ }
177
+ const principals = factory.getPrincipals();
178
+ debugLog(`Installed ${principals.length} principals for ${workspaces.length} workspaces`);
179
+ for (const principal of principals) {
180
+ const exportedSymbols = new Map();
181
+ const importedSymbols = new Map();
182
+ const analyzeSourceFile = (filePath) => {
183
+ const workspace = chief.findWorkspaceByFilePath(filePath);
184
+ if (workspace) {
185
+ const { imports, exports, scripts } = principal.analyzeSourceFile(filePath, { skipTypeOnly: isProduction });
186
+ const { internal, external, unresolved } = imports;
187
+ const { exported, duplicate } = exports;
188
+ if (exported.size > 0)
189
+ exportedSymbols.set(filePath, exported);
190
+ for (const [specifierFilePath, importItems] of internal.entries()) {
191
+ const packageName = getPackageNameFromModuleSpecifier(importItems.specifier);
192
+ if (packageName && chief.localWorkspaces.has(packageName))
193
+ external.add(packageName);
194
+ if (!importedSymbols.has(specifierFilePath)) {
195
+ importedSymbols.set(specifierFilePath, importItems);
196
+ }
197
+ else {
198
+ const importedModule = importedSymbols.get(specifierFilePath);
199
+ for (const identifier of importItems.symbols) {
200
+ importedModule.symbols.add(identifier);
201
+ }
202
+ if (importItems.isReExport) {
203
+ importedModule.isReExport = importItems.isReExport;
204
+ importedModule.isReExportedBy.add(filePath);
205
+ }
206
+ if (importItems.isStar)
207
+ importedModule.isStar = importItems.isStar;
208
+ }
209
+ }
210
+ duplicate.forEach(symbols => {
211
+ if (symbols.length > 1) {
212
+ const symbol = symbols.join('|');
213
+ collector.addIssue({ type: 'duplicates', filePath, symbol, symbols });
214
+ }
215
+ });
216
+ external.forEach(specifier => {
217
+ const packageName = getPackageNameFromModuleSpecifier(specifier);
218
+ const isHandled = packageName && deputy.maybeAddReferencedExternalDependency(workspace, packageName);
219
+ if (!isHandled)
220
+ collector.addIssue({ type: 'unlisted', filePath, symbol: specifier });
221
+ });
222
+ unresolved.forEach(moduleSpecifier => {
223
+ collector.addIssue({ type: 'unresolved', filePath, symbol: moduleSpecifier });
224
+ });
225
+ _getDependenciesFromScripts(scripts, { cwd: dirname(filePath) }).forEach(specifier => {
226
+ handleReferencedDependency({ specifier, containingFilePath: filePath, principal, workspace });
227
+ });
228
+ }
229
+ };
230
+ streamer.cast('Running async compilers...');
231
+ await principal.runAsyncCompilers();
232
+ streamer.cast('Connecting the dots...');
233
+ const analyzedFiles = new Set();
234
+ let size = principal.entryPaths.size;
235
+ let round = 0;
236
+ do {
237
+ size = principal.entryPaths.size;
238
+ const resolvedFiles = principal.getUsedResolvedFiles();
239
+ const files = resolvedFiles.filter(filePath => !analyzedFiles.has(filePath));
240
+ debugLogArray(`Analyzing used resolved files [P${principals.indexOf(principal) + 1}/${++round}]`, files);
241
+ files.forEach(filePath => {
242
+ analyzeSourceFile(filePath);
243
+ analyzedFiles.add(filePath);
244
+ });
245
+ } while (size !== principal.entryPaths.size);
246
+ const unusedFiles = principal.getUnreferencedFiles();
247
+ collector.addFilesIssues(unusedFiles);
248
+ collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
249
+ const isSymbolImported = (symbol, importingModule) => {
250
+ if (!importingModule)
251
+ return false;
252
+ if (importingModule.symbols.has(symbol))
253
+ return true;
254
+ const { isReExport, isReExportedBy } = importingModule;
255
+ const hasSymbol = (file) => isSymbolImported(symbol, importedSymbols.get(file));
256
+ return isReExport ? Array.from(isReExportedBy).some(hasSymbol) : false;
257
+ };
258
+ const isExportedInEntryFile = (importedModule) => {
259
+ if (!importedModule)
260
+ return false;
261
+ const { isReExport, isReExportedBy } = importedModule;
262
+ const { entryPaths } = principal;
263
+ const hasFile = (file) => entryPaths.has(file) || isExportedInEntryFile(importedSymbols.get(file));
264
+ return isReExport ? Array.from(isReExportedBy).some(hasFile) : false;
265
+ };
266
+ const isExportedItemReferenced = (exportedItem, filePath) => {
267
+ const hasReferences = principal.getHasReferences(filePath, exportedItem);
268
+ return (hasReferences.external ||
269
+ (hasReferences.internal &&
270
+ (typeof chief.config.ignoreExportsUsedInFile === 'object'
271
+ ? exportedItem.type !== 'unknown' && !!chief.config.ignoreExportsUsedInFile[exportedItem.type]
272
+ : chief.config.ignoreExportsUsedInFile)));
273
+ };
274
+ if (isReportValues || isReportTypes) {
275
+ streamer.cast('Analyzing source files...');
276
+ for (const [filePath, exportItems] of exportedSymbols.entries()) {
277
+ if (!isIncludeEntryExports && principal.entryPaths.has(filePath))
278
+ continue;
279
+ const importingModule = importedSymbols.get(filePath);
280
+ for (const [symbol, exportedItem] of exportItems.entries()) {
281
+ if (exportedItem.jsDocTags.includes('@public') || exportedItem.jsDocTags.includes('@beta'))
282
+ continue;
283
+ if (isIgnoreInternal && exportedItem.jsDocTags.includes('@internal'))
284
+ continue;
285
+ if (importingModule && isSymbolImported(symbol, importingModule)) {
286
+ if (importingModule.isReExport && isExportedInEntryFile(importingModule))
287
+ continue;
288
+ if (report.enumMembers && exportedItem.type === 'enum' && exportedItem.members) {
289
+ if (isProduction)
290
+ continue;
291
+ principal.findUnusedMembers(filePath, exportedItem.members).forEach(member => {
292
+ collector.addIssue({ type: 'enumMembers', filePath, symbol: member, parentSymbol: symbol });
293
+ });
294
+ }
295
+ if (report.classMembers && exportedItem.type === 'class' && exportedItem.members) {
296
+ principal.findUnusedMembers(filePath, exportedItem.members).forEach(member => {
297
+ collector.addIssue({ type: 'classMembers', filePath, symbol: member, parentSymbol: symbol });
298
+ });
299
+ }
300
+ continue;
301
+ }
302
+ const isStar = Boolean(importingModule?.isStar);
303
+ const isReExportedByEntryFile = !isIncludeEntryExports && isStar && isExportedInEntryFile(importingModule);
304
+ if (!isReExportedByEntryFile && !isExportedItemReferenced(exportedItem, filePath)) {
305
+ if (['enum', 'type', 'interface'].includes(exportedItem.type)) {
306
+ if (isProduction)
307
+ continue;
308
+ const type = isStar ? 'nsTypes' : 'types';
309
+ collector.addIssue({ type, filePath, symbol, symbolType: exportedItem.type });
310
+ }
311
+ else {
312
+ const type = isStar ? 'nsExports' : 'exports';
313
+ collector.addIssue({ type, filePath, symbol });
314
+ }
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ if (isReportDependencies) {
321
+ const { dependencyIssues, devDependencyIssues, optionalPeerDependencyIssues } = deputy.settleDependencyIssues();
322
+ const { configurationHints } = deputy.getConfigurationHints();
323
+ dependencyIssues.forEach(issue => collector.addIssue(issue));
324
+ if (!isProduction)
325
+ devDependencyIssues.forEach(issue => collector.addIssue(issue));
326
+ optionalPeerDependencyIssues.forEach(issue => collector.addIssue(issue));
327
+ configurationHints.forEach(hint => collector.addConfigurationHint(hint));
328
+ }
329
+ const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
330
+ unusedIgnoredWorkspaces.forEach(identifier => collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier }));
331
+ const { issues, counters, configurationHints } = collector.getIssues();
332
+ streamer.clear();
333
+ return { report, issues, counters, rules, configurationHints };
334
+ };
@@ -0,0 +1,4 @@
1
+ import type { Issues, Counters, Rules } from '../types/issues.js';
2
+ export declare const initIssues: () => Issues;
3
+ export declare const initCounters: () => Counters;
4
+ export declare const defaultRules: Rules;
@@ -0,0 +1,11 @@
1
+ import { ISSUE_TYPES } from '../constants.js';
2
+ export const initIssues = () => ({
3
+ ...Object.fromEntries(ISSUE_TYPES.map(issueType => [issueType, {}])),
4
+ files: new Set(),
5
+ });
6
+ export const initCounters = () => ({
7
+ ...Object.fromEntries(ISSUE_TYPES.map(issueType => [issueType, 0])),
8
+ processed: 0,
9
+ total: 0,
10
+ });
11
+ export const defaultRules = Object.fromEntries(ISSUE_TYPES.map(issueType => [issueType, 'error']));
@@ -0,0 +1,7 @@
1
+ type Options = {
2
+ dir: string;
3
+ packageName: string;
4
+ cwd: string;
5
+ };
6
+ export declare const getPackageManifest: ({ dir, packageName, cwd }: Options) => Promise<any>;
7
+ export {};
@@ -0,0 +1,16 @@
1
+ import { join } from '../util/path.js';
2
+ import { _require } from '../util/require.js';
3
+ export const getPackageManifest = async ({ dir, packageName, cwd }) => {
4
+ try {
5
+ return _require(join(dir, 'node_modules', packageName, 'package.json'));
6
+ }
7
+ catch (error) {
8
+ if (dir !== cwd) {
9
+ try {
10
+ return _require(join(cwd, 'node_modules', packageName, 'package.json'));
11
+ }
12
+ catch (error) {
13
+ }
14
+ }
15
+ }
16
+ };
@@ -0,0 +1,16 @@
1
+ /// <reference types="npmcli__package-json" />
2
+ import type { InstalledBinaries, PeerDependencies } from '../types/workspace.js';
3
+ import type { PackageJson } from '@npmcli/package-json';
4
+ type Options = {
5
+ manifest: PackageJson;
6
+ isProduction: boolean;
7
+ isStrict: boolean;
8
+ dir: string;
9
+ cwd: string;
10
+ };
11
+ export declare const findDependencies: ({ manifest, isProduction, isStrict, dir, cwd }: Options) => Promise<{
12
+ dependencies: string[];
13
+ peerDependencies: PeerDependencies;
14
+ installedBinaries: InstalledBinaries;
15
+ }>;
16
+ export {};
@@ -0,0 +1,56 @@
1
+ import { _getDependenciesFromScripts } from '../binaries/index.js';
2
+ import { timerify } from '../util/Performance.js';
3
+ import { getPackageManifest } from './helpers.js';
4
+ const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir, cwd }) => {
5
+ const scriptFilter = isProduction ? ['start', 'postinstall'] : [];
6
+ const peerDependencies = new Map();
7
+ const scripts = Object.entries(manifest.scripts ?? {}).reduce((scripts, [scriptName, script]) => {
8
+ if (script && (scriptFilter.length === 0 || scriptFilter.includes(scriptName))) {
9
+ return [...scripts, script];
10
+ }
11
+ return scripts;
12
+ }, []);
13
+ const dependencies = _getDependenciesFromScripts(scripts, { cwd: dir, manifest });
14
+ const installedBinaries = new Map();
15
+ const packageNames = [
16
+ ...Object.keys(manifest.dependencies ?? {}),
17
+ ...(isStrict ? Object.keys(manifest.peerDependencies ?? {}) : []),
18
+ ...(isProduction ? [] : Object.keys(manifest.devDependencies ?? {})),
19
+ ];
20
+ for (const packageName of packageNames) {
21
+ const manifest = await getPackageManifest({ dir, packageName, cwd });
22
+ if (manifest) {
23
+ const binaryName = packageName.replace(/^@[^/]+\//, '');
24
+ const binaries = typeof manifest.bin === 'string' ? [binaryName] : Object.keys(manifest.bin ?? {});
25
+ binaries.forEach(binaryName => {
26
+ if (installedBinaries.has(binaryName)) {
27
+ installedBinaries.get(binaryName)?.add(packageName);
28
+ }
29
+ else {
30
+ installedBinaries.set(binaryName, new Set([packageName]));
31
+ }
32
+ if (installedBinaries.has(packageName)) {
33
+ installedBinaries.get(packageName)?.add(binaryName);
34
+ }
35
+ else {
36
+ installedBinaries.set(packageName, new Set([binaryName]));
37
+ }
38
+ });
39
+ const packagePeerDependencies = Object.keys(manifest.peerDependencies ?? {});
40
+ packagePeerDependencies.forEach(packagePeerDependency => {
41
+ if (peerDependencies.has(packagePeerDependency)) {
42
+ peerDependencies.get(packagePeerDependency)?.add(packageName);
43
+ }
44
+ else {
45
+ peerDependencies.set(packagePeerDependency, new Set([packageName]));
46
+ }
47
+ });
48
+ }
49
+ }
50
+ return {
51
+ dependencies,
52
+ peerDependencies,
53
+ installedBinaries,
54
+ };
55
+ };
56
+ export const findDependencies = timerify(findManifestDependencies);
@@ -0,0 +1,9 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: never[];
6
+ export declare const ENTRY_FILE_PATTERNS: never[];
7
+ export declare const PRODUCTION_ENTRY_FILE_PATTERNS: never[];
8
+ export declare const PROJECT_FILE_PATTERNS: never[];
9
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,14 @@
1
+ import { timerify } from '../../util/Performance.js';
2
+ import { hasDependency, load } from '../../util/plugin.js';
3
+ export const NAME = '';
4
+ export const ENABLERS = [''];
5
+ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
+ export const CONFIG_FILE_PATTERNS = [];
7
+ export const ENTRY_FILE_PATTERNS = [];
8
+ export const PRODUCTION_ENTRY_FILE_PATTERNS = [];
9
+ export const PROJECT_FILE_PATTERNS = [];
10
+ const findPluginDependencies = async (configFilePath, { manifest }) => {
11
+ const config = configFilePath.endsWith('package.json') ? manifest.plugin : await load(configFilePath);
12
+ return config?.plugins ?? [];
13
+ };
14
+ export const findDependencies = timerify(findPluginDependencies);
@@ -0,0 +1,3 @@
1
+ export type PluginConfig = {
2
+ plugins?: string[];
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "Angular";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,36 @@
1
+ import { join } from '../../util/path.js';
2
+ import { timerify } from '../../util/Performance.js';
3
+ import { hasDependency, load } from '../../util/plugin.js';
4
+ import { findTypeScriptDependencies } from '../typescript/index.js';
5
+ export const NAME = 'Angular';
6
+ export const ENABLERS = ['@angular/cli'];
7
+ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
+ export const CONFIG_FILE_PATTERNS = ['angular.json'];
9
+ const findPluginDependencies = async (configFilePath, opts) => {
10
+ const { cwd } = opts;
11
+ const config = await load(configFilePath);
12
+ if (!config.projects)
13
+ return [];
14
+ const dependencies = new Set();
15
+ for (const project of Object.values(config.projects)) {
16
+ if (!project.architect)
17
+ return [];
18
+ for (const target of Object.values(project.architect)) {
19
+ const { options } = target;
20
+ const [packageName] = typeof target.builder === 'string' ? target.builder.split(':') : [];
21
+ if (typeof packageName === 'string')
22
+ dependencies.add(packageName);
23
+ if (options) {
24
+ if ('main' in options && typeof options?.main === 'string') {
25
+ dependencies.add(join(cwd, options.main));
26
+ }
27
+ if ('tsConfig' in options && typeof options.tsConfig === 'string') {
28
+ const tsConfigDependencies = await findTypeScriptDependencies(join(cwd, options.tsConfig), opts);
29
+ tsConfigDependencies.forEach(dependency => dependencies.add(dependency));
30
+ }
31
+ }
32
+ }
33
+ }
34
+ return Array.from(dependencies);
35
+ };
36
+ export const findDependencies = timerify(findPluginDependencies);