durable-actors 0.7.15 → 0.8.0

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 (66) hide show
  1. package/README.md +5 -5
  2. package/bin/durable-actors.js +2 -0
  3. package/dist/actor/actor.d.ts +2 -2
  4. package/dist/actor/actor.d.ts.map +1 -1
  5. package/dist/actor/actor.js +5 -3
  6. package/dist/actor/actor.js.map +1 -1
  7. package/dist/actor/database.d.ts +3 -2
  8. package/dist/actor/database.d.ts.map +1 -1
  9. package/dist/actor/database.js +21 -3
  10. package/dist/actor/database.js.map +1 -1
  11. package/dist/cli/dev.d.ts.map +1 -1
  12. package/dist/cli/dev.js +13 -42
  13. package/dist/cli/dev.js.map +1 -1
  14. package/dist/cli/python.d.ts.map +1 -1
  15. package/dist/cli/python.js +0 -1
  16. package/dist/cli/python.js.map +1 -1
  17. package/dist/cli.d.ts +1 -1
  18. package/dist/cli.js +9 -18
  19. package/dist/cli.js.map +1 -1
  20. package/dist/client-runtime/proxy.d.ts +1 -3
  21. package/dist/client-runtime/proxy.d.ts.map +1 -1
  22. package/dist/client-runtime/proxy.js +3 -10
  23. package/dist/client-runtime/proxy.js.map +1 -1
  24. package/dist/compiler/declarations.js +2648 -183
  25. package/dist/compiler/declarations.js.map +7 -1
  26. package/dist/compiler/generators/client-artifacts.d.ts.map +1 -1
  27. package/dist/compiler/generators/client-artifacts.js +0 -1
  28. package/dist/compiler/generators/client-artifacts.js.map +1 -1
  29. package/dist/generated/client-runtime.d.ts.map +1 -1
  30. package/dist/generated/client-runtime.js +1 -1
  31. package/dist/generated/client-runtime.js.map +1 -1
  32. package/dist/host/actor-runtime.d.ts.map +1 -1
  33. package/dist/host/actor-runtime.js +2 -3
  34. package/dist/host/actor-runtime.js.map +1 -1
  35. package/dist/host/sqlite.d.ts.map +1 -1
  36. package/dist/host/sqlite.js +2 -0
  37. package/dist/host/sqlite.js.map +1 -1
  38. package/dist/projectSdk.js +1 -1
  39. package/dist/projectSdk.js.map +1 -1
  40. package/dist/templates/actor/README.md +7 -9
  41. package/dist/templates/actor/bunfig +2 -0
  42. package/dist/templates/actor/package.json +6 -3
  43. package/dist/templates/ai-chat/README.md +8 -8
  44. package/dist/templates/ai-chat/bunfig +2 -0
  45. package/dist/templates/ai-chat/package.json +7 -5
  46. package/dist/templates/chat/README.md +8 -8
  47. package/dist/templates/chat/bunfig +2 -0
  48. package/dist/templates/chat/package.json +7 -5
  49. package/dist/templates/documents/README.md +8 -8
  50. package/dist/templates/documents/bunfig +2 -0
  51. package/dist/templates/documents/package.json +7 -5
  52. package/package.json +110 -108
  53. package/dist/cli/actor-source-watcher.d.ts +0 -25
  54. package/dist/cli/actor-source-watcher.d.ts.map +0 -1
  55. package/dist/cli/actor-source-watcher.js +0 -129
  56. package/dist/cli/actor-source-watcher.js.map +0 -1
  57. package/dist/templates/actor/pnpm-workspace.yaml +0 -2
  58. package/dist/templates/ai-chat/pnpm-workspace.yaml +0 -2
  59. package/dist/templates/chat/pnpm-workspace.yaml +0 -2
  60. package/dist/templates/documents/pnpm-workspace.yaml +0 -2
  61. package/dist/templates/python/README.md +0 -7
  62. package/dist/templates/python/gitignore +0 -6
  63. package/dist/templates/python/package.json +0 -11
  64. package/dist/templates/python/pnpm-workspace.yaml +0 -2
  65. package/dist/templates/python/pyproject.toml +0 -8
  66. package/dist/templates/python/src/actors.py +0 -9
@@ -1,218 +1,2683 @@
1
- import { generateDtsBundle } from "dts-bundle-generator";
1
+ /*! dts-bundle-generator
2
+ MIT License
3
+
4
+ Copyright (c) 2017 Evgeniy Timokhov
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ */
24
+ import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
25
+ var __create = Object.create;
26
+ var __defProp = Object.defineProperty;
27
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
28
+ var __getOwnPropNames = Object.getOwnPropertyNames;
29
+ var __getProtoOf = Object.getPrototypeOf;
30
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
31
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
32
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
33
+ }) : x)(function(x) {
34
+ if (typeof require !== "undefined") return require.apply(this, arguments);
35
+ throw Error('Dynamic require of "' + x + '" is not supported');
36
+ });
37
+ var __commonJS = (cb, mod) => function __require2() {
38
+ try {
39
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
40
+ } catch (e) {
41
+ throw mod = 0, e;
42
+ }
43
+ };
44
+ var __copyProps = (to, from, except, desc) => {
45
+ if (from && typeof from === "object" || typeof from === "function") {
46
+ for (let key of __getOwnPropNames(from))
47
+ if (!__hasOwnProp.call(to, key) && key !== except)
48
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
49
+ }
50
+ return to;
51
+ };
52
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
53
+ // If the importer is in node compatibility mode or this is not an ESM
54
+ // file that has been converted to a CommonJS file using a Babel-
55
+ // compatible transform (i.e. "__esModule" has not been set), then set
56
+ // "default" to the CommonJS "module.exports" for node compatibility.
57
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
58
+ mod
59
+ ));
60
+
61
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/logger.js
62
+ var require_logger = __commonJS({
63
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/logger.js"(exports) {
64
+ "use strict";
65
+ Object.defineProperty(exports, "__esModule", { value: true });
66
+ exports.enableNormalLog = exports.enableVerbose = exports.errorLog = exports.warnLog = exports.normalLog = exports.verboseLog = void 0;
67
+ function verboseLog(message) {
68
+ logMessage(
69
+ message,
70
+ 0
71
+ /* LogLevel.Verbose */
72
+ );
73
+ }
74
+ exports.verboseLog = verboseLog;
75
+ function normalLog(message) {
76
+ logMessage(
77
+ message,
78
+ 1
79
+ /* LogLevel.Normal */
80
+ );
81
+ }
82
+ exports.normalLog = normalLog;
83
+ function warnLog(message) {
84
+ logMessage(
85
+ message,
86
+ 2
87
+ /* LogLevel.Warning */
88
+ );
89
+ }
90
+ exports.warnLog = warnLog;
91
+ function errorLog(message) {
92
+ logMessage(
93
+ message,
94
+ 3
95
+ /* LogLevel.Error */
96
+ );
97
+ }
98
+ exports.errorLog = errorLog;
99
+ var currentLogLevel = 3;
100
+ function enableVerbose() {
101
+ currentLogLevel = 0;
102
+ normalLog("Verbose log enabled");
103
+ }
104
+ exports.enableVerbose = enableVerbose;
105
+ function enableNormalLog() {
106
+ currentLogLevel = 1;
107
+ }
108
+ exports.enableNormalLog = enableNormalLog;
109
+ function logMessage(message, level = 0) {
110
+ if (level < currentLogLevel) {
111
+ return;
112
+ }
113
+ switch (level) {
114
+ case 3:
115
+ console.error(`\x1B[0;31m${message}\x1B[0m`);
116
+ break;
117
+ case 2:
118
+ console.warn(`\x1B[1;33m${message}\x1B[0m`);
119
+ break;
120
+ case 1:
121
+ case 0:
122
+ console.log(message);
123
+ }
124
+ }
125
+ }
126
+ });
127
+
128
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/fix-path.js
129
+ var require_fix_path = __commonJS({
130
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/fix-path.js"(exports) {
131
+ "use strict";
132
+ Object.defineProperty(exports, "__esModule", { value: true });
133
+ exports.fixPath = void 0;
134
+ function fixPath(path2) {
135
+ return path2.replace(/\\/g, "/");
136
+ }
137
+ exports.fixPath = fixPath;
138
+ }
139
+ });
140
+
141
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/get-absolute-path.js
142
+ var require_get_absolute_path = __commonJS({
143
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/get-absolute-path.js"(exports) {
144
+ "use strict";
145
+ Object.defineProperty(exports, "__esModule", { value: true });
146
+ exports.getAbsolutePath = void 0;
147
+ var path2 = __require("path");
148
+ var process = __require("process");
149
+ var fix_path_1 = require_fix_path();
150
+ function getAbsolutePath(fileName, cwd) {
151
+ if (!path2.isAbsolute(fileName)) {
152
+ fileName = path2.join(cwd !== void 0 ? cwd : process.cwd(), fileName);
153
+ }
154
+ return (0, fix_path_1.fixPath)(fileName);
155
+ }
156
+ exports.getAbsolutePath = getAbsolutePath;
157
+ }
158
+ });
159
+
160
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/check-diagnostics-errors.js
161
+ var require_check_diagnostics_errors = __commonJS({
162
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/check-diagnostics-errors.js"(exports) {
163
+ "use strict";
164
+ Object.defineProperty(exports, "__esModule", { value: true });
165
+ exports.checkDiagnosticsErrors = exports.checkProgramDiagnosticsErrors = void 0;
166
+ var ts2 = __require("typescript");
167
+ var logger_1 = require_logger();
168
+ var formatDiagnosticsHost = {
169
+ getCanonicalFileName: (fileName) => ts2.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
170
+ getCurrentDirectory: ts2.sys.getCurrentDirectory,
171
+ getNewLine: () => ts2.sys.newLine
172
+ };
173
+ function checkProgramDiagnosticsErrors(program) {
174
+ if (!program.getCompilerOptions().declaration) {
175
+ throw new Error(`Something went wrong - the program doesn't have declaration option enabled`);
176
+ }
177
+ checkDiagnosticsErrors(ts2.getPreEmitDiagnostics(program), "Compiled with errors");
178
+ }
179
+ exports.checkProgramDiagnosticsErrors = checkProgramDiagnosticsErrors;
180
+ function checkDiagnosticsErrors(diagnostics, failMessage) {
181
+ if (diagnostics.length === 0) {
182
+ return;
183
+ }
184
+ (0, logger_1.errorLog)(ts2.formatDiagnostics(diagnostics, formatDiagnosticsHost).trim());
185
+ throw new Error(failMessage);
186
+ }
187
+ exports.checkDiagnosticsErrors = checkDiagnosticsErrors;
188
+ }
189
+ });
190
+
191
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/get-compiler-options.js
192
+ var require_get_compiler_options = __commonJS({
193
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/get-compiler-options.js"(exports) {
194
+ "use strict";
195
+ Object.defineProperty(exports, "__esModule", { value: true });
196
+ exports.getCompilerOptions = void 0;
197
+ var ts2 = __require("typescript");
198
+ var path2 = __require("path");
199
+ var get_absolute_path_1 = require_get_absolute_path();
200
+ var check_diagnostics_errors_1 = require_check_diagnostics_errors();
201
+ var logger_1 = require_logger();
202
+ var parseConfigHost = {
203
+ useCaseSensitiveFileNames: ts2.sys.useCaseSensitiveFileNames,
204
+ readDirectory: ts2.sys.readDirectory,
205
+ fileExists: ts2.sys.fileExists,
206
+ readFile: ts2.sys.readFile
207
+ };
208
+ function getCompilerOptions(inputFileNames, preferredConfigPath) {
209
+ const configFileName = preferredConfigPath !== void 0 ? preferredConfigPath : findConfig(inputFileNames);
210
+ (0, logger_1.verboseLog)(`Using config: ${configFileName}`);
211
+ const configParseResult = ts2.readConfigFile(configFileName, ts2.sys.readFile);
212
+ (0, check_diagnostics_errors_1.checkDiagnosticsErrors)(configParseResult.error !== void 0 ? [configParseResult.error] : [], "Error while processing tsconfig file");
213
+ const compilerOptionsParseResult = ts2.parseJsonConfigFileContent(configParseResult.config, parseConfigHost, path2.resolve(path2.dirname(configFileName)), void 0, (0, get_absolute_path_1.getAbsolutePath)(configFileName));
214
+ const diagnostics = compilerOptionsParseResult.errors.filter(
215
+ (d) => d.code !== 18003
216
+ /* Constants.NoInputsWereFoundDiagnosticCode */
217
+ );
218
+ (0, check_diagnostics_errors_1.checkDiagnosticsErrors)(diagnostics, "Error while processing tsconfig compiler options");
219
+ return compilerOptionsParseResult.options;
220
+ }
221
+ exports.getCompilerOptions = getCompilerOptions;
222
+ function findConfig(inputFiles) {
223
+ if (inputFiles.length !== 1) {
224
+ throw new Error("Cannot find tsconfig for multiple files. Please specify preferred tsconfig file");
225
+ }
226
+ const searchPath = (0, get_absolute_path_1.getAbsolutePath)(inputFiles[0]);
227
+ const configFileName = ts2.findConfigFile(searchPath, ts2.sys.fileExists);
228
+ if (!configFileName) {
229
+ throw new Error(`Cannot find config file for file ${searchPath}`);
230
+ }
231
+ return configFileName;
232
+ }
233
+ }
234
+ });
235
+
236
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/compile-dts.js
237
+ var require_compile_dts = __commonJS({
238
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/compile-dts.js"(exports) {
239
+ "use strict";
240
+ Object.defineProperty(exports, "__esModule", { value: true });
241
+ exports.compileDts = void 0;
242
+ var ts2 = __require("typescript");
243
+ var logger_1 = require_logger();
244
+ var get_compiler_options_1 = require_get_compiler_options();
245
+ var check_diagnostics_errors_1 = require_check_diagnostics_errors();
246
+ var declarationExtsRemapping = {
247
+ [ts2.Extension.Js]: ts2.Extension.Js,
248
+ [ts2.Extension.Jsx]: ts2.Extension.Jsx,
249
+ [ts2.Extension.Json]: ts2.Extension.Json,
250
+ [ts2.Extension.TsBuildInfo]: ts2.Extension.TsBuildInfo,
251
+ [ts2.Extension.Mjs]: ts2.Extension.Mjs,
252
+ [ts2.Extension.Cjs]: ts2.Extension.Cjs,
253
+ [ts2.Extension.Ts]: ts2.Extension.Dts,
254
+ [ts2.Extension.Tsx]: ts2.Extension.Dts,
255
+ [ts2.Extension.Dts]: ts2.Extension.Dts,
256
+ [ts2.Extension.Mts]: ts2.Extension.Dmts,
257
+ [ts2.Extension.Dmts]: ts2.Extension.Dmts,
258
+ [ts2.Extension.Cts]: ts2.Extension.Dcts,
259
+ [ts2.Extension.Dcts]: ts2.Extension.Dcts
260
+ };
261
+ function compileDts(rootFiles, preferredConfigPath, followSymlinks = true) {
262
+ const compilerOptions = (0, get_compiler_options_1.getCompilerOptions)(rootFiles, preferredConfigPath);
263
+ compilerOptions.outDir = void 0;
264
+ compilerOptions.incremental = void 0;
265
+ compilerOptions.tsBuildInfoFile = void 0;
266
+ compilerOptions.declarationDir = void 0;
267
+ compilerOptions.declaration = true;
268
+ if (compilerOptions.composite) {
269
+ (0, logger_1.warnLog)(`Composite projects aren't supported at the time. Prefer to use non-composite project to generate declarations instead or just ignore this message if everything works fine. See https://github.com/timocov/dts-bundle-generator/issues/93`);
270
+ compilerOptions.composite = void 0;
271
+ }
272
+ const host = createCachingCompilerHost(compilerOptions);
273
+ const dtsFiles = getDeclarationFiles(rootFiles, compilerOptions, host);
274
+ if (!followSymlinks) {
275
+ host.realpath = (p) => p;
276
+ }
277
+ const moduleResolutionCache = ts2.createModuleResolutionCache(host.getCurrentDirectory(), host.getCanonicalFileName, compilerOptions);
278
+ host.resolveModuleNameLiterals = (moduleLiterals, containingFile) => {
279
+ return moduleLiterals.map((moduleLiteral) => {
280
+ const resolvedModule = ts2.resolveModuleName(moduleLiteral.text, containingFile, compilerOptions, host, moduleResolutionCache).resolvedModule;
281
+ if (resolvedModule && !resolvedModule.isExternalLibraryImport) {
282
+ const newExt = declarationExtsRemapping[resolvedModule.extension];
283
+ if (newExt === void 0) {
284
+ (0, logger_1.verboseLog)(`Skipping module ${resolvedModule.resolvedFileName} because it has unsupported extension "${resolvedModule.extension}"`);
285
+ return { resolvedModule };
286
+ }
287
+ if (newExt !== resolvedModule.extension) {
288
+ (0, logger_1.verboseLog)(`Changing module from ${resolvedModule.extension} to ${newExt} for ${resolvedModule.resolvedFileName}`);
289
+ resolvedModule.extension = newExt;
290
+ resolvedModule.resolvedFileName = changeExtensionToDts(resolvedModule.resolvedFileName);
291
+ }
292
+ }
293
+ return { resolvedModule };
294
+ });
295
+ };
296
+ const originalGetSourceFile = host.getSourceFile;
297
+ host.getSourceFile = (fileName, languageVersion, onError) => {
298
+ const storedValue = dtsFiles.get(host.getCanonicalFileName(fileName));
299
+ if (storedValue !== void 0) {
300
+ return ts2.createSourceFile(fileName, storedValue, languageVersion);
301
+ }
302
+ return originalGetSourceFile(fileName, languageVersion, onError);
303
+ };
304
+ const rootFilesRemapping = /* @__PURE__ */ new Map();
305
+ const inputFiles = rootFiles.map((rootFile) => {
306
+ const rootDtsFile = changeExtensionToDts(rootFile);
307
+ rootFilesRemapping.set(rootFile, rootDtsFile);
308
+ return rootDtsFile;
309
+ });
310
+ const program = ts2.createProgram(inputFiles, compilerOptions, host);
311
+ (0, check_diagnostics_errors_1.checkProgramDiagnosticsErrors)(program);
312
+ warnAboutTypeScriptFilesInProgram(program);
313
+ return { program, rootFilesRemapping };
314
+ }
315
+ exports.compileDts = compileDts;
316
+ function createCachingCompilerHost(compilerOptions) {
317
+ const host = ts2.createIncrementalCompilerHost(compilerOptions);
318
+ const sourceFilesCache = /* @__PURE__ */ new Map();
319
+ const originalGetSourceFile = host.getSourceFile;
320
+ host.getSourceFile = (fileName, languageVersion, onError) => {
321
+ const key = host.getCanonicalFileName(fileName);
322
+ let cacheValue = sourceFilesCache.get(key);
323
+ if (cacheValue === void 0) {
324
+ cacheValue = originalGetSourceFile(fileName, languageVersion, onError);
325
+ sourceFilesCache.set(key, cacheValue);
326
+ }
327
+ return cacheValue;
328
+ };
329
+ return host;
330
+ }
331
+ function changeExtensionToDts(fileName) {
332
+ let ext;
333
+ if (fileName.endsWith(ts2.Extension.Dts)) {
334
+ return fileName;
335
+ }
336
+ if (fileName.endsWith(ts2.Extension.Cts)) {
337
+ ext = ts2.Extension.Cts;
338
+ } else if (fileName.endsWith(ts2.Extension.Mts)) {
339
+ ext = ts2.Extension.Mts;
340
+ } else if (fileName.endsWith(ts2.Extension.Ts)) {
341
+ ext = ts2.Extension.Ts;
342
+ } else if (fileName.endsWith(ts2.Extension.Tsx)) {
343
+ ext = ts2.Extension.Tsx;
344
+ }
345
+ if (ext === void 0) {
346
+ return fileName;
347
+ }
348
+ return fileName.slice(0, -ext.length) + declarationExtsRemapping[ext];
349
+ }
350
+ function getDeclarationFiles(rootFiles, compilerOptions, host) {
351
+ compilerOptions = {
352
+ ...compilerOptions,
353
+ noEmit: false,
354
+ declaration: true,
355
+ emitDeclarationOnly: true
356
+ };
357
+ const program = ts2.createProgram(rootFiles, compilerOptions, host);
358
+ const allFilesAreDeclarations = program.getSourceFiles().every((s) => s.isDeclarationFile);
359
+ const declarations = /* @__PURE__ */ new Map();
360
+ if (allFilesAreDeclarations) {
361
+ (0, logger_1.verboseLog)("Skipping compiling the project to generate d.ts because all files in it are d.ts already");
362
+ return declarations;
363
+ }
364
+ (0, check_diagnostics_errors_1.checkProgramDiagnosticsErrors)(program);
365
+ const emitResult = program.emit(void 0, (fileName, data) => declarations.set(host.getCanonicalFileName(fileName), data), void 0, true);
366
+ (0, check_diagnostics_errors_1.checkDiagnosticsErrors)(emitResult.diagnostics, "Errors while emitting declarations");
367
+ return declarations;
368
+ }
369
+ function warnAboutTypeScriptFilesInProgram(program) {
370
+ const nonDeclarationFiles = program.getSourceFiles().filter((file) => !file.isDeclarationFile);
371
+ if (nonDeclarationFiles.length !== 0) {
372
+ (0, logger_1.warnLog)(`WARNING: It seems that some files in the compilation still are not declaration files.
373
+ For more information see https://github.com/timocov/dts-bundle-generator/issues/53.
374
+ If you think this is a mistake, feel free to open new issue or just ignore this warning.
375
+ ${nonDeclarationFiles.map((file) => file.fileName).join("\n ")}
376
+ `);
377
+ }
378
+ }
379
+ }
380
+ });
381
+
382
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/typescript.js
383
+ var require_typescript = __commonJS({
384
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/typescript.js"(exports) {
385
+ "use strict";
386
+ Object.defineProperty(exports, "__esModule", { value: true });
387
+ exports.resolveGlobalName = exports.getDeclarationsForExportedValues = exports.getSymbolExportStarDeclarations = exports.getImportExportReferencedSymbol = exports.getImportModuleName = exports.resolveReferencedModule = exports.getClosestSourceFileLikeNode = exports.getClosestModuleLikeNode = exports.getNodeSymbol = exports.getNodeOwnSymbol = exports.getRootSourceFile = exports.getModifiers = exports.recreateRootLevelNodeWithModifiers = exports.modifiersMapToArray = exports.modifiersToMap = exports.getExportsForStatement = exports.resolveIdentifier = exports.getExportsForSourceFile = exports.getDeclarationsForSymbol = exports.isDeclareGlobalStatement = exports.isDeclareModule = exports.isAmbientModule = exports.splitTransientSymbol = exports.getDeclarationNameSymbol = exports.getActualSymbol = exports.getNodeName = exports.hasNodeModifier = exports.isNodeNamedDeclaration = void 0;
388
+ var ts2 = __require("typescript");
389
+ var logger_1 = require_logger();
390
+ var namedDeclarationKinds = [
391
+ ts2.SyntaxKind.InterfaceDeclaration,
392
+ ts2.SyntaxKind.ClassDeclaration,
393
+ ts2.SyntaxKind.EnumDeclaration,
394
+ ts2.SyntaxKind.TypeAliasDeclaration,
395
+ ts2.SyntaxKind.ModuleDeclaration,
396
+ ts2.SyntaxKind.FunctionDeclaration,
397
+ ts2.SyntaxKind.VariableDeclaration,
398
+ ts2.SyntaxKind.PropertySignature,
399
+ ts2.SyntaxKind.NamespaceExport,
400
+ ts2.SyntaxKind.NamespaceImport,
401
+ ts2.SyntaxKind.ExportSpecifier,
402
+ ts2.SyntaxKind.BindingElement
403
+ ];
404
+ function isNodeNamedDeclaration(node) {
405
+ return namedDeclarationKinds.indexOf(node.kind) !== -1;
406
+ }
407
+ exports.isNodeNamedDeclaration = isNodeNamedDeclaration;
408
+ function hasNodeModifier(node, modifier) {
409
+ const modifiers = getModifiers(node);
410
+ return Boolean(modifiers && modifiers.some((nodeModifier) => nodeModifier.kind === modifier));
411
+ }
412
+ exports.hasNodeModifier = hasNodeModifier;
413
+ function getNodeName(node) {
414
+ const nodeName = node.name;
415
+ if (nodeName === void 0) {
416
+ const modifiers = getModifiers(node);
417
+ const defaultModifier = modifiers?.find((mod) => mod.kind === ts2.SyntaxKind.DefaultKeyword);
418
+ if (defaultModifier !== void 0) {
419
+ return defaultModifier;
420
+ }
421
+ }
422
+ return nodeName;
423
+ }
424
+ exports.getNodeName = getNodeName;
425
+ function getActualSymbol(symbol, typeChecker) {
426
+ if (symbol.flags & ts2.SymbolFlags.Alias) {
427
+ symbol = typeChecker.getAliasedSymbol(symbol);
428
+ }
429
+ return typeChecker.getMergedSymbol(symbol);
430
+ }
431
+ exports.getActualSymbol = getActualSymbol;
432
+ function getDeclarationNameSymbol(name, typeChecker) {
433
+ const symbol = typeChecker.getSymbolAtLocation(name);
434
+ if (symbol === void 0) {
435
+ return null;
436
+ }
437
+ return getActualSymbol(symbol, typeChecker);
438
+ }
439
+ exports.getDeclarationNameSymbol = getDeclarationNameSymbol;
440
+ function splitTransientSymbol(symbol, typeChecker) {
441
+ if ((symbol.flags & ts2.SymbolFlags.Transient) === 0) {
442
+ return /* @__PURE__ */ new Set([symbol]);
443
+ }
444
+ const declarations = getDeclarationsForSymbol(symbol);
445
+ const result = /* @__PURE__ */ new Set();
446
+ for (const declaration of declarations) {
447
+ if (!isNodeNamedDeclaration(declaration) || declaration.name === void 0) {
448
+ continue;
449
+ }
450
+ const sym = typeChecker.getSymbolAtLocation(declaration.name);
451
+ if (sym === void 0) {
452
+ continue;
453
+ }
454
+ result.add(getActualSymbol(sym, typeChecker));
455
+ }
456
+ return result;
457
+ }
458
+ exports.splitTransientSymbol = splitTransientSymbol;
459
+ function isGlobalScopeAugmentation(module2) {
460
+ return Boolean(module2.flags & ts2.NodeFlags.GlobalAugmentation);
461
+ }
462
+ function isAmbientModule(node) {
463
+ return ts2.isModuleDeclaration(node) && (node.name.kind === ts2.SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node));
464
+ }
465
+ exports.isAmbientModule = isAmbientModule;
466
+ function isDeclareModule(node) {
467
+ return ts2.isModuleDeclaration(node) && !(node.flags & ts2.NodeFlags.Namespace) && !isGlobalScopeAugmentation(node);
468
+ }
469
+ exports.isDeclareModule = isDeclareModule;
470
+ function isDeclareGlobalStatement(statement) {
471
+ return ts2.isModuleDeclaration(statement) && isGlobalScopeAugmentation(statement);
472
+ }
473
+ exports.isDeclareGlobalStatement = isDeclareGlobalStatement;
474
+ function getDeclarationsForSymbol(symbol) {
475
+ const result = [];
476
+ if (symbol.declarations !== void 0) {
477
+ result.push(...symbol.declarations);
478
+ }
479
+ if (symbol.valueDeclaration !== void 0) {
480
+ if (!result.includes(symbol.valueDeclaration)) {
481
+ result.push(symbol.valueDeclaration);
482
+ }
483
+ }
484
+ return result;
485
+ }
486
+ exports.getDeclarationsForSymbol = getDeclarationsForSymbol;
487
+ function getExportsForSourceFile(typeChecker, sourceFileSymbol) {
488
+ if (sourceFileSymbol.exports !== void 0) {
489
+ const commonJsExport = sourceFileSymbol.exports.get(ts2.InternalSymbolName.ExportEquals);
490
+ if (commonJsExport !== void 0) {
491
+ const symbol = getActualSymbol(commonJsExport, typeChecker);
492
+ return [
493
+ {
494
+ symbol,
495
+ originalSymbol: commonJsExport,
496
+ type: 0,
497
+ exportedName: ""
498
+ }
499
+ ];
500
+ }
501
+ }
502
+ const result = typeChecker.getExportsOfModule(sourceFileSymbol).map((symbol) => ({
503
+ symbol,
504
+ originalSymbol: symbol,
505
+ exportedName: symbol.name,
506
+ type: 1
507
+ /* ExportType.ES6Named */
508
+ }));
509
+ if (sourceFileSymbol.exports !== void 0) {
510
+ const defaultExportSymbol = sourceFileSymbol.exports.get(ts2.InternalSymbolName.Default);
511
+ if (defaultExportSymbol !== void 0) {
512
+ const defaultExport = result.find((exp) => exp.symbol === defaultExportSymbol);
513
+ if (defaultExport !== void 0) {
514
+ defaultExport.type = 2;
515
+ } else {
516
+ result.push({
517
+ symbol: defaultExportSymbol,
518
+ originalSymbol: defaultExportSymbol,
519
+ type: 2,
520
+ exportedName: "default"
521
+ });
522
+ }
523
+ }
524
+ }
525
+ const symbolsMergingResolvedExports = [];
526
+ result.forEach((exp) => {
527
+ exp.symbol = getActualSymbol(exp.symbol, typeChecker);
528
+ const symbolsDeclarations = getDeclarationsForSymbol(exp.symbol);
529
+ const importSpecifierDeclaration = symbolsDeclarations.find(ts2.isImportSpecifier);
530
+ if (symbolsDeclarations.length > 1 && importSpecifierDeclaration !== void 0) {
531
+ const referencedModule = resolveReferencedModule(importSpecifierDeclaration.parent.parent.parent, typeChecker);
532
+ if (referencedModule !== null) {
533
+ const referencedModuleSymbol = getNodeSymbol(referencedModule, typeChecker);
534
+ if (referencedModuleSymbol !== null) {
535
+ const importedName = (importSpecifierDeclaration.propertyName ?? importSpecifierDeclaration.name).getText();
536
+ const exportedItemSymbol = typeChecker.getExportsOfModule(referencedModuleSymbol).find((exportSymbol) => exportSymbol.getName() === importedName);
537
+ if (exportedItemSymbol !== void 0) {
538
+ symbolsMergingResolvedExports.push({
539
+ ...exp,
540
+ symbol: getActualSymbol(exportedItemSymbol, typeChecker)
541
+ });
542
+ }
543
+ }
544
+ }
545
+ }
546
+ });
547
+ return [...result, ...symbolsMergingResolvedExports];
548
+ }
549
+ exports.getExportsForSourceFile = getExportsForSourceFile;
550
+ function resolveIdentifier(typeChecker, identifier) {
551
+ const symbol = getDeclarationNameSymbol(identifier, typeChecker);
552
+ if (symbol === null) {
553
+ return void 0;
554
+ }
555
+ return resolveDeclarationByIdentifierSymbol(symbol);
556
+ }
557
+ exports.resolveIdentifier = resolveIdentifier;
558
+ function resolveDeclarationByIdentifierSymbol(identifierSymbol) {
559
+ const declarations = getDeclarationsForSymbol(identifierSymbol);
560
+ if (declarations.length === 0) {
561
+ return void 0;
562
+ }
563
+ const decl = declarations[0];
564
+ if (!isNodeNamedDeclaration(decl)) {
565
+ return void 0;
566
+ }
567
+ return decl;
568
+ }
569
+ function getExportsForStatement(exportedSymbols, typeChecker, statement) {
570
+ if (ts2.isVariableStatement(statement)) {
571
+ if (statement.declarationList.declarations.length === 0) {
572
+ return [];
573
+ }
574
+ const firstDeclarationExports = getExportsForName(exportedSymbols, typeChecker, statement.declarationList.declarations[0].name);
575
+ const allDeclarationsHaveSameExportType = statement.declarationList.declarations.every((variableDecl) => {
576
+ return getExportsForName(exportedSymbols, typeChecker, variableDecl.name)[0]?.type === firstDeclarationExports[0]?.type;
577
+ });
578
+ if (!allDeclarationsHaveSameExportType) {
579
+ return [];
580
+ }
581
+ return firstDeclarationExports;
582
+ }
583
+ const nodeName = getNodeName(statement);
584
+ if (nodeName === void 0) {
585
+ return [];
586
+ }
587
+ return getExportsForName(exportedSymbols, typeChecker, nodeName);
588
+ }
589
+ exports.getExportsForStatement = getExportsForStatement;
590
+ function getExportsForName(exportedSymbols, typeChecker, name) {
591
+ if (ts2.isArrayBindingPattern(name) || ts2.isObjectBindingPattern(name)) {
592
+ return [];
593
+ }
594
+ const declarationSymbol = typeChecker.getSymbolAtLocation(name);
595
+ return exportedSymbols.filter((rootExport) => rootExport.symbol === declarationSymbol);
596
+ }
597
+ var modifiersPriority = {
598
+ [ts2.SyntaxKind.ExportKeyword]: 4,
599
+ [ts2.SyntaxKind.DefaultKeyword]: 3,
600
+ [ts2.SyntaxKind.DeclareKeyword]: 2,
601
+ [ts2.SyntaxKind.AsyncKeyword]: 1,
602
+ [ts2.SyntaxKind.ConstKeyword]: 1
603
+ };
604
+ function modifiersToMap(modifiers) {
605
+ modifiers = modifiers || [];
606
+ return modifiers.reduce(
607
+ (result, modifier) => {
608
+ result[modifier.kind] = true;
609
+ return result;
610
+ },
611
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
612
+ {}
613
+ );
614
+ }
615
+ exports.modifiersToMap = modifiersToMap;
616
+ function modifiersMapToArray(modifiersMap) {
617
+ return Object.entries(modifiersMap).filter(([kind, include]) => include).map(([kind]) => {
618
+ return ts2.factory.createModifier(Number(kind));
619
+ }).sort((a, b) => {
620
+ const aValue = modifiersPriority[a.kind] || 0;
621
+ const bValue = modifiersPriority[b.kind] || 0;
622
+ return bValue - aValue;
623
+ });
624
+ }
625
+ exports.modifiersMapToArray = modifiersMapToArray;
626
+ function recreateRootLevelNodeWithModifiers(node, modifiersMap, newName, keepComments = true) {
627
+ const newNode = recreateRootLevelNodeWithModifiersImpl(node, modifiersMap, newName);
628
+ if (keepComments) {
629
+ ts2.setCommentRange(newNode, ts2.getCommentRange(node));
630
+ }
631
+ return newNode;
632
+ }
633
+ exports.recreateRootLevelNodeWithModifiers = recreateRootLevelNodeWithModifiers;
634
+ function recreateRootLevelNodeWithModifiersImpl(node, modifiersMap, newName) {
635
+ const modifiers = modifiersMapToArray(modifiersMap);
636
+ if (ts2.isArrowFunction(node)) {
637
+ return ts2.factory.createArrowFunction(modifiers, node.typeParameters, node.parameters, node.type, node.equalsGreaterThanToken, node.body);
638
+ }
639
+ if (ts2.isClassDeclaration(node)) {
640
+ return ts2.factory.createClassDeclaration(modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members);
641
+ }
642
+ if (ts2.isClassExpression(node)) {
643
+ return ts2.factory.createClassExpression(modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members);
644
+ }
645
+ if (ts2.isEnumDeclaration(node)) {
646
+ return ts2.factory.createEnumDeclaration(modifiers, newName || node.name, node.members);
647
+ }
648
+ if (ts2.isExportAssignment(node)) {
649
+ return ts2.factory.createExportAssignment(modifiers, node.isExportEquals, node.expression);
650
+ }
651
+ if (ts2.isExportDeclaration(node)) {
652
+ return ts2.factory.createExportDeclaration(
653
+ modifiers,
654
+ node.isTypeOnly,
655
+ node.exportClause,
656
+ node.moduleSpecifier,
657
+ // eslint-disable-next-line deprecation/deprecation
658
+ node.attributes || node.assertClause
659
+ );
660
+ }
661
+ if (ts2.isFunctionDeclaration(node)) {
662
+ return ts2.factory.createFunctionDeclaration(modifiers, node.asteriskToken, newName || node.name, node.typeParameters, node.parameters, node.type, node.body);
663
+ }
664
+ if (ts2.isFunctionExpression(node)) {
665
+ return ts2.factory.createFunctionExpression(modifiers, node.asteriskToken, newName || node.name, node.typeParameters, node.parameters, node.type, node.body);
666
+ }
667
+ if (ts2.isImportDeclaration(node)) {
668
+ return ts2.factory.createImportDeclaration(
669
+ modifiers,
670
+ node.importClause,
671
+ node.moduleSpecifier,
672
+ // eslint-disable-next-line deprecation/deprecation
673
+ node.attributes || node.assertClause
674
+ );
675
+ }
676
+ if (ts2.isImportEqualsDeclaration(node)) {
677
+ return ts2.factory.createImportEqualsDeclaration(modifiers, node.isTypeOnly, newName || node.name, node.moduleReference);
678
+ }
679
+ if (ts2.isInterfaceDeclaration(node)) {
680
+ return ts2.factory.createInterfaceDeclaration(modifiers, newName || node.name, node.typeParameters, node.heritageClauses, node.members);
681
+ }
682
+ if (ts2.isModuleDeclaration(node)) {
683
+ return ts2.factory.createModuleDeclaration(modifiers, node.name, node.body, node.flags);
684
+ }
685
+ if (ts2.isTypeAliasDeclaration(node)) {
686
+ return ts2.factory.createTypeAliasDeclaration(modifiers, newName || node.name, node.typeParameters, node.type);
687
+ }
688
+ if (ts2.isVariableStatement(node)) {
689
+ return ts2.factory.createVariableStatement(modifiers, node.declarationList);
690
+ }
691
+ throw new Error(`Unknown top-level node kind (with modifiers): ${ts2.SyntaxKind[node.kind]}.
692
+ If you're seeing this error, please report a bug on https://github.com/timocov/dts-bundle-generator/issues`);
693
+ }
694
+ function getModifiers(node) {
695
+ if (!ts2.canHaveModifiers(node)) {
696
+ return void 0;
697
+ }
698
+ return ts2.getModifiers(node);
699
+ }
700
+ exports.getModifiers = getModifiers;
701
+ function getRootSourceFile(program, rootFileName) {
702
+ if (program.getRootFileNames().indexOf(rootFileName) === -1) {
703
+ throw new Error(`There is no such root file ${rootFileName}`);
704
+ }
705
+ const sourceFile = program.getSourceFile(rootFileName);
706
+ if (sourceFile === void 0) {
707
+ throw new Error(`Cannot get source file for root file ${rootFileName}`);
708
+ }
709
+ return sourceFile;
710
+ }
711
+ exports.getRootSourceFile = getRootSourceFile;
712
+ function getNodeOwnSymbol(node, typeChecker) {
713
+ const nodeSymbol = typeChecker.getSymbolAtLocation(node);
714
+ if (nodeSymbol === void 0) {
715
+ throw new Error(`Cannot find symbol for node "${node.getText()}" in "${node.parent.getText()}" from "${node.getSourceFile().fileName}"`);
716
+ }
717
+ return nodeSymbol;
718
+ }
719
+ exports.getNodeOwnSymbol = getNodeOwnSymbol;
720
+ function getNodeSymbol(node, typeChecker) {
721
+ if (ts2.isSourceFile(node)) {
722
+ const fileSymbol = typeChecker.getSymbolAtLocation(node);
723
+ if (fileSymbol === void 0) {
724
+ return null;
725
+ }
726
+ return getActualSymbol(fileSymbol, typeChecker);
727
+ }
728
+ const nodeName = getNodeName(node);
729
+ if (nodeName === void 0) {
730
+ return null;
731
+ }
732
+ return getDeclarationNameSymbol(nodeName, typeChecker);
733
+ }
734
+ exports.getNodeSymbol = getNodeSymbol;
735
+ function getClosestModuleLikeNode(node) {
736
+ while (!ts2.isModuleBlock(node) && !ts2.isSourceFile(node)) {
737
+ node = node.parent;
738
+ }
739
+ return ts2.isSourceFile(node) ? node : node.parent;
740
+ }
741
+ exports.getClosestModuleLikeNode = getClosestModuleLikeNode;
742
+ function getClosestSourceFileLikeNode(node) {
743
+ while (!(ts2.isModuleBlock(node) && ts2.isStringLiteral(node.parent.name)) && !ts2.isSourceFile(node)) {
744
+ node = node.parent;
745
+ }
746
+ return ts2.isSourceFile(node) ? node : node.parent;
747
+ }
748
+ exports.getClosestSourceFileLikeNode = getClosestSourceFileLikeNode;
749
+ function resolveReferencedModule(node, typeChecker) {
750
+ let moduleName;
751
+ if (ts2.isExportDeclaration(node) || ts2.isImportDeclaration(node)) {
752
+ moduleName = node.moduleSpecifier;
753
+ } else if (ts2.isModuleDeclaration(node)) {
754
+ moduleName = node.name;
755
+ } else if (ts2.isImportEqualsDeclaration(node)) {
756
+ if (ts2.isExternalModuleReference(node.moduleReference)) {
757
+ moduleName = node.moduleReference.expression;
758
+ }
759
+ } else if (ts2.isLiteralTypeNode(node.argument) && ts2.isStringLiteral(node.argument.literal)) {
760
+ moduleName = node.argument.literal;
761
+ }
762
+ if (moduleName === void 0) {
763
+ return null;
764
+ }
765
+ const moduleSymbol = typeChecker.getSymbolAtLocation(moduleName);
766
+ if (moduleSymbol === void 0) {
767
+ return null;
768
+ }
769
+ const symbol = getActualSymbol(moduleSymbol, typeChecker);
770
+ if (symbol.valueDeclaration === void 0) {
771
+ return null;
772
+ }
773
+ return ts2.isSourceFile(symbol.valueDeclaration) || ts2.isModuleDeclaration(symbol.valueDeclaration) ? symbol.valueDeclaration : null;
774
+ }
775
+ exports.resolveReferencedModule = resolveReferencedModule;
776
+ function getImportModuleName(imp) {
777
+ if (ts2.isImportDeclaration(imp)) {
778
+ return imp.importClause === void 0 ? null : imp.moduleSpecifier.text;
779
+ }
780
+ if (ts2.isExportDeclaration(imp)) {
781
+ return imp.moduleSpecifier === void 0 ? null : imp.moduleSpecifier.text;
782
+ }
783
+ if (ts2.isExternalModuleReference(imp.moduleReference)) {
784
+ if (!ts2.isStringLiteral(imp.moduleReference.expression)) {
785
+ (0, logger_1.warnLog)(`Cannot handle non string-literal-like import expression: ${imp.moduleReference.expression.getText()}`);
786
+ return null;
787
+ }
788
+ return imp.moduleReference.expression.text;
789
+ }
790
+ return null;
791
+ }
792
+ exports.getImportModuleName = getImportModuleName;
793
+ function getImportExportReferencedSymbol(importExportSpecifier, typeChecker) {
794
+ return importExportSpecifier.propertyName !== void 0 ? typeChecker.getSymbolAtLocation(importExportSpecifier.propertyName) : typeChecker.getImmediateAliasedSymbol(typeChecker.getSymbolAtLocation(importExportSpecifier.name));
795
+ }
796
+ exports.getImportExportReferencedSymbol = getImportExportReferencedSymbol;
797
+ function getSymbolExportStarDeclarations(symbol) {
798
+ if (symbol.escapedName !== ts2.InternalSymbolName.ExportStar) {
799
+ throw new Error(`Only ExportStar symbol can have export star declaration, but got ${symbol.escapedName}`);
800
+ }
801
+ return getDeclarationsForSymbol(symbol).filter((decl) => ts2.isExportDeclaration(decl) && decl.moduleSpecifier !== void 0);
802
+ }
803
+ exports.getSymbolExportStarDeclarations = getSymbolExportStarDeclarations;
804
+ function getDeclarationsForExportedValues(exp, typeChecker) {
805
+ const nodeForSymbol = ts2.isExportAssignment(exp) ? exp.expression : exp.moduleSpecifier;
806
+ if (nodeForSymbol === void 0) {
807
+ return [];
808
+ }
809
+ const symbolForExpression = typeChecker.getSymbolAtLocation(nodeForSymbol);
810
+ if (symbolForExpression === void 0) {
811
+ return [];
812
+ }
813
+ const symbol = getActualSymbol(symbolForExpression, typeChecker);
814
+ return getDeclarationsForSymbol(symbol);
815
+ }
816
+ exports.getDeclarationsForExportedValues = getDeclarationsForExportedValues;
817
+ function resolveGlobalName(typeChecker, name) {
818
+ const tsSymbolFlagsAll = (
819
+ /* ts.SymbolFlags.All */
820
+ -1
821
+ );
822
+ return typeChecker.resolveName(name, void 0, tsSymbolFlagsAll, false);
823
+ }
824
+ exports.resolveGlobalName = resolveGlobalName;
825
+ }
826
+ });
827
+
828
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js
829
+ var require_types_usage_evaluator = __commonJS({
830
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/types-usage-evaluator.js"(exports) {
831
+ "use strict";
832
+ Object.defineProperty(exports, "__esModule", { value: true });
833
+ exports.TypesUsageEvaluator = void 0;
834
+ var ts2 = __require("typescript");
835
+ var typescript_1 = require_typescript();
836
+ var TypesUsageEvaluator = class {
837
+ constructor(files, typeChecker) {
838
+ this.nodesParentsMap = /* @__PURE__ */ new Map();
839
+ this.usageResultCache = /* @__PURE__ */ new Map();
840
+ this.typeChecker = typeChecker;
841
+ this.computeUsages(files);
842
+ }
843
+ isSymbolUsedBySymbol(symbol, by) {
844
+ return this.isSymbolUsedBySymbolImpl(this.getActualSymbol(symbol), this.getActualSymbol(by), /* @__PURE__ */ new Set());
845
+ }
846
+ getSymbolsUsingSymbol(symbol) {
847
+ return this.nodesParentsMap.get(this.getActualSymbol(symbol)) || null;
848
+ }
849
+ isSymbolUsedBySymbolImpl(fromSymbol, toSymbol, visitedSymbols) {
850
+ if (fromSymbol === toSymbol) {
851
+ return this.setUsageCacheValue(fromSymbol, toSymbol, true);
852
+ }
853
+ const cacheResult = this.usageResultCache.get(fromSymbol)?.get(toSymbol);
854
+ if (cacheResult !== void 0) {
855
+ return cacheResult;
856
+ }
857
+ const reachableNodes = this.nodesParentsMap.get(fromSymbol);
858
+ if (reachableNodes !== void 0) {
859
+ for (const symbol of reachableNodes) {
860
+ if (visitedSymbols.has(symbol)) {
861
+ continue;
862
+ }
863
+ visitedSymbols.add(symbol);
864
+ if (this.isSymbolUsedBySymbolImpl(symbol, toSymbol, visitedSymbols)) {
865
+ return this.setUsageCacheValue(fromSymbol, toSymbol, true);
866
+ }
867
+ }
868
+ }
869
+ visitedSymbols.add(fromSymbol);
870
+ return false;
871
+ }
872
+ setUsageCacheValue(fromSymbol, toSymbol, value) {
873
+ let fromSymbolCacheMap = this.usageResultCache.get(fromSymbol);
874
+ if (fromSymbolCacheMap === void 0) {
875
+ fromSymbolCacheMap = /* @__PURE__ */ new Map();
876
+ this.usageResultCache.set(fromSymbol, fromSymbolCacheMap);
877
+ }
878
+ fromSymbolCacheMap.set(toSymbol, value);
879
+ return value;
880
+ }
881
+ computeUsages(files) {
882
+ this.nodesParentsMap.clear();
883
+ for (const file of files) {
884
+ ts2.forEachChild(file, this.computeUsageForNode.bind(this));
885
+ }
886
+ }
887
+ // eslint-disable-next-line complexity
888
+ computeUsageForNode(node) {
889
+ if ((0, typescript_1.isDeclareModule)(node) && node.body !== void 0 && ts2.isModuleBlock(node.body)) {
890
+ const moduleSymbol = this.getSymbol(node.name);
891
+ for (const statement of node.body.statements) {
892
+ this.computeUsageForNode(statement);
893
+ if ((0, typescript_1.isNodeNamedDeclaration)(statement)) {
894
+ const nodeName = (0, typescript_1.getNodeName)(statement);
895
+ if (nodeName !== void 0) {
896
+ const statementSymbol = this.getSymbol(nodeName);
897
+ this.addUsages(statementSymbol, moduleSymbol);
898
+ }
899
+ }
900
+ }
901
+ }
902
+ if ((0, typescript_1.isNodeNamedDeclaration)(node)) {
903
+ const nodeName = (0, typescript_1.getNodeName)(node);
904
+ if (nodeName !== void 0) {
905
+ if (ts2.isObjectBindingPattern(nodeName) || ts2.isArrayBindingPattern(nodeName)) {
906
+ for (const element of nodeName.elements) {
907
+ this.computeUsageForNode(element);
908
+ }
909
+ } else {
910
+ const childSymbol = this.getSymbol(nodeName);
911
+ if (childSymbol !== null) {
912
+ this.computeUsagesRecursively(node, childSymbol);
913
+ }
914
+ }
915
+ }
916
+ }
917
+ if (ts2.isVariableStatement(node)) {
918
+ for (const varDeclaration of node.declarationList.declarations) {
919
+ this.computeUsageForNode(varDeclaration);
920
+ }
921
+ }
922
+ if (ts2.isExportDeclaration(node) && node.moduleSpecifier !== void 0 && node.exportClause !== void 0 && ts2.isNamespaceExport(node.exportClause)) {
923
+ this.addUsagesForNamespacedModule(node.exportClause, node.moduleSpecifier);
924
+ }
925
+ if (ts2.isImportDeclaration(node) && node.moduleSpecifier !== void 0 && node.importClause?.namedBindings !== void 0 && ts2.isNamespaceImport(node.importClause.namedBindings)) {
926
+ this.addUsagesForNamespacedModule(node.importClause.namedBindings, node.moduleSpecifier, false);
927
+ }
928
+ if (ts2.isExportDeclaration(node) && node.exportClause !== void 0 && ts2.isNamedExports(node.exportClause)) {
929
+ for (const exportElement of node.exportClause.elements) {
930
+ const exportElementSymbol = (0, typescript_1.getImportExportReferencedSymbol)(exportElement, this.typeChecker);
931
+ const namespaceImportForElement = (0, typescript_1.getDeclarationsForSymbol)(exportElementSymbol).find(ts2.isNamespaceImport);
932
+ if (namespaceImportForElement !== void 0) {
933
+ this.addUsagesForNamespacedModule(namespaceImportForElement, namespaceImportForElement.parent.parent.moduleSpecifier);
934
+ }
935
+ const exportElementOwnSymbol = this.getNodeOwnSymbol(exportElement.name);
936
+ this.addUsages(exportElementSymbol, exportElementOwnSymbol);
937
+ this.addUsages(this.getActualSymbol(exportElementSymbol), exportElementOwnSymbol);
938
+ }
939
+ }
940
+ if (ts2.isExportAssignment(node) && node.isExportEquals) {
941
+ this.addUsagesForExportAssignment(node);
942
+ }
943
+ }
944
+ addUsagesForExportAssignment(exportAssignment) {
945
+ for (const declaration of (0, typescript_1.getDeclarationsForExportedValues)(exportAssignment, this.typeChecker)) {
946
+ if (ts2.isModuleDeclaration(declaration) && ts2.isIdentifier(declaration.name) && declaration.body !== void 0 && ts2.isModuleBlock(declaration.body)) {
947
+ const moduleSymbol = this.getSymbol(declaration.name);
948
+ for (const statement of declaration.body.statements) {
949
+ if ((0, typescript_1.isNodeNamedDeclaration)(statement) && statement.name !== void 0) {
950
+ const statementSymbol = this.getSymbol(statement.name);
951
+ if (statementSymbol !== null) {
952
+ this.addUsages(moduleSymbol, statementSymbol);
953
+ }
954
+ }
955
+ }
956
+ }
957
+ }
958
+ }
959
+ addUsagesForNamespacedModule(namespaceNode, moduleSpecifier, includeExports = true) {
960
+ const namespaceSymbol = this.getNodeOwnSymbol(namespaceNode.name);
961
+ const referencedSourceFileSymbol = this.getSymbol(moduleSpecifier);
962
+ this.addUsages(referencedSourceFileSymbol, namespaceSymbol);
963
+ const resolvedNamespaceSymbol = this.getSymbol(namespaceNode.name);
964
+ this.addUsages(resolvedNamespaceSymbol, namespaceSymbol);
965
+ if (includeExports) {
966
+ this.addExportsToSymbol(referencedSourceFileSymbol.exports, referencedSourceFileSymbol);
967
+ }
968
+ }
969
+ addExportsToSymbol(exports2, parentSymbol, visitedSymbols = /* @__PURE__ */ new Set()) {
970
+ exports2?.forEach((moduleExportedSymbol, name) => {
971
+ if (name === ts2.InternalSymbolName.ExportStar) {
972
+ for (const exportStarDeclaration of (0, typescript_1.getSymbolExportStarDeclarations)(moduleExportedSymbol)) {
973
+ if (exportStarDeclaration.moduleSpecifier === void 0) {
974
+ throw new Error(`Export star declaration does not have a module specifier '${exportStarDeclaration.getText()}'`);
975
+ }
976
+ const referencedSourceFileSymbol = this.getSymbol(exportStarDeclaration.moduleSpecifier);
977
+ if (visitedSymbols.has(referencedSourceFileSymbol)) {
978
+ continue;
979
+ }
980
+ visitedSymbols.add(referencedSourceFileSymbol);
981
+ this.addExportsToSymbol(referencedSourceFileSymbol.exports, parentSymbol, visitedSymbols);
982
+ }
983
+ return;
984
+ }
985
+ this.addUsages(moduleExportedSymbol, parentSymbol);
986
+ });
987
+ }
988
+ computeUsagesRecursively(parent, parentSymbol) {
989
+ ts2.forEachChild(parent, (child) => {
990
+ if (child.kind === ts2.SyntaxKind.JSDoc) {
991
+ return;
992
+ }
993
+ this.computeUsagesRecursively(child, parentSymbol);
994
+ if (ts2.isIdentifier(child) || child.kind === ts2.SyntaxKind.DefaultKeyword) {
995
+ if (ts2.isNamedTupleMember(child.parent) && child.parent.name === child) {
996
+ return;
997
+ }
998
+ if (ts2.isBindingElement(child.parent) && child.parent.propertyName === child) {
999
+ return;
1000
+ }
1001
+ this.addUsages(this.getSymbol(child), parentSymbol);
1002
+ if (!ts2.isQualifiedName(child.parent)) {
1003
+ const childOwnSymbol = this.getNodeOwnSymbol(child);
1004
+ const namespaceImport = (0, typescript_1.getDeclarationsForSymbol)(childOwnSymbol).find(ts2.isNamespaceImport);
1005
+ if (namespaceImport !== void 0) {
1006
+ this.addUsagesForNamespacedModule(namespaceImport, namespaceImport.parent.parent.moduleSpecifier, true);
1007
+ }
1008
+ }
1009
+ }
1010
+ });
1011
+ }
1012
+ addUsages(childSymbol, parentSymbol) {
1013
+ const childSymbols = (0, typescript_1.splitTransientSymbol)(childSymbol, this.typeChecker);
1014
+ for (const childSplitSymbol of childSymbols) {
1015
+ let symbols = this.nodesParentsMap.get(childSplitSymbol);
1016
+ if (symbols === void 0) {
1017
+ symbols = /* @__PURE__ */ new Set();
1018
+ this.nodesParentsMap.set(childSplitSymbol, symbols);
1019
+ }
1020
+ if (childSplitSymbol !== parentSymbol) {
1021
+ symbols.add(parentSymbol);
1022
+ }
1023
+ }
1024
+ }
1025
+ getSymbol(node) {
1026
+ return this.getActualSymbol(this.getNodeOwnSymbol(node));
1027
+ }
1028
+ getNodeOwnSymbol(node) {
1029
+ return (0, typescript_1.getNodeOwnSymbol)(node, this.typeChecker);
1030
+ }
1031
+ getActualSymbol(symbol) {
1032
+ return (0, typescript_1.getActualSymbol)(symbol, this.typeChecker);
1033
+ }
1034
+ };
1035
+ exports.TypesUsageEvaluator = TypesUsageEvaluator;
1036
+ }
1037
+ });
1038
+
1039
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/node-modules.js
1040
+ var require_node_modules = __commonJS({
1041
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/node-modules.js"(exports) {
1042
+ "use strict";
1043
+ Object.defineProperty(exports, "__esModule", { value: true });
1044
+ exports.getTypesLibraryName = exports.getLibraryName = void 0;
1045
+ var nodeModulesFolderName = "node_modules/";
1046
+ var libraryNameRegex = /node_modules\/((?:(?=@)[^/]+\/[^/]+|[^/]+))\//;
1047
+ function getLibraryName(fileName) {
1048
+ const lastNodeModulesIndex = fileName.lastIndexOf(nodeModulesFolderName);
1049
+ if (lastNodeModulesIndex === -1) {
1050
+ return null;
1051
+ }
1052
+ const match = libraryNameRegex.exec(fileName.slice(lastNodeModulesIndex));
1053
+ if (match === null) {
1054
+ return null;
1055
+ }
1056
+ return match[1];
1057
+ }
1058
+ exports.getLibraryName = getLibraryName;
1059
+ function getTypesLibraryName(path2) {
1060
+ const libraryName = getLibraryName(path2);
1061
+ if (libraryName === null) {
1062
+ return null;
1063
+ }
1064
+ const typesFolderPrefix = "@types/";
1065
+ if (!libraryName.startsWith(typesFolderPrefix)) {
1066
+ return null;
1067
+ }
1068
+ return libraryName.substring(typesFolderPrefix.length);
1069
+ }
1070
+ exports.getTypesLibraryName = getTypesLibraryName;
1071
+ }
1072
+ });
1073
+
1074
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/module-info.js
1075
+ var require_module_info = __commonJS({
1076
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/module-info.js"(exports) {
1077
+ "use strict";
1078
+ Object.defineProperty(exports, "__esModule", { value: true });
1079
+ exports.getModuleLikeModuleInfo = exports.getReferencedModuleInfo = exports.getFileModuleInfo = void 0;
1080
+ var path2 = __require("path");
1081
+ var ts2 = __require("typescript");
1082
+ var node_modules_1 = require_node_modules();
1083
+ var fix_path_1 = require_fix_path();
1084
+ var typescript_1 = require_typescript();
1085
+ function getFileModuleInfo(fileName, criteria) {
1086
+ return getModuleInfoImpl(fileName, fileName, criteria);
1087
+ }
1088
+ exports.getFileModuleInfo = getFileModuleInfo;
1089
+ function getReferencedModuleInfo(moduleDecl, criteria, typeChecker) {
1090
+ const referencedModule = (0, typescript_1.resolveReferencedModule)(moduleDecl, typeChecker);
1091
+ if (referencedModule === null) {
1092
+ return null;
1093
+ }
1094
+ const moduleFilePath = ts2.isSourceFile(referencedModule) ? referencedModule.fileName : resolveModuleFileName(referencedModule.getSourceFile().fileName, referencedModule.name.text);
1095
+ return getFileModuleInfo(moduleFilePath, criteria);
1096
+ }
1097
+ exports.getReferencedModuleInfo = getReferencedModuleInfo;
1098
+ function getModuleLikeModuleInfo(moduleLike, criteria, typeChecker) {
1099
+ const resolvedModuleLike = ts2.isSourceFile(moduleLike) ? moduleLike : (0, typescript_1.resolveReferencedModule)(moduleLike, typeChecker) ?? moduleLike;
1100
+ const fileName = ts2.isSourceFile(resolvedModuleLike) ? resolvedModuleLike.fileName : resolveModuleFileName(resolvedModuleLike.getSourceFile().fileName, resolvedModuleLike.name.text);
1101
+ return getFileModuleInfo(fileName, criteria);
1102
+ }
1103
+ exports.getModuleLikeModuleInfo = getModuleLikeModuleInfo;
1104
+ function resolveModuleFileName(currentFileName, moduleName) {
1105
+ return moduleName.startsWith(".") ? (0, fix_path_1.fixPath)(path2.join(currentFileName, "..", moduleName)) : `node_modules/${moduleName}/`;
1106
+ }
1107
+ function getModuleInfoImpl(currentFilePath, originalFileName, criteria) {
1108
+ const npmLibraryName = (0, node_modules_1.getLibraryName)(currentFilePath);
1109
+ if (npmLibraryName === null) {
1110
+ if (criteria.typeRoots !== void 0) {
1111
+ for (const root of criteria.typeRoots) {
1112
+ const relativePath = (0, fix_path_1.fixPath)(path2.relative(root, originalFileName));
1113
+ if (!relativePath.startsWith("../")) {
1114
+ return getModuleInfoImpl(remapToTypesFromNodeModules(relativePath), originalFileName, criteria);
1115
+ }
1116
+ }
1117
+ }
1118
+ return { type: 0, fileName: originalFileName, isExternal: false };
1119
+ }
1120
+ const typesLibraryName = (0, node_modules_1.getTypesLibraryName)(currentFilePath);
1121
+ if (shouldLibraryBeInlined(npmLibraryName, typesLibraryName, criteria.inlinedLibraries)) {
1122
+ return { type: 0, fileName: originalFileName, isExternal: true };
1123
+ }
1124
+ if (shouldLibraryBeImported(npmLibraryName, typesLibraryName, criteria.importedLibraries, criteria.allowedTypesLibraries)) {
1125
+ return { type: 1, fileName: originalFileName, isExternal: true };
1126
+ }
1127
+ if (typesLibraryName !== null && isLibraryAllowed(typesLibraryName, criteria.allowedTypesLibraries)) {
1128
+ return { type: 2, fileName: originalFileName, typesLibraryName, isExternal: true };
1129
+ }
1130
+ return { type: 3, fileName: originalFileName, isExternal: true };
1131
+ }
1132
+ function shouldLibraryBeInlined(npmLibraryName, typesLibraryName, inlinedLibraries) {
1133
+ return isLibraryAllowed(npmLibraryName, inlinedLibraries) || typesLibraryName !== null && isLibraryAllowed(typesLibraryName, inlinedLibraries);
1134
+ }
1135
+ function shouldLibraryBeImported(npmLibraryName, typesLibraryName, importedLibraries, allowedTypesLibraries) {
1136
+ if (typesLibraryName === null) {
1137
+ return isLibraryAllowed(npmLibraryName, importedLibraries);
1138
+ }
1139
+ if (allowedTypesLibraries === void 0 || !isLibraryAllowed(typesLibraryName, allowedTypesLibraries)) {
1140
+ return isLibraryAllowed(typesLibraryName, importedLibraries);
1141
+ }
1142
+ return false;
1143
+ }
1144
+ function isLibraryAllowed(libraryName, allowedArray) {
1145
+ return allowedArray === void 0 || allowedArray.indexOf(libraryName) !== -1;
1146
+ }
1147
+ function remapToTypesFromNodeModules(pathRelativeToTypesRoot) {
1148
+ return `node_modules/@types/${pathRelativeToTypesRoot}`;
1149
+ }
1150
+ }
1151
+ });
1152
+
1153
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/package-version.js
1154
+ var require_package_version = __commonJS({
1155
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/helpers/package-version.js"(exports) {
1156
+ "use strict";
1157
+ Object.defineProperty(exports, "__esModule", { value: true });
1158
+ exports.packageVersion = void 0;
1159
+ var fs = __require("fs");
1160
+ var path2 = __require("path");
1161
+ function packageVersion() {
1162
+ let dirName = __dirname;
1163
+ while (dirName.length !== 0) {
1164
+ const packageJsonFilePath = path2.join(dirName, "package.json");
1165
+ if (fs.existsSync(packageJsonFilePath)) {
1166
+ return __require(packageJsonFilePath).version;
1167
+ }
1168
+ dirName = path2.join(dirName, "..");
1169
+ }
1170
+ throw new Error(`Cannot find up package.json in ${__dirname}`);
1171
+ }
1172
+ exports.packageVersion = packageVersion;
1173
+ }
1174
+ });
1175
+
1176
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/generate-output.js
1177
+ var require_generate_output = __commonJS({
1178
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/generate-output.js"(exports) {
1179
+ "use strict";
1180
+ Object.defineProperty(exports, "__esModule", { value: true });
1181
+ exports.generateOutput = void 0;
1182
+ var ts2 = __require("typescript");
1183
+ var package_version_1 = require_package_version();
1184
+ var typescript_1 = require_typescript();
1185
+ function generateOutput(params, options = {}) {
1186
+ const resultOutputParts = [];
1187
+ if (!options.noBanner) {
1188
+ resultOutputParts.push(`// Generated by dts-bundle-generator v${(0, package_version_1.packageVersion)()}`);
1189
+ }
1190
+ if (params.typesReferences.size !== 0) {
1191
+ const header = generateReferenceTypesDirective(Array.from(params.typesReferences));
1192
+ resultOutputParts.push(header);
1193
+ }
1194
+ if (params.imports.size !== 0) {
1195
+ const sortedEntries = Array.from(params.imports.entries()).sort((firstEntry, secondEntry) => {
1196
+ return firstEntry[0].localeCompare(secondEntry[0]);
1197
+ });
1198
+ const importsArray = [];
1199
+ for (const [libraryName, libraryImports] of sortedEntries) {
1200
+ importsArray.push(...generateImports(libraryName, libraryImports));
1201
+ }
1202
+ if (importsArray.length !== 0) {
1203
+ resultOutputParts.push(importsArray.join("\n"));
1204
+ }
1205
+ }
1206
+ const statements = params.statements.map((statement) => getStatementText(statement, Boolean(options.sortStatements), params));
1207
+ if (options.sortStatements) {
1208
+ statements.sort(compareStatementText);
1209
+ }
1210
+ if (statements.length !== 0) {
1211
+ resultOutputParts.push(statementsTextToString(statements));
1212
+ }
1213
+ if (params.wrappedNamespaces.size !== 0) {
1214
+ resultOutputParts.push(Array.from(params.wrappedNamespaces.entries()).map(([namespaceName, exportedNames]) => {
1215
+ return `declare namespace ${namespaceName} {
1216
+ export { ${Array.from(exportedNames.entries()).map(([exportedName, localName]) => renamedExportValue(exportedName, localName)).sort().join(", ")} };
1217
+ }`;
1218
+ }).join("\n"));
1219
+ }
1220
+ if (params.renamedExports.size !== 0) {
1221
+ resultOutputParts.push(`export {
1222
+ ${Array.from(params.renamedExports.entries()).map(([exportedName, localName]) => renamedExportValue(exportedName, localName)).sort().join(",\n ")},
1223
+ };`);
1224
+ }
1225
+ if (options.umdModuleName !== void 0) {
1226
+ resultOutputParts.push(`export as namespace ${options.umdModuleName};`);
1227
+ }
1228
+ resultOutputParts.push(`export {};
1229
+ `);
1230
+ return resultOutputParts.join("\n\n");
1231
+ }
1232
+ exports.generateOutput = generateOutput;
1233
+ function statementsTextToString(statements) {
1234
+ const statementsText = statements.map((statement) => statement.text).join("\n");
1235
+ return spacesToTabs(prettifyStatementsText(statementsText));
1236
+ }
1237
+ function renamedExportValue(exportedName, localName) {
1238
+ return exportedName !== localName ? `${localName} as ${exportedName}` : exportedName;
1239
+ }
1240
+ function renamedImportValue(importedName, localName) {
1241
+ return importedName !== localName ? `${importedName} as ${localName}` : importedName;
1242
+ }
1243
+ function prettifyStatementsText(statementsText) {
1244
+ const sourceFile = ts2.createSourceFile("output.d.ts", statementsText, ts2.ScriptTarget.Latest, false, ts2.ScriptKind.TS);
1245
+ const printer = ts2.createPrinter({
1246
+ newLine: ts2.NewLineKind.LineFeed,
1247
+ removeComments: false
1248
+ });
1249
+ return printer.printFile(sourceFile).trim();
1250
+ }
1251
+ function compareStatementText(a, b) {
1252
+ if (a.sortingValue > b.sortingValue) {
1253
+ return 1;
1254
+ } else if (a.sortingValue < b.sortingValue) {
1255
+ return -1;
1256
+ }
1257
+ return 0;
1258
+ }
1259
+ function recreateEntityName(node, helpers) {
1260
+ const resolvedName = helpers.resolveIdentifierName(node);
1261
+ if (resolvedName !== null && resolvedName !== node.getText()) {
1262
+ const identifiers = resolvedName.split(".");
1263
+ let result = ts2.factory.createIdentifier(identifiers[0]);
1264
+ for (let index = 1; index < identifiers.length; index += 1) {
1265
+ result = ts2.factory.createQualifiedName(result, ts2.factory.createIdentifier(identifiers[index]));
1266
+ }
1267
+ return result;
1268
+ }
1269
+ return node;
1270
+ }
1271
+ function getStatementText(statement, includeSortingValue, helpers) {
1272
+ const { shouldHaveExportKeyword, shouldHaveJSDoc } = helpers.getStatementSettings(statement);
1273
+ const needResolveIdentifiers = !ts2.isExportDeclaration(statement) || statement.moduleSpecifier === void 0;
1274
+ const printer = ts2.createPrinter({
1275
+ newLine: ts2.NewLineKind.LineFeed,
1276
+ removeComments: false
1277
+ }, {
1278
+ // eslint-disable-next-line complexity
1279
+ substituteNode: (hint, node) => {
1280
+ if (node.parent === void 0) {
1281
+ return node;
1282
+ }
1283
+ if (needResolveIdentifiers) {
1284
+ if (ts2.isPropertyAccessExpression(node)) {
1285
+ const resolvedName = helpers.resolveIdentifierName(node);
1286
+ if (resolvedName !== null && resolvedName !== node.getText()) {
1287
+ const identifiers = resolvedName.split(".");
1288
+ let result = ts2.factory.createIdentifier(identifiers[0]);
1289
+ for (let index = 1; index < identifiers.length; index += 1) {
1290
+ result = ts2.factory.createPropertyAccessExpression(result, ts2.factory.createIdentifier(identifiers[index]));
1291
+ }
1292
+ return result;
1293
+ }
1294
+ return node;
1295
+ }
1296
+ if (ts2.isIdentifier(node) || ts2.isQualifiedName(node)) {
1297
+ if (ts2.isIdentifier(node) && (ts2.isQualifiedName(node.parent) || ts2.isPropertyAccessExpression(node.parent))) {
1298
+ return node;
1299
+ }
1300
+ if (ts2.isIdentifier(node) && ts2.isImportTypeNode(node.parent) && node.parent.qualifier === node) {
1301
+ return node;
1302
+ }
1303
+ return recreateEntityName(node, helpers);
1304
+ }
1305
+ }
1306
+ if (ts2.isImportTypeNode(node) && node.qualifier !== void 0 && helpers.needStripImportFromImportTypeNode(node)) {
1307
+ const newQualifier = recreateEntityName(node.qualifier, helpers);
1308
+ if (node.isTypeOf) {
1309
+ return ts2.factory.createTypeQueryNode(newQualifier);
1310
+ }
1311
+ return ts2.factory.createTypeReferenceNode(newQualifier, node.typeArguments);
1312
+ }
1313
+ if (node !== statement) {
1314
+ return node;
1315
+ }
1316
+ const modifiersMap = (0, typescript_1.modifiersToMap)((0, typescript_1.getModifiers)(node));
1317
+ if (ts2.isEnumDeclaration(node) && modifiersMap[ts2.SyntaxKind.ConstKeyword] && helpers.needStripConstFromConstEnum(node)) {
1318
+ modifiersMap[ts2.SyntaxKind.ConstKeyword] = false;
1319
+ }
1320
+ const nodeName = (0, typescript_1.getNodeName)(node);
1321
+ const resolvedStatementName = nodeName !== void 0 ? helpers.resolveIdentifierName(nodeName) || void 0 : void 0;
1322
+ if (modifiersMap[ts2.SyntaxKind.DefaultKeyword]) {
1323
+ modifiersMap[ts2.SyntaxKind.DefaultKeyword] = false;
1324
+ if (ts2.isClassDeclaration(node)) {
1325
+ modifiersMap[ts2.SyntaxKind.DeclareKeyword] = true;
1326
+ }
1327
+ }
1328
+ if (!shouldHaveExportKeyword) {
1329
+ modifiersMap[ts2.SyntaxKind.ExportKeyword] = false;
1330
+ } else {
1331
+ modifiersMap[ts2.SyntaxKind.ExportKeyword] = true;
1332
+ }
1333
+ if (!modifiersMap[ts2.SyntaxKind.ExportKeyword] && (ts2.isClassDeclaration(node) || ts2.isFunctionDeclaration(node) || ts2.isVariableStatement(node) || ts2.isEnumDeclaration(node) || ts2.isModuleDeclaration(node))) {
1334
+ modifiersMap[ts2.SyntaxKind.DeclareKeyword] = true;
1335
+ }
1336
+ return (0, typescript_1.recreateRootLevelNodeWithModifiers)(node, modifiersMap, resolvedStatementName, shouldHaveJSDoc);
1337
+ }
1338
+ });
1339
+ const statementText = printer.printNode(ts2.EmitHint.Unspecified, statement, statement.getSourceFile()).trim();
1340
+ let sortingValue = "";
1341
+ if (includeSortingValue) {
1342
+ const tempSourceFile = ts2.createSourceFile("temp.d.ts", statementText, ts2.ScriptTarget.ESNext);
1343
+ sortingValue = tempSourceFile.getChildren()[0].getText();
1344
+ }
1345
+ return { text: statementText, sortingValue };
1346
+ }
1347
+ function generateImports(libraryName, imports) {
1348
+ const fromEnding = `from '${libraryName}';`;
1349
+ const result = [];
1350
+ if (imports.nsImport !== null) {
1351
+ result.push(`import * as ${imports.nsImport} ${fromEnding}`);
1352
+ }
1353
+ Array.from(imports.requireImports).sort().forEach((importName) => result.push(`import ${importName} = require('${libraryName}');`));
1354
+ Array.from(imports.defaultImports).sort().forEach((importName) => result.push(`import ${importName} ${fromEnding}`));
1355
+ if (imports.namedImports.size !== 0) {
1356
+ result.push(`import { ${Array.from(imports.namedImports.entries()).map(([localName, importedName]) => renamedImportValue(importedName, localName)).sort().join(", ")} } ${fromEnding}`);
1357
+ }
1358
+ if (imports.reExports.size !== 0) {
1359
+ result.push(`export { ${Array.from(imports.reExports.entries()).map(([localName, importedName]) => renamedImportValue(importedName, localName)).sort().join(", ")} } ${fromEnding}`);
1360
+ }
1361
+ return result;
1362
+ }
1363
+ function generateReferenceTypesDirective(libraries) {
1364
+ return libraries.sort().map((library) => {
1365
+ return `/// <reference types="${library}" />`;
1366
+ }).join("\n");
1367
+ }
1368
+ function spacesToTabs(text) {
1369
+ return text.replace(/^( )+/gm, (substring) => {
1370
+ return " ".repeat(substring.length / 4);
1371
+ });
1372
+ }
1373
+ }
1374
+ });
1375
+
1376
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/collisions-resolver.js
1377
+ var require_collisions_resolver = __commonJS({
1378
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/collisions-resolver.js"(exports) {
1379
+ "use strict";
1380
+ Object.defineProperty(exports, "__esModule", { value: true });
1381
+ exports.CollisionsResolver = void 0;
1382
+ var ts2 = __require("typescript");
1383
+ var typescript_1 = require_typescript();
1384
+ var logger_1 = require_logger();
1385
+ var renamingSupportedSymbols = [
1386
+ ts2.SymbolFlags.Alias,
1387
+ ts2.SymbolFlags.Variable,
1388
+ ts2.SymbolFlags.Class,
1389
+ ts2.SymbolFlags.Enum,
1390
+ ts2.SymbolFlags.Function,
1391
+ ts2.SymbolFlags.Interface,
1392
+ ts2.SymbolFlags.NamespaceModule,
1393
+ ts2.SymbolFlags.TypeAlias,
1394
+ ts2.SymbolFlags.ValueModule
1395
+ ];
1396
+ var CollisionsResolver = class {
1397
+ constructor(typeChecker) {
1398
+ this.collisionsMap = /* @__PURE__ */ new Map();
1399
+ this.generatedNames = /* @__PURE__ */ new Map();
1400
+ this.typeChecker = typeChecker;
1401
+ }
1402
+ /**
1403
+ * Adds (or "registers") a top-level {@link identifier} (which takes a top-level scope name to use).
1404
+ */
1405
+ addTopLevelIdentifier(identifier) {
1406
+ const symbol = (0, typescript_1.getDeclarationNameSymbol)(identifier, this.typeChecker);
1407
+ if (symbol === null) {
1408
+ throw new Error(`Something went wrong - cannot find a symbol for top-level identifier ${identifier.getText()} (from ${identifier.parent.parent.getText()})`);
1409
+ }
1410
+ const newLocalName = this.registerSymbol(symbol, identifier.getText());
1411
+ if (newLocalName === null) {
1412
+ throw new Error(`Something went wrong - a symbol ${symbol.name} for top-level identifier ${identifier.getText()} cannot be renamed`);
1413
+ }
1414
+ return newLocalName;
1415
+ }
1416
+ /**
1417
+ * Returns a set of all already registered names for a given {@link symbol}.
1418
+ */
1419
+ namesForSymbol(symbol) {
1420
+ return this.generatedNames.get((0, typescript_1.getActualSymbol)(symbol, this.typeChecker)) || /* @__PURE__ */ new Set();
1421
+ }
1422
+ /**
1423
+ * Resolves given {@link referencedIdentifier} to a name.
1424
+ * It assumes that a symbol for this identifier has been registered before by calling {@link addTopLevelIdentifier} method.
1425
+ * Otherwise it will return `null`.
1426
+ *
1427
+ * Note that a returned value might be of a different type of the identifier (e.g. {@link ts.QualifiedName} for a given {@link ts.Identifier})
1428
+ */
1429
+ resolveReferencedIdentifier(referencedIdentifier) {
1430
+ const identifierSymbol = (0, typescript_1.getDeclarationNameSymbol)(referencedIdentifier, this.typeChecker);
1431
+ if (identifierSymbol === null) {
1432
+ return null;
1433
+ }
1434
+ const symbolScopePath = this.getSymbolScope(identifierSymbol);
1435
+ const currentIdentifierScope = this.getNodeScope(referencedIdentifier);
1436
+ if (symbolScopePath.length > 0 && currentIdentifierScope.length > 0 && symbolScopePath[0] === currentIdentifierScope[0]) {
1437
+ return referencedIdentifier.getText();
1438
+ }
1439
+ const topLevelIdentifierSymbol = symbolScopePath.length === 0 ? identifierSymbol : symbolScopePath[0];
1440
+ const namesForTopLevelSymbol = this.namesForSymbol(topLevelIdentifierSymbol);
1441
+ if (namesForTopLevelSymbol.size === 0) {
1442
+ return null;
1443
+ }
1444
+ let topLevelName = symbolScopePath.length === 0 ? referencedIdentifier.getText() : topLevelIdentifierSymbol.getName();
1445
+ if (!namesForTopLevelSymbol.has(topLevelName)) {
1446
+ const topLevelNamesArray = Array.from(namesForTopLevelSymbol);
1447
+ let suitableTopLevelName = topLevelNamesArray[0];
1448
+ for (const name of topLevelNamesArray) {
1449
+ if (name.startsWith(`${topLevelName}$`)) {
1450
+ suitableTopLevelName = name;
1451
+ break;
1452
+ }
1453
+ }
1454
+ topLevelName = suitableTopLevelName;
1455
+ }
1456
+ const newIdentifierParts = [
1457
+ ...symbolScopePath.map((symbol) => symbol.getName()),
1458
+ referencedIdentifier.getText()
1459
+ ];
1460
+ newIdentifierParts[0] = topLevelName;
1461
+ return newIdentifierParts.join(".");
1462
+ }
1463
+ /**
1464
+ * Similar to {@link resolveReferencedIdentifier}, but works with qualified names (Ns.Ns1.Interface).
1465
+ * The main point of this resolver is that it might change the first part of the qualifier only (as it drives uniqueness of a name).
1466
+ */
1467
+ resolveReferencedQualifiedName(referencedIdentifier) {
1468
+ let topLevelIdentifier = referencedIdentifier;
1469
+ if (ts2.isQualifiedName(topLevelIdentifier) || ts2.isPropertyAccessExpression(topLevelIdentifier)) {
1470
+ let leftmostIdentifier = ts2.isQualifiedName(topLevelIdentifier) ? topLevelIdentifier.left : topLevelIdentifier.expression;
1471
+ while (ts2.isQualifiedName(leftmostIdentifier) || ts2.isPropertyAccessExpression(leftmostIdentifier)) {
1472
+ leftmostIdentifier = ts2.isQualifiedName(leftmostIdentifier) ? leftmostIdentifier.left : leftmostIdentifier.expression;
1473
+ }
1474
+ topLevelIdentifier = leftmostIdentifier;
1475
+ }
1476
+ const topLevelName = this.resolveReferencedIdentifier(topLevelIdentifier);
1477
+ if (topLevelName === null) {
1478
+ const identifierSymbol = (0, typescript_1.getDeclarationNameSymbol)(referencedIdentifier, this.typeChecker);
1479
+ if (identifierSymbol === null) {
1480
+ return null;
1481
+ }
1482
+ const namesForSymbol = this.namesForSymbol(identifierSymbol);
1483
+ if (namesForSymbol.size !== 0) {
1484
+ return Array.from(namesForSymbol)[0];
1485
+ }
1486
+ return null;
1487
+ }
1488
+ const identifierParts = referencedIdentifier.getText().split(".");
1489
+ identifierParts[0] = topLevelName;
1490
+ return identifierParts.join(".");
1491
+ }
1492
+ getSymbolScope(identifierSymbol) {
1493
+ const identifierDeclarations = (0, typescript_1.getDeclarationsForSymbol)(identifierSymbol);
1494
+ if (identifierDeclarations.length === 0) {
1495
+ return [];
1496
+ }
1497
+ return this.getNodeScope(identifierDeclarations[0]);
1498
+ }
1499
+ /**
1500
+ * Returns a node's scope where it is located in terms of namespaces/modules.
1501
+ * E.g. A scope for `Opt` in `declare module foo { type Opt = number; }` is `[Symbol(foo)]`
1502
+ */
1503
+ getNodeScope(node) {
1504
+ const scopeIdentifiersPath = [];
1505
+ let currentNode = (0, typescript_1.getClosestModuleLikeNode)(node);
1506
+ while (ts2.isModuleDeclaration(currentNode) && ts2.isIdentifier(currentNode.name)) {
1507
+ const nameSymbol = (0, typescript_1.getDeclarationNameSymbol)(currentNode.name, this.typeChecker);
1508
+ if (nameSymbol === null) {
1509
+ throw new Error(`Cannot find symbol for identifier '${currentNode.name.getText()}'`);
1510
+ }
1511
+ scopeIdentifiersPath.push(nameSymbol);
1512
+ currentNode = (0, typescript_1.getClosestModuleLikeNode)(currentNode.parent);
1513
+ }
1514
+ return scopeIdentifiersPath.reverse();
1515
+ }
1516
+ registerSymbol(identifierSymbol, preferredName) {
1517
+ if (!renamingSupportedSymbols.some((flag) => identifierSymbol.flags & flag)) {
1518
+ (0, logger_1.verboseLog)(`Symbol ${identifierSymbol.name} cannot be renamed because its flag (${identifierSymbol.flags}) isn't supported`);
1519
+ return null;
1520
+ }
1521
+ if (identifierSymbol.flags & ts2.SymbolFlags.NamespaceModule && identifierSymbol.escapedName === ts2.InternalSymbolName.Global) {
1522
+ return null;
1523
+ }
1524
+ let symbolName = preferredName;
1525
+ if (symbolName === "default") {
1526
+ symbolName = "_default";
1527
+ }
1528
+ const collisionsKey = symbolName;
1529
+ let collisionSymbols = this.collisionsMap.get(collisionsKey);
1530
+ if (collisionSymbols === void 0) {
1531
+ collisionSymbols = /* @__PURE__ */ new Map();
1532
+ this.collisionsMap.set(collisionsKey, collisionSymbols);
1533
+ }
1534
+ const storedSymbolName = collisionSymbols.get(identifierSymbol);
1535
+ if (storedSymbolName !== void 0) {
1536
+ return storedSymbolName;
1537
+ }
1538
+ let nameIndex = collisionSymbols.size;
1539
+ let newName = collisionSymbols.size === 0 ? symbolName : `${symbolName}$${nameIndex}`;
1540
+ let resolvedGlobalSymbol = (0, typescript_1.resolveGlobalName)(this.typeChecker, newName);
1541
+ while (resolvedGlobalSymbol !== void 0 && resolvedGlobalSymbol !== identifierSymbol) {
1542
+ nameIndex += 1;
1543
+ newName = `${symbolName}$${nameIndex}`;
1544
+ resolvedGlobalSymbol = (0, typescript_1.resolveGlobalName)(this.typeChecker, newName);
1545
+ }
1546
+ collisionSymbols.set(identifierSymbol, newName);
1547
+ let symbolNames = this.generatedNames.get(identifierSymbol);
1548
+ if (symbolNames === void 0) {
1549
+ symbolNames = /* @__PURE__ */ new Set();
1550
+ this.generatedNames.set(identifierSymbol, symbolNames);
1551
+ }
1552
+ symbolNames.add(newName);
1553
+ return newName;
1554
+ }
1555
+ };
1556
+ exports.CollisionsResolver = CollisionsResolver;
1557
+ }
1558
+ });
1559
+
1560
+ // ../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/bundle-generator.js
1561
+ var require_bundle_generator = __commonJS({
1562
+ "../node_modules/.bun/dts-bundle-generator@9.5.1/node_modules/dts-bundle-generator/dist/bundle-generator.js"(exports) {
1563
+ "use strict";
1564
+ Object.defineProperty(exports, "__esModule", { value: true });
1565
+ exports.generateDtsBundle = void 0;
1566
+ var ts2 = __require("typescript");
1567
+ var compile_dts_1 = require_compile_dts();
1568
+ var types_usage_evaluator_1 = require_types_usage_evaluator();
1569
+ var typescript_1 = require_typescript();
1570
+ var module_info_1 = require_module_info();
1571
+ var generate_output_1 = require_generate_output();
1572
+ var logger_1 = require_logger();
1573
+ var collisions_resolver_1 = require_collisions_resolver();
1574
+ function generateDtsBundle2(entries, options = {}) {
1575
+ (0, logger_1.normalLog)("Compiling input files...");
1576
+ const { program, rootFilesRemapping } = (0, compile_dts_1.compileDts)(entries.map((entry) => entry.filePath), options.preferredConfigPath, options.followSymlinks);
1577
+ const typeChecker = program.getTypeChecker();
1578
+ const typeRoots = ts2.getEffectiveTypeRoots(program.getCompilerOptions(), {});
1579
+ const sourceFiles = program.getSourceFiles().filter((file) => {
1580
+ return !program.isSourceFileDefaultLibrary(file);
1581
+ });
1582
+ const typesUsageEvaluator = new types_usage_evaluator_1.TypesUsageEvaluator(sourceFiles, typeChecker);
1583
+ return entries.map((entryConfig) => {
1584
+ (0, logger_1.normalLog)(`Processing ${entryConfig.filePath}`);
1585
+ const newRootFilePath = rootFilesRemapping.get(entryConfig.filePath);
1586
+ if (newRootFilePath === void 0) {
1587
+ throw new Error(`Cannot remap root source file ${entryConfig.filePath}`);
1588
+ }
1589
+ const rootSourceFile = (0, typescript_1.getRootSourceFile)(program, newRootFilePath);
1590
+ const rootSourceFileSymbol = typeChecker.getSymbolAtLocation(rootSourceFile);
1591
+ if (rootSourceFileSymbol === void 0) {
1592
+ throw new Error(`Symbol for root source file ${newRootFilePath} not found`);
1593
+ }
1594
+ const librariesOptions = entryConfig.libraries || {};
1595
+ const criteria = {
1596
+ allowedTypesLibraries: librariesOptions.allowedTypesLibraries,
1597
+ importedLibraries: librariesOptions.importedLibraries,
1598
+ inlinedLibraries: librariesOptions.inlinedLibraries || [],
1599
+ typeRoots
1600
+ };
1601
+ const rootFileExports = (0, typescript_1.getExportsForSourceFile)(typeChecker, rootSourceFileSymbol);
1602
+ const rootFileExportSymbols = rootFileExports.map((exp) => exp.symbol);
1603
+ const collectionResult = {
1604
+ typesReferences: /* @__PURE__ */ new Set(),
1605
+ imports: /* @__PURE__ */ new Map(),
1606
+ statements: [],
1607
+ renamedExports: /* @__PURE__ */ new Map(),
1608
+ wrappedNamespaces: /* @__PURE__ */ new Map()
1609
+ };
1610
+ const outputOptions = entryConfig.output || {};
1611
+ const inlineDeclareGlobals = Boolean(outputOptions.inlineDeclareGlobals);
1612
+ const inlineDeclareExternals = Boolean(outputOptions.inlineDeclareExternals);
1613
+ const collisionsResolver = new collisions_resolver_1.CollisionsResolver(typeChecker);
1614
+ function updateResultForAnyModule(statements, currentModule) {
1615
+ const visitedModules = /* @__PURE__ */ new Set();
1616
+ function updateResultForExternalExport(exportAssignment) {
1617
+ for (const declaration of (0, typescript_1.getDeclarationsForExportedValues)(exportAssignment, typeChecker)) {
1618
+ if (ts2.isVariableDeclaration(declaration)) {
1619
+ continue;
1620
+ }
1621
+ let exportedDeclarations = [];
1622
+ if (ts2.isExportDeclaration(exportAssignment) && ts2.isSourceFile(declaration)) {
1623
+ const referencedModule = (0, module_info_1.getReferencedModuleInfo)(exportAssignment, criteria, typeChecker);
1624
+ if (referencedModule !== null) {
1625
+ if (visitedModules.has(referencedModule.fileName)) {
1626
+ continue;
1627
+ }
1628
+ visitedModules.add(referencedModule.fileName);
1629
+ }
1630
+ exportedDeclarations = declaration.statements;
1631
+ } else if (ts2.isModuleDeclaration(declaration)) {
1632
+ if (declaration.body !== void 0 && ts2.isModuleBlock(declaration.body)) {
1633
+ const referencedModule = (0, module_info_1.getReferencedModuleInfo)(declaration, criteria, typeChecker);
1634
+ if (referencedModule !== null) {
1635
+ if (visitedModules.has(referencedModule.fileName)) {
1636
+ continue;
1637
+ }
1638
+ visitedModules.add(referencedModule.fileName);
1639
+ }
1640
+ exportedDeclarations = declaration.body.statements;
1641
+ }
1642
+ } else {
1643
+ exportedDeclarations = [declaration];
1644
+ }
1645
+ updateResultImpl(exportedDeclarations);
1646
+ }
1647
+ }
1648
+ function updateResultImpl(statementsToProcess) {
1649
+ for (const statement of statementsToProcess) {
1650
+ if (statement.kind === ts2.SyntaxKind.ImportDeclaration || statement.kind === ts2.SyntaxKind.ImportEqualsDeclaration) {
1651
+ continue;
1652
+ }
1653
+ if ((0, typescript_1.isDeclareModule)(statement)) {
1654
+ updateResultForModuleDeclaration(statement, currentModule);
1655
+ if (ts2.isStringLiteral(statement.name)) {
1656
+ continue;
1657
+ }
1658
+ }
1659
+ if (currentModule.type === 3) {
1660
+ continue;
1661
+ }
1662
+ if ((0, typescript_1.isDeclareGlobalStatement)(statement) && inlineDeclareGlobals && currentModule.type === 0) {
1663
+ collectionResult.statements.push(statement);
1664
+ continue;
1665
+ }
1666
+ if (ts2.isExportDeclaration(statement)) {
1667
+ if (currentModule.type === 0) {
1668
+ continue;
1669
+ }
1670
+ if (statement.exportClause === void 0) {
1671
+ updateResultForExternalExport(statement);
1672
+ continue;
1673
+ }
1674
+ if (ts2.isNamedExports(statement.exportClause) && currentModule.type === 1) {
1675
+ updateImportsForStatement(statement);
1676
+ continue;
1677
+ }
1678
+ }
1679
+ if (ts2.isExportAssignment(statement) && statement.isExportEquals && currentModule.type !== 0) {
1680
+ updateResultForExternalExport(statement);
1681
+ continue;
1682
+ }
1683
+ if (!isNodeUsed(statement)) {
1684
+ continue;
1685
+ }
1686
+ switch (currentModule.type) {
1687
+ case 2:
1688
+ forEachNodeThatShouldBeImported(statement, () => addTypesReference(currentModule.typesLibraryName));
1689
+ break;
1690
+ case 1:
1691
+ updateImportsForStatement(statement);
1692
+ break;
1693
+ case 0:
1694
+ if (ts2.isVariableStatement(statement)) {
1695
+ for (const variableDeclaration of statement.declarationList.declarations) {
1696
+ if (ts2.isIdentifier(variableDeclaration.name)) {
1697
+ collisionsResolver.addTopLevelIdentifier(variableDeclaration.name);
1698
+ continue;
1699
+ }
1700
+ for (const element of variableDeclaration.name.elements) {
1701
+ if (!ts2.isOmittedExpression(element) && ts2.isIdentifier(element.name)) {
1702
+ collisionsResolver.addTopLevelIdentifier(element.name);
1703
+ }
1704
+ }
1705
+ }
1706
+ } else if ((0, typescript_1.isNodeNamedDeclaration)(statement)) {
1707
+ const statementName = (0, typescript_1.getNodeName)(statement);
1708
+ if (statementName !== void 0) {
1709
+ collisionsResolver.addTopLevelIdentifier(statementName);
1710
+ }
1711
+ }
1712
+ collectionResult.statements.push(statement);
1713
+ break;
1714
+ }
1715
+ }
1716
+ }
1717
+ updateResultImpl(statements);
1718
+ }
1719
+ function isReferencedModuleImportable(statement) {
1720
+ return (0, module_info_1.getReferencedModuleInfo)(statement, criteria, typeChecker)?.type === 1;
1721
+ }
1722
+ function handleExportDeclarationFromRootModule(exportDeclaration) {
1723
+ function handleExportStarStatement(exportStarStatement, visitedSymbols = /* @__PURE__ */ new Set()) {
1724
+ if (exportStarStatement.moduleSpecifier === void 0 || exportStarStatement.exportClause !== void 0) {
1725
+ throw new Error(`Invalid export-star declaration statement provided, ${exportStarStatement.getText()}`);
1726
+ }
1727
+ const importModuleSpecifier = (0, typescript_1.getImportModuleName)(exportStarStatement);
1728
+ if (importModuleSpecifier === null) {
1729
+ return;
1730
+ }
1731
+ const referencedModuleInfo = (0, module_info_1.getReferencedModuleInfo)(exportStarStatement, criteria, typeChecker);
1732
+ if (referencedModuleInfo === null) {
1733
+ return;
1734
+ }
1735
+ switch (referencedModuleInfo.type) {
1736
+ case 0: {
1737
+ const referencedModuleSymbol = (0, typescript_1.getNodeOwnSymbol)(exportStarStatement.moduleSpecifier, typeChecker);
1738
+ const referencedSourceFileExportStarSymbol = referencedModuleSymbol.exports?.get(ts2.InternalSymbolName.ExportStar);
1739
+ if (referencedSourceFileExportStarSymbol !== void 0) {
1740
+ if (visitedSymbols.has(referencedSourceFileExportStarSymbol)) {
1741
+ return;
1742
+ }
1743
+ visitedSymbols.add(referencedSourceFileExportStarSymbol);
1744
+ for (const exportDecl of (0, typescript_1.getSymbolExportStarDeclarations)(referencedSourceFileExportStarSymbol)) {
1745
+ handleExportStarStatement(exportDecl, visitedSymbols);
1746
+ }
1747
+ }
1748
+ break;
1749
+ }
1750
+ case 1: {
1751
+ collectionResult.statements.push(exportStarStatement);
1752
+ break;
1753
+ }
1754
+ }
1755
+ }
1756
+ function findExportingExportStarExportFromImportableModule(referencedModuleSymbol, nodeSymbol) {
1757
+ function findResultRecursively(referencedModuleSym, exportedNodeSym, visitedSymbols) {
1758
+ if (visitedSymbols.has(referencedModuleSym)) {
1759
+ return null;
1760
+ }
1761
+ visitedSymbols.add(referencedModuleSym);
1762
+ const exportStarExport = referencedModuleSym.exports?.get(ts2.InternalSymbolName.ExportStar);
1763
+ if (exportStarExport === void 0) {
1764
+ return null;
1765
+ }
1766
+ for (const exportStarDeclaration of (0, typescript_1.getDeclarationsForSymbol)(exportStarExport).filter(ts2.isExportDeclaration)) {
1767
+ if (exportStarDeclaration.moduleSpecifier === void 0) {
1768
+ continue;
1769
+ }
1770
+ const exportStarModuleSymbol = (0, typescript_1.getNodeOwnSymbol)(exportStarDeclaration.moduleSpecifier, typeChecker);
1771
+ if (exportStarModuleSymbol.exports === void 0) {
1772
+ continue;
1773
+ }
1774
+ if (isReferencedModuleImportable(exportStarDeclaration)) {
1775
+ const referencedModuleExports = typeChecker.getExportsOfModule(exportStarModuleSymbol);
1776
+ const exportedNodeSymbol = referencedModuleExports.find((exp) => (0, typescript_1.getActualSymbol)(exp, typeChecker) === nodeSymbol);
1777
+ if (exportedNodeSymbol !== void 0) {
1778
+ return { exportStarDeclaration, exportedNodeSymbol };
1779
+ }
1780
+ continue;
1781
+ }
1782
+ const result = findResultRecursively(exportStarModuleSymbol, exportedNodeSym, visitedSymbols);
1783
+ if (result !== null) {
1784
+ return result;
1785
+ }
1786
+ }
1787
+ return null;
1788
+ }
1789
+ if (referencedModuleSymbol.exports === void 0) {
1790
+ throw new Error(`No exports found for "${referencedModuleSymbol.getName()}" symbol`);
1791
+ }
1792
+ const hasExplicitExportOfSymbol = Array.from(referencedModuleSymbol.exports.values()).some((exp) => {
1793
+ if (exp.escapedName === ts2.InternalSymbolName.ExportStar) {
1794
+ return false;
1795
+ }
1796
+ return (0, typescript_1.getActualSymbol)(exp, typeChecker) === nodeSymbol;
1797
+ });
1798
+ if (hasExplicitExportOfSymbol) {
1799
+ return null;
1800
+ }
1801
+ return findResultRecursively(referencedModuleSymbol, nodeSymbol, /* @__PURE__ */ new Set());
1802
+ }
1803
+ if (exportDeclaration.exportClause === void 0) {
1804
+ handleExportStarStatement(exportDeclaration);
1805
+ return;
1806
+ }
1807
+ if (exportDeclaration.exportClause !== void 0 && ts2.isNamedExports(exportDeclaration.exportClause)) {
1808
+ if (exportDeclaration.moduleSpecifier === void 0) {
1809
+ for (const exportElement of exportDeclaration.exportClause.elements) {
1810
+ const exportElementSymbol = (0, typescript_1.getImportExportReferencedSymbol)(exportElement, typeChecker);
1811
+ const namespaceImportFromImportableModule = (0, typescript_1.getDeclarationsForSymbol)(exportElementSymbol).find((importDecl) => {
1812
+ return ts2.isNamespaceImport(importDecl) && isReferencedModuleImportable(importDecl.parent.parent);
1813
+ });
1814
+ if (namespaceImportFromImportableModule !== void 0) {
1815
+ const importModuleSpecifier = (0, typescript_1.getImportModuleName)(namespaceImportFromImportableModule.parent.parent);
1816
+ if (importModuleSpecifier === null) {
1817
+ throw new Error(`Cannot get import module name from '${namespaceImportFromImportableModule.parent.parent.getText()}'`);
1818
+ }
1819
+ addNsImport(getImportItem(importModuleSpecifier), namespaceImportFromImportableModule.name);
1820
+ }
1821
+ }
1822
+ return;
1823
+ }
1824
+ if (exportDeclaration.moduleSpecifier !== void 0) {
1825
+ const referencedModuleSymbol = (0, typescript_1.getNodeOwnSymbol)(exportDeclaration.moduleSpecifier, typeChecker);
1826
+ for (const exportElement of exportDeclaration.exportClause.elements) {
1827
+ const exportedNodeSymbol = (0, typescript_1.getActualSymbol)((0, typescript_1.getImportExportReferencedSymbol)(exportElement, typeChecker), typeChecker);
1828
+ const exportingExportStarResult = findExportingExportStarExportFromImportableModule(referencedModuleSymbol, exportedNodeSymbol);
1829
+ if (exportingExportStarResult === null) {
1830
+ continue;
1831
+ }
1832
+ const importModuleSpecifier = (0, typescript_1.getImportModuleName)(exportingExportStarResult.exportStarDeclaration);
1833
+ if (importModuleSpecifier === null) {
1834
+ throw new Error(`Cannot get import module name from '${exportingExportStarResult.exportStarDeclaration.getText()}'`);
1835
+ }
1836
+ addReExport(getImportItem(importModuleSpecifier), exportingExportStarResult.exportedNodeSymbol.getName(), exportElement.name.text);
1837
+ }
1838
+ return;
1839
+ }
1840
+ }
1841
+ }
1842
+ function updateResultForRootModule(statements, currentModule) {
1843
+ updateResultForAnyModule(statements, currentModule);
1844
+ for (const statement of statements) {
1845
+ if (ts2.isExportDeclaration(statement)) {
1846
+ handleExportDeclarationFromRootModule(statement);
1847
+ continue;
1848
+ }
1849
+ if (ts2.isExportAssignment(statement)) {
1850
+ if (statement.isExportEquals || !ts2.isIdentifier(statement.expression)) {
1851
+ collectionResult.statements.push(statement);
1852
+ }
1853
+ continue;
1854
+ }
1855
+ }
1856
+ }
1857
+ function updateResultForModuleDeclaration(moduleDecl, currentModule) {
1858
+ if (moduleDecl.body === void 0 || !ts2.isModuleBlock(moduleDecl.body)) {
1859
+ return;
1860
+ }
1861
+ const referencedModuleInfo = (0, module_info_1.getModuleLikeModuleInfo)(moduleDecl, criteria, typeChecker);
1862
+ if (referencedModuleInfo === null) {
1863
+ return;
1864
+ }
1865
+ if (!currentModule.isExternal && referencedModuleInfo.isExternal) {
1866
+ if (inlineDeclareExternals) {
1867
+ collectionResult.statements.push(moduleDecl);
1868
+ }
1869
+ return;
1870
+ }
1871
+ updateResultForAnyModule(moduleDecl.body.statements, referencedModuleInfo);
1872
+ }
1873
+ function addTypesReference(library) {
1874
+ if (!collectionResult.typesReferences.has(library)) {
1875
+ (0, logger_1.normalLog)(`Library "${library}" will be added via reference directive`);
1876
+ collectionResult.typesReferences.add(library);
1877
+ }
1878
+ }
1879
+ function forEachNodeThatShouldBeImported(statement, callback) {
1880
+ const statementsToImport = ts2.isVariableStatement(statement) ? statement.declarationList.declarations : ts2.isExportDeclaration(statement) && statement.exportClause !== void 0 ? ts2.isNamespaceExport(statement.exportClause) ? [statement.exportClause] : statement.exportClause.elements : [statement];
1881
+ for (const statementToImport of statementsToImport) {
1882
+ if (shouldNodeBeImported(statementToImport)) {
1883
+ callback(statementToImport);
1884
+ }
1885
+ }
1886
+ }
1887
+ function updateImportsForStatement(statement) {
1888
+ forEachNodeThatShouldBeImported(statement, (statementToImport) => {
1889
+ addImport(statementToImport);
1890
+ const sourceFile = statementToImport.getSourceFile();
1891
+ const moduleInfo = (0, module_info_1.getFileModuleInfo)(sourceFile.fileName, criteria);
1892
+ if (moduleInfo.type === 2) {
1893
+ addTypesReference(moduleInfo.typesLibraryName);
1894
+ }
1895
+ });
1896
+ }
1897
+ function getDeclarationUsagesSourceFiles(declaration) {
1898
+ return new Set(getExportedSymbolsUsingStatement(declaration).map((symbol) => (0, typescript_1.getDeclarationsForSymbol)(symbol)).reduce((acc, val) => acc.concat(val), []).map(typescript_1.getClosestModuleLikeNode));
1899
+ }
1900
+ function getImportItem(importModuleSpecifier) {
1901
+ let importItem = collectionResult.imports.get(importModuleSpecifier);
1902
+ if (importItem === void 0) {
1903
+ importItem = {
1904
+ defaultImports: /* @__PURE__ */ new Set(),
1905
+ namedImports: /* @__PURE__ */ new Map(),
1906
+ nsImport: null,
1907
+ requireImports: /* @__PURE__ */ new Set(),
1908
+ reExports: /* @__PURE__ */ new Map()
1909
+ };
1910
+ collectionResult.imports.set(importModuleSpecifier, importItem);
1911
+ }
1912
+ return importItem;
1913
+ }
1914
+ function addRequireImport(importItem, preferredLocalName) {
1915
+ importItem.requireImports.add(collisionsResolver.addTopLevelIdentifier(preferredLocalName));
1916
+ }
1917
+ function addNamedImport(importItem, preferredLocalName, importedIdentifier) {
1918
+ const newLocalName = collisionsResolver.addTopLevelIdentifier(preferredLocalName);
1919
+ const importedName = importedIdentifier.text;
1920
+ importItem.namedImports.set(newLocalName, importedName);
1921
+ }
1922
+ function addReExport(importItem, moduleExportedName, reExportedName) {
1923
+ importItem.reExports.set(reExportedName, moduleExportedName);
1924
+ }
1925
+ function addNsImport(importItem, preferredLocalName) {
1926
+ if (importItem.nsImport === null) {
1927
+ importItem.nsImport = collisionsResolver.addTopLevelIdentifier(preferredLocalName);
1928
+ }
1929
+ }
1930
+ function addDefaultImport(importItem, preferredLocalName) {
1931
+ importItem.defaultImports.add(collisionsResolver.addTopLevelIdentifier(preferredLocalName));
1932
+ }
1933
+ function addImport(statement) {
1934
+ forEachImportOfStatement(statement, (imp, referencedModuleInfo, importModuleSpecifier) => {
1935
+ if (referencedModuleInfo.type !== 1) {
1936
+ return;
1937
+ }
1938
+ const importItem = getImportItem(importModuleSpecifier);
1939
+ if (ts2.isImportEqualsDeclaration(imp)) {
1940
+ addRequireImport(importItem, imp.name);
1941
+ return;
1942
+ }
1943
+ if (ts2.isExportSpecifier(imp)) {
1944
+ addNamedImport(importItem, imp.name, imp.propertyName || imp.name);
1945
+ return;
1946
+ }
1947
+ if (ts2.isNamespaceExport(imp)) {
1948
+ addNsImport(importItem, imp.name);
1949
+ return;
1950
+ }
1951
+ if (ts2.isImportClause(imp) && imp.name !== void 0) {
1952
+ addDefaultImport(importItem, imp.name);
1953
+ return;
1954
+ }
1955
+ if (ts2.isImportSpecifier(imp)) {
1956
+ addNamedImport(importItem, imp.name, imp.propertyName || imp.name);
1957
+ return;
1958
+ }
1959
+ if (ts2.isNamespaceImport(imp)) {
1960
+ addNsImport(importItem, imp.name);
1961
+ return;
1962
+ }
1963
+ });
1964
+ }
1965
+ function forEachImportOfStatement(statement, callback) {
1966
+ if (!ts2.isSourceFile(statement) && statement.name === void 0) {
1967
+ throw new Error(`Import/usage unnamed declaration: ${statement.getText()}`);
1968
+ }
1969
+ getDeclarationUsagesSourceFiles(statement).forEach((sourceFile) => {
1970
+ if ((0, module_info_1.getModuleLikeModuleInfo)(sourceFile, criteria, typeChecker).type !== 0) {
1971
+ return;
1972
+ }
1973
+ const sourceFileStatements = ts2.isSourceFile(sourceFile) ? sourceFile.statements : sourceFile.body !== void 0 && ts2.isModuleBlock(sourceFile.body) ? sourceFile.body.statements : [];
1974
+ sourceFileStatements.forEach((st) => {
1975
+ if (!ts2.isImportEqualsDeclaration(st) && !ts2.isImportDeclaration(st) && !ts2.isExportDeclaration(st)) {
1976
+ return;
1977
+ }
1978
+ const importModuleSpecifier = (0, typescript_1.getImportModuleName)(st);
1979
+ if (importModuleSpecifier === null) {
1980
+ return;
1981
+ }
1982
+ const referencedModuleInfo = (0, module_info_1.getReferencedModuleInfo)(st, criteria, typeChecker);
1983
+ if (referencedModuleInfo === null) {
1984
+ return;
1985
+ }
1986
+ if (ts2.isImportEqualsDeclaration(st)) {
1987
+ if (areDeclarationSame(statement, st)) {
1988
+ callback(st, referencedModuleInfo, importModuleSpecifier);
1989
+ }
1990
+ return;
1991
+ }
1992
+ if (ts2.isExportDeclaration(st) && st.exportClause !== void 0) {
1993
+ if (ts2.isNamedExports(st.exportClause)) {
1994
+ st.exportClause.elements.filter(areDeclarationSame.bind(null, statement)).forEach((specifier) => {
1995
+ callback(specifier, referencedModuleInfo, importModuleSpecifier);
1996
+ });
1997
+ } else {
1998
+ if (isNodeUsed(st.exportClause)) {
1999
+ callback(st.exportClause, referencedModuleInfo, importModuleSpecifier);
2000
+ }
2001
+ }
2002
+ } else if (ts2.isImportDeclaration(st) && st.importClause !== void 0) {
2003
+ if (st.importClause.name !== void 0 && areDeclarationSame(statement, st.importClause)) {
2004
+ callback(st.importClause, referencedModuleInfo, importModuleSpecifier);
2005
+ }
2006
+ if (st.importClause.namedBindings !== void 0) {
2007
+ if (ts2.isNamedImports(st.importClause.namedBindings)) {
2008
+ st.importClause.namedBindings.elements.filter(areDeclarationSame.bind(null, statement)).forEach((specifier) => {
2009
+ callback(specifier, referencedModuleInfo, importModuleSpecifier);
2010
+ });
2011
+ } else {
2012
+ if (isNodeUsed(st.importClause)) {
2013
+ callback(st.importClause.namedBindings, referencedModuleInfo, importModuleSpecifier);
2014
+ }
2015
+ }
2016
+ }
2017
+ }
2018
+ });
2019
+ });
2020
+ }
2021
+ function getInlinedSymbolsUsingSymbol(symbol, predicate) {
2022
+ return Array.from(typesUsageEvaluator.getSymbolsUsingSymbol(symbol) ?? []).filter((usedInSymbol) => {
2023
+ if (!predicate(usedInSymbol)) {
2024
+ return false;
2025
+ }
2026
+ return (0, typescript_1.getDeclarationsForSymbol)(usedInSymbol).some((decl) => {
2027
+ const closestModuleLike = (0, typescript_1.getClosestSourceFileLikeNode)(decl);
2028
+ const moduleInfo = (0, module_info_1.getModuleLikeModuleInfo)(closestModuleLike, criteria, typeChecker);
2029
+ return moduleInfo.type === 0;
2030
+ });
2031
+ });
2032
+ }
2033
+ function isSymbolUsedByInlinedSymbols(symbol, predicate, visitedSymbols = /* @__PURE__ */ new Set()) {
2034
+ if (visitedSymbols.has(symbol)) {
2035
+ return false;
2036
+ }
2037
+ visitedSymbols.add(symbol);
2038
+ return Array.from(typesUsageEvaluator.getSymbolsUsingSymbol(symbol) ?? []).some((usedInSymbol) => {
2039
+ if (!predicate(usedInSymbol)) {
2040
+ return isSymbolUsedByInlinedSymbols(usedInSymbol, predicate, visitedSymbols);
2041
+ }
2042
+ const usedByThisSymbol = (0, typescript_1.getDeclarationsForSymbol)(usedInSymbol).some((decl) => {
2043
+ const closestModuleLike = (0, typescript_1.getClosestSourceFileLikeNode)(decl);
2044
+ const moduleInfo = (0, module_info_1.getModuleLikeModuleInfo)(closestModuleLike, criteria, typeChecker);
2045
+ return moduleInfo.type === 0;
2046
+ });
2047
+ if (usedByThisSymbol) {
2048
+ return true;
2049
+ }
2050
+ return isSymbolUsedByInlinedSymbols(usedInSymbol, predicate, visitedSymbols);
2051
+ });
2052
+ }
2053
+ function isSymbolUsedByRootFileExports(symbol) {
2054
+ return rootFileExportSymbols.some((rootSymbol) => typesUsageEvaluator.isSymbolUsedBySymbol(symbol, rootSymbol));
2055
+ }
2056
+ function isSymbolForGlobalDeclaration(symbol) {
2057
+ return symbol.escapedName === ts2.InternalSymbolName.Global;
2058
+ }
2059
+ function isSymbolForDeclareModuleDeclaration(symbol) {
2060
+ return (0, typescript_1.getDeclarationsForSymbol)(symbol).some(typescript_1.isDeclareModule);
2061
+ }
2062
+ function isNodeUsed(node) {
2063
+ if ((0, typescript_1.isNodeNamedDeclaration)(node) || ts2.isSourceFile(node)) {
2064
+ const nodeSymbol = (0, typescript_1.getNodeSymbol)(node, typeChecker);
2065
+ if (nodeSymbol === null) {
2066
+ return false;
2067
+ }
2068
+ const nodeUsedByDirectExports = isSymbolUsedByRootFileExports(nodeSymbol);
2069
+ if (nodeUsedByDirectExports) {
2070
+ return true;
2071
+ }
2072
+ if (inlineDeclareGlobals && isSymbolUsedByInlinedSymbols(nodeSymbol, isSymbolForGlobalDeclaration)) {
2073
+ return true;
2074
+ }
2075
+ if (inlineDeclareExternals && isSymbolUsedByInlinedSymbols(nodeSymbol, isSymbolForDeclareModuleDeclaration)) {
2076
+ return true;
2077
+ }
2078
+ return false;
2079
+ }
2080
+ if (ts2.isVariableStatement(node)) {
2081
+ return node.declarationList.declarations.some((declaration) => {
2082
+ if (ts2.isObjectBindingPattern(declaration.name) || ts2.isArrayBindingPattern(declaration.name)) {
2083
+ return declaration.name.elements.some(isNodeUsed);
2084
+ }
2085
+ return isNodeUsed(declaration);
2086
+ });
2087
+ }
2088
+ if (ts2.isExportDeclaration(node) && node.exportClause !== void 0 && ts2.isNamespaceExport(node.exportClause)) {
2089
+ return isNodeUsed(node.exportClause);
2090
+ }
2091
+ if (ts2.isImportClause(node) && node.namedBindings !== void 0) {
2092
+ return isNodeUsed(node.namedBindings);
2093
+ }
2094
+ return false;
2095
+ }
2096
+ function shouldNodeBeImported(node) {
2097
+ const nodeSymbol = (0, typescript_1.getNodeSymbol)(node, typeChecker);
2098
+ if (nodeSymbol === null) {
2099
+ return false;
2100
+ }
2101
+ return shouldSymbolBeImported(nodeSymbol);
2102
+ }
2103
+ function shouldSymbolBeImported(nodeSymbol) {
2104
+ const isSymbolDeclaredInDefaultLibrary = (0, typescript_1.getDeclarationsForSymbol)(nodeSymbol).some((declaration) => program.isSourceFileDefaultLibrary(declaration.getSourceFile()));
2105
+ if (isSymbolDeclaredInDefaultLibrary) {
2106
+ return false;
2107
+ }
2108
+ const symbolsDeclarations = (0, typescript_1.getDeclarationsForSymbol)(nodeSymbol);
2109
+ const shouldSymbolBeInlined = symbolsDeclarations.every(
2110
+ (decl) => (0, module_info_1.getModuleLikeModuleInfo)((0, typescript_1.getClosestSourceFileLikeNode)(decl), criteria, typeChecker).type === 0
2111
+ /* ModuleType.ShouldBeInlined */
2112
+ );
2113
+ if (shouldSymbolBeInlined) {
2114
+ return false;
2115
+ }
2116
+ return getExportedSymbolsUsingSymbol(nodeSymbol).length !== 0;
2117
+ }
2118
+ function getExportedSymbolsUsingStatement(node) {
2119
+ const nodeSymbol = (0, typescript_1.getNodeSymbol)(node, typeChecker);
2120
+ if (nodeSymbol === null) {
2121
+ return [];
2122
+ }
2123
+ return getExportedSymbolsUsingSymbol(nodeSymbol);
2124
+ }
2125
+ function getExportedSymbolsUsingSymbol(nodeSymbol) {
2126
+ const symbolsUsingNode = typesUsageEvaluator.getSymbolsUsingSymbol(nodeSymbol);
2127
+ if (symbolsUsingNode === null) {
2128
+ throw new Error(`Something went wrong - getSymbolsUsingSymbol returned null but expected to be a set of symbols (symbol=${nodeSymbol.name})`);
2129
+ }
2130
+ return [
2131
+ ...rootFileExportSymbols.includes(nodeSymbol) ? [nodeSymbol] : [],
2132
+ // symbols which are used in types directly
2133
+ ...getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolUsedByRootFileExports),
2134
+ // symbols which are used in global types i.e. in `declare global`s
2135
+ ...inlineDeclareGlobals ? getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolForGlobalDeclaration) : [],
2136
+ // symbols which are used in "declare module" types
2137
+ ...inlineDeclareExternals ? getInlinedSymbolsUsingSymbol(nodeSymbol, isSymbolForDeclareModuleDeclaration) : []
2138
+ ];
2139
+ }
2140
+ function areDeclarationSame(left, right) {
2141
+ const leftSymbols = (0, typescript_1.splitTransientSymbol)((0, typescript_1.getNodeSymbol)(left, typeChecker), typeChecker);
2142
+ const rightSymbols = (0, typescript_1.splitTransientSymbol)((0, typescript_1.getNodeSymbol)(right, typeChecker), typeChecker);
2143
+ for (const leftSymbol of leftSymbols) {
2144
+ if (rightSymbols.has(leftSymbol)) {
2145
+ return true;
2146
+ }
2147
+ }
2148
+ return false;
2149
+ }
2150
+ function createNamespaceForExports(exports2, namespaceSymbol) {
2151
+ function addSymbolToNamespaceExports(namespaceExports2, symbol) {
2152
+ if (!typesUsageEvaluator.isSymbolUsedBySymbol(symbol, namespaceSymbol)) {
2153
+ return;
2154
+ }
2155
+ const symbolKnownNames = collisionsResolver.namesForSymbol(symbol);
2156
+ if (symbolKnownNames.size === 0) {
2157
+ throw new Error(`Cannot get local names for symbol '${symbol.getName()}' while generating namespaced export`);
2158
+ }
2159
+ namespaceExports2.set(symbol.getName(), Array.from(symbolKnownNames)[0]);
2160
+ }
2161
+ function handleNamespacedImportOrExport(namespacedImportOrExport, namespaceExports2, symbol) {
2162
+ if (namespacedImportOrExport.moduleSpecifier === void 0) {
2163
+ return;
2164
+ }
2165
+ if (isReferencedModuleImportable(namespacedImportOrExport)) {
2166
+ addSymbolToNamespaceExports(namespaceExports2, symbol);
2167
+ return;
2168
+ }
2169
+ const referencedSourceFileSymbol = (0, typescript_1.getNodeOwnSymbol)(namespacedImportOrExport.moduleSpecifier, typeChecker);
2170
+ if (referencedSourceFileSymbol.exports === void 0) {
2171
+ return;
2172
+ }
2173
+ if (ts2.isImportDeclaration(namespacedImportOrExport) && referencedSourceFileSymbol.exports.has(ts2.InternalSymbolName.ExportEquals)) {
2174
+ return;
2175
+ }
2176
+ const localNamespaceName = createNamespaceForExports(referencedSourceFileSymbol.exports, symbol);
2177
+ if (localNamespaceName !== null) {
2178
+ namespaceExports2.set(symbol.getName(), localNamespaceName);
2179
+ }
2180
+ }
2181
+ function processExportSymbol(namespaceExports2, symbol) {
2182
+ if (symbol.escapedName === ts2.InternalSymbolName.ExportStar) {
2183
+ for (const exportStarDeclaration of (0, typescript_1.getSymbolExportStarDeclarations)(symbol)) {
2184
+ if (exportStarDeclaration.moduleSpecifier === void 0) {
2185
+ throw new Error(`Export star declaration does not have a module specifier '${exportStarDeclaration.getText()}'`);
2186
+ }
2187
+ if (isReferencedModuleImportable(exportStarDeclaration)) {
2188
+ throw new Error(`Having a re-export from an importable module as a part of namespaced export is not supported yet.`);
2189
+ }
2190
+ const referencedSourceFileSymbol = (0, typescript_1.getNodeOwnSymbol)(exportStarDeclaration.moduleSpecifier, typeChecker);
2191
+ referencedSourceFileSymbol.exports?.forEach(processExportSymbol.bind(null, namespaceExports2));
2192
+ }
2193
+ return;
2194
+ }
2195
+ symbol.declarations?.forEach((decl) => {
2196
+ if (ts2.isNamespaceExport(decl) && decl.parent.moduleSpecifier !== void 0) {
2197
+ handleNamespacedImportOrExport(decl.parent, namespaceExports2, symbol);
2198
+ return;
2199
+ }
2200
+ if (ts2.isExportSpecifier(decl)) {
2201
+ const exportElementSymbol = (0, typescript_1.getImportExportReferencedSymbol)(decl, typeChecker);
2202
+ const namespaceImport = (0, typescript_1.getDeclarationsForSymbol)(exportElementSymbol).find(ts2.isNamespaceImport);
2203
+ if (namespaceImport !== void 0) {
2204
+ handleNamespacedImportOrExport(namespaceImport.parent.parent, namespaceExports2, symbol);
2205
+ }
2206
+ return;
2207
+ }
2208
+ });
2209
+ addSymbolToNamespaceExports(namespaceExports2, symbol);
2210
+ }
2211
+ function getIdentifierOfNamespaceImportFromInlinedModule(nsSymbol) {
2212
+ for (const decl of (0, typescript_1.getDeclarationsForSymbol)(nsSymbol)) {
2213
+ if (!ts2.isNamespaceExport(decl) && !ts2.isExportSpecifier(decl) && !ts2.isNamespaceImport(decl)) {
2214
+ continue;
2215
+ }
2216
+ if (ts2.isNamespaceExport(decl) && !isReferencedModuleImportable(decl.parent)) {
2217
+ return decl.name;
2218
+ }
2219
+ if (ts2.isNamespaceImport(decl) && !isReferencedModuleImportable(decl.parent.parent)) {
2220
+ return decl.name;
2221
+ }
2222
+ if (ts2.isExportSpecifier(decl)) {
2223
+ if (decl.parent.parent.moduleSpecifier !== void 0) {
2224
+ if (isReferencedModuleImportable(decl.parent.parent)) {
2225
+ continue;
2226
+ }
2227
+ if (getIdentifierOfNamespaceImportFromInlinedModule((0, typescript_1.getImportExportReferencedSymbol)(decl, typeChecker))) {
2228
+ return decl.name;
2229
+ }
2230
+ }
2231
+ const result = (0, typescript_1.getDeclarationsForSymbol)((0, typescript_1.getImportExportReferencedSymbol)(decl, typeChecker)).some((importDecl) => {
2232
+ if (ts2.isNamespaceImport(importDecl)) {
2233
+ return !isReferencedModuleImportable(importDecl.parent.parent);
2234
+ }
2235
+ if (ts2.isImportSpecifier(importDecl)) {
2236
+ return getIdentifierOfNamespaceImportFromInlinedModule((0, typescript_1.getImportExportReferencedSymbol)(importDecl, typeChecker));
2237
+ }
2238
+ return false;
2239
+ });
2240
+ if (result) {
2241
+ return decl.name;
2242
+ }
2243
+ }
2244
+ }
2245
+ return null;
2246
+ }
2247
+ const namespaceNameIdentifier = getIdentifierOfNamespaceImportFromInlinedModule(namespaceSymbol);
2248
+ if (namespaceNameIdentifier === null) {
2249
+ return null;
2250
+ }
2251
+ const namespaceExports = /* @__PURE__ */ new Map();
2252
+ exports2.forEach(processExportSymbol.bind(null, namespaceExports));
2253
+ if (namespaceExports.size !== 0) {
2254
+ const namespaceLocalName = collisionsResolver.addTopLevelIdentifier(namespaceNameIdentifier);
2255
+ collectionResult.wrappedNamespaces.set(namespaceLocalName, namespaceExports);
2256
+ return namespaceLocalName;
2257
+ }
2258
+ return null;
2259
+ }
2260
+ function syncExports() {
2261
+ for (const exp of rootFileExports) {
2262
+ if (exp.type === 0) {
2263
+ continue;
2264
+ }
2265
+ const namespaceLocalName = exp.symbol.flags & ts2.SymbolFlags.ValueModule && exp.symbol.exports !== void 0 ? createNamespaceForExports(exp.symbol.exports, exp.originalSymbol) : null;
2266
+ if (namespaceLocalName !== null) {
2267
+ collectionResult.renamedExports.set(exp.exportedName, namespaceLocalName);
2268
+ }
2269
+ const symbolKnownNames = collisionsResolver.namesForSymbol(exp.symbol);
2270
+ if (symbolKnownNames.size === 0) {
2271
+ continue;
2272
+ }
2273
+ if (symbolKnownNames.has(exp.exportedName)) {
2274
+ if (shouldSymbolBeImported(exp.symbol)) {
2275
+ collectionResult.renamedExports.set(exp.exportedName, exp.exportedName);
2276
+ }
2277
+ continue;
2278
+ }
2279
+ collectionResult.renamedExports.set(exp.exportedName, Array.from(symbolKnownNames)[0]);
2280
+ }
2281
+ }
2282
+ for (const sourceFile of sourceFiles) {
2283
+ (0, logger_1.verboseLog)(`======= Processing ${sourceFile.fileName} =======`);
2284
+ const updateFn = sourceFile === rootSourceFile ? updateResultForRootModule : updateResultForAnyModule;
2285
+ const currentModule = (0, module_info_1.getFileModuleInfo)(sourceFile.fileName, criteria);
2286
+ updateFn(sourceFile.statements, currentModule);
2287
+ if (isNodeUsed(sourceFile)) {
2288
+ switch (currentModule.type) {
2289
+ case 1: {
2290
+ updateImportsForStatement(sourceFile);
2291
+ break;
2292
+ }
2293
+ case 0: {
2294
+ const sourceFileSymbol = (0, typescript_1.getNodeSymbol)(sourceFile, typeChecker);
2295
+ if (sourceFileSymbol === null || sourceFileSymbol.exports === void 0) {
2296
+ throw new Error(`Cannot find symbol or exports for source file ${sourceFile.fileName}`);
2297
+ }
2298
+ let namespaceIdentifier = null;
2299
+ forEachImportOfStatement(sourceFile, (imp) => {
2300
+ if (ts2.isNamespaceExport(imp) || ts2.isNamespaceImport(imp)) {
2301
+ namespaceIdentifier = imp.name;
2302
+ }
2303
+ });
2304
+ if (namespaceIdentifier === null) {
2305
+ break;
2306
+ }
2307
+ createNamespaceForExports(sourceFileSymbol.exports, (0, typescript_1.getNodeOwnSymbol)(namespaceIdentifier, typeChecker));
2308
+ break;
2309
+ }
2310
+ }
2311
+ }
2312
+ }
2313
+ if (entryConfig.failOnClass) {
2314
+ const classes = collectionResult.statements.filter(ts2.isClassDeclaration);
2315
+ if (classes.length !== 0) {
2316
+ const classesNames = classes.map((c) => c.name === void 0 ? "anonymous class" : c.name.text);
2317
+ throw new Error(`${classes.length} class statement(s) are found in generated dts: ${classesNames.join(", ")}`);
2318
+ }
2319
+ }
2320
+ syncExports();
2321
+ const exportReferencedTypes = outputOptions.exportReferencedTypes !== false;
2322
+ function isExportedWithLocalName(namedDeclaration, exportedName) {
2323
+ const nodeName = (0, typescript_1.getNodeName)(namedDeclaration);
2324
+ if (nodeName === void 0) {
2325
+ throw new Error(`Cannot find node name ${namedDeclaration.getText()}`);
2326
+ }
2327
+ return collisionsResolver.resolveReferencedIdentifier(nodeName) === exportedName;
2328
+ }
2329
+ const renamedAndNotExplicitlyExportedTypes = [];
2330
+ const output = (0, generate_output_1.generateOutput)({
2331
+ ...collectionResult,
2332
+ resolveIdentifierName: (identifier) => {
2333
+ if (ts2.isPropertyAccessOrQualifiedName(identifier)) {
2334
+ return collisionsResolver.resolveReferencedQualifiedName(identifier);
2335
+ } else {
2336
+ return collisionsResolver.resolveReferencedIdentifier(identifier);
2337
+ }
2338
+ },
2339
+ // eslint-disable-next-line complexity
2340
+ getStatementSettings: (statement) => {
2341
+ if ((0, typescript_1.isAmbientModule)(statement) || ts2.isExportDeclaration(statement)) {
2342
+ return { shouldHaveExportKeyword: false, shouldHaveJSDoc: true };
2343
+ }
2344
+ const statementExports = (0, typescript_1.getExportsForStatement)(rootFileExports, typeChecker, statement);
2345
+ const isExplicitlyExportedWithOriginalName = statementExports.find((exp) => {
2346
+ if (ts2.isVariableStatement(statement)) {
2347
+ for (const variableDeclaration of statement.declarationList.declarations) {
2348
+ if (ts2.isIdentifier(variableDeclaration.name)) {
2349
+ const resolvedName = collisionsResolver.resolveReferencedIdentifier(variableDeclaration.name);
2350
+ if (exp.exportedName === resolvedName) {
2351
+ return true;
2352
+ }
2353
+ continue;
2354
+ }
2355
+ (0, logger_1.warnLog)(`Unhandled variable identifier type detected (${ts2.SyntaxKind[variableDeclaration.name.kind]}). Please report this issue to https://github.com/timocov/dts-bundle-generator`);
2356
+ }
2357
+ return false;
2358
+ }
2359
+ return (0, typescript_1.isNodeNamedDeclaration)(statement) && isExportedWithLocalName(statement, exp.exportedName);
2360
+ }) !== void 0;
2361
+ const onlyExplicitlyExportedShouldBeExported = !exportReferencedTypes || ts2.isClassDeclaration(statement) || ts2.isEnumDeclaration(statement) && !(0, typescript_1.hasNodeModifier)(statement, ts2.SyntaxKind.ConstKeyword) || ts2.isFunctionDeclaration(statement) || ts2.isVariableStatement(statement) || ts2.isModuleDeclaration(statement);
2362
+ if (onlyExplicitlyExportedShouldBeExported) {
2363
+ return { shouldHaveExportKeyword: isExplicitlyExportedWithOriginalName, shouldHaveJSDoc: statementExports.length !== 0 };
2364
+ }
2365
+ if ((0, typescript_1.isNodeNamedDeclaration)(statement) && !isExportedWithLocalName(statement, (0, typescript_1.getNodeName)(statement).getText())) {
2366
+ renamedAndNotExplicitlyExportedTypes.push(statement);
2367
+ return { shouldHaveExportKeyword: false, shouldHaveJSDoc: statementExports.length !== 0 };
2368
+ }
2369
+ return { shouldHaveExportKeyword: isExplicitlyExportedWithOriginalName || statementExports.length === 0, shouldHaveJSDoc: true };
2370
+ },
2371
+ needStripConstFromConstEnum: (constEnum) => {
2372
+ if (!program.getCompilerOptions().preserveConstEnums || !outputOptions.respectPreserveConstEnum) {
2373
+ return false;
2374
+ }
2375
+ const enumSymbol = (0, typescript_1.getNodeSymbol)(constEnum, typeChecker);
2376
+ if (enumSymbol === null) {
2377
+ return false;
2378
+ }
2379
+ return rootFileExportSymbols.includes(enumSymbol);
2380
+ },
2381
+ needStripImportFromImportTypeNode: (node) => {
2382
+ if (node.qualifier === void 0) {
2383
+ return false;
2384
+ }
2385
+ if (!ts2.isLiteralTypeNode(node.argument) || !ts2.isStringLiteral(node.argument.literal)) {
2386
+ return false;
2387
+ }
2388
+ return (0, module_info_1.getReferencedModuleInfo)(node, criteria, typeChecker)?.type === 0;
2389
+ }
2390
+ }, {
2391
+ sortStatements: outputOptions.sortNodes,
2392
+ umdModuleName: outputOptions.umdModuleName,
2393
+ noBanner: outputOptions.noBanner
2394
+ });
2395
+ if (renamedAndNotExplicitlyExportedTypes.length !== 0) {
2396
+ (0, logger_1.warnLog)(`The following type nodes were renamed because of the name collisions and will not be exported from the generated bundle:
2397
+ - ${// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2398
+ renamedAndNotExplicitlyExportedTypes.map((node) => `${(0, typescript_1.getNodeName)(node).getText()} (from ${node.getSourceFile().fileName})`).join("\n- ")}${"\n"}This might lead to unpredictable and unexpected output, and possible breaking changes to your API.${"\n"}Consider either (re-)exporting them explicitly from the entry point, or disable --export-referenced-types option ('output.exportReferencedTypes' in the config).`);
2399
+ }
2400
+ return output;
2401
+ });
2402
+ }
2403
+ exports.generateDtsBundle = generateDtsBundle2;
2404
+ }
2405
+ });
2406
+
2407
+ // src/compiler/declarations.ts
2408
+ var import_dts_bundle_generator = __toESM(require_bundle_generator(), 1);
2
2409
  import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3
2410
  import os from "node:os";
4
2411
  import path from "node:path";
5
2412
  import ts from "typescript";
6
2413
  import { ActorDefinitionError } from "../errors.js";
7
- class DeclarationCompiler {
8
- system;
9
- constructor(system = ts.sys) {
10
- this.system = system;
2414
+ var DeclarationCompiler = class {
2415
+ constructor(system = ts.sys) {
2416
+ this.system = system;
2417
+ }
2418
+ system;
2419
+ compile(program, actors, contracts) {
2420
+ const directory = mkdtempSync(path.join(os.tmpdir(), "actor-declarations-"));
2421
+ try {
2422
+ return this.bundle(directory, program, actors, contracts);
2423
+ } finally {
2424
+ rmSync(directory, { recursive: true, force: true });
11
2425
  }
12
- compile(program, actors, contracts) {
13
- const directory = mkdtempSync(path.join(os.tmpdir(), "actor-declarations-"));
14
- try {
15
- return this.bundle(directory, program, actors, contracts);
2426
+ }
2427
+ bundle(directory, program, actors, contracts) {
2428
+ const packages = /* @__PURE__ */ new Map();
2429
+ const entry = this.writeActors(directory, program, actors, contracts, packages);
2430
+ const config = writeBundleConfig(directory, program.getCompilerOptions(), packages);
2431
+ const [declarations] = (0, import_dts_bundle_generator.generateDtsBundle)(
2432
+ [
2433
+ {
2434
+ filePath: entry,
2435
+ libraries: { inlinedLibraries: ["durable-actors"] },
2436
+ output: { noBanner: true, exportReferencedTypes: false, sortNodes: true }
16
2437
  }
17
- finally {
18
- rmSync(directory, { recursive: true, force: true });
19
- }
20
- }
21
- bundle(directory, program, actors, contracts) {
22
- const packages = new Map();
23
- const entry = this.writeActors(directory, program, actors, contracts, packages);
24
- const config = writeBundleConfig(directory, program.getCompilerOptions(), packages);
25
- const [declarations] = generateDtsBundle([
26
- {
27
- filePath: entry,
28
- libraries: { inlinedLibraries: ["durable-actors"] },
29
- output: { noBanner: true, exportReferencedTypes: false, sortNodes: true }
30
- }
31
- ], { preferredConfigPath: config });
32
- const dependencies = Object.fromEntries(externalModules(declarations)
33
- .map(specifier => {
34
- const name = packageName(specifier);
35
- const pkg = packages.get(name) ??
36
- findPackage(specifier, program.getRootFileNames()[0], program.getCompilerOptions(), this.system);
37
- return [name, pkg.version];
38
- })
39
- .sort(([left], [right]) => left.localeCompare(right)));
40
- return { declarations, dependencies };
41
- }
42
- writeActors(directory, program, actors, contracts, packages) {
43
- const files = emitDeclarations(program, this.system);
44
- const imports = [];
45
- const properties = [];
46
- for (const [index, contract] of contracts.entries()) {
47
- const actor = actors.find(actor => actor.name.text === contract.actorName);
48
- const source = actor.getSourceFile();
49
- const emitted = files.get(source.fileName);
50
- const projected = projectActor(emitted, actor, contract, program.getTypeChecker());
51
- const file = path.join(directory, `actor-${index}.d.ts`);
52
- const code = resolveImports(projected.code, source.fileName, program.getCompilerOptions(), this.system, packages);
53
- writeFileSync(file, code);
54
- imports.push(`import type { ${projected.name} as Actor${index} } from "./actor-${index}.js"`);
55
- properties.push(`${JSON.stringify(contract.actorName)}: Actor${index}`);
56
- }
57
- const entry = path.join(directory, "index.d.ts");
58
- writeFileSync(entry, `${imports.join("\n")}\nexport interface ActorTypes { ${properties.join(";\n")} }`);
59
- return entry;
2438
+ ],
2439
+ { preferredConfigPath: config }
2440
+ );
2441
+ const dependencies = Object.fromEntries(
2442
+ externalModules(declarations).map((specifier) => {
2443
+ const name = packageName(specifier);
2444
+ const pkg = packages.get(name) ?? findPackage(specifier, program.getRootFileNames()[0], program.getCompilerOptions(), this.system);
2445
+ return [name, pkg.version];
2446
+ }).sort(([left], [right]) => left.localeCompare(right))
2447
+ );
2448
+ return { declarations, dependencies };
2449
+ }
2450
+ writeActors(directory, program, actors, contracts, packages) {
2451
+ const files = emitDeclarations(program, this.system);
2452
+ const imports = [];
2453
+ const properties = [];
2454
+ for (const [index, contract] of contracts.entries()) {
2455
+ const actor = actors.find((actor2) => actor2.name.text === contract.actorName);
2456
+ const source = actor.getSourceFile();
2457
+ const emitted = files.get(source.fileName);
2458
+ const projected = projectActor(emitted, actor, contract, program.getTypeChecker());
2459
+ const file = path.join(directory, `actor-${index}.d.ts`);
2460
+ const code = resolveImports(
2461
+ projected.code,
2462
+ source.fileName,
2463
+ program.getCompilerOptions(),
2464
+ this.system,
2465
+ packages
2466
+ );
2467
+ writeFileSync(file, code);
2468
+ imports.push(`import type { ${projected.name} as Actor${index} } from "./actor-${index}.js"`);
2469
+ properties.push(`${JSON.stringify(contract.actorName)}: Actor${index}`);
60
2470
  }
61
- }
2471
+ const entry = path.join(directory, "index.d.ts");
2472
+ writeFileSync(entry, `${imports.join("\n")}
2473
+ export interface ActorTypes { ${properties.join(";\n")} }`);
2474
+ return entry;
2475
+ }
2476
+ };
62
2477
  function writeBundleConfig(directory, options, packages) {
63
- for (const [name, pkg] of packages) {
64
- const link = path.join(directory, "node_modules", name);
65
- mkdirSync(path.dirname(link), { recursive: true });
66
- symlinkSync(pkg.directory, link, "dir");
67
- }
68
- const config = path.join(directory, "tsconfig.json");
69
- writeFileSync(config, JSON.stringify({
70
- compilerOptions: {
71
- target: "ES2022",
72
- module: "NodeNext",
73
- strict: true,
74
- skipLibCheck: true,
75
- baseUrl: options.baseUrl ?? options.pathsBasePath,
76
- paths: options.paths,
77
- exactOptionalPropertyTypes: options.exactOptionalPropertyTypes ?? false,
78
- types: []
79
- }
80
- }));
81
- writeFileSync(path.join(directory, "package.json"), '{"type":"module"}');
82
- return config;
2478
+ for (const [name, pkg] of packages) {
2479
+ const link = path.join(directory, "node_modules", name);
2480
+ mkdirSync(path.dirname(link), { recursive: true });
2481
+ symlinkSync(pkg.directory, link, "dir");
2482
+ }
2483
+ const config = path.join(directory, "tsconfig.json");
2484
+ writeFileSync(
2485
+ config,
2486
+ JSON.stringify({
2487
+ compilerOptions: {
2488
+ target: "ES2022",
2489
+ module: "NodeNext",
2490
+ strict: true,
2491
+ skipLibCheck: true,
2492
+ baseUrl: options.baseUrl ?? options.pathsBasePath,
2493
+ paths: options.paths,
2494
+ exactOptionalPropertyTypes: options.exactOptionalPropertyTypes ?? false,
2495
+ types: []
2496
+ }
2497
+ })
2498
+ );
2499
+ writeFileSync(path.join(directory, "package.json"), '{"type":"module"}');
2500
+ return config;
83
2501
  }
84
2502
  function emitDeclarations(program, system) {
85
- const options = {
86
- ...program.getCompilerOptions(),
87
- noEmit: false,
88
- declaration: true,
89
- declarationMap: false,
90
- emitDeclarationOnly: true,
91
- outDir: undefined,
92
- outFile: undefined,
93
- incremental: false,
94
- composite: false
95
- };
96
- const host = ts.createCompilerHost(options);
97
- host.readFile = file => program.getSourceFile(file)?.text ?? system.readFile(file);
98
- host.fileExists = system.fileExists;
99
- const emitter = ts.createProgram(program.getRootFileNames(), options, host, program);
100
- const files = new Map();
101
- const result = emitter.emit(undefined, (_file, text, _bom, _error, sources) => {
102
- if (sources?.length === 1)
103
- files.set(sources[0].fileName, text);
104
- }, undefined, true);
105
- if (result.diagnostics.length)
106
- throw new ActorDefinitionError(result.diagnostics.map(d => ts.flattenDiagnosticMessageText(d.messageText, "\n")).join("\n"));
107
- return files;
2503
+ const options = {
2504
+ ...program.getCompilerOptions(),
2505
+ noEmit: false,
2506
+ declaration: true,
2507
+ declarationMap: false,
2508
+ emitDeclarationOnly: true,
2509
+ outDir: void 0,
2510
+ outFile: void 0,
2511
+ incremental: false,
2512
+ composite: false
2513
+ };
2514
+ const host = ts.createCompilerHost(options);
2515
+ host.readFile = (file) => program.getSourceFile(file)?.text ?? system.readFile(file);
2516
+ host.fileExists = system.fileExists;
2517
+ const emitter = ts.createProgram(program.getRootFileNames(), options, host, program);
2518
+ const files = /* @__PURE__ */ new Map();
2519
+ const result = emitter.emit(
2520
+ void 0,
2521
+ (_file, text, _bom, _error, sources) => {
2522
+ if (sources?.length === 1) files.set(sources[0].fileName, text);
2523
+ },
2524
+ void 0,
2525
+ true
2526
+ );
2527
+ if (result.diagnostics.length)
2528
+ throw new ActorDefinitionError(
2529
+ result.diagnostics.map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n")).join("\n")
2530
+ );
2531
+ return files;
108
2532
  }
109
2533
  function projectActor(text, actor, contract, checker) {
110
- const source = ts.createSourceFile("actor.d.ts", text, ts.ScriptTarget.Latest, true);
111
- const declaration = source.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === actor.name.text);
112
- const instance = checker.getTypeAtLocation(actor);
113
- const types = checker.getTypeArguments(instance.getBaseTypes()[0]);
114
- const declaredTypes = declaration.heritageClauses?.find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword)
115
- ?.types[0].typeArguments;
116
- const name = availableName(source, `$${contract.actorName}Contract`);
117
- const properties = ["Metadata", "Incoming", "Outgoing"].map((kind, index) => ts.factory.createPropertySignature(undefined, kind, undefined, declaredTypes?.[index] ??
118
- checker.typeToTypeNode(types[index], undefined, ts.NodeBuilderFlags.NoTruncation | ts.NodeBuilderFlags.UseFullyQualifiedType)));
119
- properties.push(ts.factory.createPropertySignature(undefined, "State", undefined, publicState(declaration, contract)));
120
- properties.push(ts.factory.createPropertySignature(undefined, "Methods", undefined, publicMethods(declaration, contract)));
121
- const root = ts.factory.createInterfaceDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], name, undefined, undefined, properties);
122
- return {
123
- name,
124
- code: ts.createPrinter().printFile(ts.factory.updateSourceFile(source, [...source.statements, root]))
125
- };
2534
+ const source = ts.createSourceFile("actor.d.ts", text, ts.ScriptTarget.Latest, true);
2535
+ const declaration = source.statements.find(
2536
+ (statement) => ts.isClassDeclaration(statement) && statement.name?.text === actor.name.text
2537
+ );
2538
+ const instance = checker.getTypeAtLocation(actor);
2539
+ const types = checker.getTypeArguments(instance.getBaseTypes()[0]);
2540
+ const declaredTypes = declaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword)?.types[0].typeArguments;
2541
+ const name = availableName(source, `$${contract.actorName}Contract`);
2542
+ const properties = ["Metadata", "Incoming", "Outgoing"].map(
2543
+ (kind, index) => ts.factory.createPropertySignature(
2544
+ void 0,
2545
+ kind,
2546
+ void 0,
2547
+ declaredTypes?.[index] ?? checker.typeToTypeNode(
2548
+ types[index],
2549
+ void 0,
2550
+ ts.NodeBuilderFlags.NoTruncation | ts.NodeBuilderFlags.UseFullyQualifiedType
2551
+ )
2552
+ )
2553
+ );
2554
+ properties.push(
2555
+ ts.factory.createPropertySignature(void 0, "State", void 0, publicState(declaration, contract))
2556
+ );
2557
+ properties.push(
2558
+ ts.factory.createPropertySignature(void 0, "Methods", void 0, publicMethods(declaration, contract))
2559
+ );
2560
+ const root = ts.factory.createInterfaceDeclaration(
2561
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
2562
+ name,
2563
+ void 0,
2564
+ void 0,
2565
+ properties
2566
+ );
2567
+ return {
2568
+ name,
2569
+ code: ts.createPrinter().printFile(ts.factory.updateSourceFile(source, [...source.statements, root]))
2570
+ };
126
2571
  }
127
2572
  function publicState(declaration, contract) {
128
- const state = declaration.members.filter(member => ts.isPropertyDeclaration(member) &&
129
- Object.hasOwn(contract.socket.schema.definitions.State.properties, propertyName(member.name)));
130
- return ts.factory.createTypeLiteralNode(state.map(member => ts.factory.createPropertySignature(member.modifiers?.filter(m => m.kind === ts.SyntaxKind.ReadonlyKeyword), member.name, member.questionToken, member.type)));
2573
+ const state = declaration.members.filter(
2574
+ (member) => ts.isPropertyDeclaration(member) && Object.hasOwn(
2575
+ contract.socket.schema.definitions.State.properties,
2576
+ propertyName(member.name)
2577
+ )
2578
+ );
2579
+ return ts.factory.createTypeLiteralNode(
2580
+ state.map(
2581
+ (member) => ts.factory.createPropertySignature(
2582
+ member.modifiers?.filter((m) => m.kind === ts.SyntaxKind.ReadonlyKeyword),
2583
+ member.name,
2584
+ member.questionToken,
2585
+ member.type
2586
+ )
2587
+ )
2588
+ );
131
2589
  }
132
2590
  function publicMethods(declaration, contract) {
133
- const members = declaration.members.filter(member => ts.isMethodDeclaration(member) &&
134
- contract.rpc.methods.some(method => method.name === propertyName(member.name)));
135
- return ts.factory.createTypeLiteralNode(members
136
- .sort((a, b) => propertyName(a.name).localeCompare(propertyName(b.name)))
137
- .map(member => ts.factory.createMethodSignature(undefined, member.name, member.questionToken, member.typeParameters, member.parameters, member.type)));
2591
+ const members = declaration.members.filter(
2592
+ (member) => ts.isMethodDeclaration(member) && contract.rpc.methods.some((method) => method.name === propertyName(member.name))
2593
+ );
2594
+ return ts.factory.createTypeLiteralNode(
2595
+ members.sort((a, b) => propertyName(a.name).localeCompare(propertyName(b.name))).map(
2596
+ (member) => ts.factory.createMethodSignature(
2597
+ void 0,
2598
+ member.name,
2599
+ member.questionToken,
2600
+ member.typeParameters,
2601
+ member.parameters,
2602
+ member.type
2603
+ )
2604
+ )
2605
+ );
138
2606
  }
139
2607
  function availableName(source, proposed) {
140
- let name = proposed;
141
- while (source.text.includes(name))
142
- name += "_";
143
- return name;
2608
+ let name = proposed;
2609
+ while (source.text.includes(name)) name += "_";
2610
+ return name;
144
2611
  }
145
2612
  function propertyName(name) {
146
- if (ts.isComputedPropertyName(name) && ts.isStringLiteral(name.expression))
147
- return name.expression.text;
148
- return ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name) ? name.text : name.getText();
2613
+ if (ts.isComputedPropertyName(name) && ts.isStringLiteral(name.expression)) return name.expression.text;
2614
+ return ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name) ? name.text : name.getText();
149
2615
  }
150
2616
  function resolveImports(text, location, options, system, packages) {
151
- const source = ts.createSourceFile("actor.d.ts", text, ts.ScriptTarget.Latest, true);
152
- const result = ts.transform(source, [
153
- context => root => ts.visitNode(root, function visit(node) {
154
- if (ts.isStringLiteral(node) && isModuleSpecifier(node)) {
155
- const resolved = ts.resolveModuleName(node.text, location, options, system).resolvedModule;
156
- if (!resolved)
157
- throw new ActorDefinitionError(`Cannot resolve public type dependency ${node.text}`);
158
- if (node.text.startsWith(".") || path.isAbsolute(node.text) || !resolved.isExternalLibraryImport)
159
- return ts.factory.createStringLiteral(resolved.resolvedFileName);
160
- const name = packageName(node.text);
161
- packages.set(name, packageAt(resolved.resolvedFileName, name, system));
162
- }
163
- return ts.visitEachChild(node, visit, context);
164
- })
165
- ]);
166
- const code = ts.createPrinter().printFile(result.transformed[0]);
167
- result.dispose();
168
- return code;
2617
+ const source = ts.createSourceFile("actor.d.ts", text, ts.ScriptTarget.Latest, true);
2618
+ const result = ts.transform(source, [
2619
+ (context) => (root) => ts.visitNode(root, function visit(node) {
2620
+ if (ts.isStringLiteral(node) && isModuleSpecifier(node)) {
2621
+ const resolved = ts.resolveModuleName(node.text, location, options, system).resolvedModule;
2622
+ if (!resolved) throw new ActorDefinitionError(`Cannot resolve public type dependency ${node.text}`);
2623
+ if (node.text.startsWith(".") || path.isAbsolute(node.text) || !resolved.isExternalLibraryImport)
2624
+ return ts.factory.createStringLiteral(resolved.resolvedFileName);
2625
+ const name = packageName(node.text);
2626
+ packages.set(name, packageAt(resolved.resolvedFileName, name, system));
2627
+ }
2628
+ return ts.visitEachChild(node, visit, context);
2629
+ })
2630
+ ]);
2631
+ const code = ts.createPrinter().printFile(result.transformed[0]);
2632
+ result.dispose();
2633
+ return code;
169
2634
  }
170
2635
  function isModuleSpecifier(node) {
171
- const parent = node.parent;
172
- return (((ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent)) && parent.moduleSpecifier === node) ||
173
- (ts.isLiteralTypeNode(parent) && ts.isImportTypeNode(parent.parent)));
2636
+ const parent = node.parent;
2637
+ return (ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent)) && parent.moduleSpecifier === node || ts.isLiteralTypeNode(parent) && ts.isImportTypeNode(parent.parent);
174
2638
  }
175
2639
  function externalModules(code) {
176
- const source = ts.createSourceFile("types.d.ts", code, ts.ScriptTarget.Latest, true);
177
- const names = new Set(source.typeReferenceDirectives.map(ref => ref.fileName.startsWith("@types/") ? ref.fileName : `@types/${ref.fileName}`));
178
- const visit = (node) => {
179
- if (ts.isStringLiteral(node) && isModuleSpecifier(node)) {
180
- if (node.text.startsWith(".") || path.isAbsolute(node.text))
181
- throw new ActorDefinitionError(`Unbundled public type dependency ${node.text}`);
182
- if (!node.text.startsWith("node:"))
183
- names.add(node.text);
184
- }
185
- ts.forEachChild(node, visit);
186
- };
187
- visit(source);
188
- return [...names].sort();
2640
+ const source = ts.createSourceFile("types.d.ts", code, ts.ScriptTarget.Latest, true);
2641
+ const names = new Set(
2642
+ source.typeReferenceDirectives.map(
2643
+ (ref) => ref.fileName.startsWith("@types/") ? ref.fileName : `@types/${ref.fileName}`
2644
+ )
2645
+ );
2646
+ const visit = (node) => {
2647
+ if (ts.isStringLiteral(node) && isModuleSpecifier(node)) {
2648
+ if (node.text.startsWith(".") || path.isAbsolute(node.text))
2649
+ throw new ActorDefinitionError(`Unbundled public type dependency ${node.text}`);
2650
+ if (!node.text.startsWith("node:")) names.add(node.text);
2651
+ }
2652
+ ts.forEachChild(node, visit);
2653
+ };
2654
+ visit(source);
2655
+ return [...names].sort();
189
2656
  }
190
2657
  function packageName(specifier) {
191
- return specifier
192
- .split("/")
193
- .slice(0, specifier.startsWith("@") ? 2 : 1)
194
- .join("/");
2658
+ return specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
195
2659
  }
196
2660
  function findPackage(specifier, location, options, system) {
197
- const resolved = ts.resolveModuleName(specifier, location, options, system).resolvedModule;
198
- if (!resolved)
199
- throw new ActorDefinitionError(`Cannot resolve public type dependency ${specifier}`);
200
- return packageAt(resolved.resolvedFileName, packageName(specifier), system);
2661
+ const resolved = ts.resolveModuleName(specifier, location, options, system).resolvedModule;
2662
+ if (!resolved) throw new ActorDefinitionError(`Cannot resolve public type dependency ${specifier}`);
2663
+ return packageAt(resolved.resolvedFileName, packageName(specifier), system);
201
2664
  }
202
2665
  function packageAt(file, name, system) {
203
- for (let directory = path.dirname(file);; directory = path.dirname(directory)) {
204
- const manifest = system.readFile(path.join(directory, "package.json"));
205
- if (manifest) {
206
- const json = JSON.parse(manifest);
207
- if (json.name === name || directory.endsWith(`${path.sep}${name}`)) {
208
- if (typeof json.version !== "string")
209
- throw new ActorDefinitionError(`Public type dependency ${name} must declare a version`);
210
- return { directory, version: json.version };
211
- }
212
- }
213
- if (directory === path.dirname(directory))
214
- throw new ActorDefinitionError(`Cannot find package metadata for ${name}`);
2666
+ for (let directory = path.dirname(file); ; directory = path.dirname(directory)) {
2667
+ const manifest = system.readFile(path.join(directory, "package.json"));
2668
+ if (manifest) {
2669
+ const json = JSON.parse(manifest);
2670
+ if (json.name === name || directory.endsWith(`${path.sep}${name}`)) {
2671
+ if (typeof json.version !== "string")
2672
+ throw new ActorDefinitionError(`Public type dependency ${name} must declare a version`);
2673
+ return { directory, version: json.version };
2674
+ }
215
2675
  }
2676
+ if (directory === path.dirname(directory))
2677
+ throw new ActorDefinitionError(`Cannot find package metadata for ${name}`);
2678
+ }
216
2679
  }
217
- export { DeclarationCompiler };
218
- //# sourceMappingURL=declarations.js.map
2680
+ export {
2681
+ DeclarationCompiler
2682
+ };
2683
+ //# sourceMappingURL=declarations.js.map