@salty-css/core 0.0.1-alpha.60 → 0.0.1-alpha.62

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/bin/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ee=require("ejs"),te=require("../compiler/index.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),_=require("winston"),ne=require("child_process"),se=require("ora");var H=typeof document<"u"?document.currentScript:null;const t=_.createLogger({level:"debug",format:_.format.combine(_.format.colorize(),_.format.cli()),transports:[new _.transports.Console({})]}),m=r=>{t.error(r)},B=r=>new Promise((h,C)=>{ne.exec(r,P=>{if(P)return C(P);h()})}),b=async(...r)=>{const h=r.map(F=>F.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),C=se(`Installing packages: ${h}`).start(),P=r.join(" ");await B(`npm install ${P}`),C.succeed(`Installed packages: ${h}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function A(r){try{if(!ae())return;await B(`./node_modules/.bin/prettier --write "${r}"`),t.info(`Formatted ${r} with Prettier`)}catch(h){t.error(`Error formatting ${r} with Prettier:`,h)}}async function oe(){const r=new Z.Command;r.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const h={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-BupieCfE.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs"))},C=async(i,a)=>{const{default:o}=await h[i],u=ee.render(o,a);return{fileName:i,content:u}},P=async()=>{const i=n.join(process.cwd(),".saltyrc");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},F=n.join(process.cwd(),"package.json"),$=async(i=F)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},V=async(i,a=F)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},z=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("bin/main.cjs",document.baseURI).href);return $(i)},M=await(async()=>(await P()).defaultProject)(),k=await z(),J={core:`@salty-css/core@${k.version}`,react:`@salty-css/react@${k.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${k.version}`,vite:`@salty-css/vite@${k.version}`,next:`@salty-css/next@${k.version}`},T=i=>{const a=i==="."?"":i,o=process.cwd();return n.join(o,a)};r.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await $().catch(()=>{}))return m("Salty CSS project must be initialized in a directory with a package.json file.");t.info("Initializing a new Salty-CSS project!");const{dir:o=i,cssFile:u,skipInstall:g}=this.opts();if(!o)return m("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");g||(await b(J.core,J.react),await b(`-D ${J.eslintPluginCore}`));const f=process.cwd(),l=T(o),j=await Promise.all([C("salty.config.ts"),C("saltygen/index.css")]);await s.mkdir(l,{recursive:!0});const y=j.map(async({fileName:e,content:d})=>{const c=n.join(l,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.debug("File already exists: "+c);return}const v=e.split("/").slice(0,-1).join("/");v&&await s.mkdir(n.join(l,v),{recursive:!0}),t.info("Creating file: "+c),await s.writeFile(c,d),await A(c)});await Promise.all(y);const D=n.relative(f,l)||".",p=n.join(f,".saltyrc"),w=await s.readFile(p,"utf-8").catch(()=>{});if(w===void 0){t.info("Creating file: "+p);const d=JSON.stringify({defaultProject:D,projects:[D]},null,2);await s.writeFile(p,d)}else{t.info("Edit file: "+p);const e=JSON.parse(w),d=new Set((e==null?void 0:e.projects)||[]);d.add(D),e.projects=[...d];const c=JSON.stringify(e,null,2);await s.writeFile(p,c)}const E=n.join(f,".gitignore"),I=await s.readFile(E,"utf-8").catch(()=>{});I!==void 0&&(I.includes("saltygen")||(t.info("Edit file: "+E),await s.writeFile(E,I+`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ee=require("ejs"),te=require("../compiler/index.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),_=require("winston"),ne=require("child_process"),se=require("ora");var H=typeof document<"u"?document.currentScript:null;const t=_.createLogger({level:"debug",format:_.format.combine(_.format.colorize(),_.format.cli()),transports:[new _.transports.Console({})]}),m=r=>{t.error(r)},B=r=>new Promise((h,C)=>{ne.exec(r,P=>{if(P)return C(P);h()})}),b=async(...r)=>{const h=r.map(F=>F.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),C=se(`Installing packages: ${h}`).start(),P=r.join(" ");await B(`npm install ${P}`),C.succeed(`Installed packages: ${h}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function A(r){try{if(!ae())return;await B(`./node_modules/.bin/prettier --write "${r}"`),t.info(`Formatted ${r} with Prettier`)}catch(h){t.error(`Error formatting ${r} with Prettier:`,h)}}async function oe(){const r=new Z.Command;r.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const h={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs"))},C=async(i,a)=>{const{default:o}=await h[i],u=ee.render(o,a);return{fileName:i,content:u}},P=async()=>{const i=n.join(process.cwd(),".saltyrc");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},F=n.join(process.cwd(),"package.json"),$=async(i=F)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},V=async(i,a=F)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},z=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:H&&H.tagName.toUpperCase()==="SCRIPT"&&H.src||new URL("bin/main.cjs",document.baseURI).href);return $(i)},M=await(async()=>(await P()).defaultProject)(),k=await z(),J={core:`@salty-css/core@${k.version}`,react:`@salty-css/react@${k.version}`,eslintPluginCore:`@salty-css/eslint-plugin-core@${k.version}`,vite:`@salty-css/vite@${k.version}`,next:`@salty-css/next@${k.version}`},T=i=>{const a=i==="."?"":i,o=process.cwd();return n.join(o,a)};r.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await $().catch(()=>{}))return m("Salty CSS project must be initialized in a directory with a package.json file.");t.info("Initializing a new Salty-CSS project!");const{dir:o=i,cssFile:u,skipInstall:g}=this.opts();if(!o)return m("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");g||(await b(J.core,J.react),await b(`-D ${J.eslintPluginCore}`));const f=process.cwd(),l=T(o),j=await Promise.all([C("salty.config.ts"),C("saltygen/index.css")]);await s.mkdir(l,{recursive:!0});const y=j.map(async({fileName:e,content:d})=>{const c=n.join(l,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.debug("File already exists: "+c);return}const v=e.split("/").slice(0,-1).join("/");v&&await s.mkdir(n.join(l,v),{recursive:!0}),t.info("Creating file: "+c),await s.writeFile(c,d),await A(c)});await Promise.all(y);const D=n.relative(f,l)||".",p=n.join(f,".saltyrc"),w=await s.readFile(p,"utf-8").catch(()=>{});if(w===void 0){t.info("Creating file: "+p);const d=JSON.stringify({defaultProject:D,projects:[D]},null,2);await s.writeFile(p,d)}else{t.info("Edit file: "+p);const e=JSON.parse(w),d=new Set((e==null?void 0:e.projects)||[]);d.add(D),e.projects=[...d];const c=JSON.stringify(e,null,2);await s.writeFile(p,c)}const E=n.join(f,".gitignore"),I=await s.readFile(E,"utf-8").catch(()=>{});I!==void 0&&(I.includes("saltygen")||(t.info("Edit file: "+E),await s.writeFile(E,I+`
2
2
 
3
3
  # Salty-CSS
4
4
  saltygen
package/bin/main.js CHANGED
@@ -36,7 +36,7 @@ async function xt() {
36
36
  o.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");
37
37
  const h = {
38
38
  // Core files
39
- "salty.config.ts": import("../salty.config-D9ANEDiH.js"),
39
+ "salty.config.ts": import("../salty.config-BhBY_oOk.js"),
40
40
  "saltygen/index.css": import("../index-D_732b92.js"),
41
41
  // React
42
42
  "react/react-styled-file.ts": import("../react-styled-file-CGVf5n1B.js")
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("esbuild"),G=require("child_process"),N=require("../dash-case-DKzpenwY.cjs"),i=require("path"),a=require("fs"),J=require("fs/promises"),R=require("../parse-templates-DVK3iZIl.cjs");var V=typeof document<"u"?document.currentScript:null;function A(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const q=A(L),I=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:V&&V.tagName.toUpperCase()==="SCRIPT"&&V.src||new URL("compiler/index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",O=e=>i.join(e,"./saltygen"),z=["salty","css","styles","styled"],B=(e=[])=>new RegExp(`\\.(${[...z,...e].join("|")})\\.`),v=(e,s=[])=>B(s).test(e),X=async e=>{const s=O(e),n=i.join(e,"salty.config.ts"),t=i.join(s,"salty.config.js"),l=I();console.log("Module type:",l),await q.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:l,external:["react"]});const C=Date.now(),{config:d}=await import(`${t}?t=${C}`);return d},H=async e=>{const s=await X(e),n=new Set,t=(c,u=[])=>c?Object.entries(c).flatMap(([f,p])=>{if(!p)return;if(typeof p=="object")return t(p,[...u,f]);const w=[...u,f].join(".");n.add(`"${w}"`);const m=[...u.map(N.dashCase),N.dashCase(f)].join("-"),{result:h}=R.parseValueTokens(p);return`--${m}: ${h};`}):[],l=c=>c?Object.entries(c).flatMap(([u,f])=>{const p=t(f);return u==="base"?p.join(""):`${u} { ${p.join("")} }`}):[],C=c=>c?Object.entries(c).flatMap(([u,f])=>Object.entries(f).flatMap(([p,w])=>{const m=t(w,[u]),h=`.${u}-${p}, [data-${u}="${p}"]`,D=m.join("");return`${h} { ${D} }`})):[],d=t(s.variables),x=l(s.responsiveVariables),r=C(s.conditionalVariables),F=O(e),j=i.join(F,"css/variables.css"),T=`:root { ${d.join("")} ${x.join("")} } ${r.join("")}`;a.writeFileSync(j,T);const g=i.join(F,"types/css-tokens.d.ts"),y=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;a.writeFileSync(g,y);const $=i.join(F,"css/global.css"),b=R.parseStyles(s.global,"");a.writeFileSync($,b);const S=i.join(F,"css/templates.css"),k=R.parseTemplates(s.templates);a.writeFileSync(S,k)},E=async(e,s)=>{const n=N.toHash(e),t=i.join(s,"js",n+".js"),l=I();console.log("Module type:",l),await q.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:l,target:["es2022"],keepNames:!0,external:["react"]});const C=Date.now();return await import(`${t}?t=${C}`)},_=async e=>{const s=O(e),n=i.join(s,"salty.config.js"),{config:t}=await import(n);return t},Y=async e=>{try{const s=[],n=[],t=O(e),l=i.join(t,"index.css");(()=>{a.existsSync(t)&&G.execSync("rm -rf "+t),a.mkdirSync(t),a.mkdirSync(i.join(t,"css")),a.mkdirSync(i.join(t,"types"))})(),await H(e);const d=await _(e);async function x(o,y){const $=["node_modules","saltygen"],b=a.statSync(o);if(b.isDirectory()){const S=a.readdirSync(o);if($.some(c=>o.includes(c)))return;await Promise.all(S.map(c=>x(i.join(o,c),i.join(y,c))))}else if(b.isFile()&&v(o)){const k=await E(o,t),c=[];Object.entries(k).forEach(([w,m])=>{if(m.isKeyframes&&m.css){const M=`${m.animationName}.css`,W=`css/${M}`,K=i.join(t,W);s.push(M),a.writeFileSync(K,m.css);return}if(!m.generator)return;const h=m.generator._withBuildContext({name:w,config:d}),D=`${h.hash}-${h.priority}.css`;n[h.priority]||(n[h.priority]=[]),n[h.priority].push(D),c.push(D);const P=`css/${D}`,U=i.join(t,P);a.writeFileSync(U,h.css)});const u=c.map(w=>`@import url('./${w}');`).join(`
2
- `),f=N.toHash(o,6),p=i.join(t,`css/${f}.css`);a.writeFileSync(p,u)}}await x(e,t);const r=s.map(o=>`@import url('./css/${o}');`).join(`
3
- `);let g=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("esbuild"),A=require("child_process"),M=require("../dash-case-DKzpenwY.cjs"),o=require("path"),l=require("fs"),X=require("fs/promises"),v=require("../parse-templates-DVK3iZIl.cjs");var R=typeof document<"u"?document.currentScript:null;function Y(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const e=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(s,n,e.get?e:{enumerable:!0,get:()=>t[n]})}}return s.default=t,Object.freeze(s)}const I=Y(J),z=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("compiler/index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",V={externalModules:[]},B=t=>{if(V.externalModules.length>0)return V.externalModules;const s=o.join(t,"salty.config.ts"),e=l.readFileSync(s,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!e)return[];const a=e[1].split(",").map(F=>F.replace(/['"`]/g,"").trim());return V.externalModules=a,a},N=t=>o.join(t,"./saltygen"),H=["salty","css","styles","styled"],U=(t=[])=>new RegExp(`\\.(${[...H,...t].join("|")})\\.`),E=(t,s=[])=>U(s).test(t),Z=async t=>{const s=N(t),n=o.join(t,"salty.config.ts"),e=o.join(s,"salty.config.js"),a=z(),F=B(t);await I.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:e,format:a,external:F});const f=Date.now(),{config:g}=await import(`${e}?t=${f}`);return g},W=async t=>{const s=await Z(t),n=new Set,e=(c,u=[])=>c?Object.entries(c).flatMap(([d,p])=>{if(!p)return;if(typeof p=="object")return e(p,[...u,d]);const C=[...u,d].join(".");n.add(`"${C}"`);const h=[...u.map(M.dashCase),M.dashCase(d)].join("-"),{result:j}=v.parseValueTokens(p);return`--${h}: ${j};`}):[],a=c=>c?Object.entries(c).flatMap(([u,d])=>{const p=e(d);return u==="base"?p.join(""):`${u} { ${p.join("")} }`}):[],F=c=>c?Object.entries(c).flatMap(([u,d])=>Object.entries(d).flatMap(([p,C])=>{const h=e(C,[u]),j=`.${u}-${p}, [data-${u}="${p}"]`,D=h.join("");return`${j} { ${D} }`})):[],f=e(s.variables),g=a(s.responsiveVariables),i=F(s.conditionalVariables),w=N(t),S=o.join(w,"css/variables.css"),T=`:root { ${f.join("")} ${g.join("")} } ${i.join("")}`;l.writeFileSync(S,T);const m=o.join(w,"types/css-tokens.d.ts"),y=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;l.writeFileSync(m,y);const x=o.join(w,"css/global.css"),$=v.parseStyles(s.global,"");l.writeFileSync(x,$);const b=o.join(w,"css/templates.css"),k=v.parseTemplates(s.templates);l.writeFileSync(b,k)},O=async(t,s,n)=>{const e=M.toHash(s),a=o.join(n,"js",e+".js"),F=z(),f=B(t);await I.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:a,format:F,target:["es2022"],keepNames:!0,external:f});const g=Date.now();return await import(`${a}?t=${g}`)},_=async t=>{const s=N(t),n=o.join(s,"salty.config.js"),{config:e}=await import(n);return e},Q=async t=>{try{const s=[],n=[],e=N(t),a=o.join(e,"index.css");(()=>{l.existsSync(e)&&A.execSync("rm -rf "+e),l.mkdirSync(e),l.mkdirSync(o.join(e,"css")),l.mkdirSync(o.join(e,"types"))})(),await W(t);const f=await _(t);async function g(r,y){const x=["node_modules","saltygen"],$=l.statSync(r);if($.isDirectory()){const b=l.readdirSync(r);if(x.some(c=>r.includes(c)))return;await Promise.all(b.map(c=>g(o.join(r,c),o.join(y,c))))}else if($.isFile()&&E(r)){const k=await O(t,r,e),c=[];Object.entries(k).forEach(([C,h])=>{if(h.isKeyframes&&h.css){const q=`${h.animationName}.css`,L=`css/${q}`,G=o.join(e,L);s.push(q),l.writeFileSync(G,h.css);return}if(!h.generator)return;const j=h.generator._withBuildContext({name:C,config:f}),D=`${j.hash}-${j.priority}.css`;n[j.priority]||(n[j.priority]=[]),n[j.priority].push(D),c.push(D);const P=`css/${D}`,K=o.join(e,P);l.writeFileSync(K,j.css)});const u=c.map(C=>`@import url('./${C}');`).join(`
2
+ `),d=M.toHash(r,6),p=o.join(e,`css/${d}.css`);l.writeFileSync(p,u)}}await g(t,e);const i=s.map(r=>`@import url('./css/${r}');`).join(`
3
+ `);let m=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
4
 
5
- ${["variables.css","global.css","templates.css"].filter(o=>{try{return a.readFileSync(i.join(t,"css",o),"utf8").length>0}catch{return!1}}).map(o=>`@import url('./css/${o}');`).join(`
5
+ ${["variables.css","global.css","templates.css"].filter(r=>{try{return l.readFileSync(o.join(e,"css",r),"utf8").length>0}catch{return!1}}).map(r=>`@import url('./css/${r}');`).join(`
6
6
  `)}
7
- ${r}`;if(d.importStrategy!=="component"){const o=n.flat().map(y=>`@import url('./css/${y}');`).join(`
8
- `);g+=o}a.writeFileSync(l,g)}catch(s){console.error(s)}},Z=async(e,s)=>{try{const n=[],t=i.join(e,"./saltygen"),l=i.join(t,"index.css");if(v(s)){const d=await _(e),x=await E(s,t);Object.entries(x).forEach(([g,o])=>{if(!o.generator)return;const y=o.generator._withBuildContext({name:g,config:d}),$=`${y.hash}-${y.priority}.css`,b=`css/${$}`,S=i.join(t,b);n.push($),a.writeFileSync(S,y.css)});const r=a.readFileSync(l,"utf8").split(`
9
- `),F=n.map(g=>`@import url('../saltygen/css/${g}');`),T=[...new Set([...r,...F])].join(`
10
- `);a.writeFileSync(l,T)}}catch(n){console.error(n)}},Q=async(e,s)=>{try{const n=i.join(e,"./saltygen");if(v(s)){const l=a.readFileSync(s,"utf8");l.replace(/^(?!export\s)const\s.*/gm,j=>`export ${j}`)!==l&&await J.writeFile(s,l);const d=await _(e),x=await E(s,n);let r=l;Object.entries(x).forEach(([j,T])=>{var D;if(T.isKeyframes||!T.generator)return;const g=T.generator._withBuildContext({name:j,config:d}),o=new RegExp(`\\s${j}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(l);if(!o)return console.error("Could not find the original declaration");const y=(D=o.at(1))==null?void 0:D.trim(),$=new RegExp(`\\s${j}[=\\s]+styled\\(`,"g").exec(r);if(!$)return console.error("Could not find the original declaration");const{index:b}=$;let S=!1;const k=setTimeout(()=>S=!0,5e3);let c=0,u=!1,f=0;for(;!u&&!S;){const P=r[b+c];P==="("&&f++,P===")"&&f--,f===0&&P===")"&&(u=!0),c>r.length&&(S=!0),c++}if(!S)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const p=b+c,w=r.slice(b,p),m=r,h=` ${j} = styled(${y}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`;r=r.replace(w,h),m===r&&console.error("Minimize file failed to change content",{name:j,tagName:y})});const F=N.toHash(s,6);return d.importStrategy==="component"&&(r=`import '../../saltygen/css/${F}.css';
11
- ${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=E;exports.generateConfigStyles=H;exports.generateCss=Y;exports.generateFile=Z;exports.isSaltyFile=v;exports.minimizeFile=Q;exports.saltyFileExtensions=z;exports.saltyFileRegExp=B;
7
+ ${i}`;if(f.importStrategy!=="component"){const r=n.flat().map(y=>`@import url('./css/${y}');`).join(`
8
+ `);m+=r}l.writeFileSync(a,m)}catch(s){console.error(s)}},tt=async(t,s)=>{try{const n=[],e=o.join(t,"./saltygen"),a=o.join(e,"index.css");if(E(s)){const f=await _(t),g=await O(t,s,e);Object.entries(g).forEach(([m,r])=>{if(!r.generator)return;const y=r.generator._withBuildContext({name:m,config:f}),x=`${y.hash}-${y.priority}.css`,$=`css/${x}`,b=o.join(e,$);n.push(x),l.writeFileSync(b,y.css)});const i=l.readFileSync(a,"utf8").split(`
9
+ `),w=n.map(m=>`@import url('../saltygen/css/${m}');`),T=[...new Set([...i,...w])].join(`
10
+ `);l.writeFileSync(a,T)}}catch(n){console.error(n)}},et=async(t,s)=>{try{const n=o.join(t,"./saltygen");if(E(s)){const a=l.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==a&&await X.writeFile(s,a);const f=await _(t),g=await O(t,s,n);let i=a;Object.entries(g).forEach(([S,T])=>{var D;if(T.isKeyframes||!T.generator)return;const m=T.generator._withBuildContext({name:S,config:f}),r=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!r)return console.error("Could not find the original declaration");const y=(D=r.at(1))==null?void 0:D.trim(),x=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(i);if(!x)return console.error("Could not find the original declaration");const{index:$}=x;let b=!1;const k=setTimeout(()=>b=!0,5e3);let c=0,u=!1,d=0;for(;!u&&!b;){const P=i[$+c];P==="("&&d++,P===")"&&d--,d===0&&P===")"&&(u=!0),c>i.length&&(b=!0),c++}if(!b)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const p=$+c,C=i.slice($,p),h=i,j=` ${S} = styled(${y}, "${m.classNames}", "${m._callerName}", ${JSON.stringify(m.props)});`;i=i.replace(C,j),h===i&&console.error("Minimize file failed to change content",{name:S,tagName:y})});const w=M.toHash(s,6);return f.importStrategy==="component"&&(i=`import '../../saltygen/css/${w}.css';
11
+ ${i}`),i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=O;exports.generateConfigStyles=W;exports.generateCss=Q;exports.generateFile=tt;exports.isSaltyFile=E;exports.minimizeFile=et;exports.saltyFileExtensions=H;exports.saltyFileRegExp=U;
@@ -3,7 +3,7 @@ export declare const saltyFileExtensions: string[];
3
3
  export declare const saltyFileRegExp: (additional?: string[]) => RegExp;
4
4
  export declare const isSaltyFile: (file: string, additional?: string[]) => boolean;
5
5
  export declare const generateConfigStyles: (dirname: string) => Promise<void>;
6
- export declare const compileSaltyFile: (sourceFilePath: string, outputDirectory: string) => Promise<{
6
+ export declare const compileSaltyFile: (dirname: string, sourceFilePath: string, outputDirectory: string) => Promise<{
7
7
  [key: string]: {
8
8
  generator: StyleComponentGenerator;
9
9
  isKeyframes?: boolean;
package/compiler/index.js CHANGED
@@ -1,188 +1,196 @@
1
- import * as _ from "esbuild";
2
- import { execSync as G } from "child_process";
3
- import { t as E, d as I } from "../dash-case-DMQMcCO6.js";
4
- import { join as r } from "path";
5
- import { writeFileSync as w, existsSync as J, mkdirSync as V, statSync as q, readdirSync as A, readFileSync as v } from "fs";
6
- import { writeFile as L } from "fs/promises";
7
- import { p as U, a as X, b as Y } from "../parse-templates-DUUSaubj.js";
8
- const z = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", N = (s) => r(s, "./saltygen"), Z = ["salty", "css", "styles", "styled"], Q = (s = []) => new RegExp(`\\.(${[...Z, ...s].join("|")})\\.`), M = (s, e = []) => Q(e).test(s), tt = async (s) => {
9
- const e = N(s), n = r(s, "salty.config.ts"), t = r(e, "salty.config.js"), a = z();
10
- console.log("Module type:", a), await _.build({
1
+ import * as z from "esbuild";
2
+ import { execSync as q } from "child_process";
3
+ import { t as v, d as _ } from "../dash-case-DMQMcCO6.js";
4
+ import { join as o } from "path";
5
+ import { writeFileSync as F, existsSync as A, mkdirSync as E, statSync as L, readdirSync as U, readFileSync as M } from "fs";
6
+ import { writeFile as X } from "fs/promises";
7
+ import { p as Y, a as Z, b as Q } from "../parse-templates-DUUSaubj.js";
8
+ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
9
+ externalModules: []
10
+ }, H = (t) => {
11
+ if (V.externalModules.length > 0) return V.externalModules;
12
+ const e = o(t, "salty.config.ts"), s = M(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
13
+ if (!s) return [];
14
+ const a = s[1].split(",").map((w) => w.replace(/['"`]/g, "").trim());
15
+ return V.externalModules = a, a;
16
+ }, N = (t) => o(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"], st = (t = []) => new RegExp(`\\.(${[...tt, ...t].join("|")})\\.`), O = (t, e = []) => st(e).test(t), et = async (t) => {
17
+ const e = N(t), n = o(t, "salty.config.ts"), s = o(e, "salty.config.js"), a = W(), w = H(t);
18
+ await z.build({
11
19
  entryPoints: [n],
12
20
  minify: !0,
13
21
  treeShaking: !0,
14
22
  bundle: !0,
15
- outfile: t,
23
+ outfile: s,
16
24
  format: a,
17
- external: ["react"]
25
+ external: w
18
26
  });
19
- const C = Date.now(), { config: y } = await import(`${t}?t=${C}`);
27
+ const f = Date.now(), { config: y } = await import(`${s}?t=${f}`);
20
28
  return y;
21
- }, st = async (s) => {
22
- const e = await tt(s), n = /* @__PURE__ */ new Set(), t = (c, l = []) => c ? Object.entries(c).flatMap(([m, p]) => {
29
+ }, nt = async (t) => {
30
+ const e = await et(t), n = /* @__PURE__ */ new Set(), s = (i, l = []) => i ? Object.entries(i).flatMap(([m, p]) => {
23
31
  if (!p) return;
24
- if (typeof p == "object") return t(p, [...l, m]);
25
- const j = [...l, m].join(".");
26
- n.add(`"${j}"`);
27
- const g = [...l.map(I), I(m)].join("-"), { result: d } = Y(p);
28
- return `--${g}: ${d};`;
29
- }) : [], a = (c) => c ? Object.entries(c).flatMap(([l, m]) => {
30
- const p = t(m);
32
+ if (typeof p == "object") return s(p, [...l, m]);
33
+ const C = [...l, m].join(".");
34
+ n.add(`"${C}"`);
35
+ const d = [...l.map(_), _(m)].join("-"), { result: h } = Q(p);
36
+ return `--${d}: ${h};`;
37
+ }) : [], a = (i) => i ? Object.entries(i).flatMap(([l, m]) => {
38
+ const p = s(m);
31
39
  return l === "base" ? p.join("") : `${l} { ${p.join("")} }`;
32
- }) : [], C = (c) => c ? Object.entries(c).flatMap(([l, m]) => Object.entries(m).flatMap(([p, j]) => {
33
- const g = t(j, [l]), d = `.${l}-${p}, [data-${l}="${p}"]`, k = g.join("");
34
- return `${d} { ${k} }`;
35
- })) : [], y = t(e.variables), x = a(e.responsiveVariables), i = C(e.conditionalVariables), F = N(s), h = r(F, "css/variables.css"), D = `:root { ${y.join("")} ${x.join("")} } ${i.join("")}`;
36
- w(h, D);
37
- const u = r(F, "types/css-tokens.d.ts"), f = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
38
- w(u, f);
39
- const S = r(F, "css/global.css"), b = U(e.global, "");
40
- w(S, b);
41
- const $ = r(F, "css/templates.css"), T = X(e.templates);
42
- w($, T);
43
- }, O = async (s, e) => {
44
- const n = E(s), t = r(e, "js", n + ".js"), a = z();
45
- console.log("Module type:", a), await _.build({
46
- entryPoints: [s],
40
+ }) : [], w = (i) => i ? Object.entries(i).flatMap(([l, m]) => Object.entries(m).flatMap(([p, C]) => {
41
+ const d = s(C, [l]), h = `.${l}-${p}, [data-${l}="${p}"]`, k = d.join("");
42
+ return `${h} { ${k} }`;
43
+ })) : [], f = s(e.variables), y = a(e.responsiveVariables), r = w(e.conditionalVariables), S = N(t), $ = o(S, "css/variables.css"), D = `:root { ${f.join("")} ${y.join("")} } ${r.join("")}`;
44
+ F($, D);
45
+ const g = o(S, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
46
+ F(g, u);
47
+ const j = o(S, "css/global.css"), x = Y(e.global, "");
48
+ F(j, x);
49
+ const b = o(S, "css/templates.css"), T = Z(e.templates);
50
+ F(b, T);
51
+ }, R = async (t, e, n) => {
52
+ const s = v(e), a = o(n, "js", s + ".js"), w = W(), f = H(t);
53
+ await z.build({
54
+ entryPoints: [e],
47
55
  minify: !0,
48
56
  treeShaking: !0,
49
57
  bundle: !0,
50
- outfile: t,
51
- format: a,
58
+ outfile: a,
59
+ format: w,
52
60
  target: ["es2022"],
53
61
  keepNames: !0,
54
- external: ["react"]
62
+ external: f
55
63
  });
56
- const C = Date.now();
57
- return await import(`${t}?t=${C}`);
58
- }, R = async (s) => {
59
- const e = N(s), n = r(e, "salty.config.js"), { config: t } = await import(n);
60
- return t;
61
- }, at = async (s) => {
64
+ const y = Date.now();
65
+ return await import(`${a}?t=${y}`);
66
+ }, B = async (t) => {
67
+ const e = N(t), n = o(e, "salty.config.js"), { config: s } = await import(n);
68
+ return s;
69
+ }, pt = async (t) => {
62
70
  try {
63
- const e = [], n = [], t = N(s), a = r(t, "index.css");
71
+ const e = [], n = [], s = N(t), a = o(s, "index.css");
64
72
  (() => {
65
- J(t) && G("rm -rf " + t), V(t), V(r(t, "css")), V(r(t, "types"));
66
- })(), await st(s);
67
- const y = await R(s);
68
- async function x(o, f) {
69
- const S = ["node_modules", "saltygen"], b = q(o);
70
- if (b.isDirectory()) {
71
- const $ = A(o);
72
- if (S.some((c) => o.includes(c))) return;
73
- await Promise.all($.map((c) => x(r(o, c), r(f, c))));
74
- } else if (b.isFile() && M(o)) {
75
- const T = await O(o, t), c = [];
76
- Object.entries(T).forEach(([j, g]) => {
77
- if (g.isKeyframes && g.css) {
78
- const B = `${g.animationName}.css`, H = `css/${B}`, K = r(t, H);
79
- e.push(B), w(K, g.css);
73
+ A(s) && q("rm -rf " + s), E(s), E(o(s, "css")), E(o(s, "types"));
74
+ })(), await nt(t);
75
+ const f = await B(t);
76
+ async function y(c, u) {
77
+ const j = ["node_modules", "saltygen"], x = L(c);
78
+ if (x.isDirectory()) {
79
+ const b = U(c);
80
+ if (j.some((i) => c.includes(i))) return;
81
+ await Promise.all(b.map((i) => y(o(c, i), o(u, i))));
82
+ } else if (x.isFile() && O(c)) {
83
+ const T = await R(t, c, s), i = [];
84
+ Object.entries(T).forEach(([C, d]) => {
85
+ if (d.isKeyframes && d.css) {
86
+ const I = `${d.animationName}.css`, G = `css/${I}`, J = o(s, G);
87
+ e.push(I), F(J, d.css);
80
88
  return;
81
89
  }
82
- if (!g.generator) return;
83
- const d = g.generator._withBuildContext({
84
- name: j,
85
- config: y
86
- }), k = `${d.hash}-${d.priority}.css`;
87
- n[d.priority] || (n[d.priority] = []), n[d.priority].push(k), c.push(k);
88
- const P = `css/${k}`, W = r(t, P);
89
- w(W, d.css);
90
+ if (!d.generator) return;
91
+ const h = d.generator._withBuildContext({
92
+ name: C,
93
+ config: f
94
+ }), k = `${h.hash}-${h.priority}.css`;
95
+ n[h.priority] || (n[h.priority] = []), n[h.priority].push(k), i.push(k);
96
+ const P = `css/${k}`, K = o(s, P);
97
+ F(K, h.css);
90
98
  });
91
- const l = c.map((j) => `@import url('./${j}');`).join(`
92
- `), m = E(o, 6), p = r(t, `css/${m}.css`);
93
- w(p, l);
99
+ const l = i.map((C) => `@import url('./${C}');`).join(`
100
+ `), m = v(c, 6), p = o(s, `css/${m}.css`);
101
+ F(p, l);
94
102
  }
95
103
  }
96
- await x(s, t);
97
- const i = e.map((o) => `@import url('./css/${o}');`).join(`
104
+ await y(t, s);
105
+ const r = e.map((c) => `@import url('./css/${c}');`).join(`
98
106
  `);
99
- let u = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
107
+ let g = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
100
108
 
101
- ${["variables.css", "global.css", "templates.css"].filter((o) => {
109
+ ${["variables.css", "global.css", "templates.css"].filter((c) => {
102
110
  try {
103
- return v(r(t, "css", o), "utf8").length > 0;
111
+ return M(o(s, "css", c), "utf8").length > 0;
104
112
  } catch {
105
113
  return !1;
106
114
  }
107
- }).map((o) => `@import url('./css/${o}');`).join(`
115
+ }).map((c) => `@import url('./css/${c}');`).join(`
108
116
  `)}
109
- ${i}`;
110
- if (y.importStrategy !== "component") {
111
- const o = n.flat().map((f) => `@import url('./css/${f}');`).join(`
117
+ ${r}`;
118
+ if (f.importStrategy !== "component") {
119
+ const c = n.flat().map((u) => `@import url('./css/${u}');`).join(`
112
120
  `);
113
- u += o;
121
+ g += c;
114
122
  }
115
- w(a, u);
123
+ F(a, g);
116
124
  } catch (e) {
117
125
  console.error(e);
118
126
  }
119
- }, lt = async (s, e) => {
127
+ }, ft = async (t, e) => {
120
128
  try {
121
- const n = [], t = r(s, "./saltygen"), a = r(t, "index.css");
122
- if (M(e)) {
123
- const y = await R(s), x = await O(e, t);
124
- Object.entries(x).forEach(([u, o]) => {
125
- if (!o.generator) return;
126
- const f = o.generator._withBuildContext({
127
- name: u,
128
- config: y
129
- }), S = `${f.hash}-${f.priority}.css`, b = `css/${S}`, $ = r(t, b);
130
- n.push(S), w($, f.css);
129
+ const n = [], s = o(t, "./saltygen"), a = o(s, "index.css");
130
+ if (O(e)) {
131
+ const f = await B(t), y = await R(t, e, s);
132
+ Object.entries(y).forEach(([g, c]) => {
133
+ if (!c.generator) return;
134
+ const u = c.generator._withBuildContext({
135
+ name: g,
136
+ config: f
137
+ }), j = `${u.hash}-${u.priority}.css`, x = `css/${j}`, b = o(s, x);
138
+ n.push(j), F(b, u.css);
131
139
  });
132
- const i = v(a, "utf8").split(`
133
- `), F = n.map((u) => `@import url('../saltygen/css/${u}');`), D = [.../* @__PURE__ */ new Set([...i, ...F])].join(`
140
+ const r = M(a, "utf8").split(`
141
+ `), S = n.map((g) => `@import url('../saltygen/css/${g}');`), D = [.../* @__PURE__ */ new Set([...r, ...S])].join(`
134
142
  `);
135
- w(a, D);
143
+ F(a, D);
136
144
  }
137
145
  } catch (n) {
138
146
  console.error(n);
139
147
  }
140
- }, pt = async (s, e) => {
148
+ }, ut = async (t, e) => {
141
149
  try {
142
- const n = r(s, "./saltygen");
143
- if (M(e)) {
144
- const a = v(e, "utf8");
145
- a.replace(/^(?!export\s)const\s.*/gm, (h) => `export ${h}`) !== a && await L(e, a);
146
- const y = await R(s), x = await O(e, n);
147
- let i = a;
148
- Object.entries(x).forEach(([h, D]) => {
150
+ const n = o(t, "./saltygen");
151
+ if (O(e)) {
152
+ const a = M(e, "utf8");
153
+ a.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== a && await X(e, a);
154
+ const f = await B(t), y = await R(t, e, n);
155
+ let r = a;
156
+ Object.entries(y).forEach(([$, D]) => {
149
157
  var k;
150
158
  if (D.isKeyframes || !D.generator) return;
151
- const u = D.generator._withBuildContext({
152
- name: h,
153
- config: y
154
- }), o = new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
155
- if (!o) return console.error("Could not find the original declaration");
156
- const f = (k = o.at(1)) == null ? void 0 : k.trim(), S = new RegExp(`\\s${h}[=\\s]+styled\\(`, "g").exec(i);
157
- if (!S) return console.error("Could not find the original declaration");
158
- const { index: b } = S;
159
- let $ = !1;
160
- const T = setTimeout(() => $ = !0, 5e3);
161
- let c = 0, l = !1, m = 0;
162
- for (; !l && !$; ) {
163
- const P = i[b + c];
164
- P === "(" && m++, P === ")" && m--, m === 0 && P === ")" && (l = !0), c > i.length && ($ = !0), c++;
159
+ const g = D.generator._withBuildContext({
160
+ name: $,
161
+ config: f
162
+ }), c = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
163
+ if (!c) return console.error("Could not find the original declaration");
164
+ const u = (k = c.at(1)) == null ? void 0 : k.trim(), j = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
165
+ if (!j) return console.error("Could not find the original declaration");
166
+ const { index: x } = j;
167
+ let b = !1;
168
+ const T = setTimeout(() => b = !0, 5e3);
169
+ let i = 0, l = !1, m = 0;
170
+ for (; !l && !b; ) {
171
+ const P = r[x + i];
172
+ P === "(" && m++, P === ")" && m--, m === 0 && P === ")" && (l = !0), i > r.length && (b = !0), i++;
165
173
  }
166
- if (!$) clearTimeout(T);
174
+ if (!b) clearTimeout(T);
167
175
  else throw new Error("Failed to find the end of the styled call and timed out");
168
- const p = b + c, j = i.slice(b, p), g = i, d = ` ${h} = styled(${f}, "${u.classNames}", "${u._callerName}", ${JSON.stringify(u.props)});`;
169
- i = i.replace(j, d), g === i && console.error("Minimize file failed to change content", { name: h, tagName: f });
176
+ const p = x + i, C = r.slice(x, p), d = r, h = ` ${$} = styled(${u}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`;
177
+ r = r.replace(C, h), d === r && console.error("Minimize file failed to change content", { name: $, tagName: u });
170
178
  });
171
- const F = E(e, 6);
172
- return y.importStrategy === "component" && (i = `import '../../saltygen/css/${F}.css';
173
- ${i}`), i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
179
+ const S = v(e, 6);
180
+ return f.importStrategy === "component" && (r = `import '../../saltygen/css/${S}.css';
181
+ ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
174
182
  }
175
183
  } catch (n) {
176
184
  console.error("Error in minimizeFile:", n);
177
185
  }
178
186
  };
179
187
  export {
180
- O as compileSaltyFile,
181
- st as generateConfigStyles,
182
- at as generateCss,
183
- lt as generateFile,
184
- M as isSaltyFile,
185
- pt as minimizeFile,
186
- Z as saltyFileExtensions,
187
- Q as saltyFileRegExp
188
+ R as compileSaltyFile,
189
+ nt as generateConfigStyles,
190
+ pt as generateCss,
191
+ ft as generateFile,
192
+ O as isSaltyFile,
193
+ ut as minimizeFile,
194
+ tt as saltyFileExtensions,
195
+ st as saltyFileRegExp
188
196
  };
@@ -1,4 +1,5 @@
1
1
  import { CssStyles } from '../types';
2
+ import { OrString } from '../types/util-types';
2
3
  type CssTemplate = CssStyles | {
3
4
  [key: PropertyKey]: CssTemplate;
4
5
  };
@@ -55,5 +56,9 @@ export interface SaltyConfig {
55
56
  * The modifiers that can transform css values.
56
57
  */
57
58
  modifiers?: CssModifiers;
59
+ /**
60
+ * Define modules that should not be bundled when generating the css file. This improves the performance of the css generation and can help with issues relared to external packages being imported in an environment that does not support them.
61
+ */
62
+ externalModules?: ('react' | 'react-dom' | OrString)[];
58
63
  }
59
64
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.60",
3
+ "version": "0.0.1-alpha.62",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -2,6 +2,7 @@ const n = `import { defineConfig } from '@salty-css/core/config';
2
2
 
3
3
  export const config = defineConfig({
4
4
  // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
5
6
  });
6
7
  `;
7
8
  export {
@@ -1,6 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=`import { defineConfig } from '@salty-css/core/config';
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=`import { defineConfig } from '@salty-css/core/config';
2
2
 
3
3
  export const config = defineConfig({
4
4
  // Add your custom config here
5
+ externalModules: ['react', 'react-dom']
5
6
  });
6
- `;exports.default=o;
7
+ `;exports.default=e;