vite-plugin-vesk 0.2.8
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/index.d.ts +33 -0
- package/dist/index.js +63 -0
- package/package.json +44 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-vesk — Vite adapter for Vesk.
|
|
3
|
+
* Transforms .vsk files to TSX via vskToTsx and lets Vite handle the rest.
|
|
4
|
+
* Handles HMR via Vite's handleHotUpdate.
|
|
5
|
+
*/
|
|
6
|
+
export interface VeskViteOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Include pattern for .vsk files. Default /\.vsk$/.
|
|
9
|
+
*/
|
|
10
|
+
include?: RegExp;
|
|
11
|
+
/**
|
|
12
|
+
* Exclude pattern. Default /node_modules/.
|
|
13
|
+
*/
|
|
14
|
+
exclude?: RegExp;
|
|
15
|
+
}
|
|
16
|
+
export default function vesk(options?: VeskViteOptions): {
|
|
17
|
+
name: string;
|
|
18
|
+
enforce: "pre";
|
|
19
|
+
transform(code: string, id: string): {
|
|
20
|
+
code: string;
|
|
21
|
+
map: null;
|
|
22
|
+
} | null | undefined;
|
|
23
|
+
resolveId(id: string, importer?: string): string | null;
|
|
24
|
+
handleHotUpdate(ctx: {
|
|
25
|
+
file: string;
|
|
26
|
+
server: {
|
|
27
|
+
ws: {
|
|
28
|
+
send: (msg: unknown) => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}): void;
|
|
32
|
+
};
|
|
33
|
+
export { vesk };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-vesk — Vite adapter for Vesk.
|
|
3
|
+
* Transforms .vsk files to TSX via vskToTsx and lets Vite handle the rest.
|
|
4
|
+
* Handles HMR via Vite's handleHotUpdate.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { resolve, dirname } from 'node:path';
|
|
8
|
+
import { vskToTsx } from '@vesk/compiler/src/vsk-tsx';
|
|
9
|
+
export default function vesk(options = {}) {
|
|
10
|
+
const include = options.include ?? /\.vsk$/;
|
|
11
|
+
const exclude = options.exclude ?? /node_modules/;
|
|
12
|
+
return {
|
|
13
|
+
name: 'vite-plugin-vesk',
|
|
14
|
+
enforce: 'pre',
|
|
15
|
+
transform(code, id) {
|
|
16
|
+
const [path] = id.split('?');
|
|
17
|
+
if (!include.test(path) || exclude.test(path))
|
|
18
|
+
return null;
|
|
19
|
+
if (!path.endsWith('.vsk'))
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const tsx = vskToTsx(code);
|
|
23
|
+
return {
|
|
24
|
+
code: tsx,
|
|
25
|
+
map: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
this.error(`[vite-plugin-vesk] Failed to compile ${id}: ${e.message}`);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
resolveId(id, importer) {
|
|
33
|
+
if (!importer)
|
|
34
|
+
return null;
|
|
35
|
+
// Allow omitting .vsk extension: import Foo from './Foo' where Foo.vsk exists
|
|
36
|
+
if (id.startsWith('.') && !id.endsWith('.vsk') && !id.includes('?')) {
|
|
37
|
+
const base = resolve(dirname(importer), id);
|
|
38
|
+
for (const ext of ['.vsk', '.vsk?client']) {
|
|
39
|
+
try {
|
|
40
|
+
const full = base + ext;
|
|
41
|
+
readFileSync(full);
|
|
42
|
+
return full;
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
}
|
|
46
|
+
// Try directory with .vsk
|
|
47
|
+
try {
|
|
48
|
+
const full = base + '.vsk';
|
|
49
|
+
readFileSync(full);
|
|
50
|
+
return full;
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
},
|
|
56
|
+
handleHotUpdate(ctx) {
|
|
57
|
+
if (ctx.file.endsWith('.vsk')) {
|
|
58
|
+
ctx.server.ws.send({ type: 'full-reload' });
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export { vesk };
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-vesk",
|
|
3
|
+
"version": "0.2.8",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vite plugin for Vesk — compiles .vsk components to TSX/JS",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@vesk/compiler": "^0.2.8"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vite": "^5.0.0 || ^6.0.0"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "emeraldlinks",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/emeraldlinks/veskTs.git"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/emeraldlinks/veskTs#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/emeraldlinks/veskTs/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20.0.0"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|