@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.
- package/dist/Glutinum.Converter/FsharpAST.js +38 -4
- package/dist/Glutinum.Converter/Generate.js +15 -7
- package/dist/Glutinum.Converter/GlueAST.js +45 -36
- package/dist/Glutinum.Converter/Hosting.js +918 -0
- package/dist/Glutinum.Converter/Merge.js +218 -82
- package/dist/Glutinum.Converter/Packages.js +44 -8
- package/dist/Glutinum.Converter/Printer.js +77 -49
- package/dist/Glutinum.Converter/Read.js +8 -8
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
- package/dist/Glutinum.Converter/Reader/Declaration.js +26 -26
- package/dist/Glutinum.Converter/Reader/Documentation.js +37 -36
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +5 -5
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +31 -19
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +6 -7
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +36 -29
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
- package/dist/Glutinum.Converter/Reader/Node.js +20 -20
- package/dist/Glutinum.Converter/Reader/Parameters.js +7 -7
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
- package/dist/Glutinum.Converter/Reader/TypeNode.js +291 -232
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +8 -8
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +108 -40
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +2 -2
- package/dist/Glutinum.Converter/Reader/Types.js +6 -6
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +7 -6
- package/dist/Glutinum.Converter/Reader/Utils.js +106 -56
- package/dist/Glutinum.Converter/Transform.js +2057 -700
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +194 -202
- package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
- package/dist/Glutinum.Converter/Utils/String.js +2 -2
- package/dist/Program.js +38 -26
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
- package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
- package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
- package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
- package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
- package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
- package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
- package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
- package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
- package/package.json +2 -2
- package/dist/Glutinum.Converter/TypeScript.js +0 -12
- package/src/Glutinum.Converter/js/bootstrap.js +0 -123
- package/src/Glutinum.Converter/js/host.js +0 -144
- package/src/Glutinum.Converter/js/npm.js +0 -137
- 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.
|
|
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.
|
|
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
|
-
}
|