packtory 0.0.7 → 0.0.9

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 (339) hide show
  1. package/artifacts/artifacts-builder.d.ts +7 -5
  2. package/artifacts/artifacts-builder.d.ts.map +1 -1
  3. package/artifacts/artifacts-builder.js +47 -18
  4. package/artifacts/artifacts-builder.js.map +1 -1
  5. package/bundle-emitter/emitter.d.ts +12 -2
  6. package/bundle-emitter/emitter.d.ts.map +1 -1
  7. package/bundle-emitter/emitter.js +11 -6
  8. package/bundle-emitter/emitter.js.map +1 -1
  9. package/bundle-emitter/extract-package-tarball.js +1 -2
  10. package/bundle-emitter/extract-package-tarball.js.map +1 -1
  11. package/bundle-emitter/publish-settings-bridge.js +133 -0
  12. package/bundle-emitter/publish-settings-bridge.js.map +1 -0
  13. package/bundle-emitter/registry-client.d.ts +13 -6
  14. package/bundle-emitter/registry-client.d.ts.map +1 -1
  15. package/bundle-emitter/registry-client.js +217 -45
  16. package/bundle-emitter/registry-client.js.map +1 -1
  17. package/bundle-emitter/repository-coherence.js +54 -0
  18. package/bundle-emitter/repository-coherence.js.map +1 -0
  19. package/bundle-emitter/repository-url-normalizer.js +38 -0
  20. package/bundle-emitter/repository-url-normalizer.js.map +1 -0
  21. package/checks/check-runner.js +3 -9
  22. package/checks/check-runner.js.map +1 -1
  23. package/checks/rule.js +13 -0
  24. package/checks/rule.js.map +1 -0
  25. package/checks/rules/max-bundle-size.js +44 -0
  26. package/checks/rules/max-bundle-size.js.map +1 -0
  27. package/checks/rules/no-dev-dependency-imports.js +37 -0
  28. package/checks/rules/no-dev-dependency-imports.js.map +1 -0
  29. package/checks/rules/no-duplicated-files.js +102 -27
  30. package/checks/rules/no-duplicated-files.js.map +1 -1
  31. package/checks/rules/no-side-effects.js +51 -0
  32. package/checks/rules/no-side-effects.js.map +1 -0
  33. package/checks/rules/no-unused-bundle-dependencies.js +33 -0
  34. package/checks/rules/no-unused-bundle-dependencies.js.map +1 -0
  35. package/checks/rules/registry.js +17 -0
  36. package/checks/rules/registry.js.map +1 -0
  37. package/checks/rules/required-files.js +41 -0
  38. package/checks/rules/required-files.js.map +1 -0
  39. package/checks/rules/unique-target-paths.js +34 -0
  40. package/checks/rules/unique-target-paths.js.map +1 -0
  41. package/common/clock.d.ts +7 -0
  42. package/common/clock.d.ts.map +1 -0
  43. package/common/clock.js +11 -0
  44. package/common/clock.js.map +1 -0
  45. package/common/code-files.js +5 -0
  46. package/common/code-files.js.map +1 -0
  47. package/config/additional-package-json-attributes-schema.js +7 -0
  48. package/config/additional-package-json-attributes-schema.js.map +1 -0
  49. package/config/automatic-versioning-settings.js +7 -0
  50. package/config/automatic-versioning-settings.js.map +1 -0
  51. package/config/checks-schema.d.ts +74 -0
  52. package/config/checks-schema.d.ts.map +1 -0
  53. package/config/checks-schema.js +27 -0
  54. package/config/checks-schema.js.map +1 -0
  55. package/config/common-package-settings-schemas.js +20 -0
  56. package/config/common-package-settings-schemas.js.map +1 -0
  57. package/config/config.d.ts +16 -704
  58. package/config/config.d.ts.map +1 -1
  59. package/config/config.js +3 -71
  60. package/config/config.js.map +1 -1
  61. package/config/dead-code-elimination-settings.d.ts +6 -0
  62. package/config/dead-code-elimination-settings.d.ts.map +1 -0
  63. package/config/dead-code-elimination-settings.js +5 -0
  64. package/config/dead-code-elimination-settings.js.map +1 -0
  65. package/config/dependency-policy.d.ts +6 -0
  66. package/config/dependency-policy.d.ts.map +1 -0
  67. package/config/dependency-policy.js +6 -0
  68. package/config/dependency-policy.js.map +1 -0
  69. package/config/main-package-json-schema.js +14 -0
  70. package/config/main-package-json-schema.js.map +1 -0
  71. package/config/manual-versioning-settings.js +7 -0
  72. package/config/manual-versioning-settings.js.map +1 -0
  73. package/config/optional-package-settings-schema.js +15 -0
  74. package/config/optional-package-settings-schema.js.map +1 -0
  75. package/config/package-config.d.ts +49 -0
  76. package/config/package-config.d.ts.map +1 -0
  77. package/config/package-config.js +7 -0
  78. package/config/package-config.js.map +1 -0
  79. package/config/package-interface.d.ts +34 -0
  80. package/config/package-interface.d.ts.map +1 -0
  81. package/config/package-interface.js +26 -0
  82. package/config/package-interface.js.map +1 -0
  83. package/config/package-json.d.ts +11 -10
  84. package/config/package-json.d.ts.map +1 -1
  85. package/config/package-json.js +11 -19
  86. package/config/package-json.js.map +1 -1
  87. package/config/package-schemas.js +10 -0
  88. package/config/package-schemas.js.map +1 -0
  89. package/config/packtory-config-schema.js +7 -0
  90. package/config/packtory-config-schema.js.map +1 -0
  91. package/config/packtory-config-without-registry-schema.js +32 -0
  92. package/config/packtory-config-without-registry-schema.js.map +1 -0
  93. package/config/per-package-settings-schema.js +22 -0
  94. package/config/per-package-settings-schema.js.map +1 -0
  95. package/config/publish-settings.d.ts +22 -0
  96. package/config/publish-settings.d.ts.map +1 -0
  97. package/config/publish-settings.js +26 -0
  98. package/config/publish-settings.js.map +1 -0
  99. package/config/publish-settings.report.js +17 -0
  100. package/config/publish-settings.report.js.map +1 -0
  101. package/config/registry-settings.d.ts +83 -1
  102. package/config/registry-settings.d.ts.map +1 -1
  103. package/config/registry-settings.js +35 -1
  104. package/config/registry-settings.js.map +1 -1
  105. package/config/registry-settings.report.js +41 -0
  106. package/config/registry-settings.report.js.map +1 -0
  107. package/config/root.d.ts +7 -0
  108. package/config/root.d.ts.map +1 -0
  109. package/config/{entry-point.js → root.js} +2 -2
  110. package/config/root.js.map +1 -0
  111. package/config/sbom-settings.js +5 -0
  112. package/config/sbom-settings.js.map +1 -0
  113. package/config/validation.d.ts +2 -2
  114. package/config/validation.d.ts.map +1 -1
  115. package/config/validation.js +155 -37
  116. package/config/validation.js.map +1 -1
  117. package/config/versioning-settings.d.ts.map +1 -1
  118. package/config/versioning-settings.js +2 -9
  119. package/config/versioning-settings.js.map +1 -1
  120. package/dead-code-eliminator/analyzed-bundle.d.ts +27 -0
  121. package/dead-code-eliminator/analyzed-bundle.d.ts.map +1 -0
  122. package/dead-code-eliminator/analyzed-bundle.js +8 -0
  123. package/dead-code-eliminator/analyzed-bundle.js.map +1 -0
  124. package/dead-code-eliminator/cross-bundle/cross-bundle-seeds.js +126 -0
  125. package/dead-code-eliminator/cross-bundle/cross-bundle-seeds.js.map +1 -0
  126. package/dead-code-eliminator/elimination-emitter.js +53 -0
  127. package/dead-code-eliminator/elimination-emitter.js.map +1 -0
  128. package/dead-code-eliminator/eliminator.js +141 -0
  129. package/dead-code-eliminator/eliminator.js.map +1 -0
  130. package/dead-code-eliminator/load-bundle.js +52 -0
  131. package/dead-code-eliminator/load-bundle.js.map +1 -0
  132. package/dead-code-eliminator/reachability/binding-extractor.js +88 -0
  133. package/dead-code-eliminator/reachability/binding-extractor.js.map +1 -0
  134. package/dead-code-eliminator/reachability/impure-statements.js +12 -0
  135. package/dead-code-eliminator/reachability/impure-statements.js.map +1 -0
  136. package/dead-code-eliminator/reachability/reachability.js +141 -0
  137. package/dead-code-eliminator/reachability/reachability.js.map +1 -0
  138. package/dead-code-eliminator/side-effect-classifier.js +289 -0
  139. package/dead-code-eliminator/side-effect-classifier.js.map +1 -0
  140. package/dead-code-eliminator/side-effects-field.js +25 -0
  141. package/dead-code-eliminator/side-effects-field.js.map +1 -0
  142. package/dead-code-eliminator/transform/atom-translator.js +13 -0
  143. package/dead-code-eliminator/transform/atom-translator.js.map +1 -0
  144. package/dead-code-eliminator/transform/declaration-remover.js +92 -0
  145. package/dead-code-eliminator/transform/declaration-remover.js.map +1 -0
  146. package/dead-code-eliminator/transform/line-index.js +27 -0
  147. package/dead-code-eliminator/transform/line-index.js.map +1 -0
  148. package/dead-code-eliminator/transform/source-map-composer.js +68 -0
  149. package/dead-code-eliminator/transform/source-map-composer.js.map +1 -0
  150. package/dependency-scanner/dependency-graph.d.ts +1 -1
  151. package/dependency-scanner/dependency-graph.d.ts.map +1 -1
  152. package/dependency-scanner/dependency-graph.js +5 -7
  153. package/dependency-scanner/dependency-graph.js.map +1 -1
  154. package/dependency-scanner/external-dependencies.js +2 -2
  155. package/dependency-scanner/external-dependencies.js.map +1 -1
  156. package/dependency-scanner/scanner.d.ts +7 -7
  157. package/dependency-scanner/scanner.d.ts.map +1 -1
  158. package/dependency-scanner/scanner.js +9 -14
  159. package/dependency-scanner/scanner.js.map +1 -1
  160. package/dependency-scanner/source-file-references.js +3 -42
  161. package/dependency-scanner/source-file-references.js.map +1 -1
  162. package/dependency-scanner/source-map-file-locator.d.ts.map +1 -1
  163. package/dependency-scanner/source-map-file-locator.js +10 -3
  164. package/dependency-scanner/source-map-file-locator.js.map +1 -1
  165. package/dependency-scanner/typescript-file-host.d.ts +2 -0
  166. package/dependency-scanner/typescript-file-host.d.ts.map +1 -1
  167. package/dependency-scanner/typescript-file-host.js +99 -32
  168. package/dependency-scanner/typescript-file-host.js.map +1 -1
  169. package/dependency-scanner/typescript-project-analyzer.d.ts +4 -5
  170. package/dependency-scanner/typescript-project-analyzer.d.ts.map +1 -1
  171. package/dependency-scanner/typescript-project-analyzer.js +5 -17
  172. package/dependency-scanner/typescript-project-analyzer.js.map +1 -1
  173. package/directed-graph/graph.d.ts +1 -1
  174. package/directed-graph/graph.d.ts.map +1 -1
  175. package/directed-graph/graph.js +132 -97
  176. package/directed-graph/graph.js.map +1 -1
  177. package/file-manager/compare.js +11 -9
  178. package/file-manager/compare.js.map +1 -1
  179. package/file-manager/file-manager.d.ts +1 -1
  180. package/file-manager/file-manager.d.ts.map +1 -1
  181. package/file-manager/file-manager.js +7 -1
  182. package/file-manager/file-manager.js.map +1 -1
  183. package/file-manager/permissions.js +20 -6
  184. package/file-manager/permissions.js.map +1 -1
  185. package/linker/linked-bundle.d.ts +5 -3
  186. package/linker/linked-bundle.d.ts.map +1 -1
  187. package/linker/linker.d.ts.map +1 -1
  188. package/linker/linker.js +8 -7
  189. package/linker/linker.js.map +1 -1
  190. package/linker/resource-graph.js +5 -8
  191. package/linker/resource-graph.js.map +1 -1
  192. package/linker/source-modifier/import-paths.js +1 -12
  193. package/linker/source-modifier/import-paths.js.map +1 -1
  194. package/linker/substitute-bundles.js +55 -48
  195. package/linker/substitute-bundles.js.map +1 -1
  196. package/linker/substituted-resource-graph.js +5 -8
  197. package/linker/substituted-resource-graph.js.map +1 -1
  198. package/npm-oidc-id-token-resolver.js +56 -0
  199. package/npm-oidc-id-token-resolver.js.map +1 -0
  200. package/package-surface/modules.js +307 -0
  201. package/package-surface/modules.js.map +1 -0
  202. package/package-surface/public-module-usage.js +37 -0
  203. package/package-surface/public-module-usage.js.map +1 -0
  204. package/package-surface/surface.d.ts +14 -0
  205. package/package-surface/surface.d.ts.map +1 -0
  206. package/package-surface/surface.js +16 -0
  207. package/package-surface/surface.js.map +1 -0
  208. package/package.json +20 -16
  209. package/packages/package-processor.composition.js +127 -0
  210. package/packages/package-processor.composition.js.map +1 -0
  211. package/packages/packtory/packtory.entry-point.d.ts +16 -6
  212. package/packages/packtory/packtory.entry-point.d.ts.map +1 -1
  213. package/packages/packtory/packtory.entry-point.js +7 -43
  214. package/packages/packtory/packtory.entry-point.js.map +1 -1
  215. package/packtory/map-config.d.ts +7 -16
  216. package/packtory/map-config.d.ts.map +1 -1
  217. package/packtory/map-config.js +5 -60
  218. package/packtory/map-config.js.map +1 -1
  219. package/packtory/normalize-paths.js +2 -2
  220. package/packtory/normalize-paths.js.map +1 -1
  221. package/packtory/package-processor-build.js +75 -0
  222. package/packtory/package-processor-build.js.map +1 -0
  223. package/packtory/package-processor-publish.d.ts +29 -0
  224. package/packtory/package-processor-publish.d.ts.map +1 -0
  225. package/packtory/package-processor-publish.js +134 -0
  226. package/packtory/package-processor-publish.js.map +1 -0
  227. package/packtory/package-processor.d.ts +17 -21
  228. package/packtory/package-processor.d.ts.map +1 -1
  229. package/packtory/package-processor.js +6 -81
  230. package/packtory/package-processor.js.map +1 -1
  231. package/packtory/packtory-publish.js +66 -0
  232. package/packtory/packtory-publish.js.map +1 -0
  233. package/packtory/packtory-resolve.js +77 -0
  234. package/packtory/packtory-resolve.js.map +1 -0
  235. package/packtory/packtory-results.d.ts +47 -0
  236. package/packtory/packtory-results.d.ts.map +1 -0
  237. package/packtory/packtory-results.js +16 -0
  238. package/packtory/packtory-results.js.map +1 -0
  239. package/packtory/packtory.d.ts +16 -37
  240. package/packtory/packtory.d.ts.map +1 -1
  241. package/packtory/packtory.js +33 -114
  242. package/packtory/packtory.js.map +1 -1
  243. package/packtory/prepare-package-options.d.ts +28 -0
  244. package/packtory/prepare-package-options.d.ts.map +1 -0
  245. package/packtory/prepare-package-options.js +122 -0
  246. package/packtory/prepare-package-options.js.map +1 -0
  247. package/packtory/report-attachment.js +25 -0
  248. package/packtory/report-attachment.js.map +1 -0
  249. package/packtory/resolved-package.d.ts +17 -0
  250. package/packtory/resolved-package.d.ts.map +1 -0
  251. package/packtory/resolved-package.js +35 -0
  252. package/packtory/resolved-package.js.map +1 -0
  253. package/packtory/scheduler.d.ts.map +1 -1
  254. package/packtory/scheduler.js +17 -15
  255. package/packtory/scheduler.js.map +1 -1
  256. package/progress/progress-broadcaster.d.ts +128 -5
  257. package/progress/progress-broadcaster.d.ts.map +1 -1
  258. package/progress/progress-broadcaster.js +37 -8
  259. package/progress/progress-broadcaster.js.map +1 -1
  260. package/report/artifact-entry-merger.js +22 -0
  261. package/report/artifact-entry-merger.js.map +1 -0
  262. package/report/config-redactor.js +27 -0
  263. package/report/config-redactor.js.map +1 -0
  264. package/report/decorators.js +68 -0
  265. package/report/decorators.js.map +1 -0
  266. package/report/inspectors.js +74 -0
  267. package/report/inspectors.js.map +1 -0
  268. package/report/report-aggregator.d.ts +61 -0
  269. package/report/report-aggregator.d.ts.map +1 -0
  270. package/report/report-aggregator.js +187 -0
  271. package/report/report-aggregator.js.map +1 -0
  272. package/resource-resolver/content.js +14 -0
  273. package/resource-resolver/content.js.map +1 -1
  274. package/resource-resolver/resolved-bundle.d.ts +4 -2
  275. package/resource-resolver/resolved-bundle.d.ts.map +1 -1
  276. package/resource-resolver/resource-resolve-options.d.ts +12 -5
  277. package/resource-resolver/resource-resolve-options.d.ts.map +1 -1
  278. package/resource-resolver/resource-resolve-options.js +14 -0
  279. package/resource-resolver/resource-resolve-options.js.map +1 -0
  280. package/resource-resolver/resource-resolver.d.ts +1 -1
  281. package/resource-resolver/resource-resolver.d.ts.map +1 -1
  282. package/resource-resolver/resource-resolver.js +37 -22
  283. package/resource-resolver/resource-resolver.js.map +1 -1
  284. package/sbom/extract-license.js +12 -0
  285. package/sbom/extract-license.js.map +1 -0
  286. package/sbom/license-resolver.d.ts +14 -0
  287. package/sbom/license-resolver.d.ts.map +1 -0
  288. package/sbom/license-resolver.js +22 -0
  289. package/sbom/license-resolver.js.map +1 -0
  290. package/sbom/sbom-builder.js +68 -0
  291. package/sbom/sbom-builder.js.map +1 -0
  292. package/sbom/sbom-file.d.ts +19 -0
  293. package/sbom/sbom-file.d.ts.map +1 -0
  294. package/sbom/sbom-file.js +57 -0
  295. package/sbom/sbom-file.js.map +1 -0
  296. package/sbom/sbom-serializer.d.ts +6 -0
  297. package/sbom/sbom-serializer.d.ts.map +1 -0
  298. package/sbom/sbom-serializer.js +11 -0
  299. package/sbom/sbom-serializer.js.map +1 -0
  300. package/sbom/tool-version.js +44 -0
  301. package/sbom/tool-version.js.map +1 -0
  302. package/tar/extract-tar.js +28 -3
  303. package/tar/extract-tar.js.map +1 -1
  304. package/tar/tarball-builder.d.ts.map +1 -1
  305. package/tar/tarball-builder.js +10 -7
  306. package/tar/tarball-builder.js.map +1 -1
  307. package/version-manager/manager.d.ts +5 -1
  308. package/version-manager/manager.d.ts.map +1 -1
  309. package/version-manager/manager.js +9 -1
  310. package/version-manager/manager.js.map +1 -1
  311. package/version-manager/manifest/builder.js +52 -6
  312. package/version-manager/manifest/builder.js.map +1 -1
  313. package/version-manager/manifest/serialize.js +31 -39
  314. package/version-manager/manifest/serialize.js.map +1 -1
  315. package/version-manager/manifest/sort-values.js +17 -0
  316. package/version-manager/manifest/sort-values.js.map +1 -0
  317. package/version-manager/specifier-classifier.js +35 -0
  318. package/version-manager/specifier-classifier.js.map +1 -0
  319. package/version-manager/specifier-errors.js +44 -0
  320. package/version-manager/specifier-errors.js.map +1 -0
  321. package/version-manager/versioned-bundle-dependencies.js +112 -0
  322. package/version-manager/versioned-bundle-dependencies.js.map +1 -0
  323. package/version-manager/versioned-bundle-imports.d.ts +5 -0
  324. package/version-manager/versioned-bundle-imports.d.ts.map +1 -0
  325. package/version-manager/versioned-bundle-imports.js +75 -0
  326. package/version-manager/versioned-bundle-imports.js.map +1 -0
  327. package/version-manager/versioned-bundle.d.ts +16 -8
  328. package/version-manager/versioned-bundle.d.ts.map +1 -1
  329. package/version-manager/versioned-bundle.js +48 -62
  330. package/version-manager/versioned-bundle.js.map +1 -1
  331. package/config/entry-point.d.ts +0 -7
  332. package/config/entry-point.d.ts.map +0 -1
  333. package/config/entry-point.js.map +0 -1
  334. package/file-manager/sort.js +0 -13
  335. package/file-manager/sort.js.map +0 -1
  336. package/list/unique-list.js +0 -5
  337. package/list/unique-list.js.map +0 -1
  338. package/version-manager/manifest/builder.d.ts +0 -5
  339. package/version-manager/manifest/builder.d.ts.map +0 -1
@@ -0,0 +1,126 @@
1
+ import { Node as TsMorphNode } from 'ts-morph';
2
+ import { resolvePublicModuleSourceFilePath } from "../../package-surface/modules.js";
3
+ import { bindingId } from "../reachability/reachability.js";
4
+ function indexBundles(inputs) {
5
+ const map = new Map();
6
+ for (const input of inputs) {
7
+ const bindingsByFilePath = new Map(input.fileBindings.map((file) => {
8
+ return [file.sourceFilePath, file];
9
+ }));
10
+ map.set(input.bundle.name, { bundle: input.bundle, bindingsByFilePath });
11
+ }
12
+ return map;
13
+ }
14
+ function tryResolveAgainstBundle(indexedBundle, specifier) {
15
+ const sourceFilePath = resolvePublicModuleSourceFilePath(indexedBundle.bundle, specifier);
16
+ if (sourceFilePath === undefined) {
17
+ return undefined;
18
+ }
19
+ return { bundleName: indexedBundle.bundle.name, sourceFilePath, indexedBundle };
20
+ }
21
+ function resolveCrossBundleTarget(specifier, indexed) {
22
+ if (specifier === undefined) {
23
+ return undefined;
24
+ }
25
+ for (const info of indexed.values()) {
26
+ const resolved = tryResolveAgainstBundle(info, specifier);
27
+ if (resolved !== undefined) {
28
+ return resolved;
29
+ }
30
+ }
31
+ return undefined;
32
+ }
33
+ function recordSeed(seeds, bundleName, seed) {
34
+ const existing = seeds.get(bundleName) ?? new Set();
35
+ existing.add(seed);
36
+ seeds.set(bundleName, existing);
37
+ }
38
+ function seedAllBindings(seeds, target) {
39
+ const fileBindings = target.indexedBundle.bindingsByFilePath.get(target.sourceFilePath);
40
+ if (fileBindings === undefined) {
41
+ return;
42
+ }
43
+ for (const binding of fileBindings.bindings) {
44
+ recordSeed(seeds, target.bundleName, bindingId(target.sourceFilePath, binding.name));
45
+ }
46
+ }
47
+ function localNameOfNamedImport(namedImport) {
48
+ return namedImport.getAliasNode()?.getText() ?? namedImport.getName();
49
+ }
50
+ function isLocalBindingReachable(context, localName) {
51
+ return context.localReachable.has(bindingId(context.sourceFilePath, localName));
52
+ }
53
+ function recordDefaultImportSeed(importDeclaration, target, context) {
54
+ const defaultImport = importDeclaration.getDefaultImport();
55
+ if (defaultImport === undefined) {
56
+ return;
57
+ }
58
+ if (!isLocalBindingReachable(context, defaultImport.getText())) {
59
+ return;
60
+ }
61
+ recordSeed(context.seeds, target.bundleName, bindingId(target.sourceFilePath, 'default'));
62
+ }
63
+ function recordNamedImportSeeds(importDeclaration, target, context) {
64
+ for (const namedImport of importDeclaration.getNamedImports()) {
65
+ if (isLocalBindingReachable(context, localNameOfNamedImport(namedImport))) {
66
+ recordSeed(context.seeds, target.bundleName, bindingId(target.sourceFilePath, namedImport.getName()));
67
+ }
68
+ }
69
+ }
70
+ function processImportDeclaration(importDeclaration, context) {
71
+ const target = resolveCrossBundleTarget(importDeclaration.getModuleSpecifierValue(), context.indexed);
72
+ if (target === undefined) {
73
+ return;
74
+ }
75
+ const namespaceImport = importDeclaration.getNamespaceImport();
76
+ if (namespaceImport !== undefined) {
77
+ if (isLocalBindingReachable(context, namespaceImport.getText())) {
78
+ seedAllBindings(context.seeds, target);
79
+ }
80
+ return;
81
+ }
82
+ recordDefaultImportSeed(importDeclaration, target, context);
83
+ recordNamedImportSeeds(importDeclaration, target, context);
84
+ }
85
+ function recordNamedReExportSeeds(exportDeclaration, target, seeds) {
86
+ for (const namedExport of exportDeclaration.getNamedExports()) {
87
+ recordSeed(seeds, target.bundleName, bindingId(target.sourceFilePath, namedExport.getName()));
88
+ }
89
+ }
90
+ function processExportDeclaration(exportDeclaration, context) {
91
+ const target = resolveCrossBundleTarget(exportDeclaration.getModuleSpecifierValue(), context.indexed);
92
+ if (target === undefined) {
93
+ return;
94
+ }
95
+ if (exportDeclaration.isNamespaceExport()) {
96
+ seedAllBindings(context.seeds, target);
97
+ return;
98
+ }
99
+ recordNamedReExportSeeds(exportDeclaration, target, context.seeds);
100
+ }
101
+ function walkCrossBundleStatements(sourceFile, context) {
102
+ for (const statement of sourceFile.getStatements()) {
103
+ if (TsMorphNode.isImportDeclaration(statement)) {
104
+ processImportDeclaration(statement, context);
105
+ }
106
+ else if (TsMorphNode.isExportDeclaration(statement)) {
107
+ processExportDeclaration(statement, context);
108
+ }
109
+ }
110
+ }
111
+ export function buildCrossBundleSeeds(inputs) {
112
+ const indexed = indexBundles(inputs);
113
+ const seeds = new Map();
114
+ for (const input of inputs) {
115
+ for (const sourceFile of input.sourceFiles) {
116
+ walkCrossBundleStatements(sourceFile, {
117
+ indexed,
118
+ seeds,
119
+ sourceFilePath: sourceFile.getFilePath(),
120
+ localReachable: input.localReachable
121
+ });
122
+ }
123
+ }
124
+ return seeds;
125
+ }
126
+ //# sourceMappingURL=cross-bundle-seeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-bundle-seeds.js","sourceRoot":"","sources":["../../../../../source/dead-code-eliminator/cross-bundle/cross-bundle-seeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,WAAW,EAAmE,MAAM,UAAU,CAAC;AAEhH,OAAO,EAAE,iCAAiC,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AAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YACzC,yBAAyB,CAAC,UAAU,EAAE;gBAClC,OAAO;gBACP,KAAK;gBACL,cAAc,EAAE,UAAU,CAAC,WAAW,EAAE;gBACxC,cAAc,EAAE,KAAK,CAAC,cAAc;aACvC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,53 @@
1
+ function buildFileDecisions(original, analyzed) {
2
+ const analyzedBySourcePath = new Map(analyzed.contents.map((entry) => {
3
+ return [entry.fileDescription.sourceFilePath, entry];
4
+ }));
5
+ return original.contents.map((entry) => {
6
+ const emitted = analyzedBySourcePath.get(entry.fileDescription.sourceFilePath);
7
+ const sourceBytes = Buffer.byteLength(entry.fileDescription.content);
8
+ if (emitted === undefined) {
9
+ return {
10
+ path: entry.fileDescription.sourceFilePath,
11
+ decision: 'eliminated',
12
+ reason: 'not-emitted-after-analysis',
13
+ sourceBytes
14
+ };
15
+ }
16
+ const outputBytes = Buffer.byteLength(emitted.fileDescription.content);
17
+ if (entry.fileDescription.content !== emitted.fileDescription.content) {
18
+ return {
19
+ path: entry.fileDescription.sourceFilePath,
20
+ decision: 'transformed',
21
+ reason: 'rewritten-after-analysis',
22
+ sourceBytes,
23
+ outputBytes
24
+ };
25
+ }
26
+ return {
27
+ path: entry.fileDescription.sourceFilePath,
28
+ decision: 'kept',
29
+ reason: 'reachable',
30
+ sourceBytes
31
+ };
32
+ });
33
+ }
34
+ export function maybeEmitElimination(broadcaster, originalBundles, analyzed) {
35
+ if (!broadcaster.hasSubscribers('eliminationCompleted')) {
36
+ return;
37
+ }
38
+ broadcaster.emit('eliminationCompleted', {
39
+ perBundle: analyzed.map((bundle, index) => {
40
+ const originalBundle = originalBundles[index];
41
+ if (originalBundle === undefined) {
42
+ throw new Error(`Original bundle missing for analyzed bundle "${bundle.name}"`);
43
+ }
44
+ return {
45
+ packageName: bundle.name,
46
+ files: buildFileDecisions(originalBundle, bundle),
47
+ droppedSymbols: [],
48
+ seeds: []
49
+ };
50
+ })
51
+ });
52
+ }
53
+ //# sourceMappingURL=elimination-emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elimination-emitter.js","sourceRoot":"","sources":["../../../../source/dead-code-eliminator/elimination-emitter.ts"],"names":[],"mappings":"AAIA,SAAS,kBAAkB,CAAC,QAAsB,EAAE,QAAwB;IACxE,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAChC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,cAAc,EAAE,KAAK,CAAU,CAAC;IAClE,CAAC,CAAC,CACL,CAAC;IACF,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAgB,EAAE;QACjD,MAAM,OAAO,GAAG,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAC/E,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACrE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO;gBACH,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,cAAc;gBAC1C,QAAQ,EAAE,YAAY;gBACtB,MAAM,EAAE,4BAA4B;gBACpC,WAAW;aACd,CAAC;QACN,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACvE,IAAI,KAAK,CAAC,eAAe,CAAC,OAAO,KAAK,OAAO,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;YACpE,OAAO;gBACH,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,cAAc;gBAC1C,QAAQ,EAAE,aAAa;gBACvB,MAAM,EAAE,0BAA0B;gBAClC,WAAW;gBACX,WAAW;aACd,CAAC;QACN,CAAC;QACD,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,cAAc;YAC1C,QAAQ,EAAE,MAAM;YAChB,MAAM,EAAE,WAAW;YACnB,WAAW;SACd,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,oBAAoB,CAChC,WAAsC,EACtC,eAAwC,EACxC,QAAmC;IAEnC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACtD,OAAO;IACX,CAAC;IACD,WAAW,CAAC,IAAI,CAAC,sBAAsB,EAAE;QACrC,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACtC,MAAM,cAAc,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;YAC9C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,gDAAgD,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;YACpF,CAAC;YACD,OAAO;gBACH,WAAW,EAAE,MAAM,CAAC,IAAI;gBACxB,KAAK,EAAE,kBAAkB,CAAC,cAAc,EAAE,MAAM,CAAC;gBACjD,cAAc,EAAE,EAAE;gBAClB,KAAK,EAAE,EAAE;aACZ,CAAC;QACN,CAAC,CAAC;KACL,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,141 @@
1
+ import { createEmptyFileAnalysis } from "./analyzed-bundle.js";
2
+ import { maybeEmitElimination } from "./elimination-emitter.js";
3
+ import { buildCrossBundleSeeds } from "./cross-bundle/cross-bundle-seeds.js";
4
+ import { loadBundle } from "./load-bundle.js";
5
+ import { bindingId } from "./reachability/reachability.js";
6
+ import { classifySideEffects } from "./side-effect-classifier.js";
7
+ import { computeSideEffectsField } from "./side-effects-field.js";
8
+ import { applyRemovalPlan } from "./transform/declaration-remover.js";
9
+ import { recomposeSourceMap } from "./transform/source-map-composer.js";
10
+ function allBindingNamesFor(loaded) {
11
+ const names = new Set();
12
+ for (const binding of loaded.bindings) {
13
+ names.add(binding.name);
14
+ }
15
+ return names;
16
+ }
17
+ function reachableBindingsFor(loaded, reachable) {
18
+ const { sourceFilePath } = loaded.resource.fileDescription;
19
+ const surviving = new Set();
20
+ for (const binding of loaded.bindings) {
21
+ if (reachable.has(bindingId(sourceFilePath, binding.name))) {
22
+ surviving.add(binding.name);
23
+ }
24
+ }
25
+ return surviving;
26
+ }
27
+ function transformSourceFile(sourceFile, surviving) {
28
+ const result = applyRemovalPlan(sourceFile, { survivingNames: surviving });
29
+ return { transformedCode: sourceFile.getFullText(), atoms: result.atoms };
30
+ }
31
+ function analyzeCodeFile(loaded, context) {
32
+ const sideEffectStatements = classifySideEffects(loaded.sourceFile);
33
+ const reachableBindings = reachableBindingsFor(loaded, context.reachable);
34
+ const shouldTransform = context.transformationsEnabled && sideEffectStatements.length === 0;
35
+ const survivingBindings = shouldTransform ? reachableBindings : allBindingNamesFor(loaded);
36
+ return {
37
+ analysis: { survivingBindings, sideEffectStatements, sideEffectImports: new Set() },
38
+ reachableBindings,
39
+ shouldTransform
40
+ };
41
+ }
42
+ const noTransforms = [];
43
+ function buildAnalyzedResource(loaded, context) {
44
+ if (loaded.sourceFile === undefined) {
45
+ return { resource: { ...loaded.resource, analysis: createEmptyFileAnalysis() }, transforms: noTransforms };
46
+ }
47
+ const { analysis, reachableBindings, shouldTransform } = analyzeCodeFile(loaded, context);
48
+ if (!shouldTransform) {
49
+ return { resource: { ...loaded.resource, analysis }, transforms: noTransforms };
50
+ }
51
+ const originalCode = loaded.resource.fileDescription.content;
52
+ const { transformedCode, atoms } = transformSourceFile(loaded.sourceFile, reachableBindings);
53
+ if (transformedCode === originalCode) {
54
+ return { resource: { ...loaded.resource, analysis }, transforms: noTransforms };
55
+ }
56
+ return {
57
+ resource: {
58
+ ...loaded.resource,
59
+ fileDescription: { ...loaded.resource.fileDescription, content: transformedCode },
60
+ analysis
61
+ },
62
+ transforms: [{ originalCode, transformedCode, atoms }]
63
+ };
64
+ }
65
+ function crossBundleInputFrom(loaded) {
66
+ const sourceFiles = [];
67
+ for (const entry of loaded.loaded) {
68
+ if (entry.sourceFile !== undefined) {
69
+ sourceFiles.push(entry.sourceFile);
70
+ }
71
+ }
72
+ return {
73
+ bundle: loaded.input.bundle,
74
+ sourceFiles,
75
+ fileBindings: loaded.fileBindings,
76
+ localReachable: loaded.reachability.localReachable
77
+ };
78
+ }
79
+ function recomposePairedSourceMaps(contents, transformsByMapPath) {
80
+ return contents.map((resource) => {
81
+ const transform = transformsByMapPath.get(resource.fileDescription.targetFilePath);
82
+ if (transform === undefined) {
83
+ return resource;
84
+ }
85
+ const recomposed = recomposeSourceMap({
86
+ originalMap: resource.fileDescription.content,
87
+ originalCode: transform.originalCode,
88
+ transformedCode: transform.transformedCode,
89
+ atoms: transform.atoms
90
+ });
91
+ return {
92
+ ...resource,
93
+ fileDescription: { ...resource.fileDescription, content: recomposed }
94
+ };
95
+ });
96
+ }
97
+ function buildMapPathTransformIndex(outputs) {
98
+ return new Map(outputs.flatMap((output) => {
99
+ return output.transforms.map((transform) => {
100
+ return [`${output.resource.fileDescription.targetFilePath}.map`, transform];
101
+ });
102
+ }));
103
+ }
104
+ function analyzeBundleWithSeeds(loaded, externalSeeds) {
105
+ const context = {
106
+ reachable: loaded.reachability.expandWith(externalSeeds),
107
+ transformationsEnabled: loaded.input.transformationsEnabled
108
+ };
109
+ const outputs = loaded.loaded.map((entry) => {
110
+ return buildAnalyzedResource(entry, context);
111
+ });
112
+ const transformsByMapPath = buildMapPathTransformIndex(outputs);
113
+ const contents = outputs.map((output) => {
114
+ return output.resource;
115
+ });
116
+ const finalContents = recomposePairedSourceMaps(contents, transformsByMapPath);
117
+ return {
118
+ ...loaded.input.bundle,
119
+ contents: finalContents,
120
+ sideEffectsField: computeSideEffectsField(finalContents)
121
+ };
122
+ }
123
+ export function createDeadCodeEliminator(dependencies) {
124
+ const { createProject, progressBroadcaster } = dependencies;
125
+ return {
126
+ async eliminate(inputs) {
127
+ const loadedBundles = inputs.map((input) => {
128
+ return loadBundle(createProject, input);
129
+ });
130
+ const seedMap = buildCrossBundleSeeds(loadedBundles.map(crossBundleInputFrom));
131
+ const analyzed = loadedBundles.map((loaded) => {
132
+ return analyzeBundleWithSeeds(loaded, seedMap.get(loaded.input.bundle.name));
133
+ });
134
+ maybeEmitElimination(progressBroadcaster, inputs.map((input) => {
135
+ return input.bundle;
136
+ }), analyzed);
137
+ return analyzed;
138
+ }
139
+ };
140
+ }
141
+ //# sourceMappingURL=eliminator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eliminator.js","sourceRoot":"","sources":["../../../../source/dead-code-eliminator/eliminator.ts"],"names":[],"mappings":"AACA,OAAO,EACH,uBAAuB,EAK1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,sCAAsC,CAAC;AACpG,OAAO,EACH,UAAU,EAKb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAqB,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAIxE,SAAS,kBAAkB,CAAC,MAA0B;IAClD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,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,CAAC,MAAM;YAClB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;gBACvC,OAAO,UAAU,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAC5C,CAAC,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,qBAAqB,CAAC,aAAa,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC/E,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC1C,OAAO,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACjF,CAAC,CAAC,CAAC;YACH,oBAAoB,CAChB,mBAAmB,EACnB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;gBACjB,OAAO,KAAK,CAAC,MAAM,CAAC;YACxB,CAAC,CAAC,EACF,QAAQ,CACX,CAAC;YACF,OAAO,QAAQ,CAAC;QACpB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { isCodeFile } from "../common/code-files.js";
2
+ import { getPublicRootIds } from "../package-surface/modules.js";
3
+ import { extractTopLevelBindings } from "./reachability/binding-extractor.js";
4
+ import { buildReachabilityIndex } from "./reachability/reachability.js";
5
+ function loadResource(project, resource) {
6
+ if (!isCodeFile(resource.fileDescription.targetFilePath)) {
7
+ return { resource };
8
+ }
9
+ const sourceFile = project.createSourceFile(resource.fileDescription.sourceFilePath, resource.fileDescription.content);
10
+ return { resource, sourceFile, bindings: extractTopLevelBindings(sourceFile) };
11
+ }
12
+ function buildFileBindings(loaded) {
13
+ const result = [];
14
+ for (const entry of loaded) {
15
+ if (entry.sourceFile !== undefined) {
16
+ result.push({
17
+ sourceFilePath: entry.resource.fileDescription.sourceFilePath,
18
+ sourceFile: entry.sourceFile,
19
+ bindings: entry.bindings
20
+ });
21
+ }
22
+ }
23
+ return result;
24
+ }
25
+ function publicRootFilePathsFor(bundle) {
26
+ const publicRootIds = getPublicRootIds(bundle);
27
+ const paths = new Set();
28
+ for (const rootId of publicRootIds) {
29
+ const root = bundle.roots[rootId];
30
+ if (root === undefined) {
31
+ throw new Error(`Bundle "${bundle.name}" is missing root "${rootId}" referenced by its public surface`);
32
+ }
33
+ paths.add(root.js.sourceFilePath);
34
+ if (root.declarationFile !== undefined) {
35
+ paths.add(root.declarationFile.sourceFilePath);
36
+ }
37
+ }
38
+ return paths;
39
+ }
40
+ export function loadBundle(createProject, input) {
41
+ const project = createProject();
42
+ const loaded = input.bundle.contents.map((resource) => {
43
+ return loadResource(project, resource);
44
+ });
45
+ const fileBindings = buildFileBindings(loaded);
46
+ const reachability = buildReachabilityIndex({
47
+ files: fileBindings,
48
+ entryPointFilePaths: publicRootFilePathsFor(input.bundle)
49
+ });
50
+ return { input, project, loaded, fileBindings, reachability };
51
+ }
52
+ //# sourceMappingURL=load-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-bundle.js","sourceRoot":"","sources":["../../../../source/dead-code-eliminator/load-bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAA0B,MAAM,qCAAqC,CAAC;AACtG,OAAO,EAAE,sBAAsB,EAA6C,MAAM,gCAAgC,CAAC;AAyBnH,SAAS,YAAY,CAAC,OAAgB,EAAE,QAA8B;IAClE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,CAAC;QACvD,OAAO,EAAE,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,UAAU,GAAG,OAAO,CAAC,gBAAgB,CACvC,QAAQ,CAAC,eAAe,CAAC,cAAc,EACvC,QAAQ,CAAC,eAAe,CAAC,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AAE,KAAuB;IAC5E,MAAM,OAAO,GAAG,aAAa,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAClD,OAAO,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,sBAAsB,CAAC;QACxC,KAAK,EAAE,YAAY;QACnB,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC;KAC5D,CAAC,CAAC;IACH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { Node as TsMorphNode } from 'ts-morph';
2
+ function isNamedDeclaration(statement) {
3
+ return (TsMorphNode.isFunctionDeclaration(statement) ||
4
+ TsMorphNode.isClassDeclaration(statement) ||
5
+ TsMorphNode.isInterfaceDeclaration(statement) ||
6
+ TsMorphNode.isTypeAliasDeclaration(statement) ||
7
+ TsMorphNode.isEnumDeclaration(statement) ||
8
+ TsMorphNode.isModuleDeclaration(statement));
9
+ }
10
+ function bindingsFromNamedDeclaration(statement) {
11
+ const name = statement.getName();
12
+ if (name === undefined) {
13
+ return [];
14
+ }
15
+ const isExported = statement.isExported() || statement.isDefaultExport();
16
+ return [{ name, isExported, statement, declarationNode: statement }];
17
+ }
18
+ function bindingsFromVariableStatement(statement) {
19
+ const isExported = statement.isExported();
20
+ return statement.getDeclarations().map((declarator) => {
21
+ return { name: declarator.getName(), isExported, statement, declarationNode: declarator };
22
+ });
23
+ }
24
+ function localNameOfNamedImport(namedImport) {
25
+ return namedImport.getAliasNode()?.getText() ?? namedImport.getName();
26
+ }
27
+ function bindingsFromImportDeclaration(statement) {
28
+ const result = [];
29
+ const defaultImport = statement.getDefaultImport();
30
+ if (defaultImport !== undefined) {
31
+ result.push({
32
+ name: defaultImport.getText(),
33
+ isExported: false,
34
+ statement,
35
+ declarationNode: defaultImport.getParent()
36
+ });
37
+ }
38
+ const namespaceImport = statement.getNamespaceImport();
39
+ if (namespaceImport !== undefined) {
40
+ result.push({
41
+ name: namespaceImport.getText(),
42
+ isExported: false,
43
+ statement,
44
+ declarationNode: namespaceImport.getParent()
45
+ });
46
+ }
47
+ for (const namedImport of statement.getNamedImports()) {
48
+ result.push({
49
+ name: localNameOfNamedImport(namedImport),
50
+ isExported: false,
51
+ statement,
52
+ declarationNode: namedImport
53
+ });
54
+ }
55
+ return result;
56
+ }
57
+ function bindingsFromExportAssignment(statement) {
58
+ if (statement.isExportEquals()) {
59
+ return [];
60
+ }
61
+ return [
62
+ {
63
+ name: 'default',
64
+ isExported: true,
65
+ statement,
66
+ declarationNode: statement
67
+ }
68
+ ];
69
+ }
70
+ function bindingsFromStatement(statement) {
71
+ if (isNamedDeclaration(statement)) {
72
+ return bindingsFromNamedDeclaration(statement);
73
+ }
74
+ if (TsMorphNode.isVariableStatement(statement)) {
75
+ return bindingsFromVariableStatement(statement);
76
+ }
77
+ if (TsMorphNode.isImportDeclaration(statement)) {
78
+ return bindingsFromImportDeclaration(statement);
79
+ }
80
+ if (TsMorphNode.isExportAssignment(statement)) {
81
+ return bindingsFromExportAssignment(statement);
82
+ }
83
+ return [];
84
+ }
85
+ export function extractTopLevelBindings(sourceFile) {
86
+ return sourceFile.getStatements().flatMap(bindingsFromStatement);
87
+ }
88
+ //# sourceMappingURL=binding-extractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding-extractor.js","sourceRoot":"","sources":["../../../../../source/dead-code-eliminator/reachability/binding-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,IAAI,WAAW,EAYtB,MAAM,UAAU,CAAC;AAiBlB,SAAS,kBAAkB,CAAC,SAAoB;IAC5C,OAAO,CACH,WAA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AAC,CAAC;IACpD,CAAC;IACD,IAAI,WAAW,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7C,OAAO,6BAA6B,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,OAAO,4BAA4B,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,UAAgC;IACpE,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Node as TsMorphNode } from 'ts-morph';
2
+ import { classifySideEffects } from "../side-effect-classifier.js";
3
+ export function collectImpureStatements(sourceFile) {
4
+ const impureLines = new Set();
5
+ for (const statement of classifySideEffects(sourceFile)) {
6
+ impureLines.add(statement.line);
7
+ }
8
+ return sourceFile.getStatements().filter((statement) => {
9
+ return impureLines.has(statement.getStartLineNumber()) && !TsMorphNode.isImportDeclaration(statement);
10
+ });
11
+ }
12
+ //# sourceMappingURL=impure-statements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"impure-statements.js","sourceRoot":"","sources":["../../../../../source/dead-code-eliminator/reachability/impure-statements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,WAAW,EAAmC,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,MAAM,UAAU,uBAAuB,CAAC,UAAgC;IACpE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,KAAK,MAAM,SAAS,IAAI,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,UAAU,CAAC,aAAa,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE;QACnD,OAAO,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC1G,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,141 @@
1
+ import { SyntaxKind } from 'ts-morph';
2
+ import { collectImpureStatements } from "./impure-statements.js";
3
+ export function bindingId(filePath, name) {
4
+ return `${filePath}::${name}`;
5
+ }
6
+ function buildDeclarationNodeIndex(files) {
7
+ const index = new Map();
8
+ for (const file of files) {
9
+ for (const binding of file.bindings) {
10
+ index.set(binding.declarationNode, bindingId(file.sourceFilePath, binding.name));
11
+ }
12
+ }
13
+ return index;
14
+ }
15
+ function buildBindingsByFile(files) {
16
+ const map = new Map();
17
+ for (const file of files) {
18
+ const ids = new Set();
19
+ for (const binding of file.bindings) {
20
+ ids.add(bindingId(file.sourceFilePath, binding.name));
21
+ }
22
+ map.set(file.sourceFilePath, ids);
23
+ }
24
+ return map;
25
+ }
26
+ function buildNodeById(files) {
27
+ const map = new Map();
28
+ for (const file of files) {
29
+ for (const binding of file.bindings) {
30
+ map.set(bindingId(file.sourceFilePath, binding.name), binding.declarationNode);
31
+ }
32
+ }
33
+ return map;
34
+ }
35
+ function addDeclarationTargets(declarations, declarationIndex, targets) {
36
+ for (const declaration of declarations) {
37
+ const candidate = declarationIndex.get(declaration);
38
+ if (candidate !== undefined) {
39
+ targets.add(candidate);
40
+ }
41
+ }
42
+ }
43
+ function addSymbolTargets(symbol, declarationIndex, targets) {
44
+ addDeclarationTargets(symbol.getDeclarations(), declarationIndex, targets);
45
+ const aliased = symbol.getAliasedSymbol();
46
+ if (aliased !== undefined) {
47
+ addDeclarationTargets(aliased.getDeclarations(), declarationIndex, targets);
48
+ }
49
+ }
50
+ function collectIdentifierTargets(rootNode, declarationIndex) {
51
+ const targets = new Set();
52
+ for (const identifier of rootNode.getDescendantsOfKind(SyntaxKind.Identifier)) {
53
+ const symbol = identifier.getSymbol();
54
+ if (symbol !== undefined) {
55
+ addSymbolTargets(symbol, declarationIndex, targets);
56
+ }
57
+ }
58
+ return targets;
59
+ }
60
+ function assertTraversalIteration(remainingIterations) {
61
+ if (remainingIterations === 0) {
62
+ throw new Error('Reachability traversal exceeded the maximum iteration budget');
63
+ }
64
+ }
65
+ function createTraversalBudget(maximumIterations) {
66
+ return Array.from({ length: maximumIterations + 1 }, (_value, index) => {
67
+ return maximumIterations - index;
68
+ });
69
+ }
70
+ function getMaximumTraversalIterations(initialVisitedSize, seedCount, maximumNodeCount) {
71
+ return initialVisitedSize + seedCount + maximumNodeCount * maximumNodeCount;
72
+ }
73
+ function createTraversalState(initialVisited, seedList) {
74
+ const visited = new Set([...initialVisited, ...seedList]);
75
+ return { visited, queue: Array.from(visited) };
76
+ }
77
+ function enqueueUnvisitedNeighbors(current, expand, visited, queue) {
78
+ for (const neighbor of expand(current)) {
79
+ if (!visited.has(neighbor)) {
80
+ visited.add(neighbor);
81
+ queue.push(neighbor);
82
+ }
83
+ }
84
+ }
85
+ function bfsClosure(seeds, expand, initialVisited, maximumNodeCount) {
86
+ const seedList = Array.from(seeds);
87
+ const maximumIterations = getMaximumTraversalIterations(initialVisited.size, seedList.length, maximumNodeCount);
88
+ const traversalState = createTraversalState(initialVisited, seedList);
89
+ for (const remainingIterations of createTraversalBudget(maximumIterations)) {
90
+ const current = traversalState.queue.shift();
91
+ if (current === undefined) {
92
+ break;
93
+ }
94
+ assertTraversalIteration(remainingIterations);
95
+ enqueueUnvisitedNeighbors(current, expand, traversalState.visited, traversalState.queue);
96
+ }
97
+ return traversalState.visited;
98
+ }
99
+ function addStatementSeeds(statements, declarationIndex, seeds) {
100
+ for (const statement of statements) {
101
+ for (const target of collectIdentifierTargets(statement, declarationIndex)) {
102
+ seeds.add(target);
103
+ }
104
+ }
105
+ }
106
+ function gatherLocalSeeds(files, entryPointFilePaths, declarationIndex) {
107
+ const seeds = new Set();
108
+ for (const file of files) {
109
+ const isEntry = entryPointFilePaths.has(file.sourceFilePath);
110
+ for (const binding of file.bindings) {
111
+ if (isEntry && binding.isExported) {
112
+ seeds.add(bindingId(file.sourceFilePath, binding.name));
113
+ }
114
+ }
115
+ addStatementSeeds(collectImpureStatements(file.sourceFile), declarationIndex, seeds);
116
+ }
117
+ return seeds;
118
+ }
119
+ const emptyStringSet = new Set();
120
+ export function buildReachabilityIndex(input) {
121
+ const declarationIndex = buildDeclarationNodeIndex(input.files);
122
+ const nodeById = buildNodeById(input.files);
123
+ const maximumNodeCount = nodeById.size;
124
+ const expand = (id) => {
125
+ const node = nodeById.get(id);
126
+ return node === undefined ? emptyStringSet : collectIdentifierTargets(node, declarationIndex);
127
+ };
128
+ const localSeeds = gatherLocalSeeds(input.files, input.entryPointFilePaths, declarationIndex);
129
+ const localReachable = bfsClosure(localSeeds, expand, emptyStringSet, maximumNodeCount);
130
+ return {
131
+ localReachable,
132
+ bindingIdsByFile: buildBindingsByFile(input.files),
133
+ expandWith(externalSeeds) {
134
+ if (externalSeeds === undefined || externalSeeds.size === 0) {
135
+ return localReachable;
136
+ }
137
+ return bfsClosure(externalSeeds, expand, localReachable, maximumNodeCount);
138
+ }
139
+ };
140
+ }
141
+ //# sourceMappingURL=reachability.js.map