@salty-css/core 0.0.1-alpha.282 → 0.0.1-alpha.284
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 +1 -1
- package/bin/main.js +2 -2
- package/cache/resolve-dynamic-config-cache.cjs +1 -1
- package/cache/resolve-dynamic-config-cache.js +9 -6
- package/compiler/index.cjs +1 -1
- package/compiler/index.d.ts +1 -0
- package/compiler/index.js +8 -7
- package/index-BYrtB4JM.cjs +41 -0
- package/{index-8a_5lZS1.js → index-CR0k7PXM.js} +46 -43
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/{should-restart-Z7Vfizh9.cjs → should-restart-BFVRQc0_.cjs} +1 -1
- package/{should-restart-Cjw8WqZq.js → should-restart-CR-ZEYLq.js} +1 -1
- package/index-DOl289-D.cjs +0 -41
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),A=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),e=require("../index-BYrtB4JM.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora"),ae=require("../should-restart-BFVRQc0_.cjs");var G=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,x=>{if(x)return P(x);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),x=y.join(" ");await X(`npm install ${x}`),P.succeed(`Installed packages: ${C}`)},re=()=>A.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!re())return;await X(`./node_modules/.bin/prettier --write "${y}"`),e.logger.info(`Formatted ${y} with Prettier`)}catch(C){e.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function ce(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"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")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:f}=await C[i],d=ne.render(f,a);return{fileName:i,content:d}},x=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await x()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},H=i=>{const a=i==="."?"":i,f=process.cwd();return n.join(f,a)};y.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 N().catch(()=>{}))return e.logError("Salty CSS project must be initialized in a directory with a package.json file.");e.logger.info("Initializing a new Salty-CSS project!");const{dir:f=i,cssFile:d,skipInstall:p}=this.opts();if(!f)return e.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const c=process.cwd(),r=H(f),q=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=q.map(async({fileName:t,content:u})=>{const l=n.join(r,t);if(await s.readFile(l,"utf-8").catch(()=>{})!==void 0){e.logger.debug("File already exists: "+l);return}const k=t.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),e.logger.info("Creating file: "+l),await s.writeFile(l,u),await S(l)});await Promise.all(m);const w=n.relative(c,r)||".",h=n.join(c,".saltyrc.json"),g=await s.readFile(h,"utf-8").catch(()=>{});if(g===void 0){e.logger.info("Creating file: "+h);const u=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,u),await S(h)}else{const t=JSON.parse(g),u=(t==null?void 0:t.projects)||[];if(u.findIndex(o=>o.dir===w)===-1){u.push({dir:w,framework:"react"}),t.projects=[...u];const o=JSON.stringify(t,null,2);o!==g&&(e.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(c,".gitignore"),T=await s.readFile(j,"utf-8").catch(()=>{});T!==void 0&&(T.includes("saltygen")||(e.logger.info("Edit file: "+j),await s.writeFile(j,T+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,11 +3,11 @@ import { existsSync as Q, watch as re } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as S, writeFile as C } from "fs/promises";
|
4
4
|
import { join as a, relative as z, parse as ce, format as te } from "path";
|
5
5
|
import { render as le } from "ejs";
|
6
|
-
import { l as t, a as h,
|
6
|
+
import { l as t, a as h, b as K, i as de, c as fe } from "../index-CR0k7PXM.js";
|
7
7
|
import { p as pe } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as ue } from "child_process";
|
9
9
|
import ge from "ora";
|
10
|
-
import { c as ye } from "../should-restart-
|
10
|
+
import { c as ye } from "../should-restart-CR-ZEYLq.js";
|
11
11
|
const ne = (g) => new Promise((P, x) => {
|
12
12
|
ue(g, ($) => {
|
13
13
|
if ($) return x($);
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("fs/promises"),r=require("path"),i=require("../index-BYrtB4JM.cjs"),t=async()=>{const c=i.getCorePackageRoot(),e=r.join(c,"cache/config-cache.json");console.log(`Resolving dynamic config cache from ${e}`);const o=await n.readFile(e,"utf8");if(!o)throw new Error("Could not find config cache file");return JSON.parse(o)};exports.resolveDynamicConfigCache=t;
|
@@ -1,10 +1,13 @@
|
|
1
|
-
import { readFile as
|
1
|
+
import { readFile as n } from "fs/promises";
|
2
2
|
import { join as r } from "path";
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
import { g as t } from "../index-CR0k7PXM.js";
|
4
|
+
const s = async () => {
|
5
|
+
const e = t(), o = r(e, "cache/config-cache.json");
|
6
|
+
console.log(`Resolving dynamic config cache from ${o}`);
|
7
|
+
const c = await n(o, "utf8");
|
8
|
+
if (!c) throw new Error("Could not find config cache file");
|
9
|
+
return JSON.parse(c);
|
7
10
|
};
|
8
11
|
export {
|
9
|
-
|
12
|
+
s as resolveDynamicConfigCache
|
10
13
|
};
|
package/compiler/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-Bdgw_4ME.cjs");require("../parsers/index.cjs");const e=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-Bdgw_4ME.cjs");require("../parsers/index.cjs");const e=require("../index-BYrtB4JM.cjs");require("../css/merge.cjs");require("../define-templates-Cunsb_Tr.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.getCorePackageRoot=e.getCorePackageRoot;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.d.ts
CHANGED
package/compiler/index.js
CHANGED
@@ -6,16 +6,17 @@ import "fs";
|
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-C1E6ETeH.js";
|
8
8
|
import "../parsers/index.js";
|
9
|
-
import {
|
9
|
+
import { f as F, e as y, b as c, c as f, g as x, i as C, m as S, s as E, d as R } from "../index-CR0k7PXM.js";
|
10
10
|
import "../css/merge.js";
|
11
11
|
import "../define-templates-4A2yHcMF.js";
|
12
12
|
export {
|
13
13
|
F as compileSaltyFile,
|
14
14
|
y as generateConfigStyles,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
E as
|
15
|
+
c as generateCss,
|
16
|
+
f as generateFile,
|
17
|
+
x as getCorePackageRoot,
|
18
|
+
C as isSaltyFile,
|
19
|
+
S as minimizeFile,
|
20
|
+
E as saltyFileExtensions,
|
21
|
+
R as saltyFileRegExp
|
21
22
|
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";const Re=require("esbuild"),ve=require("child_process"),_=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),be=require("fs/promises"),ce=require("./parse-styles-Bdgw_4ME.cjs"),Se=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),re=require("typescript");var I=typeof document<"u"?document.currentScript:null;function Ve(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const Fe=Ve(Re),$e=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:$e(i.join(e,".."))},Me=async e=>{const t=$e(e);return await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Je=async e=>{const t=await Me(e);if(t)return t.type};let H;const Ce=async e=>{if(H)return H;const t=await Je(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-BYrtB4JM.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),qe=e=>{B.error(e)};function Pe(e){return e?typeof e!="string"?Pe(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},He=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=re.createSourceFile("temp.ts",e,re.ScriptTarget.Latest,!0);function o(y){if(re.isVariableDeclaration(y)&&y.name.getText()===t){const S=y.getStart(),d=y.getEnd();clearTimeout(r),s([S,d])}y.forEachChild(o)}o(l)}),Ne=()=>{let{pathname:e}=new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-BYrtB4JM.cjs",document.baseURI).href);for(;/core\/?(src\/)?$/.test(e)===!1;)e=i.join(e,"../");return e},R={externalModules:[],rcFile:void 0,destDir:void 0},xe=e=>{if(R.externalModules.length>0)return R.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return R.externalModules=n,n},q=async e=>{if(R.destDir)return R.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},le=["salty","css","styles","styled"],ke=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>ke(t).test(e),De=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):De(i.join(e,".."))},fe=async e=>{var n,r;const t=await De(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},Ie=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Ce(e),o=xe(n);await Fe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:S}=await import(`${r}?t=${y}`);return{config:S,path:r}},Te=async(e,t)=>{var ge,he;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:F,outputFilePath:G}=await A(e,w,s);Object.entries(F).forEach(([D,P])=>{P.isMedia?n.mediaQueries.push([D,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${D};;${G}`))})}));const{config:r,path:l}=await Ie(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([w,F])=>[`@${w}`,F]));const S=y.map(([w])=>`'@${w}'`).join(" | "),d=new Set,a=async(w,F=[])=>{if(!w)return[];const G=Object.entries(w).map(async([P,M])=>{const K=async T=>{if(!T)return;if(T instanceof Promise)return await K(await T);if(typeof T=="function")return await K(await T());if(typeof T=="object")return await a(T,[...F,P]);const oe=Pe(P),ie=_.dashCase(P),ae=[...F,oe].join(".");d.add(`"${ae}"`);const Z=[...F.map(_.dashCase),ie].join("-"),we=ce.parseVariableTokens(T);return we?`--${Z}: ${we.transformed};`:`--${Z}: ${T};`};return await K(M)});return(await Promise.all(G)).flat()},g=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=await a(P);return D==="base"?M.join(""):o.mediaQueries[D]?`${o.mediaQueries[D]} { ${M.join("")} }`:`${D} { ${M.join("")} }`});return(await Promise.all(F)).flat()},m=async w=>{if(!w)return[];const F=Object.entries(w).map(async([D,P])=>{const M=Object.entries(P).map(async([T,oe])=>{const ie=await a(oe,[D]),ae=`.${D}-${T}, [data-${D}="${T}"]`,Z=ie.join("");return`${ae} { ${Z} }`});return(await Promise.all(M)).flat()});return(await Promise.all(F)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),p=w=>n.variables.map(F=>w==="static"?h(F._current):F._current[w]),$=J.mergeObjects(h(r.variables),p("static")),x=await a($),k=J.mergeObjects((ge=r.variables)==null?void 0:ge.responsive,p("responsive")),v=await g(k),z=J.mergeObjects((he=r.variables)==null?void 0:he.conditional,p("conditional")),X=await m(z),de=i.join(s,"css/_variables.css"),E=`:root { ${x.join("")} ${v.join("")} } ${X.join("")}`;c.writeFileSync(de,E),o.staticVariables=$;const te=i.join(s,"css/_global.css"),u=J.mergeObjects(r.global,n.globalStyles),j=await ce.parseAndJoinStyles(u,"");c.writeFileSync(te,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:ze,N=await ce.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const O=i.join(s,"css/_templates.css"),V=J.mergeObjects(r.templates,n.templates),L=await Se.parseTemplates(V),W=Se.getTemplateTypes(V);c.writeFileSync(O,`@layer templates { ${L} }`),o.templates=V;const Y=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],se=J.mergeFactories(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(se).map(([w,F])=>[w,F._path]));const U=i.join(s,"types/css-tokens.d.ts"),_e=`
|
2
|
+
// Variable types
|
3
|
+
type VariableTokens = ${[...d].join("|")};
|
4
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
+
|
6
|
+
// Template types
|
7
|
+
type TemplateTokens = {
|
8
|
+
${Object.entries(W).map(([w,F])=>`${w}?: ${F}`).join(`
|
9
|
+
`)}
|
10
|
+
}
|
11
|
+
|
12
|
+
// Media query types
|
13
|
+
type MediaQueryKeys = ${S||"''"};
|
14
|
+
`;c.writeFileSync(U,_e);const Oe=i.join(s,"cache/config-cache.json");c.writeFileSync(Oe,JSON.stringify(o,null,2));const me=Ne();console.log("corePackageRoot",me);const ye=i.join(me,"cache/config-cache.json");console.log("Config cache secondary path",ye),c.writeFileSync(ye,JSON.stringify(o,null,2))},je=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const o=r.exec(e);if(o){const y=o.at(1);if(le.some(d=>y==null?void 0:y.includes(d)))return t}return"styled('div',"}),Le=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
15
|
+
|
16
|
+
${e}`:`globalThis.saltyConfig = {};
|
17
|
+
|
18
|
+
${e}`}catch{return e}},A=async(e,t,s)=>{const n=_.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=je(o),o=Le(o,e);const y=i.join(s,"js",n+".js"),S=await fe(e),d=i.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),a=xe(d),g=await Ce(e);await Fe.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:je(x),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},We=async e=>{const t=await q(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await We(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ue=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&ve.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const d=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&ee(u)){d.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await Te(e,a);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...d].map(async u=>{const{contents:j}=await A(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:b}):f.isClassName?m.classNames.push({...f,src:u,name:b}):f.generator&&m.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of m.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const p={};for(const u of m.components){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}for(const u of m.classNames){const{src:j,name:b}=u;p[j]||(p[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&p[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([u,j])=>{const b=j.map(V=>`@import url('./${V}');`).join(`
|
19
|
+
`),f=_.toHash(u,6),C=i.parse(u),N=_.dashCase(C.name),O=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(O,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
|
20
|
+
`);let X=`/*!
|
21
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
22
|
+
* Do not edit this file directly
|
23
|
+
*/
|
24
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
25
|
+
|
26
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
27
|
+
`)}
|
28
|
+
${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((L,W)=>{var ne;const Y=i.join(o,"css",W),se=c.readFileSync(Y,"utf8"),U=((ne=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:ne.at(1))||_.toHash(Y,6);return L.includes(U)?L:`${L}
|
29
|
+
/*start:${U}-${W}*/
|
30
|
+
${se}
|
31
|
+
/*end:${U}*/
|
32
|
+
`},""),N=`l_${f}.css`,O=i.join(o,"css",N),V=`@layer l${f} { ${C}
|
33
|
+
}`;return c.writeFileSync(O,V),`${j}
|
34
|
+
@import url('./css/${N}');`},"");X+=u}c.writeFileSync(y,X);const E=Date.now()-n,te=E<200?"🔥":E<500?"🚀":E<1e3?"🎉":E<2e3?"🚗":E<5e3?"🤔":"🥴";B.info(`Generated CSS in ${E}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=pe())=>{try{const n=await q(e);if(ee(t)){const l=[],o=await ue(e),{contents:y}=await A(e,t,n);for(const[S,d]of Object.entries(y)){if(d.isKeyframes&&d.css){const $=`css/${`a_${d.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await d.css);continue}if(d.isClassName){const p=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),$=await p.css;if(!$)continue;l[p.priority]||(l[p.priority]=[]),l[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=i.join(n,x);c.writeFileSync(k,$);continue}if(!d.generator)continue;const a=d.generator._withBuildContext({callerName:S,isProduction:s,config:o}),g=await a.css;if(!g)continue;const m=`css/${a.cssFileName}`,h=i.join(n,m);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((S,d)=>{const a=`l_${d}.css`,g=i.join(n,"css",a);let m=c.readFileSync(g,"utf8");S.forEach(h=>{var k;const p=i.join(n,"css",h),$=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||_.toHash(p,6);if(!m.includes($)){const v=c.readFileSync(p,"utf8"),z=`/*start:${$}-${h}*/
|
35
|
+
${v}
|
36
|
+
/*end:${$}*/
|
37
|
+
`;m=`${m.replace(/\}$/,"")}
|
38
|
+
${z}
|
39
|
+
}`}}),c.writeFileSync(g,m)});else{const S=l.flat().map(h=>`@import url('./${h}');`).join(`
|
40
|
+
`),d=_.toHash(t,6),a=i.parse(t),g=_.dashCase(a.name),m=i.join(n,`css/f_${g}-${d}.css`);c.writeFileSync(m,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=pe())=>{var n,r;try{const l=await q(e);if(ee(t)){const y=c.readFileSync(t,"utf8"),S=await ue(e),{contents:d}=await A(e,t,l);let a=y;for(const[g,m]of Object.entries(d)){if(m.isKeyframes||!m.generator)continue;const h=m.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[p,$]=await He(a,g),x=a.slice(p,$);if(m.isClassName){const k=a,v=` ${g} = className("${h.classNames}")`;a=a.replace(x,v),k===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),v=a,z=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),v===a&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(S.importStrategy==="component"){const g=_.toHash(t,6),m=i.parse(t);a=`import '../../saltygen/css/${`f_${_.dashCase(m.name)}-${g}.css`}';
|
41
|
+
${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=A;exports.generateConfigStyles=Te;exports.generateCss=Ue;exports.generateFile=Ge;exports.getCorePackageRoot=Ne;exports.isSaltyFile=ee;exports.logError=qe;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=le;exports.saltyFileRegExp=ke;
|
@@ -4,8 +4,8 @@ import { t as I, d as U } from "./dash-case-DBThphLm.js";
|
|
4
4
|
import { join as i, parse as tt } from "path";
|
5
5
|
import { existsSync as ft, writeFileSync as C, mkdirSync as G, readFileSync as _, statSync as Et, readdirSync as Ot } from "fs";
|
6
6
|
import { readFile as Pt } from "fs/promises";
|
7
|
-
import { p as St, a as
|
8
|
-
import { parseTemplates as
|
7
|
+
import { p as St, a as Rt } from "./parse-styles-C1E6ETeH.js";
|
8
|
+
import { parseTemplates as Mt, getTemplateTypes as Jt } from "./parsers/index.js";
|
9
9
|
import { createLogger as zt, format as rt, transports as Wt } from "winston";
|
10
10
|
import { mergeObjects as H, mergeFactories as Gt } from "./css/merge.js";
|
11
11
|
import { d as Ht } from "./define-templates-4A2yHcMF.js";
|
@@ -97,13 +97,15 @@ const Qt = {
|
|
97
97
|
}
|
98
98
|
o(r);
|
99
99
|
}), Bt = () => {
|
100
|
-
|
101
|
-
|
100
|
+
let { pathname: t } = new URL(import.meta.url);
|
101
|
+
for (; /core\/?(src\/)?$/.test(t) === !1; )
|
102
|
+
t = i(t, "../");
|
103
|
+
return t;
|
102
104
|
}, v = {
|
103
105
|
externalModules: [],
|
104
106
|
rcFile: void 0,
|
105
107
|
destDir: void 0
|
106
|
-
},
|
108
|
+
}, kt = (t) => {
|
107
109
|
if (v.externalModules.length > 0) return v.externalModules;
|
108
110
|
const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
109
111
|
if (!s) return [];
|
@@ -113,7 +115,7 @@ const Qt = {
|
|
113
115
|
if (v.destDir) return v.destDir;
|
114
116
|
const e = await pt(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
115
117
|
return v.destDir = s, s;
|
116
|
-
},
|
118
|
+
}, Dt = ["salty", "css", "styles", "styled"], qt = (t = []) => new RegExp(`\\.(${[...Dt, ...t].join("|")})\\.`), mt = (t, e = []) => qt(e).test(t), Tt = async (t) => {
|
117
119
|
if (v.rcFile) return v.rcFile;
|
118
120
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
119
121
|
const e = i(t, ".saltyrc.json"), s = await Pt(e, "utf-8").then(JSON.parse).catch(() => {
|
@@ -124,7 +126,7 @@ const Qt = {
|
|
124
126
|
const e = await Tt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
|
125
127
|
return s || ((c = e.projects) == null ? void 0 : c.find((r) => r.dir === e.defaultProject));
|
126
128
|
}, Ut = async (t) => {
|
127
|
-
const e = await pt(t), s = await J(t), n = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = i(s, "salty.config.js"), r = await Nt(t), o =
|
129
|
+
const e = await pt(t), s = await J(t), n = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = i(s, "salty.config.js"), r = await Nt(t), o = kt(n);
|
128
130
|
await Ft.build({
|
129
131
|
entryPoints: [n],
|
130
132
|
minify: !0,
|
@@ -147,8 +149,8 @@ const Qt = {
|
|
147
149
|
await Promise.all(
|
148
150
|
[...e].map(async (h) => {
|
149
151
|
const { contents: S, outputFilePath: B } = await et(t, h, s);
|
150
|
-
Object.entries(S).forEach(([
|
151
|
-
j.isMedia ? n.mediaQueries.push([
|
152
|
+
Object.entries(S).forEach(([D, j]) => {
|
153
|
+
j.isMedia ? n.mediaQueries.push([D, j]) : j.isGlobalDefine ? n.globalStyles.push(j) : j.isDefineVariables ? n.variables.push(j) : j.isDefineTemplates && n.templates.push(j._setPath(`${D};;${B}`));
|
152
154
|
});
|
153
155
|
})
|
154
156
|
);
|
@@ -156,7 +158,7 @@ const Qt = {
|
|
156
158
|
o.mediaQueries = Object.fromEntries(d.map(([h, S]) => [`@${h}`, S]));
|
157
159
|
const w = d.map(([h]) => `'@${h}'`).join(" | "), p = /* @__PURE__ */ new Set(), a = async (h, S = []) => {
|
158
160
|
if (!h) return [];
|
159
|
-
const B = Object.entries(h).map(async ([j,
|
161
|
+
const B = Object.entries(h).map(async ([j, M]) => {
|
160
162
|
const q = async (T) => {
|
161
163
|
if (!T) return;
|
162
164
|
if (T instanceof Promise) return await q(await T);
|
@@ -164,37 +166,37 @@ const Qt = {
|
|
164
166
|
if (typeof T == "object") return await a(T, [...S, j]);
|
165
167
|
const at = xt(j), it = U(j), ct = [...S, at].join(".");
|
166
168
|
p.add(`"${ct}"`);
|
167
|
-
const Y = [...S.map(U), it].join("-"), bt =
|
169
|
+
const Y = [...S.map(U), it].join("-"), bt = Rt(T);
|
168
170
|
return bt ? `--${Y}: ${bt.transformed};` : `--${Y}: ${T};`;
|
169
171
|
};
|
170
|
-
return await q(
|
172
|
+
return await q(M);
|
171
173
|
});
|
172
174
|
return (await Promise.all(B)).flat();
|
173
175
|
}, g = async (h) => {
|
174
176
|
if (!h) return [];
|
175
|
-
const S = Object.entries(h).map(async ([
|
176
|
-
const
|
177
|
-
return
|
177
|
+
const S = Object.entries(h).map(async ([D, j]) => {
|
178
|
+
const M = await a(j);
|
179
|
+
return D === "base" ? M.join("") : o.mediaQueries[D] ? `${o.mediaQueries[D]} { ${M.join("")} }` : `${D} { ${M.join("")} }`;
|
178
180
|
});
|
179
181
|
return (await Promise.all(S)).flat();
|
180
182
|
}, u = async (h) => {
|
181
183
|
if (!h) return [];
|
182
|
-
const S = Object.entries(h).map(async ([
|
183
|
-
const
|
184
|
-
const it = await a(at, [
|
184
|
+
const S = Object.entries(h).map(async ([D, j]) => {
|
185
|
+
const M = Object.entries(j).map(async ([T, at]) => {
|
186
|
+
const it = await a(at, [D]), ct = `.${D}-${T}, [data-${D}="${T}"]`, Y = it.join("");
|
185
187
|
return `${ct} { ${Y} }`;
|
186
188
|
});
|
187
|
-
return (await Promise.all(
|
189
|
+
return (await Promise.all(M)).flat();
|
188
190
|
});
|
189
191
|
return (await Promise.all(S)).flat();
|
190
|
-
}, y = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), m = (h) => n.variables.map((S) => h === "static" ? y(S._current) : S._current[h]), F = H(y(c.variables), m("static")), x = await a(F),
|
192
|
+
}, y = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), m = (h) => n.variables.map((S) => h === "static" ? y(S._current) : S._current[h]), F = H(y(c.variables), m("static")), x = await a(F), k = H((wt = c.variables) == null ? void 0 : wt.responsive, m("responsive")), E = await g(k), z = H(($t = c.variables) == null ? void 0 : $t.conditional, m("conditional")), A = await u(z), gt = i(s, "css/_variables.css"), O = `:root { ${x.join("")} ${E.join("")} } ${A.join("")}`;
|
191
193
|
C(gt, O), o.staticVariables = F;
|
192
194
|
const st = i(s, "css/_global.css"), f = H(c.global, n.globalStyles), $ = await St(f, "");
|
193
195
|
C(st, `@layer global { ${$} }`);
|
194
196
|
const b = i(s, "css/_reset.css"), P = c.reset === "none" ? {} : typeof c.reset == "object" ? c.reset : Qt, N = await St(P, "");
|
195
197
|
C(b, `@layer reset { ${N} }`);
|
196
|
-
const V = i(s, "css/_templates.css"),
|
197
|
-
C(V, `@layer templates { ${K} }`), o.templates =
|
198
|
+
const V = i(s, "css/_templates.css"), R = H(c.templates, n.templates), K = await Mt(R), Q = Jt(R);
|
199
|
+
C(V, `@layer templates { ${K} }`), o.templates = R;
|
198
200
|
const X = c.templates ? [Ht(c.templates)._setPath(`config;;${r}`)] : [], nt = Gt(n.templates, X);
|
199
201
|
o.templatePaths = Object.fromEntries(Object.entries(nt).map(([h, S]) => [h, S._path]));
|
200
202
|
const L = i(s, "types/css-tokens.d.ts"), _t = `
|
@@ -215,8 +217,8 @@ const Qt = {
|
|
215
217
|
const Vt = i(s, "cache/config-cache.json");
|
216
218
|
C(Vt, JSON.stringify(o, null, 2));
|
217
219
|
const yt = Bt();
|
218
|
-
console.log("
|
219
|
-
const ht = i(yt, "
|
220
|
+
console.log("corePackageRoot", yt);
|
221
|
+
const ht = i(yt, "cache/config-cache.json");
|
220
222
|
console.log("Config cache secondary path", ht), C(ht, JSON.stringify(o, null, 2));
|
221
223
|
}, Ct = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
222
224
|
if (/^['"`]/.test(s)) return e;
|
@@ -225,7 +227,7 @@ const Qt = {
|
|
225
227
|
const o = c.exec(t);
|
226
228
|
if (o) {
|
227
229
|
const d = o.at(1);
|
228
|
-
if (
|
230
|
+
if (Dt.some((p) => d == null ? void 0 : d.includes(p))) return e;
|
229
231
|
}
|
230
232
|
return "styled('div',";
|
231
233
|
}), Xt = (t, e) => {
|
@@ -245,7 +247,7 @@ ${t}`;
|
|
245
247
|
const r = tt(e);
|
246
248
|
let o = _(e, "utf8");
|
247
249
|
o = Ct(o), o = Xt(o, t);
|
248
|
-
const d = i(s, "js", n + ".js"), w = await pt(t), p = i(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), a =
|
250
|
+
const d = i(s, "js", n + ".js"), w = await pt(t), p = i(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), a = kt(p), g = await Nt(t);
|
249
251
|
await Ft.build({
|
250
252
|
stdin: {
|
251
253
|
contents: o,
|
@@ -370,7 +372,7 @@ ${t}`;
|
|
370
372
|
C(V, P), y.importStrategy === "component" && m[$].push(l.cssFileName);
|
371
373
|
}
|
372
374
|
y.importStrategy === "component" && Object.entries(m).forEach(([f, $]) => {
|
373
|
-
const b = $.map((
|
375
|
+
const b = $.map((R) => `@import url('./${R}');`).join(`
|
374
376
|
`), l = I(f, 6), P = tt(f), N = U(P.name), V = i(o, `css/f_${N}-${l}.css`);
|
375
377
|
C(V, b || "/* Empty file */");
|
376
378
|
});
|
@@ -403,9 +405,9 @@ ${F}`;
|
|
403
405
|
${nt}
|
404
406
|
/*end:${L}*/
|
405
407
|
`;
|
406
|
-
}, ""), N = `l_${l}.css`, V = i(o, "css", N),
|
408
|
+
}, ""), N = `l_${l}.css`, V = i(o, "css", N), R = `@layer l${l} { ${P}
|
407
409
|
}`;
|
408
|
-
return C(V,
|
410
|
+
return C(V, R), `${$}
|
409
411
|
@import url('./css/${N}');`;
|
410
412
|
}, "");
|
411
413
|
A += f;
|
@@ -435,8 +437,8 @@ ${nt}
|
|
435
437
|
}), F = await m.css;
|
436
438
|
if (!F) continue;
|
437
439
|
r[m.priority] || (r[m.priority] = []), r[m.priority].push(m.cssFileName);
|
438
|
-
const x = `css/${m.cssFileName}`,
|
439
|
-
C(
|
440
|
+
const x = `css/${m.cssFileName}`, k = i(n, x);
|
441
|
+
C(k, F);
|
440
442
|
continue;
|
441
443
|
}
|
442
444
|
if (!p.generator) continue;
|
@@ -454,8 +456,8 @@ ${nt}
|
|
454
456
|
const a = `l_${p}.css`, g = i(n, "css", a);
|
455
457
|
let u = _(g, "utf8");
|
456
458
|
w.forEach((y) => {
|
457
|
-
var
|
458
|
-
const m = i(n, "css", y), F = ((
|
459
|
+
var k;
|
460
|
+
const m = i(n, "css", y), F = ((k = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : k.at(1)) || I(m, 6);
|
459
461
|
if (!u.includes(F)) {
|
460
462
|
const E = _(m, "utf8"), z = `/*start:${F}-${y}*/
|
461
463
|
${E}
|
@@ -491,12 +493,12 @@ ${z}
|
|
491
493
|
config: w
|
492
494
|
}), [m, F] = await Lt(a, g), x = a.slice(m, F);
|
493
495
|
if (u.isClassName) {
|
494
|
-
const
|
495
|
-
a = a.replace(x, E),
|
496
|
+
const k = a, E = ` ${g} = className("${y.classNames}")`;
|
497
|
+
a = a.replace(x, E), k === a && console.error("Minimize file failed to change content", { name: g });
|
496
498
|
}
|
497
499
|
if (x.includes("styled")) {
|
498
|
-
const
|
499
|
-
a = a.replace(x, z), E === a && console.error("Minimize file failed to change content", { name: g, tagName:
|
500
|
+
const k = (c = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : c.trim(), E = a, z = ` ${g} = styled(${k}, "${y.classNames}", ${JSON.stringify(y.clientProps)})`;
|
501
|
+
a = a.replace(x, z), E === a && console.error("Minimize file failed to change content", { name: g, tagName: k });
|
500
502
|
}
|
501
503
|
}
|
502
504
|
if (w.importStrategy === "component") {
|
@@ -512,13 +514,14 @@ ${a}`;
|
|
512
514
|
};
|
513
515
|
export {
|
514
516
|
fe as a,
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
517
|
+
me as b,
|
518
|
+
pe as c,
|
519
|
+
qt as d,
|
520
|
+
At as e,
|
521
|
+
et as f,
|
522
|
+
Bt as g,
|
520
523
|
mt as i,
|
521
524
|
Z as l,
|
522
525
|
ue as m,
|
523
|
-
|
526
|
+
Dt as s
|
524
527
|
};
|
package/package.json
CHANGED
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../should-restart-BFVRQc0_.cjs");exports.checkShouldRestart=e.checkShouldRestart;
|
package/server/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const s=require("fs/promises"),r=require("./index-
|
1
|
+
"use strict";const s=require("fs/promises"),r=require("./index-BYrtB4JM.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!(/.+define[A-Z]\w+/.test(e)||/.+keyframes\(.+/.test(e))};exports.checkShouldRestart=i;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFile as r } from "fs/promises";
|
2
|
-
import { i as e } from "./index-
|
2
|
+
import { i as e } from "./index-CR0k7PXM.js";
|
3
3
|
const f = async (t) => {
|
4
4
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
5
5
|
if (t.includes("salty.config")) return !0;
|
package/index-DOl289-D.cjs
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";const Oe=require("esbuild"),ve=require("child_process"),T=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),be=require("fs/promises"),ce=require("./parse-styles-Bdgw_4ME.cjs"),Se=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),re=require("typescript");var I=typeof document<"u"?document.currentScript:null;function Ve(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const Fe=Ve(Oe),$e=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:$e(i.join(e,".."))},Re=async e=>{const t=$e(e);return await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Me=async e=>{const t=await Re(e);if(t)return t.type};let H;const Ce=async e=>{if(H)return H;const t=await Me(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-DOl289-D.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),Je=e=>{B.error(e)};function Pe(e){return e?typeof e!="string"?Pe(String(e)):e.replace(/[^\d\w]/g,"."):""}const qe={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},ze=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=re.createSourceFile("temp.ts",e,re.ScriptTarget.Latest,!0);function o(y){if(re.isVariableDeclaration(y)&&y.name.getText()===t){const S=y.getStart(),p=y.getEnd();clearTimeout(r),s([S,p])}y.forEachChild(o)}o(l)}),He=()=>{const{pathname:e}=new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:I&&I.tagName.toUpperCase()==="SCRIPT"&&I.src||new URL("index-DOl289-D.cjs",document.baseURI).href);return i.join(e,"../")},v={externalModules:[],rcFile:void 0,destDir:void 0},Ne=e=>{if(v.externalModules.length>0)return v.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return v.externalModules=n,n},q=async e=>{if(v.destDir)return v.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return v.destDir=s,s},le=["salty","css","styles","styled"],xe=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),ee=(e,t=[])=>xe(t).test(e),_e=async e=>{if(v.rcFile)return v.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await be.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(v.rcFile=s,s):_e(i.join(e,".."))},fe=async e=>{var n,r;const t=await _e(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},Ie=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await Ce(e),o=Ne(n);await Fe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:S}=await import(`${r}?t=${y}`);return{config:S,path:r}},ke=async(e,t)=>{var ge,he;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async w=>{const{contents:F,outputFilePath:G}=await A(e,w,s);Object.entries(F).forEach(([k,P])=>{P.isMedia?n.mediaQueries.push([k,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${k};;${G}`))})}));const{config:r,path:l}=await Ie(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([w,F])=>[`@${w}`,F]));const S=y.map(([w])=>`'@${w}'`).join(" | "),p=new Set,a=async(w,F=[])=>{if(!w)return[];const G=Object.entries(w).map(async([P,M])=>{const K=async D=>{if(!D)return;if(D instanceof Promise)return await K(await D);if(typeof D=="function")return await K(await D());if(typeof D=="object")return await a(D,[...F,P]);const oe=Pe(P),ie=T.dashCase(P),ae=[...F,oe].join(".");p.add(`"${ae}"`);const Z=[...F.map(T.dashCase),ie].join("-"),we=ce.parseVariableTokens(D);return we?`--${Z}: ${we.transformed};`:`--${Z}: ${D};`};return await K(M)});return(await Promise.all(G)).flat()},g=async w=>{if(!w)return[];const F=Object.entries(w).map(async([k,P])=>{const M=await a(P);return k==="base"?M.join(""):o.mediaQueries[k]?`${o.mediaQueries[k]} { ${M.join("")} }`:`${k} { ${M.join("")} }`});return(await Promise.all(F)).flat()},m=async w=>{if(!w)return[];const F=Object.entries(w).map(async([k,P])=>{const M=Object.entries(P).map(async([D,oe])=>{const ie=await a(oe,[k]),ae=`.${k}-${D}, [data-${k}="${D}"]`,Z=ie.join("");return`${ae} { ${Z} }`});return(await Promise.all(M)).flat()});return(await Promise.all(F)).flat()},h=w=>({...w,responsive:void 0,conditional:void 0}),d=w=>n.variables.map(F=>w==="static"?h(F._current):F._current[w]),$=J.mergeObjects(h(r.variables),d("static")),x=await a($),_=J.mergeObjects((ge=r.variables)==null?void 0:ge.responsive,d("responsive")),E=await g(_),z=J.mergeObjects((he=r.variables)==null?void 0:he.conditional,d("conditional")),X=await m(z),pe=i.join(s,"css/_variables.css"),V=`:root { ${x.join("")} ${E.join("")} } ${X.join("")}`;c.writeFileSync(pe,V),o.staticVariables=$;const te=i.join(s,"css/_global.css"),u=J.mergeObjects(r.global,n.globalStyles),j=await ce.parseAndJoinStyles(u,"");c.writeFileSync(te,`@layer global { ${j} }`);const b=i.join(s,"css/_reset.css"),C=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:qe,N=await ce.parseAndJoinStyles(C,"");c.writeFileSync(b,`@layer reset { ${N} }`);const O=i.join(s,"css/_templates.css"),R=J.mergeObjects(r.templates,n.templates),L=await Se.parseTemplates(R),W=Se.getTemplateTypes(R);c.writeFileSync(O,`@layer templates { ${L} }`),o.templates=R;const Y=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],se=J.mergeFactories(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(se).map(([w,F])=>[w,F._path]));const U=i.join(s,"types/css-tokens.d.ts"),De=`
|
2
|
-
// Variable types
|
3
|
-
type VariableTokens = ${[...p].join("|")};
|
4
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
5
|
-
|
6
|
-
// Template types
|
7
|
-
type TemplateTokens = {
|
8
|
-
${Object.entries(W).map(([w,F])=>`${w}?: ${F}`).join(`
|
9
|
-
`)}
|
10
|
-
}
|
11
|
-
|
12
|
-
// Media query types
|
13
|
-
type MediaQueryKeys = ${S||"''"};
|
14
|
-
`;c.writeFileSync(U,De);const Te=i.join(s,"cache/config-cache.json");c.writeFileSync(Te,JSON.stringify(o,null,2));const me=He();console.log("Config _dirname",me);const ye=i.join(me,"../cache/config-cache.json");console.log("Config cache secondary path",ye),c.writeFileSync(ye,JSON.stringify(o,null,2))},je=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const o=r.exec(e);if(o){const y=o.at(1);if(le.some(p=>y==null?void 0:y.includes(p)))return t}return"styled('div',"}),Le=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
15
|
-
|
16
|
-
${e}`:`globalThis.saltyConfig = {};
|
17
|
-
|
18
|
-
${e}`}catch{return e}},A=async(e,t,s)=>{const n=T.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=je(o),o=Le(o,e);const y=i.join(s,"js",n+".js"),S=await fe(e),p=i.join(e,(S==null?void 0:S.configDir)||"","salty.config.ts"),a=Ne(p),g=await Ce(e);await Fe.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},$=>{const x=c.readFileSync($.path,"utf8");return{contents:je(x),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${y}?t=${m}`),outputFilePath:y}},We=async e=>{const t=await q(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await We(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},de=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ue=async(e,t=de(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&ve.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const p=new Set,a=new Set;async function g(u){const j=["node_modules","saltygen"],b=c.statSync(u);if(b.isDirectory()){const f=c.readdirSync(u);if(j.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>g(i.join(u,N))))}else if(b.isFile()&&ee(u)){p.add(u);const C=c.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&a.add(u)}}await g(e),await ke(e,a);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...p].map(async u=>{const{contents:j}=await A(e,u,o);for(let[b,f]of Object.entries(j))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:b}):f.isClassName?m.classNames.push({...f,src:u,name:b}):f.generator&&m.components.push({...f,src:u,name:b})}));const h=await ue(e);for(const u of m.keyframes){const{value:j}=u,b=`a_${j.animationName}.css`,f=`css/${b}`,C=i.join(o,f);r.push(b),c.writeFileSync(C,j.css)}const d={};for(const u of m.components){const{src:j,name:b}=u;d[j]||(d[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h});l[f.priority]||(l[f.priority]=[]);const C=await f.css;if(!C)continue;l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&d[j].push(f.cssFileName)}for(const u of m.classNames){const{src:j,name:b}=u;d[j]||(d[j]=[]);const f=u.generator._withBuildContext({callerName:b,isProduction:t,config:h}),C=await f.css;if(!C)continue;l[f.priority]||(l[f.priority]=[]),l[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,O=i.join(o,N);c.writeFileSync(O,C),h.importStrategy==="component"&&d[j].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(d).forEach(([u,j])=>{const b=j.map(R=>`@import url('./${R}');`).join(`
|
19
|
-
`),f=T.toHash(u,6),C=i.parse(u),N=T.dashCase(C.name),O=i.join(o,`css/f_${N}-${f}.css`);c.writeFileSync(O,b||"/* Empty file */")});const $=r.map(u=>`@import url('./css/${u}');`).join(`
|
20
|
-
`);let X=`/*!
|
21
|
-
* Generated with Salty CSS (https://salty-css.dev)
|
22
|
-
* Do not edit this file directly
|
23
|
-
*/
|
24
|
-
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
25
|
-
|
26
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(u=>{try{return c.readFileSync(i.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
27
|
-
`)}
|
28
|
-
${$}`;if(h.importStrategy!=="component"){const u=l.reduce((j,b,f)=>{const C=b.reduce((L,W)=>{var ne;const Y=i.join(o,"css",W),se=c.readFileSync(Y,"utf8"),U=((ne=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:ne.at(1))||T.toHash(Y,6);return L.includes(U)?L:`${L}
|
29
|
-
/*start:${U}-${W}*/
|
30
|
-
${se}
|
31
|
-
/*end:${U}*/
|
32
|
-
`},""),N=`l_${f}.css`,O=i.join(o,"css",N),R=`@layer l${f} { ${C}
|
33
|
-
}`;return c.writeFileSync(O,R),`${j}
|
34
|
-
@import url('./css/${N}');`},"");X+=u}c.writeFileSync(y,X);const V=Date.now()-n,te=V<200?"🔥":V<500?"🚀":V<1e3?"🎉":V<2e3?"🚗":V<5e3?"🤔":"🥴";B.info(`Generated CSS in ${V}ms! ${te}`)}catch(n){console.error(n)}},Ge=async(e,t,s=de())=>{try{const n=await q(e);if(ee(t)){const l=[],o=await ue(e),{contents:y}=await A(e,t,n);for(const[S,p]of Object.entries(y)){if(p.isKeyframes&&p.css){const $=`css/${`a_${p.animationName}.css`}`,x=i.join(n,$);c.writeFileSync(x,await p.css);continue}if(p.isClassName){const d=p.generator._withBuildContext({callerName:S,isProduction:s,config:o}),$=await d.css;if(!$)continue;l[d.priority]||(l[d.priority]=[]),l[d.priority].push(d.cssFileName);const x=`css/${d.cssFileName}`,_=i.join(n,x);c.writeFileSync(_,$);continue}if(!p.generator)continue;const a=p.generator._withBuildContext({callerName:S,isProduction:s,config:o}),g=await a.css;if(!g)continue;const m=`css/${a.cssFileName}`,h=i.join(n,m);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((S,p)=>{const a=`l_${p}.css`,g=i.join(n,"css",a);let m=c.readFileSync(g,"utf8");S.forEach(h=>{var _;const d=i.join(n,"css",h),$=((_=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:_.at(1))||T.toHash(d,6);if(!m.includes($)){const E=c.readFileSync(d,"utf8"),z=`/*start:${$}-${h}*/
|
35
|
-
${E}
|
36
|
-
/*end:${$}*/
|
37
|
-
`;m=`${m.replace(/\}$/,"")}
|
38
|
-
${z}
|
39
|
-
}`}}),c.writeFileSync(g,m)});else{const S=l.flat().map(h=>`@import url('./${h}');`).join(`
|
40
|
-
`),p=T.toHash(t,6),a=i.parse(t),g=T.dashCase(a.name),m=i.join(n,`css/f_${g}-${p}.css`);c.writeFileSync(m,S||"/* Empty file */")}}}catch(n){console.error(n)}},Ke=async(e,t,s=de())=>{var n,r;try{const l=await q(e);if(ee(t)){const y=c.readFileSync(t,"utf8"),S=await ue(e),{contents:p}=await A(e,t,l);let a=y;for(const[g,m]of Object.entries(p)){if(m.isKeyframes||!m.generator)continue;const h=m.generator._withBuildContext({callerName:g,isProduction:s,config:S}),[d,$]=await ze(a,g),x=a.slice(d,$);if(m.isClassName){const _=a,E=` ${g} = className("${h.classNames}")`;a=a.replace(x,E),_===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const _=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),E=a,z=` ${g} = styled(${_}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),E===a&&console.error("Minimize file failed to change content",{name:g,tagName:_})}}if(S.importStrategy==="component"){const g=T.toHash(t,6),m=i.parse(t);a=`import '../../saltygen/css/${`f_${T.dashCase(m.name)}-${g}.css`}';
|
41
|
-
${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=A;exports.generateConfigStyles=ke;exports.generateCss=Ue;exports.generateFile=Ge;exports.isSaltyFile=ee;exports.logError=Je;exports.logger=B;exports.minimizeFile=Ke;exports.saltyFileExtensions=le;exports.saltyFileRegExp=xe;
|