@sugarcube-sh/vite 0.0.1
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 +9 -0
- package/README.md +25 -0
- package/dist/index.d.mts +30 -0
- package/dist/index.mjs +5 -0
- package/package.json +61 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Mark Tomlinson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @sugarcube-sh/vite
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@sugarcube-sh/vite"><img src="https://img.shields.io/npm/v/@sugarcube-sh/vite.svg" alt="Latest Release"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@sugarcube-sh/vite"><img src="https://img.shields.io/npm/dt/@sugarcube-sh/vite.svg" alt="Total Downloads"></a>
|
|
6
|
+
<a href="https://github.com/sugarcube-sh/sugarcube/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/license-see%20LICENSE-blue" alt="License"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
Vite plugin for [sugarcube](https://sugarcube.sh).
|
|
10
|
+
|
|
11
|
+
Automatically regenerates CSS variables and utilities when your design tokens change during development.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add -D @sugarcube-sh/vite
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
For full documentation, visit [sugarcube.sh](https://sugarcube.sh).
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
See [LICENSE.md](./LICENSE.md) for terms.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InternalConfig, NormalizedConvertedTokens } from '@sugarcube-sh/core';
|
|
2
|
+
export { SugarcubeConfig, defineConfig } from '@sugarcube-sh/core';
|
|
3
|
+
import { ViteDevServer, Logger, Plugin } from 'vite';
|
|
4
|
+
|
|
5
|
+
/** CSS object for UnoCSS rules - matches @unocss/core CSSObject */
|
|
6
|
+
type CSSObject = Record<string, string | number | undefined>;
|
|
7
|
+
/** UnoCSS dynamic rule: [pattern, handler] */
|
|
8
|
+
type UnoRule = [RegExp, (match: RegExpMatchArray) => CSSObject];
|
|
9
|
+
interface SugarcubePluginContext {
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
config: InternalConfig | null;
|
|
12
|
+
tokens: NormalizedConvertedTokens | null;
|
|
13
|
+
getCSS: () => string;
|
|
14
|
+
reloadConfig: () => Promise<void>;
|
|
15
|
+
reloadTokens: () => Promise<void>;
|
|
16
|
+
getRules: () => UnoRule[];
|
|
17
|
+
getTokenDirs: () => string[];
|
|
18
|
+
invalidate: (server: ViteDevServer) => void;
|
|
19
|
+
onReload: (fn: () => void) => void;
|
|
20
|
+
tasks: Promise<void>[];
|
|
21
|
+
flushTasks: () => Promise<void>;
|
|
22
|
+
setLogger: (logger: Logger) => void;
|
|
23
|
+
}
|
|
24
|
+
interface SugarcubePluginOptions<T = any> {
|
|
25
|
+
unoPresets?: T[];
|
|
26
|
+
unoTheme?: Record<string, any>;
|
|
27
|
+
}
|
|
28
|
+
declare function sugarcubePlugin(options?: SugarcubePluginOptions): Promise<Plugin[]>;
|
|
29
|
+
|
|
30
|
+
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-sh/core";import{defineConfig as Q}from"@sugarcube-sh/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")},C=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 k=p.map((M,x)=>` ${x+1}. ${M.message}`).join(`
|
|
3
|
+
`);u.warn(`[sugarcube] Found ${p.length} token error(s):
|
|
4
|
+
${k}`)}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:C(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 k of v)k();r.end("Reload Config")}catch(r){var g=r,n=!0}finally{S(l,g,n)}})();return C(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 C(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[k,M]of a.moduleGraph.idToModuleMap)if(k==="/__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 C=m,T=!0}finally{S(u,C,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,Q as defineConfig};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sugarcube-sh/vite",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"provenance": false
|
|
8
|
+
},
|
|
9
|
+
"description": "Vite plugin for sugarcube",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Mark Tomlinson",
|
|
13
|
+
"email": "mark@marktomlinson.dev",
|
|
14
|
+
"url": "https://marktomlinson.dev"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/sugarcube-sh/sugarcube"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/sugarcube-sh/sugarcube/issues"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"vite",
|
|
25
|
+
"vite-plugin",
|
|
26
|
+
"design-tokens",
|
|
27
|
+
"design-system",
|
|
28
|
+
"cube-css",
|
|
29
|
+
"css",
|
|
30
|
+
"sugarcube"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE.md"
|
|
36
|
+
],
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.mts",
|
|
40
|
+
"import": "./dist/index.mjs"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@unocss/vite": "66.5.2",
|
|
45
|
+
"@sugarcube-sh/core": "0.0.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"vite": "^5.2.0 || ^6 || ^7"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"pkgroll": "2.5.1",
|
|
52
|
+
"vite": "5.2.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "pkgroll --minify",
|
|
56
|
+
"dev": "pkgroll --watch",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"type-check": "tsc --noEmit"
|
|
60
|
+
}
|
|
61
|
+
}
|