bakit 2.0.0-alpha.17 → 2.0.0-alpha.18

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.js CHANGED
@@ -3,15 +3,12 @@ import { program } from 'commander';
3
3
  import { fork } from 'child_process';
4
4
  import chokidar from 'chokidar';
5
5
  import path, { relative, sep } from 'path';
6
- import { createJiti } from 'jiti';
6
+ import { pathToFileURL } from 'url';
7
7
 
8
8
  // src/cli/bin.ts
9
- createJiti(process.cwd());
10
9
  function getTopLevelDirectory(path2, entryDir) {
11
10
  return relative(entryDir, path2).split(sep)[0] ?? null;
12
11
  }
13
-
14
- // src/cli/process/DevProcessManager.ts
15
12
  var DevProcessManager = class {
16
13
  constructor(options) {
17
14
  this.options = options;
@@ -25,7 +22,7 @@ var DevProcessManager = class {
25
22
  if (this.child) return;
26
23
  let entry = path.resolve(this.options.entry);
27
24
  this.child = fork(entry, {
28
- execArgv: ["--import", "tsx"],
25
+ execArgv: ["--import", "bakit/loader/register"],
29
26
  stdio: "inherit",
30
27
  env: {
31
28
  ...process.env,
@@ -51,7 +48,9 @@ var DevProcessManager = class {
51
48
  stabilityThreshold: 200,
52
49
  pollInterval: 50
53
50
  }
54
- }).on("change", (file) => this.onFileChanged(file));
51
+ }).on("change", (file) => {
52
+ this.onFileChanged(pathToFileURL(file).href);
53
+ });
55
54
  }
56
55
  onFileChanged(file) {
57
56
  if (!this.child)
package/dist/index.d.ts CHANGED
@@ -447,9 +447,6 @@ declare function tokenize(content: string): string[];
447
447
  */
448
448
  declare function extractSnowflakeId(input: string): string | null;
449
449
 
450
- declare function importModule<T>(modulePath: string, defaultImport?: boolean): Promise<T | null>;
451
- declare function isModuleLoaded(modulePath: string): boolean;
452
- declare function unloadModule(modulePath: string): boolean;
453
450
  declare function getTopLevelDirectory(path: string, entryDir: string): string | null;
454
451
 
455
452
  declare const messageCommandHandler: Listener<Events.MessageCreate>;
@@ -482,4 +479,4 @@ declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
482
479
  */
483
480
  declare function getConfig(): ProjectConfig;
484
481
 
485
- export { type AnyParam, ArgumentError, BakitClient, type BakitClientEvents, BakitError, BaseClientManager, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, Context, type ContextSendOptions, EVENT_INTENT_MAPPING, type ErrorHookCallback, type GetPrefixFunction, HookOrder, HookState, type InferParamTuple, type InferParamValue, Instance, LifecycleManager, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, type MainHookCallback, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, ProjectCacheManager, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, type UserOptions, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getTopLevelDirectory, importModule, isModuleLoaded, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, unloadModule, useApp, validateParamsOrder };
482
+ export { type AnyParam, ArgumentError, BakitClient, type BakitClientEvents, BakitError, BaseClientManager, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, Context, type ContextSendOptions, EVENT_INTENT_MAPPING, type ErrorHookCallback, type GetPrefixFunction, HookOrder, HookState, type InferParamTuple, type InferParamValue, Instance, LifecycleManager, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, type MainHookCallback, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, ProjectCacheManager, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, type UserOptions, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getTopLevelDirectory, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, useApp, validateParamsOrder };
package/dist/index.js CHANGED
@@ -1,14 +1,42 @@
1
+ import { register } from 'module';
2
+ import { posix, resolve, relative, sep, join, dirname } from 'path';
3
+ import { pathToFileURL } from 'url';
4
+ import { MessageChannel } from 'worker_threads';
1
5
  import { GatewayIntentBits, Events, Client, Collection, IntentsBitField, SlashCommandBuilder, SlashCommandStringOption, SlashCommandNumberOption, SlashCommandUserOption, ChatInputCommandInteraction, Message } from 'discord.js';
2
6
  import { inspect } from 'util';
3
- import { posix, resolve, relative, sep, join, dirname } from 'path';
4
7
  import glob from 'tiny-glob';
5
8
  import z4 from 'zod';
6
- import { createJiti } from 'jiti';
7
9
  import { existsSync, mkdirSync, rmSync } from 'fs';
8
10
  import { mkdir, writeFile, readFile, rm } from 'fs/promises';
9
11
  import { createHash } from 'crypto';
10
12
 
11
- // src/core/client/BakitClient.ts
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropNames = Object.getOwnPropertyNames;
15
+ var __esm = (fn, res) => function() {
16
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ };
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, { get: all[name], enumerable: true });
21
+ };
22
+
23
+ // src/loader/register.ts
24
+ var register_exports = {};
25
+ __export(register_exports, {
26
+ unload: () => unload
27
+ });
28
+ function unload(module) {
29
+ port2.postMessage({ type: "unload", target: module });
30
+ }
31
+ var port1, port2, hookPath, init_register = __esm({
32
+ "src/loader/register.ts"() {
33
+ (({ port1, port2 } = new MessageChannel())), hookPath = pathToFileURL(resolve("./loader.js")).href;
34
+ register(hookPath, import.meta.url, {
35
+ data: { port: port1 },
36
+ transferList: [port1]
37
+ });
38
+ }
39
+ });
12
40
  var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z4.object({
13
41
  name: z4.string(),
14
42
  description: z4.string().optional(),
@@ -159,23 +187,6 @@ function extractSnowflakeId(input) {
159
187
  let idMatch = /^(\d{17,20})$/.exec(input);
160
188
  return idMatch?.[1] ? idMatch[1] : null;
161
189
  }
162
- var jiti = createJiti(process.cwd());
163
- async function importModule(modulePath, defaultImport = false) {
164
- let path = resolve(modulePath);
165
- try {
166
- return await jiti.import(path, { default: defaultImport });
167
- } catch (error) {
168
- return console.error(`[Module] Import failed for ${path}:`, error), null;
169
- }
170
- }
171
- function isModuleLoaded(modulePath) {
172
- let path = resolve(modulePath);
173
- return !!path && !!jiti.cache[path];
174
- }
175
- function unloadModule(modulePath) {
176
- let path = resolve(modulePath);
177
- return !path || !jiti.cache[path] ? false : (delete jiti.cache[path], true);
178
- }
179
190
  function getTopLevelDirectory(path, entryDir) {
180
191
  return relative(entryDir, path).split(sep)[0] ?? null;
181
192
  }
@@ -476,7 +487,7 @@ var CommandManager = class extends BaseClientManager {
476
487
  * @returns The command object if added successfully.
477
488
  */
478
489
  async load(path) {
479
- let command = await importModule(path, true);
490
+ let command = (await import(path)).default;
480
491
  if (!command) {
481
492
  console.warn(`[Loader] File has no default export: ${path}`);
482
493
  return;
@@ -494,7 +505,7 @@ var CommandManager = class extends BaseClientManager {
494
505
  */
495
506
  async unload(path) {
496
507
  let command = this.entries.get(path);
497
- if (isModuleLoaded(path) && (command ??= await importModule(path, true), unloadModule(path)), this.entries.delete(path), !!command)
508
+ if (this.entries.delete(path), (await Promise.resolve().then(() => (init_register(), register_exports))).unload(path), !!command)
498
509
  return this.remove(command);
499
510
  }
500
511
  async reload(path) {
@@ -575,7 +586,7 @@ var ListenerManager = class extends BaseClientManager {
575
586
  * @returns The listener object if added successfully.
576
587
  */
577
588
  async load(path) {
578
- let listener = await importModule(path, true);
589
+ let listener = (await import(path)).default;
579
590
  if (!listener) {
580
591
  console.warn(`[Loader] File has no default export: ${path}`);
581
592
  return;
@@ -593,7 +604,7 @@ var ListenerManager = class extends BaseClientManager {
593
604
  */
594
605
  async unload(path) {
595
606
  let listener = this.entries.get(path);
596
- if (isModuleLoaded(path) && (listener ??= await importModule(path, true), unloadModule(path)), this.entries.delete(path), !!listener)
607
+ if (this.entries.delete(path), (await Promise.resolve().then(() => (init_register(), register_exports))).unload(path), !!listener)
597
608
  return this.remove(listener)?.[0];
598
609
  }
599
610
  async reload(path) {
@@ -793,7 +804,7 @@ async function loadConfig(cwd = process.cwd()) {
793
804
  if (!configPath)
794
805
  throw new Error("Missing config file");
795
806
  other && console.warn(`Multiple config files found in ${cwd}. Using ${configPath}.`);
796
- let config = await importModule(configPath, true);
807
+ let config = (await import(configPath)).default;
797
808
  return _config = Object.freeze(await ProjectConfigSchema.parseAsync(config)), _config;
798
809
  }
799
810
  function getConfig() {
@@ -952,4 +963,4 @@ var Params = {
952
963
  user: createFactory(UserParam)
953
964
  };
954
965
 
955
- export { ArgumentError, BakitClient, BakitError, BaseClientManager, BaseCommandContext, BaseParam, BaseParamSchema, ChatInputContext, Command, CommandManager, CommandOptionsSchema, Context, EVENT_INTENT_MAPPING, HookOrder, HookState, Instance, LifecycleManager, Listener, ListenerManager, ListenerOptionsSchema, MessageContext, NumberParam, NumberParamSchema, ParamUserType, Params, ProjectCacheManager, ProjectConfigSchema, StringParam, StringParamSchema, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getTopLevelDirectory, importModule, isModuleLoaded, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, unloadModule, useApp, validateParamsOrder };
966
+ export { ArgumentError, BakitClient, BakitError, BaseClientManager, BaseCommandContext, BaseParam, BaseParamSchema, ChatInputContext, Command, CommandManager, CommandOptionsSchema, Context, EVENT_INTENT_MAPPING, HookOrder, HookState, Instance, LifecycleManager, Listener, ListenerManager, ListenerOptionsSchema, MessageContext, NumberParam, NumberParamSchema, ParamUserType, Params, ProjectCacheManager, ProjectConfigSchema, StringParam, StringParamSchema, UserParam, UserParamSchema, chatInputCommandHandler, defineCommand, defineConfig, defineListener, extractSnowflakeId, getConfig, getTopLevelDirectory, loadConfig, messageCommandHandler, registerCommandsHandler, tokenize, useApp, validateParamsOrder };