@sugarcube-org/vite 0.0.0-alpha.3 → 0.0.0-alpha.4

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.md CHANGED
@@ -1,9 +1,31 @@
1
- # Proprietary Software
1
+ # Sugarcube Private Alpha License
2
2
 
3
- This software is proprietary and confidential. All rights reserved.
3
+ Copyright © 2025 Mark Tomlinson. All rights reserved.
4
4
 
5
- Copyright (c) 2025 Mark Tomlinson
5
+ **Version 1.0 December 2025**
6
6
 
7
- This software is provided "as is" without warranty of any kind, either express or implied.
7
+ This software is provided under a temporary, non-exclusive, non-transferable
8
+ license for private evaluation and internal use as part of the Sugarcube
9
+ Private Alpha Program.
8
10
 
9
- Unauthorized copying, distribution, or use of this software is strictly prohibited.
11
+ ## Permitted
12
+
13
+ - Use in internal and client projects for the purpose of evaluating Sugarcube
14
+ - Reporting bugs, performance issues, and usability feedback
15
+
16
+ ## Not Permitted
17
+
18
+ - Redistribution of the software or any derivative works
19
+ - Public hosting of the source code
20
+ - Sublicensing, resale, or commercial distribution of Sugarcube itself
21
+ - Reverse engineering for the purpose of creating a competing product
22
+
23
+ ## Disclaimer
24
+
25
+ This software is provided "as is", without warranty of any kind, express or
26
+ implied. The author assumes no liability for damages arising from its use.
27
+
28
+ ## Future Licensing
29
+
30
+ This license will be replaced by an open-source license at public beta or
31
+ general availability.
package/README.md CHANGED
@@ -1,42 +1,7 @@
1
1
  # @sugarcube-org/vite
2
2
 
3
- Vite plugin for automatic sugarcube CSS generation.
3
+ > ⚠️ **Private Alpha** This package is under active development and not yet ready for public use.
4
4
 
5
- ## What it does
5
+ ## License
6
6
 
7
- - Automatically regenerates CSS variables and utilities when design tokens change
8
- - Integrates with Vite's file watching and hot module replacement
9
- - Provides seamless development experience for sugarcube projects
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm install @sugarcube-org/vite
15
- ```
16
-
17
- ## Usage
18
-
19
- ```js
20
- // vite.config.js
21
- import { defineConfig } from 'vite'
22
- import sugarcube from '@sugarcube-org/vite'
23
-
24
- export default defineConfig({
25
- plugins: [sugarcube()]
26
- })
27
- ```
28
-
29
- ## Features
30
-
31
- - **Hot reload** - CSS updates automatically when tokens change
32
- - **File watching** - Monitors token files and configuration
33
- - **Error handling** - Graceful error reporting in development
34
- - **Performance** - Efficient processing with caching
35
-
36
- ## Development
37
-
38
- ```bash
39
- pnpm install
40
- pnpm build
41
- pnpm test
42
- ```
7
+ See [LICENSE.md](./LICENSE.md) for terms.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,30 @@
1
- import { Plugin } from 'vite';
1
+ import { InternalConfig } from '@sugarcube-org/core';
2
+ export { UserConfig } from '@sugarcube-org/core';
3
+ import { Plugin, ViteDevServer } from 'vite';
2
4
 
3
- declare function sugarcubePlugin(): Plugin;
5
+ interface SugarcubePluginContext {
6
+ ready: Promise<void>;
7
+ config: InternalConfig | null;
8
+ tokens: any | null;
9
+ cssCache: Map<string, string>;
10
+ getCSS: (collection?: string) => string;
11
+ getCollections: () => string[];
12
+ tokenFiles: string[];
13
+ reloadConfig: () => Promise<void>;
14
+ reloadTokens: () => Promise<void>;
15
+ getRules: () => any[];
16
+ getTokenFiles: () => Promise<string[]>;
17
+ getTokenDirs: () => string[];
18
+ clearTokenFilesCache: () => void;
19
+ invalidate: (server: ViteDevServer) => void;
20
+ onReload: (fn: () => void) => void;
21
+ tasks: Promise<any>[];
22
+ flushTasks: () => Promise<any>;
23
+ }
24
+ interface SugarcubePluginOptions<T = any> {
25
+ unoPresets?: T[];
26
+ unoTheme?: Record<string, any>;
27
+ }
28
+ declare function sugarcubePlugin(options?: SugarcubePluginOptions): Promise<Plugin[]>;
4
29
 
5
- export { sugarcubePlugin as default };
30
+ export { type SugarcubePluginContext, sugarcubePlugin as default };
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- var _=Object.defineProperty;var c=(t,n)=>_(t,"name",{value:n,configurable:!0});import{loadConfig as k,normalizeConfig as C,Instrumentation as w,generateIndex as v,tokenProcessingPipeline as W,generateCSSVariables as D,writeCSSVariablesToDisk as T,generateCSSUtilityClasses as V,writeCSSUtilitiesToDisk as z}from"@sugarcube-org/core";import{normalize as m,relative as G}from"pathe";var I=c((t,n)=>(n=Symbol[t])?n:Symbol.for("Symbol."+t),"__knownSymbol"),P=c(t=>{throw TypeError(t)},"__typeError"),S=c((t,n,u)=>{if(n!=null){typeof n!="object"&&typeof n!="function"&&P("Object expected");var f,d;f===void 0&&(f=n[I("dispose")]),typeof f!="function"&&P("Object not disposable"),d&&(f=c(function(){try{d.call(this)}catch(p){return Promise.reject(p)}},"dispose")),t.push([u,f,n])}return n},"__using"),y=c((t,n,u)=>{var f=typeof SuppressedError=="function"?SuppressedError:function(l,e,i,a){return a=Error(i),a.name="SuppressedError",a.error=l,a.suppressed=e,a},d=c(l=>n=u?new f(l,n,"An error was suppressed during disposal"):(u=!0,l),"fail"),p=c(l=>{for(;l=t.pop();)try{var e=l[1]&&l[1].call(l[2]);if(l[0])return Promise.resolve(e).then(p,i=>(d(i),p()))}catch(i){d(i)}if(u)throw n},"next");return p()},"__callDispose");let b=null;const o=process.env.DEBUG==="true",E=c((t,n)=>{if(!b){console.error(`[sugarcube] ${t}`,n);return}const u=n instanceof Error?n.message:String(n);b.config.logger.error(`[sugarcube] ${t}${u}`)},"reportError"),j=c(t=>{try{return m(G(process.cwd(),t))}catch(n){return o&&console.warn("[sugarcube] Failed to convert path to relative:",t,n),m(t)}},"toRelativePath");function x(){let t=null;const n=c(e=>{if(!t)return!1;const i=j(e),a=t.config.output.tokens;return i.startsWith(a)&&i.endsWith(".json")},"isTokenFile"),u=c(e=>e===t?.configPath,"isSCConfigFile"),f=c(async()=>{var e=[];try{const s=S(e,new w);if(o&&s.start("Process Tokens"),!t)throw new Error("Sugarcube config not initialized");o&&s.start("Token Processing Pipeline");const r=await W({type:"files",config:t.config}),g=[...r.errors.load,...r.errors.flatten,...r.errors.validation,...r.errors.resolution];return g.length>0&&E(`Token processing issues found:
2
- `,g.map(h=>` - ${h.message}`).join(`
3
- `)),o&&s.end("Token Processing Pipeline"),o&&s.end("Process Tokens"),{resolved:r.resolved,trees:r.trees}}catch(s){var i=s,a=!0}finally{y(e,i,a)}},"processTokens"),d=c(async e=>{var i=[];try{const r=S(i,new w);if(o&&r.start("Generate and Write CSS Variables"),!t)throw new Error("Sugarcube config not initialized");o&&r.start("CSS Variables Pipeline");const g=await D(e.trees,e.resolved,t.config);o&&r.end("CSS Variables Pipeline"),o&&r.start("Write CSS Variables to Disk"),await T(g.output),o&&r.end("Write CSS Variables to Disk"),o&&r.end("Generate and Write CSS Variables")}catch(r){var a=r,s=!0}finally{y(i,a,s)}},"generateAndWriteCSSVariables"),p=c(async e=>{var i=[];try{const r=S(i,new w);if(o&&r.start("Generate and Write Utilities"),!t)throw new Error("Sugarcube config not initialized");o&&r.start("Generate Utility CSS");const{output:g}=V(e.resolved,t.config);o&&r.end("Generate Utility CSS"),o&&r.start("Write CSS Utilities to Disk"),await z(g),o&&r.end("Write CSS Utilities to Disk"),o&&r.end("Generate and Write Utilities")}catch(r){var a=r,s=!0}finally{y(i,a,s)}},"generateAndWriteUtilities"),l=c(async()=>{var e=[];try{const s=S(e,new w);o&&s.start("Process and Update");try{const r=await f();await d(r),await p(r)}catch(r){E("Sugarcube processing failed",r)}o&&s.end("Process and Update")}catch(s){var i=s,a=!0}finally{y(e,i,a)}},"processAndUpdate");return{name:"vite-plugin-sugarcube",async config(){try{if(t=await k(),!t)throw new Error("Failed to load Sugarcube config");const e=C(t.config);return t={...t,config:e},{exclude:[t.config.output.css]}}catch(e){throw e instanceof Error?new Error(`[sugarcube] Configuration error:
4
- ${e.message}`):e}},async configResolved(e){if(!t)throw new Error("Sugarcube config not initialized")},async buildStart(){await l()},configureServer(e){var i=[];try{const r=S(i,new w);if(b=e,t){e.watcher.add(t.config.output.tokens),e.watcher.add(t.config.output.css);const g=t.config,h=t.config.output.css;e.watcher.on("add",async U=>{await v(h,g)}),e.watcher.on("unlink",async U=>{await v(h,g)})}t?.configPath&&e.watcher.add(t.configPath)}catch(r){var a=r,s=!0}finally{y(i,a,s)}},async handleHotUpdate({file:e}){if(!e.includes("/.astro/")&&(n(e)||u(e))){if(u(e)&&(t=await k(),t)){const i=C(t.config);t={...t,config:i}}return await l(),[]}}}}c(x,"sugarcubePlugin");export{x as default};
1
+ var j=Object.defineProperty;var g=(n,a)=>j(n,"name",{value:a,configurable:!0});import{Instrumentation as v,loadInternalConfig as I,loadAndResolveTokens as F,processAndConvertTokens as M,generateCSSVariables as D,convertConfigToUnoRules as P}from"@sugarcube-org/core";import O from"@unocss/vite";import $ from"fast-glob";var A=g((n,a)=>(a=Symbol[n])?a:Symbol.for("Symbol."+n),"__knownSymbol"),x=g(n=>{throw TypeError(n)},"__typeError"),_=g((n,a,d)=>{if(a!=null){typeof a!="object"&&typeof a!="function"&&x("Object expected");var t,c;t===void 0&&(t=a[A("dispose")]),typeof t!="function"&&x("Object not disposable"),c&&(t=g(function(){try{c.call(this)}catch(f){return Promise.reject(f)}},"dispose")),n.push([d,t,a])}return a},"__using"),k=g((n,a,d)=>{var t=typeof SuppressedError=="function"?SuppressedError:function(e,i,l,p){return p=Error(l),p.name="SuppressedError",p.error=e,p.suppressed=i,p},c=g(e=>a=d?new t(e,a,"An error was suppressed during disposal"):(d=!0,e),"fail"),f=g(e=>{for(;e=n.pop();)try{var i=e[1]&&e[1].call(e[2]);if(e[0])return Promise.resolve(i).then(f,l=>(c(l),f()))}catch(l){c(l)}if(d)throw a},"next");return f()},"__callDispose");function E(){let n=null,a=null;const d=new Map;let t=[],c=[];const f=[],e=[],i=g(s=>(e.push(s),s.finally(()=>{const u=e.indexOf(s);u>-1&&e.splice(u,1)}),s),"addTask"),l=g(()=>{var s=[];try{if(!a||!n)return[];const o=_(s,new v);o.start("Build Rules");const r=P(n.utilities??{},a);return o.end("Build Rules"),r}catch(o){var u=o,h=!0}finally{k(s,u,h)}},"buildRules"),p=g(async()=>{var s=[];try{if(!a||!n){d.clear();return}const o=_(s,new v);o.start("Generate CSS Variables");const r=await D(a,n);d.clear();for(const b of r){const m=b.collection??"default",T=d.get(m)||"";d.set(m,T+b.css)}o.end("Generate CSS Variables")}catch(o){var u=o,h=!0}finally{k(s,u,h)}},"generateCSS"),w=g(async()=>{await p(),t=l()},"updateAll"),C=g(async()=>{var s=[];try{if(!n)return;const o=_(s,new v);o.start("Load Tokens From Disk");const r=await F({type:"files",config:n});o.end("Load Tokens From Disk");const b=[...r.errors.load,...r.errors.flatten,...r.errors.validation,...r.errors.resolution];b.length>0&&(console.warn(`[sugarcube] Found ${b.length} token error(s):`),b.forEach((m,T)=>{console.warn(` ${T+1}. ${m.message}`)})),o.start("Process Tokens"),a=await M(r.trees,r.resolved,n,r.errors.validation),o.end("Process Tokens")}catch(o){var u=o,h=!0}finally{k(s,u,h)}},"loadTokens");return{ready:i(g(async()=>{var s=[];try{const o=_(s,new v);o.start("Initial total process");const{config:r}=await I();n=r,await C(),await w(),o.end("Initial total process")}catch(o){var u=o,h=!0}finally{k(s,u,h)}},"initialize")()),get config(){return n},get tokens(){return a},get cssCache(){return d},get tokenFiles(){return c},get tasks(){return e},getRules(){return t},async reloadConfig(){const s=(async()=>{var u=[];try{const r=_(u,new v);r.start("Reload Config");const{config:b}=await I();n=b,await w();for(const m of f)m();r.end("Reload Config")}catch(r){var h=r,o=!0}finally{k(u,h,o)}})();return i(s)},async reloadTokens(){const s=(async()=>{var u=[];try{const r=_(u,new v);r.start("Reload total process"),await C(),await w();for(const b of f)b();r.end("Reload total process")}catch(r){var h=r,o=!0}finally{k(u,h,o)}})();return i(s)},getCSS(s){return s?d.get(s)||"":Array.from(d.values()).join(`
2
+ `)},getCollections(){return Array.from(d.keys())},async getTokenFiles(){if(c.length===0&&n){const u=R(n).map(h=>`${h}/**/*.json`);u.length>0&&(c=await $(u,{onlyFiles:!0}))}return c},getTokenDirs(){return n?R(n):[]},clearTokenFilesCache(){c=[]},invalidate(s){var u=[];try{const r=_(u,new v);r.start("Invalidate");for(const[b,m]of s.moduleGraph.idToModuleMap)if(b==="/__uno.css"){console.log("Invalidating UnoCSS virtual module"),s.moduleGraph.invalidateModule(m),s.reloadModule(m);break}r.end("Invalidate")}catch(r){var h=r,o=!0}finally{k(u,h,o)}},onReload(s){f.push(s)},async flushTasks(){await Promise.all(e)}}}g(E,"createSugarcubeContext");function R(n){const a=new Set,d=g(t=>{const c=t.indexOf("*");if(c!==-1){const e=t.slice(0,c),i=e.lastIndexOf("/");return i===-1?".":e.slice(0,i)}const f=t.lastIndexOf("/");return f===-1?".":t.slice(0,f)},"extractDir");if(n.tokens&&"source"in n.tokens){const t=n.tokens;for(const c of t.source)a.add(d(c));if(t.themes)for(const c of Object.values(t.themes))for(const f of c)a.add(d(f))}else{const t=n.tokens;for(const c of Object.values(t)){for(const f of c.source)a.add(d(f));if(c.themes)for(const f of Object.values(c.themes))for(const e of f)a.add(d(e))}}return Array.from(a)}g(R,"extractTokenDirs");async function G(n={}){const{unoPresets:a=[],unoTheme:d}=n,t=E();await t.ready;const c={name:"sugarcube",get rules(){return t.getRules()}};return[...O({presets:[...a,c],theme:d}),{name:"sugarcube:virtual-css",enforce:"pre",resolveId(e,i){if(e==="virtual:sugarcube/variables.css")return"/__sugarcube_variables.css";const l=e.match(/^virtual:sugarcube\/variables\/(.+)\.css$/);if(l)return`/__sugarcube_variables_${l[1]}.css`;if(e==="virtual:sugarcube/utilities.css")return"/__uno.css";if(e==="virtual:sugarcube.css")return"/__sugarcube_combined.js"},load(e){const i=e.split("?")[0];if(i==="/__sugarcube_variables.css")return{code:t.getCSS(),map:{mappings:""}};if(i?.startsWith("/__sugarcube_variables_")){const l=i.match(/^\/__sugarcube_variables_(.+)\.css$/);if(l){const p=l[1];return{code:t.getCSS(p),map:{mappings:""}}}}if(i==="/__sugarcube_combined.js")return{code:`import "virtual:sugarcube/variables.css";
3
+ import "virtual:uno.css";`,map:null}}},{name:"sugarcube:config-watcher",apply:"serve",configureServer(e){e.watcher.add(["sugarcube.config.ts","sugarcube.config.js"]),e.watcher.on("change",async i=>{if(i.endsWith("sugarcube.config.ts")||i.endsWith("sugarcube.config.js")){console.log("[sugarcube] Config changed, reloading..."),await t.reloadConfig();const l=e.config.plugins.find(p=>p.name==="unocss:api");if(l?.api){const p=l.api.getContext();console.log("[sugarcube] Forcing UnoCSS config reload"),await p.reloadConfig()}t.invalidate(e)}})}},{name:"sugarcube:token-watcher",apply:"serve",async configureServer(e){e.watcher.setMaxListeners(30);const i=t.getTokenDirs();if(i.length===0){console.warn("[sugarcube] Could not determine token directories from config");return}for(const l of i)e.watcher.add(`${l}/**/*.json`);e.watcher.on("change",async l=>{if(l.endsWith(".json")&&i.some(y=>l.includes(y))){var p=[];try{t.clearTokenFilesCache(),console.log("[sugarcube] Design tokens changed, reloading...");const y=_(p,new v);y.start("Total File Change Handler"),await t.reloadTokens();const S=e.moduleGraph.getModuleById("/__sugarcube_variables.css");S&&(e.moduleGraph.invalidateModule(S),e.reloadModule(S)),y.start("Vite Invalidate"),t.invalidate(e),y.end("Vite Invalidate"),y.end("Total File Change Handler")}catch(y){var w=y,C=!0}finally{k(p,w,C)}}})}},{name:"sugarcube:api",api:{getContext:g(()=>t,"getContext")}},{name:"sugarcube:build",apply:"build",enforce:"pre",async configResolved(){await t.ready},async buildStart(){await t.flushTasks()}}]}g(G,"sugarcubePlugin");export{G as default};
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@sugarcube-org/vite",
3
- "version": "0.0.0-alpha.3",
3
+ "version": "0.0.0-alpha.4",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
- "access": "public"
6
+ "access": "public",
7
+ "provenance": false
7
8
  },
8
9
  "description": "Vite plugin for sugarcube",
9
- "license": "UNLICENSED",
10
+ "license": "SEE LICENSE IN LICENSE.md",
10
11
  "author": "Mark Tomlinson",
11
12
  "repository": {
12
13
  "type": "git",
@@ -23,7 +24,9 @@
23
24
  "sugarcube"
24
25
  ],
25
26
  "files": [
26
- "dist/"
27
+ "dist/",
28
+ "README.md",
29
+ "LICENSE.md"
27
30
  ],
28
31
  "exports": {
29
32
  ".": {
@@ -32,17 +35,18 @@
32
35
  }
33
36
  },
34
37
  "dependencies": {
35
- "minimatch": "^10.0.1",
36
- "pathe": "^2.0.3",
37
- "@sugarcube-org/core": "0.0.1-alpha.6"
38
+ "@sugarcube-org/core": "0.0.1-alpha.7",
39
+ "@types/micromatch": "4.0.9",
40
+ "@unocss/vite": "66.5.2",
41
+ "fast-glob": "3.3.3"
38
42
  },
39
43
  "peerDependencies": {
40
- "vite": "^5.2.0 || ^6"
44
+ "vite": "^5.2.0 || ^6 || ^7"
41
45
  },
42
46
  "devDependencies": {
43
- "pkgroll": "^2.5.1",
44
- "tsx": "^4.19.2",
45
- "vite": "^6.0.0"
47
+ "pkgroll": "2.5.1",
48
+ "tsx": "4.19.2",
49
+ "vite": "7.0.0"
46
50
  },
47
51
  "scripts": {
48
52
  "build": "pkgroll --minify",