@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.
- 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 +154 -69
- package/dist/Glutinum.Converter/Generate.js +44 -23
- package/dist/Glutinum.Converter/GlueAST.js +122 -74
- package/dist/Glutinum.Converter/Hosting.js +892 -0
- package/dist/Glutinum.Converter/Merge.js +469 -301
- package/dist/Glutinum.Converter/Packages.js +403 -77
- package/dist/Glutinum.Converter/Printer.js +455 -388
- package/dist/Glutinum.Converter/Read.js +366 -104
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +9 -9
- package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
- package/dist/Glutinum.Converter/Reader/Declaration.js +24 -30
- package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
- package/dist/Glutinum.Converter/Reader/Documentation.js +56 -67
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +105 -38
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +52 -55
- package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +28 -16
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +46 -45
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +48 -5
- package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
- package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +55 -7
- package/dist/Glutinum.Converter/Reader/Node.js +23 -26
- package/dist/Glutinum.Converter/Reader/Parameters.js +39 -30
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
- package/dist/Glutinum.Converter/Reader/TypeNode.js +410 -1545
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +78 -51
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +116 -71
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +25 -7
- package/dist/Glutinum.Converter/Reader/Types.js +296 -16
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +21 -34
- package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
- package/dist/Glutinum.Converter/Reader/Utils.js +584 -148
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +2971 -6875
- 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 +1087 -0
- package/dist/Glutinum.Converter/Transformer/Context.js +678 -0
- package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
- package/dist/Glutinum.Converter/Transformer/Exports.js +704 -0
- package/dist/Glutinum.Converter/Transformer/Heritage.js +493 -0
- package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
- package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameter.js +219 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
- package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +356 -0
- package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +193 -211
- package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
- package/dist/Glutinum.Converter/Utils/String.js +15 -4
- package/dist/Program.js +107 -232
- package/package.json +4 -3
- package/dist/Glutinum.Converter/TypeScript.js +0 -12
- package/src/Glutinum.Converter/js/bootstrap.js +0 -123
- package/src/Glutinum.Converter/js/host.js +0 -144
- package/src/Glutinum.Converter/js/npm.js +0 -137
- package/src/Glutinum.Converter/js/resolve.js +0 -402
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
|
|
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_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
|
+
import { ts, InMemoryFileSystemHost, createProjectSync } from "@ts-morph/bootstrap";
|
|
6
|
+
import * as path_1 from "path";
|
|
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";
|
|
9
|
+
import { replace, split as split_2, match, isMatch } from "../fable_modules/fable-library-js.5.17.2/RegExp.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";
|
|
12
|
+
import { tryParse } from "../fable_modules/fable-library-js.5.17.2/Int32.js";
|
|
13
|
+
import { FSharpRef } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
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
|
+
import { promise } from "../fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js";
|
|
16
|
+
import { addToSet, tryGetValue, getItemFromDict } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
|
|
17
|
+
import { rangeDouble } from "../fable_modules/fable-library-js.5.17.2/Range.js";
|
|
18
|
+
|
|
19
|
+
const declarationFile = /\.d\.[cm]?ts$/gu;
|
|
20
|
+
|
|
21
|
+
const javaScriptFile = /\.[cm]?js$/gu;
|
|
22
|
+
|
|
23
|
+
export function PosixPath_normalize(p) {
|
|
24
|
+
const absolute = p.startsWith("/");
|
|
25
|
+
const segments = [];
|
|
26
|
+
const arr = split_1(p, ["/"], undefined, 0);
|
|
27
|
+
for (let idx = 0; idx <= (arr.length - 1); idx++) {
|
|
28
|
+
const segment = item(idx, arr);
|
|
29
|
+
if ((segment === "") ? true : (segment === ".")) {
|
|
30
|
+
}
|
|
31
|
+
else if (segment === "..") {
|
|
32
|
+
if ((segments.length > 0) && (item(segments.length - 1, segments) !== "..")) {
|
|
33
|
+
segments.splice(segments.length - 1, 1);
|
|
34
|
+
}
|
|
35
|
+
else if (!absolute) {
|
|
36
|
+
void (segments.push(".."));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
void (segments.push(segment));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const joined = join("/", segments);
|
|
44
|
+
if (absolute) {
|
|
45
|
+
return "/" + joined;
|
|
46
|
+
}
|
|
47
|
+
else if (joined === "") {
|
|
48
|
+
return ".";
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return joined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function PosixPath_join(parts) {
|
|
56
|
+
return PosixPath_normalize(join("/", parts.filter((part) => (part !== ""))));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function PosixPath_dirname(p) {
|
|
60
|
+
const normalized = PosixPath_normalize(p);
|
|
61
|
+
const index = normalized.lastIndexOf("/") | 0;
|
|
62
|
+
switch (index) {
|
|
63
|
+
case -1:
|
|
64
|
+
return ".";
|
|
65
|
+
case 0:
|
|
66
|
+
return "/";
|
|
67
|
+
default:
|
|
68
|
+
return substring(normalized, 0, index);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function PosixPath_basename(p) {
|
|
73
|
+
const normalized = PosixPath_normalize(p);
|
|
74
|
+
return substring(normalized, normalized.lastIndexOf("/") + 1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function PosixPath_resolve(parts) {
|
|
78
|
+
let result = "/";
|
|
79
|
+
for (let idx = 0; idx <= (parts.length - 1); idx++) {
|
|
80
|
+
const part = item(idx, parts);
|
|
81
|
+
result = (part.startsWith("/") ? part : ((result + "/") + part));
|
|
82
|
+
}
|
|
83
|
+
return PosixPath_normalize(result);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const posixPath = {
|
|
87
|
+
join(parts) {
|
|
88
|
+
return PosixPath_join(parts);
|
|
89
|
+
},
|
|
90
|
+
dirname(p) {
|
|
91
|
+
return PosixPath_dirname(p);
|
|
92
|
+
},
|
|
93
|
+
basename(p_1) {
|
|
94
|
+
return PosixPath_basename(p_1);
|
|
95
|
+
},
|
|
96
|
+
resolve(parts_1) {
|
|
97
|
+
return PosixPath_resolve(parts_1);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A host over a ts-morph file system, the in-memory one in the browser
|
|
103
|
+
*/
|
|
104
|
+
export function createFileSystemHost(fileSystem, cwd) {
|
|
105
|
+
return new (class {
|
|
106
|
+
get cwd() {
|
|
107
|
+
return cwd;
|
|
108
|
+
}
|
|
109
|
+
get fileSystem() {
|
|
110
|
+
return fileSystem;
|
|
111
|
+
}
|
|
112
|
+
get path() {
|
|
113
|
+
return posixPath;
|
|
114
|
+
}
|
|
115
|
+
get fs() {
|
|
116
|
+
return {
|
|
117
|
+
fileExists(p) {
|
|
118
|
+
return fileSystem.fileExistsSync(p);
|
|
119
|
+
},
|
|
120
|
+
directoryExists(p_1) {
|
|
121
|
+
return fileSystem.directoryExistsSync(p_1);
|
|
122
|
+
},
|
|
123
|
+
readFile(p_2) {
|
|
124
|
+
return fileSystem.readFileSync(p_2, "utf8");
|
|
125
|
+
},
|
|
126
|
+
readDirectory(p_3) {
|
|
127
|
+
return toArray(map((entry) => entry.name, fileSystem.readDirSync(p_3)));
|
|
128
|
+
},
|
|
129
|
+
realPath(p_4) {
|
|
130
|
+
try {
|
|
131
|
+
return fileSystem.realpathSync(p_4);
|
|
132
|
+
}
|
|
133
|
+
catch (matchValue) {
|
|
134
|
+
return p_4;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
createProject(compilerOptions) {
|
|
140
|
+
return createProjectSync({
|
|
141
|
+
compilerOptions: compilerOptions,
|
|
142
|
+
skipAddingFilesFromTsConfig: true,
|
|
143
|
+
fileSystem: fileSystem,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
)();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function createInMemoryHost(cwd) {
|
|
151
|
+
return createFileSystemHost(new InMemoryFileSystemHost(), cwd);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The host of the CLI, over the disk
|
|
156
|
+
*/
|
|
157
|
+
export function createNodeHost(cwd) {
|
|
158
|
+
return new (class {
|
|
159
|
+
get cwd() {
|
|
160
|
+
return cwd;
|
|
161
|
+
}
|
|
162
|
+
get path() {
|
|
163
|
+
return {
|
|
164
|
+
join(parts) {
|
|
165
|
+
return path_1.join(...parts);
|
|
166
|
+
},
|
|
167
|
+
dirname(p) {
|
|
168
|
+
return path_1.dirname(p);
|
|
169
|
+
},
|
|
170
|
+
basename(p_1) {
|
|
171
|
+
return path_1.basename(p_1);
|
|
172
|
+
},
|
|
173
|
+
resolve(parts_1) {
|
|
174
|
+
return path_1.resolve(...parts_1);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
get fs() {
|
|
179
|
+
return {
|
|
180
|
+
fileExists(p_2) {
|
|
181
|
+
return fs.existsSync(p_2) && fs.statSync(p_2).isFile();
|
|
182
|
+
},
|
|
183
|
+
directoryExists(p_3) {
|
|
184
|
+
return fs.existsSync(p_3) && fs.statSync(p_3).isDirectory();
|
|
185
|
+
},
|
|
186
|
+
readFile(p_4) {
|
|
187
|
+
return fs.readFileSync(p_4, "utf8");
|
|
188
|
+
},
|
|
189
|
+
readDirectory(p_5) {
|
|
190
|
+
return fs.readdirSync(p_5);
|
|
191
|
+
},
|
|
192
|
+
realPath(p_6) {
|
|
193
|
+
try {
|
|
194
|
+
return fs.realpathSync(p_6);
|
|
195
|
+
}
|
|
196
|
+
catch (matchValue) {
|
|
197
|
+
return p_6;
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
createProject(compilerOptions) {
|
|
203
|
+
return createProjectSync({
|
|
204
|
+
compilerOptions: compilerOptions,
|
|
205
|
+
skipAddingFilesFromTsConfig: true,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
)();
|
|
210
|
+
}
|
|
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
|
+
|
|
222
|
+
function Dynamic_replaceFirst(value, search, replacement) {
|
|
223
|
+
const index = value.indexOf(search) | 0;
|
|
224
|
+
if (index < 0) {
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
return (substring(value, 0, index) + replacement) + substring(value, index + search.length);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
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;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
host_mut = host;
|
|
244
|
+
start_mut = parent;
|
|
245
|
+
tryDir_mut = tryDir;
|
|
246
|
+
continue Resolve_walkUp;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
return some(value_7(matchValue));
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
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
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function Resolve_findPackageDir(host, file) {
|
|
264
|
+
return Resolve_walkUp(host, host.path.dirname(host.path.resolve([file])), (dir) => {
|
|
265
|
+
let x, o;
|
|
266
|
+
const packageJsonPath = host.path.join([dir, "package.json"]);
|
|
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
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function Resolve_collectExportsTypes(exportsField) {
|
|
272
|
+
const result = [];
|
|
273
|
+
const visit = (subpath, node) => {
|
|
274
|
+
if (node === null || node === undefined) {
|
|
275
|
+
}
|
|
276
|
+
else if ((typeof node) === "string") {
|
|
277
|
+
const text = node;
|
|
278
|
+
if (isMatch(declarationFile, text)) {
|
|
279
|
+
void (result.push([subpath, text]));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else if ((typeof node) === "object") {
|
|
283
|
+
const arr = Object.entries(node);
|
|
284
|
+
for (let idx = 0; idx <= (arr.length - 1); idx++) {
|
|
285
|
+
const forLoopVar = item(idx, arr);
|
|
286
|
+
const value = forLoopVar[1];
|
|
287
|
+
const key = forLoopVar[0];
|
|
288
|
+
if (key.startsWith(".")) {
|
|
289
|
+
visit(key, value);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
visit(subpath, value);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
visit(".", exportsField);
|
|
298
|
+
const bySubpath = new Map([]);
|
|
299
|
+
let enumerator = getEnumerator(result);
|
|
300
|
+
try {
|
|
301
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
302
|
+
const forLoopVar_1 = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
303
|
+
const subpath_1 = forLoopVar_1[0];
|
|
304
|
+
if (!bySubpath.has(subpath_1)) {
|
|
305
|
+
bySubpath.set(subpath_1, forLoopVar_1[1]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
disposeSafe(enumerator);
|
|
311
|
+
}
|
|
312
|
+
return toList(delay(() => map((entry) => [entry[0], entry[1]], bySubpath)));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function Resolve_exportsRuntimeFile(node) {
|
|
316
|
+
if ((typeof node) === "string") {
|
|
317
|
+
return !isMatch(declarationFile, node);
|
|
318
|
+
}
|
|
319
|
+
else if (!(node === null || node === undefined) && ((typeof node) === "object")) {
|
|
320
|
+
const array = Object.values(node);
|
|
321
|
+
return array.some(Resolve_exportsRuntimeFile);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function Resolve_hasRuntime(host, packageDir, pkg) {
|
|
329
|
+
const declared = (field) => {
|
|
330
|
+
if ((typeof field) === "string") {
|
|
331
|
+
return field !== "";
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
return !(field === null || field === undefined);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
if (((declared(pkg["main"]) ? true : declared(pkg["module"])) ? true : declared(pkg["bin"])) ? true : declared(pkg["browser"])) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
else if (Resolve_exportsRuntimeFile(pkg["exports"])) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
return exists((file) => host.fs.fileExists(host.path.join([packageDir, file])), ofArray(["index.js", "index.mjs", "index.cjs", ".glutinum-runtime"]));
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function Resolve_parseVersion(version) {
|
|
349
|
+
const parts = split_1(version, ["."], undefined, 0);
|
|
350
|
+
const at = (i) => {
|
|
351
|
+
if (i < parts.length) {
|
|
352
|
+
let matchValue;
|
|
353
|
+
let outArg = 0;
|
|
354
|
+
matchValue = [tryParse(item(i, parts), 511, false, 32, new FSharpRef(() => (outArg | 0), (v) => {
|
|
355
|
+
outArg = (v | 0);
|
|
356
|
+
})), outArg];
|
|
357
|
+
if (matchValue[0]) {
|
|
358
|
+
return matchValue[1] | 0;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
return 0;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
return new Int32Array([at(0), at(1), at(2)]);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function Resolve_compareVersions(a, b) {
|
|
372
|
+
return defaultArg(tryFind((y_1) => (0 !== y_1), map2((x, y) => ((x - y) | 0), a, b, Int32Array)), 0) | 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function Resolve_satisfiesComparator(version, comparator) {
|
|
376
|
+
const m = match(/^(>=|<=|>|<|=|\^|~)?\s*(.+)$/gu, comparator);
|
|
377
|
+
if (!(m != null)) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
const operator = ((m[1] != null) && ((m[1] || "") !== "")) ? (m[1] || "") : "=";
|
|
382
|
+
const text = m[2] || "";
|
|
383
|
+
if ((text === "*") ? true : (text === "x")) {
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
const parts = choose((part) => {
|
|
388
|
+
let matchValue;
|
|
389
|
+
let outArg = 0;
|
|
390
|
+
matchValue = [tryParse(part, 511, false, 32, new FSharpRef(() => (outArg | 0), (v) => {
|
|
391
|
+
outArg = (v | 0);
|
|
392
|
+
})), outArg];
|
|
393
|
+
if (matchValue[0]) {
|
|
394
|
+
return matchValue[1];
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
}, split_1(text, ["."], undefined, 0), Int32Array);
|
|
400
|
+
const g = (i) => {
|
|
401
|
+
if (i < parts.length) {
|
|
402
|
+
return item(i, parts) | 0;
|
|
403
|
+
}
|
|
404
|
+
else {
|
|
405
|
+
return 0;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
const lower = new Int32Array([g(0), g(1), g(2)]);
|
|
409
|
+
let upper;
|
|
410
|
+
const matchValue_1 = parts.length | 0;
|
|
411
|
+
upper = ((matchValue_1 === 1) ? (new Int32Array([item(0, lower) + 1, 0, 0])) : ((matchValue_1 === 2) ? (new Int32Array([item(0, lower), item(1, lower) + 1, 0])) : (new Int32Array([item(0, lower), item(1, lower), item(2, lower) + 1]))));
|
|
412
|
+
switch (operator) {
|
|
413
|
+
case ">=":
|
|
414
|
+
return Resolve_compareVersions(version, lower) >= 0;
|
|
415
|
+
case ">":
|
|
416
|
+
return Resolve_compareVersions(version, upper) >= 0;
|
|
417
|
+
case "<":
|
|
418
|
+
return Resolve_compareVersions(version, lower) < 0;
|
|
419
|
+
case "<=":
|
|
420
|
+
return Resolve_compareVersions(version, upper) < 0;
|
|
421
|
+
case "^":
|
|
422
|
+
if (Resolve_compareVersions(version, lower) >= 0) {
|
|
423
|
+
return Resolve_compareVersions(version, new Int32Array([item(0, lower) + 1, 0, 0])) < 0;
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
case "~":
|
|
429
|
+
if (Resolve_compareVersions(version, lower) >= 0) {
|
|
430
|
+
return Resolve_compareVersions(version, new Int32Array([item(0, lower), item(1, lower) + 1, 0])) < 0;
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
default:
|
|
436
|
+
if (Resolve_compareVersions(version, lower) >= 0) {
|
|
437
|
+
return Resolve_compareVersions(version, upper) < 0;
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function Resolve_satisfiesRange(version, range) {
|
|
448
|
+
const parsed = Resolve_parseVersion(version);
|
|
449
|
+
const array_1 = split_1(range, ["||"], undefined, 0);
|
|
450
|
+
return array_1.some((alternative) => {
|
|
451
|
+
const array = split_2(alternative.trim(), "\\s+");
|
|
452
|
+
return array.every((comparator) => Resolve_satisfiesComparator(parsed, comparator));
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
export function Resolve_applyTypesVersions(typesVersions, file) {
|
|
457
|
+
if (typesVersions === null || typesVersions === undefined) {
|
|
458
|
+
return file;
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
let paths;
|
|
462
|
+
const option_1 = tryFind((tupledArg) => Resolve_satisfiesRange(ts.version, tupledArg[0]), Object.entries(typesVersions));
|
|
463
|
+
paths = ((option_1 != null) ? some(option_1[1]) : undefined);
|
|
464
|
+
if (paths != null) {
|
|
465
|
+
const paths_1 = value_7(paths);
|
|
466
|
+
const normalized = replace(file, "^\\./", "");
|
|
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);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
}, Object.entries(paths_1)), file);
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
return file;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export function Resolve_describePackage(host, packageDir) {
|
|
488
|
+
let option_1;
|
|
489
|
+
const packageJsonPath = host.path.join([packageDir, "package.json"]);
|
|
490
|
+
if (!host.fs.fileExists(packageJsonPath)) {
|
|
491
|
+
return undefined;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
const pkg = JSON.parse(host.fs.readFile(packageJsonPath));
|
|
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;
|
|
497
|
+
if (name.startsWith("@types/")) {
|
|
498
|
+
const typed = substring(name, "@types/".length);
|
|
499
|
+
runtimeName = ((typed.indexOf("__") >= 0) ? ("@" + replace_1(typed, "__", "/")) : typed);
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
runtimeName = name;
|
|
503
|
+
}
|
|
504
|
+
const candidates = [];
|
|
505
|
+
let typesField;
|
|
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);
|
|
509
|
+
if ((typeof typesField) === "string") {
|
|
510
|
+
void (candidates.push([".", typesField]));
|
|
511
|
+
}
|
|
512
|
+
const mainField = pkg["main"];
|
|
513
|
+
if ((typeof mainField) === "string") {
|
|
514
|
+
void (candidates.push([".", replace(mainField, "\\.[cm]?js$", ".d.ts")]));
|
|
515
|
+
}
|
|
516
|
+
void (candidates.push([".", "index.d.ts"]));
|
|
517
|
+
const entries = [];
|
|
518
|
+
let enumerator = getEnumerator(candidates);
|
|
519
|
+
try {
|
|
520
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
521
|
+
const forLoopVar = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
522
|
+
const subpath = forLoopVar[0];
|
|
523
|
+
const candidateFile = forLoopVar[1];
|
|
524
|
+
const mappedFile = Resolve_applyTypesVersions(pkg["typesVersions"], candidateFile);
|
|
525
|
+
let file = host.path.resolve([packageDir, mappedFile]);
|
|
526
|
+
if (!isMatch(declarationFile, file) && host.fs.fileExists(file + ".d.ts")) {
|
|
527
|
+
file = (file + ".d.ts");
|
|
528
|
+
}
|
|
529
|
+
if (host.fs.fileExists(file) && isMatch(declarationFile, file)) {
|
|
530
|
+
if (!exists_1((entry) => {
|
|
531
|
+
if (entry.subpath === subpath) {
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
return entry.file === file;
|
|
536
|
+
}
|
|
537
|
+
}, entries)) {
|
|
538
|
+
void (entries.push({
|
|
539
|
+
file: file,
|
|
540
|
+
isMapped: mappedFile !== candidateFile,
|
|
541
|
+
subpath: subpath,
|
|
542
|
+
}));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
finally {
|
|
548
|
+
disposeSafe(enumerator);
|
|
549
|
+
}
|
|
550
|
+
const matchValue = tryFind_1((entry_1) => (entry_1.subpath === "."), entries);
|
|
551
|
+
if (matchValue != null) {
|
|
552
|
+
const main = matchValue;
|
|
553
|
+
return new (class {
|
|
554
|
+
get name() {
|
|
555
|
+
return name;
|
|
556
|
+
}
|
|
557
|
+
get runtimeName() {
|
|
558
|
+
return runtimeName;
|
|
559
|
+
}
|
|
560
|
+
get hasRuntime() {
|
|
561
|
+
return name.startsWith("@types/") ? true : Resolve_hasRuntime(host, packageDir, pkg);
|
|
562
|
+
}
|
|
563
|
+
get dir() {
|
|
564
|
+
return packageDir;
|
|
565
|
+
}
|
|
566
|
+
get typesRoot() {
|
|
567
|
+
return main.isMapped ? host.path.dirname(main.file) : packageDir;
|
|
568
|
+
}
|
|
569
|
+
get entryFile() {
|
|
570
|
+
return main.file;
|
|
571
|
+
}
|
|
572
|
+
get hasExportsMap() {
|
|
573
|
+
let x_2;
|
|
574
|
+
return !((x_2 = (pkg["exports"]), x_2 === null || x_2 === undefined));
|
|
575
|
+
}
|
|
576
|
+
get subpathEntries() {
|
|
577
|
+
return toArray(map((entry_3) => (new (class {
|
|
578
|
+
get subpath() {
|
|
579
|
+
return replace(entry_3.subpath, "^\\./", "");
|
|
580
|
+
}
|
|
581
|
+
get file() {
|
|
582
|
+
return entry_3.file;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
)()), filter((entry_2) => (entry_2.subpath !== "."), entries)));
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
)();
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function Resolve_resolvedFile(file) {
|
|
597
|
+
return {
|
|
598
|
+
kind: "file",
|
|
599
|
+
file: file,
|
|
600
|
+
packageDir: "",
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function Resolve_resolvedPackage(packageDir) {
|
|
605
|
+
return {
|
|
606
|
+
kind: "package",
|
|
607
|
+
file: "",
|
|
608
|
+
packageDir: packageDir,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export function Resolve_resolveInput(host, input) {
|
|
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
|
+
};
|
|
617
|
+
if (isMatch(declarationFile, input) && host.fs.fileExists(asPath)) {
|
|
618
|
+
return Resolve_resolvedFile(asPath);
|
|
619
|
+
}
|
|
620
|
+
else if (host.fs.directoryExists(asPath)) {
|
|
621
|
+
return Resolve_resolvedPackage(host.fs.realPath(asPath));
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
const matchValue = Resolve_findNodeModules(host, host.cwd);
|
|
625
|
+
if (matchValue != null) {
|
|
626
|
+
const nodeModules = matchValue;
|
|
627
|
+
const segments = split_1(input, ["/"], undefined, 0);
|
|
628
|
+
const packageName = input.startsWith("@") ? join("/", segments.slice(0, 1 + 1)) : item(0, segments);
|
|
629
|
+
const typesPackage = host.path.join(["@types", Dynamic_replaceFirst(replace(packageName, "^@", ""), "/", "__")]);
|
|
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);
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
return undefined;
|
|
638
|
+
}
|
|
639
|
+
}, installed);
|
|
640
|
+
if (resolved == null) {
|
|
641
|
+
if (isEmpty(installed)) {
|
|
642
|
+
return notFound();
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
throw new Exception(`'${head(installed)[0]}' ships no type declaration, install '${typesPackage}' and generate that instead.`);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
return resolved;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
return notFound();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export function Resolve_listInstalledPackages(host) {
|
|
659
|
+
let source_1, objectArg;
|
|
660
|
+
const matchValue = Resolve_findNodeModules(host, host.cwd);
|
|
661
|
+
if (matchValue != null) {
|
|
662
|
+
const nodeModules = matchValue;
|
|
663
|
+
const result = [];
|
|
664
|
+
const arr = host.fs.readDirectory(nodeModules);
|
|
665
|
+
for (let idx = 0; idx <= (arr.length - 1); idx++) {
|
|
666
|
+
const entry = item(idx, arr);
|
|
667
|
+
if (!entry.startsWith(".")) {
|
|
668
|
+
const entryPath = host.path.join([nodeModules, entry]);
|
|
669
|
+
if (entry.startsWith("@")) {
|
|
670
|
+
const arr_1 = host.fs.readDirectory(entryPath);
|
|
671
|
+
for (let idx_1 = 0; idx_1 <= (arr_1.length - 1); idx_1++) {
|
|
672
|
+
const scoped = item(idx_1, arr_1);
|
|
673
|
+
void (result.push(host.path.join([entryPath, scoped])));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
void (result.push(entryPath));
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return toArray(filter((dir_1) => (Resolve_describePackage(host, dir_1) != null), (source_1 = filter((dir) => host.fs.fileExists(host.path.join([dir, "package.json"])), result), map((objectArg = host.fs, (path) => objectArg.realPath(path)), source_1))));
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
return [];
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* `@types/foo` for `foo`, `@types/scope__foo` for `@scope/foo`
|
|
690
|
+
*/
|
|
691
|
+
export function Npm_typesPackageName(name) {
|
|
692
|
+
return "@types/" + Dynamic_replaceFirst(replace(name, "^@", ""), "/", "__");
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* `chalk`, `chalk@5`, `@scope/name@^1.2`
|
|
697
|
+
*/
|
|
698
|
+
export function Npm_parsePackageSpec(spec) {
|
|
699
|
+
const at = spec.indexOf("@", 1) | 0;
|
|
700
|
+
if (at === -1) {
|
|
701
|
+
return {
|
|
702
|
+
name: spec,
|
|
703
|
+
range: "latest",
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
const range = substring(spec, at + 1);
|
|
708
|
+
return {
|
|
709
|
+
name: substring(spec, 0, at),
|
|
710
|
+
range: (range === "") ? "latest" : range,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Download the declaration files of a package and of the packages it depends on into
|
|
717
|
+
* `/node_modules` of the file system, like `npm install` would, from jsDelivr
|
|
718
|
+
*/
|
|
719
|
+
export function Npm_installPackage(fileSystem, spec, options) {
|
|
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")));
|
|
725
|
+
const installed = new Map([]);
|
|
726
|
+
const ignoreP = (p) => PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => (p.then((_arg) => (Promise.resolve(undefined))))));
|
|
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;
|
|
735
|
+
return (resolveResponse.status === 404) ? (Promise.resolve((() => {
|
|
736
|
+
throw new Exception(concat("No package named \'", name, "\' on npm"));
|
|
737
|
+
})())) : (!resolveResponse.ok ? (Promise.resolve((() => {
|
|
738
|
+
throw new Exception(`${resolveResponse.url}: ${resolveResponse.status}`);
|
|
739
|
+
})())) : (resolveResponse.json().then((_arg_5) => {
|
|
740
|
+
let x;
|
|
741
|
+
const resolved = _arg_5;
|
|
742
|
+
if ((x = (resolved["version"]), x === null || x === undefined)) {
|
|
743
|
+
return Promise.resolve((() => {
|
|
744
|
+
throw new Exception(`No version of '${name}' matches '${range}'`);
|
|
745
|
+
})());
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
const version = resolved["version"];
|
|
749
|
+
installed.set(name, {
|
|
750
|
+
name: name,
|
|
751
|
+
version: version,
|
|
752
|
+
});
|
|
753
|
+
onProgress(concat(name, "@", version, ": listing files"));
|
|
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) => {
|
|
755
|
+
let array_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) => {
|
|
758
|
+
if (isMatch(declarationFile, file_1)) {
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
return file_1.endsWith("/package.json");
|
|
763
|
+
}
|
|
764
|
+
})));
|
|
765
|
+
let doneCount = 0;
|
|
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, () => {
|
|
767
|
+
const file_2 = item(0, wanted);
|
|
768
|
+
wanted.splice(0, 1);
|
|
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);
|
|
771
|
+
doneCount = ((doneCount + 1) | 0);
|
|
772
|
+
onProgress(`${name}@${version}: ${doneCount} files`);
|
|
773
|
+
return Promise.resolve();
|
|
774
|
+
});
|
|
775
|
+
}))))), rangeDouble(1, 1, 8)))))).then((_arg_8) => {
|
|
776
|
+
const packageJson = JSON.parse(fileSystem.readFileSync(concat("/node_modules/", name, "/package.json"), "utf8"));
|
|
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, () => {
|
|
778
|
+
const hasDeclarations = files.some((file_4) => isMatch(declarationFile, file_4["name"]));
|
|
779
|
+
return ((!hasDeclarations && !name.startsWith("@types/")) ? (PromiseBuilder__Delay_62FBFDE1(promise, () => (ignoreP(install(Npm_typesPackageName(name), "latest")).then(() => (Promise.resolve(undefined))))).catch((_arg_10) => {
|
|
780
|
+
return Promise.resolve();
|
|
781
|
+
})) : (Promise.resolve())).then(() => PromiseBuilder__Delay_62FBFDE1(promise, () => {
|
|
782
|
+
let dependencies;
|
|
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)))));
|
|
786
|
+
}));
|
|
787
|
+
}));
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
})));
|
|
792
|
+
})))));
|
|
793
|
+
return PromiseBuilder__Run_212F1D4B(promise, PromiseBuilder__Delay_62FBFDE1(promise, () => {
|
|
794
|
+
const parsed = Npm_parsePackageSpec(spec);
|
|
795
|
+
return install(parsed.name, parsed.range).then((_arg_13) => (Promise.resolve(toNullable(_arg_13))));
|
|
796
|
+
}));
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
export function Bootstrap_createProgramForCLI(_fileName, source) {
|
|
800
|
+
const compilerOptions = {};
|
|
801
|
+
compilerOptions.strict = true;
|
|
802
|
+
const project = createProjectSync({
|
|
803
|
+
compilerOptions: compilerOptions,
|
|
804
|
+
});
|
|
805
|
+
project.createSourceFile(_fileName, source);
|
|
806
|
+
return project.createProgram();
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Create a program from declaration files of the host, following their imports
|
|
811
|
+
*/
|
|
812
|
+
export function Bootstrap_createProgramFromFiles(host, entryFiles, globalTypes, withoutDomLib, noLib) {
|
|
813
|
+
const compilerOptions = {};
|
|
814
|
+
compilerOptions.target = 99;
|
|
815
|
+
compilerOptions.module = 99;
|
|
816
|
+
compilerOptions.moduleResolution = 100;
|
|
817
|
+
compilerOptions.types = Array.from(globalTypes);
|
|
818
|
+
compilerOptions.strict = true;
|
|
819
|
+
if (withoutDomLib) {
|
|
820
|
+
compilerOptions.lib = ["lib.esnext.d.ts", "lib.decorators.d.ts", "lib.decorators.legacy.d.ts"];
|
|
821
|
+
}
|
|
822
|
+
if (noLib) {
|
|
823
|
+
compilerOptions.noLib = true;
|
|
824
|
+
}
|
|
825
|
+
const project = host.createProject(compilerOptions);
|
|
826
|
+
for (let idx = 0; idx <= (entryFiles.length - 1); idx++) {
|
|
827
|
+
const entryFile = item(idx, entryFiles);
|
|
828
|
+
project.addSourceFileAtPathSync(entryFile);
|
|
829
|
+
}
|
|
830
|
+
project.resolveSourceFileDependencies();
|
|
831
|
+
return project.createProgram();
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* The files reachable from the entry files through imports and references, without going
|
|
836
|
+
* through a package of `excludedRuntimeNames` (`node` for `@types/node`)
|
|
837
|
+
*/
|
|
838
|
+
export function Bootstrap_reachableFiles(host, program, entryFiles, excludedRuntimeNames) {
|
|
839
|
+
const runtimeNames = new Map([]);
|
|
840
|
+
const seen = new Set([]);
|
|
841
|
+
const queue = Array.from(entryFiles);
|
|
842
|
+
const visit = (fileName_1) => {
|
|
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, {
|
|
847
|
+
Equals: (x, y) => (x === y),
|
|
848
|
+
GetHashCode: (x) => (stringHash(x) | 0),
|
|
849
|
+
}))))))) {
|
|
850
|
+
void (queue.push(fileName_1));
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
while (queue.length > 0) {
|
|
854
|
+
let option_3;
|
|
855
|
+
const fileName_2 = item(queue.length - 1, queue);
|
|
856
|
+
queue.splice(queue.length - 1, 1);
|
|
857
|
+
if (!seen.has(fileName_2)) {
|
|
858
|
+
const matchValue_2 = program.getSourceFile(fileName_2);
|
|
859
|
+
if (matchValue_2 != null) {
|
|
860
|
+
const sourceFile = matchValue_2;
|
|
861
|
+
addToSet(fileName_2, seen);
|
|
862
|
+
const imports = defaultArg((option_3 = Dynamic_tryProp(sourceFile, "imports"), (option_3 != null) ? value_7(option_3) : undefined), []);
|
|
863
|
+
for (let idx = 0; idx <= (imports.length - 1); idx++) {
|
|
864
|
+
const usage = item(idx, imports);
|
|
865
|
+
visit(program.getResolvedModuleFromModuleSpecifier(usage, sourceFile)?.resolvedModule?.resolvedFileName);
|
|
866
|
+
}
|
|
867
|
+
const enumerator = getEnumerator(sourceFile.referencedFiles);
|
|
868
|
+
try {
|
|
869
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
870
|
+
const reference = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
871
|
+
visit(host.path.resolve([host.path.dirname(sourceFile.fileName), reference.fileName]));
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
finally {
|
|
875
|
+
disposeSafe(enumerator);
|
|
876
|
+
}
|
|
877
|
+
const enumerator_1 = getEnumerator(sourceFile.typeReferenceDirectives);
|
|
878
|
+
try {
|
|
879
|
+
while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
880
|
+
const reference_1 = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
881
|
+
visit(program.getResolvedTypeReferenceDirective(sourceFile, reference_1.fileName, reference_1.resolutionMode)?.resolvedTypeReferenceDirective?.resolvedFileName);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
finally {
|
|
885
|
+
disposeSafe(enumerator_1);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return toArray(seen);
|
|
891
|
+
}
|
|
892
|
+
|