@colletdev/core 0.1.4 → 0.1.6
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/generated/index.js +1 -1
- package/package.json +4 -1
- package/src/purge.mjs +67 -0
- package/src/server.js +7 -3
- package/src/vite-plugin.js +12 -6
package/generated/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { initWasm, loadSharedStyles, loadInlineSharedStyles, loadMotionStyles, loadInlineMotionStyles, injectTokensToHead, injectFoucPrevention, CxElement, CxFormElement } from '../src/runtime.js';
|
|
24
24
|
|
|
25
25
|
// Package version — used for CDN fallback URL
|
|
26
|
-
const PKG_VERSION = '0.1.
|
|
26
|
+
const PKG_VERSION = '0.1.5';
|
|
27
27
|
|
|
28
28
|
// ─── Lazy WASM + CSS ───
|
|
29
29
|
// WASM glue and CSS strings are NOT imported at module level.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colletdev/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Rust/WASM Custom Elements — 48 production-grade UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "generated/index.js",
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"wasm/",
|
|
41
41
|
"custom-elements.json"
|
|
42
42
|
],
|
|
43
|
+
"bin": {
|
|
44
|
+
"collet-purge": "src/purge.mjs"
|
|
45
|
+
},
|
|
43
46
|
"customElements": "custom-elements.json",
|
|
44
47
|
"keywords": [
|
|
45
48
|
"web-components",
|
package/src/purge.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// collet-purge — Clear stale WASM, CSS, and Vite cache artifacts after upgrading.
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// npx @colletdev/core purge # clear caches and stale artifacts
|
|
6
|
+
// npx collet-purge # same thing
|
|
7
|
+
//
|
|
8
|
+
// What it clears:
|
|
9
|
+
// 1. Vite dep cache (.vite/) — forces re-optimization with new WASM
|
|
10
|
+
// 2. Vite build cache (node_modules/.vite/) — stale pre-bundled modules
|
|
11
|
+
// 3. Copied WASM in public/ — replaced by fresh binary from package
|
|
12
|
+
// 4. Old @collet/ scope packages — if migrating from @collet to @colletdev
|
|
13
|
+
//
|
|
14
|
+
// This is safe to run at any time — Vite rebuilds its cache on next dev start.
|
|
15
|
+
|
|
16
|
+
import { existsSync, rmSync, readdirSync } from 'node:fs';
|
|
17
|
+
import { resolve, join } from 'node:path';
|
|
18
|
+
|
|
19
|
+
const CWD = process.cwd();
|
|
20
|
+
let cleared = 0;
|
|
21
|
+
|
|
22
|
+
function rm(path, label) {
|
|
23
|
+
if (existsSync(path)) {
|
|
24
|
+
rmSync(path, { recursive: true, force: true });
|
|
25
|
+
console.log(` Cleared: ${label}`);
|
|
26
|
+
cleared++;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log('Collet Purge — clearing stale artifacts');
|
|
32
|
+
console.log('─'.repeat(45));
|
|
33
|
+
|
|
34
|
+
// 1. Vite dep optimization cache
|
|
35
|
+
rm(resolve(CWD, 'node_modules/.vite'), 'node_modules/.vite/ (Vite dep cache)');
|
|
36
|
+
|
|
37
|
+
// 2. Vite build cache in project root
|
|
38
|
+
rm(resolve(CWD, '.vite'), '.vite/ (Vite build cache)');
|
|
39
|
+
|
|
40
|
+
// 3. Stale WASM binary copied to public/
|
|
41
|
+
rm(resolve(CWD, 'public/wasm_api_bg.wasm'), 'public/wasm_api_bg.wasm (stale WASM copy)');
|
|
42
|
+
|
|
43
|
+
// 4. Old @collet/ scope packages (pre-rename)
|
|
44
|
+
const oldScopeDir = resolve(CWD, 'node_modules/@collet');
|
|
45
|
+
if (existsSync(oldScopeDir)) {
|
|
46
|
+
try {
|
|
47
|
+
const entries = readdirSync(oldScopeDir);
|
|
48
|
+
if (entries.length > 0) {
|
|
49
|
+
rm(oldScopeDir, '@collet/ (old scope — migrate to @colletdev/)');
|
|
50
|
+
}
|
|
51
|
+
} catch { /* permission error — skip */ }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 5. Framework-specific caches
|
|
55
|
+
rm(resolve(CWD, '.next/cache'), '.next/cache/ (Next.js build cache)');
|
|
56
|
+
rm(resolve(CWD, '.nuxt'), '.nuxt/ (Nuxt build cache)');
|
|
57
|
+
rm(resolve(CWD, '.svelte-kit'), '.svelte-kit/ (SvelteKit build cache)');
|
|
58
|
+
rm(resolve(CWD, '.angular/cache'), '.angular/cache/ (Angular build cache)');
|
|
59
|
+
|
|
60
|
+
console.log('');
|
|
61
|
+
if (cleared === 0) {
|
|
62
|
+
console.log('Nothing to clear — caches are clean.');
|
|
63
|
+
} else {
|
|
64
|
+
console.log(`Cleared ${cleared} stale artifact${cleared > 1 ? 's' : ''}.`);
|
|
65
|
+
console.log('Run your dev server to rebuild fresh caches.');
|
|
66
|
+
}
|
|
67
|
+
console.log('');
|
package/src/server.js
CHANGED
|
@@ -114,7 +114,11 @@ export async function createRenderer(options = {}) {
|
|
|
114
114
|
* @returns {{ html: string, sprites: string, a11y: object }}
|
|
115
115
|
*/
|
|
116
116
|
function renderToString(component, config) {
|
|
117
|
-
|
|
117
|
+
// Always enable slot mode so shadow HTML includes <slot> elements.
|
|
118
|
+
// Without this, slot-based components (text, card, dialog, drawer, etc.)
|
|
119
|
+
// render empty containers because content comes from light DOM children,
|
|
120
|
+
// not the config object.
|
|
121
|
+
const result = cx_render(component, { ...config, slotted: true });
|
|
118
122
|
return result;
|
|
119
123
|
}
|
|
120
124
|
|
|
@@ -135,7 +139,7 @@ export async function createRenderer(options = {}) {
|
|
|
135
139
|
* @returns {string} Full HTML string ready for insertion into a document
|
|
136
140
|
*/
|
|
137
141
|
function renderDSD(component, config, children = '') {
|
|
138
|
-
const result = cx_render(component, config);
|
|
142
|
+
const result = cx_render(component, { ...config, slotted: true });
|
|
139
143
|
const tag = `cx-${component.replace(/_/g, '-')}`;
|
|
140
144
|
const attrs = propsToAttributes(config);
|
|
141
145
|
const styles = stylesheetBlock();
|
|
@@ -156,7 +160,7 @@ export async function createRenderer(options = {}) {
|
|
|
156
160
|
* @returns {string} `<template shadowrootmode="open">...</template>`
|
|
157
161
|
*/
|
|
158
162
|
function renderDSDFragment(component, config) {
|
|
159
|
-
const result = cx_render(component, config);
|
|
163
|
+
const result = cx_render(component, { ...config, slotted: true });
|
|
160
164
|
const styles = stylesheetBlock();
|
|
161
165
|
const shadow = `${styles}${result.sprites}${result.html}`;
|
|
162
166
|
return `<template shadowrootmode="open">${shadow}</template>`;
|
package/src/vite-plugin.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// preload: true, // Inject <link rel="preload"> for WASM
|
|
18
18
|
// })
|
|
19
19
|
|
|
20
|
-
import { existsSync, copyFileSync, mkdirSync, readFileSync } from 'fs';
|
|
20
|
+
import { existsSync, copyFileSync, mkdirSync, readFileSync, statSync } from 'fs';
|
|
21
21
|
import { dirname, join, resolve } from 'path';
|
|
22
22
|
import { fileURLToPath } from 'url';
|
|
23
23
|
import { UTILITIES_CSS, TOKENS_SHADOW_CSS } from '../generated/styles.js';
|
|
@@ -72,13 +72,19 @@ export function colletPlugin(options = {}) {
|
|
|
72
72
|
// 2. Copy WASM to public/ if missing
|
|
73
73
|
// 3. Serve CSS assets for DSD <link> refs
|
|
74
74
|
configureServer(server) {
|
|
75
|
-
//
|
|
75
|
+
// Always copy WASM to public/ — overwrites stale binaries from previous
|
|
76
|
+
// package versions. Without this, upgrading @colletdev/core leaves the old
|
|
77
|
+
// WASM in public/ and new components fail with "Unknown component" errors.
|
|
76
78
|
const wasmSrc = join(PKG_ROOT, 'wasm', 'wasm_api_bg.wasm');
|
|
77
79
|
const wasmDest = join(publicDir, 'wasm_api_bg.wasm');
|
|
78
|
-
if (existsSync(wasmSrc)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
if (existsSync(wasmSrc)) {
|
|
81
|
+
const srcSize = statSync(wasmSrc).size;
|
|
82
|
+
const destSize = existsSync(wasmDest) ? statSync(wasmDest).size : 0;
|
|
83
|
+
if (srcSize !== destSize) {
|
|
84
|
+
mkdirSync(publicDir, { recursive: true });
|
|
85
|
+
copyFileSync(wasmSrc, wasmDest);
|
|
86
|
+
server.config.logger.info('[collet] Updated wasm_api_bg.wasm in public/ (new version)');
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
server.middlewares.use((req, res, next) => {
|