@glutinum/cli 0.14.0 → 1.0.0-beta.1

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 (182) hide show
  1. package/dist/Glutinum.Converter/FsharpAST.js +38 -4
  2. package/dist/Glutinum.Converter/Generate.js +15 -7
  3. package/dist/Glutinum.Converter/GlueAST.js +45 -36
  4. package/dist/Glutinum.Converter/Hosting.js +918 -0
  5. package/dist/Glutinum.Converter/Merge.js +218 -82
  6. package/dist/Glutinum.Converter/Packages.js +44 -8
  7. package/dist/Glutinum.Converter/Printer.js +77 -49
  8. package/dist/Glutinum.Converter/Read.js +8 -8
  9. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
  10. package/dist/Glutinum.Converter/Reader/Declaration.js +26 -26
  11. package/dist/Glutinum.Converter/Reader/Documentation.js +37 -36
  12. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +5 -5
  13. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +31 -19
  14. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +6 -7
  15. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +36 -29
  16. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
  17. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
  18. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
  19. package/dist/Glutinum.Converter/Reader/Node.js +20 -20
  20. package/dist/Glutinum.Converter/Reader/Parameters.js +7 -7
  21. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
  22. package/dist/Glutinum.Converter/Reader/TypeNode.js +291 -232
  23. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +8 -8
  24. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +108 -40
  25. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +2 -2
  26. package/dist/Glutinum.Converter/Reader/Types.js +6 -6
  27. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +7 -6
  28. package/dist/Glutinum.Converter/Reader/Utils.js +106 -56
  29. package/dist/Glutinum.Converter/Transform.js +2057 -700
  30. package/dist/Glutinum.Converter/TypeScript.Extensions.js +194 -202
  31. package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
  32. package/dist/Glutinum.Converter/Utils/String.js +2 -2
  33. package/dist/Program.js +38 -26
  34. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
  35. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
  36. package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
  37. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
  38. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
  39. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
  40. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
  41. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
  42. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
  43. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
  44. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
  45. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
  46. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
  47. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
  48. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
  49. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
  50. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
  51. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
  52. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
  53. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
  54. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
  55. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
  56. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
  57. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
  58. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
  59. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
  60. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
  61. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
  62. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
  63. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
  64. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
  65. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
  73. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
  74. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
  75. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
  76. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
  77. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
  78. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
  79. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
  80. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
  81. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
  82. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
  83. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
  84. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
  85. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
  86. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
  87. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
  88. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
  89. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
  90. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
  91. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
  92. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
  93. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
  94. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
  95. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
  96. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
  97. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
  98. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  99. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  100. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
  101. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  102. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
  103. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  104. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  105. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  106. package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
  107. package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
  108. package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
  109. package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
  110. package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
  111. package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
  112. package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
  113. package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
  114. package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
  115. package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
  116. package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
  117. package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
  118. package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
  119. package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
  120. package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
  121. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
  122. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
  123. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
  124. package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
  125. package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
  126. package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
  127. package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
  128. package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
  129. package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
  130. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
  131. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
  132. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
  133. package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
  134. package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
  135. package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
  136. package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
  137. package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
  138. package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
  139. package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
  140. package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
  141. package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
  142. package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
  143. package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
  144. package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
  145. package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
  146. package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
  147. package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
  148. package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
  149. package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
  150. package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
  151. package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
  152. package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
  153. package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
  154. package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
  155. package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
  156. package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
  157. package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
  158. package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
  159. package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
  160. package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
  161. package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
  162. package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
  163. package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
  164. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
  165. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
  166. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
  167. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
  168. package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
  169. package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
  170. package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
  171. package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
  172. package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
  173. package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
  174. package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
  175. package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
  176. package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
  177. package/package.json +2 -2
  178. package/dist/Glutinum.Converter/TypeScript.js +0 -12
  179. package/src/Glutinum.Converter/js/bootstrap.js +0 -123
  180. package/src/Glutinum.Converter/js/host.js +0 -144
  181. package/src/Glutinum.Converter/js/npm.js +0 -137
  182. package/src/Glutinum.Converter/js/resolve.js +0 -402
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glutinum/cli",
3
- "version": "0.14.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "TypeScript definition to F# bindings converter",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -51,7 +51,7 @@
51
51
  "vitest": "^1.5.0"
52
52
  },
53
53
  "dependencies": {
54
- "@ts-morph/bootstrap": "^0.22.0",
54
+ "@ts-morph/bootstrap": "^0.29.0",
55
55
  "chalk": "^5.3.0"
56
56
  }
57
57
  }
@@ -1,12 +0,0 @@
1
-
2
- import { class_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
3
-
4
- export class Ts_NoisTypeNodede {
5
- constructor() {
6
- }
7
- }
8
-
9
- export function Ts_NoisTypeNodede_$reflection() {
10
- return class_type("TypeScript.Ts.NoisTypeNodede", undefined, Ts_NoisTypeNodede);
11
- }
12
-
@@ -1,123 +0,0 @@
1
- import { createProjectSync, ts } from "@ts-morph/bootstrap";
2
- import { describePackage, findPackageDir } from "./resolve.js";
3
-
4
- /**
5
- *
6
- * @param {string} filePath
7
- * @param {string} source
8
- * @returns
9
- */
10
- export default function createProgramForCLI(filePath, source) {
11
-
12
- // `strict`, so that `T | undefined` is kept by the checker
13
- const project = createProjectSync({ compilerOptions: { strict: true } })
14
-
15
- project.createSourceFile(filePath, source)
16
-
17
- return project.createProgram()
18
- }
19
-
20
- /**
21
- * Create a program from declaration files of the host, following their imports.
22
- *
23
- * @param {import("./host.js").Host} host
24
- * @param {string[]} entryFiles
25
- * @param {{ withoutDomLib?: boolean, noLib?: boolean }} options
26
- * @returns
27
- */
28
- export function createProgramFromFiles(host, entryFiles, options = {}) {
29
- // ESNext, so that lib types such as `AsyncIterable` resolve instead of being left undefined.
30
- // `types: []` stops TypeScript from loading every package under `node_modules/@types`.
31
- // ESNext module + Bundler resolution: follows `exports` maps and node_modules
32
- const compilerOptions = { target: 99, module: 99, moduleResolution: 100, types: [], strict: true }
33
-
34
- // A package replacing the DOM lib (`@types/web`) redeclares its globals
35
- if (options.withoutDomLib) {
36
- compilerOptions.lib = ["lib.esnext.d.ts", "lib.decorators.d.ts", "lib.decorators.legacy.d.ts"]
37
- }
38
-
39
- // A package made of the ES library files declares the library itself
40
- if (options.noLib) {
41
- compilerOptions.noLib = true
42
- }
43
-
44
- const project = host.createProject(compilerOptions)
45
-
46
- for (const entryFile of entryFiles) {
47
- project.addSourceFileAtPathSync(entryFile)
48
- }
49
-
50
- project.resolveSourceFileDependencies()
51
-
52
- return project.createProgram()
53
- }
54
-
55
- /**
56
- * The files reachable from the entry files through imports and references, without
57
- * going through a package of `excludedRuntimeNames` (`node` for `@types/node`).
58
- *
59
- * @param {import("./host.js").Host} host
60
- * @param {import("typescript").Program} program
61
- * @param {string[]} entryFiles
62
- * @param {string[]} excludedRuntimeNames
63
- * @returns {string[]}
64
- */
65
- export function reachableFiles(host, program, entryFiles, excludedRuntimeNames) {
66
- const runtimeNames = new Map();
67
-
68
- const isExcluded = (fileName) => {
69
- const dir = findPackageDir(host, fileName);
70
-
71
- if (dir === null) {
72
- return false;
73
- }
74
-
75
- if (!runtimeNames.has(dir)) {
76
- const description = describePackage(host, dir);
77
- runtimeNames.set(dir, description === null ? null : description.runtimeName);
78
- }
79
-
80
- return excludedRuntimeNames.includes(runtimeNames.get(dir));
81
- };
82
-
83
- const seen = new Set();
84
- const queue = [...entryFiles];
85
-
86
- const visit = (fileName) => {
87
- if (fileName !== undefined && !seen.has(fileName) && !isExcluded(fileName)) {
88
- queue.push(fileName);
89
- }
90
- };
91
-
92
- while (queue.length > 0) {
93
- const fileName = queue.pop();
94
-
95
- if (seen.has(fileName)) {
96
- continue;
97
- }
98
-
99
- const sourceFile = program.getSourceFile(fileName);
100
-
101
- if (sourceFile === undefined) {
102
- continue;
103
- }
104
-
105
- seen.add(fileName);
106
-
107
- for (const usage of sourceFile.imports ?? []) {
108
- const mode = ts.getModeForUsageLocation(sourceFile, usage);
109
- visit(program.getResolvedModule(sourceFile, usage.text, mode)?.resolvedModule?.resolvedFileName);
110
- }
111
-
112
- for (const reference of sourceFile.referencedFiles ?? []) {
113
- visit(host.path.resolve(host.path.dirname(sourceFile.fileName), reference.fileName));
114
- }
115
-
116
- for (const reference of sourceFile.typeReferenceDirectives ?? []) {
117
- const resolved = program.getResolvedTypeReferenceDirective(sourceFile, reference.fileName, reference.resolutionMode);
118
- visit(resolved?.resolvedTypeReferenceDirective?.resolvedFileName);
119
- }
120
- }
121
-
122
- return [...seen];
123
- }
@@ -1,144 +0,0 @@
1
- import { createProjectSync, InMemoryFileSystemHost } from "@ts-morph/bootstrap";
2
-
3
- /**
4
- * @typedef {object} Host
5
- * @property {string} cwd
6
- * @property {{ join: (...parts: string[]) => string, dirname: (p: string) => string, basename: (p: string) => string, resolve: (...parts: string[]) => string }} path
7
- * @property {{ fileExists: (p: string) => boolean, directoryExists: (p: string) => boolean, readFile: (p: string) => string, readDirectory: (p: string) => string[], realPath: (p: string) => string }} fs
8
- * @property {(compilerOptions: object) => import("@ts-morph/bootstrap").Project} createProject
9
- */
10
-
11
- /**
12
- * `/` separated paths, the only ones of the in-memory file system.
13
- */
14
- export const posixPath = {
15
- normalize(p) {
16
- const absolute = p.startsWith("/");
17
- const segments = [];
18
-
19
- for (const segment of p.split("/")) {
20
- if (segment === "" || segment === ".") {
21
- continue;
22
- }
23
-
24
- if (segment === "..") {
25
- if (segments.length > 0 && segments[segments.length - 1] !== "..") {
26
- segments.pop();
27
- } else if (!absolute) {
28
- segments.push("..");
29
- }
30
-
31
- continue;
32
- }
33
-
34
- segments.push(segment);
35
- }
36
-
37
- const joined = segments.join("/");
38
-
39
- return absolute ? "/" + joined : joined === "" ? "." : joined;
40
- },
41
-
42
- join(...parts) {
43
- return posixPath.normalize(parts.filter((part) => part !== "").join("/"));
44
- },
45
-
46
- dirname(p) {
47
- const normalized = posixPath.normalize(p);
48
- const index = normalized.lastIndexOf("/");
49
-
50
- if (index === -1) {
51
- return ".";
52
- }
53
-
54
- return index === 0 ? "/" : normalized.slice(0, index);
55
- },
56
-
57
- basename(p) {
58
- const normalized = posixPath.normalize(p);
59
-
60
- return normalized.slice(normalized.lastIndexOf("/") + 1);
61
- },
62
-
63
- resolve(...parts) {
64
- let result = "/";
65
-
66
- for (const part of parts) {
67
- result = part.startsWith("/") ? part : result + "/" + part;
68
- }
69
-
70
- return posixPath.normalize(result);
71
- },
72
- };
73
-
74
- /**
75
- * A host over a ts-morph file system, the in-memory one in the browser.
76
- *
77
- * @param {import("@ts-morph/bootstrap").FileSystemHost} fileSystem
78
- * @param {string} cwd
79
- * @returns {Host}
80
- */
81
- export function createFileSystemHost(fileSystem, cwd = "/") {
82
- return {
83
- cwd,
84
- fileSystem,
85
- path: posixPath,
86
- fs: {
87
- fileExists: (p) => fileSystem.fileExistsSync(p),
88
- directoryExists: (p) => fileSystem.directoryExistsSync(p),
89
- readFile: (p) => fileSystem.readFileSync(p, "utf8"),
90
- readDirectory: (p) => fileSystem.readDirSync(p).map((entry) => entry.name),
91
- realPath: (p) => {
92
- try {
93
- return fileSystem.realpathSync(p);
94
- } catch {
95
- return p;
96
- }
97
- },
98
- },
99
- createProject: (compilerOptions) =>
100
- createProjectSync({ fileSystem, compilerOptions, skipAddingFilesFromTsConfig: true }),
101
- };
102
- }
103
-
104
- /**
105
- * @param {string} cwd
106
- * @returns {Host}
107
- */
108
- export function createInMemoryHost(cwd = "/") {
109
- return createFileSystemHost(new InMemoryFileSystemHost(), cwd);
110
- }
111
-
112
- /**
113
- * The host of the CLI, over the disk.
114
- *
115
- * @param {typeof import("node:fs")} fs
116
- * @param {typeof import("node:path")} path
117
- * @param {string} cwd
118
- * @returns {Host}
119
- */
120
- export function createNodeHost(fs, path, cwd) {
121
- return {
122
- cwd,
123
- path: {
124
- join: (...parts) => path.join(...parts),
125
- dirname: (p) => path.dirname(p),
126
- basename: (p) => path.basename(p),
127
- resolve: (...parts) => path.resolve(...parts),
128
- },
129
- fs: {
130
- fileExists: (p) => fs.existsSync(p) && fs.statSync(p).isFile(),
131
- directoryExists: (p) => fs.existsSync(p) && fs.statSync(p).isDirectory(),
132
- readFile: (p) => fs.readFileSync(p, "utf8"),
133
- readDirectory: (p) => fs.readdirSync(p),
134
- realPath: (p) => {
135
- try {
136
- return fs.realpathSync(p);
137
- } catch {
138
- return p;
139
- }
140
- },
141
- },
142
- createProject: (compilerOptions) => createProjectSync({ compilerOptions, skipAddingFilesFromTsConfig: true }),
143
- };
144
- }
@@ -1,137 +0,0 @@
1
- const DECLARATION_FILE = /\.d\.[cm]?ts$/;
2
- const REGISTRY = "https://data.jsdelivr.com/v1/package";
3
- const CDN = "https://cdn.jsdelivr.net/npm";
4
- const CONCURRENCY = 8;
5
-
6
- /**
7
- * `@types/foo` for `foo`, `@types/scope__foo` for `@scope/foo`
8
- *
9
- * @param {string} name
10
- */
11
- export function typesPackageName(name) {
12
- return "@types/" + name.replace(/^@/, "").replace("/", "__");
13
- }
14
-
15
- /**
16
- * `chalk`, `chalk@5`, `@scope/name@^1.2`
17
- *
18
- * @param {string} spec
19
- * @returns {{ name: string, range: string }}
20
- */
21
- export function parsePackageSpec(spec) {
22
- const at = spec.indexOf("@", 1);
23
-
24
- if (at === -1) {
25
- return { name: spec, range: "latest" };
26
- }
27
-
28
- return { name: spec.slice(0, at), range: spec.slice(at + 1) || "latest" };
29
- }
30
-
31
- /**
32
- * Download the declaration files of a package and of the packages it depends on into
33
- * `/node_modules` of the file system, like `npm install` would, from jsDelivr.
34
- *
35
- * @param {import("@ts-morph/bootstrap").FileSystemHost} fileSystem
36
- * @param {string} spec package name, with an optional version range
37
- * @param {{ fetch?: typeof fetch, onProgress?: (message: string) => void, skip?: string[] }} options
38
- * @returns {Promise<{ name: string, version: string }>} the package installed for `spec`
39
- */
40
- export async function installPackage(fileSystem, spec, options = {}) {
41
- const fetchImpl = options.fetch ?? globalThis.fetch;
42
- const onProgress = options.onProgress ?? (() => {});
43
- // `@types/node` describes the runtime, it is not needed to generate a package
44
- const skip = new Set(options.skip ?? ["@types/node"]);
45
- const installed = new Map();
46
-
47
- const getJson = async (url) => {
48
- const response = await fetchImpl(url);
49
-
50
- if (!response.ok) {
51
- throw new Error(`${url}: ${response.status}`);
52
- }
53
-
54
- return await response.json();
55
- };
56
-
57
- const getText = async (url) => {
58
- const response = await fetchImpl(url);
59
-
60
- if (!response.ok) {
61
- throw new Error(`${url}: ${response.status}`);
62
- }
63
-
64
- return await response.text();
65
- };
66
-
67
- const install = async (name, range) => {
68
- if (installed.has(name) || skip.has(name)) {
69
- return installed.get(name) ?? null;
70
- }
71
-
72
- const resolveResponse = await fetchImpl(`${REGISTRY}/resolve/npm/${name}@${encodeURIComponent(range)}`);
73
-
74
- if (resolveResponse.status === 404) {
75
- throw new Error(`No package named '${name}' on npm`);
76
- }
77
-
78
- if (!resolveResponse.ok) {
79
- throw new Error(`${resolveResponse.url}: ${resolveResponse.status}`);
80
- }
81
-
82
- const { version } = await resolveResponse.json();
83
-
84
- if (version === null || version === undefined) {
85
- throw new Error(`No version of '${name}' matches '${range}'`);
86
- }
87
-
88
- installed.set(name, { name, version });
89
- onProgress(`${name}@${version}: listing files`);
90
-
91
- const { files } = await getJson(`${REGISTRY}/npm/${name}@${version}/flat`);
92
-
93
- const wanted = files
94
- .map((file) => file.name)
95
- .filter((file) => DECLARATION_FILE.test(file) || file.endsWith("/package.json"));
96
-
97
- let done = 0;
98
-
99
- const worker = async () => {
100
- while (wanted.length > 0) {
101
- const file = wanted.shift();
102
- const content = await getText(`${CDN}/${name}@${version}${file}`);
103
-
104
- fileSystem.writeFileSync(`/node_modules/${name}${file}`, content);
105
- done++;
106
- onProgress(`${name}@${version}: ${done} files`);
107
- }
108
- };
109
-
110
- await Promise.all(Array.from({ length: CONCURRENCY }, worker));
111
-
112
- const packageJson = JSON.parse(fileSystem.readFileSync(`/node_modules/${name}/package.json`, "utf8"));
113
-
114
- const hasDeclarations = files.some((file) => DECLARATION_FILE.test(file.name));
115
-
116
- // A package without declaration files (`ws`) is described by its `@types` package
117
- if (!hasDeclarations && !name.startsWith("@types/")) {
118
- try {
119
- await install(typesPackageName(name), "latest");
120
- } catch {
121
- // No `@types` package either, the package stays untyped
122
- }
123
- }
124
-
125
- for (const [dependency, dependencyRange] of Object.entries(packageJson.dependencies ?? {})) {
126
- await install(dependency, dependencyRange);
127
- }
128
-
129
- return installed.get(name);
130
- };
131
-
132
- const { name, range } = parsePackageSpec(spec);
133
- const result = await install(name, range);
134
-
135
- // `ws` itself has no declaration file: the package to generate is its `@types` package
136
- return result;
137
- }