@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.
Files changed (47) 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 +116 -65
  6. package/dist/Glutinum.Converter/Generate.js +34 -21
  7. package/dist/Glutinum.Converter/GlueAST.js +79 -41
  8. package/dist/Glutinum.Converter/Hosting.js +132 -157
  9. package/dist/Glutinum.Converter/Merge.js +369 -337
  10. package/dist/Glutinum.Converter/Packages.js +391 -92
  11. package/dist/Glutinum.Converter/Printer.js +404 -424
  12. package/dist/Glutinum.Converter/Read.js +387 -88
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
  14. package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
  15. package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
  16. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
  17. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
  18. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
  19. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +15 -21
  20. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
  21. package/dist/Glutinum.Converter/Reader/Node.js +8 -11
  22. package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
  23. package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1343
  24. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
  25. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
  26. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
  27. package/dist/Glutinum.Converter/Reader/Types.js +290 -15
  28. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
  29. package/dist/Glutinum.Converter/Reader/Utils.js +343 -28
  30. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
  31. package/dist/Glutinum.Converter/Transform.js +3619 -8456
  32. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  33. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  34. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  35. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
  36. package/dist/Glutinum.Converter/Transformer/Context.js +664 -0
  37. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  38. package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
  39. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  40. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
  41. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  42. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
  43. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  44. package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
  45. package/dist/Glutinum.Converter/Utils/String.js +14 -3
  46. package/dist/Program.js +18 -10
  47. package/package.json +1 -1
@@ -1,19 +1,19 @@
1
1
 
2
2
  import { concat, replace as replace_1, substring, join, split as split_1 } from "../fable_modules/fable-library-js.5.17.2/String.js";
3
- import { contains, map as map_1, addRangeInPlace, tryFind, choose, item } from "../fable_modules/fable-library-js.5.17.2/Array.js";
4
- import { singleton, collect, filter, tryFind as tryFind_1, exists as exists_1, delay, toList, map, toArray } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
3
+ import { contains, map as map_2, addRangeInPlace, tryPick, choose, map2, tryFind, item } from "../fable_modules/fable-library-js.5.17.2/Array.js";
4
+ import { collect, singleton, ofArray as ofArray_1, filter, tryFind as tryFind_1, exists as exists_1, delay, toList, map, toArray } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
5
5
  import { ts, InMemoryFileSystemHost, createProjectSync } from "@ts-morph/bootstrap";
6
6
  import * as path_1 from "path";
7
7
  import * as fs from "fs";
8
+ import { toNullable, defaultArg, value as value_7, some } from "../fable_modules/fable-library-js.5.17.2/Option.js";
8
9
  import { replace, split as split_2, match, isMatch } from "../fable_modules/fable-library-js.5.17.2/RegExp.js";
9
- import { stringHash, Exception, disposeSafe, getEnumerator } from "../fable_modules/fable-library-js.5.17.2/Util.js";
10
- import { ofArray, exists } from "../fable_modules/fable-library-js.5.17.2/List.js";
10
+ import { stringHash, defaultOf, Exception, disposeSafe, getEnumerator } from "../fable_modules/fable-library-js.5.17.2/Util.js";
11
+ import { head, isEmpty, tryPick as tryPick_1, map as map_1, filter as filter_1, ofArray, exists } from "../fable_modules/fable-library-js.5.17.2/List.js";
11
12
  import { tryParse } from "../fable_modules/fable-library-js.5.17.2/Int32.js";
12
13
  import { FSharpRef } from "../fable_modules/fable-library-js.5.17.2/Types.js";
13
- import { toNullable, value as value_2, some } from "../fable_modules/fable-library-js.5.17.2/Option.js";
14
14
  import { PromiseBuilder__For_1565554B, PromiseBuilder__While_2044D34, PromiseBuilder__Delay_62FBFDE1, PromiseBuilder__Run_212F1D4B } from "../fable_modules/Fable.Promise.3.2.1/Promise.fs.js";
15
15
  import { promise } from "../fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js";
16
- import { addToSet, getItemFromDict } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
16
+ import { addToSet, tryGetValue, getItemFromDict } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
17
17
  import { rangeDouble } from "../fable_modules/fable-library-js.5.17.2/Range.js";
18
18
 
19
19
  const declarationFile = /\.d\.[cm]?ts$/gu;
@@ -209,6 +209,16 @@ export function createNodeHost(cwd) {
209
209
  )();
210
210
  }
211
211
 
212
+ function Dynamic_tryProp(o, key) {
213
+ const value = o[key];
214
+ if (value === null || value === undefined) {
215
+ return undefined;
216
+ }
217
+ else {
218
+ return some(value);
219
+ }
220
+ }
221
+
212
222
  function Dynamic_replaceFirst(value, search, replacement) {
213
223
  const index = value.indexOf(search) | 0;
214
224
  if (index < 0) {
@@ -219,51 +229,43 @@ function Dynamic_replaceFirst(value, search, replacement) {
219
229
  }
220
230
  }
221
231
 
222
- export function Resolve_findNodeModules(host, cwd) {
223
- let dir = host.path.resolve([cwd]);
224
- let result = undefined;
225
- let go = true;
226
- while (go) {
227
- const candidate = host.path.join([dir, "node_modules"]);
228
- if (host.fs.directoryExists(candidate)) {
229
- result = candidate;
230
- go = false;
231
- }
232
- else {
233
- const parent = host.path.dirname(dir);
234
- if (parent === dir) {
235
- go = false;
232
+ function Resolve_walkUp(host_mut, start_mut, tryDir_mut) {
233
+ Resolve_walkUp:
234
+ while (true) {
235
+ const host = host_mut, start = start_mut, tryDir = tryDir_mut;
236
+ const matchValue = tryDir(start);
237
+ if (matchValue == null) {
238
+ const parent = host.path.dirname(start);
239
+ if (parent === start) {
240
+ return undefined;
236
241
  }
237
242
  else {
238
- dir = parent;
243
+ host_mut = host;
244
+ start_mut = parent;
245
+ tryDir_mut = tryDir;
246
+ continue Resolve_walkUp;
239
247
  }
240
248
  }
249
+ else {
250
+ return some(value_7(matchValue));
251
+ }
252
+ break;
241
253
  }
242
- return result;
254
+ }
255
+
256
+ export function Resolve_findNodeModules(host, cwd) {
257
+ return Resolve_walkUp(host, host.path.resolve([cwd]), (dir) => {
258
+ const candidate = host.path.join([dir, "node_modules"]);
259
+ return host.fs.directoryExists(candidate) ? candidate : undefined;
260
+ });
243
261
  }
244
262
 
245
263
  export function Resolve_findPackageDir(host, file) {
246
- let dir = host.path.dirname(host.path.resolve([file]));
247
- let result = undefined;
248
- let go = true;
249
- while (go) {
264
+ return Resolve_walkUp(host, host.path.dirname(host.path.resolve([file])), (dir) => {
250
265
  let x, o;
251
266
  const packageJsonPath = host.path.join([dir, "package.json"]);
252
- if (host.fs.fileExists(packageJsonPath) && !((x = ((o = JSON.parse(host.fs.readFile(packageJsonPath)), o["name"])), x === null || x === undefined))) {
253
- result = host.fs.realPath(dir);
254
- go = false;
255
- }
256
- else {
257
- const parent = host.path.dirname(dir);
258
- if (parent === dir) {
259
- go = false;
260
- }
261
- else {
262
- dir = parent;
263
- }
264
- }
265
- }
266
- return result;
267
+ return (host.fs.fileExists(packageJsonPath) && !((x = ((o = JSON.parse(host.fs.readFile(packageJsonPath)), o["name"])), x === null || x === undefined))) ? host.fs.realPath(dir) : undefined;
268
+ });
267
269
  }
268
270
 
269
271
  function Resolve_collectExportsTypes(exportsField) {
@@ -367,15 +369,7 @@ function Resolve_parseVersion(version) {
367
369
  }
368
370
 
369
371
  function Resolve_compareVersions(a, b) {
370
- let result = 0;
371
- let i = 0;
372
- while ((i < 3) && (result === 0)) {
373
- if (item(i, a) !== item(i, b)) {
374
- result = ((item(i, a) - item(i, b)) | 0);
375
- }
376
- i = ((i + 1) | 0);
377
- }
378
- return result | 0;
372
+ return defaultArg(tryFind((y_1) => (0 !== y_1), map2((x, y) => ((x - y) | 0), a, b, Int32Array)), 0) | 0;
379
373
  }
380
374
 
381
375
  function Resolve_satisfiesComparator(version, comparator) {
@@ -468,29 +462,21 @@ function Resolve_applyTypesVersions(typesVersions, file) {
468
462
  const option_1 = tryFind((tupledArg) => Resolve_satisfiesRange(ts.version, tupledArg[0]), Object.entries(typesVersions));
469
463
  paths = ((option_1 != null) ? some(option_1[1]) : undefined);
470
464
  if (paths != null) {
471
- const paths_1 = value_2(paths);
465
+ const paths_1 = value_7(paths);
472
466
  const normalized = replace(file, "^\\./", "");
473
- let found = undefined;
474
- const arr = Object.entries(paths_1);
475
- for (let idx = 0; idx <= (arr.length - 1); idx++) {
476
- const forLoopVar = item(idx, arr);
477
- if (found == null) {
478
- const split = split_1(forLoopVar[0], ["*"], undefined, 0);
479
- const prefix = item(0, split);
480
- const suffix = (split.length > 1) ? item(1, split) : "";
481
- const targets_1 = forLoopVar[1];
482
- if ((normalized.startsWith(prefix) && normalized.endsWith(suffix)) && (targets_1.length > 0)) {
483
- const captured = substring(normalized, prefix.length, (normalized.length - suffix.length) - prefix.length);
484
- found = replace_1(item(0, targets_1), "*", captured);
485
- }
467
+ return defaultArg(tryPick((tupledArg_1) => {
468
+ const split = split_1(tupledArg_1[0], ["*"], undefined, 0);
469
+ const prefix = item(0, split);
470
+ const suffix = (split.length > 1) ? item(1, split) : "";
471
+ const targets_1 = tupledArg_1[1];
472
+ if ((normalized.startsWith(prefix) && normalized.endsWith(suffix)) && (targets_1.length > 0)) {
473
+ const captured = substring(normalized, prefix.length, (normalized.length - suffix.length) - prefix.length);
474
+ return replace_1(item(0, targets_1), "*", captured);
486
475
  }
487
- }
488
- if (found == null) {
489
- return file;
490
- }
491
- else {
492
- return found;
493
- }
476
+ else {
477
+ return undefined;
478
+ }
479
+ }, Object.entries(paths_1)), file);
494
480
  }
495
481
  else {
496
482
  return file;
@@ -499,28 +485,30 @@ function Resolve_applyTypesVersions(typesVersions, file) {
499
485
  }
500
486
 
501
487
  export function Resolve_describePackage(host, packageDir) {
488
+ let option_1;
502
489
  const packageJsonPath = host.path.join([packageDir, "package.json"]);
503
490
  if (!host.fs.fileExists(packageJsonPath)) {
504
491
  return undefined;
505
492
  }
506
493
  else {
507
494
  const pkg = JSON.parse(host.fs.readFile(packageJsonPath));
508
- let name;
509
- const matchValue = pkg["name"];
510
- name = (!(matchValue === null || matchValue === undefined) ? matchValue : host.path.basename(packageDir));
511
- let runtimeName = name;
495
+ const name = defaultArg((option_1 = Dynamic_tryProp(pkg, "name"), (option_1 != null) ? value_7(option_1) : undefined), host.path.basename(packageDir));
496
+ let runtimeName;
512
497
  if (name.startsWith("@types/")) {
513
498
  const typed = substring(name, "@types/".length);
514
499
  runtimeName = ((typed.indexOf("__") >= 0) ? ("@" + replace_1(typed, "__", "/")) : typed);
515
500
  }
501
+ else {
502
+ runtimeName = name;
503
+ }
516
504
  const candidates = [];
517
505
  let typesField;
518
- const matchValue_1 = pkg["types"];
519
- typesField = (!(matchValue_1 === null || matchValue_1 === undefined) ? matchValue_1 : (pkg["typings"]));
506
+ const option_4 = Dynamic_tryProp(pkg, "types");
507
+ typesField = ((option_4 != null) ? value_7(option_4) : (pkg["typings"]));
508
+ addRangeInPlace(Resolve_collectExportsTypes(pkg["exports"]), candidates);
520
509
  if ((typeof typesField) === "string") {
521
510
  void (candidates.push([".", typesField]));
522
511
  }
523
- addRangeInPlace(Resolve_collectExportsTypes(pkg["exports"]), candidates);
524
512
  const mainField = pkg["main"];
525
513
  if ((typeof mainField) === "string") {
526
514
  void (candidates.push([".", replace(mainField, "\\.[cm]?js$", ".d.ts")]));
@@ -559,9 +547,9 @@ export function Resolve_describePackage(host, packageDir) {
559
547
  finally {
560
548
  disposeSafe(enumerator);
561
549
  }
562
- const matchValue_2 = tryFind_1((entry_1) => (entry_1.subpath === "."), entries);
563
- if (matchValue_2 != null) {
564
- const main = matchValue_2;
550
+ const matchValue = tryFind_1((entry_1) => (entry_1.subpath === "."), entries);
551
+ if (matchValue != null) {
552
+ const main = matchValue;
565
553
  return new (class {
566
554
  get name() {
567
555
  return name;
@@ -581,6 +569,10 @@ export function Resolve_describePackage(host, packageDir) {
581
569
  get entryFile() {
582
570
  return main.file;
583
571
  }
572
+ get hasExportsMap() {
573
+ let x_2;
574
+ return !((x_2 = (pkg["exports"]), x_2 === null || x_2 === undefined));
575
+ }
584
576
  get subpathEntries() {
585
577
  return toArray(map((entry_3) => (new (class {
586
578
  get subpath() {
@@ -619,6 +611,9 @@ function Resolve_resolvedPackage(packageDir) {
619
611
 
620
612
  export function Resolve_resolveInput(host, input) {
621
613
  const asPath = host.path.resolve([host.cwd, input]);
614
+ const notFound = () => {
615
+ throw new Exception(concat("Could not find \'", input, "\': it is neither a declaration file, a package directory, nor a package installed in node_modules."));
616
+ };
622
617
  if (isMatch(declarationFile, input) && host.fs.fileExists(asPath)) {
623
618
  return Resolve_resolvedFile(asPath);
624
619
  }
@@ -627,48 +622,36 @@ export function Resolve_resolveInput(host, input) {
627
622
  }
628
623
  else {
629
624
  const matchValue = Resolve_findNodeModules(host, host.cwd);
630
- if (matchValue == null) {
631
- throw new Exception(concat("Could not find \'", input, "\': it is neither a declaration file, a package directory, nor a package installed in node_modules."));
632
- }
633
- else {
625
+ if (matchValue != null) {
634
626
  const nodeModules = matchValue;
635
627
  const segments = split_1(input, ["/"], undefined, 0);
636
628
  const packageName = input.startsWith("@") ? join("/", segments.slice(0, 1 + 1)) : item(0, segments);
637
629
  const typesPackage = host.path.join(["@types", Dynamic_replaceFirst(replace(packageName, "^@", ""), "/", "__")]);
638
- let withoutDeclaration = undefined;
639
- let result = undefined;
640
- const enumerator = getEnumerator([packageName, typesPackage]);
641
- try {
642
- while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
643
- const candidate = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
644
- if (result == null) {
645
- const packageDir = host.fs.realPath(host.path.join([nodeModules, candidate]));
646
- if (host.fs.fileExists(host.path.join([packageDir, "package.json"]))) {
647
- if (Resolve_describePackage(host, packageDir) != null) {
648
- result = Resolve_resolvedPackage(packageDir);
649
- }
650
- else if (withoutDeclaration == null) {
651
- withoutDeclaration = candidate;
652
- }
653
- }
654
- }
630
+ const installed = filter_1((tupledArg) => host.fs.fileExists(host.path.join([tupledArg[1], "package.json"])), map_1((candidate) => [candidate, host.fs.realPath(host.path.join([nodeModules, candidate]))], ofArray([packageName, typesPackage])));
631
+ const resolved = tryPick_1((tupledArg_1) => {
632
+ const packageDir_1 = tupledArg_1[1];
633
+ if (Resolve_describePackage(host, packageDir_1) != null) {
634
+ return Resolve_resolvedPackage(packageDir_1);
655
635
  }
656
- }
657
- finally {
658
- disposeSafe(enumerator);
659
- }
660
- if (result == null) {
661
- if (withoutDeclaration == null) {
662
- throw new Exception(concat("Could not find \'", input, "\': it is neither a declaration file, a package directory, nor a package installed in node_modules."));
636
+ else {
637
+ return undefined;
638
+ }
639
+ }, installed);
640
+ if (resolved == null) {
641
+ if (isEmpty(installed)) {
642
+ return notFound();
663
643
  }
664
644
  else {
665
- throw new Exception(`'${value_2(withoutDeclaration)}' ships no type declaration, install '${typesPackage}' and generate that instead.`);
645
+ throw new Exception(`'${head(installed)[0]}' ships no type declaration, install '${typesPackage}' and generate that instead.`);
666
646
  }
667
647
  }
668
648
  else {
669
- return result;
649
+ return resolved;
670
650
  }
671
651
  }
652
+ else {
653
+ return notFound();
654
+ }
672
655
  }
673
656
  }
674
657
 
@@ -734,27 +717,29 @@ export function Npm_parsePackageSpec(spec) {
734
717
  * `/node_modules` of the file system, like `npm install` would, from jsDelivr
735
718
  */
736
719
  export function Npm_installPackage(fileSystem, spec, options) {
737
- let matchValue_2;
738
- let fetchImpl;
739
- const matchValue = options["fetch"];
740
- fetchImpl = (!(matchValue === null || matchValue === undefined) ? matchValue : (globalThis.fetch));
741
- let onProgress;
742
- const matchValue_1 = options["onProgress"];
743
- onProgress = (!(matchValue_1 === null || matchValue_1 === undefined) ? matchValue_1 : ((value) => {
744
- }));
745
- const skip = new Set((matchValue_2 = (options["skip"]), !(matchValue_2 === null || matchValue_2 === undefined) ? matchValue_2 : ["@types/node"]));
720
+ let option_1, option_4, option_7;
721
+ const fetchImpl = defaultArg((option_1 = Dynamic_tryProp(options, "fetch"), (option_1 != null) ? value_7(option_1) : undefined), globalThis.fetch);
722
+ const onProgress = defaultArg((option_4 = Dynamic_tryProp(options, "onProgress"), (option_4 != null) ? value_7(option_4) : undefined), (value_2) => {
723
+ });
724
+ const skip = new Set(defaultArg((option_7 = Dynamic_tryProp(options, "skip"), (option_7 != null) ? ofArray_1(value_7(option_7)) : undefined), singleton("@types/node")));
746
725
  const installed = new Map([]);
747
726
  const ignoreP = (p) => PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (p.then((_arg) => (Promise.resolve(undefined))))));
748
- const install = (name, range) => PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => ((installed.has(name) ? true : skip.has(name)) ? (Promise.resolve(installed.has(name) ? getItemFromDict(installed, name) : undefined)) : (fetchImpl(`${"https://data.jsdelivr.com/v1/package"}/resolve/npm/${name}@${encodeURIComponent(range)}`).then((_arg_3) => {
749
- const resolveResponse = _arg_3;
727
+ const fetchOk = (url) => PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (fetchImpl(url).then((_arg_1) => {
728
+ const response = _arg_1;
729
+ return !response.ok ? (Promise.resolve((() => {
730
+ throw new Exception(`${url}: ${response.status}`);
731
+ })())) : (Promise.resolve(response));
732
+ }))));
733
+ const install = (name, range) => PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => ((installed.has(name) ? true : skip.has(name)) ? (Promise.resolve(installed.has(name) ? getItemFromDict(installed, name) : undefined)) : (fetchImpl(`${"https://data.jsdelivr.com/v1/package"}/resolve/npm/${name}@${encodeURIComponent(range)}`).then((_arg_4) => {
734
+ const resolveResponse = _arg_4;
750
735
  return (resolveResponse.status === 404) ? (Promise.resolve((() => {
751
736
  throw new Exception(concat("No package named \'", name, "\' on npm"));
752
737
  })())) : (!resolveResponse.ok ? (Promise.resolve((() => {
753
738
  throw new Exception(`${resolveResponse.url}: ${resolveResponse.status}`);
754
- })())) : (resolveResponse.json().then((_arg_4) => {
755
- let x_3, url;
756
- const resolved = _arg_4;
757
- if ((x_3 = (resolved["version"]), x_3 === null || x_3 === undefined)) {
739
+ })())) : (resolveResponse.json().then((_arg_5) => {
740
+ let x;
741
+ const resolved = _arg_5;
742
+ if ((x = (resolved["version"]), x === null || x === undefined)) {
758
743
  return Promise.resolve((() => {
759
744
  throw new Exception(`No version of '${name}' matches '${range}'`);
760
745
  })());
@@ -766,15 +751,10 @@ export function Npm_installPackage(fileSystem, spec, options) {
766
751
  version: version,
767
752
  });
768
753
  onProgress(concat(name, "@", version, ": listing files"));
769
- return ((url = (`${"https://data.jsdelivr.com/v1/package"}/npm/${name}@${version}/flat`), PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (fetchImpl(url).then((_arg_1) => {
770
- const response = _arg_1;
771
- return !response.ok ? (Promise.resolve((() => {
772
- throw new Exception(`${url}: ${response.status}`);
773
- })())) : (response.json());
774
- })))))).then((_arg_5) => {
754
+ return PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (fetchOk(`${"https://data.jsdelivr.com/v1/package"}/npm/${name}@${version}/flat`).then((_arg_2) => (_arg_2.json()))))).then((_arg_6) => {
775
755
  let array_1;
776
- const files = _arg_5["files"];
777
- const wanted = Array.from((array_1 = map_1((file) => (file["name"]), files), array_1.filter((file_1) => {
756
+ const files = _arg_6["files"];
757
+ const wanted = Array.from((array_1 = map_2((file) => (file["name"]), files), array_1.filter((file_1) => {
778
758
  if (isMatch(declarationFile, file_1)) {
779
759
  return true;
780
760
  }
@@ -783,32 +763,26 @@ export function Npm_installPackage(fileSystem, spec, options) {
783
763
  }
784
764
  })));
785
765
  let doneCount = 0;
786
- return (Promise.all(toArray(delay(() => collect((matchValue_3) => singleton(PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => PromiseBuilder__While_2044D34(promise, () => (wanted.length > 0), PromiseBuilder__Delay_62FBFDE1(promise, () => {
787
- let url_1;
766
+ return (Promise.all(toArray(delay(() => collect((matchValue) => singleton(PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => PromiseBuilder__While_2044D34(promise, () => (wanted.length > 0), PromiseBuilder__Delay_62FBFDE1(promise, () => {
788
767
  const file_2 = item(0, wanted);
789
768
  wanted.splice(0, 1);
790
- return ((url_1 = (`${"https://cdn.jsdelivr.net/npm"}/${name}@${version}${file_2}`), PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (fetchImpl(url_1).then((_arg_2) => {
791
- const response_1 = _arg_2;
792
- return !response_1.ok ? (Promise.resolve((() => {
793
- throw new Exception(`${url_1}: ${response_1.status}`);
794
- })())) : (response_1.text());
795
- })))))).then((_arg_6) => {
796
- fileSystem.writeFileSync(concat("/node_modules/", name, file_2), _arg_6);
769
+ return PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (fetchOk(`${"https://cdn.jsdelivr.net/npm"}/${name}@${version}${file_2}`).then((_arg_3) => (_arg_3.text()))))).then((_arg_7) => {
770
+ fileSystem.writeFileSync(concat("/node_modules/", name, file_2), _arg_7);
797
771
  doneCount = ((doneCount + 1) | 0);
798
772
  onProgress(`${name}@${version}: ${doneCount} files`);
799
773
  return Promise.resolve();
800
774
  });
801
- }))))), rangeDouble(1, 1, 8)))))).then((_arg_7) => {
775
+ }))))), rangeDouble(1, 1, 8)))))).then((_arg_8) => {
802
776
  const packageJson = JSON.parse(fileSystem.readFileSync(concat("/node_modules/", name, "/package.json"), "utf8"));
803
777
  return (files.some((file_3) => isMatch(javaScriptFile, file_3["name"])) ? ((fileSystem.writeFileSync(concat("/node_modules/", name, "/", ".glutinum-runtime"), ""), Promise.resolve())) : (Promise.resolve())).then(() => PromiseBuilder__Delay_62FBFDE1(promise, () => {
804
778
  const hasDeclarations = files.some((file_4) => isMatch(declarationFile, file_4["name"]));
805
- return ((!hasDeclarations && !name.startsWith("@types/")) ? (PromiseBuilder__Delay_62FBFDE1(promise, () => (ignoreP(install(Npm_typesPackageName(name), "latest")).then(() => (Promise.resolve(undefined))))).catch((_arg_9) => {
779
+ return ((!hasDeclarations && !name.startsWith("@types/")) ? (PromiseBuilder__Delay_62FBFDE1(promise, () => (ignoreP(install(Npm_typesPackageName(name), "latest")).then(() => (Promise.resolve(undefined))))).catch((_arg_10) => {
806
780
  return Promise.resolve();
807
781
  })) : (Promise.resolve())).then(() => PromiseBuilder__Delay_62FBFDE1(promise, () => {
808
782
  let dependencies;
809
- const matchValue_4 = packageJson["dependencies"];
810
- dependencies = (!(matchValue_4 === null || matchValue_4 === undefined) ? matchValue_4 : {});
811
- return PromiseBuilder__For_1565554B(promise, Object.entries(dependencies), (_arg_10) => (ignoreP(install(_arg_10[0], _arg_10[1])).then(() => (Promise.resolve(undefined))))).then(() => PromiseBuilder__Delay_62FBFDE1(promise, () => (Promise.resolve(installed.has(name) ? getItemFromDict(installed, name) : undefined))));
783
+ const option_10 = Dynamic_tryProp(packageJson, "dependencies");
784
+ dependencies = ((option_10 != null) ? value_7(option_10) : {});
785
+ return PromiseBuilder__For_1565554B(promise, Object.entries(dependencies), (_arg_11) => (ignoreP(install(_arg_11[0], _arg_11[1])).then(() => (Promise.resolve(undefined))))).then(() => PromiseBuilder__Delay_62FBFDE1(promise, () => (Promise.resolve(getItemFromDict(installed, name)))));
812
786
  }));
813
787
  }));
814
788
  });
@@ -818,7 +792,7 @@ export function Npm_installPackage(fileSystem, spec, options) {
818
792
  })))));
819
793
  return PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => {
820
794
  const parsed = Npm_parsePackageSpec(spec);
821
- return install(parsed.name, parsed.range).then((_arg_12) => (Promise.resolve(toNullable(_arg_12))));
795
+ return install(parsed.name, parsed.range).then((_arg_13) => (Promise.resolve(toNullable(_arg_13))));
822
796
  }));
823
797
  }
824
798
 
@@ -835,12 +809,12 @@ export function Bootstrap_createProgramForCLI(_fileName, source) {
835
809
  /**
836
810
  * Create a program from declaration files of the host, following their imports
837
811
  */
838
- export function Bootstrap_createProgramFromFiles(host, entryFiles, withoutDomLib, noLib) {
812
+ export function Bootstrap_createProgramFromFiles(host, entryFiles, globalTypes, withoutDomLib, noLib) {
839
813
  const compilerOptions = {};
840
814
  compilerOptions.target = 99;
841
815
  compilerOptions.module = 99;
842
816
  compilerOptions.moduleResolution = 100;
843
- compilerOptions.types = [];
817
+ compilerOptions.types = Array.from(globalTypes);
844
818
  compilerOptions.strict = true;
845
819
  if (withoutDomLib) {
846
820
  compilerOptions.lib = ["lib.esnext.d.ts", "lib.decorators.d.ts", "lib.decorators.legacy.d.ts"];
@@ -866,15 +840,18 @@ export function Bootstrap_reachableFiles(host, program, entryFiles, excludedRunt
866
840
  const seen = new Set([]);
867
841
  const queue = Array.from(entryFiles);
868
842
  const visit = (fileName_1) => {
869
- let matchValue, dir, option_1, d, matchValue_1;
870
- if ((!(fileName_1 === null || fileName_1 === undefined) && !seen.has(fileName_1)) && !((matchValue = Resolve_findPackageDir(host, fileName_1), (matchValue != null) && ((dir = matchValue, (!runtimeNames.has(dir) ? runtimeNames.set(dir, (option_1 = Resolve_describePackage(host, dir), (option_1 != null) ? ((d = option_1, d.runtimeName)) : undefined)) : undefined, (matchValue_1 = getItemFromDict(runtimeNames, dir), (matchValue_1 == null) ? false : contains(matchValue_1, excludedRuntimeNames, {
843
+ let matchValue, dir, runtimeName_2, matchValue_1, outArg, runtimeName_1, option_1, _arg;
844
+ if ((!(fileName_1 === null || fileName_1 === undefined) && !seen.has(fileName_1)) && !((matchValue = Resolve_findPackageDir(host, fileName_1), (matchValue != null) && ((dir = matchValue, (runtimeName_2 = ((matchValue_1 = ((outArg = defaultOf(), [tryGetValue(runtimeNames, dir, new FSharpRef(() => outArg, (v) => {
845
+ outArg = v;
846
+ })), outArg])), matchValue_1[0] ? matchValue_1[1] : ((runtimeName_1 = ((option_1 = Resolve_describePackage(host, dir), (option_1 != null) ? ((_arg = option_1, _arg.runtimeName)) : undefined)), (runtimeNames.set(dir, runtimeName_1), runtimeName_1))))), (runtimeName_2 == null) ? false : contains(runtimeName_2, excludedRuntimeNames, {
871
847
  Equals: (x, y) => (x === y),
872
848
  GetHashCode: (x) => (stringHash(x) | 0),
873
- })))))))) {
849
+ }))))))) {
874
850
  void (queue.push(fileName_1));
875
851
  }
876
852
  };
877
853
  while (queue.length > 0) {
854
+ let option_3;
878
855
  const fileName_2 = item(queue.length - 1, queue);
879
856
  queue.splice(queue.length - 1, 1);
880
857
  if (!seen.has(fileName_2)) {
@@ -882,9 +859,7 @@ export function Bootstrap_reachableFiles(host, program, entryFiles, excludedRunt
882
859
  if (matchValue_2 != null) {
883
860
  const sourceFile = matchValue_2;
884
861
  addToSet(fileName_2, seen);
885
- let imports;
886
- const matchValue_3 = sourceFile.imports;
887
- imports = (!(matchValue_3 === null || matchValue_3 === undefined) ? matchValue_3 : []);
862
+ const imports = defaultArg((option_3 = Dynamic_tryProp(sourceFile, "imports"), (option_3 != null) ? value_7(option_3) : undefined), []);
888
863
  for (let idx = 0; idx <= (imports.length - 1); idx++) {
889
864
  const usage = item(idx, imports);
890
865
  visit(program.getResolvedModuleFromModuleSpecifier(usage, sourceFile)?.resolvedModule?.resolvedFileName);