@decantr/vite-plugin 0.1.0 → 0.1.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/README.md +32 -0
- package/dist/index.js +33 -46
- package/dist/index.js.map +1 -1
- package/package.json +16 -7
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @decantr/vite-plugin
|
|
2
|
+
|
|
3
|
+
Support status: `supported-secondary`
|
|
4
|
+
Release channel: `experimental`
|
|
5
|
+
|
|
6
|
+
Experimental Vite plugin that surfaces Decantr guard violations in local development.
|
|
7
|
+
|
|
8
|
+
This package is not part of the main Decantr product nucleus and is excluded from the default release wave unless explicitly requested.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -D @decantr/vite-plugin
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { defineConfig } from 'vite';
|
|
20
|
+
import react from '@vitejs/plugin-react';
|
|
21
|
+
import { decantrPlugin } from '@decantr/vite-plugin';
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [react(), decantrPlugin()],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
By default the plugin watches `decantr.essence.json` and re-runs Decantr guard checks as source files change.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -2,48 +2,6 @@
|
|
|
2
2
|
import { join } from "path";
|
|
3
3
|
import { evaluateGuard } from "@decantr/essence-spec";
|
|
4
4
|
|
|
5
|
-
// src/watcher.ts
|
|
6
|
-
import { readFileSync, existsSync } from "fs";
|
|
7
|
-
import { normalizeEssence } from "@decantr/essence-spec";
|
|
8
|
-
function loadEssence(filePath) {
|
|
9
|
-
if (!existsSync(filePath)) return null;
|
|
10
|
-
try {
|
|
11
|
-
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
12
|
-
return normalizeEssence(raw);
|
|
13
|
-
} catch {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
var TRIGGER_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
18
|
-
".ts",
|
|
19
|
-
".tsx",
|
|
20
|
-
".js",
|
|
21
|
-
".jsx",
|
|
22
|
-
".vue",
|
|
23
|
-
".svelte",
|
|
24
|
-
".astro"
|
|
25
|
-
]);
|
|
26
|
-
var IGNORE_PATTERNS = [
|
|
27
|
-
"node_modules",
|
|
28
|
-
".decantr",
|
|
29
|
-
"decantr.essence.json"
|
|
30
|
-
];
|
|
31
|
-
function shouldTriggerGuard(filePath) {
|
|
32
|
-
if (IGNORE_PATTERNS.some((p) => filePath.includes(p))) return false;
|
|
33
|
-
const ext = filePath.slice(filePath.lastIndexOf("."));
|
|
34
|
-
return TRIGGER_EXTENSIONS.has(ext);
|
|
35
|
-
}
|
|
36
|
-
function createDebouncedGuard(callback, delayMs) {
|
|
37
|
-
let timer = null;
|
|
38
|
-
return () => {
|
|
39
|
-
if (timer) clearTimeout(timer);
|
|
40
|
-
timer = setTimeout(() => {
|
|
41
|
-
timer = null;
|
|
42
|
-
callback();
|
|
43
|
-
}, delayMs);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
5
|
// src/overlay.ts
|
|
48
6
|
function formatViolation(v) {
|
|
49
7
|
const layerTag = v.layer ? `[${v.layer === "dna" ? "DNA" : "Blueprint"}] ` : "";
|
|
@@ -76,6 +34,36 @@ function formatViolations(violations) {
|
|
|
76
34
|
};
|
|
77
35
|
}
|
|
78
36
|
|
|
37
|
+
// src/watcher.ts
|
|
38
|
+
import { existsSync, readFileSync } from "fs";
|
|
39
|
+
import { normalizeEssence } from "@decantr/essence-spec";
|
|
40
|
+
function loadEssence(filePath) {
|
|
41
|
+
if (!existsSync(filePath)) return null;
|
|
42
|
+
try {
|
|
43
|
+
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
44
|
+
return normalizeEssence(raw);
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var TRIGGER_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".vue", ".svelte", ".astro"]);
|
|
50
|
+
var IGNORE_PATTERNS = ["node_modules", ".decantr", "decantr.essence.json"];
|
|
51
|
+
function shouldTriggerGuard(filePath) {
|
|
52
|
+
if (IGNORE_PATTERNS.some((p) => filePath.includes(p))) return false;
|
|
53
|
+
const ext = filePath.slice(filePath.lastIndexOf("."));
|
|
54
|
+
return TRIGGER_EXTENSIONS.has(ext);
|
|
55
|
+
}
|
|
56
|
+
function createDebouncedGuard(callback, delayMs) {
|
|
57
|
+
let timer = null;
|
|
58
|
+
return () => {
|
|
59
|
+
if (timer) clearTimeout(timer);
|
|
60
|
+
timer = setTimeout(() => {
|
|
61
|
+
timer = null;
|
|
62
|
+
callback();
|
|
63
|
+
}, delayMs);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
79
67
|
// src/index.ts
|
|
80
68
|
function decantrPlugin(options = {}) {
|
|
81
69
|
const essenceFileName = options.essencePath ?? "decantr.essence.json";
|
|
@@ -95,10 +83,9 @@ function decantrPlugin(options = {}) {
|
|
|
95
83
|
const violations = evaluateGuard(essence, {});
|
|
96
84
|
const overlayError = formatViolations(violations);
|
|
97
85
|
if (overlayError) {
|
|
98
|
-
server.config.logger.warn(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
86
|
+
server.config.logger.warn(`[decantr] ${violations.length} guard violation(s) detected`, {
|
|
87
|
+
timestamp: true
|
|
88
|
+
});
|
|
102
89
|
server.hot.send({
|
|
103
90
|
type: "error",
|
|
104
91
|
err: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/overlay.ts","../src/watcher.ts"],"sourcesContent":["import { join } from 'node:path';\nimport type { EssenceFile } from '@decantr/essence-spec';\nimport { evaluateGuard } from '@decantr/essence-spec';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport { formatViolations } from './overlay.js';\nimport { createDebouncedGuard, loadEssence, shouldTriggerGuard } from './watcher.js';\n\nexport interface DecantrPluginOptions {\n /** Path to the essence file, relative to project root. Default: 'decantr.essence.json' */\n essencePath?: string;\n /** Debounce delay in ms before running guard after a file change. Default: 300 */\n debounceMs?: number;\n}\n\nexport function decantrPlugin(options: DecantrPluginOptions = {}): Plugin {\n const essenceFileName = options.essencePath ?? 'decantr.essence.json';\n const debounceMs = options.debounceMs ?? 300;\n\n let essence: EssenceFile | null = null;\n let root = '';\n\n function runGuard(server: ViteDevServer): void {\n const essencePath = join(root, essenceFileName);\n essence = loadEssence(essencePath);\n\n if (!essence) {\n server.hot.send({\n type: 'error',\n err: { message: '', stack: '', plugin: '@decantr/vite-plugin' },\n });\n return;\n }\n\n const violations = evaluateGuard(essence, {});\n const overlayError = formatViolations(violations);\n\n if (overlayError) {\n server.config.logger.warn(`[decantr] ${violations.length} guard violation(s) detected`, {\n timestamp: true,\n });\n server.hot.send({\n type: 'error',\n err: {\n message: overlayError.message,\n stack: overlayError.frame,\n plugin: overlayError.plugin,\n },\n });\n }\n }\n\n return {\n name: 'decantr-guard',\n\n configureServer(server) {\n root = server.config.root;\n\n const debouncedGuard = createDebouncedGuard(() => runGuard(server), debounceMs);\n\n server.httpServer?.once('listening', () => {\n runGuard(server);\n });\n\n server.watcher.on('change', (filePath: string) => {\n const relative = filePath.startsWith(root) ? filePath.slice(root.length + 1) : filePath;\n\n if (relative === essenceFileName || relative.endsWith('decantr.essence.json')) {\n runGuard(server);\n } else if (shouldTriggerGuard(relative)) {\n debouncedGuard();\n }\n });\n },\n };\n}\n\nexport default decantrPlugin;\nexport type { EssenceFile, GuardContext, GuardViolation } from '@decantr/essence-spec';\n","import type { GuardViolation } from '@decantr/essence-spec';\n\nexport interface OverlayError {\n id: string;\n message: string;\n frame: string;\n plugin: string;\n}\n\nexport function formatViolation(v: GuardViolation): string {\n const layerTag = v.layer ? `[${v.layer === 'dna' ? 'DNA' : 'Blueprint'}] ` : '';\n const fixHint = v.autoFixable ? ' (auto-fixable via decantr_accept_drift)' : '';\n return `${layerTag}[${v.rule}] ${v.message}${fixHint}`;\n}\n\nexport function formatViolations(violations: GuardViolation[]): OverlayError | null {\n if (violations.length === 0) return null;\n\n const errors = violations.filter((v) => v.severity === 'error');\n const warnings = violations.filter((v) => v.severity === 'warning');\n\n const sections: string[] = [];\n\n if (errors.length > 0) {\n sections.push('Errors:');\n for (const v of errors) {\n sections.push(` ${formatViolation(v)}`);\n }\n }\n\n if (warnings.length > 0) {\n if (sections.length > 0) sections.push('');\n sections.push('Warnings:');\n for (const v of warnings) {\n sections.push(` ${formatViolation(v)}`);\n }\n }\n\n return {\n id: 'decantr-guard',\n message: `Decantr: ${violations.length} guard violation${violations.length === 1 ? '' : 's'} detected`,\n frame: sections.join('\\n'),\n plugin: '@decantr/vite-plugin',\n };\n}\n","import { existsSync, readFileSync } from 'node:fs';\nimport type { EssenceFile } from '@decantr/essence-spec';\nimport { normalizeEssence } from '@decantr/essence-spec';\n\nexport function loadEssence(filePath: string): EssenceFile | null {\n if (!existsSync(filePath)) return null;\n\n try {\n const raw = JSON.parse(readFileSync(filePath, 'utf-8'));\n return normalizeEssence(raw);\n } catch {\n return null;\n }\n}\n\nconst TRIGGER_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx', '.vue', '.svelte', '.astro']);\n\nconst IGNORE_PATTERNS = ['node_modules', '.decantr', 'decantr.essence.json'];\n\nexport function shouldTriggerGuard(filePath: string): boolean {\n if (IGNORE_PATTERNS.some((p) => filePath.includes(p))) return false;\n\n const ext = filePath.slice(filePath.lastIndexOf('.'));\n return TRIGGER_EXTENSIONS.has(ext);\n}\n\nexport function createDebouncedGuard(callback: () => void, delayMs: number): () => void {\n let timer: ReturnType<typeof setTimeout> | null = null;\n\n return () => {\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = null;\n callback();\n }, delayMs);\n };\n}\n"],"mappings":";AAAA,SAAS,YAAY;AAErB,SAAS,qBAAqB;;;ACOvB,SAAS,gBAAgB,GAA2B;AACzD,QAAM,WAAW,EAAE,QAAQ,IAAI,EAAE,UAAU,QAAQ,QAAQ,WAAW,OAAO;AAC7E,QAAM,UAAU,EAAE,cAAc,6CAA6C;AAC7E,SAAO,GAAG,QAAQ,IAAI,EAAE,IAAI,KAAK,EAAE,OAAO,GAAG,OAAO;AACtD;AAEO,SAAS,iBAAiB,YAAmD;AAClF,MAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,QAAM,SAAS,WAAW,OAAO,CAAC,MAAM,EAAE,aAAa,OAAO;AAC9D,QAAM,WAAW,WAAW,OAAO,CAAC,MAAM,EAAE,aAAa,SAAS;AAElE,QAAM,WAAqB,CAAC;AAE5B,MAAI,OAAO,SAAS,GAAG;AACrB,aAAS,KAAK,SAAS;AACvB,eAAW,KAAK,QAAQ;AACtB,eAAS,KAAK,KAAK,gBAAgB,CAAC,CAAC,EAAE;AAAA,IACzC;AAAA,EACF;AAEA,MAAI,SAAS,SAAS,GAAG;AACvB,QAAI,SAAS,SAAS,EAAG,UAAS,KAAK,EAAE;AACzC,aAAS,KAAK,WAAW;AACzB,eAAW,KAAK,UAAU;AACxB,eAAS,KAAK,KAAK,gBAAgB,CAAC,CAAC,EAAE;AAAA,IACzC;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS,YAAY,WAAW,MAAM,mBAAmB,WAAW,WAAW,IAAI,KAAK,GAAG;AAAA,IAC3F,OAAO,SAAS,KAAK,IAAI;AAAA,IACzB,QAAQ;AAAA,EACV;AACF;;;AC5CA,SAAS,YAAY,oBAAoB;AAEzC,SAAS,wBAAwB;AAE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B,aAAO,OAAO,OAAO,KAAK,aAAa,WAAW,MAAM,gCAAgC;AAAA,QACtF,WAAW;AAAA,MACb,CAAC;AACD,aAAO,IAAI,KAAK;AAAA,QACd,MAAM;AAAA,QACN,KAAK;AAAA,UACH,SAAS,aAAa;AAAA,UACtB,OAAO,aAAa;AAAA,UACpB,QAAQ,aAAa;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,gBAAgB,QAAQ;AACtB,aAAO,OAAO,OAAO;AAErB,YAAM,iBAAiB,qBAAqB,MAAM,SAAS,MAAM,GAAG,UAAU;AAE9E,aAAO,YAAY,KAAK,aAAa,MAAM;AACzC,iBAAS,MAAM;AAAA,MACjB,CAAC;AAED,aAAO,QAAQ,GAAG,UAAU,CAAC,aAAqB;AAChD,cAAM,WAAW,SAAS,WAAW,IAAI,IAAI,SAAS,MAAM,KAAK,SAAS,CAAC,IAAI;AAE/E,YAAI,aAAa,mBAAmB,SAAS,SAAS,sBAAsB,GAAG;AAC7E,mBAAS,MAAM;AAAA,QACjB,WAAW,mBAAmB,QAAQ,GAAG;AACvC,yBAAe;AAAA,QACjB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decantr/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Vite plugin for
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Experimental Vite plugin for Decantr guard feedback during local development",
|
|
5
|
+
"author": "Decantr AI",
|
|
5
6
|
"license": "MIT",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/decantr-ai/decantr/issues"
|
|
9
|
+
},
|
|
6
10
|
"repository": {
|
|
7
11
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/decantr-ai/decantr.git",
|
|
12
|
+
"url": "git+https://github.com/decantr-ai/decantr.git",
|
|
9
13
|
"directory": "packages/vite-plugin"
|
|
10
14
|
},
|
|
15
|
+
"homepage": "https://decantr.ai",
|
|
11
16
|
"type": "module",
|
|
12
17
|
"main": "dist/index.js",
|
|
13
18
|
"types": "dist/index.d.ts",
|
|
@@ -20,21 +25,25 @@
|
|
|
20
25
|
"files": [
|
|
21
26
|
"dist"
|
|
22
27
|
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
23
31
|
"publishConfig": {
|
|
24
32
|
"access": "public"
|
|
25
33
|
},
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@decantr/essence-spec": "1.0.
|
|
35
|
+
"@decantr/essence-spec": "1.0.8"
|
|
28
36
|
},
|
|
29
37
|
"peerDependencies": {
|
|
30
|
-
"vite": "^5.0.0 || ^6.0.0"
|
|
38
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
31
39
|
},
|
|
32
40
|
"devDependencies": {
|
|
33
|
-
"vite": "^
|
|
41
|
+
"vite": "^8.0.11"
|
|
34
42
|
},
|
|
35
43
|
"scripts": {
|
|
36
44
|
"build": "tsup",
|
|
37
45
|
"test": "vitest run",
|
|
38
|
-
"test:watch": "vitest"
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"preversion": "pnpm build && pnpm test"
|
|
39
48
|
}
|
|
40
49
|
}
|