@jskit-ai/shell-web 0.1.252 → 0.1.254
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/README.md +5 -79
- package/package.json +6 -7
- package/src/architecture/cli.js +1 -33
- package/src/architecture/inspectVueArchitecture.js +1 -1156
- package/test/architecture.test.js +0 -154
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { mkdtemp, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import { inspectVueArchitecture } from "../src/architecture/inspectVueArchitecture.js";
|
|
8
|
-
|
|
9
|
-
async function fixture(t, source, discovery) {
|
|
10
|
-
const root = await mkdtemp(path.join(os.tmpdir(), "jskit-architecture-"));
|
|
11
|
-
t.after(() => rm(root, { recursive: true, force: true }));
|
|
12
|
-
const files = [];
|
|
13
|
-
for (const [file, text] of Object.entries(source)) {
|
|
14
|
-
await mkdir(path.dirname(path.join(root, file)), { recursive: true });
|
|
15
|
-
await writeFile(path.join(root, file), text);
|
|
16
|
-
files.push({ path: file, hash: `sha256:${createHash("sha256").update(text).digest("hex")}` });
|
|
17
|
-
}
|
|
18
|
-
return { root, input: { schema: "vibe64.architecture-inspection-input.v1", files, uiDiscovery: { discoveries: [discovery] } } };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
test('source import evidence resolves configured aliases and project-root paths without treating every target export as imported', async t => {
|
|
22
|
-
const { root, input } = await fixture(t, {
|
|
23
|
-
'src/tools.js': 'export function run() {} export function internal() {}',
|
|
24
|
-
'src/use.vue': '<template>Use</template>\n<script setup>import { run as invoke } from "@/tools.js"; import * as tools from "/src/tools.js"; invoke();</script>',
|
|
25
|
-
'outside.js': 'import { run } from "@/tools.js";',
|
|
26
|
-
}, { id: 'unused', adapter: 'native', surface: 'app', mode: 'registered', registrations: [], pageRoots: [] });
|
|
27
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input, aliases: { '@': 'src' } });
|
|
28
|
-
assert.equal(result.imports.length, 3);
|
|
29
|
-
assert.ok(result.imports.every(use => use.targetFile === 'src/tools.js' && use.resolution === 'resolved'));
|
|
30
|
-
assert.deepEqual(result.imports.map(use => use.names).sort(), [['*'], ['run'], ['run']].sort());
|
|
31
|
-
assert.equal(result.imports.some(use => use.names.includes('internal')), false);
|
|
32
|
-
for (const use of result.imports) {
|
|
33
|
-
const range = use.evidence[0];
|
|
34
|
-
const line = (await readFile(path.join(root, range.path), 'utf8')).split('\n')[range.start.line - 1];
|
|
35
|
-
assert.match(line.slice(range.start.column - 1, range.end.column - 1), /^import /);
|
|
36
|
-
}
|
|
37
|
-
assert.equal(result.inputs.some(file => file.path.startsWith('node_modules/')), false);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('binary asset imports do not prevent route and cross-file import inspection', async t => {
|
|
41
|
-
const { root, input } = await fixture(t, {
|
|
42
|
-
'routes.js': 'import { createRouter } from "vue-router"; import Screen from "./Screen.vue"; createRouter({ routes: [{ path: "/", component: Screen }] });',
|
|
43
|
-
'Screen.vue': '<script setup>import image from "@/image.png";</script><template><img :src="image" /></template>',
|
|
44
|
-
'src/image.png': Buffer.from([0x89, 0x50, 0x4e, 0x47, 0xff, 0x00]),
|
|
45
|
-
}, { id: 'app', adapter: 'vue-registered-router', surface: 'app', mode: 'registered', registrations: ['routes.js'], pageRoots: [] });
|
|
46
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input, aliases: { '@': 'src' } });
|
|
47
|
-
assert.equal(result.pages.length, 1);
|
|
48
|
-
assert.equal(result.pages[0].file, 'Screen.vue');
|
|
49
|
-
assert.ok(result.imports.some(use => use.targetFile === 'src/image.png' && use.names.includes('default')));
|
|
50
|
-
assert.ok(result.inputs.some(file => file.path === 'src/image.png' && file.hash === input.files.find(file => file.path === 'src/image.png').hash));
|
|
51
|
-
assert.deepEqual(result.diagnostics, []);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("explicit registered routes discover real pages and referenced shared elements", async t => {
|
|
55
|
-
const source = {
|
|
56
|
-
"routes.ts": 'import { createRouter } from "vue-router";\nimport Checkout from "./views/Checkout.vue";\nconst routes = [{ path: "/shop", component: Checkout, children: [{ path: "detail", component: () => import("./views/Detail.vue") }] }];\ncreateRouter({ routes });\n',
|
|
57
|
-
"views/Checkout.vue": '<template><SharedForm /></template>\n<script setup>import SharedForm from "../packages/payments/SharedForm.vue"; import Unused from "../Unused.vue";</script>\n',
|
|
58
|
-
"views/Detail.vue": '<template>Detail</template>\n',
|
|
59
|
-
"packages/payments/SharedForm.vue": '<template><button @click="save">Save</button></template>\n<script setup>async function save() { await fetch("/api/save", { method: "POST" }); } function unused() { fetch("/api/unused"); }</script>\n',
|
|
60
|
-
"Unused.vue": '<template>Unused</template>\n',
|
|
61
|
-
"engine/Feature.js": 'import { defineFeature } from "@jskit-ai/kernel/server/features";\nexport const feature = defineFeature({ setup({ http }) { http.router.register("POST", "/save", {}, async () => ({ ok: true })); } });\n',
|
|
62
|
-
};
|
|
63
|
-
const { root, input } = await fixture(t, source, { id: "shop", adapter: "vue-registered-router", surface: "app", mode: "registered", registrations: ["routes.ts"], pageRoots: [], componentRoots: [] });
|
|
64
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input, httpScope: "shop", apiBasePath: "/api" });
|
|
65
|
-
assert.equal(result.pages.length, 2);
|
|
66
|
-
assert.equal(result.registrations[1].identity, "/shop/detail");
|
|
67
|
-
assert.equal(result.pages.find(page => page.file === "views/Detail.vue").parentId, result.pages.find(page => page.file === "views/Checkout.vue").id);
|
|
68
|
-
assert.deepEqual(result.components.map(component => component.file), ["packages/payments/SharedForm.vue"]);
|
|
69
|
-
assert.equal(result.operationUses.length, 1);
|
|
70
|
-
assert.equal(result.operationUses[0].key.operation, "/api/save");
|
|
71
|
-
assert.deepEqual(result.entryOperations[0].key, result.operationUses[0].key);
|
|
72
|
-
assert.equal(result.entryOperations[0].controllerFile, "engine/Feature.js");
|
|
73
|
-
const use = result.componentUses[0];
|
|
74
|
-
const range = use.evidence[0];
|
|
75
|
-
assert.equal(source[range.path].split("\n")[range.start.line - 1].slice(range.start.column - 1, range.end.column - 1), "<SharedForm />");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("filesystem routing reuses the Vue Router scanner without generated files or watchers", async t => {
|
|
79
|
-
const { root, input } = await fixture(t, {
|
|
80
|
-
"vite.config.mjs": 'import VueRouter from "vue-router/vite";\nVueRouter({ routesFolder: "pages", dts: "generated-router.d.ts", nestedChildren: false });\n',
|
|
81
|
-
"pages/shop.vue": '<template><router-view /></template>\n',
|
|
82
|
-
"pages/shop/index.vue": '<template>Shop index</template>\n',
|
|
83
|
-
"pages/shop/[id].vue": '<template>Shop detail</template>\n',
|
|
84
|
-
"pages/shop/helper.ts": 'export const helper = true;\n',
|
|
85
|
-
}, { id: "shop", adapter: "jskit", surface: "app", mode: "filesystem", registrations: ["vite.config.mjs"], pageRoots: ["pages"], componentRoots: [] });
|
|
86
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input });
|
|
87
|
-
assert.equal(result.pages.length, 3);
|
|
88
|
-
assert.equal(result.pages.find(page => page.file === "pages/shop/index.vue").title, "shop");
|
|
89
|
-
assert.ok(result.registrations.some(registration => registration.identity.includes(":id")));
|
|
90
|
-
assert.equal(result.pages.some(page => page.file.endsWith("helper.ts")), false);
|
|
91
|
-
await assert.rejects(readFile(path.join(root, "generated-router.d.ts")), { code: "ENOENT" });
|
|
92
|
-
assert.deepEqual((await readdir(root)).sort(), ["pages", "vite.config.mjs"]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test("dynamic registration and unsupported routing adapters do not invent pages", async t => {
|
|
96
|
-
const { root, input } = await fixture(t, { "routes.js": 'import { createRouter } from "vue-router"; createRouter({ routes: makeRoutes() });\n' }, { id: "dynamic", adapter: "vue-registered-router", surface: "app", mode: "registered", registrations: ["routes.js"], pageRoots: [] });
|
|
97
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input });
|
|
98
|
-
assert.equal(result.pages.length, 0);
|
|
99
|
-
assert.equal(result.capabilities.pages, "unsupported");
|
|
100
|
-
assert.ok(result.diagnostics.some(diagnostic => diagnostic.code === "ROUTES_DYNAMIC"));
|
|
101
|
-
input.uiDiscovery.discoveries[0].adapter = "native-scenes";
|
|
102
|
-
const other = await inspectVueArchitecture({ projectRoot: root, input });
|
|
103
|
-
assert.equal(other.pages.length, 0);
|
|
104
|
-
assert.equal(other.capabilities.pages, "unsupported");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('actual library component uses reference the declared package boundary without opening its internals', async t => {
|
|
108
|
-
const { root, input } = await fixture(t, {
|
|
109
|
-
'routes.js': 'import { createRouter } from "vue-router"; import Screen from "./Screen.vue"; createRouter({ routes: [{ path: "/", component: Screen }] });',
|
|
110
|
-
'Screen.vue': '<template><LibraryButton /></template>\n<script setup>import { Button as LibraryButton, Unused } from "widgets";</script>',
|
|
111
|
-
}, { id: 'library', adapter: 'vue-registered-router', surface: 'app', mode: 'registered', registrations: ['routes.js'], pageRoots: [] });
|
|
112
|
-
input.packages = [{ id: 'package:widgets', name: 'widgets', root: 'node_modules/widgets', manifest: 'package.json', opaque: true, entryPoints: [{ importPath: '.', file: 'node_modules/widgets/index.js' }] }];
|
|
113
|
-
input.packageIdentity = 'inspected-package-identity';
|
|
114
|
-
const result = await inspectVueArchitecture({ projectRoot: root, input });
|
|
115
|
-
assert.equal(result.packageIdentity, input.packageIdentity);
|
|
116
|
-
assert.equal(result.components.length, 1);
|
|
117
|
-
assert.equal(result.components[0].file, null);
|
|
118
|
-
assert.deepEqual(result.components[0].origin, { kind: 'package', packageId: 'package:widgets', importPath: '.', symbol: 'Button' });
|
|
119
|
-
assert.equal(result.componentUses[0].componentId, result.components[0].id);
|
|
120
|
-
assert.equal(result.inputs.some(entry => entry.path.startsWith('node_modules/')), false);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
test('used CRUD screens resolve resources through workspace barrels to exported controller declarations', async t => {
|
|
125
|
-
const source = {
|
|
126
|
-
'package.json': '{}',
|
|
127
|
-
'routes.js': 'import { createRouter } from "vue-router"; import Screen from "./Screen.vue"; createRouter({ routes: [{ path: "/new", component: Screen }] });',
|
|
128
|
-
'Screen.vue': '<template><CrudAddEditScreen :screen="screen" /></template>\n<script setup>import CrudAddEditScreen from "@jskit-ai/http-web/client/components/CrudAddEditScreen"; import { useCrudAddEditScreen } from "@jskit-ai/http-web/client/composables/useCrudAddEditScreen"; import { resource } from "@local/resource/shared"; const screen = useCrudAddEditScreen({ resource, operationName: "create", addEditOptions: { apiSuffix: "/names" } }); const unused = useCrudAddEditScreen({ resource, operationName: "view" });</script>',
|
|
129
|
-
'packages/resource/shared.js': 'export { resource } from "./resource.js";',
|
|
130
|
-
'packages/resource/resource.js': 'import { defineCrudResource } from "@jskit-ai/resource-crud-core/shared/crudResource"; export const resource = defineCrudResource({ namespace: "names", tableName: "names", crudOperations: ["list", "create"] });',
|
|
131
|
-
'packages/resource/Feature.js': 'import { defineCrudJsonApiFeature } from "@jskit-ai/crud-core/server/defineCrudJsonApiFeature"; import { resource } from "./resource.js"; export const NamesFeature = defineCrudJsonApiFeature({ resource, surface: "home", relativePath: "/names" });',
|
|
132
|
-
'packages/resource/Disabled.js': 'import { defineCrudJsonApiFeature } from "@jskit-ai/crud-core/server/defineCrudJsonApiFeature"; import { resource } from "./resource.js"; export const Disabled = defineCrudJsonApiFeature({ resource, surface: "home", routes: false });',
|
|
133
|
-
};
|
|
134
|
-
const { root, input } = await fixture(t, source, { id: 'crud', adapter: 'vue-registered-router', surface: 'home', mode: 'registered', registrations: ['routes.js'] });
|
|
135
|
-
input.packages = [{ id: 'package:local', name: '@local/resource', root: 'packages/resource', manifest: 'package.json', opaque: false, entryPoints: [{ importPath: './shared', file: 'packages/resource/shared.js' }] }];
|
|
136
|
-
const options = { projectRoot: root, input, httpScope: 'app' };
|
|
137
|
-
const result = await inspectVueArchitecture(options);
|
|
138
|
-
assert.equal(result.operationUses.length, 1);
|
|
139
|
-
assert.equal(result.entryOperations.length, 2);
|
|
140
|
-
const receiving = result.entryOperations.find(entry => entry.key.operation === 'names:create');
|
|
141
|
-
assert.deepEqual(receiving.key, result.operationUses[0].key);
|
|
142
|
-
assert.equal(receiving.controllerFile, 'packages/resource/Feature.js');
|
|
143
|
-
assert.ok(result.operationUses[0].evidence.some(entry => entry.path === 'packages/resource/resource.js'));
|
|
144
|
-
assert.ok(!result.entryOperations.some(entry => entry.controllerFile.endsWith('Disabled.js')));
|
|
145
|
-
await writeFile(path.join(root, 'Screen.vue'), source['Screen.vue'].replace('apiSuffix: "/names"', 'apiSuffix: "/other"'));
|
|
146
|
-
input.files.find(entry => entry.path === 'Screen.vue').hash = `sha256:${createHash('sha256').update(await readFile(path.join(root, 'Screen.vue'))).digest('hex')}`;
|
|
147
|
-
const otherPath = await inspectVueArchitecture(options);
|
|
148
|
-
assert.notDeepEqual(receiving.key, otherPath.operationUses[0].key);
|
|
149
|
-
await writeFile(path.join(root, 'Screen.vue'), source['Screen.vue'].replace('resource, operationName: "create"', 'resource, operationName: "create", client: alternateClient'));
|
|
150
|
-
input.files.find(entry => entry.path === 'Screen.vue').hash = `sha256:${createHash('sha256').update(await readFile(path.join(root, 'Screen.vue'))).digest('hex')}`;
|
|
151
|
-
const dynamic = await inspectVueArchitecture(options);
|
|
152
|
-
assert.equal(dynamic.operationUses[0].resolution, 'unresolved');
|
|
153
|
-
assert.equal(dynamic.operationUses[0].key, undefined);
|
|
154
|
-
});
|