@glutinum/cli 1.0.0-beta.2 → 1.0.0-beta.4
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/README.md +16 -0
- package/dist/Glutinum.Converter/Abbreviations.js +9 -32
- package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
- package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
- package/dist/Glutinum.Converter/FsharpAST.js +116 -65
- package/dist/Glutinum.Converter/Generate.js +34 -21
- package/dist/Glutinum.Converter/GlueAST.js +79 -41
- package/dist/Glutinum.Converter/Hosting.js +132 -157
- package/dist/Glutinum.Converter/Merge.js +369 -337
- package/dist/Glutinum.Converter/Packages.js +391 -92
- package/dist/Glutinum.Converter/Printer.js +404 -424
- package/dist/Glutinum.Converter/Read.js +387 -88
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
- package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
- package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +15 -21
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
- package/dist/Glutinum.Converter/Reader/Node.js +8 -11
- package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
- package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1343
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
- package/dist/Glutinum.Converter/Reader/Types.js +290 -15
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
- package/dist/Glutinum.Converter/Reader/Utils.js +343 -28
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +3619 -8456
- package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
- package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
- package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
- package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
- package/dist/Glutinum.Converter/Transformer/Context.js +664 -0
- package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
- package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
- package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
- package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
- package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
- package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
- package/dist/Glutinum.Converter/Utils/String.js +14 -3
- package/dist/Program.js +18 -10
- package/package.json +1 -1
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
|
|
2
2
|
import { toString, Record } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
3
3
|
import { GlueModuleDeclaration, GlueType, GlueFileModule, GlueType_$reflection } from "./GlueAST.js";
|
|
4
|
-
import { tuple_type, option_type, bool_type, record_type, string_type, list_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
|
|
4
|
+
import { int32_type, tuple_type, option_type, bool_type, record_type, string_type, list_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
|
|
5
5
|
import { FSharpType_$reflection } from "./FsharpAST.js";
|
|
6
|
-
import { Bootstrap_reachableFiles, Bootstrap_createProgramFromFiles,
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { stringHash, Exception, defaultOf, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
6
|
+
import { Bootstrap_reachableFiles, Bootstrap_createProgramFromFiles, Resolve_findNodeModules, Resolve_findPackageDir, Resolve_resolveInput, Resolve_listInstalledPackages, Resolve_describePackage, Npm_installPackage, createInMemoryHost as createInMemoryHost_1 } from "./Hosting.js";
|
|
7
|
+
import { FSharpSet__get_IsEmpty, filter as filter_2, map as map_3, union, difference, FSharpSet__Contains, empty as empty_1, ofSeq } from "../fable_modules/fable-library-js.5.17.2/Set.js";
|
|
8
|
+
import { stringHash, Exception, defaultOf, equals, compareArrays, comparePrimitives } from "../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
10
9
|
import { replace, concat, split, substring, join } from "../fable_modules/fable-library-js.5.17.2/String.js";
|
|
11
10
|
import { map } from "../fable_modules/fable-library-js.5.17.2/Array.js";
|
|
12
11
|
import { normalizePath } from "./Utils/String.js";
|
|
13
|
-
import {
|
|
12
|
+
import { contains, sortBy, tryFind as tryFind_1, collect, toArray, singleton, isEmpty, choose, empty as empty_2, filter as filter_1, sort, append, exists as exists_1, cons, fold, ofArray, map as map_1 } from "../fable_modules/fable-library-js.5.17.2/List.js";
|
|
13
|
+
import { add, ofSeq as ofSeq_1, toList, FSharpMap__TryFind, FSharpMap__ContainsKey, FSharpMap__Add, containsKey, empty } from "../fable_modules/fable-library-js.5.17.2/Map.js";
|
|
14
14
|
import { PackageContext__TryFindPackage_Z721C83C5, PackageContext, ExternalPackage, PackageInfo } from "./Reader/Types.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { choose as choose_1, singleton as singleton_1, collect as collect_1, empty as empty_3, append as append_1, delay, sort as sort_1, toList as toList_1, exists, filter, tryPick, map as map_2, tryFind, fold as fold_1 } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
|
|
16
|
+
import { ambientModuleSpecifier, promotedAmbientModule, ambientModuleNames, $007CHasSymbolFlags$007C_$007C } from "./Reader/Utils.js";
|
|
17
|
+
import { toArray as toArray_1, defaultArg } from "../fable_modules/fable-library-js.5.17.2/Option.js";
|
|
18
|
+
import { defaultMaxOverloads } from "./Transformer/UnionOverloads.js";
|
|
19
|
+
import { List_distinctBy, List_distinct } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
|
|
17
20
|
import { readPackages } from "./Read.js";
|
|
18
|
-
import {
|
|
21
|
+
import { TransformOptions, applyWithOptions } from "./Transform.js";
|
|
22
|
+
import { ImportSource } from "./Transformer/Context.js";
|
|
19
23
|
import { printFileWith, Printer_$ctor } from "./Printer.js";
|
|
20
24
|
|
|
21
25
|
export class GenerationResult extends Record {
|
|
@@ -45,40 +49,289 @@ export function installPackage(fileSystem, spec, options) {
|
|
|
45
49
|
return Npm_installPackage(fileSystem, spec, options);
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
52
|
+
const domLibReplacements = ofSeq(["@types/web", "@typescript/lib-dom"], {
|
|
53
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
54
|
+
});
|
|
51
55
|
|
|
52
|
-
function
|
|
53
|
-
return
|
|
56
|
+
function moduleNameForPackage(runtimeName) {
|
|
57
|
+
return join("", map((part) => (part[0].toLocaleUpperCase() + substring(part, 1)), split(runtimeName, ["@", "/", "-", ".", "_"], undefined, 1)));
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
function
|
|
57
|
-
return
|
|
60
|
+
function toPackageInfo(description) {
|
|
61
|
+
return new PackageInfo(moduleNameForPackage(description.runtimeName), description.runtimeName, description.hasRuntime, normalizePath(description.dir) + "/", normalizePath(description.typesRoot) + "/", normalizePath(description.entryFile), map_1((entry) => [normalizePath(entry.file), entry.subpath], ofArray(description.subpathEntries)), empty({
|
|
62
|
+
Compare: (x, y) => (compareArrays(x, y) | 0),
|
|
63
|
+
}), empty({
|
|
64
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
65
|
+
}), empty({
|
|
66
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
67
|
+
}), empty({
|
|
68
|
+
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
69
|
+
}), false, empty_1({
|
|
70
|
+
Compare: (x_4, y_4) => (compareArrays(x_4, y_4) | 0),
|
|
71
|
+
}), empty({
|
|
72
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
73
|
+
}));
|
|
58
74
|
}
|
|
59
75
|
|
|
60
|
-
function
|
|
61
|
-
|
|
76
|
+
function reExportedNames(program, checker, hasExportsMap, package$) {
|
|
77
|
+
if (!hasExportsMap) {
|
|
78
|
+
return empty({
|
|
79
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return fold((acc, tupledArg) => {
|
|
84
|
+
const matchValue = program.getSourceFile(tupledArg[0]);
|
|
85
|
+
if (matchValue != null) {
|
|
86
|
+
const sourceFile = matchValue;
|
|
87
|
+
const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
|
|
88
|
+
if (matchValue_1 != null) {
|
|
89
|
+
const moduleSymbol = matchValue_1;
|
|
90
|
+
return fold_1((acc_1, exportedSymbol) => {
|
|
91
|
+
if (containsKey(exportedSymbol.name, acc_1)) {
|
|
92
|
+
return acc_1;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return FSharpMap__Add(acc_1, exportedSymbol.name, tupledArg[1]);
|
|
96
|
+
}
|
|
97
|
+
}, acc, checker.getExportsOfModule(moduleSymbol));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return acc;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return acc;
|
|
105
|
+
}
|
|
106
|
+
}, empty({
|
|
107
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
108
|
+
}), cons([package$.EntryFile, ""], package$.SubpathEntries));
|
|
109
|
+
}
|
|
62
110
|
}
|
|
63
111
|
|
|
64
|
-
function
|
|
65
|
-
|
|
112
|
+
function resolveAlias(checker, symbol) {
|
|
113
|
+
const matchValue = symbol.flags;
|
|
114
|
+
if ($007CHasSymbolFlags$007C_$007C(2097152, matchValue) != null) {
|
|
115
|
+
return checker.getAliasedSymbol(symbol);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return symbol;
|
|
119
|
+
}
|
|
66
120
|
}
|
|
67
121
|
|
|
68
|
-
function
|
|
69
|
-
|
|
122
|
+
function defaultExportOf(program, checker, fileName) {
|
|
123
|
+
let option_5;
|
|
124
|
+
let option_3;
|
|
125
|
+
const option_1 = program.getSourceFile(fileName);
|
|
126
|
+
if (option_1 != null) {
|
|
127
|
+
const sourceFile = option_1;
|
|
128
|
+
option_3 = checker.getSymbolAtLocation(sourceFile);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
option_3 = undefined;
|
|
132
|
+
}
|
|
133
|
+
if (option_3 != null) {
|
|
134
|
+
const moduleSymbol = option_3;
|
|
135
|
+
option_5 = tryFind((exported) => (exported.name === "default"), checker.getExportsOfModule(moduleSymbol));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
option_5 = undefined;
|
|
139
|
+
}
|
|
140
|
+
if (option_5 != null) {
|
|
141
|
+
return resolveAlias(checker, option_5);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
70
146
|
}
|
|
71
147
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
148
|
+
function reExportedSymbols(program, checker, hasExportsMap, package$) {
|
|
149
|
+
if (!hasExportsMap) {
|
|
150
|
+
return [empty({
|
|
151
|
+
Compare: (x, y) => (compareArrays(x, y) | 0),
|
|
152
|
+
}), empty({
|
|
153
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
154
|
+
})];
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const entries = cons([package$.EntryFile, ""], package$.SubpathEntries);
|
|
158
|
+
const entryFiles = ofSeq(map_1((tuple) => tuple[0], entries), {
|
|
159
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
160
|
+
});
|
|
161
|
+
return fold((acc, tupledArg) => {
|
|
162
|
+
const matchValue = program.getSourceFile(tupledArg[0]);
|
|
163
|
+
if (matchValue != null) {
|
|
164
|
+
const sourceFile = matchValue;
|
|
165
|
+
const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
|
|
166
|
+
if (matchValue_1 != null) {
|
|
167
|
+
const moduleSymbol = matchValue_1;
|
|
168
|
+
const tupledArg_3 = acc;
|
|
169
|
+
return fold_1((acc_1, exportedSymbol) => {
|
|
170
|
+
const exportName = exportedSymbol.name;
|
|
171
|
+
const exportedSymbol_1 = resolveAlias(checker, exportedSymbol);
|
|
172
|
+
const matchValue_2 = exportedSymbol_1.declarations;
|
|
173
|
+
if (matchValue_2 != null) {
|
|
174
|
+
const tupledArg_2 = acc_1;
|
|
175
|
+
return fold_1((tupledArg_1, declaration) => {
|
|
176
|
+
const symbols = tupledArg_1[0];
|
|
177
|
+
const defaults = tupledArg_1[1];
|
|
178
|
+
const declaringFile = normalizePath(declaration.getSourceFile().fileName);
|
|
179
|
+
const key = [declaringFile, exportName];
|
|
180
|
+
if ((declaringFile.startsWith(package$.Dir) && !FSharpSet__Contains(entryFiles, declaringFile)) && !FSharpMap__ContainsKey(symbols, key)) {
|
|
181
|
+
let isDefault;
|
|
182
|
+
if (!FSharpMap__ContainsKey(defaults, declaringFile)) {
|
|
183
|
+
const matchValue_3 = defaultExportOf(program, checker, declaringFile);
|
|
184
|
+
isDefault = ((matchValue_3 == null) ? false : (matchValue_3 === exportedSymbol_1));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
isDefault = false;
|
|
188
|
+
}
|
|
189
|
+
return [FSharpMap__Add(symbols, key, tupledArg[1]), isDefault ? FSharpMap__Add(defaults, declaringFile, exportName) : defaults];
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return [symbols, defaults];
|
|
193
|
+
}
|
|
194
|
+
}, [tupledArg_2[0], tupledArg_2[1]], matchValue_2);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return acc_1;
|
|
198
|
+
}
|
|
199
|
+
}, [tupledArg_3[0], tupledArg_3[1]], checker.getExportsOfModule(moduleSymbol));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
return acc;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
return acc;
|
|
207
|
+
}
|
|
208
|
+
}, [empty({
|
|
209
|
+
Compare: (x_3, y_3) => (compareArrays(x_3, y_3) | 0),
|
|
210
|
+
}), empty({
|
|
211
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
212
|
+
})], entries);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
75
215
|
|
|
76
|
-
function
|
|
77
|
-
|
|
216
|
+
function declaredNames(program, checker, defaultExportNames, fileName) {
|
|
217
|
+
const matchValue = program.getSourceFile(fileName);
|
|
218
|
+
if (matchValue != null) {
|
|
219
|
+
const sourceFile = matchValue;
|
|
220
|
+
const matchValue_1 = checker.getSymbolAtLocation(sourceFile);
|
|
221
|
+
if (matchValue_1 != null) {
|
|
222
|
+
const moduleSymbol = matchValue_1;
|
|
223
|
+
const normalized = normalizePath(fileName);
|
|
224
|
+
return ofSeq(map_2((exportedSymbol_2) => {
|
|
225
|
+
let option_1;
|
|
226
|
+
if (exportedSymbol_2.name === "default") {
|
|
227
|
+
const matchValue_4 = FSharpMap__TryFind(defaultExportNames, normalized);
|
|
228
|
+
if (matchValue_4 == null) {
|
|
229
|
+
return defaultArg((option_1 = exportedSymbol_2.declarations, (option_1 != null) ? tryPick((declaration_1) => {
|
|
230
|
+
const matchValue_5 = declaration_1.name;
|
|
231
|
+
if (equals(matchValue_5, defaultOf())) {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return matchValue_5.getText();
|
|
236
|
+
}
|
|
237
|
+
}, option_1) : undefined), exportedSymbol_2.name);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return matchValue_4;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return exportedSymbol_2.name;
|
|
245
|
+
}
|
|
246
|
+
}, filter((exportedSymbol_1) => {
|
|
247
|
+
const matchValue_3 = resolveAlias(checker, exportedSymbol_1).declarations;
|
|
248
|
+
if (matchValue_3 == null) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return exists((declaration) => {
|
|
253
|
+
if ((declaration.kind !== 282) && (declaration.kind !== 278)) {
|
|
254
|
+
return normalizePath(declaration.getSourceFile().fileName) === normalized;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}, matchValue_3);
|
|
260
|
+
}
|
|
261
|
+
}, filter((exportedSymbol) => {
|
|
262
|
+
const matchValue_2 = exportedSymbol.flags;
|
|
263
|
+
let matchResult;
|
|
264
|
+
if ($007CHasSymbolFlags$007C_$007C(512, matchValue_2) != null) {
|
|
265
|
+
matchResult = 0;
|
|
266
|
+
}
|
|
267
|
+
else if ($007CHasSymbolFlags$007C_$007C(1024, matchValue_2) != null) {
|
|
268
|
+
matchResult = 0;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
matchResult = 1;
|
|
272
|
+
}
|
|
273
|
+
switch (matchResult) {
|
|
274
|
+
case 0:
|
|
275
|
+
return false;
|
|
276
|
+
default:
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
}, checker.getExportsOfModule(moduleSymbol)))), {
|
|
280
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
return empty_1({
|
|
285
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
return empty_1({
|
|
291
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
78
294
|
}
|
|
79
295
|
|
|
80
|
-
function
|
|
81
|
-
|
|
296
|
+
function hoistableDeclarations(program, checker, package$, reExportedFiles, defaultExportNames) {
|
|
297
|
+
const declaredNames_1 = (fileName) => declaredNames(program, checker, defaultExportNames, fileName);
|
|
298
|
+
const entryNames = declaredNames_1(package$.EntryFile);
|
|
299
|
+
const isEntry = (file) => {
|
|
300
|
+
if (file === package$.EntryFile) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
return exists_1((tupledArg) => (tupledArg[0] === file), package$.SubpathEntries);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const candidates = append(sort(map_1((tuple) => tuple[0], filter_1((tupledArg_1) => {
|
|
308
|
+
if (tupledArg_1[1] === "") {
|
|
309
|
+
return !isEntry(tupledArg_1[0]);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
}, toList(reExportedFiles))), {
|
|
315
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
316
|
+
}), toList_1(sort_1(filter((file_2) => {
|
|
317
|
+
if ((file_2.startsWith(package$.Dir) && !(substring(file_2, package$.Dir.length).indexOf("node_modules/") >= 0)) && !isEntry(file_2)) {
|
|
318
|
+
return !FSharpMap__ContainsKey(reExportedFiles, file_2);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}, map_2((sourceFile) => normalizePath(sourceFile.fileName), program.getSourceFiles())), {
|
|
324
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
325
|
+
})));
|
|
326
|
+
return fold((tupledArg_2, file_3) => {
|
|
327
|
+
const taken = tupledArg_2[0];
|
|
328
|
+
const free = difference(declaredNames_1(file_3), taken);
|
|
329
|
+
return [union(taken, free), union(tupledArg_2[1], map_3((name) => [file_3, name], free, {
|
|
330
|
+
Compare: (x_3, y_3) => (compareArrays(x_3, y_3) | 0),
|
|
331
|
+
}))];
|
|
332
|
+
}, [entryNames, empty_1({
|
|
333
|
+
Compare: (x_2, y_2) => (compareArrays(x_2, y_2) | 0),
|
|
334
|
+
})], candidates)[1];
|
|
82
335
|
}
|
|
83
336
|
|
|
84
337
|
function isTypeScriptLibFile(fileName) {
|
|
@@ -86,21 +339,23 @@ function isTypeScriptLibFile(fileName) {
|
|
|
86
339
|
}
|
|
87
340
|
|
|
88
341
|
export class GenerateOptions extends Record {
|
|
89
|
-
constructor(ExternalPackages, Externals, ModuleName, Include, NoLib) {
|
|
342
|
+
constructor(ExternalPackages, Externals, ModuleName, GlobalScript, MaxOverloads, Include, NoLib) {
|
|
90
343
|
super();
|
|
91
344
|
this.ExternalPackages = ExternalPackages;
|
|
92
345
|
this.Externals = Externals;
|
|
93
346
|
this.ModuleName = ModuleName;
|
|
347
|
+
this.GlobalScript = GlobalScript;
|
|
348
|
+
this.MaxOverloads = (MaxOverloads | 0);
|
|
94
349
|
this.Include = Include;
|
|
95
350
|
this.NoLib = NoLib;
|
|
96
351
|
}
|
|
97
352
|
}
|
|
98
353
|
|
|
99
354
|
export function GenerateOptions_$reflection() {
|
|
100
|
-
return record_type("Glutinum.Converter.Packages.GenerateOptions", [], GenerateOptions, () => [["ExternalPackages", bool_type], ["Externals", list_type(tuple_type(string_type, option_type(string_type)))], ["ModuleName", option_type(string_type)], ["Include", list_type(string_type)], ["NoLib", bool_type]]);
|
|
355
|
+
return record_type("Glutinum.Converter.Packages.GenerateOptions", [], GenerateOptions, () => [["ExternalPackages", bool_type], ["Externals", list_type(tuple_type(string_type, option_type(string_type)))], ["ModuleName", option_type(string_type)], ["GlobalScript", bool_type], ["MaxOverloads", int32_type], ["Include", list_type(string_type)], ["NoLib", bool_type]]);
|
|
101
356
|
}
|
|
102
357
|
|
|
103
|
-
export const defaultOptions = new GenerateOptions(true,
|
|
358
|
+
export const defaultOptions = new GenerateOptions(true, empty_2(), undefined, false, defaultMaxOverloads, empty_2(), false);
|
|
104
359
|
|
|
105
360
|
function splitModuleName(fullName) {
|
|
106
361
|
const matchValue = fullName.lastIndexOf(".") | 0;
|
|
@@ -161,7 +416,7 @@ function isValue(glueType_mut) {
|
|
|
161
416
|
}
|
|
162
417
|
|
|
163
418
|
function keepIncluded(included, types) {
|
|
164
|
-
const values =
|
|
419
|
+
const values = map_3((name_1) => substring(name_1, "value:".length), filter_2((name) => name.startsWith("value:"), included), {
|
|
165
420
|
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
166
421
|
});
|
|
167
422
|
return choose((glueType) => {
|
|
@@ -172,7 +427,7 @@ function keepIncluded(included, types) {
|
|
|
172
427
|
return undefined;
|
|
173
428
|
}
|
|
174
429
|
else {
|
|
175
|
-
return new GlueType(/* FileModule */ 31, [new GlueFileModule(glueType.fields[0].Name, glueType.fields[0].ImportSpecifier, glueType.fields[0].IsGlobal, glueType.fields[0].HasRuntime, matchValue)]);
|
|
430
|
+
return new GlueType(/* FileModule */ 31, [new GlueFileModule(glueType.fields[0].Name, glueType.fields[0].ImportSpecifier, glueType.fields[0].SymbolSpecifiers, glueType.fields[0].IsGlobal, glueType.fields[0].HasRuntime, matchValue)]);
|
|
176
431
|
}
|
|
177
432
|
}
|
|
178
433
|
case 11:
|
|
@@ -220,34 +475,34 @@ function keepIncluded(included, types) {
|
|
|
220
475
|
}, types);
|
|
221
476
|
}
|
|
222
477
|
|
|
223
|
-
const builtInExternalPackageNames = ofArray([["@types/node", "Node",
|
|
478
|
+
const builtInExternalPackageNames = ofArray([["@types/node", "Node", empty_2()], ["@types/web", "Web", singleton("/typescript/lib/lib.dom")]]);
|
|
224
479
|
|
|
225
480
|
/**
|
|
226
481
|
* Generate a single binding file for the packages, and the packages they depend on.
|
|
227
482
|
* An empty list generates every package installed in the nearest <c>node_modules</c>.
|
|
228
483
|
*/
|
|
229
484
|
export function generateWith(options, host, inputs) {
|
|
230
|
-
let
|
|
485
|
+
let option_11, option_8, option_6, option_5, nodeModules, predicate_3, objectArg, option_7, mapping_6, objectArg_1, option_9;
|
|
231
486
|
const targets = map_1((dir) => {
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
|
|
487
|
+
const option_3 = Resolve_describePackage(host, dir);
|
|
488
|
+
if (option_3 != null) {
|
|
489
|
+
return option_3;
|
|
235
490
|
}
|
|
236
491
|
else {
|
|
237
|
-
|
|
492
|
+
throw new Exception(concat("Could not find a declaration file for the package in ", dir));
|
|
238
493
|
}
|
|
239
|
-
}, isEmpty(inputs) ? ofArray(
|
|
240
|
-
const resolved =
|
|
494
|
+
}, isEmpty(inputs) ? ofArray(Resolve_listInstalledPackages(host)) : List_distinct(map_1((input) => {
|
|
495
|
+
const resolved = Resolve_resolveInput(host, input);
|
|
241
496
|
if (resolved.kind === "package") {
|
|
242
497
|
return resolved.packageDir;
|
|
243
498
|
}
|
|
244
499
|
else {
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
|
|
500
|
+
const option_1 = Resolve_findPackageDir(host, resolved.file);
|
|
501
|
+
if (option_1 != null) {
|
|
502
|
+
return option_1;
|
|
248
503
|
}
|
|
249
504
|
else {
|
|
250
|
-
|
|
505
|
+
throw new Exception(concat("Could not find the package of ", resolved.file));
|
|
251
506
|
}
|
|
252
507
|
}
|
|
253
508
|
}, inputs), {
|
|
@@ -255,87 +510,131 @@ export function generateWith(options, host, inputs) {
|
|
|
255
510
|
GetHashCode: (x) => (stringHash(x) | 0),
|
|
256
511
|
}));
|
|
257
512
|
const entryFiles = toArray(collect((target) => cons(target.entryFile, map_1((_arg) => _arg.file, ofArray(target.subpathEntries))), targets));
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
513
|
+
const withoutDomLib = exists_1((target_1) => FSharpSet__Contains(domLibReplacements, target_1.name), targets);
|
|
514
|
+
let globalTypePackages;
|
|
515
|
+
const isRuntime = exists_1((target_2) => exists_1((tupledArg) => (tupledArg[0] === target_2.name), builtInExternalPackageNames), targets);
|
|
516
|
+
globalTypePackages = ((options.ExternalPackages && !isRuntime) ? ofArray(toArray_1((option_11 = ((option_8 = ((option_6 = ((option_5 = Resolve_findNodeModules(host, host.cwd), (option_5 != null) ? ((nodeModules = option_5, host.path.join([nodeModules, "@types/node"]))) : undefined)), (predicate_3 = ((objectArg = host.fs, (path) => objectArg.directoryExists(path))), (option_7 = option_6, (option_7 != null) ? (predicate_3(option_7) ? option_7 : undefined) : undefined)))), (mapping_6 = ((objectArg_1 = host.fs, (path_1) => objectArg_1.realPath(path_1))), (option_9 = option_8, (option_9 != null) ? mapping_6(option_9) : undefined)))), (option_11 != null) ? Resolve_describePackage(host, option_11) : undefined))) : empty_2());
|
|
517
|
+
const program = Bootstrap_createProgramFromFiles(host, entryFiles, map_1((_arg_3) => _arg_3.runtimeName, globalTypePackages), withoutDomLib, options.NoLib);
|
|
262
518
|
const checker = program.getTypeChecker();
|
|
263
|
-
const
|
|
519
|
+
const targetDirSet = ofSeq(map_1((target_3) => normalizePath(target_3.dir), targets), {
|
|
264
520
|
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
265
521
|
});
|
|
266
|
-
const describeReachable = (excludedRuntimeNames) => choose((
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
return
|
|
522
|
+
const describeReachable = (excludedRuntimeNames) => choose((packageDir_1) => Resolve_describePackage(host, packageDir_1), filter_1((dir_1) => !FSharpSet__Contains(targetDirSet, dir_1), List_distinct(choose((arg) => {
|
|
523
|
+
const option_14 = Resolve_findPackageDir(host, arg);
|
|
524
|
+
if (option_14 != null) {
|
|
525
|
+
return normalizePath(option_14);
|
|
270
526
|
}
|
|
271
527
|
else {
|
|
272
|
-
return matchValue_4;
|
|
273
|
-
}
|
|
274
|
-
}, filter_1((dir_2) => !FSharpSet__Contains(targetDirs_1, dir_2), List_distinct(choose((fileName_1) => {
|
|
275
|
-
const matchValue_3 = findPackageDir(host, fileName_1);
|
|
276
|
-
if (matchValue_3 === defaultOf()) {
|
|
277
528
|
return undefined;
|
|
278
529
|
}
|
|
279
|
-
|
|
280
|
-
return normalizePath(matchValue_3);
|
|
281
|
-
}
|
|
282
|
-
}, filter_1((fileName) => !isTypeScriptLibFile(fileName), ofArray(reachableFiles(host, program, entryFiles, toArray(excludedRuntimeNames))))), {
|
|
530
|
+
}, filter_1((fileName) => !isTypeScriptLibFile(fileName), ofArray(Bootstrap_reachableFiles(host, program, entryFiles, toArray(excludedRuntimeNames))))), {
|
|
283
531
|
Equals: (x_2, y_2) => (x_2 === y_2),
|
|
284
532
|
GetHashCode: (x_2) => (stringHash(x_2) | 0),
|
|
285
533
|
})));
|
|
286
|
-
const externalPackageNames =
|
|
534
|
+
const externalPackageNames = toList_1(delay(() => append_1(options.ExternalPackages ? builtInExternalPackageNames : empty_3(), delay(() => collect_1((matchValue_1) => singleton_1([matchValue_1[0], matchValue_1[1], empty_2()]), options.Externals)))));
|
|
287
535
|
let externals;
|
|
288
536
|
if (isEmpty(externalPackageNames)) {
|
|
289
|
-
externals =
|
|
537
|
+
externals = empty_2();
|
|
290
538
|
}
|
|
291
539
|
else {
|
|
292
|
-
const reachable = describeReachable(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
540
|
+
const reachable = List_distinctBy((_arg_4) => _arg_4.name, append(describeReachable(empty_2()), globalTypePackages), {
|
|
541
|
+
Equals: (x_3, y_3) => (x_3 === y_3),
|
|
542
|
+
GetHashCode: (x_3) => (stringHash(x_3) | 0),
|
|
543
|
+
});
|
|
544
|
+
externals = map_1((tupledArg_2) => {
|
|
545
|
+
let package$_1, option_16;
|
|
546
|
+
const name_3 = tupledArg_2[0];
|
|
547
|
+
const moduleName_1 = tupledArg_2[1];
|
|
548
|
+
const package$ = tryFind_1((description) => (description.name === name_3), reachable);
|
|
549
|
+
return new ExternalPackage((moduleName_1 == null) ? ((package$ == null) ? moduleNameForPackage(replace(name_3, "@types/", "")) : ((package$_1 = package$, moduleNameForPackage(package$_1.runtimeName)))) : moduleName_1, (option_16 = package$, (option_16 != null) ? toPackageInfo(option_16) : undefined), tupledArg_2[2]);
|
|
550
|
+
}, filter_1((tupledArg_1) => !exists_1((target_4) => (target_4.name === tupledArg_1[0]), targets), externalPackageNames));
|
|
300
551
|
}
|
|
301
552
|
const externalRuntimeNames = choose((external) => {
|
|
302
|
-
const
|
|
303
|
-
if (
|
|
304
|
-
return
|
|
553
|
+
const option_18 = external.Package;
|
|
554
|
+
if (option_18 != null) {
|
|
555
|
+
return option_18.RuntimeName;
|
|
305
556
|
}
|
|
306
557
|
else {
|
|
307
558
|
return undefined;
|
|
308
559
|
}
|
|
309
560
|
}, externals);
|
|
310
|
-
const dependencies = sortBy((
|
|
311
|
-
Equals: (
|
|
312
|
-
GetHashCode: (
|
|
561
|
+
const dependencies = sortBy((_arg_8) => _arg_8.runtimeName, filter_1((description_2) => !contains(description_2.runtimeName, externalRuntimeNames, {
|
|
562
|
+
Equals: (x_4, y_4) => (x_4 === y_4),
|
|
563
|
+
GetHashCode: (x_4) => (stringHash(x_4) | 0),
|
|
313
564
|
}), describeReachable(externalRuntimeNames)), {
|
|
314
|
-
Compare: (
|
|
565
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
315
566
|
});
|
|
316
567
|
let patternInput;
|
|
317
|
-
const
|
|
318
|
-
patternInput = ((
|
|
568
|
+
const matchValue_3 = options.ModuleName;
|
|
569
|
+
patternInput = ((matchValue_3 == null) ? ["Glutinum", ""] : splitModuleName(matchValue_3));
|
|
319
570
|
const moduleName_3 = patternInput[1];
|
|
320
571
|
const targetPackages = map_1((package$_2) => {
|
|
321
572
|
if (moduleName_3 === "") {
|
|
322
573
|
return package$_2;
|
|
323
574
|
}
|
|
324
575
|
else {
|
|
325
|
-
return new PackageInfo(moduleName_3, package$_2.RuntimeName, package$_2.HasRuntime, package$_2.Dir, package$_2.TypesRoot, package$_2.EntryFile, package$_2.SubpathEntries);
|
|
576
|
+
return new PackageInfo(moduleName_3, package$_2.RuntimeName, package$_2.HasRuntime, package$_2.Dir, package$_2.TypesRoot, package$_2.EntryFile, package$_2.SubpathEntries, package$_2.ReExportedSymbols, package$_2.ReExportedFiles, package$_2.ReExportedNames, package$_2.DefaultExportNames, package$_2.HasExportsMap, package$_2.HoistableDeclarations, package$_2.AmbientModuleFiles);
|
|
326
577
|
}
|
|
327
578
|
}, map_1(toPackageInfo, targets));
|
|
328
579
|
const included = ofSeq(options.Include, {
|
|
329
|
-
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
330
|
-
});
|
|
331
|
-
const packageContext = new PackageContext(append_1(targetPackages, map_1(toPackageInfo, dependencies)), externals, (name_3) => ((options.NoLib && !FSharpSet__get_IsEmpty(included)) && !FSharpSet__Contains(included, name_3)));
|
|
332
|
-
const readerResult = readPackages(checker, packageContext, filter_1((sourceFile) => (PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile.fileName) != null), toList(program.getSourceFiles())));
|
|
333
|
-
const transformResult = applyWith("REPLACE_ME_WITH_MODULE_NAME", readerResult.TypeMemory, (matchValue_8 = options.Include, isEmpty(matchValue_8) ? readerResult.GlueAST : keepIncluded(ofSeq(matchValue_8, {
|
|
334
580
|
Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
|
|
335
|
-
})
|
|
581
|
+
});
|
|
582
|
+
const exportsMapPackages = ofSeq(map_1((description_5) => (normalizePath(description_5.dir) + "/"), filter_1((description_4) => description_4.hasExportsMap, append(targets, dependencies))), {
|
|
583
|
+
Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
|
|
584
|
+
});
|
|
585
|
+
const ambientNames = ambientModuleNames(checker);
|
|
586
|
+
const packageContext = new PackageContext(map_1((package$_3) => {
|
|
587
|
+
const hasExportsMap = FSharpSet__Contains(exportsMapPackages, package$_3.Dir);
|
|
588
|
+
const ambientModuleFiles = ofSeq_1(choose_1((sourceFile) => {
|
|
589
|
+
const fileName_1 = normalizePath(sourceFile.fileName);
|
|
590
|
+
if (fileName_1.startsWith(package$_3.Dir)) {
|
|
591
|
+
const option_20 = promotedAmbientModule(sourceFile);
|
|
592
|
+
if (option_20 != null) {
|
|
593
|
+
return [fileName_1, ambientModuleSpecifier(ambientNames, option_20)];
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
return undefined;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
}, program.getSourceFiles()), {
|
|
603
|
+
Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
|
|
604
|
+
});
|
|
605
|
+
const patternInput_1 = reExportedSymbols(program, checker, hasExportsMap, package$_3);
|
|
606
|
+
const symbols = patternInput_1[0];
|
|
607
|
+
const defaultExportNames = patternInput_1[1];
|
|
608
|
+
let reExportedFiles;
|
|
609
|
+
const list_28 = toList(symbols);
|
|
610
|
+
reExportedFiles = fold((acc, tupledArg_3) => {
|
|
611
|
+
const file_1 = tupledArg_3[0][0];
|
|
612
|
+
if (containsKey(file_1, acc)) {
|
|
613
|
+
return acc;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
return add(file_1, tupledArg_3[1], acc);
|
|
617
|
+
}
|
|
618
|
+
}, empty({
|
|
619
|
+
Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
|
|
620
|
+
}), list_28);
|
|
621
|
+
const HoistableDeclarations = hasExportsMap ? hoistableDeclarations(program, checker, package$_3, reExportedFiles, defaultExportNames) : empty_1({
|
|
622
|
+
Compare: (x_10, y_10) => (compareArrays(x_10, y_10) | 0),
|
|
623
|
+
});
|
|
624
|
+
return new PackageInfo(package$_3.ModuleName, package$_3.RuntimeName, package$_3.HasRuntime, package$_3.Dir, package$_3.TypesRoot, package$_3.EntryFile, package$_3.SubpathEntries, symbols, reExportedFiles, reExportedNames(program, checker, hasExportsMap, package$_3), defaultExportNames, hasExportsMap, HoistableDeclarations, ambientModuleFiles);
|
|
625
|
+
}, append(targetPackages, map_1(toPackageInfo, dependencies))), externals, (name_4) => ((options.NoLib && !FSharpSet__get_IsEmpty(included)) && !FSharpSet__Contains(included, name_4)), ambientNames);
|
|
626
|
+
const readerResult = readPackages(checker, packageContext, filter_1((sourceFile_1) => (PackageContext__TryFindPackage_Z721C83C5(packageContext, sourceFile_1.fileName) != null), toList_1(program.getSourceFiles())));
|
|
627
|
+
let glueAst;
|
|
628
|
+
const matchValue_4 = options.Include;
|
|
629
|
+
glueAst = (isEmpty(matchValue_4) ? readerResult.GlueAST : keepIncluded(ofSeq(matchValue_4, {
|
|
630
|
+
Compare: (x_11, y_11) => (comparePrimitives(x_11, y_11) | 0),
|
|
631
|
+
}), readerResult.GlueAST));
|
|
632
|
+
const transformResult = applyWithOptions(new TransformOptions(new ImportSource(/* Module */ 0, ["REPLACE_ME_WITH_MODULE_NAME", empty({
|
|
633
|
+
Compare: (x_12, y_12) => (comparePrimitives(x_12, y_12) | 0),
|
|
634
|
+
})]), options.MaxOverloads), readerResult.TypeMemory, glueAst);
|
|
336
635
|
const printer = Printer_$ctor();
|
|
337
|
-
printFileWith(patternInput[0], true, map_1((
|
|
338
|
-
return new GenerationResult(readerResult.GlueAST, transformResult.FSharpAST, toString(printer),
|
|
636
|
+
printFileWith(patternInput[0], true, map_1((_arg_10) => _arg_10.ModuleName, externals), printer, transformResult);
|
|
637
|
+
return new GenerationResult(readerResult.GlueAST, transformResult.FSharpAST, toString(printer), toList_1(delay(() => append_1(readerResult.Warnings, delay(() => transformResult.Warnings)))), toList_1(transformResult.Errors));
|
|
339
638
|
}
|
|
340
639
|
|
|
341
640
|
export function generate(host, inputs) {
|