@mantaq/inspect 0.0.0-stage → 0.1.0
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/README.md +94 -2
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +86 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.mjs +3 -0
- package/dist/inspect-DvQtAcwv.d.mts +66 -0
- package/dist/load-C4rGWmGU.mjs +1790 -0
- package/dist/page-rr9IQ-4k.mjs +38 -0
- package/dist/vite.d.mts +11 -0
- package/dist/vite.mjs +102 -0
- package/package.json +50 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { serializeViz, standaloneHtml } from "@mantaq/viz";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { build } from "vite";
|
|
5
|
+
// src/page.ts
|
|
6
|
+
/** The viewer as one classic script, built from `@mantaq/viz/standalone`, plus its stylesheets. */
|
|
7
|
+
async function viewerBundle() {
|
|
8
|
+
const entry = fileURLToPath(import.meta.resolve("@mantaq/viz/standalone"));
|
|
9
|
+
const output = await build({
|
|
10
|
+
configFile: false,
|
|
11
|
+
logLevel: "silent",
|
|
12
|
+
build: {
|
|
13
|
+
write: false,
|
|
14
|
+
minify: true,
|
|
15
|
+
cssCodeSplit: false,
|
|
16
|
+
lib: {
|
|
17
|
+
entry,
|
|
18
|
+
formats: ["iife"],
|
|
19
|
+
name: "MantaqViz",
|
|
20
|
+
fileName: () => "viz.js"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
script: (Array.isArray(output) ? output : [output]).flatMap((each) => "output" in each ? each.output : []).flatMap((file) => file.type === "chunk" ? [file.code] : []).join("\n"),
|
|
26
|
+
css: ["@mantaq/viz/viewer.css", "@mantaq/viz/page.css"].map((id) => readFileSync(fileURLToPath(import.meta.resolve(id)), "utf8")).join("\n")
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** A self-contained HTML page for `document`: open it from disk, attach it, commit it. */
|
|
30
|
+
async function htmlPage(document, title) {
|
|
31
|
+
const bundle = await viewerBundle();
|
|
32
|
+
return standaloneHtml({
|
|
33
|
+
title,
|
|
34
|
+
...bundle,
|
|
35
|
+
document: serializeViz(document)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export { htmlPage as t };
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as FuzzSettings } from "./inspect-DvQtAcwv.mjs";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
export interface MantaqVizOptions {
|
|
4
|
+
/** Files that export machines: paths or globs, relative to the Vite root. */
|
|
5
|
+
machines: string | string[];
|
|
6
|
+
/** Where the page is served. Default `/__mantaq/`. */
|
|
7
|
+
base?: string;
|
|
8
|
+
/** `false` = structure only. Default: 500 iterations, so a save redraws quickly. */
|
|
9
|
+
fuzz?: false | FuzzSettings;
|
|
10
|
+
}
|
|
11
|
+
export declare function mantaqViz(options: MantaqVizOptions): Plugin[];
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { c as vizDocument, i as runOf, n as inspectEntry, t as entryId } from "./load-C4rGWmGU.mjs";
|
|
2
|
+
import { UPDATE_EVENT, livePageHtml, serializeViz } from "@mantaq/viz";
|
|
3
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { globSync, readFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { searchForWorkspaceRoot } from "vite";
|
|
7
|
+
// src/vite.ts
|
|
8
|
+
/**
|
|
9
|
+
* Vite plugin: a live page of your machines on your own dev server.
|
|
10
|
+
*
|
|
11
|
+
* // vite.config.ts
|
|
12
|
+
* import { mantaqViz } from "@mantaq/inspect/vite";
|
|
13
|
+
* export default defineConfig({ plugins: [mantaqViz({ machines: "src/**\/*.machine.ts" })] });
|
|
14
|
+
*
|
|
15
|
+
* Open `/__mantaq/` while the dev server runs. Machines load through your own
|
|
16
|
+
* Vite config (aliases, tsconfig paths), are inspected on the server, and the
|
|
17
|
+
* page redraws, keeping the walk, when you save a file.
|
|
18
|
+
*/
|
|
19
|
+
const STYLESHEETS = ["@mantaq/viz/viewer.css", "@mantaq/viz/page.css"];
|
|
20
|
+
const DEV_ITERATIONS = 500;
|
|
21
|
+
function machineFiles(root, patterns) {
|
|
22
|
+
const files = patterns.flatMap((pattern) => globSync(pattern, { cwd: root }));
|
|
23
|
+
return [...new Set(files.map((file) => isAbsolute(file) ? file : resolve(root, file)))].sort();
|
|
24
|
+
}
|
|
25
|
+
async function documentText(server, context) {
|
|
26
|
+
const results = [];
|
|
27
|
+
for (const file of context.files) {
|
|
28
|
+
const run = runOf(await server.ssrLoadModule(entryId(file)));
|
|
29
|
+
results.push(run === null ? {
|
|
30
|
+
machines: [],
|
|
31
|
+
warnings: [`${file}: could not load the inspector`]
|
|
32
|
+
} : await run({ fuzz: context.fuzz }));
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
text: serializeViz(vizDocument(results.flatMap((result) => result.machines))),
|
|
36
|
+
warnings: results.flatMap((result) => result.warnings)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function mantaqViz(options) {
|
|
40
|
+
const base = (options.base ?? "/__mantaq/").replace(/\/?$/, "/");
|
|
41
|
+
const patterns = Array.isArray(options.machines) ? options.machines : [options.machines];
|
|
42
|
+
const fuzz = options.fuzz ?? { iterations: DEV_ITERATIONS };
|
|
43
|
+
const live = fileURLToPath(import.meta.resolve("@mantaq/viz/live"));
|
|
44
|
+
return [inspectEntry(), {
|
|
45
|
+
name: "mantaq-viz",
|
|
46
|
+
apply: "serve",
|
|
47
|
+
config: (config) => ({ server: { fs: { allow: [searchForWorkspaceRoot(config.root ?? process.cwd()), dirname(dirname(live))] } } }),
|
|
48
|
+
configureServer(server) {
|
|
49
|
+
let cached = null;
|
|
50
|
+
const build = async () => {
|
|
51
|
+
const { text, warnings } = await documentText(server, {
|
|
52
|
+
files: machineFiles(server.config.root, patterns),
|
|
53
|
+
fuzz
|
|
54
|
+
});
|
|
55
|
+
for (const warning of warnings) server.config.logger.warn(`[mantaq-viz] ${warning}`);
|
|
56
|
+
return text;
|
|
57
|
+
};
|
|
58
|
+
server.watcher.on("all", (_event, path) => {
|
|
59
|
+
if (!/\.[cm]?[jt]sx?$/.test(path)) return;
|
|
60
|
+
cached = null;
|
|
61
|
+
server.environments.ssr.moduleGraph.invalidateAll();
|
|
62
|
+
server.ws.send({
|
|
63
|
+
type: "custom",
|
|
64
|
+
event: UPDATE_EVENT
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
server.middlewares.use((request, response, next) => {
|
|
68
|
+
const path = request.url?.split("?")[0];
|
|
69
|
+
if (path === `${base}viz.json`) {
|
|
70
|
+
cached ??= build();
|
|
71
|
+
cached.then((text) => {
|
|
72
|
+
response.setHeader("content-type", "application/json");
|
|
73
|
+
response.end(text);
|
|
74
|
+
}, (error) => {
|
|
75
|
+
cached = null;
|
|
76
|
+
response.statusCode = 500;
|
|
77
|
+
response.end(String(error));
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (path !== base && path !== base.slice(0, -1)) {
|
|
82
|
+
next();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const html = livePageHtml({
|
|
86
|
+
title: "mantaq viz",
|
|
87
|
+
source: `${base}viz.json`,
|
|
88
|
+
entry: `/@fs${live}`,
|
|
89
|
+
css: STYLESHEETS.map((id) => readFileSync(fileURLToPath(import.meta.resolve(id)), "utf8")).join("\n")
|
|
90
|
+
});
|
|
91
|
+
server.transformIndexHtml(request.url ?? base, html).then((page) => {
|
|
92
|
+
response.setHeader("content-type", "text/html");
|
|
93
|
+
response.end(page);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
server.httpServer?.once("listening", () => {
|
|
97
|
+
server.config.logger.info(` mantaq viz: ${base}`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}];
|
|
101
|
+
}
|
|
102
|
+
export { mantaqViz };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mantaq/inspect",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Turn a Mantaq machine into a viz document: structure, handler explanations (AST), fuzz and test coverage. CLI and Vite plugin included.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/AndersCan/mantaq",
|
|
9
|
+
"directory": "packages/inspect"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"mantaq-inspect": "./dist/cli.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.mjs",
|
|
20
|
+
"./vite": "./dist/vite.mjs",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"typescript": "6.0.3",
|
|
28
|
+
"@mantaq/core": "0.5.0",
|
|
29
|
+
"@mantaq/pbt": "0.0.3",
|
|
30
|
+
"@mantaq/traversal": "0.3.0",
|
|
31
|
+
"@mantaq/utils": "0.0.4",
|
|
32
|
+
"@mantaq/viz": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^26.2.0",
|
|
36
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
37
|
+
"happy-dom": "^21.0.4",
|
|
38
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
39
|
+
"vite-plus": "1.4.0",
|
|
40
|
+
"@mantaq/sugar": "2.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vite": "*"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vp pack",
|
|
47
|
+
"dev": "vp pack --watch",
|
|
48
|
+
"test": "vp test",
|
|
49
|
+
"check": "vp check",
|
|
50
|
+
"viz:export": "node src/examples-cli.ts export",
|
|
51
|
+
"viz:compare": "node src/examples-cli.ts compare"
|
|
52
|
+
}
|
|
6
53
|
}
|