@celox-sim/vite-plugin 0.1.12 → 0.1.14
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/cache.d.ts.map +1 -1
- package/dist/cache.js +1 -1
- package/dist/cache.js.map +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -14
- package/dist/index.js.map +1 -1
- package/dist/sidecar.d.ts.map +1 -1
- package/dist/sidecar.js +2 -2
- package/dist/sidecar.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cache.ts +63 -66
- package/src/generator.ts +3 -3
- package/src/index.ts +152 -126
- package/src/sidecar.ts +43 -43
- package/src/types.ts +15 -15
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,UAAU;IAIV,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,SAAS,CAAM;gBAEM,YAAY,EAAE,MAAM;IAEjD,kEAAkE;IAClE,GAAG,IAAI,eAAe;IAUtB,mEAAmE;IACnE,UAAU,IAAI,IAAI;IAKlB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,cAAc;CA6BtB"}
|
package/dist/cache.js
CHANGED
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":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C;QAC1C,IAAI,CAAC;YACJ,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO;QACR,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACzB,qCAAqC;gBACrC,IACC,KAAK,CAAC,IAAI,KAAK,cAAc;oBAC7B,KAAK,CAAC,IAAI,KAAK,QAAQ;oBACvB,KAAK,CAAC,IAAI,KAAK,MAAM;oBACrB,KAAK,CAAC,IAAI,KAAK,MAAM,EACpB,CAAC;oBACF,SAAS;gBACV,CAAC;gBACD,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC/B,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC7C,IAAI,CAAC;oBACJ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;gBAC5B,CAAC;gBAAC,MAAM,CAAC;oBACR,6BAA6B;gBAC9B,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
|
package/dist/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAmB;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC3C,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAoB,CAAC;AAC5C,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,kBAAkB,EAAe,MAAM,YAAY,CAAC;AAElE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAIrD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAwGxE"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { resolve, isAbsolute, dirname } from "node:path";
|
|
2
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
3
|
import { GenTsCache } from "./cache.js";
|
|
4
|
-
import {
|
|
4
|
+
import { cleanSidecars, generateSidecars } from "./sidecar.js";
|
|
5
5
|
const VERYL_PREFIX = "\0veryl:";
|
|
6
6
|
/**
|
|
7
7
|
* Vite plugin for importing `.veryl` files as typed `ModuleDefinition` objects.
|
|
@@ -40,28 +40,40 @@ export default function celoxPlugin(options) {
|
|
|
40
40
|
sidecarPaths = generateSidecars(data, projectRoot);
|
|
41
41
|
},
|
|
42
42
|
resolveId(source, importer) {
|
|
43
|
-
|
|
43
|
+
// Split off query string (e.g. "?dse=preserveAllPorts")
|
|
44
|
+
const [rawPath, queryStr] = source.split("?", 2);
|
|
45
|
+
if (!rawPath.endsWith(".veryl"))
|
|
44
46
|
return;
|
|
45
47
|
// Resolve to absolute path
|
|
46
48
|
let absPath;
|
|
47
|
-
if (isAbsolute(
|
|
48
|
-
absPath =
|
|
49
|
+
if (isAbsolute(rawPath)) {
|
|
50
|
+
absPath = rawPath;
|
|
49
51
|
}
|
|
50
52
|
else if (importer) {
|
|
51
|
-
absPath = resolve(dirname(importer),
|
|
53
|
+
absPath = resolve(dirname(importer), rawPath);
|
|
52
54
|
}
|
|
53
55
|
else {
|
|
54
|
-
absPath = resolve(
|
|
56
|
+
absPath = resolve(rawPath);
|
|
55
57
|
}
|
|
56
58
|
// Only handle .veryl files that exist
|
|
57
59
|
if (!existsSync(absPath))
|
|
58
60
|
return;
|
|
59
|
-
|
|
61
|
+
// Preserve query string in virtual ID
|
|
62
|
+
return VERYL_PREFIX + absPath + (queryStr ? `?${queryStr}` : "");
|
|
60
63
|
},
|
|
61
64
|
load(id) {
|
|
62
65
|
if (!id.startsWith(VERYL_PREFIX))
|
|
63
66
|
return;
|
|
64
|
-
const
|
|
67
|
+
const rest = id.slice(VERYL_PREFIX.length);
|
|
68
|
+
const [absPath, queryStr] = rest.split("?", 2);
|
|
69
|
+
const params = new URLSearchParams(queryStr ?? "");
|
|
70
|
+
// Parse ?dse= query parameter
|
|
71
|
+
let dsePolicy;
|
|
72
|
+
if (params.has("dse")) {
|
|
73
|
+
const raw = params.get("dse");
|
|
74
|
+
// ?dse (no value) defaults to "preserveAllPorts" (safe side)
|
|
75
|
+
dsePolicy = raw || "preserveAllPorts";
|
|
76
|
+
}
|
|
65
77
|
const data = cache.get();
|
|
66
78
|
// Find the relative source file path
|
|
67
79
|
const relPath = makeRelative(absPath, projectRoot);
|
|
@@ -70,13 +82,16 @@ export default function celoxPlugin(options) {
|
|
|
70
82
|
this.warn(`No modules found in ${relPath}`);
|
|
71
83
|
return "export {};";
|
|
72
84
|
}
|
|
85
|
+
const defaultOptions = dsePolicy
|
|
86
|
+
? { deadStorePolicy: dsePolicy }
|
|
87
|
+
: undefined;
|
|
73
88
|
// Build ESM exports for each module in this file
|
|
74
89
|
const exports = moduleNames
|
|
75
90
|
.map((name) => {
|
|
76
91
|
const mod = data.modules.find((m) => m.moduleName === name);
|
|
77
92
|
if (!mod)
|
|
78
93
|
return "";
|
|
79
|
-
return generateEsmExport(mod, data.projectPath);
|
|
94
|
+
return generateEsmExport(mod, data.projectPath, defaultOptions);
|
|
80
95
|
})
|
|
81
96
|
.filter((s) => s.length > 0)
|
|
82
97
|
.join("\n\n");
|
|
@@ -120,7 +135,7 @@ function makeRelative(absPath, base) {
|
|
|
120
135
|
const normAbs = absPath.replace(/\\/g, "/");
|
|
121
136
|
const normBase = base.replace(/\\/g, "/").replace(/\/$/, "");
|
|
122
137
|
let rel = normAbs;
|
|
123
|
-
if (normAbs.startsWith(normBase
|
|
138
|
+
if (normAbs.startsWith(`${normBase}/`)) {
|
|
124
139
|
rel = normAbs.slice(normBase.length + 1);
|
|
125
140
|
}
|
|
126
141
|
else if (normAbs.startsWith(normBase)) {
|
|
@@ -134,19 +149,22 @@ function makeRelative(absPath, base) {
|
|
|
134
149
|
/**
|
|
135
150
|
* Generate an ESM export for a single module.
|
|
136
151
|
*/
|
|
137
|
-
function generateEsmExport(mod, projectPath) {
|
|
152
|
+
function generateEsmExport(mod, projectPath, defaultOptions) {
|
|
138
153
|
const portsJson = JSON.stringify(mod.ports, null, 2)
|
|
139
154
|
.split("\n")
|
|
140
|
-
.map((line, i) => (i === 0 ? line :
|
|
155
|
+
.map((line, i) => (i === 0 ? line : ` ${line}`))
|
|
141
156
|
.join("\n");
|
|
142
157
|
const eventsJson = JSON.stringify(mod.events);
|
|
158
|
+
const defaultOptsLine = defaultOptions
|
|
159
|
+
? `\n defaultOptions: ${JSON.stringify(defaultOptions)},`
|
|
160
|
+
: "";
|
|
143
161
|
return `export const ${mod.moduleName} = {
|
|
144
162
|
__celox_module: true,
|
|
145
163
|
name: ${JSON.stringify(mod.moduleName)},
|
|
146
164
|
source: "",
|
|
147
165
|
projectPath: ${JSON.stringify(projectPath)},
|
|
148
166
|
ports: ${portsJson},
|
|
149
|
-
events: ${eventsJson}
|
|
167
|
+
events: ${eventsJson},${defaultOptsLine}
|
|
150
168
|
};`;
|
|
151
169
|
}
|
|
152
170
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAK/D,MAAM,YAAY,GAAG,UAAU,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,OAA4B;IAC/D,IAAI,WAAmB,CAAC;IACxB,IAAI,KAAiB,CAAC;IACtB,IAAI,YAAY,GAAa,EAAE,CAAC;IAEhC,OAAO;QACN,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK;QAEd,cAAc,CAAC,MAAM;YACpB,yBAAyB;YACzB,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;gBAC1B,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACP,WAAW,GAAG,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC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;;UAE5B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC;;iBAEvB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;WACjC,SAAS;YACR,UAAU,IAAI,eAAe;GACtC,CAAC;AACJ,CAAC"}
|
package/dist/sidecar.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidecar.d.ts","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,gFAAgF;AAChF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"sidecar.d.ts","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,gFAAgF;AAChF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,MAAM,GACjB,MAAM,EAAE,CAkCV;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAUnD"}
|
package/dist/sidecar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
3
|
/** Default directory (relative to project root) for generated sidecar files. */
|
|
4
4
|
export const SIDECAR_DIR = ".celox";
|
|
5
5
|
/**
|
package/dist/sidecar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sidecar.js","sourceRoot":"","sources":["../src/sidecar.ts"],"names":[],"mappings":"AAAA,OAAO,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,IAAI,aAAa,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,MAAM,WAAW,eAAe;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;CACxD;AAED,mDAAmD;AACnD,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC3B;AAED,sBAAsB;AACtB,MAAM,WAAW,kBAAkB;IAClC,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celox-sim/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Vite plugin for importing .veryl files as typed ModuleDefinition objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"vite": ">=5.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@celox-sim/celox": "0.1.
|
|
36
|
+
"@celox-sim/celox": "0.1.14"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^25.3.2",
|
package/src/cache.ts
CHANGED
|
@@ -1,75 +1,72 @@
|
|
|
1
|
-
import { readdirSync, statSync } from "node:fs";
|
|
2
|
-
import {
|
|
3
|
-
import type { GenTsJsonOutput } from "./types.js";
|
|
1
|
+
import { type Dirent, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, join } from "node:path";
|
|
4
3
|
import { runGenTs } from "./generator.js";
|
|
4
|
+
import type { GenTsJsonOutput } from "./types.js";
|
|
5
5
|
|
|
6
6
|
export class GenTsCache {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
private _data: GenTsJsonOutput | undefined;
|
|
8
|
+
private _mtimeKey = "";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
constructor(private readonly _projectRoot: string) {}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
/** Get cached data, refreshing if any .veryl file has changed. */
|
|
13
|
+
get(): GenTsJsonOutput {
|
|
14
|
+
const key = this.computeMtimeKey();
|
|
15
|
+
if (this._data && this._mtimeKey === key) {
|
|
16
|
+
return this._data;
|
|
17
|
+
}
|
|
18
|
+
this._data = runGenTs(this._projectRoot);
|
|
19
|
+
this._mtimeKey = key;
|
|
20
|
+
return this._data;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/** Force invalidation — next `get()` will re-run the generator. */
|
|
24
|
+
invalidate(): void {
|
|
25
|
+
this._mtimeKey = "";
|
|
26
|
+
this._data = undefined;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Build a key from the max mtime of all .veryl files in the project.
|
|
31
|
+
* This is intentionally cheap — only stats, no file reads.
|
|
32
|
+
*/
|
|
33
|
+
private computeMtimeKey(): string {
|
|
34
|
+
let maxMtime = 0;
|
|
35
|
+
let count = 0;
|
|
36
|
+
this.walkVerylFiles(this._projectRoot, (mtimeMs) => {
|
|
37
|
+
if (mtimeMs > maxMtime) maxMtime = mtimeMs;
|
|
38
|
+
count++;
|
|
39
|
+
});
|
|
40
|
+
return `${count}:${maxMtime}`;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
43
|
+
private walkVerylFiles(dir: string, cb: (mtimeMs: number) => void): void {
|
|
44
|
+
let entries: Dirent<string>[] | undefined;
|
|
45
|
+
try {
|
|
46
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
47
|
+
} catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
const full = join(dir, entry.name);
|
|
52
|
+
if (entry.isDirectory()) {
|
|
53
|
+
// Skip common non-source directories
|
|
54
|
+
if (
|
|
55
|
+
entry.name === "node_modules" ||
|
|
56
|
+
entry.name === "target" ||
|
|
57
|
+
entry.name === ".git" ||
|
|
58
|
+
entry.name === "dist"
|
|
59
|
+
) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
this.walkVerylFiles(full, cb);
|
|
63
|
+
} else if (extname(entry.name) === ".veryl") {
|
|
64
|
+
try {
|
|
65
|
+
cb(statSync(full).mtimeMs);
|
|
66
|
+
} catch {
|
|
67
|
+
// file may have been deleted
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
75
72
|
}
|
package/src/generator.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { GenTsJsonOutput } from "./types.js";
|
|
|
5
5
|
* Run the TypeScript type generator via the NAPI addon and parse the output.
|
|
6
6
|
*/
|
|
7
7
|
export function runGenTs(projectRoot: string): GenTsJsonOutput {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const addon = loadNativeAddon();
|
|
9
|
+
const json = addon.genTs(projectRoot);
|
|
10
|
+
return JSON.parse(json) as GenTsJsonOutput;
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { resolve, isAbsolute, dirname } from "node:path";
|
|
2
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
3
|
import type { Plugin } from "vite";
|
|
4
|
-
import type { CeloxPluginOptions, GenTsModule } from "./types.js";
|
|
5
4
|
import { GenTsCache } from "./cache.js";
|
|
6
|
-
import {
|
|
5
|
+
import { cleanSidecars, generateSidecars } from "./sidecar.js";
|
|
6
|
+
import type { CeloxPluginOptions, GenTsModule } from "./types.js";
|
|
7
7
|
|
|
8
8
|
export type { CeloxPluginOptions } from "./types.js";
|
|
9
9
|
|
|
@@ -23,150 +23,176 @@ const VERYL_PREFIX = "\0veryl:";
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export default function celoxPlugin(options?: CeloxPluginOptions): Plugin {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
26
|
+
let projectRoot: string;
|
|
27
|
+
let cache: GenTsCache;
|
|
28
|
+
let sidecarPaths: string[] = [];
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
name: "vite-plugin-celox",
|
|
32
|
+
enforce: "pre",
|
|
33
|
+
|
|
34
|
+
configResolved(config) {
|
|
35
|
+
// Determine project root
|
|
36
|
+
if (options?.projectRoot) {
|
|
37
|
+
projectRoot = resolve(options.projectRoot);
|
|
38
|
+
} else {
|
|
39
|
+
projectRoot = findVerylProjectRoot(config.root);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cache = new GenTsCache(projectRoot);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
buildStart() {
|
|
46
|
+
// Run generator and create type sidecars
|
|
47
|
+
const data = cache.get();
|
|
48
|
+
cleanSidecars(sidecarPaths);
|
|
49
|
+
sidecarPaths = generateSidecars(data, projectRoot);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
resolveId(source, importer) {
|
|
53
|
+
// Split off query string (e.g. "?dse=preserveAllPorts")
|
|
54
|
+
const [rawPath, queryStr] = source.split("?", 2);
|
|
55
|
+
if (!rawPath!.endsWith(".veryl")) return;
|
|
56
|
+
|
|
57
|
+
// Resolve to absolute path
|
|
58
|
+
let absPath: string;
|
|
59
|
+
if (isAbsolute(rawPath!)) {
|
|
60
|
+
absPath = rawPath!;
|
|
61
|
+
} else if (importer) {
|
|
62
|
+
absPath = resolve(dirname(importer), rawPath!);
|
|
63
|
+
} else {
|
|
64
|
+
absPath = resolve(rawPath!);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Only handle .veryl files that exist
|
|
68
|
+
if (!existsSync(absPath)) return;
|
|
69
|
+
|
|
70
|
+
// Preserve query string in virtual ID
|
|
71
|
+
return VERYL_PREFIX + absPath + (queryStr ? `?${queryStr}` : "");
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
load(id) {
|
|
75
|
+
if (!id.startsWith(VERYL_PREFIX)) return;
|
|
76
|
+
|
|
77
|
+
const rest = id.slice(VERYL_PREFIX.length);
|
|
78
|
+
const [absPath, queryStr] = rest.split("?", 2);
|
|
79
|
+
const params = new URLSearchParams(queryStr ?? "");
|
|
80
|
+
|
|
81
|
+
// Parse ?dse= query parameter
|
|
82
|
+
let dsePolicy: string | undefined;
|
|
83
|
+
if (params.has("dse")) {
|
|
84
|
+
const raw = params.get("dse");
|
|
85
|
+
// ?dse (no value) defaults to "preserveAllPorts" (safe side)
|
|
86
|
+
dsePolicy = raw || "preserveAllPorts";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const data = cache.get();
|
|
90
|
+
|
|
91
|
+
// Find the relative source file path
|
|
92
|
+
const relPath = makeRelative(absPath!, projectRoot);
|
|
93
|
+
const moduleNames = data.fileModules[relPath];
|
|
94
|
+
|
|
95
|
+
if (!moduleNames || moduleNames.length === 0) {
|
|
96
|
+
this.warn(`No modules found in ${relPath}`);
|
|
97
|
+
return "export {};";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const defaultOptions = dsePolicy
|
|
101
|
+
? { deadStorePolicy: dsePolicy }
|
|
102
|
+
: undefined;
|
|
103
|
+
|
|
104
|
+
// Build ESM exports for each module in this file
|
|
105
|
+
const exports = moduleNames
|
|
106
|
+
.map((name) => {
|
|
107
|
+
const mod = data.modules.find((m) => m.moduleName === name);
|
|
108
|
+
if (!mod) return "";
|
|
109
|
+
return generateEsmExport(mod, data.projectPath, defaultOptions);
|
|
110
|
+
})
|
|
111
|
+
.filter((s) => s.length > 0)
|
|
112
|
+
.join("\n\n");
|
|
113
|
+
|
|
114
|
+
return exports;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
handleHotUpdate({ file }) {
|
|
118
|
+
if (!file.endsWith(".veryl")) return;
|
|
119
|
+
|
|
120
|
+
// Invalidate cache so next load re-runs the generator
|
|
121
|
+
cache.invalidate();
|
|
122
|
+
|
|
123
|
+
// Re-generate sidecars
|
|
124
|
+
const data = cache.get();
|
|
125
|
+
cleanSidecars(sidecarPaths);
|
|
126
|
+
sidecarPaths = generateSidecars(data, projectRoot);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
/**
|
|
114
132
|
* Search upward from `startDir` for a directory containing `Veryl.toml`.
|
|
115
133
|
*/
|
|
116
134
|
function findVerylProjectRoot(startDir: string): string {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
let dir = resolve(startDir);
|
|
136
|
+
// eslint-disable-next-line no-constant-condition
|
|
137
|
+
while (true) {
|
|
138
|
+
if (existsSync(resolve(dir, "Veryl.toml"))) {
|
|
139
|
+
return dir;
|
|
140
|
+
}
|
|
141
|
+
const parent = dirname(dir);
|
|
142
|
+
if (parent === dir) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
"Could not find Veryl.toml in any parent directory. " +
|
|
145
|
+
"Set the projectRoot plugin option explicitly.",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
dir = parent;
|
|
149
|
+
}
|
|
132
150
|
}
|
|
133
151
|
|
|
134
152
|
/**
|
|
135
153
|
* Make `absPath` relative to `base`, using forward slashes.
|
|
136
154
|
*/
|
|
137
155
|
function makeRelative(absPath: string, base: string): string {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
// Normalise to forward slashes so the comparison works on Windows
|
|
157
|
+
const normAbs = absPath.replace(/\\/g, "/");
|
|
158
|
+
const normBase = base.replace(/\\/g, "/").replace(/\/$/, "");
|
|
159
|
+
let rel = normAbs;
|
|
160
|
+
if (normAbs.startsWith(`${normBase}/`)) {
|
|
161
|
+
rel = normAbs.slice(normBase.length + 1);
|
|
162
|
+
} else if (normAbs.startsWith(normBase)) {
|
|
163
|
+
rel = normAbs.slice(normBase.length);
|
|
164
|
+
}
|
|
165
|
+
if (rel.startsWith("/")) {
|
|
166
|
+
rel = rel.slice(1);
|
|
167
|
+
}
|
|
168
|
+
return rel;
|
|
151
169
|
}
|
|
152
170
|
|
|
153
171
|
/**
|
|
154
172
|
* Generate an ESM export for a single module.
|
|
155
173
|
*/
|
|
156
|
-
function generateEsmExport(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
function generateEsmExport(
|
|
175
|
+
mod: GenTsModule,
|
|
176
|
+
projectPath: string,
|
|
177
|
+
defaultOptions?: Record<string, unknown>,
|
|
178
|
+
): string {
|
|
179
|
+
const portsJson = JSON.stringify(mod.ports, null, 2)
|
|
180
|
+
.split("\n")
|
|
181
|
+
.map((line, i) => (i === 0 ? line : ` ${line}`))
|
|
182
|
+
.join("\n");
|
|
183
|
+
|
|
184
|
+
const eventsJson = JSON.stringify(mod.events);
|
|
185
|
+
|
|
186
|
+
const defaultOptsLine = defaultOptions
|
|
187
|
+
? `\n defaultOptions: ${JSON.stringify(defaultOptions)},`
|
|
188
|
+
: "";
|
|
189
|
+
|
|
190
|
+
return `export const ${mod.moduleName} = {
|
|
165
191
|
__celox_module: true,
|
|
166
192
|
name: ${JSON.stringify(mod.moduleName)},
|
|
167
193
|
source: "",
|
|
168
194
|
projectPath: ${JSON.stringify(projectPath)},
|
|
169
195
|
ports: ${portsJson},
|
|
170
|
-
events: ${eventsJson}
|
|
196
|
+
events: ${eventsJson},${defaultOptsLine}
|
|
171
197
|
};`;
|
|
172
198
|
}
|
package/src/sidecar.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
3
|
import type { GenTsJsonOutput } from "./types.js";
|
|
4
4
|
|
|
5
5
|
/** Default directory (relative to project root) for generated sidecar files. */
|
|
@@ -14,65 +14,65 @@ export const SIDECAR_DIR = ".celox";
|
|
|
14
14
|
* `.celox/src/Adder.d.veryl.ts`.
|
|
15
15
|
*/
|
|
16
16
|
export function generateSidecars(
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
data: GenTsJsonOutput,
|
|
18
|
+
projectRoot: string,
|
|
19
19
|
): string[] {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const written: string[] = [];
|
|
21
|
+
const root = resolve(projectRoot);
|
|
22
|
+
const outDir = join(root, SIDECAR_DIR);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
for (const [sourceFile, moduleNames] of Object.entries(data.fileModules)) {
|
|
25
|
+
const verylPath = resolve(projectRoot, sourceFile);
|
|
26
|
+
// Skip files that don't exist on disk (e.g. standard library paths
|
|
27
|
+
// reported with a stripped leading "/" by celox-gen-ts)
|
|
28
|
+
if (!existsSync(verylPath)) continue;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const rel = relative(root, verylPath);
|
|
31
|
+
// Skip files outside the project root (e.g. standard library from global
|
|
32
|
+
// cache). On Windows, relative() across different drives returns an
|
|
33
|
+
// absolute path; on all platforms, paths outside root start with "..".
|
|
34
|
+
if (isAbsolute(rel) || rel.startsWith("..")) continue;
|
|
35
|
+
const sidecarPath = sidecarPathFor(join(outDir, rel));
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const modules = moduleNames
|
|
38
|
+
.map((name) => data.modules.find((m) => m.moduleName === name))
|
|
39
|
+
.filter((m) => m !== undefined);
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
if (modules.length === 0) continue;
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// Combine dtsContent from all modules in this file
|
|
44
|
+
// Each module's dtsContent already contains the import and interface
|
|
45
|
+
const content = modules.map((m) => m.dtsContent).join("\n");
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
mkdirSync(dirname(sidecarPath), { recursive: true });
|
|
48
|
+
writeFileSync(sidecarPath, content, "utf-8");
|
|
49
|
+
written.push(sidecarPath);
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
return written;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Remove all sidecar files that were previously generated.
|
|
57
57
|
*/
|
|
58
58
|
export function cleanSidecars(paths: string[]): void {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
for (const p of paths) {
|
|
60
|
+
try {
|
|
61
|
+
if (existsSync(p)) {
|
|
62
|
+
unlinkSync(p);
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// ignore cleanup errors
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Given `/path/to/.celox/src/Adder.veryl`, returns `/path/to/.celox/src/Adder.d.veryl.ts`.
|
|
72
72
|
*/
|
|
73
73
|
function sidecarPathFor(verylPath: string): string {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const dir = dirname(verylPath);
|
|
75
|
+
const base = verylPath.slice(dir.length + 1); // "Adder.veryl"
|
|
76
|
+
const stem = base.replace(/\.veryl$/, "");
|
|
77
|
+
return join(dir, `${stem}.d.veryl.ts`);
|
|
78
78
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
/** JSON output from `celox-gen-ts --json`. */
|
|
2
2
|
export interface GenTsJsonOutput {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
readonly projectPath: string;
|
|
4
|
+
readonly modules: readonly GenTsModule[];
|
|
5
|
+
readonly fileModules: Record<string, readonly string[]>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
/** Per-module entry from `celox-gen-ts --json`. */
|
|
9
9
|
export interface GenTsModule {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
readonly moduleName: string;
|
|
11
|
+
readonly sourceFile: string;
|
|
12
|
+
readonly dtsContent: string;
|
|
13
|
+
readonly mdContent: string;
|
|
14
|
+
readonly ports: Record<string, GenTsPortInfo>;
|
|
15
|
+
readonly events: readonly string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** Port metadata from the generator. */
|
|
19
19
|
export interface GenTsPortInfo {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
readonly direction: "input" | "output" | "inout";
|
|
21
|
+
readonly type: "clock" | "reset" | "logic" | "bit";
|
|
22
|
+
readonly width: number;
|
|
23
|
+
readonly is4state: boolean;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** Plugin options. */
|
|
27
27
|
export interface CeloxPluginOptions {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/** Explicit path to the Veryl project root (directory containing Veryl.toml). */
|
|
29
|
+
projectRoot?: string;
|
|
30
30
|
}
|