seedcord 0.21.2 → 0.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,8 +8,8 @@
8
8
  <div align="center">
9
9
  <h3>The whole Discord bot, typed end to end</h3>
10
10
  <a href="https://seedcord.org">Website</a> ·
11
- <a href="https://guide.seedcord.org">Guide</a> ·
12
- <a href="https://docs.seedcord.org">Reference</a> ·
11
+ <a href="https://seedcord.org/guide">Guide</a> ·
12
+ <a href="https://seedcord.org/docs">Reference</a> ·
13
13
  <a href="https://discord.gg/DzFxY58WXf">Discord</a>
14
14
  </div>
15
15
 
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-DiTXfD0A.mjs";
2
- import { createRequire, findPackageJSON } from "node:module";
1
+ import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-BfciUrzr.mjs";
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";
5
5
  import { formatBody, installNodeDefaults } from "@seedcord/logger/node";
@@ -31,7 +31,6 @@ import process$1 from "node:process";
31
31
  import { assertNever } from "@seedcord/utils";
32
32
  import { settleWithin } from "@seedcord/core/node/internal";
33
33
  import { createServer, createServerModuleRunner, defineConfig, mergeConfig } from "vite";
34
- import { EvaluatedModules } from "vite/module-runner";
35
34
  import tsconfigPaths from "vite-tsconfig-paths";
36
35
  import { minimatch } from "minimatch";
37
36
  import { createServer as createServer$1 } from "node:net";
@@ -967,17 +966,17 @@ var CleanRunner = class CleanRunner {
967
966
  async fetchBotGuilds(rest) {
968
967
  const guilds = [];
969
968
  let after;
970
- for (;;) {
969
+ let page;
970
+ do {
971
971
  const query = new URLSearchParams({ limit: String(GUILD_PAGE) });
972
972
  if (after) query.set("after", after);
973
- const page = await rest.get(Routes.userGuilds(), { query });
973
+ page = await rest.get(Routes.userGuilds(), { query });
974
974
  for (const guild of page) guilds.push({
975
975
  id: guild.id,
976
976
  name: guild.name
977
977
  });
978
978
  after = page.at(-1)?.id;
979
- if (page.length < GUILD_PAGE || !after) break;
980
- }
979
+ } while (page.length === GUILD_PAGE && after);
981
980
  return guilds;
982
981
  }
983
982
  async fetchGlobalNames(rest, appId) {
@@ -1040,7 +1039,7 @@ async function confirm$1(opts) {
1040
1039
  }
1041
1040
 
1042
1041
  //#endregion
1043
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/usingCtx.js
1042
+ //#region \0@oxc-project+runtime@0.152.0/helpers/esm/usingCtx.js
1044
1043
  function _usingCtx() {
1045
1044
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
1046
1045
  var n = Error();
@@ -1640,10 +1639,9 @@ function useRailWidth(railRef, phase, rows, columns) {
1640
1639
  }
1641
1640
  if (!needsMeasureRef.current || !railRef.current) return;
1642
1641
  const measured = measureElement(railRef.current).width;
1643
- if (measured > 0) {
1644
- needsMeasureRef.current = false;
1645
- setRailWidth(measured);
1646
- }
1642
+ if (!(measured > 0)) return;
1643
+ needsMeasureRef.current = false;
1644
+ setRailWidth(measured);
1647
1645
  }, [
1648
1646
  rows,
1649
1647
  columns,
@@ -2888,7 +2886,6 @@ var DevStore = class extends TypedEventEmitter {
2888
2886
  case "module-loading":
2889
2887
  case "module-loaded":
2890
2888
  case "module-error":
2891
- case "file-change":
2892
2889
  case "ready": break;
2893
2890
  default: assertNever(event);
2894
2891
  }
@@ -3081,11 +3078,17 @@ var DevSession = class {
3081
3078
  //#endregion
3082
3079
  //#region src/commands/dev/runtime/HmrPlugin.ts
3083
3080
  const DEBOUNCE_MS = 250;
3081
+ const TYPE_COLOR = {
3082
+ create: paint.mint,
3083
+ createDir: paint.mint,
3084
+ update: paint.sky,
3085
+ delete: paint.coral,
3086
+ deleteDir: paint.coral
3087
+ };
3084
3088
  var HmrPlugin = class extends TypedEventEmitter {
3085
3089
  config;
3086
3090
  logger;
3087
3091
  lastUpdate = /* @__PURE__ */ new Map();
3088
- awaitingCreateEcho = /* @__PURE__ */ new Set();
3089
3092
  server = null;
3090
3093
  dynamicRestartPatterns = /* @__PURE__ */ new Set();
3091
3094
  get hot() {
@@ -3100,10 +3103,13 @@ var HmrPlugin = class extends TypedEventEmitter {
3100
3103
  this.logger = new Logger("HMR", { channel: "hmr" });
3101
3104
  }
3102
3105
  get plugin() {
3106
+ const onHotUpdate = this.hotUpdate.bind(this);
3103
3107
  return {
3104
3108
  name: "seedcord:hmr",
3105
3109
  configureServer: this.configureServer.bind(this),
3106
- hotUpdate: this.hotUpdate.bind(this)
3110
+ hotUpdate(ctx) {
3111
+ return onHotUpdate(this.environment, ctx);
3112
+ }
3107
3113
  };
3108
3114
  }
3109
3115
  sendRefreshCommands(shouldRefresh) {
@@ -3111,10 +3117,8 @@ var HmrPlugin = class extends TypedEventEmitter {
3111
3117
  }
3112
3118
  configureServer(server) {
3113
3119
  this.server = server;
3114
- server.watcher.on("add", (file) => this.handleFileEvent(file, "create"));
3115
- server.watcher.on("unlink", (file) => this.handleFileEvent(file, "delete"));
3116
- server.watcher.on("addDir", (file) => this.handleFileEvent(file, "createDir"));
3117
- server.watcher.on("unlinkDir", (file) => this.handleFileEvent(file, "deleteDir"));
3120
+ server.watcher.on("addDir", (dir) => this.handleDirEvent(dir, "createDir"));
3121
+ server.watcher.on("unlinkDir", (dir) => this.handleDirEvent(dir, "deleteDir"));
3118
3122
  server.watcher.add(this.config.configFile);
3119
3123
  server.watcher.on("change", (file) => this.handleChange(file));
3120
3124
  this.dev?.on("seedcord:commands-update-prompt", (data) => {
@@ -3135,14 +3139,12 @@ var HmrPlugin = class extends TypedEventEmitter {
3135
3139
  });
3136
3140
  }
3137
3141
  isDebounced(file, type) {
3138
- if (this.justSaw(file, type)) return true;
3139
- this.lastUpdate.set(`${file}::${type}`, Date.now());
3142
+ const key = `${file}::${type}`;
3143
+ const last = this.lastUpdate.get(key);
3144
+ if (last !== void 0 && Date.now() - last < DEBOUNCE_MS) return true;
3145
+ this.lastUpdate.set(key, Date.now());
3140
3146
  return false;
3141
3147
  }
3142
- justSaw(file, type) {
3143
- const last = this.lastUpdate.get(`${file}::${type}`);
3144
- return last !== void 0 && Date.now() - last < DEBOUNCE_MS;
3145
- }
3146
3148
  handleChange(file) {
3147
3149
  if (!this.isCriticalFile(file) || this.isDebounced(file, "update")) return;
3148
3150
  this.reportRestartRequired(file);
@@ -3152,78 +3154,56 @@ var HmrPlugin = class extends TypedEventEmitter {
3152
3154
  this.logger.warn(`${paint.coral("Critical file changed:")} ${paint.sky.bold(relPath)}. Restart required.`);
3153
3155
  this.emit("event", { type: "restart-required" });
3154
3156
  }
3155
- handleFileEvent(file, type) {
3156
- if (this.isDebounced(file, type)) return;
3157
- if (type === "create") this.awaitingCreateEcho.add(file);
3158
- const relPath = relative(process.cwd(), file);
3159
- const typeColor = type === "create" || type === "createDir" ? paint.mint : type === "delete" || type === "deleteDir" ? paint.coral : paint.sky;
3160
- this.logger.trace(`${typeColor(type.toUpperCase())} ${paint.mute(relPath)}`);
3161
- const payload = {
3162
- file,
3163
- type,
3157
+ handleDirEvent(dir, type) {
3158
+ if (this.isDebounced(dir, type)) return;
3159
+ this.send({
3160
+ file: dir,
3161
+ type
3162
+ });
3163
+ }
3164
+ send(event) {
3165
+ const relPath = relative(process.cwd(), event.file);
3166
+ this.logger.trace(`${TYPE_COLOR[event.type](event.type.toUpperCase())} ${paint.mute(relPath)}`);
3167
+ this.dev?.send("seedcord:hmr", {
3168
+ ...event,
3164
3169
  rollback: this.config.hmr?.rollback ?? true
3165
- };
3166
- this.dev?.send("seedcord:hmr", payload);
3170
+ });
3167
3171
  }
3168
- hotUpdate(ctx) {
3169
- const { file, modules, server } = ctx;
3170
- const type = "update";
3171
- if (this.awaitingCreateEcho.delete(file) && this.justSaw(file, "create") || this.isDebounced(file, type)) return [];
3172
- const relPath = relative(process.cwd(), file);
3173
- this.logger.trace(`${paint.sky(type.toUpperCase())} ${paint.mute(relPath)}`);
3172
+ hotUpdate(environment, ctx) {
3173
+ const { type, file, modules } = ctx;
3174
+ if (environment.name !== "ssr" || this.isDebounced(file, type)) return [];
3174
3175
  if (this.isCriticalFile(file)) {
3175
3176
  this.reportRestartRequired(file);
3176
3177
  return [];
3177
3178
  }
3178
- const moduleGraph = server.moduleGraph;
3179
- const fileModules = moduleGraph.getModulesByFile(file);
3180
- const allModules = fileModules ? [...fileModules] : [];
3181
- const combinedModules = /* @__PURE__ */ new Set([...modules, ...allModules]);
3182
- const affectedModules = this.getAffectedModules([...combinedModules]);
3183
- const filesToInvalidate = /* @__PURE__ */ new Set([file, ...affectedModules]);
3184
- for (const fileToInvalidate of filesToInvalidate) {
3185
- const mods = moduleGraph.getModulesByFile(fileToInvalidate);
3186
- if (mods) for (const mod of mods) moduleGraph.invalidateModule(mod);
3187
- }
3188
- this.emit("event", {
3189
- type: "file-change",
3190
- path: file
3191
- });
3192
- const payload = {
3179
+ const { moduleGraph } = environment;
3180
+ const affectedModules = affectedFiles(file, modules);
3181
+ for (const target of affectedModules) for (const mod of moduleGraph.getModulesByFile(target) ?? []) moduleGraph.invalidateModule(mod);
3182
+ this.send({
3193
3183
  file,
3194
3184
  type,
3195
- affectedModules,
3196
- rollback: this.config.hmr?.rollback ?? true
3197
- };
3198
- this.dev?.send("seedcord:hmr", payload);
3185
+ affectedModules
3186
+ });
3199
3187
  return [];
3200
3188
  }
3201
3189
  isCriticalFile(file) {
3202
- const root = this.config.root;
3190
+ const { root, configFile, entry, instance } = this.config;
3203
3191
  const relPath = relative(root, file);
3204
- if (this.config.hmr?.restart) {
3205
- for (const pattern of this.config.hmr.restart) if (minimatch(relPath, pattern)) return true;
3206
- }
3207
- for (const pattern of this.dynamicRestartPatterns) if (minimatch(relPath, pattern)) return true;
3208
- if (file === this.config.configFile || file.endsWith("package.json") || file.endsWith("tsconfig.json") || file.endsWith(".env")) return true;
3209
- const entryPath = resolve(root, this.config.entry);
3210
- const instancePath = resolve(root, this.config.instance);
3211
- if (file === entryPath || file === instancePath) return true;
3212
- return false;
3213
- }
3214
- getAffectedModules(modules) {
3215
- const affected = /* @__PURE__ */ new Set();
3216
- const seen = /* @__PURE__ */ new Set();
3217
- const traverse = (mod) => {
3218
- if (!mod.file || seen.has(mod.file)) return;
3219
- seen.add(mod.file);
3220
- affected.add(mod.file);
3221
- mod.importers.forEach(traverse);
3222
- };
3223
- modules.forEach(traverse);
3224
- return [...affected];
3192
+ return [...this.config.hmr?.restart ?? [], ...this.dynamicRestartPatterns].some((pattern) => minimatch(relPath, pattern)) || file === configFile || file.endsWith("package.json") || file.endsWith("tsconfig.json") || file.endsWith(".env") || file === resolve(root, entry) || file === resolve(root, instance);
3225
3193
  }
3226
3194
  };
3195
+ function affectedFiles(file, modules) {
3196
+ const files = /* @__PURE__ */ new Set([file]);
3197
+ const visited = /* @__PURE__ */ new Set();
3198
+ const visit = (mod) => {
3199
+ if (visited.has(mod)) return;
3200
+ visited.add(mod);
3201
+ if (mod.file) files.add(mod.file);
3202
+ mod.importers.forEach(visit);
3203
+ };
3204
+ modules.forEach(visit);
3205
+ return [...files];
3206
+ }
3227
3207
 
3228
3208
  //#endregion
3229
3209
  //#region src/commands/dev/runtime/seedcordDependents.ts
@@ -3242,12 +3222,14 @@ function dependencyNames(manifestPath, fields) {
3242
3222
  });
3243
3223
  }
3244
3224
  function installedManifest(name, fromManifest) {
3245
- try {
3246
- return findPackageJSON(name, pathToFileURL(fromManifest));
3247
- } catch (error) {
3248
- if (Error.isError(error) && "code" in error && error.code === "ERR_MODULE_NOT_FOUND") return void 0;
3249
- throw error;
3250
- }
3225
+ let dir = dirname(fromManifest);
3226
+ let checked;
3227
+ do {
3228
+ const candidate = join(dir, "node_modules", name, "package.json");
3229
+ if (existsSync(candidate)) return realpathSync(candidate);
3230
+ checked = dir;
3231
+ dir = dirname(dir);
3232
+ } while (dir !== checked);
3251
3233
  }
3252
3234
  function isSeedcordPackage(name) {
3253
3235
  return name.startsWith("@seedcord/");
@@ -3354,7 +3336,6 @@ var ViteDevRuntime = class {
3354
3336
  viteServer = null;
3355
3337
  moduleRunner = null;
3356
3338
  eventHandler = null;
3357
- evaluatedModules = null;
3358
3339
  hmrPlugin = null;
3359
3340
  async start(context) {
3360
3341
  this.context = context;
@@ -3376,26 +3357,14 @@ var ViteDevRuntime = class {
3376
3357
  plugins: [tsconfigPaths({ root: projectDir }), hmrPlugin.plugin]
3377
3358
  });
3378
3359
  this.viteServer = await createServer(config);
3379
- this.evaluatedModules = new EvaluatedModules();
3380
- this.moduleRunner = createServerModuleRunner(this.viteServer.environments.ssr, { evaluatedModules: this.evaluatedModules });
3381
- hmrPlugin.on("event", this.handleHmrEvent.bind(this));
3360
+ this.moduleRunner = createServerModuleRunner(this.viteServer.environments.ssr);
3361
+ hmrPlugin.on("event", this.emit.bind(this));
3382
3362
  this.emit({
3383
3363
  type: "module-loaded",
3384
3364
  path: projectRoot
3385
3365
  });
3386
3366
  this.emit({ type: "ready" });
3387
3367
  }
3388
- handleHmrEvent(event) {
3389
- if (event.type === "file-change") this.invalidateModule(event.path);
3390
- this.emit(event);
3391
- }
3392
- invalidateModule(file) {
3393
- const projectRoot = this.context?.config.root;
3394
- if (!projectRoot || !this.evaluatedModules) return;
3395
- const moduleId = toModuleId(projectRoot, file);
3396
- const moduleNode = this.evaluatedModules.getModuleById(moduleId);
3397
- if (moduleNode) this.evaluatedModules.invalidateModule(moduleNode);
3398
- }
3399
3368
  refreshCommands(shouldRefresh) {
3400
3369
  this.hmrPlugin?.sendRefreshCommands(shouldRefresh);
3401
3370
  }
@@ -3431,7 +3400,6 @@ var ViteDevRuntime = class {
3431
3400
  this.viteServer = null;
3432
3401
  }
3433
3402
  this.moduleRunner = null;
3434
- this.evaluatedModules = null;
3435
3403
  this.hmrPlugin = null;
3436
3404
  this.context = null;
3437
3405
  this.eventHandler = null;
@@ -3576,7 +3544,7 @@ var CloudflaredTunnel = class {
3576
3544
  }
3577
3545
  const cause = this.failure;
3578
3546
  this.stop();
3579
- throw new SeedcordError(SeedcordErrorCode.CliTunnelUrlUnavailable, [6e4 / 1e3], { cause });
3547
+ throw new SeedcordError(SeedcordErrorCode.CliTunnelUrlUnavailable, [60], { cause });
3580
3548
  }
3581
3549
  async pollOnce(metricsPort, signal) {
3582
3550
  try {