tstyche 7.2.5 → 8.0.0-beta.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 (393) hide show
  1. package/README.md +4 -0
  2. package/dist/api.d.ts +16 -761
  3. package/dist/api.js +16 -6204
  4. package/dist/bin.js +2 -3
  5. package/dist/checker/BaseCheckerAdapter.d.ts +15 -0
  6. package/dist/checker/BaseCheckerAdapter.js +32 -0
  7. package/dist/checker/CompatCheckerAdapter.d.ts +70 -0
  8. package/dist/checker/CompatCheckerAdapter.js +221 -0
  9. package/dist/checker/NativeCheckerAdapter.d.ts +70 -0
  10. package/dist/checker/NativeCheckerAdapter.js +200 -0
  11. package/dist/checker/index.d.ts +3 -0
  12. package/dist/checker/index.js +2 -0
  13. package/dist/checker/types.d.ts +9 -0
  14. package/dist/checker/types.js +1 -0
  15. package/dist/cli/Cli.d.ts +5 -0
  16. package/dist/cli/Cli.js +144 -0
  17. package/dist/cli/CliDIagnosticText.d.ts +3 -0
  18. package/dist/cli/CliDIagnosticText.js +9 -0
  19. package/dist/cli/index.d.ts +1 -0
  20. package/dist/cli/index.js +1 -0
  21. package/dist/collect/CollectDiagnosticText.d.ts +3 -0
  22. package/dist/collect/CollectDiagnosticText.js +5 -0
  23. package/dist/collect/CollectService.d.ts +9 -0
  24. package/dist/collect/CollectService.js +150 -0
  25. package/dist/collect/ExpectNode.d.ts +16 -0
  26. package/dist/collect/ExpectNode.js +30 -0
  27. package/dist/collect/IdentifierLookup.d.ts +18 -0
  28. package/dist/collect/IdentifierLookup.js +90 -0
  29. package/dist/collect/TestTree.d.ts +16 -0
  30. package/dist/collect/TestTree.js +15 -0
  31. package/dist/collect/TestTreeNode.d.ts +15 -0
  32. package/dist/collect/TestTreeNode.js +27 -0
  33. package/dist/collect/TestTreeNodeBrand.enum.d.ts +6 -0
  34. package/dist/collect/TestTreeNodeBrand.enum.js +7 -0
  35. package/dist/collect/TestTreeNodeFlags.enum.d.ts +6 -0
  36. package/dist/collect/TestTreeNodeFlags.enum.js +7 -0
  37. package/dist/collect/index.d.ts +6 -0
  38. package/dist/collect/index.js +6 -0
  39. package/dist/config/CommandParser.d.ts +7 -0
  40. package/dist/config/CommandParser.js +107 -0
  41. package/dist/config/Config.d.ts +18 -0
  42. package/dist/config/Config.js +59 -0
  43. package/dist/config/ConfigDiagnosticText.d.ts +19 -0
  44. package/dist/config/ConfigDiagnosticText.js +57 -0
  45. package/dist/config/ConfigParser.d.ts +10 -0
  46. package/dist/config/ConfigParser.js +165 -0
  47. package/dist/config/Directive.d.ts +9 -0
  48. package/dist/config/Directive.js +119 -0
  49. package/dist/config/DirectiveDiagnosticText.d.ts +5 -0
  50. package/dist/config/DirectiveDiagnosticText.js +11 -0
  51. package/dist/config/OptionBrand.enum.d.ts +8 -0
  52. package/dist/config/OptionBrand.enum.js +9 -0
  53. package/dist/config/OptionGroup.enum.d.ts +5 -0
  54. package/dist/config/OptionGroup.enum.js +6 -0
  55. package/dist/config/Options.d.ts +29 -0
  56. package/dist/config/Options.js +290 -0
  57. package/dist/config/Target.d.ts +7 -0
  58. package/dist/config/Target.js +47 -0
  59. package/dist/config/defaultOptions.d.ts +2 -0
  60. package/dist/config/defaultOptions.js +14 -0
  61. package/dist/config/index.d.ts +8 -0
  62. package/dist/config/index.js +7 -0
  63. package/dist/config/types.d.ts +55 -0
  64. package/dist/config/types.js +1 -0
  65. package/dist/diagnostic/Diagnostic.d.ts +19 -0
  66. package/dist/diagnostic/Diagnostic.js +51 -0
  67. package/dist/diagnostic/DiagnosticCategory.enum.d.ts +4 -0
  68. package/dist/diagnostic/DiagnosticCategory.enum.js +5 -0
  69. package/dist/diagnostic/DiagnosticOrigin.d.ts +13 -0
  70. package/dist/diagnostic/DiagnosticOrigin.js +27 -0
  71. package/dist/diagnostic/helpers.d.ts +6 -0
  72. package/dist/diagnostic/helpers.js +74 -0
  73. package/dist/diagnostic/index.d.ts +5 -0
  74. package/dist/diagnostic/index.js +4 -0
  75. package/dist/diagnostic/types.d.ts +2 -0
  76. package/dist/diagnostic/types.js +1 -0
  77. package/dist/editor/TextEditor.d.ts +15 -0
  78. package/dist/editor/TextEditor.js +88 -0
  79. package/dist/editor/index.d.ts +2 -0
  80. package/dist/editor/index.js +1 -0
  81. package/dist/editor/types.d.ts +4 -0
  82. package/dist/editor/types.js +1 -0
  83. package/dist/environment/Environment.d.ts +5 -0
  84. package/dist/environment/Environment.js +89 -0
  85. package/dist/environment/environmentOptions.d.ts +1 -0
  86. package/dist/environment/environmentOptions.js +2 -0
  87. package/dist/environment/index.d.ts +2 -0
  88. package/dist/environment/index.js +1 -0
  89. package/dist/environment/types.d.ts +10 -0
  90. package/dist/environment/types.js +1 -0
  91. package/dist/events/EventEmitter.d.ts +14 -0
  92. package/dist/events/EventEmitter.js +42 -0
  93. package/dist/events/index.d.ts +2 -0
  94. package/dist/events/index.js +1 -0
  95. package/dist/events/types.d.ts +88 -0
  96. package/dist/events/types.js +1 -0
  97. package/dist/expect/AbilityMatcherBase.d.ts +16 -0
  98. package/dist/expect/AbilityMatcherBase.js +52 -0
  99. package/dist/expect/Ensure.d.ts +10 -0
  100. package/dist/expect/Ensure.js +51 -0
  101. package/dist/expect/ExpectDiagnosticText.d.ts +29 -0
  102. package/dist/expect/ExpectDiagnosticText.js +87 -0
  103. package/dist/expect/ExpectService.d.ts +21 -0
  104. package/dist/expect/ExpectService.js +90 -0
  105. package/dist/expect/RelationMatcherBase.d.ts +12 -0
  106. package/dist/expect/RelationMatcherBase.js +16 -0
  107. package/dist/expect/ToAcceptProps.d.ts +10 -0
  108. package/dist/expect/ToAcceptProps.js +52 -0
  109. package/dist/expect/ToBe.d.ts +13 -0
  110. package/dist/expect/ToBe.js +18 -0
  111. package/dist/expect/ToBeApplicable.d.ts +10 -0
  112. package/dist/expect/ToBeApplicable.js +72 -0
  113. package/dist/expect/ToBeAssignableFrom.d.ts +9 -0
  114. package/dist/expect/ToBeAssignableFrom.js +12 -0
  115. package/dist/expect/ToBeAssignableTo.d.ts +9 -0
  116. package/dist/expect/ToBeAssignableTo.js +12 -0
  117. package/dist/expect/ToBeCallableWith.d.ts +11 -0
  118. package/dist/expect/ToBeCallableWith.js +29 -0
  119. package/dist/expect/ToBeConstructableWith.d.ts +11 -0
  120. package/dist/expect/ToBeConstructableWith.js +29 -0
  121. package/dist/expect/ToBeInstantiableWith.d.ts +10 -0
  122. package/dist/expect/ToBeInstantiableWith.js +31 -0
  123. package/dist/expect/ToHaveProperty.d.ts +10 -0
  124. package/dist/expect/ToHaveProperty.js +59 -0
  125. package/dist/expect/ToRaiseError.d.ts +9 -0
  126. package/dist/expect/ToRaiseError.js +82 -0
  127. package/dist/expect/index.d.ts +2 -0
  128. package/dist/expect/index.js +1 -0
  129. package/dist/expect/types.d.ts +7 -0
  130. package/dist/expect/types.js +1 -0
  131. package/dist/file/FilePosition.d.ts +7 -0
  132. package/dist/file/FilePosition.js +16 -0
  133. package/dist/file/index.d.ts +1 -0
  134. package/dist/file/index.js +1 -0
  135. package/dist/glob/Braces.d.ts +4 -0
  136. package/dist/glob/Braces.js +56 -0
  137. package/dist/glob/Glob.d.ts +4 -0
  138. package/dist/glob/Glob.js +47 -0
  139. package/dist/glob/index.d.ts +1 -0
  140. package/dist/glob/index.js +1 -0
  141. package/dist/handlers/CancellationHandler.d.ts +7 -0
  142. package/dist/handlers/CancellationHandler.js +15 -0
  143. package/dist/handlers/ExitCodeHandler.d.ts +7 -0
  144. package/dist/handlers/ExitCodeHandler.js +20 -0
  145. package/dist/handlers/ResultHandler.d.ts +5 -0
  146. package/dist/handlers/ResultHandler.js +206 -0
  147. package/dist/handlers/index.d.ts +3 -0
  148. package/dist/handlers/index.js +3 -0
  149. package/dist/index.cjs +5 -5
  150. package/dist/index.d.cts +40 -45
  151. package/dist/index.d.ts +40 -45
  152. package/dist/index.js +1 -2
  153. package/dist/input/InputService.d.ts +6 -0
  154. package/dist/input/InputService.js +16 -0
  155. package/dist/input/index.d.ts +1 -0
  156. package/dist/input/index.js +1 -0
  157. package/dist/json/JsonNode.d.ts +11 -0
  158. package/dist/json/JsonNode.js +28 -0
  159. package/dist/json/JsonScanner.d.ts +14 -0
  160. package/dist/json/JsonScanner.js +105 -0
  161. package/dist/json/index.d.ts +3 -0
  162. package/dist/json/index.js +2 -0
  163. package/dist/json/types.d.ts +1 -0
  164. package/dist/json/types.js +1 -0
  165. package/dist/layers/AbilityLayer.d.ts +10 -0
  166. package/dist/layers/AbilityLayer.js +186 -0
  167. package/dist/layers/Layers.d.ts +11 -0
  168. package/dist/layers/Layers.js +47 -0
  169. package/dist/layers/SuppressedLayer.d.ts +11 -0
  170. package/dist/layers/SuppressedLayer.js +93 -0
  171. package/dist/layers/index.d.ts +2 -0
  172. package/dist/layers/index.js +1 -0
  173. package/dist/layers/types.d.ts +8 -0
  174. package/dist/layers/types.js +1 -0
  175. package/dist/output/CodeFrameText.d.ts +10 -0
  176. package/dist/output/CodeFrameText.js +71 -0
  177. package/dist/output/OutputService.d.ts +13 -0
  178. package/dist/output/OutputService.js +38 -0
  179. package/dist/output/StreamController.d.ts +10 -0
  180. package/dist/output/StreamController.js +16 -0
  181. package/dist/output/addsText.d.ts +4 -0
  182. package/dist/output/addsText.js +8 -0
  183. package/dist/output/describeNameText.d.ts +2 -0
  184. package/dist/output/describeNameText.js +5 -0
  185. package/dist/output/diagnosticText.d.ts +4 -0
  186. package/dist/output/diagnosticText.js +23 -0
  187. package/dist/output/dotText.d.ts +3 -0
  188. package/dist/output/dotText.js +11 -0
  189. package/dist/output/fileStatusText.d.ts +4 -0
  190. package/dist/output/fileStatusText.js +26 -0
  191. package/dist/output/formattedText.d.ts +2 -0
  192. package/dist/output/formattedText.js +19 -0
  193. package/dist/output/helpText.d.ts +3 -0
  194. package/dist/output/helpText.js +52 -0
  195. package/dist/output/helpers.d.ts +5 -0
  196. package/dist/output/helpers.js +23 -0
  197. package/dist/output/index.d.ts +16 -0
  198. package/dist/output/index.js +15 -0
  199. package/dist/output/prologueText.d.ts +2 -0
  200. package/dist/output/prologueText.js +5 -0
  201. package/dist/output/summaryText.d.ts +12 -0
  202. package/dist/output/summaryText.js +31 -0
  203. package/dist/output/testNameText.d.ts +3 -0
  204. package/dist/output/testNameText.js +24 -0
  205. package/dist/output/types.d.ts +5 -0
  206. package/dist/output/types.js +1 -0
  207. package/dist/output/usesText.d.ts +5 -0
  208. package/dist/output/usesText.js +22 -0
  209. package/dist/output/waitingForFileChangesText.d.ts +2 -0
  210. package/dist/output/waitingForFileChangesText.js +5 -0
  211. package/dist/output/watchUsageText.d.ts +2 -0
  212. package/dist/output/watchUsageText.js +12 -0
  213. package/dist/path/Path.d.ts +7 -0
  214. package/dist/path/Path.js +28 -0
  215. package/dist/path/index.d.ts +1 -0
  216. package/dist/path/index.js +1 -0
  217. package/dist/project/CompatMappedDiagnostic.d.ts +12 -0
  218. package/dist/project/CompatMappedDiagnostic.js +25 -0
  219. package/dist/project/CompatProjectService.d.ts +19 -0
  220. package/dist/project/CompatProjectService.js +188 -0
  221. package/dist/project/FileMapService.d.ts +6 -0
  222. package/dist/project/FileMapService.js +14 -0
  223. package/dist/project/NativeMappedDiagnostic.d.ts +14 -0
  224. package/dist/project/NativeMappedDiagnostic.js +29 -0
  225. package/dist/project/NativeProjectService.d.ts +21 -0
  226. package/dist/project/NativeProjectService.js +216 -0
  227. package/dist/project/ProjectConfigService.d.ts +8 -0
  228. package/dist/project/ProjectConfigService.js +73 -0
  229. package/dist/project/index.d.ts +3 -0
  230. package/dist/project/index.js +2 -0
  231. package/dist/project/types.d.ts +7 -0
  232. package/dist/project/types.js +1 -0
  233. package/dist/reject/Reject.d.ts +9 -0
  234. package/dist/reject/Reject.js +43 -0
  235. package/dist/reject/RejectDiagnosticText.d.ts +5 -0
  236. package/dist/reject/RejectDiagnosticText.js +16 -0
  237. package/dist/reject/helpers.d.ts +1 -0
  238. package/dist/reject/helpers.js +3 -0
  239. package/dist/reject/index.d.ts +1 -0
  240. package/dist/reject/index.js +1 -0
  241. package/dist/reporters/BaseReporter.d.ts +7 -0
  242. package/dist/reporters/BaseReporter.js +6 -0
  243. package/dist/reporters/DotReporter.d.ts +6 -0
  244. package/dist/reporters/DotReporter.js +51 -0
  245. package/dist/reporters/FileView.d.ts +13 -0
  246. package/dist/reporters/FileView.js +33 -0
  247. package/dist/reporters/ListReporter.d.ts +6 -0
  248. package/dist/reporters/ListReporter.js +125 -0
  249. package/dist/reporters/SetupReporter.d.ts +4 -0
  250. package/dist/reporters/SetupReporter.js +21 -0
  251. package/dist/reporters/SummaryReporter.d.ts +5 -0
  252. package/dist/reporters/SummaryReporter.js +19 -0
  253. package/dist/reporters/WatchReporter.d.ts +5 -0
  254. package/dist/reporters/WatchReporter.js +21 -0
  255. package/dist/reporters/index.d.ts +7 -0
  256. package/dist/reporters/index.js +6 -0
  257. package/dist/reporters/types.d.ts +5 -0
  258. package/dist/reporters/types.js +1 -0
  259. package/dist/result/DescribeResult.d.ts +9 -0
  260. package/dist/result/DescribeResult.js +11 -0
  261. package/dist/result/ExpectResult.d.ts +10 -0
  262. package/dist/result/ExpectResult.js +11 -0
  263. package/dist/result/FileResult.d.ts +15 -0
  264. package/dist/result/FileResult.js +13 -0
  265. package/dist/result/ProjectConfigKind.enum.d.ts +6 -0
  266. package/dist/result/ProjectConfigKind.enum.js +7 -0
  267. package/dist/result/ProjectResult.d.ts +8 -0
  268. package/dist/result/ProjectResult.js +9 -0
  269. package/dist/result/Result.d.ts +13 -0
  270. package/dist/result/Result.js +14 -0
  271. package/dist/result/ResultStatus.enum.d.ts +10 -0
  272. package/dist/result/ResultStatus.enum.js +11 -0
  273. package/dist/result/SuppressedResult.d.ts +5 -0
  274. package/dist/result/SuppressedResult.js +6 -0
  275. package/dist/result/TargetResult.d.ts +11 -0
  276. package/dist/result/TargetResult.js +12 -0
  277. package/dist/result/TestResult.d.ts +13 -0
  278. package/dist/result/TestResult.js +13 -0
  279. package/dist/result/helpers.d.ts +7 -0
  280. package/dist/result/helpers.js +21 -0
  281. package/dist/result/index.d.ts +11 -0
  282. package/dist/result/index.js +10 -0
  283. package/dist/result/types.d.ts +31 -0
  284. package/dist/result/types.js +1 -0
  285. package/dist/runner/FileRunner.d.ts +10 -0
  286. package/dist/runner/FileRunner.js +93 -0
  287. package/dist/runner/FixmeDiagnosticText.d.ts +4 -0
  288. package/dist/runner/FixmeDiagnosticText.js +8 -0
  289. package/dist/runner/FixmeService.d.ts +9 -0
  290. package/dist/runner/FixmeService.js +51 -0
  291. package/dist/runner/RunModeFlags.enum.d.ts +7 -0
  292. package/dist/runner/RunModeFlags.enum.js +8 -0
  293. package/dist/runner/Runner.d.ts +9 -0
  294. package/dist/runner/Runner.js +101 -0
  295. package/dist/runner/TestTreeWalker.d.ts +19 -0
  296. package/dist/runner/TestTreeWalker.js +169 -0
  297. package/dist/runner/index.d.ts +1 -0
  298. package/dist/runner/index.js +1 -0
  299. package/dist/scribbler/Color.enum.d.ts +10 -0
  300. package/dist/scribbler/Color.enum.js +11 -0
  301. package/dist/scribbler/Line.d.ts +9 -0
  302. package/dist/scribbler/Line.js +5 -0
  303. package/dist/scribbler/Scribbler.d.ts +10 -0
  304. package/dist/scribbler/Scribbler.js +53 -0
  305. package/dist/scribbler/Text.d.ts +9 -0
  306. package/dist/scribbler/Text.js +8 -0
  307. package/dist/scribbler/index.d.ts +5 -0
  308. package/dist/scribbler/index.js +4 -0
  309. package/dist/scribbler/jsxRuntime.d.ts +4 -0
  310. package/dist/scribbler/jsxRuntime.js +4 -0
  311. package/dist/scribbler/types.d.ts +19 -0
  312. package/dist/scribbler/types.js +1 -0
  313. package/dist/select/Select.d.ts +7 -0
  314. package/dist/select/Select.js +91 -0
  315. package/dist/select/SelectDiagnosticText.d.ts +6 -0
  316. package/dist/select/SelectDiagnosticText.js +24 -0
  317. package/dist/select/index.d.ts +2 -0
  318. package/dist/select/index.js +2 -0
  319. package/dist/store/Fetcher.d.ts +8 -0
  320. package/dist/store/Fetcher.js +52 -0
  321. package/dist/store/Lock.d.ts +5 -0
  322. package/dist/store/Lock.js +17 -0
  323. package/dist/store/LockService.d.ts +8 -0
  324. package/dist/store/LockService.js +36 -0
  325. package/dist/store/Manifest.d.ts +35 -0
  326. package/dist/store/Manifest.js +58 -0
  327. package/dist/store/ManifestService.d.ts +10 -0
  328. package/dist/store/ManifestService.js +129 -0
  329. package/dist/store/PackageService.d.ts +8 -0
  330. package/dist/store/PackageService.js +69 -0
  331. package/dist/store/Store.d.ts +12 -0
  332. package/dist/store/Store.js +103 -0
  333. package/dist/store/StoreDiagnosticText.d.ts +12 -0
  334. package/dist/store/StoreDiagnosticText.js +36 -0
  335. package/dist/store/TarReader.d.ts +9 -0
  336. package/dist/store/TarReader.js +56 -0
  337. package/dist/store/helpers.d.ts +1 -0
  338. package/dist/store/helpers.js +3 -0
  339. package/dist/store/index.d.ts +1 -0
  340. package/dist/store/index.js +1 -0
  341. package/dist/structure/ComparisonResult.enum.d.ts +5 -0
  342. package/dist/structure/ComparisonResult.enum.js +6 -0
  343. package/dist/structure/Structure.d.ts +24 -0
  344. package/dist/structure/Structure.js +481 -0
  345. package/dist/structure/index.d.ts +1 -0
  346. package/dist/structure/index.js +1 -0
  347. package/dist/suppressed/SuppressedDiagnosticText.d.ts +6 -0
  348. package/dist/suppressed/SuppressedDiagnosticText.js +18 -0
  349. package/dist/suppressed/SuppressedService.d.ts +5 -0
  350. package/dist/suppressed/SuppressedService.js +61 -0
  351. package/dist/suppressed/index.d.ts +1 -0
  352. package/dist/suppressed/index.js +1 -0
  353. package/dist/tag.d.ts +1 -3
  354. package/dist/tag.js +2 -5
  355. package/dist/text/TextFile.d.ts +11 -0
  356. package/dist/text/TextFile.js +41 -0
  357. package/dist/text/TextFileService.d.ts +10 -0
  358. package/dist/text/TextFileService.js +31 -0
  359. package/dist/text/index.d.ts +3 -0
  360. package/dist/text/index.js +2 -0
  361. package/dist/text/types.d.ts +5 -0
  362. package/dist/text/types.js +1 -0
  363. package/dist/token/CancellationReason.enum.d.ts +6 -0
  364. package/dist/token/CancellationReason.enum.js +7 -0
  365. package/dist/token/CancellationToken.d.ts +8 -0
  366. package/dist/token/CancellationToken.js +22 -0
  367. package/dist/token/index.d.ts +2 -0
  368. package/dist/token/index.js +2 -0
  369. package/dist/typescript/BaseAdapter.d.ts +36 -0
  370. package/dist/typescript/BaseAdapter.js +83 -0
  371. package/dist/typescript/CompatTypeScript.d.ts +21 -0
  372. package/dist/typescript/CompatTypeScript.js +37 -0
  373. package/dist/typescript/NativeTypeScript.d.ts +24 -0
  374. package/dist/typescript/NativeTypeScript.js +44 -0
  375. package/dist/typescript/index.d.ts +3 -0
  376. package/dist/typescript/index.js +2 -0
  377. package/dist/typescript/types.d.ts +69 -0
  378. package/dist/typescript/types.js +1 -0
  379. package/dist/version/Version.d.ts +6 -0
  380. package/dist/version/Version.js +30 -0
  381. package/dist/version/index.d.ts +1 -0
  382. package/dist/version/index.js +1 -0
  383. package/dist/watch/Debounce.d.ts +9 -0
  384. package/dist/watch/Debounce.js +27 -0
  385. package/dist/watch/FileWatcher.d.ts +5 -0
  386. package/dist/watch/FileWatcher.js +12 -0
  387. package/dist/watch/WatchService.d.ts +8 -0
  388. package/dist/watch/WatchService.js +96 -0
  389. package/dist/watch/Watcher.d.ts +10 -0
  390. package/dist/watch/Watcher.js +31 -0
  391. package/dist/watch/index.d.ts +3 -0
  392. package/dist/watch/index.js +3 -0
  393. package/package.json +9 -1
@@ -0,0 +1,52 @@
1
+ import process from "node:process";
2
+ import { sleep } from "./helpers.js";
3
+ import { StoreDiagnosticText } from "./StoreDiagnosticText.js";
4
+ export class Fetcher {
5
+ #onDiagnostics;
6
+ #retries;
7
+ #timeout;
8
+ constructor(onDiagnostics, retries, timeout) {
9
+ this.#onDiagnostics = onDiagnostics;
10
+ this.#retries = retries;
11
+ this.#timeout = timeout;
12
+ }
13
+ async get(request, diagnostic, options) {
14
+ let delay = 3000;
15
+ request.headers.set("User-Agent", `tstyche/8.0.0-beta.0 ${process.platform} ${process.arch}`);
16
+ for (let attempt = 0; attempt <= this.#retries; attempt++) {
17
+ const isLastAttempt = attempt === this.#retries;
18
+ const suppressErrors = options?.suppressErrors || !isLastAttempt;
19
+ try {
20
+ const response = await fetch(request, { signal: AbortSignal.timeout(this.#timeout) });
21
+ if (response.ok) {
22
+ return response;
23
+ }
24
+ if (response.status >= 400 && response.status < 500 && response.status !== 429) {
25
+ if (options?.suppressErrors) {
26
+ return;
27
+ }
28
+ this.#onDiagnostics(diagnostic().extendWith(StoreDiagnosticText.requestFailed(response.status)));
29
+ return;
30
+ }
31
+ if (!suppressErrors) {
32
+ this.#onDiagnostics(diagnostic().extendWith(StoreDiagnosticText.requestFailed(response.status)));
33
+ }
34
+ }
35
+ catch (error) {
36
+ if (!suppressErrors) {
37
+ if (error instanceof Error && error.name === "TimeoutError") {
38
+ this.#onDiagnostics(diagnostic().extendWith(StoreDiagnosticText.requestTimeoutWasExceeded(this.#timeout)));
39
+ }
40
+ else {
41
+ this.#onDiagnostics(diagnostic().extendWith(StoreDiagnosticText.networkFailure(this.#retries)));
42
+ }
43
+ }
44
+ }
45
+ if (!isLastAttempt) {
46
+ await sleep(delay);
47
+ delay *= 2;
48
+ }
49
+ }
50
+ return;
51
+ }
52
+ }
@@ -0,0 +1,5 @@
1
+ export declare class Lock {
2
+ #private;
3
+ constructor(lockFilePath: string);
4
+ release(): void;
5
+ }
@@ -0,0 +1,17 @@
1
+ import { mkdirSync, rmSync, writeFileSync } from "node:fs";
2
+ import process from "node:process";
3
+ import { Path } from "#path";
4
+ export class Lock {
5
+ #lockFilePath;
6
+ constructor(lockFilePath) {
7
+ this.#lockFilePath = lockFilePath;
8
+ mkdirSync(Path.dirname(this.#lockFilePath), { recursive: true });
9
+ writeFileSync(this.#lockFilePath, "");
10
+ process.on("exit", () => {
11
+ this.release();
12
+ });
13
+ }
14
+ release() {
15
+ rmSync(this.#lockFilePath, { force: true });
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { Diagnostic, DiagnosticsHandler } from "#diagnostic";
2
+ import { Lock } from "./Lock.js";
3
+ export declare class LockService {
4
+ #private;
5
+ constructor(onDiagnostics: DiagnosticsHandler, timeout: number);
6
+ getLock(targetPath: string): Lock;
7
+ isLocked(targetPath: string, diagnostic: () => Diagnostic): Promise<boolean>;
8
+ }
@@ -0,0 +1,36 @@
1
+ import { existsSync } from "node:fs";
2
+ import { sleep } from "./helpers.js";
3
+ import { Lock } from "./Lock.js";
4
+ import { StoreDiagnosticText } from "./StoreDiagnosticText.js";
5
+ export class LockService {
6
+ #onDiagnostics;
7
+ #timeout;
8
+ constructor(onDiagnostics, timeout) {
9
+ this.#onDiagnostics = onDiagnostics;
10
+ this.#timeout = timeout;
11
+ }
12
+ #getLockFilePath(targetPath) {
13
+ return `${targetPath}__lock__`;
14
+ }
15
+ getLock(targetPath) {
16
+ const lockFilePath = this.#getLockFilePath(targetPath);
17
+ return new Lock(lockFilePath);
18
+ }
19
+ async isLocked(targetPath, diagnostic) {
20
+ const lockFilePath = this.#getLockFilePath(targetPath);
21
+ let isLocked = existsSync(lockFilePath);
22
+ if (!isLocked) {
23
+ return isLocked;
24
+ }
25
+ const waitStartTime = Date.now();
26
+ while (isLocked) {
27
+ if (Date.now() - waitStartTime > this.#timeout) {
28
+ this.#onDiagnostics(diagnostic().extendWith(StoreDiagnosticText.lockWaitTimeoutWasExceeded(this.#timeout)));
29
+ break;
30
+ }
31
+ await sleep(1000);
32
+ isLocked = existsSync(lockFilePath);
33
+ }
34
+ return isLocked;
35
+ }
36
+ }
@@ -0,0 +1,35 @@
1
+ export interface Resource {
2
+ integrity: string;
3
+ tarball: string;
4
+ }
5
+ export interface PackageResource extends Resource {
6
+ binary?: Resource & {
7
+ name: string;
8
+ };
9
+ }
10
+ export interface ManifestData {
11
+ $version?: string;
12
+ lastUpdated?: number;
13
+ minorVersions: Array<string>;
14
+ npmRegistry: string;
15
+ packages: Record<string, PackageResource>;
16
+ resolutions: Record<string, string>;
17
+ versions: Array<string>;
18
+ }
19
+ export declare class Manifest {
20
+ #private;
21
+ $version: string;
22
+ lastUpdated: number;
23
+ minorVersions: Array<string>;
24
+ npmRegistry: string;
25
+ packages: Record<string, PackageResource>;
26
+ resolutions: Record<string, string>;
27
+ versions: Array<string>;
28
+ constructor(data: ManifestData);
29
+ isOutdated(options?: {
30
+ ageTolerance?: number;
31
+ }): boolean;
32
+ static parse(text: string): Manifest | undefined;
33
+ resolve(tag: string): string | undefined;
34
+ stringify(): string;
35
+ }
@@ -0,0 +1,58 @@
1
+ export class Manifest {
2
+ static #version = "4";
3
+ $version;
4
+ lastUpdated;
5
+ minorVersions;
6
+ npmRegistry;
7
+ packages;
8
+ resolutions;
9
+ versions;
10
+ constructor(data) {
11
+ this.$version = data.$version ?? Manifest.#version;
12
+ this.lastUpdated = data.lastUpdated ?? Date.now();
13
+ this.minorVersions = data.minorVersions;
14
+ this.npmRegistry = data.npmRegistry;
15
+ this.packages = data.packages;
16
+ this.resolutions = data.resolutions;
17
+ this.versions = data.versions;
18
+ }
19
+ isOutdated(options) {
20
+ if (Date.now() - this.lastUpdated > 2 * 60 * 60 * 1000 + (options?.ageTolerance ?? 0) * 1000) {
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ static parse(text) {
26
+ let manifestData;
27
+ try {
28
+ manifestData = JSON.parse(text);
29
+ }
30
+ catch {
31
+ }
32
+ if (manifestData != null && manifestData.$version === Manifest.#version) {
33
+ return new Manifest(manifestData);
34
+ }
35
+ return;
36
+ }
37
+ resolve(tag) {
38
+ if (tag === "*") {
39
+ return this.resolutions["latest"];
40
+ }
41
+ if (this.versions.includes(tag)) {
42
+ return tag;
43
+ }
44
+ return this.resolutions[tag];
45
+ }
46
+ stringify() {
47
+ const manifestData = {
48
+ $version: this.$version,
49
+ lastUpdated: this.lastUpdated,
50
+ minorVersions: this.minorVersions,
51
+ npmRegistry: this.npmRegistry,
52
+ packages: this.packages,
53
+ resolutions: this.resolutions,
54
+ versions: this.versions,
55
+ };
56
+ return JSON.stringify(manifestData);
57
+ }
58
+ }
@@ -0,0 +1,10 @@
1
+ import type { Fetcher } from "./Fetcher.js";
2
+ import { Manifest } from "./Manifest.js";
3
+ export declare class ManifestService {
4
+ #private;
5
+ constructor(storePath: string, npmRegistry: string, fetcher: Fetcher);
6
+ open(options?: {
7
+ refresh?: boolean | undefined;
8
+ }): Promise<Manifest | undefined>;
9
+ prune(): Promise<void>;
10
+ }
@@ -0,0 +1,129 @@
1
+ import { existsSync } from "node:fs";
2
+ import fs from "node:fs/promises";
3
+ import process from "node:process";
4
+ import { Diagnostic } from "#diagnostic";
5
+ import { Path } from "#path";
6
+ import { Version } from "#version";
7
+ import { Manifest } from "./Manifest.js";
8
+ import { StoreDiagnosticText } from "./StoreDiagnosticText.js";
9
+ export class ManifestService {
10
+ #fetcher;
11
+ #manifestFilePath;
12
+ #npmRegistry;
13
+ #storePath;
14
+ constructor(storePath, npmRegistry, fetcher) {
15
+ this.#storePath = storePath;
16
+ this.#npmRegistry = npmRegistry;
17
+ this.#fetcher = fetcher;
18
+ this.#manifestFilePath = Path.join(storePath, "store-manifest.json");
19
+ }
20
+ async #create() {
21
+ const manifest = await this.#fetch();
22
+ if (manifest != null) {
23
+ await this.#persist(manifest);
24
+ }
25
+ return manifest;
26
+ }
27
+ async #fetchMetadata(packageSpecifier, options) {
28
+ const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchMetadata(this.#npmRegistry));
29
+ const request = new Request(new URL(packageSpecifier, this.#npmRegistry), {
30
+ headers: {
31
+ ["Accept"]: "application/vnd.npm.install-v1+json;q=1.0, application/json;q=0.8, */*",
32
+ },
33
+ });
34
+ const response = await this.#fetcher.get(request, diagnostic, { suppressErrors: options?.suppressErrors });
35
+ if (!response) {
36
+ return;
37
+ }
38
+ return (await response.json());
39
+ }
40
+ async #fetch(options) {
41
+ const packageMetadata = await this.#fetchMetadata("typescript", {
42
+ suppressErrors: options?.suppressErrors,
43
+ });
44
+ if (!packageMetadata) {
45
+ return;
46
+ }
47
+ const resolutions = {};
48
+ const packages = {};
49
+ const versions = [];
50
+ for (const [tag, meta] of Object.entries(packageMetadata.versions)) {
51
+ if (!tag.includes("-") && !tag.startsWith("7.0") && Version.isSatisfiedWith(tag, "5.4")) {
52
+ versions.push(tag);
53
+ packages[tag] = { integrity: meta.dist.integrity, tarball: meta.dist.tarball };
54
+ }
55
+ }
56
+ const minorVersions = [...new Set(versions.map((version) => version.slice(0, -2)))];
57
+ for (const tag of minorVersions) {
58
+ const resolvedVersion = versions.findLast((version) => version.startsWith(tag));
59
+ if (resolvedVersion != null) {
60
+ resolutions[tag] = resolvedVersion;
61
+ }
62
+ }
63
+ for (const tag of ["beta", "latest", "next", "rc"]) {
64
+ const version = packageMetadata["dist-tags"][tag];
65
+ if (version != null) {
66
+ resolutions[tag] = version;
67
+ const meta = packageMetadata.versions[version];
68
+ if (meta != null) {
69
+ packages[version] = { integrity: meta.dist.integrity, tarball: meta.dist.tarball };
70
+ }
71
+ }
72
+ }
73
+ for (const tag in packages) {
74
+ if (!Version.isSatisfiedWith(tag, "7.0")) {
75
+ continue;
76
+ }
77
+ const packageBinaryName = `@typescript/typescript-${process.platform}-${process.arch}`;
78
+ const packageBinaryVersion = packageMetadata.versions[tag]?.optionalDependencies?.[packageBinaryName];
79
+ if (!packageBinaryVersion) {
80
+ continue;
81
+ }
82
+ const packageSpecifier = `${packageBinaryName}/${packageBinaryVersion}`;
83
+ const versionMetadata = await this.#fetchMetadata(packageSpecifier, {
84
+ suppressErrors: options?.suppressErrors,
85
+ });
86
+ if (!versionMetadata) {
87
+ continue;
88
+ }
89
+ packages[tag].binary = {
90
+ name: packageBinaryName,
91
+ integrity: versionMetadata.dist.integrity,
92
+ tarball: versionMetadata.dist.tarball,
93
+ };
94
+ }
95
+ return new Manifest({
96
+ minorVersions,
97
+ npmRegistry: this.#npmRegistry,
98
+ packages,
99
+ resolutions,
100
+ versions,
101
+ });
102
+ }
103
+ async open(options) {
104
+ if (!existsSync(this.#manifestFilePath)) {
105
+ return this.#create();
106
+ }
107
+ const manifestText = await fs.readFile(this.#manifestFilePath, { encoding: "utf8" });
108
+ const manifest = Manifest.parse(manifestText);
109
+ if (!manifest || manifest.npmRegistry !== this.#npmRegistry) {
110
+ await this.prune();
111
+ return this.#create();
112
+ }
113
+ if (manifest.isOutdated() || options?.refresh) {
114
+ const freshManifest = await this.#fetch({ suppressErrors: !options?.refresh });
115
+ if (freshManifest != null) {
116
+ await this.#persist(freshManifest);
117
+ return freshManifest;
118
+ }
119
+ }
120
+ return manifest;
121
+ }
122
+ async #persist(manifest) {
123
+ await fs.mkdir(this.#storePath, { recursive: true });
124
+ await fs.writeFile(this.#manifestFilePath, manifest.stringify());
125
+ }
126
+ async prune() {
127
+ await fs.rm(this.#storePath, { force: true, recursive: true });
128
+ }
129
+ }
@@ -0,0 +1,8 @@
1
+ import type { Fetcher } from "./Fetcher.js";
2
+ import type { LockService } from "./LockService.js";
3
+ import type { Manifest } from "./Manifest.js";
4
+ export declare class PackageService {
5
+ #private;
6
+ constructor(storePath: string, fetcher: Fetcher, lockService: LockService);
7
+ ensure(packageVersion: string, manifest: Manifest): Promise<string | undefined>;
8
+ }
@@ -0,0 +1,69 @@
1
+ import { existsSync } from "node:fs";
2
+ import fs from "node:fs/promises";
3
+ import { pathToFileURL } from "node:url";
4
+ import { Diagnostic } from "#diagnostic";
5
+ import { EventEmitter } from "#events";
6
+ import { Path } from "#path";
7
+ import { StoreDiagnosticText } from "./StoreDiagnosticText.js";
8
+ import { TarReader } from "./TarReader.js";
9
+ export class PackageService {
10
+ #fetcher;
11
+ #lockService;
12
+ #storePath;
13
+ constructor(storePath, fetcher, lockService) {
14
+ this.#storePath = storePath;
15
+ this.#fetcher = fetcher;
16
+ this.#lockService = lockService;
17
+ }
18
+ async ensure(packageVersion, manifest) {
19
+ const packageSpecifier = `typescript@${packageVersion}`;
20
+ const packagePath = Path.join(this.#storePath, packageSpecifier);
21
+ const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchPackage(packageSpecifier));
22
+ if (await this.#lockService.isLocked(packagePath, diagnostic)) {
23
+ return;
24
+ }
25
+ if (!existsSync(packagePath)) {
26
+ EventEmitter.dispatch(["store:adds", { packagePath, packageVersion }]);
27
+ const resource = manifest.packages[packageVersion];
28
+ let success = await this.#fetch(packagePath, packageSpecifier, resource);
29
+ if (success && resource.binary) {
30
+ const binaryPackagePath = Path.join(packagePath, "node_modules", resource.binary.name);
31
+ const binaryPackageSpecifier = `${resource.binary.name}@${packageVersion}`;
32
+ success = await this.#fetch(binaryPackagePath, binaryPackageSpecifier, resource.binary);
33
+ }
34
+ if (!success) {
35
+ await fs.rm(packagePath, { recursive: true, force: true });
36
+ return;
37
+ }
38
+ }
39
+ return `${pathToFileURL(packagePath)}/`;
40
+ }
41
+ async #fetch(packagePath, packageSpecifier, resource) {
42
+ const diagnostic = () => Diagnostic.error(StoreDiagnosticText.failedToFetchPackage(packageSpecifier));
43
+ const lock = this.#lockService.getLock(packagePath);
44
+ try {
45
+ const request = new Request(resource.tarball, { integrity: resource.integrity });
46
+ const response = await this.#fetcher.get(request, diagnostic);
47
+ if (!response?.body) {
48
+ return false;
49
+ }
50
+ const targetPath = await fs.mkdtemp(`${packagePath}-`);
51
+ const stream = response.body.pipeThrough(new DecompressionStream("gzip"));
52
+ const tarReader = new TarReader(stream);
53
+ for await (const file of tarReader.extract()) {
54
+ const filePath = Path.join(targetPath, file.name.replace(/^package\//, ""));
55
+ const directoryPath = Path.dirname(filePath);
56
+ await fs.mkdir(directoryPath, { recursive: true });
57
+ await fs.writeFile(filePath, file.content);
58
+ if ((file.mode & fs.constants.S_IXUSR) !== 0) {
59
+ await fs.chmod(filePath, file.mode);
60
+ }
61
+ }
62
+ await fs.rename(targetPath, packagePath);
63
+ return true;
64
+ }
65
+ finally {
66
+ lock.release();
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,12 @@
1
+ import type * as ts from "#typescript";
2
+ import type { Manifest } from "./Manifest.js";
3
+ export declare class Store {
4
+ #private;
5
+ static manifest: Manifest | undefined;
6
+ static fetch(tag: string): Promise<void>;
7
+ static load(tag: string): Promise<ts.TypeScript | undefined>;
8
+ static open(): Promise<void>;
9
+ static prune(): Promise<void>;
10
+ static update(): Promise<void>;
11
+ static validateTag(tag: string): Promise<boolean | undefined>;
12
+ }
@@ -0,0 +1,103 @@
1
+ import fs from "node:fs/promises";
2
+ import { Diagnostic } from "#diagnostic";
3
+ import { environmentOptions } from "#environment";
4
+ import { EventEmitter } from "#events";
5
+ import { CompatTypeScript, NativeTypeScript } from "#typescript";
6
+ import { Version } from "#version";
7
+ import { Fetcher } from "./Fetcher.js";
8
+ import { LockService } from "./LockService.js";
9
+ import { ManifestService } from "./ManifestService.js";
10
+ import { PackageService } from "./PackageService.js";
11
+ import { StoreDiagnosticText } from "./StoreDiagnosticText.js";
12
+ export class Store {
13
+ static #fetcher;
14
+ static #lockService;
15
+ static manifest;
16
+ static #manifestService;
17
+ static #packageService;
18
+ static #npmRegistry = environmentOptions.npmRegistry;
19
+ static #fetchRetries = environmentOptions.fetchRetries;
20
+ static #fetchTimeout = environmentOptions.fetchTimeout * 1000;
21
+ static #storePath = environmentOptions.storePath;
22
+ static #supportedTags;
23
+ static {
24
+ Store.#fetcher = new Fetcher(Store.#onDiagnostics, Store.#fetchRetries, Store.#fetchTimeout);
25
+ Store.#lockService = new LockService(Store.#onDiagnostics, Store.#fetchTimeout);
26
+ Store.#packageService = new PackageService(Store.#storePath, Store.#fetcher, Store.#lockService);
27
+ Store.#manifestService = new ManifestService(Store.#storePath, Store.#npmRegistry, Store.#fetcher);
28
+ }
29
+ static async #ensure(tag) {
30
+ await Store.open();
31
+ const version = Store.manifest?.resolve(tag);
32
+ if (!version) {
33
+ Store.#onDiagnostics(Diagnostic.error(StoreDiagnosticText.cannotAddTypeScriptPackage(tag)));
34
+ return;
35
+ }
36
+ return await Store.#packageService.ensure(version, Store.manifest);
37
+ }
38
+ static async fetch(tag) {
39
+ if (tag === "*" && environmentOptions.typescriptSpecifier != null) {
40
+ return;
41
+ }
42
+ await Store.#ensure(tag);
43
+ }
44
+ static async #getAdapter(specifier) {
45
+ const packageJsonText = await fs.readFile(new URL("package.json", specifier), { encoding: "utf8" });
46
+ const packageJson = JSON.parse(packageJsonText);
47
+ if (packageJson.version.startsWith("7.0")) {
48
+ Store.#onDiagnostics(Diagnostic.error(StoreDiagnosticText.versionIsNotSupported()));
49
+ return;
50
+ }
51
+ if (Version.isSatisfiedWith(packageJson.version, "7")) {
52
+ const api = await import(new URL(packageJson.exports["./sync"], specifier).toString());
53
+ const ast = await import(new URL(packageJson.exports["./ast"], specifier).toString());
54
+ return new NativeTypeScript(api, ast, packageJson.version);
55
+ }
56
+ const compiler = (await import(new URL(packageJson.main, specifier).toString())).default;
57
+ return new CompatTypeScript(compiler, packageJson.version);
58
+ }
59
+ static async load(tag) {
60
+ if (tag === "*" && environmentOptions.typescriptSpecifier != null) {
61
+ return Store.#getAdapter(environmentOptions.typescriptSpecifier);
62
+ }
63
+ const specifier = await Store.#ensure(tag);
64
+ if (!specifier) {
65
+ return;
66
+ }
67
+ return Store.#getAdapter(specifier);
68
+ }
69
+ static #onDiagnostics(diagnostic) {
70
+ EventEmitter.dispatch(["store:error", { diagnostics: [diagnostic] }]);
71
+ }
72
+ static async open() {
73
+ if (Store.manifest != null) {
74
+ return;
75
+ }
76
+ Store.manifest = await Store.#manifestService.open();
77
+ if (Store.manifest != null) {
78
+ Store.#supportedTags = [...Object.keys(Store.manifest.resolutions), ...Store.manifest.versions];
79
+ }
80
+ }
81
+ static async prune() {
82
+ await Store.#manifestService.prune();
83
+ }
84
+ static async update() {
85
+ await Store.#manifestService.open({ refresh: true });
86
+ }
87
+ static async validateTag(tag) {
88
+ if (tag === "*") {
89
+ return true;
90
+ }
91
+ await Store.open();
92
+ if (Store.manifest?.isOutdated({ ageTolerance: 60 }) &&
93
+ (!/^\d/.test(tag) ||
94
+ (Store.manifest.resolutions["latest"] != null &&
95
+ Version.isGreaterThan(tag, Store.manifest.resolutions["latest"])))) {
96
+ Store.#onDiagnostics(Diagnostic.warning([
97
+ StoreDiagnosticText.failedToUpdateMetadata(Store.#npmRegistry),
98
+ StoreDiagnosticText.maybeOutdatedResolution(tag),
99
+ ]));
100
+ }
101
+ return Store.#supportedTags?.includes(tag);
102
+ }
103
+ }
@@ -0,0 +1,12 @@
1
+ export declare class StoreDiagnosticText {
2
+ static cannotAddTypeScriptPackage(tag: string): string;
3
+ static failedToFetchMetadata(registry: string): string;
4
+ static failedToFetchPackage(packageSpecifier: string): string;
5
+ static failedToUpdateMetadata(registry: string): string;
6
+ static maybeOutdatedResolution(tag: string): string;
7
+ static networkFailure(retries: number): string;
8
+ static requestFailed(code: number): string;
9
+ static requestTimeoutWasExceeded(timeout: number): string;
10
+ static lockWaitTimeoutWasExceeded(timeout: number): string;
11
+ static versionIsNotSupported(): Array<string>;
12
+ }
@@ -0,0 +1,36 @@
1
+ export class StoreDiagnosticText {
2
+ static cannotAddTypeScriptPackage(tag) {
3
+ return `Cannot add the 'typescript' package for the '${tag}' tag.`;
4
+ }
5
+ static failedToFetchMetadata(registry) {
6
+ return `Failed to fetch metadata of the 'typescript' package from '${registry}'.`;
7
+ }
8
+ static failedToFetchPackage(packageSpecifier) {
9
+ return `Failed to fetch the '${packageSpecifier}' package.`;
10
+ }
11
+ static failedToUpdateMetadata(registry) {
12
+ return `Failed to update metadata of the 'typescript' package from '${registry}'.`;
13
+ }
14
+ static maybeOutdatedResolution(tag) {
15
+ return `The resolution of the '${tag}' tag may be outdated.`;
16
+ }
17
+ static networkFailure(retries) {
18
+ return `The network connection failed after ${retries + 1} attempts.`;
19
+ }
20
+ static requestFailed(code) {
21
+ return `The request failed with status code ${code}.`;
22
+ }
23
+ static requestTimeoutWasExceeded(timeout) {
24
+ return `The request timeout of ${timeout / 1000}s was exceeded.`;
25
+ }
26
+ static lockWaitTimeoutWasExceeded(timeout) {
27
+ return `Lock wait timeout of ${timeout / 1000}s was exceeded.`;
28
+ }
29
+ static versionIsNotSupported() {
30
+ return [
31
+ "The installed TypeScript version 7.0 is not supported.",
32
+ "Please upgrade to TypeScript 7.1 or later.",
33
+ "Or use the '--target' command line option to specify a supported version explicitly.",
34
+ ];
35
+ }
36
+ }
@@ -0,0 +1,9 @@
1
+ export declare class TarReader {
2
+ #private;
3
+ constructor(stream: ReadableStream);
4
+ extract(): AsyncIterable<{
5
+ name: string;
6
+ mode: number;
7
+ content: Uint8Array;
8
+ }>;
9
+ }
@@ -0,0 +1,56 @@
1
+ export class TarReader {
2
+ #leftover = new Uint8Array(0);
3
+ #reader;
4
+ #textDecoder = new TextDecoder();
5
+ constructor(stream) {
6
+ this.#reader = stream.getReader();
7
+ }
8
+ async *extract() {
9
+ while (true) {
10
+ const header = await this.#read(512);
11
+ if (this.#isEndOfArchive(header)) {
12
+ break;
13
+ }
14
+ const name = this.#textDecoder.decode(header.subarray(0, 100)).replace(/\0.*$/, "");
15
+ const mode = Number.parseInt(this.#textDecoder.decode(header.subarray(100, 108)).replace(/\0.*$/, "").trim(), 8);
16
+ const sizeOctal = this.#textDecoder.decode(header.subarray(124, 136)).replace(/\0.*$/, "").trim();
17
+ const size = Number.parseInt(sizeOctal, 8);
18
+ const content = await this.#read(size);
19
+ yield { name, mode, content };
20
+ if (size % 512 !== 0) {
21
+ const toSkip = 512 - (size % 512);
22
+ await this.#read(toSkip);
23
+ }
24
+ }
25
+ }
26
+ #isEndOfArchive(entry) {
27
+ return entry.every((byte) => byte === 0);
28
+ }
29
+ async #read(n) {
30
+ const result = new Uint8Array(n);
31
+ let filled = 0;
32
+ if (this.#leftover.length > 0) {
33
+ const toCopy = Math.min(this.#leftover.length, n);
34
+ result.set(this.#leftover.subarray(0, toCopy), filled);
35
+ filled += toCopy;
36
+ this.#leftover = this.#leftover.subarray(toCopy);
37
+ if (filled === n) {
38
+ return result;
39
+ }
40
+ }
41
+ while (filled < n) {
42
+ const { value, done } = await this.#reader.read();
43
+ if (done) {
44
+ break;
45
+ }
46
+ const toCopy = Math.min(value.length, n - filled);
47
+ result.set(value.subarray(0, toCopy), filled);
48
+ filled += toCopy;
49
+ if (toCopy < value.length) {
50
+ this.#leftover = value.subarray(toCopy);
51
+ break;
52
+ }
53
+ }
54
+ return result.subarray(0, filled);
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export declare function sleep(delay: number): Promise<unknown>;