@nkzw/fate-devtools 0.0.0-stage → 2.0.1
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/LICENSE +21 -0
- package/lib/index.d.mts +19 -0
- package/lib/index.mjs +1 -0
- package/lib/panel/assets/index-B8BrSDrl.js +13 -0
- package/lib/panel/assets/index-NKFD_JQx.css +1 -0
- package/lib/panel/index.html +13 -0
- package/lib/react.d.mts +10 -0
- package/lib/react.mjs +25 -0
- package/lib/src-BAd3o4sS.mjs +563 -0
- package/lib/vite.d.mts +31 -0
- package/lib/vite.mjs +98 -0
- package/package.json +57 -3
- package/README.md +0 -3
package/lib/vite.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { extname, join, normalize, sep } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
// src/vite.ts
|
|
6
|
+
/**
|
|
7
|
+
* Vite plugin for the fate devtools.
|
|
8
|
+
*
|
|
9
|
+
* Adds a "fate" panel to Vite DevTools and serves the same panel as a
|
|
10
|
+
* standalone page at `/__fate-devtools/`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { fateDevtools } from '@nkzw/fate-devtools/vite';
|
|
14
|
+
*
|
|
15
|
+
* export default defineConfig({
|
|
16
|
+
* devtools: true,
|
|
17
|
+
* plugins: [fateDevtools()],
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* @module @nkzw/fate-devtools/vite
|
|
21
|
+
*/
|
|
22
|
+
const contentTypes = {
|
|
23
|
+
".css": "text/css; charset=utf-8",
|
|
24
|
+
".html": "text/html; charset=utf-8",
|
|
25
|
+
".js": "text/javascript; charset=utf-8",
|
|
26
|
+
".json": "application/json; charset=utf-8",
|
|
27
|
+
".svg": "image/svg+xml"
|
|
28
|
+
};
|
|
29
|
+
const icon = `data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\"><rect width=\"64\" height=\"64\" rx=\"18\" fill=\"#3d87f5\"/><text x=\"18\" y=\"47\" fill=\"white\" font-family=\"Georgia,serif\" font-style=\"italic\" font-size=\"52\">f</text></svg>")}`;
|
|
30
|
+
const findPanelDirectory = () => {
|
|
31
|
+
const candidates = [new URL("./panel/", import.meta.url), new URL("../lib/panel/", import.meta.url)];
|
|
32
|
+
for (const candidate of candidates) {
|
|
33
|
+
const directory = fileURLToPath(candidate);
|
|
34
|
+
if (existsSync(join(directory, "index.html"))) return directory;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Registers the fate panel with Vite DevTools and serves it during development.
|
|
40
|
+
*/
|
|
41
|
+
function fateDevtools({ base = "/__fate-devtools/" } = {}) {
|
|
42
|
+
const mountPath = base.endsWith("/") ? base : `${base}/`;
|
|
43
|
+
return {
|
|
44
|
+
apply: "serve",
|
|
45
|
+
configureServer(server) {
|
|
46
|
+
const directory = findPanelDirectory();
|
|
47
|
+
server.middlewares.use(async (request, response, next) => {
|
|
48
|
+
const url = request.url?.split("?")[0];
|
|
49
|
+
if (!url || url !== mountPath.slice(0, -1) && !url.startsWith(mountPath)) return next();
|
|
50
|
+
if (!directory) {
|
|
51
|
+
response.statusCode = 500;
|
|
52
|
+
response.end("fate-devtools: The panel has not been built. Run `vp run build` in @nkzw/fate-devtools.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (url === mountPath.slice(0, -1)) {
|
|
56
|
+
response.statusCode = 302;
|
|
57
|
+
response.setHeader("Location", mountPath);
|
|
58
|
+
response.end();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let path;
|
|
62
|
+
try {
|
|
63
|
+
path = decodeURIComponent(url.slice(mountPath.length));
|
|
64
|
+
} catch {
|
|
65
|
+
response.statusCode = 400;
|
|
66
|
+
response.end();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const file = normalize(join(directory, path || "index.html"));
|
|
70
|
+
if (!file.startsWith(directory.endsWith(sep) ? directory : directory + sep)) {
|
|
71
|
+
response.statusCode = 403;
|
|
72
|
+
response.end();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const body = await readFile(existsSync(file) ? file : join(directory, "index.html"));
|
|
77
|
+
response.setHeader("Content-Type", contentTypes[extname(file)] ?? "application/octet-stream");
|
|
78
|
+
response.setHeader("Cache-Control", "no-cache");
|
|
79
|
+
response.end(body);
|
|
80
|
+
} catch {
|
|
81
|
+
next();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
devtools: { setup(context) {
|
|
86
|
+
context.docks.register({
|
|
87
|
+
category: "app",
|
|
88
|
+
icon,
|
|
89
|
+
id: "fate",
|
|
90
|
+
title: "fate",
|
|
91
|
+
type: "iframe",
|
|
92
|
+
url: mountPath
|
|
93
|
+
});
|
|
94
|
+
} },
|
|
95
|
+
name: "fate:devtools"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export { fateDevtools };
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nkzw/fate-devtools",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Devtools for fate, with a Vite DevTools panel.",
|
|
5
|
+
"homepage": "https://github.com/nkzw-tech/fate",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/nkzw-tech/fate"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/index.d.mts",
|
|
19
|
+
"@nkzw/source": "./src/index.ts",
|
|
20
|
+
"default": "./lib/index.mjs"
|
|
21
|
+
},
|
|
22
|
+
"./react": {
|
|
23
|
+
"types": "./lib/react.d.mts",
|
|
24
|
+
"@nkzw/source": "./src/react.tsx",
|
|
25
|
+
"default": "./lib/react.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"types": "./lib/vite.d.mts",
|
|
29
|
+
"@nkzw/source": "./src/vite.ts",
|
|
30
|
+
"default": "./lib/vite.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@nkzw/fate": "2.0.1",
|
|
35
|
+
"@types/react": "19.3.0",
|
|
36
|
+
"@types/react-dom": "19.3.0",
|
|
37
|
+
"react": "19.3.1",
|
|
38
|
+
"react-dom": "19.3.1",
|
|
39
|
+
"react-fate": "2.0.1",
|
|
40
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.6.0",
|
|
41
|
+
"vite-plus": "1.6.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@nkzw/fate": "^2.0.0",
|
|
45
|
+
"react": "^19.2.0",
|
|
46
|
+
"react-fate": "^2.0.0",
|
|
47
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"react": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"react-fate": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"vite": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
6
60
|
}
|
package/README.md
DELETED