@pithyjs/vite-plugin 0.1.0-beta.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 +237 -0
- package/dist/aotCodegen/generateBindings.d.ts +184 -0
- package/dist/aotCodegen/generateBindings.d.ts.map +1 -0
- package/dist/aotCodegen/generateBindings.js +326 -0
- package/dist/aotCodegen/generateBindings.js.map +1 -0
- package/dist/aotCodegen/generateDomFactory.d.ts +59 -0
- package/dist/aotCodegen/generateDomFactory.d.ts.map +1 -0
- package/dist/aotCodegen/generateDomFactory.js +302 -0
- package/dist/aotCodegen/generateDomFactory.js.map +1 -0
- package/dist/aotCodegen/index.d.ts +18 -0
- package/dist/aotCodegen/index.d.ts.map +1 -0
- package/dist/aotCodegen/index.js +17 -0
- package/dist/aotCodegen/index.js.map +1 -0
- package/dist/aotCodegen/serializeNode.d.ts +74 -0
- package/dist/aotCodegen/serializeNode.d.ts.map +1 -0
- package/dist/aotCodegen/serializeNode.js +169 -0
- package/dist/aotCodegen/serializeNode.js.map +1 -0
- package/dist/aotCodegen/structuralCodegen.d.ts +38 -0
- package/dist/aotCodegen/structuralCodegen.d.ts.map +1 -0
- package/dist/aotCodegen/structuralCodegen.js +56 -0
- package/dist/aotCodegen/structuralCodegen.js.map +1 -0
- package/dist/aotCodegen/utils.d.ts +38 -0
- package/dist/aotCodegen/utils.d.ts.map +1 -0
- package/dist/aotCodegen/utils.js +48 -0
- package/dist/aotCodegen/utils.js.map +1 -0
- package/dist/babelPlugin/babelPlugin.d.ts +44 -0
- package/dist/babelPlugin/babelPlugin.d.ts.map +1 -0
- package/dist/babelPlugin/babelPlugin.js +392 -0
- package/dist/babelPlugin/babelPlugin.js.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts +20 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.js +44 -0
- package/dist/babelPlugin/extractOriginalTagNames.js.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts +26 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js +206 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js.map +1 -0
- package/dist/buildPlugin/plugin.d.ts +79 -0
- package/dist/buildPlugin/plugin.d.ts.map +1 -0
- package/dist/buildPlugin/plugin.js +142 -0
- package/dist/buildPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/collector.d.ts +63 -0
- package/dist/designSystemPlugin/collector.d.ts.map +1 -0
- package/dist/designSystemPlugin/collector.js +175 -0
- package/dist/designSystemPlugin/collector.js.map +1 -0
- package/dist/designSystemPlugin/cssTokens.d.ts +34 -0
- package/dist/designSystemPlugin/cssTokens.d.ts.map +1 -0
- package/dist/designSystemPlugin/cssTokens.js +56 -0
- package/dist/designSystemPlugin/cssTokens.js.map +1 -0
- package/dist/designSystemPlugin/enumerate.d.ts +24 -0
- package/dist/designSystemPlugin/enumerate.d.ts.map +1 -0
- package/dist/designSystemPlugin/enumerate.js +430 -0
- package/dist/designSystemPlugin/enumerate.js.map +1 -0
- package/dist/designSystemPlugin/extractor.d.ts +95 -0
- package/dist/designSystemPlugin/extractor.d.ts.map +1 -0
- package/dist/designSystemPlugin/extractor.js +150 -0
- package/dist/designSystemPlugin/extractor.js.map +1 -0
- package/dist/designSystemPlugin/generator.d.ts +33 -0
- package/dist/designSystemPlugin/generator.d.ts.map +1 -0
- package/dist/designSystemPlugin/generator.js +256 -0
- package/dist/designSystemPlugin/generator.js.map +1 -0
- package/dist/designSystemPlugin/index.d.ts +18 -0
- package/dist/designSystemPlugin/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/index.js +19 -0
- package/dist/designSystemPlugin/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.js +230 -0
- package/dist/designSystemPlugin/patterns/a11y.js.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.js +474 -0
- package/dist/designSystemPlugin/patterns/borders.js.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.js +134 -0
- package/dist/designSystemPlugin/patterns/colors.js.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.js +61 -0
- package/dist/designSystemPlugin/patterns/iconography.js.map +1 -0
- package/dist/designSystemPlugin/patterns/index.d.ts +22 -0
- package/dist/designSystemPlugin/patterns/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/index.js +44 -0
- package/dist/designSystemPlugin/patterns/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts +34 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.js +917 -0
- package/dist/designSystemPlugin/patterns/layout.js.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.js +162 -0
- package/dist/designSystemPlugin/patterns/motion.js.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.js +107 -0
- package/dist/designSystemPlugin/patterns/radius.js.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.js +161 -0
- package/dist/designSystemPlugin/patterns/shadows.js.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js +96 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.js +333 -0
- package/dist/designSystemPlugin/patterns/spacing.js.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.js +416 -0
- package/dist/designSystemPlugin/patterns/typography.js.map +1 -0
- package/dist/designSystemPlugin/plugin.d.ts +39 -0
- package/dist/designSystemPlugin/plugin.d.ts.map +1 -0
- package/dist/designSystemPlugin/plugin.js +351 -0
- package/dist/designSystemPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/types.d.ts +156 -0
- package/dist/designSystemPlugin/types.d.ts.map +1 -0
- package/dist/designSystemPlugin/types.js +49 -0
- package/dist/designSystemPlugin/types.js.map +1 -0
- package/dist/htmlTransform/htmlTransform.d.ts +47 -0
- package/dist/htmlTransform/htmlTransform.d.ts.map +1 -0
- package/dist/htmlTransform/htmlTransform.js +86 -0
- package/dist/htmlTransform/htmlTransform.js.map +1 -0
- package/dist/iconsPlugin/index.d.ts +18 -0
- package/dist/iconsPlugin/index.d.ts.map +1 -0
- package/dist/iconsPlugin/index.js +17 -0
- package/dist/iconsPlugin/index.js.map +1 -0
- package/dist/iconsPlugin/optimize.d.ts +54 -0
- package/dist/iconsPlugin/optimize.d.ts.map +1 -0
- package/dist/iconsPlugin/optimize.js +253 -0
- package/dist/iconsPlugin/optimize.js.map +1 -0
- package/dist/iconsPlugin/plugin.d.ts +49 -0
- package/dist/iconsPlugin/plugin.d.ts.map +1 -0
- package/dist/iconsPlugin/plugin.js +242 -0
- package/dist/iconsPlugin/plugin.js.map +1 -0
- package/dist/iconsPlugin/types.d.ts +49 -0
- package/dist/iconsPlugin/types.d.ts.map +1 -0
- package/dist/iconsPlugin/types.js +30 -0
- package/dist/iconsPlugin/types.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/pithyPlugin/plugin.d.ts +38 -0
- package/dist/pithyPlugin/plugin.d.ts.map +1 -0
- package/dist/pithyPlugin/plugin.js +119 -0
- package/dist/pithyPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/manifest.d.ts +33 -0
- package/dist/routerPlugin/manifest.d.ts.map +1 -0
- package/dist/routerPlugin/manifest.js +223 -0
- package/dist/routerPlugin/manifest.js.map +1 -0
- package/dist/routerPlugin/plugin.d.ts +51 -0
- package/dist/routerPlugin/plugin.d.ts.map +1 -0
- package/dist/routerPlugin/plugin.js +164 -0
- package/dist/routerPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/scanner.d.ts +69 -0
- package/dist/routerPlugin/scanner.d.ts.map +1 -0
- package/dist/routerPlugin/scanner.js +290 -0
- package/dist/routerPlugin/scanner.js.map +1 -0
- package/dist/ssrPlugin/plugin.d.ts +76 -0
- package/dist/ssrPlugin/plugin.d.ts.map +1 -0
- package/dist/ssrPlugin/plugin.js +439 -0
- package/dist/ssrPlugin/plugin.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons",
|
|
4
|
+
"title": "Vite Plugin for Icon Sprite Generation",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "SVG icon sprite generation plugin with optimization, HMR, and virtual module output.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync, readdirSync } from 'fs';
|
|
17
|
+
import { join, basename, dirname, extname, resolve } from 'path';
|
|
18
|
+
import { optimizeIcon, generateSprite } from './optimize';
|
|
19
|
+
import { VIRTUAL_MODULE_ID, RESOLVED_VIRTUAL_MODULE_ID, resolveOptions, } from './types';
|
|
20
|
+
/**
|
|
21
|
+
* Vite plugin for SVG icon sprite generation.
|
|
22
|
+
*
|
|
23
|
+
* Scans an icons directory, optimizes SVGs (strip metadata, enforce
|
|
24
|
+
* `currentColor`), and generates:
|
|
25
|
+
* - An SVG sprite asset (emitted as a Rollup asset in build, served in dev)
|
|
26
|
+
* - A `virtual:pithy-icons` module exporting `SPRITE_URL`, `ICON_NAMES`,
|
|
27
|
+
* and `ICON_META` for runtime registration
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // vite.config.ts
|
|
32
|
+
* import { pithyIcons } from '@pithyjs/vite-plugin';
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* plugins: [
|
|
36
|
+
* pithyIcons({ dir: 'src/icons' })
|
|
37
|
+
* ]
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // main.ts — register icons at app startup
|
|
44
|
+
* import { SPRITE_URL, ICON_NAMES, ICON_META } from "virtual:pithy-icons";
|
|
45
|
+
* import { registerIconSprite } from "@pithyjs/ui-kit/icons";
|
|
46
|
+
* registerIconSprite(SPRITE_URL, ICON_NAMES, ICON_META);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons","name":"pithyIcons","stability":"stable","signature":"(options?: PithyIconsOptions) => Plugin"} */
|
|
50
|
+
export function pithyIcons(options = {}) {
|
|
51
|
+
const resolved = resolveOptions(options);
|
|
52
|
+
let config;
|
|
53
|
+
let iconsDir;
|
|
54
|
+
let cachedIcons = null;
|
|
55
|
+
let spriteContent = null;
|
|
56
|
+
let emittedAssetId = null;
|
|
57
|
+
/** Dev-mode sprite serving path (computed from base config) */
|
|
58
|
+
let devSpritePath;
|
|
59
|
+
function log(...args) {
|
|
60
|
+
if (resolved.debug) {
|
|
61
|
+
console.log('[pithy:icons]', ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Scan the icons directory and optimize all SVG files.
|
|
66
|
+
*/
|
|
67
|
+
function scanIcons() {
|
|
68
|
+
if (cachedIcons)
|
|
69
|
+
return cachedIcons;
|
|
70
|
+
const icons = [];
|
|
71
|
+
let entries;
|
|
72
|
+
try {
|
|
73
|
+
entries = readdirSync(iconsDir, {
|
|
74
|
+
withFileTypes: true,
|
|
75
|
+
encoding: 'utf-8',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
log(`Icons directory not found: ${iconsDir}`);
|
|
80
|
+
cachedIcons = icons;
|
|
81
|
+
spriteContent = generateSprite(icons);
|
|
82
|
+
return icons;
|
|
83
|
+
}
|
|
84
|
+
for (const entry of entries) {
|
|
85
|
+
if (!entry.isFile())
|
|
86
|
+
continue;
|
|
87
|
+
const ext = extname(entry.name).toLowerCase();
|
|
88
|
+
if (ext !== '.svg')
|
|
89
|
+
continue;
|
|
90
|
+
const name = basename(entry.name, ext);
|
|
91
|
+
const filePath = join(iconsDir, entry.name);
|
|
92
|
+
try {
|
|
93
|
+
const raw = readFileSync(filePath, 'utf-8');
|
|
94
|
+
const icon = optimizeIcon(raw, name, {
|
|
95
|
+
prefix: resolved.prefix,
|
|
96
|
+
enforceCurrentColor: resolved.enforceCurrentColor,
|
|
97
|
+
});
|
|
98
|
+
icons.push(icon);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
console.warn(`[pithy:icons] Failed to process ${entry.name}:`, err instanceof Error ? err.message : err);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
icons.sort((a, b) => a.id.localeCompare(b.id));
|
|
105
|
+
cachedIcons = icons;
|
|
106
|
+
spriteContent = generateSprite(icons);
|
|
107
|
+
log(`Scanned ${icons.length} icons from ${iconsDir}`);
|
|
108
|
+
return icons;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generate the virtual module code.
|
|
112
|
+
*/
|
|
113
|
+
function generateVirtualModule(icons) {
|
|
114
|
+
const names = icons.map(i => i.id);
|
|
115
|
+
const meta = {};
|
|
116
|
+
for (const icon of icons) {
|
|
117
|
+
meta[icon.id] = { viewBox: icon.viewBox, tags: icon.tags };
|
|
118
|
+
}
|
|
119
|
+
// In dev mode, serve the sprite inline via a data URL or a custom route.
|
|
120
|
+
// In build mode, reference the emitted asset.
|
|
121
|
+
const isBuild = config.command === 'build';
|
|
122
|
+
if (isBuild && emittedAssetId) {
|
|
123
|
+
// Rollup asset reference — resolved at bundle time
|
|
124
|
+
return [
|
|
125
|
+
`export const SPRITE_URL = import.meta.ROLLUP_FILE_URL_${emittedAssetId};`,
|
|
126
|
+
`export const ICON_NAMES = ${JSON.stringify(names)};`,
|
|
127
|
+
`export const ICON_META = ${JSON.stringify(meta)};`,
|
|
128
|
+
].join('\n');
|
|
129
|
+
}
|
|
130
|
+
// Dev mode: serve sprite from a virtual URL (uses pre-computed devSpritePath)
|
|
131
|
+
// HMR: self-accept and re-register the sprite so the runtime registry stays
|
|
132
|
+
// in sync when icon files are added/changed/removed during development.
|
|
133
|
+
return [
|
|
134
|
+
`export const SPRITE_URL = ${JSON.stringify(devSpritePath)};`,
|
|
135
|
+
`export const ICON_NAMES = ${JSON.stringify(names)};`,
|
|
136
|
+
`export const ICON_META = ${JSON.stringify(meta)};`,
|
|
137
|
+
`if (import.meta.hot) {`,
|
|
138
|
+
` import.meta.hot.accept((newModule) => {`,
|
|
139
|
+
` if (newModule) {`,
|
|
140
|
+
` import("@pithyjs/ui-kit/icons").then(({ registerIconSprite }) => {`,
|
|
141
|
+
` registerIconSprite(newModule.SPRITE_URL, newModule.ICON_NAMES, newModule.ICON_META);`,
|
|
142
|
+
` });`,
|
|
143
|
+
` }`,
|
|
144
|
+
` });`,
|
|
145
|
+
`}`,
|
|
146
|
+
].join('\n');
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
name: 'pithy:icons',
|
|
150
|
+
configResolved(resolvedConfig) {
|
|
151
|
+
config = resolvedConfig;
|
|
152
|
+
iconsDir = resolve(config.root, resolved.dir);
|
|
153
|
+
// Compute dev sprite path from base config (used by both virtual module and middleware)
|
|
154
|
+
let base = config.base ?? '/';
|
|
155
|
+
// Normalize relative bases (e.g. "./") and empty strings to "/"
|
|
156
|
+
if (base === './' || base === '.' || base === '')
|
|
157
|
+
base = '/';
|
|
158
|
+
const normalizedBase = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
159
|
+
devSpritePath = `${normalizedBase}/@pithy-icons-sprite.svg`;
|
|
160
|
+
log('Plugin initialized, icons dir:', iconsDir);
|
|
161
|
+
},
|
|
162
|
+
buildStart() {
|
|
163
|
+
// Invalidate cache on each build
|
|
164
|
+
cachedIcons = null;
|
|
165
|
+
spriteContent = null;
|
|
166
|
+
emittedAssetId = null;
|
|
167
|
+
scanIcons();
|
|
168
|
+
// In build mode, emit the sprite as an asset
|
|
169
|
+
if (config.command === 'build' && spriteContent) {
|
|
170
|
+
emittedAssetId = this.emitFile({
|
|
171
|
+
type: 'asset',
|
|
172
|
+
name: 'icons-sprite.svg',
|
|
173
|
+
source: spriteContent,
|
|
174
|
+
});
|
|
175
|
+
log('Emitted sprite asset:', emittedAssetId);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
resolveId(id) {
|
|
179
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
180
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
},
|
|
184
|
+
load(id) {
|
|
185
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
186
|
+
const icons = scanIcons();
|
|
187
|
+
return generateVirtualModule(icons);
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
},
|
|
191
|
+
configureServer(server) {
|
|
192
|
+
// Serve the sprite SVG in dev mode (matches devSpritePath which respects base config)
|
|
193
|
+
server.middlewares.use((req, res, next) => {
|
|
194
|
+
const pathname = req.url?.split('?')[0];
|
|
195
|
+
if (pathname === devSpritePath) {
|
|
196
|
+
const icons = scanIcons();
|
|
197
|
+
const content = spriteContent ?? generateSprite(icons);
|
|
198
|
+
res.setHeader('Content-Type', 'image/svg+xml');
|
|
199
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
200
|
+
res.end(content);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
next();
|
|
204
|
+
});
|
|
205
|
+
// Watch the icons directory for changes
|
|
206
|
+
server.watcher.add(iconsDir);
|
|
207
|
+
server.watcher.on('all', (event, filePath) => {
|
|
208
|
+
if (resolve(dirname(filePath)) !== resolve(iconsDir))
|
|
209
|
+
return;
|
|
210
|
+
if (!filePath.endsWith('.svg'))
|
|
211
|
+
return;
|
|
212
|
+
if (!['add', 'change', 'unlink'].includes(event))
|
|
213
|
+
return;
|
|
214
|
+
log(`Icon ${event}: ${basename(filePath)}`);
|
|
215
|
+
// Invalidate cache
|
|
216
|
+
cachedIcons = null;
|
|
217
|
+
spriteContent = null;
|
|
218
|
+
// Invalidate the virtual module so re-imports get fresh data
|
|
219
|
+
const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
220
|
+
if (mod) {
|
|
221
|
+
server.moduleGraph.invalidateModule(mod);
|
|
222
|
+
// Send a module update so Vite's HMR pipeline picks up the change.
|
|
223
|
+
// Use the module's actual URL from the module graph (not the bare virtual ID)
|
|
224
|
+
// so Vite's client-side HMR can match the update to the imported module.
|
|
225
|
+
const modUrl = mod.url ?? `/${VIRTUAL_MODULE_ID}`;
|
|
226
|
+
server.ws.send({
|
|
227
|
+
type: 'update',
|
|
228
|
+
updates: [
|
|
229
|
+
{
|
|
230
|
+
type: 'js-update',
|
|
231
|
+
path: modUrl,
|
|
232
|
+
acceptedPath: modUrl,
|
|
233
|
+
timestamp: Date.now(),
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/iconsPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAC;AAC9E,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,GAGf,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,oJAAoJ;AACpJ,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAEzC,IAAI,MAAsB,CAAC;IAC3B,IAAI,QAAgB,CAAC;IACrB,IAAI,WAAW,GAA2B,IAAI,CAAC;IAC/C,IAAI,aAAa,GAAkB,IAAI,CAAC;IACxC,IAAI,cAAc,GAAkB,IAAI,CAAC;IAEzC,+DAA+D;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AAI,EAAE,MAAM;gCACZ,YAAY,EAAE,MAAM;gCACpB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;6BACtB;yBACF;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons-types",
|
|
4
|
+
"title": "Icon Sprite Plugin Types",
|
|
5
|
+
"category": "types",
|
|
6
|
+
"description": "TypeScript interfaces for icon sprite plugin options and resolved configuration.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/** Plugin configuration options */
|
|
17
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons","name":"PithyIconsOptions","stability":"stable","signature":"interface PithyIconsOptions"} */
|
|
18
|
+
export interface PithyIconsOptions {
|
|
19
|
+
/** Directory containing SVG icon files. Default: "src/icons" */
|
|
20
|
+
dir?: string;
|
|
21
|
+
/** Prefix for symbol IDs in the sprite. Default: "" (use filename as-is) */
|
|
22
|
+
prefix?: string;
|
|
23
|
+
/** Whether to strip hardcoded fill/stroke and replace with currentColor. Default: true */
|
|
24
|
+
enforceCurrentColor?: boolean;
|
|
25
|
+
/** Whether to emit debug logging. Default: false */
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Resolved plugin configuration with all defaults applied */
|
|
29
|
+
export interface ResolvedIconsOptions {
|
|
30
|
+
dir: string;
|
|
31
|
+
prefix: string;
|
|
32
|
+
enforceCurrentColor: boolean;
|
|
33
|
+
debug: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Metadata for a single icon in the sprite */
|
|
36
|
+
export interface SpriteIconMeta {
|
|
37
|
+
/** Original viewBox from the SVG */
|
|
38
|
+
viewBox: string;
|
|
39
|
+
/** Optional search tags (from filename segments) */
|
|
40
|
+
tags: string[];
|
|
41
|
+
}
|
|
42
|
+
/** Virtual module ID for the generated icon sprite module */
|
|
43
|
+
export declare const VIRTUAL_MODULE_ID = "virtual:pithy-icons";
|
|
44
|
+
/** Resolved virtual module ID (Vite convention: \0 prefix) */
|
|
45
|
+
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
46
|
+
/** Default options */
|
|
47
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons","name":"resolveOptions","stability":"stable","signature":"(options: PithyIconsOptions) => ResolvedIconsOptions"} */
|
|
48
|
+
export declare function resolveOptions(options: PithyIconsOptions): ResolvedIconsOptions;
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/iconsPlugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,mCAAmC;AACnC,+IAA+I;AAC/I,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0FAA0F;IAC1F,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oDAAoD;IACpD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,8DAA8D;AAC9D,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,OAAO,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AAEvD,8DAA8D;AAC9D,eAAO,MAAM,0BAA0B,QAA2B,CAAC;AAEnE,sBAAsB;AACtB,qKAAqK;AACrK,wBAAgB,cAAc,CAC5B,OAAO,EAAE,iBAAiB,GACzB,oBAAoB,CAOtB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-icons-types",
|
|
4
|
+
"title": "Icon Sprite Plugin Types",
|
|
5
|
+
"category": "types",
|
|
6
|
+
"description": "TypeScript interfaces for icon sprite plugin options and resolved configuration.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "iconsPlugin.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/** Virtual module ID for the generated icon sprite module */
|
|
17
|
+
export const VIRTUAL_MODULE_ID = 'virtual:pithy-icons';
|
|
18
|
+
/** Resolved virtual module ID (Vite convention: \0 prefix) */
|
|
19
|
+
export const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
20
|
+
/** Default options */
|
|
21
|
+
/** @codexApi {"parent":"pithy.vite-plugin-icons","name":"resolveOptions","stability":"stable","signature":"(options: PithyIconsOptions) => ResolvedIconsOptions"} */
|
|
22
|
+
export function resolveOptions(options) {
|
|
23
|
+
return {
|
|
24
|
+
dir: options.dir ?? 'src/icons',
|
|
25
|
+
prefix: options.prefix ?? '',
|
|
26
|
+
enforceCurrentColor: options.enforceCurrentColor ?? true,
|
|
27
|
+
debug: options.debug ?? false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/iconsPlugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AA+BF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEvD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,GAAG,iBAAiB,CAAC;AAEnE,sBAAsB;AACtB,qKAAqK;AACrK,MAAM,UAAU,cAAc,CAC5B,OAA0B;IAE1B,OAAO;QACL,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,WAAW;QAC/B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;QAC5B,mBAAmB,EAAE,OAAO,CAAC,mBAAmB,IAAI,IAAI;QACxD,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;KAC9B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin",
|
|
4
|
+
"title": "Vite Plugin Entry",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Public entry point re-exporting all PithyJS Vite plugins.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @pithyjs/vite-plugin
|
|
18
|
+
*
|
|
19
|
+
* Vite plugins for the PithyJS framework.
|
|
20
|
+
*
|
|
21
|
+
* @module @pithyjs/vite-plugin
|
|
22
|
+
*/
|
|
23
|
+
export { pithyPlugin } from './pithyPlugin/plugin';
|
|
24
|
+
export { htmlTransformPlugin, type HtmlTransformPluginOptions, } from './htmlTransform/htmlTransform';
|
|
25
|
+
export type { ComponentScopesMap, ComponentScopeConfig, } from './babelPlugin/extractUsedIdentifiers';
|
|
26
|
+
export { pithyBuild } from './buildPlugin/plugin';
|
|
27
|
+
export { pithyRouter, type PithyRouterPluginOptions, } from './routerPlugin/plugin';
|
|
28
|
+
export { designSystemPlugin, type DesignSystemPluginOptions, } from './designSystemPlugin';
|
|
29
|
+
export { pithySSR, type PithySSRPluginOptions } from './ssrPlugin/plugin';
|
|
30
|
+
export { pithyIcons, type PithyIconsOptions } from './iconsPlugin';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EACL,mBAAmB,EACnB,KAAK,0BAA0B,GAChC,MAAM,+BAA+B,CAAC;AACvC,YAAY,EACV,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,EACL,WAAW,EACX,KAAK,wBAAwB,GAC9B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAG1E,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin",
|
|
4
|
+
"title": "Vite Plugin Entry",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Public entry point re-exporting all PithyJS Vite plugins.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @pithyjs/vite-plugin
|
|
18
|
+
*
|
|
19
|
+
* Vite plugins for the PithyJS framework.
|
|
20
|
+
*
|
|
21
|
+
* @module @pithyjs/vite-plugin
|
|
22
|
+
*/
|
|
23
|
+
// Main .pithy file transform plugin
|
|
24
|
+
export { pithyPlugin } from './pithyPlugin/plugin';
|
|
25
|
+
// HTML template transform plugin (for html`` tagged templates)
|
|
26
|
+
export { htmlTransformPlugin, } from './htmlTransform/htmlTransform';
|
|
27
|
+
// Build optimization plugin (chunk naming, vendor splitting)
|
|
28
|
+
export { pithyBuild } from './buildPlugin/plugin';
|
|
29
|
+
// Router plugin (file-based routing)
|
|
30
|
+
export { pithyRouter, } from './routerPlugin/plugin';
|
|
31
|
+
// Design system CSS tree-shaking plugin
|
|
32
|
+
export { designSystemPlugin, } from './designSystemPlugin';
|
|
33
|
+
// SSR dev server plugin
|
|
34
|
+
export { pithySSR } from './ssrPlugin/plugin';
|
|
35
|
+
// Icon sprite generation plugin
|
|
36
|
+
export { pithyIcons } from './iconsPlugin';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF;;;;;;GAMG;AAEH,oCAAoC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,+DAA+D;AAC/D,OAAO,EACL,mBAAmB,GAEpB,MAAM,+BAA+B,CAAC;AAMvC,6DAA6D;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,qCAAqC;AACrC,OAAO,EACL,WAAW,GAEZ,MAAM,uBAAuB,CAAC;AAE/B,wCAAwC;AACxC,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAE9B,wBAAwB;AACxB,OAAO,EAAE,QAAQ,EAA8B,MAAM,oBAAoB,CAAC;AAE1E,gCAAgC;AAChC,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite.plugin",
|
|
4
|
+
"title": "Vite Pithy Plugin",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Vite plugin that transforms .pithy single-file components into compiled TypeScript modules with HMR support.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import { type Plugin } from 'vite';
|
|
17
|
+
/**
|
|
18
|
+
* Vite plugin to support `.pithy` single-file components (SFC).
|
|
19
|
+
*
|
|
20
|
+
* - Transforms `.pithy` files into compiled JavaScript modules (the generated
|
|
21
|
+
* TypeScript is transpiled to JS via esbuild before being returned).
|
|
22
|
+
* - Automatically scopes styles and templates.
|
|
23
|
+
* - Supports hot module replacement (HMR) for faster development.
|
|
24
|
+
*
|
|
25
|
+
* @returns A Vite plugin that handles .pithy file transformation and HMR
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { pithyPlugin } from '@pithyjs/vite-plugin';
|
|
30
|
+
*
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* plugins: [pithyPlugin()],
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
/** @codexApi {"parent":"pithy.vite.plugin","name":"pithyPlugin","stability":"stable","signature":"() => Plugin"} */
|
|
37
|
+
export declare function pithyPlugin(): Plugin;
|
|
38
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/pithyPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAWF,OAAO,EAAwB,KAAK,MAAM,EAAmB,MAAM,MAAM,CAAC;AAE1E;;;;;;;;;;;;;;;;;;GAkBG;AACH,oHAAoH;AACpH,wBAAgB,WAAW,IAAI,MAAM,CAwDpC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite.plugin",
|
|
4
|
+
"title": "Vite Pithy Plugin",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Vite plugin that transforms .pithy single-file components into compiled TypeScript modules with HMR support.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import path from 'path';
|
|
17
|
+
// NOTE: import from compiler *source* (relative), not the `@pithyjs/compiler`
|
|
18
|
+
// package specifier. Vite loads plugins in its config bundler, which externalizes
|
|
19
|
+
// bare deps → Node then imports `@pithyjs/compiler`'s dist, whose extensionless
|
|
20
|
+
// `export * from './parse'` re-exports throw ERR_UNSUPPORTED_DIR_IMPORT. The
|
|
21
|
+
// relative path is bundled by esbuild instead and works. (Making the published
|
|
22
|
+
// plugin resolve the compiler is a separate build-tooling task — see R0.4.)
|
|
23
|
+
import { parsePithyFile } from '../../../compiler/src/parse/parsePithyFile.js';
|
|
24
|
+
import { compileToModule } from '../../../compiler/src/transform/compileToModule.js';
|
|
25
|
+
import { transformWithEsbuild } from 'vite';
|
|
26
|
+
/**
|
|
27
|
+
* Vite plugin to support `.pithy` single-file components (SFC).
|
|
28
|
+
*
|
|
29
|
+
* - Transforms `.pithy` files into compiled JavaScript modules (the generated
|
|
30
|
+
* TypeScript is transpiled to JS via esbuild before being returned).
|
|
31
|
+
* - Automatically scopes styles and templates.
|
|
32
|
+
* - Supports hot module replacement (HMR) for faster development.
|
|
33
|
+
*
|
|
34
|
+
* @returns A Vite plugin that handles .pithy file transformation and HMR
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { pithyPlugin } from '@pithyjs/vite-plugin';
|
|
39
|
+
*
|
|
40
|
+
* export default defineConfig({
|
|
41
|
+
* plugins: [pithyPlugin()],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
/** @codexApi {"parent":"pithy.vite.plugin","name":"pithyPlugin","stability":"stable","signature":"() => Plugin"} */
|
|
46
|
+
export function pithyPlugin() {
|
|
47
|
+
return {
|
|
48
|
+
name: 'vite-plugin-pithy',
|
|
49
|
+
enforce: 'pre', // Run early before other plugins
|
|
50
|
+
/**
|
|
51
|
+
* Transforms a `.pithy` file into a compiled JavaScript module: the compiler
|
|
52
|
+
* emits a TypeScript module, which is transpiled to JS via esbuild here.
|
|
53
|
+
*
|
|
54
|
+
* @param code - Raw source code of the `.pithy` file
|
|
55
|
+
* @param id - Full path or virtual ID of the file
|
|
56
|
+
* @returns Compiled JavaScript code and a source map
|
|
57
|
+
*/
|
|
58
|
+
async transform(code, id) {
|
|
59
|
+
// Vite appends query suffixes to ids (e.g. `.pithy?import`, `.pithy?v=…`). Match
|
|
60
|
+
// and derive the filename/scope id from the bare path (before the `?`) so
|
|
61
|
+
// `.pithy` modules are always transformed and the scope id is stable across
|
|
62
|
+
// reloads. `#` is left intact — module ids carry queries, not URL fragments, and
|
|
63
|
+
// `#` can be a legitimate path character.
|
|
64
|
+
const filePath = id.split('?', 1)[0];
|
|
65
|
+
if (!filePath.endsWith('.pithy'))
|
|
66
|
+
return;
|
|
67
|
+
// Parse the raw .pithy file into its sections (template, script, style)
|
|
68
|
+
const parsed = parsePithyFile(code);
|
|
69
|
+
// Generate a short scoped ID for styles based on the file path
|
|
70
|
+
const filename = path.basename(filePath);
|
|
71
|
+
const scopeId = generateScopeId(filePath);
|
|
72
|
+
// Compile the parsed content into a full TypeScript module. The <script
|
|
73
|
+
// lang="ts"> body may contain TS-only syntax (type aliases, generics, `as`),
|
|
74
|
+
// and Vite's esbuild pass does NOT run on `.pithy` ids — so transpile the
|
|
75
|
+
// generated module to JS here (also yields a proper source map).
|
|
76
|
+
const tsCode = compileToModule(parsed, { filename, scopeId });
|
|
77
|
+
const { code: jsCode, map } = await transformWithEsbuild(tsCode, id, {
|
|
78
|
+
loader: 'ts',
|
|
79
|
+
});
|
|
80
|
+
return { code: jsCode, map };
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Handles hot module replacement (HMR) for `.pithy` files.
|
|
84
|
+
*
|
|
85
|
+
* Invalidates the module graph so Vite reloads updated components automatically.
|
|
86
|
+
*
|
|
87
|
+
* @param ctx - Vite HMR context
|
|
88
|
+
*/
|
|
89
|
+
handleHotUpdate(ctx) {
|
|
90
|
+
if (ctx.file.endsWith('.pithy')) {
|
|
91
|
+
for (const mod of ctx.modules) {
|
|
92
|
+
ctx.server.moduleGraph.invalidateModule(mod);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generates a short, per-file-unique scope ID from a file path.
|
|
100
|
+
*
|
|
101
|
+
* Uses a djb2 hash of the WHOLE path rather than a base64 prefix: sibling files
|
|
102
|
+
* share a long common path prefix, so slicing the first base64 chars produced
|
|
103
|
+
* identical IDs for every component — making their scoped styles collide. The hash
|
|
104
|
+
* spreads across the full path, and base36 keeps the id lowercase (the runtime
|
|
105
|
+
* lowercases the `data-scope-<id>` attribute name, so the CSS must match).
|
|
106
|
+
*
|
|
107
|
+
* Example: "src/components/Button.pithy" → "pithy-1a2b3c"
|
|
108
|
+
*
|
|
109
|
+
* @param filepath - Full file path
|
|
110
|
+
* @returns A short scope ID like `pithy-abc123`
|
|
111
|
+
*/
|
|
112
|
+
function generateScopeId(filepath) {
|
|
113
|
+
let hash = 5381;
|
|
114
|
+
for (let i = 0; i < filepath.length; i++) {
|
|
115
|
+
hash = (((hash << 5) + hash) ^ filepath.charCodeAt(i)) >>> 0;
|
|
116
|
+
}
|
|
117
|
+
return 'pithy-' + hash.toString(36);
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/pithyPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,8EAA8E;AAC9E,kFAAkF;AAClF,gFAAgF;AAChF,6EAA6E;AAC7E,+EAA+E;AAC/E,4EAA4E;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAgC,MAAM,MAAM,CAAC;AAE1E;;;;;;;;;;;;;;;;;;GAkBG;AACH,oHAAoH;AACpH,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,KAAK,EAAE,iCAAiC;QAEjD;;;;;;;WAOG;QACH,KAAK,CA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IACvC,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACzC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-router.manifest",
|
|
4
|
+
"title": "Route Manifest Generator",
|
|
5
|
+
"category": "compiler",
|
|
6
|
+
"description": "Generates typed TypeScript route manifests and CLI-formatted route tables from a route tree.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "manifest.test.ts" },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import type { RouteNode } from '@pithyjs/router';
|
|
17
|
+
/**
|
|
18
|
+
* Generate TypeScript code for the route manifest
|
|
19
|
+
* Creates virtual:pithy/routes.gen module with typed RouteNode tree
|
|
20
|
+
*/
|
|
21
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"generateManifest","stability":"stable","signature":"(routes: RouteNode[]) => string"} */
|
|
22
|
+
export declare function generateManifest(routes: RouteNode[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* Generate CLI command output for route tree inspection
|
|
25
|
+
*/
|
|
26
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"generateCliOutput","stability":"stable","signature":"(routes: RouteNode[]) => string"} */
|
|
27
|
+
export declare function generateCliOutput(routes: RouteNode[]): string;
|
|
28
|
+
/**
|
|
29
|
+
* Validate generated manifest for common issues
|
|
30
|
+
*/
|
|
31
|
+
/** @codexApi {"parent":"pithy.vite-plugin-router.manifest","name":"validateManifest","stability":"stable","signature":"(routes: RouteNode[]) => string[]"} */
|
|
32
|
+
export declare function validateManifest(routes: RouteNode[]): string[];
|
|
33
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/routerPlugin/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AASjD;;;GAGG;AACH,4JAA4J;AAC5J,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAmB5D;AAkKD;;GAEG;AACH,6JAA6J;AAC7J,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAkB7D;AAED;;GAEG;AACH,8JAA8J;AAC9J,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,CA8B9D"}
|