seedcord 0.19.5 → 0.21.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.
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-
|
|
1
|
+
import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-CZ2Lqriy.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { Command } from "@commander-js/extra-typings";
|
|
4
4
|
import { LEVEL_COLOR, Logger, LoggerChannelRegistry } from "@seedcord/logger";
|
|
@@ -10,7 +10,6 @@ import { BRAND, SeedcordError, validateDiscordToken } from "@seedcord/errors/int
|
|
|
10
10
|
import { delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import { createJiti } from "jiti";
|
|
13
|
-
import { tsImport } from "tsx/esm/api";
|
|
14
13
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
15
14
|
import { spawn } from "node:child_process";
|
|
16
15
|
import "reflect-metadata";
|
|
@@ -221,45 +220,34 @@ const TS_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
221
220
|
".mts",
|
|
222
221
|
".cts"
|
|
223
222
|
]);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
const EXTENSIONS = [
|
|
224
|
+
...TS_EXTENSIONS,
|
|
225
|
+
".js",
|
|
226
|
+
".mjs",
|
|
227
|
+
".cjs"
|
|
228
|
+
];
|
|
229
|
+
function jitiFor(entryPath) {
|
|
230
|
+
return createJiti(pathToFileURL(entryPath).href, {
|
|
227
231
|
cache: false,
|
|
228
232
|
interopDefault: true,
|
|
229
|
-
extensions:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
".mts",
|
|
233
|
-
".cts",
|
|
234
|
-
".js",
|
|
235
|
-
".mjs",
|
|
236
|
-
".cjs"
|
|
237
|
-
]
|
|
233
|
+
extensions: EXTENSIONS,
|
|
234
|
+
tsconfigPaths: true,
|
|
235
|
+
jsx: true
|
|
238
236
|
});
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
237
|
+
}
|
|
238
|
+
var RuntimeModuleLoader = class {
|
|
242
239
|
async importModule(entryPath) {
|
|
243
240
|
const normalized = resolve(entryPath);
|
|
244
241
|
if (!existsSync(normalized)) throw new SeedcordError(SeedcordErrorCode.CliEntryNotFound, [normalized]);
|
|
245
|
-
if (
|
|
242
|
+
if (TS_EXTENSIONS.has(extname(normalized).toLowerCase())) return this.importTypeScript(normalized);
|
|
246
243
|
return this.importWithNode(normalized);
|
|
247
244
|
}
|
|
248
|
-
|
|
249
|
-
if (this.options.forceTsx) return true;
|
|
250
|
-
return TS_EXTENSIONS.has(extname(filePath).toLowerCase());
|
|
251
|
-
}
|
|
252
|
-
async importWithTsx(entryPath) {
|
|
253
|
-
const specifier = pathToFileURL(entryPath).href;
|
|
254
|
-
const tsconfig = this.resolveTsconfig(entryPath);
|
|
245
|
+
async importTypeScript(entryPath) {
|
|
255
246
|
try {
|
|
256
|
-
return await
|
|
257
|
-
parentURL: import.meta.url,
|
|
258
|
-
tsconfig
|
|
259
|
-
});
|
|
247
|
+
return await jitiFor(entryPath).import(entryPath);
|
|
260
248
|
} catch (error) {
|
|
261
|
-
const reason = Error.isError(error) ? error.message : "Unknown
|
|
262
|
-
throw new SeedcordError(SeedcordErrorCode.
|
|
249
|
+
const reason = Error.isError(error) ? error.message : "Unknown jiti error";
|
|
250
|
+
throw new SeedcordError(SeedcordErrorCode.CliTsImportFailed, [entryPath, reason]);
|
|
263
251
|
}
|
|
264
252
|
}
|
|
265
253
|
async importWithNode(entryPath) {
|
|
@@ -268,7 +256,7 @@ var RuntimeModuleLoader = class {
|
|
|
268
256
|
return await import(specifier);
|
|
269
257
|
} catch (nativeError) {
|
|
270
258
|
try {
|
|
271
|
-
return await
|
|
259
|
+
return await jitiFor(entryPath).import(entryPath);
|
|
272
260
|
} catch (fallbackError) {
|
|
273
261
|
const nativeReason = Error.isError(nativeError) ? nativeError.message : "Unknown ESM import error";
|
|
274
262
|
const fallbackReason = Error.isError(fallbackError) ? fallbackError.message : "Unknown jiti error";
|
|
@@ -280,17 +268,6 @@ var RuntimeModuleLoader = class {
|
|
|
280
268
|
}
|
|
281
269
|
}
|
|
282
270
|
}
|
|
283
|
-
resolveTsconfig(entryPath) {
|
|
284
|
-
if (this.options.tsconfig !== void 0) return this.options.tsconfig;
|
|
285
|
-
return this.findNearestTsconfig(dirname(entryPath)) ?? false;
|
|
286
|
-
}
|
|
287
|
-
findNearestTsconfig(startDir) {
|
|
288
|
-
const candidate = resolve(startDir, "tsconfig.json");
|
|
289
|
-
if (existsSync(candidate)) return candidate;
|
|
290
|
-
const parent = dirname(startDir);
|
|
291
|
-
if (parent === startDir) return void 0;
|
|
292
|
-
return this.findNearestTsconfig(parent);
|
|
293
|
-
}
|
|
294
271
|
};
|
|
295
272
|
|
|
296
273
|
//#endregion
|
|
@@ -640,12 +617,18 @@ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
640
617
|
const CONTROL_CHAR = 32;
|
|
641
618
|
const HEX_RADIX = 16;
|
|
642
619
|
function renderAugmentation(registry, target, plugins) {
|
|
643
|
-
const keys = (plugins?.keys ?? []).toSorted(compare);
|
|
620
|
+
const keys = groupNames(plugins?.keys ?? []).toSorted(compare);
|
|
644
621
|
const attached = plugins !== void 0 && keys.length > 0;
|
|
645
622
|
const botImport = attached ? `import type ${BOT_BINDING} from '${escapeLiteral(plugins.specifier)}';\n\n` : "";
|
|
646
623
|
const coreRows = attached ? ` interface Core {\n${renderPluginRows(keys)}\n }\n` : "";
|
|
647
624
|
return `${`${BANNER}\n\n${botImport}// prettier-ignore\ndeclare module '${target}' {\n` + coreRows} interface SlashRegistry {\n${renderSlashRows(registry.slash)}\n }\n interface UserContextMenuRegistry {\n${renderContextMenuRows(registry.userContextMenus)}\n }\n interface MessageContextMenuRegistry {\n${renderContextMenuRows(registry.messageContextMenus)}\n }\n interface EmojiMap {\n${renderEmojiRows(registry.emojis)}\n }\n}\n\nexport {};\n`;
|
|
648
625
|
}
|
|
626
|
+
function groupNames(keys) {
|
|
627
|
+
return [...new Set(keys.map((key) => {
|
|
628
|
+
const dot = key.indexOf(".");
|
|
629
|
+
return dot === -1 ? key : key.slice(0, dot);
|
|
630
|
+
}))];
|
|
631
|
+
}
|
|
649
632
|
function renderPluginRows(keys) {
|
|
650
633
|
return keys.map((key) => ` ${renderKey(key)}: (typeof ${BOT_BINDING})['${escapeLiteral(key)}'];`).join("\n");
|
|
651
634
|
}
|