bakit 2.0.0-alpha.22 → 2.0.0-alpha.23
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 +1 -1
- package/dist/{loader/hooks.js → hooks.js} +29 -15
- package/dist/index.d.ts +16 -1
- package/dist/index.js +35 -4
- package/dist/register.js +4 -0
- package/package.json +2 -2
- package/dist/loader/register.js +0 -14
package/dist/cli.js
CHANGED
|
@@ -22,7 +22,7 @@ var DevProcessManager = class {
|
|
|
22
22
|
if (this.child) return;
|
|
23
23
|
let entry = path.resolve(this.options.entry);
|
|
24
24
|
this.child = fork(entry, {
|
|
25
|
-
execArgv: ["--import", "bakit/
|
|
25
|
+
execArgv: ["--import", "bakit/register"],
|
|
26
26
|
stdio: "inherit",
|
|
27
27
|
env: {
|
|
28
28
|
...process.env,
|
|
@@ -4,7 +4,7 @@ import { Module } from 'module';
|
|
|
4
4
|
import { dirname, resolve as resolve$1, basename } from 'path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
6
|
|
|
7
|
-
// src/loader/hooks.ts
|
|
7
|
+
// src/lib/loader/hooks.ts
|
|
8
8
|
var EXTENSIONS = [".js", ".ts"], inDev = false, parentPort, versions, esbuild;
|
|
9
9
|
async function initialize({ port }) {
|
|
10
10
|
inDev = process.env.NODE_ENV === "development", inDev && (parentPort = port, parentPort.on("message", onMessage), versions = /* @__PURE__ */ new Map(), esbuild = await import('esbuild'));
|
|
@@ -39,19 +39,22 @@ async function resolve(specifier, context, nextResolve) {
|
|
|
39
39
|
async function load(url, context, nextLoad) {
|
|
40
40
|
if (shouldSkip(url))
|
|
41
41
|
return nextLoad(url, context);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
try {
|
|
43
|
+
let cleanURL = url.split("?")[0], filePath = fileURLToPath(cleanURL ?? "");
|
|
44
|
+
if (filePath.endsWith(".ts") && esbuild) {
|
|
45
|
+
let raw = await readFile(filePath, "utf8");
|
|
46
|
+
return {
|
|
47
|
+
source: (await esbuild.transform(raw, {
|
|
48
|
+
platform: "node",
|
|
49
|
+
sourcefile: filePath,
|
|
50
|
+
sourcemap: "inline",
|
|
51
|
+
loader: "ts"
|
|
52
|
+
})).code,
|
|
53
|
+
format: "module",
|
|
54
|
+
shortCircuit: !0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
55
58
|
}
|
|
56
59
|
return nextLoad(url, context);
|
|
57
60
|
}
|
|
@@ -69,7 +72,18 @@ function shouldSkip(specifier) {
|
|
|
69
72
|
return true;
|
|
70
73
|
}
|
|
71
74
|
function onMessage(message) {
|
|
72
|
-
|
|
75
|
+
let { type, data, id } = message;
|
|
76
|
+
if (type !== "unload") {
|
|
77
|
+
parentPort?.postMessage({
|
|
78
|
+
id,
|
|
79
|
+
data: false
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
versions?.delete(data), parentPort?.postMessage({
|
|
84
|
+
id,
|
|
85
|
+
data: true
|
|
86
|
+
});
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
export { initialize, load, resolve };
|
package/dist/index.d.ts
CHANGED
|
@@ -449,6 +449,21 @@ declare function extractSnowflakeId(input: string): string | null;
|
|
|
449
449
|
|
|
450
450
|
declare function getTopLevelDirectory(path: string, entryDir: string): string | null;
|
|
451
451
|
|
|
452
|
+
interface PostMessage<Data> {
|
|
453
|
+
id: number;
|
|
454
|
+
type: string;
|
|
455
|
+
data: Data;
|
|
456
|
+
}
|
|
457
|
+
interface ResponseMessage<Data> {
|
|
458
|
+
id: number;
|
|
459
|
+
error?: string;
|
|
460
|
+
data?: Data;
|
|
461
|
+
}
|
|
462
|
+
declare function $initLoader(): void;
|
|
463
|
+
declare function $postLoaderMessage<Data>(type: string, data: Data, wait?: false): void;
|
|
464
|
+
declare function $postLoaderMessage<Data, Output = unknown>(type: string, data: Data, wait: true): Promise<Output>;
|
|
465
|
+
declare function $unloadFile(path: string): Promise<boolean>;
|
|
466
|
+
|
|
452
467
|
declare const messageCommandHandler: Listener<Events.MessageCreate>;
|
|
453
468
|
declare const chatInputCommandHandler: Listener<Events.InteractionCreate>;
|
|
454
469
|
declare const registerCommandsHandler: Listener<Events.ClientReady>;
|
|
@@ -479,4 +494,4 @@ declare function loadConfig(cwd?: string): Promise<ProjectConfig>;
|
|
|
479
494
|
*/
|
|
480
495
|
declare function getConfig(): ProjectConfig;
|
|
481
496
|
|
|
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 };
|
|
497
|
+
export { $initLoader, $postLoaderMessage, $unloadFile, 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, type PostMessage, ProjectCacheManager, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type ResponseMessage, 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,8 +1,10 @@
|
|
|
1
1
|
import { GatewayIntentBits, Events, Client, Collection, IntentsBitField, SlashCommandBuilder, SlashCommandStringOption, SlashCommandNumberOption, SlashCommandUserOption, ChatInputCommandInteraction, Message } from 'discord.js';
|
|
2
2
|
import { inspect } from 'util';
|
|
3
|
-
import { posix, relative, sep, join, dirname } from 'path';
|
|
3
|
+
import { posix, resolve, relative, sep, join, dirname } from 'path';
|
|
4
4
|
import glob from 'tiny-glob';
|
|
5
5
|
import z4 from 'zod';
|
|
6
|
+
import { register } from 'module';
|
|
7
|
+
import { MessageChannel } from 'worker_threads';
|
|
6
8
|
import { pathToFileURL } from 'url';
|
|
7
9
|
import { existsSync, mkdirSync, rmSync } from 'fs';
|
|
8
10
|
import { mkdir, writeFile, readFile, rm } from 'fs/promises';
|
|
@@ -162,6 +164,35 @@ function extractSnowflakeId(input) {
|
|
|
162
164
|
function getTopLevelDirectory(path, entryDir) {
|
|
163
165
|
return relative(entryDir, path).split(sep)[0] ?? null;
|
|
164
166
|
}
|
|
167
|
+
var port1, port2, messageId = 0, pending = /* @__PURE__ */ new Map();
|
|
168
|
+
function $initLoader() {
|
|
169
|
+
let channel = new MessageChannel();
|
|
170
|
+
port1 = channel.port1, port2 = channel.port2;
|
|
171
|
+
let hookPath = new URL("./hooks.js", import.meta.url).href;
|
|
172
|
+
register(hookPath, import.meta.url, {
|
|
173
|
+
data: { port: port1 },
|
|
174
|
+
transferList: [port1]
|
|
175
|
+
}), port2.on("message", onMessage), port2.unref();
|
|
176
|
+
}
|
|
177
|
+
function onMessage(message) {
|
|
178
|
+
let { id, error, data } = message, request = pending.get(id);
|
|
179
|
+
request && (pending.delete(id), error ? request.reject(new Error(error)) : request.resolve(data));
|
|
180
|
+
}
|
|
181
|
+
function $postLoaderMessage(type, data, wait = false) {
|
|
182
|
+
let id = messageId++, message = { id, type, data };
|
|
183
|
+
if (!wait) {
|
|
184
|
+
port2?.postMessage(message);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
return new Promise((resolve2, reject) => {
|
|
188
|
+
if (!port2)
|
|
189
|
+
return reject(new Error("Loader is not initialized"));
|
|
190
|
+
pending.set(id, { resolve: resolve2, reject }), port2.postMessage(message);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function $unloadFile(path) {
|
|
194
|
+
return $postLoaderMessage("unload", resolve(path), true);
|
|
195
|
+
}
|
|
165
196
|
|
|
166
197
|
// src/core/structures/param/Param.ts
|
|
167
198
|
var BaseParam = class {
|
|
@@ -475,7 +506,7 @@ var CommandManager = class extends BaseClientManager {
|
|
|
475
506
|
*/
|
|
476
507
|
async unload(path) {
|
|
477
508
|
let command = this.entries.get(path);
|
|
478
|
-
if (this.entries.delete(path),
|
|
509
|
+
if (this.entries.delete(path), await $unloadFile(path), !!command)
|
|
479
510
|
return this.remove(command);
|
|
480
511
|
}
|
|
481
512
|
async reload(path) {
|
|
@@ -572,7 +603,7 @@ var ListenerManager = class extends BaseClientManager {
|
|
|
572
603
|
*/
|
|
573
604
|
async unload(path) {
|
|
574
605
|
let listener = this.entries.get(path);
|
|
575
|
-
if (this.entries.delete(path),
|
|
606
|
+
if (this.entries.delete(path), await $unloadFile(path), !!listener)
|
|
576
607
|
return this.remove(listener)?.[0];
|
|
577
608
|
}
|
|
578
609
|
async reload(path) {
|
|
@@ -931,4 +962,4 @@ var Params = {
|
|
|
931
962
|
user: createFactory(UserParam)
|
|
932
963
|
};
|
|
933
964
|
|
|
934
|
-
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 };
|
|
965
|
+
export { $initLoader, $postLoaderMessage, $unloadFile, 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 };
|
package/dist/register.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bakit",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.23",
|
|
4
4
|
"description": "A framework for discord.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"import": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts"
|
|
10
10
|
},
|
|
11
|
-
"./
|
|
11
|
+
"./register": "./dist/register.js"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsup",
|
package/dist/loader/register.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { register } from 'module';
|
|
2
|
-
import { MessageChannel } from 'worker_threads';
|
|
3
|
-
|
|
4
|
-
// src/loader/register.ts
|
|
5
|
-
var { port1, port2 } = new MessageChannel(), hookPath = new URL("./hooks.js", import.meta.url).href;
|
|
6
|
-
register(hookPath, import.meta.url, {
|
|
7
|
-
data: { port: port1 },
|
|
8
|
-
transferList: [port1]
|
|
9
|
-
});
|
|
10
|
-
function unload(module) {
|
|
11
|
-
port2.postMessage({ type: "unload", target: module });
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { unload };
|