@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
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
import { ts } from "@ts-morph/bootstrap";
|
|
2
|
-
|
|
3
|
-
const DECLARATION_FILE = /\.d\.[cm]?ts$/;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Directory of the nearest `node_modules` folder, walking up from `cwd`.
|
|
7
|
-
*
|
|
8
|
-
* @param {import("./host.js").Host} host
|
|
9
|
-
* @param {string} cwd
|
|
10
|
-
* @returns {string | null}
|
|
11
|
-
*/
|
|
12
|
-
export function findNodeModules(host, cwd) {
|
|
13
|
-
const { path, fs } = host;
|
|
14
|
-
let dir = path.resolve(cwd);
|
|
15
|
-
|
|
16
|
-
while (true) {
|
|
17
|
-
const candidate = path.join(dir, "node_modules");
|
|
18
|
-
|
|
19
|
-
if (fs.directoryExists(candidate)) {
|
|
20
|
-
return candidate;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const parent = path.dirname(dir);
|
|
24
|
-
|
|
25
|
-
if (parent === dir) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
dir = parent;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Real path of a directory: pnpm links `node_modules/<pkg>` into its store, the
|
|
35
|
-
* dependencies of a package are only reachable from the real location.
|
|
36
|
-
*
|
|
37
|
-
* @param {string} dir
|
|
38
|
-
* @returns {string}
|
|
39
|
-
*/
|
|
40
|
-
function realDir(host, dir) {
|
|
41
|
-
return host.fs.realPath(dir);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Directory of the package that owns `file`: the closest parent directory containing a `package.json`.
|
|
46
|
-
*
|
|
47
|
-
* @param {import("./host.js").Host} host
|
|
48
|
-
* @param {string} file
|
|
49
|
-
* @returns {string | null}
|
|
50
|
-
*/
|
|
51
|
-
export function findPackageDir(host, file) {
|
|
52
|
-
const { path, fs } = host;
|
|
53
|
-
let dir = path.dirname(path.resolve(file));
|
|
54
|
-
|
|
55
|
-
while (true) {
|
|
56
|
-
const packageJsonPath = path.join(dir, "package.json");
|
|
57
|
-
|
|
58
|
-
// `dist/esm/package.json` files only holding `{ "type": "module" }` do not delimit a package
|
|
59
|
-
if (fs.fileExists(packageJsonPath) && JSON.parse(fs.readFile(packageJsonPath)).name !== undefined) {
|
|
60
|
-
return realDir(host, dir);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const parent = path.dirname(dir);
|
|
64
|
-
|
|
65
|
-
if (parent === dir) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
dir = parent;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The `types` entries found in a package.json `exports` map, keyed by subpath.
|
|
75
|
-
*
|
|
76
|
-
* @param {unknown} exportsField
|
|
77
|
-
* @returns {{ subpath: string, file: string }[]}
|
|
78
|
-
*/
|
|
79
|
-
function collectExportsTypes(exportsField) {
|
|
80
|
-
const result = [];
|
|
81
|
-
|
|
82
|
-
const visit = (subpath, node) => {
|
|
83
|
-
if (node === null || node === undefined) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (typeof node === "string") {
|
|
88
|
-
if (DECLARATION_FILE.test(node)) {
|
|
89
|
-
result.push({ subpath, file: node });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (typeof node === "object") {
|
|
96
|
-
for (const [key, value] of Object.entries(node)) {
|
|
97
|
-
if (key.startsWith(".")) {
|
|
98
|
-
visit(key, value);
|
|
99
|
-
} else if (key === "types" || key === "typings") {
|
|
100
|
-
visit(subpath, value);
|
|
101
|
-
} else {
|
|
102
|
-
// Conditions such as `import`, `default`, `node`, ...
|
|
103
|
-
visit(subpath, value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
if (typeof exportsField === "string" || (exportsField && !Object.keys(exportsField).some((key) => key.startsWith(".")))) {
|
|
110
|
-
visit(".", exportsField);
|
|
111
|
-
} else {
|
|
112
|
-
visit(".", exportsField);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Keep the first declaration file found for a subpath
|
|
116
|
-
const bySubpath = new Map();
|
|
117
|
-
|
|
118
|
-
for (const entry of result) {
|
|
119
|
-
if (!bySubpath.has(entry.subpath)) {
|
|
120
|
-
bySubpath.set(entry.subpath, entry.file);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return [...bySubpath.entries()].map(([subpath, file]) => ({ subpath, file }));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* `[major, minor, patch]` of a version, missing parts are 0
|
|
130
|
-
*
|
|
131
|
-
* @param {string} version
|
|
132
|
-
*/
|
|
133
|
-
function parseVersion(version) {
|
|
134
|
-
const parts = version.split(".").map((part) => parseInt(part, 10));
|
|
135
|
-
|
|
136
|
-
return [parts[0] || 0, parts[1] || 0, parts[2] || 0];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @param {number[]} a
|
|
141
|
-
* @param {number[]} b
|
|
142
|
-
*/
|
|
143
|
-
function compareVersions(a, b) {
|
|
144
|
-
for (let i = 0; i < 3; i++) {
|
|
145
|
-
if (a[i] !== b[i]) {
|
|
146
|
-
return a[i] - b[i];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return 0;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Whether `version` satisfies one comparator of a `typesVersions` range (`<=5.5`, `>=4.2`, `*`)
|
|
155
|
-
*
|
|
156
|
-
* @param {number[]} version
|
|
157
|
-
* @param {string} comparator
|
|
158
|
-
*/
|
|
159
|
-
function satisfiesComparator(version, comparator) {
|
|
160
|
-
const match = comparator.match(/^(>=|<=|>|<|=|\^|~)?\s*(.+)$/);
|
|
161
|
-
|
|
162
|
-
if (match === null) {
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const operator = match[1] ?? "=";
|
|
167
|
-
const text = match[2];
|
|
168
|
-
|
|
169
|
-
if (text === "*" || text === "x") {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const parts = text.split(".").map((part) => parseInt(part, 10)).filter((part) => !isNaN(part));
|
|
174
|
-
const lower = [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0];
|
|
175
|
-
|
|
176
|
-
// `5.5` stands for every `5.5.x`, the bound after it is `5.6.0`
|
|
177
|
-
const upper =
|
|
178
|
-
parts.length === 1 ? [lower[0] + 1, 0, 0]
|
|
179
|
-
: parts.length === 2 ? [lower[0], lower[1] + 1, 0]
|
|
180
|
-
: [lower[0], lower[1], lower[2] + 1];
|
|
181
|
-
|
|
182
|
-
switch (operator) {
|
|
183
|
-
case ">=":
|
|
184
|
-
return compareVersions(version, lower) >= 0;
|
|
185
|
-
case ">":
|
|
186
|
-
return compareVersions(version, upper) >= 0;
|
|
187
|
-
case "<":
|
|
188
|
-
return compareVersions(version, lower) < 0;
|
|
189
|
-
case "<=":
|
|
190
|
-
return compareVersions(version, upper) < 0;
|
|
191
|
-
case "^":
|
|
192
|
-
return compareVersions(version, lower) >= 0 && compareVersions(version, [lower[0] + 1, 0, 0]) < 0;
|
|
193
|
-
case "~":
|
|
194
|
-
return compareVersions(version, lower) >= 0 && compareVersions(version, [lower[0], lower[1] + 1, 0]) < 0;
|
|
195
|
-
default:
|
|
196
|
-
return compareVersions(version, lower) >= 0 && compareVersions(version, upper) < 0;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* @param {string} version
|
|
202
|
-
* @param {string} range
|
|
203
|
-
*/
|
|
204
|
-
function satisfiesRange(version, range) {
|
|
205
|
-
const parsed = parseVersion(version);
|
|
206
|
-
|
|
207
|
-
return range
|
|
208
|
-
.split("||")
|
|
209
|
-
.some((alternative) => alternative.trim().split(/\s+/).every((comparator) => satisfiesComparator(parsed, comparator)));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* The declaration file to use for the bundled TypeScript, following the `typesVersions` of the
|
|
214
|
-
* package (`{ "<=5.5": { "*": ["ts5.5/*"] } }`).
|
|
215
|
-
*
|
|
216
|
-
* @param {Record<string, Record<string, string[]>> | undefined} typesVersions
|
|
217
|
-
* @param {string} file
|
|
218
|
-
*/
|
|
219
|
-
function applyTypesVersions(typesVersions, file) {
|
|
220
|
-
if (typesVersions === undefined || typesVersions === null) {
|
|
221
|
-
return file;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const paths = Object.entries(typesVersions).find(([range]) => satisfiesRange(ts.version, range))?.[1];
|
|
225
|
-
|
|
226
|
-
if (paths === undefined) {
|
|
227
|
-
return file;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const normalized = file.replace(/^\.\//, "");
|
|
231
|
-
|
|
232
|
-
for (const [pattern, targets] of Object.entries(paths)) {
|
|
233
|
-
const [prefix, suffix = ""] = pattern.split("*");
|
|
234
|
-
|
|
235
|
-
if (normalized.startsWith(prefix) && normalized.endsWith(suffix) && targets.length > 0) {
|
|
236
|
-
const captured = normalized.slice(prefix.length, normalized.length - suffix.length);
|
|
237
|
-
|
|
238
|
-
return targets[0].replace("*", captured);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return file;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Describe an installed package: its runtime name and declaration entry points.
|
|
247
|
-
*
|
|
248
|
-
* @param {import("./host.js").Host} host
|
|
249
|
-
* @param {string} packageDir
|
|
250
|
-
* @returns {{ name: string, runtimeName: string, dir: string, typesRoot: string, entryFile: string, subpathEntries: { subpath: string, file: string }[] } | null}
|
|
251
|
-
*/
|
|
252
|
-
export function describePackage(host, packageDir) {
|
|
253
|
-
const { path, fs } = host;
|
|
254
|
-
const packageJsonPath = path.join(packageDir, "package.json");
|
|
255
|
-
|
|
256
|
-
if (!fs.fileExists(packageJsonPath)) {
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const pkg = JSON.parse(fs.readFile(packageJsonPath));
|
|
261
|
-
const name = pkg.name ?? path.basename(packageDir);
|
|
262
|
-
|
|
263
|
-
// `@types/foo` describes the `foo` package, `@types/scope__foo` the `@scope/foo` one
|
|
264
|
-
let runtimeName = name;
|
|
265
|
-
|
|
266
|
-
if (name.startsWith("@types/")) {
|
|
267
|
-
const typed = name.slice("@types/".length);
|
|
268
|
-
runtimeName = typed.includes("__") ? "@" + typed.replace("__", "/") : typed;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const candidates = [];
|
|
272
|
-
const typesField = pkg.types ?? pkg.typings;
|
|
273
|
-
|
|
274
|
-
if (typeof typesField === "string") {
|
|
275
|
-
candidates.push({ subpath: ".", file: typesField });
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
candidates.push(...collectExportsTypes(pkg.exports));
|
|
279
|
-
|
|
280
|
-
if (typeof pkg.main === "string") {
|
|
281
|
-
candidates.push({ subpath: ".", file: pkg.main.replace(/\.[cm]?js$/, ".d.ts") });
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
candidates.push({ subpath: ".", file: "index.d.ts" });
|
|
285
|
-
|
|
286
|
-
const entries = [];
|
|
287
|
-
|
|
288
|
-
for (const candidate of candidates) {
|
|
289
|
-
const mappedFile = applyTypesVersions(pkg.typesVersions, candidate.file);
|
|
290
|
-
let file = path.resolve(packageDir, mappedFile);
|
|
291
|
-
|
|
292
|
-
// `"types": "./lib/umd/main"` is allowed without an extension
|
|
293
|
-
if (!DECLARATION_FILE.test(file) && fs.fileExists(file + ".d.ts")) {
|
|
294
|
-
file = file + ".d.ts";
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (!fs.fileExists(file) || !DECLARATION_FILE.test(file)) {
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (!entries.some((entry) => entry.subpath === candidate.subpath || entry.file === file)) {
|
|
302
|
-
entries.push({ subpath: candidate.subpath, file, isMapped: mappedFile !== candidate.file });
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const main = entries.find((entry) => entry.subpath === ".");
|
|
307
|
-
|
|
308
|
-
if (main === undefined) {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return {
|
|
313
|
-
name,
|
|
314
|
-
runtimeName,
|
|
315
|
-
dir: packageDir,
|
|
316
|
-
// The files of a `typesVersions` folder are named as if they were at the root
|
|
317
|
-
typesRoot: main.isMapped ? path.dirname(main.file) : packageDir,
|
|
318
|
-
entryFile: main.file,
|
|
319
|
-
subpathEntries: entries
|
|
320
|
-
.filter((entry) => entry !== main)
|
|
321
|
-
.map((entry) => ({ subpath: entry.subpath.replace(/^\.\//, ""), file: entry.file })),
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Resolve the CLI input to a package directory or a declaration file.
|
|
327
|
-
*
|
|
328
|
-
* @param {import("./host.js").Host} host
|
|
329
|
-
* @param {string} input package name, package directory or `.d.ts` path
|
|
330
|
-
* @returns {{ kind: "file", file: string } | { kind: "package", packageDir: string }}
|
|
331
|
-
*/
|
|
332
|
-
export function resolveInput(host, input) {
|
|
333
|
-
const { path, fs } = host;
|
|
334
|
-
const asPath = path.resolve(host.cwd, input);
|
|
335
|
-
|
|
336
|
-
if (DECLARATION_FILE.test(input) && fs.fileExists(asPath)) {
|
|
337
|
-
return { kind: "file", file: asPath };
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (fs.directoryExists(asPath)) {
|
|
341
|
-
return { kind: "package", packageDir: realDir(host, asPath) };
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const nodeModules = findNodeModules(host, host.cwd);
|
|
345
|
-
|
|
346
|
-
if (nodeModules !== null) {
|
|
347
|
-
// `date-fns/locale` is a subpath of `date-fns`, generated with the package
|
|
348
|
-
const segments = input.split("/");
|
|
349
|
-
const packageName = input.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
|
|
350
|
-
|
|
351
|
-
// A package without declaration files (`ws`) is described by its `@types` package
|
|
352
|
-
for (const candidate of [packageName, path.join("@types", packageName.replace(/^@/, "").replace("/", "__"))]) {
|
|
353
|
-
const packageDir = realDir(host, path.join(nodeModules, candidate));
|
|
354
|
-
|
|
355
|
-
if (fs.fileExists(path.join(packageDir, "package.json")) && describePackage(host, packageDir) !== null) {
|
|
356
|
-
return { kind: "package", packageDir };
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
throw new Error(
|
|
362
|
-
`Could not find '${input}': it is neither a declaration file, a package directory, nor a package installed in node_modules.`
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Every package installed in the nearest `node_modules` that ships declaration files.
|
|
368
|
-
*
|
|
369
|
-
* @param {import("./host.js").Host} host
|
|
370
|
-
* @returns {string[]} package directories
|
|
371
|
-
*/
|
|
372
|
-
export function listInstalledPackages(host) {
|
|
373
|
-
const { path, fs } = host;
|
|
374
|
-
const nodeModules = findNodeModules(host, host.cwd);
|
|
375
|
-
|
|
376
|
-
if (nodeModules === null) {
|
|
377
|
-
return [];
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
const result = [];
|
|
381
|
-
|
|
382
|
-
for (const entry of fs.readDirectory(nodeModules)) {
|
|
383
|
-
if (entry.startsWith(".")) {
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const entryPath = path.join(nodeModules, entry);
|
|
388
|
-
|
|
389
|
-
if (entry.startsWith("@")) {
|
|
390
|
-
for (const scoped of fs.readDirectory(entryPath)) {
|
|
391
|
-
result.push(path.join(entryPath, scoped));
|
|
392
|
-
}
|
|
393
|
-
} else {
|
|
394
|
-
result.push(entryPath);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return result
|
|
399
|
-
.filter((dir) => fs.fileExists(path.join(dir, "package.json")))
|
|
400
|
-
.map((dir) => realDir(host, dir))
|
|
401
|
-
.filter((dir) => describePackage(host, dir) !== null);
|
|
402
|
-
}
|