@salty-css/core 0.0.1-alpha.202 → 0.0.1-alpha.203
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 +1 -1
- package/compiler/index.cjs +1 -1
- package/compiler/index.js +1 -1
- package/{index-B-fI-Hqk.js → index-CuE3hjO7.js} +22 -23
- package/{index-CTYuOIyS.cjs → index-_k0TKi9f.cjs} +11 -11
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-_k0TKi9f.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);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(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){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:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=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:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).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}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,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 t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.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 f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=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,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
|
4
4
|
import { join as i, relative as z, parse as re, format as ee } from "path";
|
5
5
|
import { render as ce } from "ejs";
|
6
|
-
import { l as t, a as h, g as te } from "../index-
|
6
|
+
import { l as t, a as h, g as te } from "../index-CuE3hjO7.js";
|
7
7
|
import { p as le } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as de } from "child_process";
|
9
9
|
import fe from "ora";
|
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-DhDStS4F.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-DhDStS4F.cjs");const e=require("../index-_k0TKi9f.cjs");require("../css/merge.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.js
CHANGED
@@ -5,7 +5,7 @@ import "path";
|
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-CbYzTfwr.js";
|
8
|
-
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-
|
8
|
+
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-CuE3hjO7.js";
|
9
9
|
import "../css/merge.js";
|
10
10
|
export {
|
11
11
|
n as compileSaltyFile,
|
@@ -2,7 +2,7 @@ import * as mt from "esbuild";
|
|
2
2
|
import { execSync as Nt } from "child_process";
|
3
3
|
import { d as W, t as I } from "./dash-case-DBThphLm.js";
|
4
4
|
import { join as i, parse as Y } from "path";
|
5
|
-
import { existsSync as it, writeFileSync as j, mkdirSync as
|
5
|
+
import { existsSync as it, writeFileSync as j, mkdirSync as J, readFileSync as D, statSync as Pt, readdirSync as kt } from "fs";
|
6
6
|
import { readFile as gt, writeFile as Dt } from "fs/promises";
|
7
7
|
import { p as at, a as _t } from "./parse-styles-CbYzTfwr.js";
|
8
8
|
import { createLogger as Tt, format as ot, transports as Et } from "winston";
|
@@ -10,15 +10,14 @@ import { mergeStyles as z, mergeFactories as Ot } from "./css/merge.js";
|
|
10
10
|
const yt = async (t, e = []) => {
|
11
11
|
if (!t) return "";
|
12
12
|
const s = [], o = {};
|
13
|
-
|
14
|
-
if (typeof a == "function")
|
15
|
-
if (typeof a == "object") {
|
16
|
-
if (!a) return;
|
13
|
+
for (const [n, a] of Object.entries(t))
|
14
|
+
if (typeof a == "function") console.log("Function found", n);
|
15
|
+
else if (a && typeof a == "object") {
|
17
16
|
const l = n.trim(), u = await yt(a, [...e, l]);
|
18
17
|
s.push(u);
|
19
18
|
} else
|
20
19
|
o[n] = a;
|
21
|
-
|
20
|
+
if (Object.keys(o).length) {
|
22
21
|
const n = e.map(W).join("-"), a = await at(o, `.${n}`);
|
23
22
|
s.push(a);
|
24
23
|
}
|
@@ -35,16 +34,16 @@ const yt = async (t, e = []) => {
|
|
35
34
|
const e = bt(t);
|
36
35
|
return await gt(e, "utf-8").then(JSON.parse).catch(() => {
|
37
36
|
});
|
38
|
-
},
|
37
|
+
}, vt = async (t) => {
|
39
38
|
const e = await Mt(t);
|
40
39
|
if (e)
|
41
40
|
return e.type;
|
42
41
|
};
|
43
|
-
let
|
42
|
+
let R;
|
44
43
|
const $t = async (t) => {
|
45
|
-
if (
|
46
|
-
const e = await
|
47
|
-
return e === "module" ?
|
44
|
+
if (R) return R;
|
45
|
+
const e = await vt(t);
|
46
|
+
return e === "module" ? R = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (R = "cjs"), R || "esm";
|
48
47
|
}, X = Tt({
|
49
48
|
level: "debug",
|
50
49
|
format: ot.combine(ot.colorize(), ot.cli()),
|
@@ -55,7 +54,7 @@ const $t = async (t) => {
|
|
55
54
|
function wt(t) {
|
56
55
|
return t ? typeof t != "string" ? wt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
57
56
|
}
|
58
|
-
const
|
57
|
+
const Rt = {
|
59
58
|
/** Set box model to border-box */
|
60
59
|
"*, *::before, *::after": {
|
61
60
|
boxSizing: "border-box"
|
@@ -115,7 +114,7 @@ const Jt = {
|
|
115
114
|
if (V.destDir) return V.destDir;
|
116
115
|
const e = await ct(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
117
116
|
return V.destDir = s, s;
|
118
|
-
}, Ct = ["salty", "css", "styles", "styled"],
|
117
|
+
}, Ct = ["salty", "css", "styles", "styled"], Jt = (t = []) => new RegExp(`\\.(${[...Ct, ...t].join("|")})\\.`), rt = (t, e = []) => Jt(e).test(t), Ft = async (t) => {
|
119
118
|
if (V.rcFile) return V.rcFile;
|
120
119
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
121
120
|
const e = i(t, ".saltyrc.json"), s = await gt(e, "utf-8").then(JSON.parse).catch(() => {
|
@@ -167,11 +166,11 @@ const Jt = {
|
|
167
166
|
}) : [], f = (y) => y ? Object.entries(y).flatMap(([w, O]) => Object.entries(O).flatMap(([x, P]) => {
|
168
167
|
const st = u(P, [w]), nt = `.${w}-${x}, [data-${w}="${x}"]`, U = st.join("");
|
169
168
|
return `${nt} { ${U} }`;
|
170
|
-
})) : [], m = (y) => ({ ...y, responsive: void 0, conditional: void 0 }), g = (y) => o.variables.map((w) => y === "static" ? m(w._current) : w._current[y]), p = z(m(n.variables), g("static")), S = u(p), h = z((ft = n.variables) == null ? void 0 : ft.responsive, g("responsive")), T = d(h), k = z((ut = n.variables) == null ? void 0 : ut.conditional, g("conditional")), _ = f(k),
|
171
|
-
j(
|
169
|
+
})) : [], m = (y) => ({ ...y, responsive: void 0, conditional: void 0 }), g = (y) => o.variables.map((w) => y === "static" ? m(w._current) : w._current[y]), p = z(m(n.variables), g("static")), S = u(p), h = z((ft = n.variables) == null ? void 0 : ft.responsive, g("responsive")), T = d(h), k = z((ut = n.variables) == null ? void 0 : ut.conditional, g("conditional")), _ = f(k), v = i(s, "css/_variables.css"), E = `:root { ${S.join("")} ${T.join("")} } ${_.join("")}`;
|
170
|
+
j(v, E), a.staticVariables = p;
|
172
171
|
const B = i(s, "css/_global.css"), N = z(n.global, o.globalStyles), G = await at(N, "");
|
173
172
|
j(B, `@layer global { ${G} }`);
|
174
|
-
const r = i(s, "css/_reset.css"), $ = n.reset === "none" ? {} : typeof n.reset == "object" ? n.reset :
|
173
|
+
const r = i(s, "css/_reset.css"), $ = n.reset === "none" ? {} : typeof n.reset == "object" ? n.reset : Rt, c = await at($, "");
|
175
174
|
j(r, `@layer reset { ${c} }`);
|
176
175
|
const C = i(s, "css/_templates.css"), F = z(n.templates, o.templates), H = await yt(F), K = Vt(F);
|
177
176
|
j(C, H), a.templates = F;
|
@@ -221,7 +220,7 @@ ${t}`;
|
|
221
220
|
}
|
222
221
|
}, tt = async (t, e, s) => {
|
223
222
|
const o = I(e), n = i(s, "./temp");
|
224
|
-
it(n) ||
|
223
|
+
it(n) || J(n);
|
225
224
|
const a = Y(e);
|
226
225
|
let l = D(e, "utf8");
|
227
226
|
l = dt(l), l = It(l, t);
|
@@ -275,7 +274,7 @@ ${t}`;
|
|
275
274
|
e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
|
276
275
|
const n = [], a = [], l = await M(t), u = i(l, "index.css");
|
277
276
|
s && (() => {
|
278
|
-
it(l) && Nt("rm -rf " + l),
|
277
|
+
it(l) && Nt("rm -rf " + l), J(l, { recursive: !0 }), J(i(l, "css")), J(i(l, "types")), J(i(l, "js")), J(i(l, "cache"));
|
279
278
|
})();
|
280
279
|
const f = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Set();
|
281
280
|
async function g(r) {
|
@@ -417,12 +416,12 @@ ${et}
|
|
417
416
|
var k;
|
418
417
|
const S = i(s, "css", p), h = ((k = /.*-([^-]+)-\d+.css/.exec(p)) == null ? void 0 : k.at(1)) || I(S, 6);
|
419
418
|
if (!g.includes(h)) {
|
420
|
-
const _ = D(S, "utf8"),
|
419
|
+
const _ = D(S, "utf8"), v = `/*start:${h}*/
|
421
420
|
${_}
|
422
421
|
/*end:${h}*/
|
423
422
|
`;
|
424
423
|
g = `${g.replace(/\}$/, "")}
|
425
|
-
${
|
424
|
+
${v}
|
426
425
|
}`;
|
427
426
|
}
|
428
427
|
}), j(m, g);
|
@@ -457,13 +456,13 @@ ${R}
|
|
457
456
|
if (!T) return console.error("Could not find the original declaration");
|
458
457
|
const { index: k } = T;
|
459
458
|
let _ = !1;
|
460
|
-
const
|
459
|
+
const v = setTimeout(() => _ = !0, 5e3);
|
461
460
|
let E = 0, B = !1, N = 0;
|
462
461
|
for (; !B && !_; ) {
|
463
462
|
const C = f[k + E];
|
464
463
|
C === "(" && N++, C === ")" && N--, N === 0 && C === ")" && (B = !0), E > f.length && (_ = !0), E++;
|
465
464
|
}
|
466
|
-
if (!_) clearTimeout(
|
465
|
+
if (!_) clearTimeout(v);
|
467
466
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
468
467
|
const G = k + E, r = f.slice(k, G), b = f, $ = ` ${m} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;
|
469
468
|
f = f.replace(r, $), b === f && console.error("Minimize file failed to change content", { name: m, tagName: h });
|
@@ -480,7 +479,7 @@ ${f}`;
|
|
480
479
|
};
|
481
480
|
export {
|
482
481
|
Ut as a,
|
483
|
-
|
482
|
+
Jt as b,
|
484
483
|
Wt as c,
|
485
484
|
tt as d,
|
486
485
|
Yt as e,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
"use strict";const Ce=require("esbuild"),xe=require("child_process"),
|
2
|
-
`)},
|
1
|
+
"use strict";const Ce=require("esbuild"),xe=require("child_process"),P=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),a=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-DhDStS4F.cjs"),B=require("winston"),V=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(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 de=Ne(Ce),pe=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,i]of Object.entries(e))if(typeof i=="function")console.log("Function found",o);else if(i&&typeof i=="object"){const f=o.trim(),d=await pe(i,[...t,f]);s.push(d)}else n[o]=i;if(Object.keys(n).length){const o=t.map(P.dashCase).join("-"),i=await X.parseAndJoinStyles(n,`.${o}`);s.push(i)}return s.join(`
|
2
|
+
`)},ke=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ye(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},ye=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?ye(o,i,s):s.add(t)}),[...s]):[],me=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return a.existsSync(t)?t:me(r.join(e,".."))},Pe=async e=>{const t=me(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await Pe(e);if(t)return t.type};let J;const ge=async e=>{if(J)return J;const t=await De(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-_k0TKi9f.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};function he(e){return e?typeof e!="string"?he(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Te={"*, *::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"}},R={externalModules:[],rcFile:void 0,destDir:void 0},Se=e=>{if(R.externalModules.length>0)return R.externalModules;const s=a.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return R.externalModules=n,n},M=async e=>{if(R.destDir)return R.destDir;const t=await re(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return R.destDir=s,s},ie=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>we(t).test(e),je=async e=>{if(R.rcFile)return R.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(R.rcFile=s,s):je(r.join(e,".."))},re=async e=>{var n,o;const t=await je(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},Ee=async e=>{const t=await re(e),s=await M(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=r.join(s,"salty.config.js"),i=await ge(e),f=Se(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:f});const d=Date.now(),{config:y}=await import(`${o}?t=${d}`);return y},be=async(e,t)=>{var ce,le;const s=await M(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async h=>{const{contents:b,outputFilePath:O}=await K(e,h,s);Object.entries(b).forEach(([x,k])=>{k.isMedia?n.mediaQueries.push([x,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(O))})}));const o=await Ee(e),i={...o},f=new Set,d=(h,b=[])=>h?Object.entries(h).flatMap(([O,x])=>{if(!x)return;if(typeof x=="object")return d(x,[...b,O]);const k=he(O),te=P.dashCase(O),se=[...b,k].join(".");f.add(`"${se}"`);const U=[...b.map(P.dashCase),te].join("-"),fe=X.parseVariableTokens(x);return fe?`--${U}: ${fe.transformed};`:`--${U}: ${x};`}):[],y=h=>h?Object.entries(h).flatMap(([b,O])=>{const x=d(O);return b==="base"?x.join(""):`${b} { ${x.join("")} }`}):[],u=h=>h?Object.entries(h).flatMap(([b,O])=>Object.entries(O).flatMap(([x,k])=>{const te=d(k,[b]),se=`.${b}-${x}, [data-${b}="${x}"]`,U=te.join("");return`${se} { ${U} }`})):[],m=h=>({...h,responsive:void 0,conditional:void 0}),g=h=>n.variables.map(b=>h==="static"?m(b._current):b._current[h]),p=V.mergeStyles(m(o.variables),g("static")),F=d(p),S=V.mergeStyles((ce=o.variables)==null?void 0:ce.responsive,g("responsive")),T=y(S),D=V.mergeStyles((le=o.variables)==null?void 0:le.conditional,g("conditional")),_=u(D),v=r.join(s,"css/_variables.css"),E=`:root { ${F.join("")} ${T.join("")} } ${_.join("")}`;a.writeFileSync(v,E),i.staticVariables=p;const z=r.join(s,"css/_global.css"),N=V.mergeStyles(o.global,n.globalStyles),H=await X.parseAndJoinStyles(N,"");a.writeFileSync(z,`@layer global { ${H} }`);const c=r.join(s,"css/_reset.css"),j=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Te,l=await X.parseAndJoinStyles(j,"");a.writeFileSync(c,`@layer reset { ${l} }`);const $=r.join(s,"css/_templates.css"),C=V.mergeStyles(o.templates,n.templates),q=await pe(C),I=ke(C);a.writeFileSync($,q),i.templates=C;const W=V.mergeFactories(n.templates);i.templatePaths=Object.fromEntries(Object.entries(W).map(([h,b])=>[h,b._path||"nope"]));const{mediaQueries:A}=n;i.mediaQueries=Object.fromEntries(A.map(([h,b])=>[`@${h}`,b]));const L=A.map(([h])=>`'@${h}'`).join(" | "),ee=r.join(s,"types/css-tokens.d.ts"),Z=`
|
3
3
|
// Variable types
|
4
4
|
type VariableTokens = ${[...f].join("|")};
|
5
5
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -12,27 +12,27 @@
|
|
12
12
|
|
13
13
|
// Media query types
|
14
14
|
type MediaQueryKeys = ${L||"''"};
|
15
|
-
`;a.writeFileSync(ee,Z);const $e=r.join(s,"cache/config-cache.json");a.writeFileSync($e,JSON.stringify(i,null,2))},
|
15
|
+
`;a.writeFileSync(ee,Z);const $e=r.join(s,"cache/config-cache.json");a.writeFileSync($e,JSON.stringify(i,null,2))},ue=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const f=o.exec(e);if(f){const d=f.at(1);if(ie.some(u=>d==null?void 0:d.includes(u)))return t}return"styled('div',"}),Oe=(e,t)=>{try{const s=a.readFileSync(r.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
16
|
|
17
17
|
${e}`:`globalThis.saltyConfig = {};
|
18
18
|
|
19
|
-
${e}`}catch{return e}},K=async(e,t,s)=>{const n=
|
20
|
-
`),l=
|
19
|
+
${e}`}catch{return e}},K=async(e,t,s)=>{const n=P.toHash(t),o=r.join(s,"./temp");a.existsSync(o)||a.mkdirSync(o);const i=r.parse(t);let f=a.readFileSync(t,"utf8");f=ue(f),f=Oe(f,e);const d=r.join(s,"js",n+".js"),y=await re(e),u=r.join(e,(y==null?void 0:y.configDir)||"","salty.config.ts"),m=Se(u),g=await ge(e);await de.build({stdin:{contents:f,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:g,target:["node20"],keepNames:!0,external:m,packages:"external",plugins:[{name:"test",setup:S=>{S.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const D=a.readFileSync(T.path,"utf8");return{contents:ue(D),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${d}?t=${p}`),outputFilePath:d}},Re=async e=>{const t=await M(e),s=r.join(t,"cache/config-cache.json"),n=a.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await M(e),n=r.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return V.mergeStyles(i,t)},Fe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=Fe(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const o=[],i=[],f=await M(e),d=r.join(f,"index.css");s&&(()=>{a.existsSync(f)&&xe.execSync("rm -rf "+f),a.mkdirSync(f,{recursive:!0}),a.mkdirSync(r.join(f,"css")),a.mkdirSync(r.join(f,"types")),a.mkdirSync(r.join(f,"js")),a.mkdirSync(r.join(f,"cache"))})();const u=new Set,m=new Set;async function g(c){const w=["node_modules","saltygen"],j=a.statSync(c);if(j.isDirectory()){const l=a.readdirSync(c);if(w.some(C=>c.includes(C)))return;await Promise.all(l.map(C=>g(r.join(c,C))))}else if(j.isFile()&&Y(c)){u.add(c);const $=a.readFileSync(c,"utf8");/define[\w\d]+\(/.test($)&&m.add(c)}}await g(e),await be(e,m);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async c=>{const{contents:w}=await K(e,c,f);Object.entries(w).forEach(([j,l])=>{l.isKeyframes?p.keyframes.push({value:l,src:c,name:j}):l.isClassName?p.classNames.push({...l,src:c,name:j}):l.generator&&p.components.push({...l,src:c,name:j})})}));const F=await ae(e);for(const c of p.keyframes){const{value:w}=c,j=`a_${w.animationName}.css`,l=`css/${j}`,$=r.join(f,l);o.push(j),a.writeFileSync($,w.css)}const S={};for(const c of p.components){const{src:w,name:j}=c,l=c.generator._withBuildContext({callerName:j,isProduction:t,config:F});i[l.priority]||(i[l.priority]=[]),i[l.priority].push(l.cssFileName);const $=`css/${l.cssFileName}`,C=r.join(f,$);a.writeFileSync(C,await l.css),F.importStrategy==="component"&&(S[w]?S[w].push(l.cssFileName):S[w]=[l.cssFileName])}for(const c of p.classNames){const{src:w,name:j}=c,l=c.generator._withBuildContext({callerName:j,isProduction:t,config:F});i[0].push(l.cssFileName);const $=`css/${l.cssFileName}`,C=r.join(f,$);a.writeFileSync(C,await l.css),F.importStrategy==="component"&&(S[w]?S[w].push(l.cssFileName):S[w]=[l.cssFileName])}F.importStrategy==="component"&&Object.entries(S).forEach(([c,w])=>{const j=w.map(I=>`@import url('./${I}');`).join(`
|
20
|
+
`),l=P.toHash(c,6),$=r.parse(c),C=P.dashCase($.name),q=r.join(f,`css/f_${C}-${l}.css`);a.writeFileSync(q,j)});const T=o.map(c=>`@import url('./css/${c}');`).join(`
|
21
21
|
`);let E=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
22
|
|
23
23
|
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return a.readFileSync(r.join(f,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
|
24
24
|
`)}
|
25
|
-
${T}`;if(F.importStrategy!=="component"){const c=i.reduce((w,j,l)=>{const $=j.reduce((W,A)=>{var Z;const L=r.join(f,"css",A),ee=a.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:Z.at(1))||
|
25
|
+
${T}`;if(F.importStrategy!=="component"){const c=i.reduce((w,j,l)=>{const $=j.reduce((W,A)=>{var Z;const L=r.join(f,"css",A),ee=a.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:Z.at(1))||P.toHash(L,6);return W.includes(Q)?W:`${W}
|
26
26
|
/*start:${Q}*/
|
27
27
|
${ee}
|
28
28
|
/*end:${Q}*/
|
29
29
|
`},""),C=`l_${l}.css`,q=r.join(f,"css",C),I=`@layer l${l} { ${$}
|
30
30
|
}`;return a.writeFileSync(q,I),`${w}
|
31
|
-
@import url('./css/${C}');`},"");E+=c}a.writeFileSync(
|
31
|
+
@import url('./css/${C}');`},"");E+=c}a.writeFileSync(d,E);const N=Date.now()-n,H=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";G.info(`Generated CSS in ${N}ms! ${H}`)}catch(n){console.error(n)}},Me=async(e,t)=>{try{const s=await M(e);if(Y(t)){const o=[],i=await ae(e),{contents:f}=await K(e,t,s);for(const[d,y]of Object.entries(f)){if(y.isKeyframes&&y.css){const F=`css/${`a_${y.animationName}.css`}`,S=r.join(s,F);a.writeFileSync(S,await y.css);return}if(y.isClassName){const p=y.factory._withBuildContext({name:d});o[0].push(p.cssFileName);const F=`css/${p.cssFileName}`,S=r.join(s,F);a.writeFileSync(S,await p.css)}if(!y.generator)return;const u=y.generator._withBuildContext({name:d,config:i}),m=`css/${u.cssFileName}`,g=r.join(s,m);a.writeFileSync(g,await u.css),o[u.priority]||(o[u.priority]=[]),o[u.priority].push(u.cssFileName)}if(i.importStrategy!=="component")o.forEach((d,y)=>{const u=`l_${y}.css`,m=r.join(s,"css",u);let g=a.readFileSync(m,"utf8");d.forEach(p=>{var D;const F=r.join(s,"css",p),S=((D=/.*-([^-]+)-\d+.css/.exec(p))==null?void 0:D.at(1))||P.toHash(F,6);if(!g.includes(S)){const _=a.readFileSync(F,"utf8"),v=`/*start:${S}*/
|
32
32
|
${_}
|
33
33
|
/*end:${S}*/
|
34
34
|
`;g=`${g.replace(/\}$/,"")}
|
35
|
-
${
|
36
|
-
}`}}),a.writeFileSync(m,g)});else{const
|
37
|
-
`),y=
|
38
|
-
${
|
35
|
+
${v}
|
36
|
+
}`}}),a.writeFileSync(m,g)});else{const d=o.flat().map(p=>`@import url('./${p}');`).join(`
|
37
|
+
`),y=P.toHash(t,6),u=r.parse(t),m=P.dashCase(u.name),g=r.join(s,`css/f_${m}-${y}.css`);a.writeFileSync(g,d)}}}catch(s){console.error(s)}},ve=async(e,t,s=Fe())=>{try{const n=await M(e);if(Y(t)){const i=a.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==i&&await oe.writeFile(t,i);const d=await ae(e),{contents:y}=await K(e,t,n);let u=i;if(Object.entries(y).forEach(([m,g])=>{var l;if(g.isKeyframes||!g.generator)return;const p=g.generator._withBuildContext({name:m,config:d,prod:s}),F=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!F)return console.error("Could not find the original declaration");const S=(l=F.at(1))==null?void 0:l.trim(),T=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(u);if(!T)return console.error("Could not find the original declaration");const{index:D}=T;let _=!1;const v=setTimeout(()=>_=!0,5e3);let E=0,z=!1,N=0;for(;!z&&!_;){const $=u[D+E];$==="("&&N++,$===")"&&N--,N===0&&$===")"&&(z=!0),E>u.length&&(_=!0),E++}if(!_)clearTimeout(v);else throw new Error("Failed to find the end of the styled call and timed out");const H=D+E,c=u.slice(D,H),w=u,j=` ${m} = styled(${S}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;u=u.replace(c,j),w===u&&console.error("Minimize file failed to change content",{name:m,tagName:S})}),d.importStrategy==="component"){const m=P.toHash(t,6),g=r.parse(t);u=`import '../../saltygen/css/${`f_${P.dashCase(g.name)}-${m}.css`}';
|
38
|
+
${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=be;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
|
package/package.json
CHANGED
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-_k0TKi9f.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)};exports.checkShouldRestart=i;
|
package/server/index.js
CHANGED
@@ -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-CuE3hjO7.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;
|