@salty-css/astro 0.1.0-alpha.7 → 0.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("@salty-css/core/compiler/helpers"),k=require("@salty-css/core/compiler/get-function-range"),A=require("@salty-css/core/compiler/salty-compiler"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),m=require("fs/promises"),_=require("path"),q=E=>{const c=new A.SaltyCompiler(E);return{name:"stylegen",configureServer(t){c.importFile=async n=>{const r=Date.now();return t.ssrLoadModule(`${n}?t=${r}`)}},buildStart:async()=>{await c.generateCss()},load:async t=>{var r,h;if(S.isSaltyFile(t)){const u=await c.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const p=new URLSearchParams(t.split("?")[1]).get("configFile");if(!p)return;const i=_.join(u,"astro",p),g=await m.readFile(i,"utf-8");if(!g)return;try{const a=JSON.parse(g),{clientProps:f={},classNames:s="",tagIsComponent:d,tagName:o="div"}=a,y=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...a.imports||[]],j=d?o:`__r.element || ${JSON.stringify(f.element||o)}`;return`---
2
- ${y.join(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const N=require("@salty-css/core/compiler/helpers"),b=require("@salty-css/core/compiler/get-function-range"),k=require("@salty-css/core/compiler/salty-compiler"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),g=require("fs/promises"),x=require("path"),q=E=>{const l=new k.SaltyCompiler(E);return{name:"stylegen",configureServer(t){l.importFile=async o=>{const n=Date.now();return t.ssrLoadModule(`${o}?t=${n}`)}},buildStart:async()=>{await l.generateCss()},load:async function(t){var n,d;if(N.isSaltyFile(t)){const m=await l.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const h=new URLSearchParams(t.split("?")[1]).get("configFile");if(!h)return;const r=x.join(m,"astro",h);this.addWatchFile(r);const y=await g.readFile(r,"utf-8");if(!y)return;try{const c=JSON.parse(y),{clientProps:F={},classNames:s="",tagIsComponent:w,tagName:i="div"}=c,$=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...c.imports||[]],j=w?i:`__r.element || ${JSON.stringify(F.element||i)}`;return`---
2
+ ${$.join(`
3
3
  `)}
4
- const __gp = ${JSON.stringify(f)};
4
+ const __gp = ${JSON.stringify(F)};
5
5
  const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(s)});
6
6
  const Element = ${j};
7
7
  ---
8
- <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(a){console.error("Error parsing config file:",a);return}}const v=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],x=[],w=[],$=await m.readFile(t,"utf-8"),J=await c.compileSaltyFile(t,u),R=Object.entries(J.contents);for(const[e,p]of R){const i=await S.resolveExportValue(p,1);if(!i.generator)continue;if(i.isClassName){const C=i.generator._withBuildContext({callerName:e,isProduction:!1,config:{}});x.push(`const ${e} = classNameInstance(${JSON.stringify(C.params)});`),w.push(e);continue}const[g,a]=await k.getFunctionRange($,e),f=$.slice(g,a),s=(h=(r=/styled\(([^,]+),/.exec(f))==null?void 0:r.at(1))==null?void 0:h.trim();if(!s){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const d=i.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),o={componentName:e,tagName:s.replace(/['"`]/g,""),tagIsComponent:!1,classNames:d.classNames,imports:[],clientProps:d.clientProps},F=/^\w+$/.test(s);if(o.tagIsComponent=F,F){const C=R.some(([l])=>l===s),I=$.match(new RegExp(`import[^;]*${s}[^;]*;`));if(C){const l=P.toHash(s),b=`import ${s} from '${t}.astro?configFile=${l}.config';`;o.imports=[b]}else if(I){const l=I.at(0);o.imports=[l]}}const y=_.join(u,"astro");await m.readFile(y,"utf-8").catch(()=>!1)||await m.mkdir(y,{recursive:!0});const N=P.toHash(e),D=_.join(u,"astro",`${N}.config`);await m.writeFile(D,JSON.stringify(o)),v.push(`import ${e} from '${t}.astro?configFile=${N}.config';`),w.push(e)}return`${v.join(`
8
+ <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(c){console.error("Error parsing config file:",c);return}}const u=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],f=[],a=[],S=await g.readFile(t,"utf-8"),J=await l.compileSaltyFile(t,m),R=Object.entries(J.contents);for(const[e,h]of R){const r=await N.resolveExportValue(h,1);if(!r.generator)continue;if(r.isClassName){const v=r.generator._withBuildContext({callerName:e,isProduction:!1,config:{}});f.push(`const ${e} = classNameInstance(${JSON.stringify(v.params)});`),a.push(e);continue}const[y,c]=await b.getFunctionRange(S,e),F=S.slice(y,c),s=(d=(n=/styled\(([^,]+),/.exec(F))==null?void 0:n.at(1))==null?void 0:d.trim();if(!s){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const w=r.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),i={componentName:e,tagName:s.replace(/['"`]/g,""),tagIsComponent:!1,classNames:w.classNames,imports:[],clientProps:w.clientProps},C=/^\w+$/.test(s);if(i.tagIsComponent=C,C){const v=R.some(([p])=>p===s),I=S.match(new RegExp(`import[^;]*${s}[^;]*;`));if(v){const p=P.toHash(s),D=`import ${s} from '${t}.astro?configFile=${p}.config';`;i.imports=[D]}else if(I){const p=I.at(0);i.imports=[p]}}const $=x.join(m,"astro");await g.readFile($,"utf-8").catch(()=>!1)||await g.mkdir($,{recursive:!0});const _=P.toHash(e),M=x.join(m,"astro",`${_}.config`);await g.writeFile(M,JSON.stringify(i)),u.push(`import ${e} from '${t}.astro?configFile=${_}.config';`),a.push(e)}return`${u.join(`
9
9
  `)}
10
- ${x.join(`
10
+ ${f.join(`
11
11
  `)}
12
- export { ${w.join(", ")} };`}},handleHotUpdate:async({file:t,server:n})=>{await O.checkShouldRestart(t)&&n.restart()},watchChange:{handler:async(t,n)=>{S.isSaltyFile(t)&&n.event!=="delete"&&(await O.checkShouldRestart(t)||await c.generateFile(t))}}}};exports.default=q;exports.saltyPlugin=q;
12
+ export { ${a.join(", ")} };`}},handleHotUpdate:async({file:t,server:o,modules:n})=>{if(await O.checkShouldRestart(t))return o.restart();if(!N.isSaltyFile(t))return;const u=[];for(const[f,a]of o.moduleGraph.idToModuleMap)f.startsWith(t+".astro?configFile=")&&(o.moduleGraph.invalidateModule(a),u.push(a));return[...n,...u]},watchChange:{handler:async(t,o)=>{N.isSaltyFile(t)&&o.event!=="delete"&&(await O.checkShouldRestart(t)||await l.generateFile(t))}}}};exports.default=q;exports.saltyPlugin=q;
@@ -1,110 +1,117 @@
1
- import { isSaltyFile as E, resolveExportValue as b } from "@salty-css/core/compiler/helpers";
2
- import { getFunctionRange as k } from "@salty-css/core/compiler/get-function-range";
3
- import { SaltyCompiler as B } from "@salty-css/core/compiler/salty-compiler";
1
+ import { isSaltyFile as S, resolveExportValue as A } from "@salty-css/core/compiler/helpers";
2
+ import { getFunctionRange as b } from "@salty-css/core/compiler/get-function-range";
3
+ import { SaltyCompiler as k } from "@salty-css/core/compiler/salty-compiler";
4
4
  import { checkShouldRestart as O } from "@salty-css/core/server";
5
5
  import { toHash as j } from "@salty-css/core/util";
6
- import { readFile as C, mkdir as H, writeFile as L } from "fs/promises";
7
- import { join as _ } from "path";
8
- const T = (J) => {
9
- const c = new B(J);
6
+ import { readFile as v, mkdir as B, writeFile as G } from "fs/promises";
7
+ import { join as x } from "path";
8
+ const K = (J) => {
9
+ const l = new k(J);
10
10
  return {
11
11
  name: "stylegen",
12
12
  configureServer(t) {
13
- c.importFile = async (n) => {
14
- const r = Date.now();
15
- return t.ssrLoadModule(`${n}?t=${r}`);
13
+ l.importFile = async (e) => {
14
+ const n = Date.now();
15
+ return t.ssrLoadModule(`${e}?t=${n}`);
16
16
  };
17
17
  },
18
18
  buildStart: async () => {
19
- await c.generateCss();
19
+ await l.generateCss();
20
20
  },
21
- load: async (t) => {
22
- var r, y;
23
- if (E(t)) {
24
- const m = await c.getDestDir();
21
+ load: async function(t) {
22
+ var n, u;
23
+ if (S(t)) {
24
+ const m = await l.getDestDir();
25
25
  if (/.+\?configFile=(\w+).+/.test(t)) {
26
- const p = new URLSearchParams(t.split("?")[1]).get("configFile");
27
- if (!p) return;
28
- const a = _(m, "astro", p), f = await C(a, "utf-8");
29
- if (!f) return;
26
+ const d = new URLSearchParams(t.split("?")[1]).get("configFile");
27
+ if (!d) return;
28
+ const r = x(m, "astro", d);
29
+ this.addWatchFile(r);
30
+ const h = await v(r, "utf-8");
31
+ if (!h) return;
30
32
  try {
31
- const i = JSON.parse(f), { clientProps: g = {}, classNames: e = "", tagIsComponent: u, tagName: o = "div" } = i, d = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...i.imports || []], I = u ? o : `__r.element || ${JSON.stringify(g.element || o)}`;
33
+ const c = JSON.parse(h), { clientProps: y = {}, classNames: s = "", tagIsComponent: w, tagName: a = "div" } = c, $ = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...c.imports || []], R = w ? a : `__r.element || ${JSON.stringify(y.element || a)}`;
32
34
  return `---
33
- ${d.join(`
35
+ ${$.join(`
34
36
  `)}
35
- const __gp = ${JSON.stringify(g)};
36
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(e)});
37
- const Element = ${I};
37
+ const __gp = ${JSON.stringify(y)};
38
+ const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(s)});
39
+ const Element = ${R};
38
40
  ---
39
41
  <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`;
40
- } catch (i) {
41
- console.error("Error parsing config file:", i);
42
+ } catch (c) {
43
+ console.error("Error parsing config file:", c);
42
44
  return;
43
45
  }
44
46
  }
45
- const S = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], v = [], w = [], $ = await C(t, "utf-8"), P = await c.compileSaltyFile(t, m), x = Object.entries(P.contents);
46
- for (const [s, p] of x) {
47
- const a = await b(p, 1);
48
- if (!a.generator) continue;
49
- if (a.isClassName) {
50
- const F = a.generator._withBuildContext({
51
- callerName: s,
47
+ const p = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], g = [], i = [], F = await v(t, "utf-8"), P = await l.compileSaltyFile(t, m), I = Object.entries(P.contents);
48
+ for (const [o, d] of I) {
49
+ const r = await A(d, 1);
50
+ if (!r.generator) continue;
51
+ if (r.isClassName) {
52
+ const _ = r.generator._withBuildContext({
53
+ callerName: o,
52
54
  isProduction: !1,
53
55
  config: {}
54
56
  });
55
- v.push(`const ${s} = classNameInstance(${JSON.stringify(F.params)});`), w.push(s);
57
+ g.push(`const ${o} = classNameInstance(${JSON.stringify(_.params)});`), i.push(o);
56
58
  continue;
57
59
  }
58
- const [f, i] = await k($, s), g = $.slice(f, i), e = (y = (r = /styled\(([^,]+),/.exec(g)) == null ? void 0 : r.at(1)) == null ? void 0 : y.trim();
59
- if (!e) {
60
- console.warn(`Could not determine tag name for ${s} in ${t}`);
60
+ const [h, c] = await b(F, o), y = F.slice(h, c), s = (u = (n = /styled\(([^,]+),/.exec(y)) == null ? void 0 : n.at(1)) == null ? void 0 : u.trim();
61
+ if (!s) {
62
+ console.warn(`Could not determine tag name for ${o} in ${t}`);
61
63
  continue;
62
64
  }
63
- const u = a.generator._withBuildContext({
64
- callerName: s,
65
+ const w = r.generator._withBuildContext({
66
+ callerName: o,
65
67
  isProduction: !1,
66
68
  config: {}
67
- }), o = {
68
- componentName: s,
69
- tagName: e.replace(/['"`]/g, ""),
69
+ }), a = {
70
+ componentName: o,
71
+ tagName: s.replace(/['"`]/g, ""),
70
72
  tagIsComponent: !1,
71
- classNames: u.classNames,
73
+ classNames: w.classNames,
72
74
  imports: [],
73
- clientProps: u.clientProps
74
- }, h = /^\w+$/.test(e);
75
- if (o.tagIsComponent = h, h) {
76
- const F = x.some(([l]) => l === e), R = $.match(new RegExp(`import[^;]*${e}[^;]*;`));
77
- if (F) {
78
- const l = j(e), A = `import ${e} from '${t}.astro?configFile=${l}.config';`;
79
- o.imports = [A];
80
- } else if (R) {
81
- const l = R.at(0);
82
- o.imports = [l];
75
+ clientProps: w.clientProps
76
+ }, N = /^\w+$/.test(s);
77
+ if (a.tagIsComponent = N, N) {
78
+ const _ = I.some(([f]) => f === s), E = F.match(new RegExp(`import[^;]*${s}[^;]*;`));
79
+ if (_) {
80
+ const f = j(s), M = `import ${s} from '${t}.astro?configFile=${f}.config';`;
81
+ a.imports = [M];
82
+ } else if (E) {
83
+ const f = E.at(0);
84
+ a.imports = [f];
83
85
  }
84
86
  }
85
- const d = _(m, "astro");
86
- await C(d, "utf-8").catch(() => !1) || await H(d, { recursive: !0 });
87
- const N = j(s), D = _(m, "astro", `${N}.config`);
88
- await L(D, JSON.stringify(o)), S.push(`import ${s} from '${t}.astro?configFile=${N}.config';`), w.push(s);
87
+ const $ = x(m, "astro");
88
+ await v($, "utf-8").catch(() => !1) || await B($, { recursive: !0 });
89
+ const C = j(o), D = x(m, "astro", `${C}.config`);
90
+ await G(D, JSON.stringify(a)), p.push(`import ${o} from '${t}.astro?configFile=${C}.config';`), i.push(o);
89
91
  }
90
- return `${S.join(`
92
+ return `${p.join(`
91
93
  `)}
92
- ${v.join(`
94
+ ${g.join(`
93
95
  `)}
94
- export { ${w.join(", ")} };`;
96
+ export { ${i.join(", ")} };`;
95
97
  }
96
98
  },
97
- handleHotUpdate: async ({ file: t, server: n }) => {
98
- await O(t) && n.restart();
99
+ handleHotUpdate: async ({ file: t, server: e, modules: n }) => {
100
+ if (await O(t)) return e.restart();
101
+ if (!S(t)) return;
102
+ const p = [];
103
+ for (const [g, i] of e.moduleGraph.idToModuleMap)
104
+ g.startsWith(t + ".astro?configFile=") && (e.moduleGraph.invalidateModule(i), p.push(i));
105
+ return [...n, ...p];
99
106
  },
100
107
  watchChange: {
101
- handler: async (t, n) => {
102
- E(t) && n.event !== "delete" && (await O(t) || await c.generateFile(t));
108
+ handler: async (t, e) => {
109
+ S(t) && e.event !== "delete" && (await O(t) || await l.generateFile(t));
103
110
  }
104
111
  }
105
112
  };
106
113
  };
107
114
  export {
108
- T as default,
109
- T as saltyPlugin
115
+ K as default,
116
+ K as saltyPlugin
110
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/astro",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -78,7 +78,7 @@
78
78
  }
79
79
  },
80
80
  "dependencies": {
81
- "@salty-css/core": "^0.1.0-alpha.7",
81
+ "@salty-css/core": "^0.1.0-alpha.9",
82
82
  "astro": "^5.13.2",
83
83
  "vite": "^6.3.5"
84
84
  }