bakit 2.0.0-alpha.13 → 2.0.0-alpha.14
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/bin/bakit.js +4 -15
- package/dist/index.d.ts +0 -1
- package/dist/index.js +13 -25
- package/package.json +1 -1
package/dist/bin/bakit.js
CHANGED
|
@@ -2,17 +2,14 @@ import { config } from 'dotenv';
|
|
|
2
2
|
import { program } from 'commander';
|
|
3
3
|
import { fork } from 'child_process';
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
|
-
import path, { relative, sep } from 'path';
|
|
5
|
+
import path, { resolve, relative, sep } from 'path';
|
|
6
6
|
import { createJiti } from 'jiti';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
7
|
|
|
9
8
|
// src/bin/bakit.ts
|
|
10
9
|
var Module = class {
|
|
11
10
|
static jiti = createJiti(process.cwd());
|
|
12
11
|
static async import(module, defaultImport = false) {
|
|
13
|
-
let path2 =
|
|
14
|
-
if (!path2)
|
|
15
|
-
return null;
|
|
12
|
+
let path2 = resolve(module);
|
|
16
13
|
try {
|
|
17
14
|
return await this.jiti.import(path2, { default: defaultImport });
|
|
18
15
|
} catch (error) {
|
|
@@ -20,21 +17,13 @@ var Module = class {
|
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
static isLoaded(module) {
|
|
23
|
-
let path2 =
|
|
20
|
+
let path2 = resolve(module);
|
|
24
21
|
return !!path2 && !!this.jiti.cache[path2];
|
|
25
22
|
}
|
|
26
23
|
static unload(module) {
|
|
27
|
-
let path2 =
|
|
24
|
+
let path2 = resolve(module);
|
|
28
25
|
return !path2 || !this.jiti.cache[path2] ? false : (delete this.jiti.cache[path2], true);
|
|
29
26
|
}
|
|
30
|
-
static resolve(module) {
|
|
31
|
-
try {
|
|
32
|
-
let url = this.jiti.esmResolve(module);
|
|
33
|
-
return fileURLToPath(url);
|
|
34
|
-
} catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
27
|
static getTopLevel(path2, entryDir) {
|
|
39
28
|
return relative(entryDir, path2).split(sep)[0] ?? null;
|
|
40
29
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,6 @@ declare class Module {
|
|
|
45
45
|
static import<T>(module: string, defaultImport?: boolean): Promise<T | null>;
|
|
46
46
|
static isLoaded(module: string): boolean;
|
|
47
47
|
static unload(module: string): boolean;
|
|
48
|
-
static resolve(module: string): string | null;
|
|
49
48
|
static getTopLevel(path: string, entryDir: string): string | null;
|
|
50
49
|
}
|
|
51
50
|
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,7 @@ import { GatewayIntentBits, Events, Client, Collection, IntentsBitField, SlashCo
|
|
|
2
2
|
import z4, { z } from 'zod';
|
|
3
3
|
import glob from 'tiny-glob';
|
|
4
4
|
import { createJiti } from 'jiti';
|
|
5
|
-
import {
|
|
6
|
-
import path, { relative, sep, posix, join, dirname } from 'path';
|
|
5
|
+
import path, { resolve, relative, sep, posix, join, dirname } from 'path';
|
|
7
6
|
import { inspect } from 'util';
|
|
8
7
|
import { fork } from 'child_process';
|
|
9
8
|
import chokidar from 'chokidar';
|
|
@@ -138,9 +137,7 @@ function extractSnowflakeId(input) {
|
|
|
138
137
|
var Module = class {
|
|
139
138
|
static jiti = createJiti(process.cwd());
|
|
140
139
|
static async import(module, defaultImport = false) {
|
|
141
|
-
let path2 =
|
|
142
|
-
if (!path2)
|
|
143
|
-
return null;
|
|
140
|
+
let path2 = resolve(module);
|
|
144
141
|
try {
|
|
145
142
|
return await this.jiti.import(path2, { default: defaultImport });
|
|
146
143
|
} catch (error) {
|
|
@@ -148,21 +145,13 @@ var Module = class {
|
|
|
148
145
|
}
|
|
149
146
|
}
|
|
150
147
|
static isLoaded(module) {
|
|
151
|
-
let path2 =
|
|
148
|
+
let path2 = resolve(module);
|
|
152
149
|
return !!path2 && !!this.jiti.cache[path2];
|
|
153
150
|
}
|
|
154
151
|
static unload(module) {
|
|
155
|
-
let path2 =
|
|
152
|
+
let path2 = resolve(module);
|
|
156
153
|
return !path2 || !this.jiti.cache[path2] ? false : (delete this.jiti.cache[path2], true);
|
|
157
154
|
}
|
|
158
|
-
static resolve(module) {
|
|
159
|
-
try {
|
|
160
|
-
let url = this.jiti.esmResolve(module);
|
|
161
|
-
return fileURLToPath(url);
|
|
162
|
-
} catch {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
155
|
static getTopLevel(path2, entryDir) {
|
|
167
156
|
return relative(entryDir, path2).split(sep)[0] ?? null;
|
|
168
157
|
}
|
|
@@ -194,7 +183,10 @@ var ProjectConfigSchema = z.object({
|
|
|
194
183
|
function defineConfig(config) {
|
|
195
184
|
return config;
|
|
196
185
|
}
|
|
186
|
+
var _config;
|
|
197
187
|
async function loadConfig(cwd = process.cwd()) {
|
|
188
|
+
if (_config)
|
|
189
|
+
return console.warn("loadConfig() was called more than once. This shouldn't happen."), _config;
|
|
198
190
|
let globPattern = `bakit.config.{${["ts", "js"].join(",")}}`, [configPath, other] = await glob(globPattern, {
|
|
199
191
|
cwd: cwd.replace(/\\/g, "/"),
|
|
200
192
|
// ensure the path uses `/` instead of `\` on Windows
|
|
@@ -204,10 +196,12 @@ async function loadConfig(cwd = process.cwd()) {
|
|
|
204
196
|
throw new Error("Missing config file");
|
|
205
197
|
other && console.warn(`Multiple config files found in ${cwd}. Using ${configPath}.`);
|
|
206
198
|
let config = await Module.import(configPath, true);
|
|
207
|
-
return Object.freeze(await ProjectConfigSchema.parseAsync(config));
|
|
199
|
+
return _config = Object.freeze(await ProjectConfigSchema.parseAsync(config)), _config;
|
|
208
200
|
}
|
|
209
201
|
function getConfig() {
|
|
210
|
-
|
|
202
|
+
if (!_config)
|
|
203
|
+
throw new Error("Project config is not loaded.");
|
|
204
|
+
return _config;
|
|
211
205
|
}
|
|
212
206
|
|
|
213
207
|
// src/base/lifecycle/Context.ts
|
|
@@ -595,10 +589,7 @@ var CommandManager = class extends BaseClientManager {
|
|
|
595
589
|
commands = new Collection();
|
|
596
590
|
entries = new Collection();
|
|
597
591
|
async loadModules(entryDir) {
|
|
598
|
-
let pattern = posix.join(posix.resolve(entryDir), "commands", "**/*.{ts,js}"), files = await glob(pattern, {
|
|
599
|
-
cwd: process.cwd(),
|
|
600
|
-
absolute: true
|
|
601
|
-
}), filtered = (await Promise.all(files.map((file) => this.load(file)))).filter((c) => !!c);
|
|
592
|
+
let pattern = posix.join(posix.resolve(entryDir), "commands", "**/*.{ts,js}"), files = await glob(pattern, { cwd: process.cwd() }), filtered = (await Promise.all(files.map((file) => this.load(file)))).filter((c) => !!c);
|
|
602
593
|
return console.log(`[Loader] Loaded ${filtered.length}/${files.length}`), filtered;
|
|
603
594
|
}
|
|
604
595
|
/**
|
|
@@ -681,10 +672,7 @@ var ListenerManager = class extends BaseClientManager {
|
|
|
681
672
|
entries = new Collection();
|
|
682
673
|
executors = /* @__PURE__ */ new WeakMap();
|
|
683
674
|
async loadModules(entryDir) {
|
|
684
|
-
let pattern = posix.join(posix.resolve(entryDir), "listeners", "**/*.{ts,js}"), files = await glob(pattern, {
|
|
685
|
-
cwd: process.cwd(),
|
|
686
|
-
absolute: true
|
|
687
|
-
}), filtered = (await Promise.all(files.map((file) => this.load(file)))).filter((l) => !!l);
|
|
675
|
+
let pattern = posix.join(posix.resolve(entryDir), "listeners", "**/*.{ts,js}"), files = await glob(pattern, { cwd: process.cwd() }), filtered = (await Promise.all(files.map((file) => this.load(file)))).filter((l) => !!l);
|
|
688
676
|
return console.log(`[Loader] Loaded ${filtered.length}/${files.length}`), filtered;
|
|
689
677
|
}
|
|
690
678
|
/**
|