@glutinum/cli 0.14.1 → 1.0.0-beta.10

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