seedcord 0.19.0 → 0.19.2
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/bin/seedcord.mjs
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
5
|
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
function declaredNodeRange() {
|
|
9
|
+
try {
|
|
10
|
+
const pkg = JSON.parse(readFileSync(resolve(here, '../package.json'), 'utf8'));
|
|
11
|
+
return pkg.engines?.node ?? '';
|
|
12
|
+
} catch {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// importing core's own check here would load the code this guards
|
|
18
|
+
function unsupportedNodeRange() {
|
|
19
|
+
const range = declaredNodeRange();
|
|
20
|
+
|
|
21
|
+
const required = new RegExp(String.raw`^>=(\d+)(?:\.(\d+))?`).exec(range.replaceAll(/\s/g, ''));
|
|
22
|
+
const current = /^v?(\d+)\.(\d+)/.exec(process.version);
|
|
23
|
+
if (!required || !current) return null;
|
|
24
|
+
|
|
25
|
+
const requiredMinor = required[2] ?? '0';
|
|
26
|
+
const meets =
|
|
27
|
+
Number(current[1]) > Number(required[1]) ||
|
|
28
|
+
(Number(current[1]) === Number(required[1]) && Number(current[2]) >= Number(requiredMinor));
|
|
29
|
+
return meets ? null : range;
|
|
30
|
+
}
|
|
31
|
+
|
|
6
32
|
async function run() {
|
|
7
|
-
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
33
|
const distEntry = resolve(here, '../dist/cli.mjs');
|
|
9
34
|
if (existsSync(distEntry)) {
|
|
10
35
|
await import(pathToFileURL(distEntry).href);
|
|
@@ -16,8 +41,15 @@ async function run() {
|
|
|
16
41
|
await import(pathToFileURL(srcEntry).href);
|
|
17
42
|
}
|
|
18
43
|
|
|
44
|
+
const unsupported = unsupportedNodeRange();
|
|
45
|
+
if (unsupported) {
|
|
46
|
+
// eslint-disable-next-line no-console -- the bin has no logger
|
|
47
|
+
console.error(`seedcord requires Node ${unsupported} and this process runs ${process.version}.`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
19
51
|
run().catch((error) => {
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
52
|
+
// eslint-disable-next-line no-console -- the bin has no logger
|
|
21
53
|
console.error(error);
|
|
22
54
|
process.exitCode = 1;
|
|
23
55
|
});
|
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-B9hiTPr7.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";
|
|
@@ -13,7 +13,9 @@ import { createJiti } from "jiti";
|
|
|
13
13
|
import { tsImport } from "tsx/esm/api";
|
|
14
14
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
15
15
|
import { spawn } from "node:child_process";
|
|
16
|
-
import
|
|
16
|
+
import "reflect-metadata";
|
|
17
|
+
import { isCommandClass, wrapHot } from "@seedcord/core/internal";
|
|
18
|
+
import { HostAugmentTarget, HostPluginKeys, HostShutdown, HostStartup, HostVersion, SeedcordBrand } from "@seedcord/types/internal";
|
|
17
19
|
import { isTsOrJsFile } from "@seedcord/utils/node";
|
|
18
20
|
import { ApplicationCommandOptionType, ApplicationCommandType, InteractionContextType, RESTJSONErrorCodes, Routes } from "discord-api-types/v10";
|
|
19
21
|
import { routeLeavesOf } from "@seedcord/utils/internal";
|
|
@@ -32,7 +34,6 @@ import { settleWithin } from "@seedcord/core/node/internal";
|
|
|
32
34
|
import { createServer, createServerModuleRunner, defineConfig, mergeConfig } from "vite";
|
|
33
35
|
import { EvaluatedModules } from "vite/module-runner";
|
|
34
36
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
35
|
-
import { wrapHot } from "@seedcord/core/internal";
|
|
36
37
|
import { minimatch } from "minimatch";
|
|
37
38
|
import { createServer as createServer$1 } from "node:net";
|
|
38
39
|
|
|
@@ -619,7 +620,7 @@ var AugmentationBuilder = class {
|
|
|
619
620
|
toSlashOption(option) {
|
|
620
621
|
const choices = "choices" in option && option.choices && option.choices.length > 0 ? option.choices.map((choice) => choice.value) : void 0;
|
|
621
622
|
const autocomplete = "autocomplete" in option && option.autocomplete === true ? true : void 0;
|
|
622
|
-
const channelTypes = "channel_types" in option && option.channel_types && option.channel_types.length > 0 ?
|
|
623
|
+
const channelTypes = "channel_types" in option && option.channel_types && option.channel_types.length > 0 ? option.channel_types.toSorted((first, second) => first - second) : void 0;
|
|
623
624
|
return {
|
|
624
625
|
kind: KIND_BY_TYPE[option.type],
|
|
625
626
|
required: option.required ?? false,
|
|
@@ -639,7 +640,7 @@ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
639
640
|
const CONTROL_CHAR = 32;
|
|
640
641
|
const HEX_RADIX = 16;
|
|
641
642
|
function renderAugmentation(registry, target, plugins) {
|
|
642
|
-
const keys =
|
|
643
|
+
const keys = (plugins?.keys ?? []).toSorted(compare);
|
|
643
644
|
const attached = plugins !== void 0 && keys.length > 0;
|
|
644
645
|
const botImport = attached ? `import type ${BOT_BINDING} from '${escapeLiteral(plugins.specifier)}';\n\n` : "";
|
|
645
646
|
const coreRows = attached ? ` interface Core {\n${renderPluginRows(keys)}\n }\n` : "";
|
|
@@ -788,7 +789,7 @@ var CodegenRunner = class CodegenRunner {
|
|
|
788
789
|
for (const exported of Object.values(imported)) {
|
|
789
790
|
if (seen.has(exported)) continue;
|
|
790
791
|
seen.add(exported);
|
|
791
|
-
const json = this.commandJsonOf(exported);
|
|
792
|
+
const json = this.commandJsonOf(exported, fullPath);
|
|
792
793
|
if (json) yield {
|
|
793
794
|
sourceFile: fullPath,
|
|
794
795
|
json
|
|
@@ -806,27 +807,24 @@ var CodegenRunner = class CodegenRunner {
|
|
|
806
807
|
return {
|
|
807
808
|
commandsDir: commandsPath ? resolve(process.cwd(), commandsPath) : void 0,
|
|
808
809
|
emojis: instance.config.bot.emojis ?? {},
|
|
809
|
-
augmentTarget: instance
|
|
810
|
-
pluginKeys: instance
|
|
810
|
+
augmentTarget: instance[HostAugmentTarget],
|
|
811
|
+
pluginKeys: instance[HostPluginKeys]
|
|
811
812
|
};
|
|
812
813
|
}
|
|
813
|
-
commandJsonOf(exported) {
|
|
814
|
-
if (
|
|
815
|
-
let
|
|
814
|
+
commandJsonOf(exported, sourceFile) {
|
|
815
|
+
if (!isCommandClass(exported)) return void 0;
|
|
816
|
+
let json;
|
|
816
817
|
try {
|
|
817
|
-
|
|
818
|
-
} catch {
|
|
819
|
-
|
|
818
|
+
json = new exported().component.toJSON();
|
|
819
|
+
} catch (error) {
|
|
820
|
+
const reason = Error.isError(error) ? error.message : "Unknown error";
|
|
821
|
+
throw new SeedcordError(SeedcordErrorCode.CliCodegenCommandConstructorThrew, [
|
|
822
|
+
exported.name,
|
|
823
|
+
sourceFile,
|
|
824
|
+
reason
|
|
825
|
+
]);
|
|
820
826
|
}
|
|
821
|
-
|
|
822
|
-
const json = instance.component.toJSON();
|
|
823
|
-
if (!this.isApplicationCommand(json)) return void 0;
|
|
824
|
-
return json;
|
|
825
|
-
}
|
|
826
|
-
isBuilderLike(value) {
|
|
827
|
-
if (typeof value !== "object" || value === null) return false;
|
|
828
|
-
const component = value.component;
|
|
829
|
-
return typeof component === "object" && component !== null && typeof component.toJSON === "function";
|
|
827
|
+
return this.isApplicationCommand(json) ? json : void 0;
|
|
830
828
|
}
|
|
831
829
|
isApplicationCommand(json) {
|
|
832
830
|
if (typeof json !== "object" || json === null) return false;
|
|
@@ -2707,7 +2705,7 @@ function startup() {
|
|
|
2707
2705
|
function profileReport() {
|
|
2708
2706
|
if (!enabled) return null;
|
|
2709
2707
|
const session = performance.now();
|
|
2710
|
-
const sorted =
|
|
2708
|
+
const sorted = renderTimes.toSorted((a, b) => a - b);
|
|
2711
2709
|
const layoutTotal = renderTimes.reduce((sum, time) => sum + time, 0);
|
|
2712
2710
|
const mb = (written / BYTES_PER_MB).toFixed(2);
|
|
2713
2711
|
const share = (part) => `${(part / session * PERCENT).toFixed(1)}% of session`;
|
|
@@ -3054,8 +3052,8 @@ var DevSession = class {
|
|
|
3054
3052
|
if (!isSeedcordInstance(instance)) throw new SeedcordError(SeedcordErrorCode.CliInstanceInvalid);
|
|
3055
3053
|
this.instance = instance;
|
|
3056
3054
|
this.store.setTransport({
|
|
3057
|
-
name: instance
|
|
3058
|
-
version: instance
|
|
3055
|
+
name: instance[HostAugmentTarget],
|
|
3056
|
+
version: instance[HostVersion]
|
|
3059
3057
|
});
|
|
3060
3058
|
try {
|
|
3061
3059
|
this.store.setPhase("starting");
|
|
@@ -3083,11 +3081,11 @@ var DevSession = class {
|
|
|
3083
3081
|
async runStop() {
|
|
3084
3082
|
this.isStopped = true;
|
|
3085
3083
|
this.tscRunner?.stop();
|
|
3086
|
-
this.instance?.
|
|
3084
|
+
this.instance?.[HostStartup].abort();
|
|
3087
3085
|
if (this.startupPromise) try {
|
|
3088
3086
|
await this.startupPromise;
|
|
3089
3087
|
} catch {}
|
|
3090
|
-
await this.instance?.
|
|
3088
|
+
await this.instance?.[HostShutdown].run(0, false);
|
|
3091
3089
|
this.stopResolve?.();
|
|
3092
3090
|
}
|
|
3093
3091
|
async dispose() {
|