bakit 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +81 -0
- package/dist/index.d.ts +256 -106
- package/dist/index.js +753 -258
- package/dist/loader/hooks.js +75 -0
- package/dist/loader/register.js +14 -0
- package/package.json +17 -6
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { Module } from 'module';
|
|
4
|
+
import { dirname, resolve as resolve$1, basename } from 'path';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
|
+
|
|
7
|
+
// src/loader/hooks.ts
|
|
8
|
+
var EXTENSIONS = [".js", ".ts"], inDev = false, parentPort, versions, esbuild;
|
|
9
|
+
async function initialize({ port }) {
|
|
10
|
+
inDev = process.env.NODE_ENV === "development", inDev && (parentPort = port, parentPort.on("message", onMessage), versions = /* @__PURE__ */ new Map(), esbuild = await import('esbuild'));
|
|
11
|
+
}
|
|
12
|
+
async function resolve(specifier, context, nextResolve) {
|
|
13
|
+
if (shouldSkip(specifier))
|
|
14
|
+
return nextResolve(specifier, context);
|
|
15
|
+
let url = specifier, parentURL = context.parentURL?.split("?")[0], baseDir = parentURL ? dirname(fileURLToPath(parentURL)) : process.cwd();
|
|
16
|
+
if (specifier.startsWith(".")) {
|
|
17
|
+
let absPath = resolve$1(baseDir, specifier);
|
|
18
|
+
if (!existsSync(absPath) && absPath.endsWith(".js")) {
|
|
19
|
+
let tsPath = absPath.slice(0, -3) + ".ts";
|
|
20
|
+
existsSync(tsPath) && (absPath = tsPath);
|
|
21
|
+
}
|
|
22
|
+
url = pathToFileURL(absPath).href;
|
|
23
|
+
}
|
|
24
|
+
let urlObj = new URL(url);
|
|
25
|
+
if (inDev) {
|
|
26
|
+
let filePath = fileURLToPath(urlObj), version = createVersion(filePath);
|
|
27
|
+
urlObj.searchParams.set("hmr", version), parentURL && parentPort && parentPort.postMessage({
|
|
28
|
+
type: "dependency",
|
|
29
|
+
parent: parentURL,
|
|
30
|
+
child: url
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
url: urlObj.href,
|
|
35
|
+
shortCircuit: true,
|
|
36
|
+
format: "module"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function load(url, context, nextLoad) {
|
|
40
|
+
if (shouldSkip(url))
|
|
41
|
+
return nextLoad(url, context);
|
|
42
|
+
let cleanURL = url.split("?")[0], filePath = fileURLToPath(cleanURL ?? "");
|
|
43
|
+
if (filePath.endsWith(".ts") && esbuild) {
|
|
44
|
+
let raw = await readFile(filePath, "utf8");
|
|
45
|
+
return {
|
|
46
|
+
source: (await esbuild.transform(raw, {
|
|
47
|
+
platform: "node",
|
|
48
|
+
sourcefile: filePath,
|
|
49
|
+
sourcemap: "inline",
|
|
50
|
+
loader: "ts"
|
|
51
|
+
})).code,
|
|
52
|
+
format: "module",
|
|
53
|
+
shortCircuit: true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return nextLoad(url, context);
|
|
57
|
+
}
|
|
58
|
+
function createVersion(filename) {
|
|
59
|
+
let version = versions?.get(filename);
|
|
60
|
+
return version || (version = Date.now().toString(), versions?.set(filename, version)), version;
|
|
61
|
+
}
|
|
62
|
+
function shouldSkip(specifier) {
|
|
63
|
+
if (Module.isBuiltin(specifier))
|
|
64
|
+
return true;
|
|
65
|
+
if (specifier.startsWith(".") || specifier.startsWith("file://")) {
|
|
66
|
+
let filePath = specifier.startsWith("file://") ? fileURLToPath(specifier) : specifier, filename = basename(filePath);
|
|
67
|
+
return !EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
function onMessage(message) {
|
|
72
|
+
message.type === "unload" && versions?.delete(fileURLToPath(message.target));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { initialize, load, resolve };
|
|
@@ -0,0 +1,14 @@
|
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bakit",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.20",
|
|
4
4
|
"description": "A framework for discord.js",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./loader/*": "./dist/loader/*.js"
|
|
12
|
+
},
|
|
8
13
|
"scripts": {
|
|
9
14
|
"build": "tsup",
|
|
10
15
|
"type-check": "tsc --noEmit",
|
|
11
16
|
"test": "vitest run --pass-with-no-tests"
|
|
12
17
|
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"bakit": "./dist/cli.js"
|
|
20
|
+
},
|
|
13
21
|
"files": [
|
|
14
22
|
"dist"
|
|
15
23
|
],
|
|
@@ -33,12 +41,15 @@
|
|
|
33
41
|
"peerDependencies": {
|
|
34
42
|
"discord.js": "^14.0.0"
|
|
35
43
|
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"esbuild": "^0.27.0"
|
|
46
|
+
},
|
|
36
47
|
"dependencies": {
|
|
48
|
+
"chokidar": "^5.0.0",
|
|
49
|
+
"commander": "^14.0.2",
|
|
50
|
+
"dotenv": "^17.2.1",
|
|
37
51
|
"tiny-glob": "^0.2.9",
|
|
38
52
|
"type-fest": "^4.41.0",
|
|
39
53
|
"zod": "^4.1.12"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@swc/core": "^1.13.5"
|
|
43
54
|
}
|
|
44
55
|
}
|