@sugarcube-org/vite 0.0.0-alpha.10
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 +31 -0
- package/README.md +7 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +5 -0
- package/package.json +58 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Sugarcube Private Alpha License
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 Mark Tomlinson. All rights reserved.
|
|
4
|
+
|
|
5
|
+
**Version 1.0 – December 2025**
|
|
6
|
+
|
|
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.
|
|
10
|
+
|
|
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
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InternalConfig } from '@sugarcube-org/core';
|
|
2
|
+
export { UserConfig } from '@sugarcube-org/core';
|
|
3
|
+
import { Plugin, ViteDevServer, Logger } from 'vite';
|
|
4
|
+
|
|
5
|
+
interface SugarcubePluginContext {
|
|
6
|
+
ready: Promise<void>;
|
|
7
|
+
config: InternalConfig | null;
|
|
8
|
+
tokens: any | null;
|
|
9
|
+
/** Get all generated CSS variables */
|
|
10
|
+
getCSS: () => string;
|
|
11
|
+
reloadConfig: () => Promise<void>;
|
|
12
|
+
reloadTokens: () => Promise<void>;
|
|
13
|
+
getRules: () => any[];
|
|
14
|
+
getTokenDirs: () => string[];
|
|
15
|
+
invalidate: (server: ViteDevServer) => void;
|
|
16
|
+
onReload: (fn: () => void) => void;
|
|
17
|
+
tasks: Promise<any>[];
|
|
18
|
+
flushTasks: () => Promise<any>;
|
|
19
|
+
setLogger: (logger: Logger) => void;
|
|
20
|
+
}
|
|
21
|
+
interface SugarcubePluginOptions<T = any> {
|
|
22
|
+
unoPresets?: T[];
|
|
23
|
+
unoTheme?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
declare function sugarcubePlugin(options?: SugarcubePluginOptions): Promise<Plugin[]>;
|
|
26
|
+
|
|
27
|
+
export { type SugarcubePluginContext, sugarcubePlugin as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var E=Object.defineProperty;var d=(t,o)=>E(t,"name",{value:o,configurable:!0});import{PerfMonitor as j,Instrumentation as y,loadInternalConfig as R,clearMatchCache as D,loadAndResolveTokens as P,processAndConvertTokens as z,generateCSSVariables as O,convertConfigToUnoRules as L}from"@sugarcube-org/core";import A from"@unocss/vite";var N=d((t,o)=>(o=Symbol[t])?o:Symbol.for("Symbol."+t),"__knownSymbol"),G=d(t=>{throw TypeError(t)},"__typeError"),w=d((t,o,f)=>{if(o!=null){typeof o!="object"&&typeof o!="function"&&G("Object expected");var s,b;s===void 0&&(s=o[N("dispose")]),typeof s!="function"&&G("Object not disposable"),b&&(s=d(function(){try{b.call(this)}catch(v){return Promise.reject(v)}},"dispose")),t.push([f,s,o])}return o},"__using"),S=d((t,o,f)=>{var s=typeof SuppressedError=="function"?SuppressedError:function(e,i,c,u){return u=Error(c),u.name="SuppressedError",u.error=e,u.suppressed=i,u},b=d(e=>o=f?new s(e,o,"An error was suppressed during disposal"):(f=!0,e),"fail"),v=d(e=>{for(;e=t.pop();)try{var i=e[1]&&e[1].call(e[2]);if(e[0])return Promise.resolve(i).then(v,c=>(b(c),v()))}catch(c){b(c)}if(f)throw o},"next");return v()},"__callDispose");const h=new j;function F(){let t=null,o=null,f=[],s="",b=[];const v=[],e=[];let i=null;const c=[],u={warn:d(a=>{i?i.warn(a):c.push({level:"warn",msg:a})},"warn"),info:d(a=>{i?i.info(a):c.push({level:"info",msg:a})},"info")},k=d(a=>(e.push(a),a.finally(()=>{const l=e.indexOf(a);l>-1&&e.splice(l,1)}),a),"addTask"),T=d(()=>{var a=[];try{if(!o||!t)return[];const n=w(a,new y);n.start("Build Rules");const r=L(t.utilities??{},o);return n.end("Build Rules"),r}catch(n){var l=n,g=!0}finally{S(a,l,g)}},"buildRules"),m=d(async()=>{var a=[];try{if(!o||!t){s="";return}const n=w(a,new y);n.start("Generate CSS Variables"),s=(await O(o,t,f)).map(p=>p.css).join(`
|
|
2
|
+
`),n.end("Generate CSS Variables")}catch(n){var l=n,g=!0}finally{S(a,l,g)}},"generateCSS"),_=d(async()=>{await m(),b=T()},"updateAll"),I=d(async()=>{var a=[];try{if(!t)return;if(!t.resolver){u.warn("[sugarcube] No resolver path specified in config. Skipping token loading.");return}D();const n=w(a,new y);n.start("Load Tokens From Resolver");const r=await P({type:"resolver",resolverPath:t.resolver,config:t});n.end("Load Tokens From Resolver"),f=r.modifiers??[];const p=[...r.errors.load,...r.errors.flatten,...r.errors.validation,...r.errors.resolution];if(p.length>0){const C=p.map((M,x)=>` ${x+1}. ${M.message}`).join(`
|
|
3
|
+
`);u.warn(`[sugarcube] Found ${p.length} token error(s):
|
|
4
|
+
${C}`)}n.start("Process Tokens"),o=await z(r.trees,r.resolved,t,r.errors.validation),n.end("Process Tokens")}catch(n){var l=n,g=!0}finally{S(a,l,g)}},"loadTokens");return{ready:k(d(async()=>{var a=[];try{const n=w(a,new y);n.start("Initial total process");const{config:r}=await R();t=r,await I(),await _(),n.end("Initial total process")}catch(n){var l=n,g=!0}finally{S(a,l,g)}},"initialize")()),get config(){return t},get tokens(){return o},get tasks(){return e},getRules(){return b},async reloadConfig(){const a=(async()=>{var l=[];try{const r=w(l,new y);r.start("Reload Config");const{config:p}=await R();t=p,await _();for(const C of v)C();r.end("Reload Config")}catch(r){var g=r,n=!0}finally{S(l,g,n)}})();return k(a)},async reloadTokens(){const a=(async()=>{var l=[];try{const r=w(l,new y);r.start("Reload total process"),await I(),await _();for(const p of v)p();r.end("Reload total process")}catch(r){var g=r,n=!0}finally{S(l,g,n)}})();return k(a)},getCSS(){return s},getTokenDirs(){return t?W(t):[]},invalidate(a){var l=[];try{const r=w(l,new y);r.start("Invalidate");const p=a.moduleGraph.idToModuleMap.size;h.log("SCANNING MODULE GRAPH for /__uno.css",{mapSize:p});for(const[C,M]of a.moduleGraph.idToModuleMap)if(C==="/__uno.css"){a.moduleGraph.invalidateModule(M),a.reloadModule(M);break}r.end("Invalidate")}catch(r){var g=r,n=!0}finally{S(l,g,n)}},onReload(a){v.push(a)},async flushTasks(){await Promise.all(e)},setLogger(a){i=a;for(const{level:l,msg:g}of c)i[l](g);c.length=0}}}d(F,"createSugarcubeContext");function W(t){if(!t.resolver)return[];const o=t.resolver.lastIndexOf("/");return[o===-1?".":t.resolver.slice(0,o)]}d(W,"extractTokenDirs");async function U(t={}){const{unoPresets:o=[],unoTheme:f}=t,s=F();await s.ready;const b={name:"sugarcube",get rules(){return s.getRules()}};return[{name:"sugarcube:config",configResolved(e){s.setLogger(e.logger)}},...A({presets:[...o,b],theme:f}),{name:"sugarcube:virtual-css",enforce:"pre",config(){return{optimizeDeps:{exclude:["virtual:sugarcube.css","virtual:sugarcube/variables.css","virtual:sugarcube/utilities.css"]}}},resolveId(e){if(e==="virtual:sugarcube/variables.css")return"/__sugarcube_variables.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:s.getCSS(),map:{mappings:""}};if(i==="/__sugarcube_combined.js")return{code:`import "virtual:sugarcube/variables.css";
|
|
5
|
+
import "virtual:uno.css";`,map:null}}},{name:"sugarcube:config-watcher",apply:"serve",configureServer(e){h.logWatcherSetup("sugarcube.config.ts/js",process.cwd()),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")){e.config.logger.info("[sugarcube] Config changed, reloading..."),h.log("CONFIG CHANGE DETECTED",{file:i.split("/").slice(-2).join("/")}),await s.reloadConfig();const c=e.config.plugins.find(u=>u.name==="unocss:api");if(c?.api){const u=c.api.getContext();h.log("FORCING UNOCSS RELOAD"),await u.reloadConfig(),h.log("UNO CSS RELOAD COMPLETE")}s.invalidate(e)}})}},{name:"sugarcube:token-watcher",apply:"serve",async configureServer(e){e.watcher.setMaxListeners(30),h.startMemoryMonitor(),h.logModuleGraphStats(e.moduleGraph.idToModuleMap.size,e.moduleGraph.urlToModuleMap.size,"server start");const i=s.getTokenDirs();if(i.length===0){e.config.logger.warn("[sugarcube] Could not determine token directories from config");return}for(const c of i){const u=`${c}/**/*.json`;h.logWatcherSetup(u,c),e.watcher.add(u)}e.watcher.on("all",(c,u)=>{h.trackWatcherEvent(u,e.moduleGraph.idToModuleMap.size)}),e.watcher.on("change",async c=>{if(c.endsWith(".json")&&i.some(m=>c.includes(m))){var u=[];try{e.config.logger.info("[sugarcube] Design tokens changed, reloading...");const m=w(u,new y);m.start("Total File Change Handler"),h.logModuleGraphStats(e.moduleGraph.idToModuleMap.size,e.moduleGraph.urlToModuleMap.size,"before reload"),await s.reloadTokens();const _=e.moduleGraph.getModuleById("/__sugarcube_variables.css");_&&(e.moduleGraph.invalidateModule(_),e.reloadModule(_)),m.start("Vite Invalidate"),s.invalidate(e),m.end("Vite Invalidate"),h.logModuleGraphStats(e.moduleGraph.idToModuleMap.size,e.moduleGraph.urlToModuleMap.size,"after invalidate"),m.end("Total File Change Handler")}catch(m){var k=m,T=!0}finally{S(u,k,T)}}})}},{name:"sugarcube:api",api:{getContext:d(()=>s,"getContext")}},{name:"sugarcube:build",apply:"build",enforce:"pre",async configResolved(){await s.ready},async buildStart(){await s.flushTasks()}}]}d(U,"sugarcubePlugin");export{U as default};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sugarcube-org/vite",
|
|
3
|
+
"version": "0.0.0-alpha.10",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"provenance": false
|
|
8
|
+
},
|
|
9
|
+
"description": "Vite plugin for sugarcube",
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
11
|
+
"author": "Mark Tomlinson",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/sugarcube-org/sugarcube"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/sugarcube-org/sugarcube/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"vite",
|
|
21
|
+
"design-tokens",
|
|
22
|
+
"design-system",
|
|
23
|
+
"css",
|
|
24
|
+
"sugarcube"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE.md"
|
|
30
|
+
],
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
34
|
+
"import": "./dist/index.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@sugarcube-org/core": "0.0.1-alpha.12",
|
|
39
|
+
"@types/micromatch": "4.0.9",
|
|
40
|
+
"@unocss/vite": "66.5.2",
|
|
41
|
+
"fast-glob": "3.3.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"vite": "^5.2.0 || ^6 || ^7"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"pkgroll": "2.5.1",
|
|
48
|
+
"tsx": "4.19.2",
|
|
49
|
+
"vite": "7.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "pkgroll --minify",
|
|
53
|
+
"dev": "pkgroll --watch",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"type-check": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|