seedcord 0.19.1 → 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/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-Cm47mkrk.mjs";
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 { SeedcordBrand } from "@seedcord/types/internal";
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 ? [...option.channel_types].sort((first, second) => first - second) : void 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 = [...plugins?.keys ?? []].sort(compare);
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.augmentTarget,
810
- pluginKeys: instance.pluginKeys
810
+ augmentTarget: instance[HostAugmentTarget],
811
+ pluginKeys: instance[HostPluginKeys]
811
812
  };
812
813
  }
813
- commandJsonOf(exported) {
814
- if (typeof exported !== "function") return void 0;
815
- let instance;
814
+ commandJsonOf(exported, sourceFile) {
815
+ if (!isCommandClass(exported)) return void 0;
816
+ let json;
816
817
  try {
817
- instance = new exported();
818
- } catch {
819
- return;
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
- if (!this.isBuilderLike(instance)) return void 0;
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 = [...renderTimes].sort((a, b) => a - b);
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.augmentTarget,
3058
- version: instance.version
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?.startup.abort();
3084
+ this.instance?.[HostStartup].abort();
3087
3085
  if (this.startupPromise) try {
3088
3086
  await this.startupPromise;
3089
3087
  } catch {}
3090
- await this.instance?.shutdown.run(0, false);
3088
+ await this.instance?.[HostShutdown].run(0, false);
3091
3089
  this.stopResolve?.();
3092
3090
  }
3093
3091
  async dispose() {