@sugarcube-sh/vite 0.1.7 → 0.1.9
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.mts +8 -1
- package/dist/index.mjs +4 -4
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InternalConfig, NormalizedConvertedTokens } from '@sugarcube-sh/core';
|
|
1
|
+
import { InternalConfig, NormalizedConvertedTokens, TokenTree, ResolvedTokens } from '@sugarcube-sh/core';
|
|
2
2
|
export { SugarcubeConfig, defineConfig } from '@sugarcube-sh/core';
|
|
3
3
|
import { ViteDevServer, Logger } from 'vite';
|
|
4
4
|
|
|
@@ -38,7 +38,14 @@ interface SugarcubePluginContext {
|
|
|
38
38
|
ready: Promise<void>;
|
|
39
39
|
config: InternalConfig | null;
|
|
40
40
|
tokens: NormalizedConvertedTokens | null;
|
|
41
|
+
trees: TokenTree[] | null;
|
|
42
|
+
resolved: ResolvedTokens | null;
|
|
41
43
|
getCSS: () => string;
|
|
44
|
+
writeTokenEdits: (sourcePath: string, edits: Array<{
|
|
45
|
+
jsonPath: string[];
|
|
46
|
+
value: unknown;
|
|
47
|
+
}>) => Promise<void>;
|
|
48
|
+
rerunPipeline: (modifiedResolved: ResolvedTokens) => Promise<void>;
|
|
42
49
|
reloadConfig: () => Promise<void>;
|
|
43
50
|
reloadTokens: () => Promise<void>;
|
|
44
51
|
getRules: () => UnoRule[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
`);
|
|
4
|
-
${
|
|
1
|
+
var j=Object.defineProperty;var l=(o,r)=>j(o,"name",{value:r,configurable:!0});import{PerfMonitor as F,Instrumentation as v,loadInternalConfig as G,clearMatchCache as L,loadTokens as O,resolveTokens as N,convertTokens as R,generateCSSVariables as A,convertConfigToUnoRules as V}from"@sugarcube-sh/core";import{defineConfig as ie}from"@sugarcube-sh/core";import{readFile as $,writeFile as H}from"node:fs/promises";import{resolve as W}from"node:path";import U from"@unocss/vite";import{modify as B,applyEdits as q}from"jsonc-parser";var J=l((o,r)=>(r=Symbol[o])?r:Symbol.for("Symbol."+o),"__knownSymbol"),E=l(o=>{throw TypeError(o)},"__typeError"),m=l((o,r,s)=>{if(r!=null){typeof r!="object"&&typeof r!="function"&&E("Object expected");var p,h;p===void 0&&(p=r[J("dispose")]),typeof p!="function"&&E("Object not disposable"),h&&(p=l(function(){try{h.call(this)}catch(y){return Promise.reject(y)}},"dispose")),o.push([s,p,r])}return r},"__using"),b=l((o,r,s)=>{var p=typeof SuppressedError=="function"?SuppressedError:function(t,g,u,d){return d=Error(u),d.name="SuppressedError",d.error=t,d.suppressed=g,d},h=l(t=>r=s?new p(t,r,"An error was suppressed during disposal"):(s=!0,t),"fail"),y=l(t=>{for(;t=o.pop();)try{var g=t[1]&&t[1].call(t[2]);if(t[0])return Promise.resolve(g).then(y,u=>(h(u),y()))}catch(u){h(u)}if(s)throw r},"next");return y()},"__callDispose");const k=new F;function K(){let o=null,r=null,s=null,p=null,h="",y=[];const t=[],g=[];let u=null;const d=[],M={warn:l(e=>{u?u.warn(e):d.push({level:"warn",msg:e})},"warn"),info:l(e=>{u?u.info(e):d.push({level:"info",msg:e})},"info")},C=l(e=>(g.push(e),e.finally(()=>{const a=g.indexOf(e);a>-1&&g.splice(a,1)}),e),"addTask"),w=l(()=>{var e=[];try{if(!r||!o)return[];const n=m(e,new v);n.start("Build Rules");const i=V(o.utilities.classes??{},r);return n.end("Build Rules"),i}catch(n){var a=n,c=!0}finally{b(e,a,c)}},"buildRules"),x=l(async()=>{var e=[];try{if(!r||!o){h="";return}const n=m(e,new v);n.start("Generate CSS Variables"),h=(await A(r,o)).map(f=>f.css).join(`
|
|
2
|
+
`),n.end("Generate CSS Variables")}catch(n){var a=n,c=!0}finally{b(e,a,c)}},"generateCSS"),_=l(async()=>{await x(),y=w()},"updateAll"),I=l(async()=>{var e=[];try{if(!o)return;if(!o.resolver){M.warn("[sugarcube] No resolver path specified in config. Skipping token loading.");return}L();const n=m(e,new v);n.start("Load Tokens From Resolver");const i=await O({type:"resolver",resolverPath:o.resolver,config:o}),f=N(i.trees);n.end("Load Tokens From Resolver");const S=[...i.errors,...f.errors.flatten,...f.errors.validation,...f.errors.resolution];if(S.length>0){const T=S.map((P,D)=>` ${D+1}. ${P.message}`).join(`
|
|
3
|
+
`);M.warn(`[sugarcube] Found ${S.length} token error(s):
|
|
4
|
+
${T}`)}if(f.warnings.length>0)for(const T of f.warnings)M.warn(`[sugarcube] ${T.message}`);s=f.trees,p=f.resolved,n.start("Process Tokens"),r=await R(s,p,o,f.errors.validation),n.end("Process Tokens")}catch(n){var a=n,c=!0}finally{b(e,a,c)}},"runPipeline");return{ready:C(l(async()=>{var e=[];try{const n=m(e,new v);n.start("Initial total process");const{config:i}=await G();o=i,await I(),await _(),n.end("Initial total process")}catch(n){var a=n,c=!0}finally{b(e,a,c)}},"initialize")()),get config(){return o},get tokens(){return r},get trees(){return s},get resolved(){return p},get tasks(){return g},getRules(){return y},async rerunPipeline(e){const a=o,c=s;if(!a||!c)return;const n=(async()=>{r=await R(c,e,a),await x(),y=w()})();return C(n)},async reloadConfig(){const e=(async()=>{var a=[];try{const i=m(a,new v);i.start("Reload Config");const{config:f}=await G();o=f,await I(),await _();for(const S of t)S();i.end("Reload Config")}catch(i){var c=i,n=!0}finally{b(a,c,n)}})();return C(e)},async reloadTokens(){const e=(async()=>{var a=[];try{const i=m(a,new v);i.start("Reload total process"),await I(),await _();for(const f of t)f();i.end("Reload total process")}catch(i){var c=i,n=!0}finally{b(a,c,n)}})();return C(e)},getCSS(){return h},getTokenDirs(){return o?z(o):[]},invalidate(e){var a=[];try{const i=m(a,new v);i.start("Invalidate");const f=e.moduleGraph.idToModuleMap.size;k.log("SCANNING MODULE GRAPH for /__uno.css",{mapSize:f});for(const[S,T]of e.moduleGraph.idToModuleMap)if(S==="/__uno.css"){e.moduleGraph.invalidateModule(T),e.reloadModule(T);break}i.end("Invalidate")}catch(i){var c=i,n=!0}finally{b(a,c,n)}},onReload(e){t.push(e)},async writeTokenEdits(e,a){const c={formattingOptions:{tabSize:2,insertSpaces:!0}};let n=await $(e,"utf-8");for(const i of a){const f=B(n,i.jsonPath,i.value,c);n=q(n,f)}await H(e,n,"utf-8")},async flushTasks(){await Promise.all(g)},setLogger(e){u=e;for(const{level:a,msg:c}of d)u[a](c);d.length=0}}}l(K,"createSugarcubeContext");function z(o){if(!o.resolver)return[];const r=W(process.cwd(),o.resolver),s=r.lastIndexOf("/");return[r.slice(0,s)]}l(z,"extractTokenDirs");async function Q(o={}){const{unoOptions:r={}}=o,s=K();await s.ready;const p={name:"sugarcube",get rules(){return s.getRules()},preflights:[{getCSS:l(()=>s.getCSS(),"getCSS")}]},h={configFile:!1,...r,presets:[...r.presets||[],p]};return[{name:"sugarcube:config",configResolved(t){s.setLogger(t.logger)}},...U(h),{name:"sugarcube:virtual-css",enforce:"pre",config(){return{optimizeDeps:{exclude:["virtual:sugarcube.css"]}}},async resolveId(t){if(t==="virtual:sugarcube.css")return await this.resolve("virtual:uno.css",void 0,{skipSelf:!0})}},{name:"sugarcube:config-watcher",apply:"serve",configureServer(t){t.watcher.on("change",async g=>{if(g.endsWith("sugarcube.config.ts")||g.endsWith("sugarcube.config.js")){t.config.logger.info("[sugarcube] Config changed, reloading..."),k.log("CONFIG CHANGE DETECTED",{file:g.split("/").slice(-2).join("/")}),await s.reloadConfig();const u=t.config.plugins.find(d=>d.name==="unocss:api");u?.api&&await u.api.getContext().reloadConfig(),s.invalidate(t)}})}},{name:"sugarcube:token-watcher",apply:"serve",async configureServer(t){t.watcher.setMaxListeners(30),k.startMemoryMonitor(),k.logModuleGraphStats(t.moduleGraph.idToModuleMap.size,t.moduleGraph.urlToModuleMap.size,"server start");const g=s.getTokenDirs();if(g.length===0){t.config.logger.warn("[sugarcube] Could not determine token directories from config");return}t.watcher.on("all",(u,d)=>{k.trackWatcherEvent(d,t.moduleGraph.idToModuleMap.size)}),t.watcher.on("change",async u=>{if(u.endsWith(".json")&&g.some(w=>u.includes(w))){var d=[];try{t.config.logger.info("[sugarcube] Design tokens changed, reloading...");const w=m(d,new v);w.start("Total File Change Handler"),k.logModuleGraphStats(t.moduleGraph.idToModuleMap.size,t.moduleGraph.urlToModuleMap.size,"before reload"),await s.reloadTokens(),w.start("Vite Invalidate"),s.invalidate(t),w.end("Vite Invalidate"),k.logModuleGraphStats(t.moduleGraph.idToModuleMap.size,t.moduleGraph.urlToModuleMap.size,"after invalidate"),w.end("Total File Change Handler")}catch(w){var M=w,C=!0}finally{b(d,M,C)}}})}},{name:"sugarcube:api",api:{getContext:l(()=>s,"getContext")}},{name:"sugarcube:build",apply:"build",enforce:"pre",async configResolved(){await s.ready},async buildStart(){await s.flushTasks()}}]}l(Q,"sugarcubePlugin");export{Q as default,ie as defineConfig,z as extractTokenDirs};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarcube-sh/vite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -42,10 +42,11 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@unocss/vite": "^66.5.2",
|
|
45
|
-
"
|
|
45
|
+
"jsonc-parser": "^3.3.1",
|
|
46
|
+
"@sugarcube-sh/core": "0.2.2"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"vite": "^6.0.0 || ^7"
|
|
49
|
+
"vite": "^6.0.0 || ^7 || ^8"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"pkgroll": "^2.26.0",
|