@salty-css/astro 0.0.1-alpha.315 → 0.0.1-alpha.317

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,7 +1,10 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C=require("@salty-css/core/compiler/helpers"),D=require("@salty-css/core/compiler/get-function-range"),b=require("@salty-css/core/compiler/as-class"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),s=require("fs/promises"),p=require("path"),N=S=>{const r=new b.SaltyCompiler(S);return{name:"stylegen",configureServer(t){r.importFile=async a=>{const n=Date.now();return t.ssrLoadModule(`${a}?t=${n}`)}},buildStart:async()=>{await r.generateCss()},load:async t=>{var n,d;if(C.isSaltyFile(t)){const i=await r.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const c=new URLSearchParams(t.split("?")[1]).get("configFile");if(!c)return;const l=p.join(i,"astro",c),m=await s.readFile(l,"utf-8");if(!m)return;try{const e=JSON.parse(m);return`---
2
- ${(e.imports||[]).join(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("@salty-css/core/compiler/helpers"),O=require("@salty-css/core/compiler/get-function-range"),_=require("@salty-css/core/compiler/as-class"),S=require("@salty-css/core/server"),k=require("@salty-css/core/util"),i=require("fs/promises"),w=require("path"),x=R=>{const r=new _.SaltyCompiler(R);return{name:"stylegen",configureServer(t){r.importFile=async s=>{const n=Date.now();return t.ssrLoadModule(`${s}?t=${n}`)}},buildStart:async()=>{await r.generateCss()},load:async t=>{var n,p;if(h.isSaltyFile(t)){const c=await r.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const l=new URLSearchParams(t.split("?")[1]).get("configFile");if(!l)return;const a=w.join(c,"astro",l),u=await i.readFile(a,"utf-8");if(!u)return;try{const o=JSON.parse(u);return`---
2
+ ${(o.imports||[]).join(`
3
3
  `)}
4
4
  const { props } = Astro;
5
5
  ---
6
- <${e.tagName} class="${e.classNames}" data-component-name="${e.componentName}" {...props}><slot/></${e.tagName}>`}catch(e){console.error("Error parsing config file:",e);return}}const f=[],w=[],g=await s.readFile(t,"utf-8"),x=await r.compileSaltyFile(t,i);for(const[o,c]of Object.entries(x.contents)){const l=await C.resolveExportValue(c,1);if(!l.generator)continue;const[m,e]=await D.getFunctionRange(g,o),h=g.slice(m,e),u=(d=(n=/styled\(([^,]+),/.exec(h))==null?void 0:n.at(1))==null?void 0:d.trim();if(!u){console.warn(`Could not determine tag name for ${o} in ${t}`);continue}const j=l.generator._withBuildContext({callerName:o,isProduction:!1,config:{}}),y={componentName:o,tagName:u.replace(/['"`]/g,""),classNames:j.classNames,imports:[]};if(/^\w+$/.test(u)){const v=g.match(new RegExp(`import[^;]*${u}[^;]*;`));if(v){const R=v.at(0);y.imports=[R]}}const $=p.join(i,"astro");await s.readFile($,"utf-8").catch(()=>!1)||await s.mkdir($,{recursive:!0});const F=P.toHash(o),q=p.join(i,"astro",`${F}.config`);await s.writeFile(q,JSON.stringify(y)),f.push(`import ${o} from '${t}.astro?configFile=${F}.config';`),w.push(o)}return`${f.join(`
7
- `)}export { ${w.join(", ")} };`}},handleHotUpdate:async({file:t,server:a})=>{await O.checkShouldRestart(t)&&a.restart()}}};exports.default=N;exports.saltyPlugin=N;
6
+ <${o.tagName} class="${o.classNames}" data-component-name="${o.componentName}" {...props}><slot/></${o.tagName}>`}catch(o){console.error("Error parsing config file:",o);return}}const y=[],F=[],d=[],f=await i.readFile(t,"utf-8"),j=await r.compileSaltyFile(t,c);for(const[e,l]of Object.entries(j.contents)){const a=await h.resolveExportValue(l,1);if(!a.generator)continue;if(a.isClassName){const g=a.generator._withBuildContext({callerName:e,isProduction:!1,config:{}});F.push(`const ${e} = '${g.classNames}';`),d.push(e);continue}const[u,o]=await O.getFunctionRange(f,e),$=f.slice(u,o),m=(p=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:p.trim();if(!m){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const q=a.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),C={componentName:e,tagName:m.replace(/['"`]/g,""),classNames:q.classNames,imports:[]};if(/^\w+$/.test(m)){const g=f.match(new RegExp(`import[^;]*${m}[^;]*;`));if(g){const b=g.at(0);C.imports=[b]}}const N=w.join(c,"astro");await i.readFile(N,"utf-8").catch(()=>!1)||await i.mkdir(N,{recursive:!0});const v=k.toHash(e),D=w.join(c,"astro",`${v}.config`);await i.writeFile(D,JSON.stringify(C)),y.push(`import ${e} from '${t}.astro?configFile=${v}.config';`),d.push(e)}return`${y.join(`
7
+ `)}
8
+ ${F.join(`
9
+ `)}
10
+ export { ${d.join(", ")} };`}},handleHotUpdate:async({file:t,server:s})=>{await S.checkShouldRestart(t)&&s.restart()},watchChange:{handler:async(t,s)=>{h.isSaltyFile(t)&&s.event!=="delete"&&(await S.checkShouldRestart(t)||await r.generateFile(t))}}}};exports.default=x;exports.saltyPlugin=x;
@@ -1,86 +1,103 @@
1
- import { isSaltyFile as j, resolveExportValue as D } from "@salty-css/core/compiler/helpers";
2
- import { getFunctionRange as E } from "@salty-css/core/compiler/get-function-range";
3
- import { SaltyCompiler as O } from "@salty-css/core/compiler/as-class";
4
- import { checkShouldRestart as b } from "@salty-css/core/server";
5
- import { toHash as k } from "@salty-css/core/util";
6
- import { readFile as f, mkdir as H, writeFile as J } from "fs/promises";
7
- import { join as g } from "path";
8
- const q = (C) => {
9
- const s = new O(C);
1
+ import { isSaltyFile as x, resolveExportValue as O } 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/as-class";
4
+ import { checkShouldRestart as v } from "@salty-css/core/server";
5
+ import { toHash as B } from "@salty-css/core/util";
6
+ import { readFile as d, mkdir as H, writeFile as J } from "fs/promises";
7
+ import { join as w } from "path";
8
+ const z = (S) => {
9
+ const r = new k(S);
10
10
  return {
11
11
  name: "stylegen",
12
12
  configureServer(t) {
13
- s.importFile = async (r) => {
14
- const n = Date.now();
15
- return t.ssrLoadModule(`${r}?t=${n}`);
13
+ r.importFile = async (n) => {
14
+ const s = Date.now();
15
+ return t.ssrLoadModule(`${n}?t=${s}`);
16
16
  };
17
17
  },
18
18
  buildStart: async () => {
19
- await s.generateCss();
19
+ await r.generateCss();
20
20
  },
21
21
  load: async (t) => {
22
- var n, u;
23
- if (j(t)) {
24
- const a = await s.getDestDir();
22
+ var s, f;
23
+ if (x(t)) {
24
+ const i = await r.getDestDir();
25
25
  if (/.+\?configFile=(\w+).+/.test(t)) {
26
- const i = new URLSearchParams(t.split("?")[1]).get("configFile");
27
- if (!i) return;
28
- const c = g(a, "astro", i), m = await f(c, "utf-8");
29
- if (!m) return;
26
+ const c = new URLSearchParams(t.split("?")[1]).get("configFile");
27
+ if (!c) return;
28
+ const a = w(i, "astro", c), l = await d(a, "utf-8");
29
+ if (!l) return;
30
30
  try {
31
- const o = JSON.parse(m);
31
+ const e = JSON.parse(l);
32
32
  return `---
33
- ${(o.imports || []).join(`
33
+ ${(e.imports || []).join(`
34
34
  `)}
35
35
  const { props } = Astro;
36
36
  ---
37
- <${o.tagName} class="${o.classNames}" data-component-name="${o.componentName}" {...props}><slot/></${o.tagName}>`;
38
- } catch (o) {
39
- console.error("Error parsing config file:", o);
37
+ <${e.tagName} class="${e.classNames}" data-component-name="${e.componentName}" {...props}><slot/></${e.tagName}>`;
38
+ } catch (e) {
39
+ console.error("Error parsing config file:", e);
40
40
  return;
41
41
  }
42
42
  }
43
- const d = [], w = [], p = await f(t, "utf-8"), x = await s.compileSaltyFile(t, a);
44
- for (const [e, i] of Object.entries(x.contents)) {
45
- const c = await D(i, 1);
46
- if (!c.generator) continue;
47
- const [m, o] = await E(p, e), $ = p.slice(m, o), l = (u = (n = /styled\(([^,]+),/.exec($)) == null ? void 0 : n.at(1)) == null ? void 0 : u.trim();
48
- if (!l) {
49
- console.warn(`Could not determine tag name for ${e} in ${t}`);
43
+ const h = [], $ = [], g = [], u = await d(t, "utf-8"), R = await r.compileSaltyFile(t, i);
44
+ for (const [o, c] of Object.entries(R.contents)) {
45
+ const a = await O(c, 1);
46
+ if (!a.generator) continue;
47
+ if (a.isClassName) {
48
+ const p = a.generator._withBuildContext({
49
+ callerName: o,
50
+ isProduction: !1,
51
+ config: {}
52
+ });
53
+ $.push(`const ${o} = '${p.classNames}';`), g.push(o);
50
54
  continue;
51
55
  }
52
- const v = c.generator._withBuildContext({
53
- callerName: e,
56
+ const [l, e] = await b(u, o), y = u.slice(l, e), m = (f = (s = /styled\(([^,]+),/.exec(y)) == null ? void 0 : s.at(1)) == null ? void 0 : f.trim();
57
+ if (!m) {
58
+ console.warn(`Could not determine tag name for ${o} in ${t}`);
59
+ continue;
60
+ }
61
+ const j = a.generator._withBuildContext({
62
+ callerName: o,
54
63
  isProduction: !1,
55
64
  config: {}
56
- }), h = {
57
- componentName: e,
58
- tagName: l.replace(/['"`]/g, ""),
59
- classNames: v.classNames,
65
+ }), F = {
66
+ componentName: o,
67
+ tagName: m.replace(/['"`]/g, ""),
68
+ classNames: j.classNames,
60
69
  imports: []
61
70
  };
62
- if (/^\w+$/.test(l)) {
63
- const N = p.match(new RegExp(`import[^;]*${l}[^;]*;`));
64
- if (N) {
65
- const R = N.at(0);
66
- h.imports = [R];
71
+ if (/^\w+$/.test(m)) {
72
+ const p = u.match(new RegExp(`import[^;]*${m}[^;]*;`));
73
+ if (p) {
74
+ const E = p.at(0);
75
+ F.imports = [E];
67
76
  }
68
77
  }
69
- const y = g(a, "astro");
70
- await f(y, "utf-8").catch(() => !1) || await H(y, { recursive: !0 });
71
- const F = k(e), S = g(a, "astro", `${F}.config`);
72
- await J(S, JSON.stringify(h)), d.push(`import ${e} from '${t}.astro?configFile=${F}.config';`), w.push(e);
78
+ const N = w(i, "astro");
79
+ await d(N, "utf-8").catch(() => !1) || await H(N, { recursive: !0 });
80
+ const C = B(o), D = w(i, "astro", `${C}.config`);
81
+ await J(D, JSON.stringify(F)), h.push(`import ${o} from '${t}.astro?configFile=${C}.config';`), g.push(o);
73
82
  }
74
- return `${d.join(`
75
- `)}export { ${w.join(", ")} };`;
83
+ return `${h.join(`
84
+ `)}
85
+ ${$.join(`
86
+ `)}
87
+ export { ${g.join(", ")} };`;
76
88
  }
77
89
  },
78
- handleHotUpdate: async ({ file: t, server: r }) => {
79
- await b(t) && r.restart();
90
+ handleHotUpdate: async ({ file: t, server: n }) => {
91
+ await v(t) && n.restart();
92
+ },
93
+ watchChange: {
94
+ handler: async (t, n) => {
95
+ x(t) && n.event !== "delete" && (await v(t) || await r.generateFile(t));
96
+ }
80
97
  }
81
98
  };
82
99
  };
83
100
  export {
84
- q as default,
85
- q as saltyPlugin
101
+ z as default,
102
+ z as saltyPlugin
86
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/astro",
3
- "version": "0.0.1-alpha.315",
3
+ "version": "0.0.1-alpha.317",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -66,7 +66,7 @@
66
66
  }
67
67
  },
68
68
  "dependencies": {
69
- "@salty-css/core": "^0.0.1-alpha.315",
69
+ "@salty-css/core": "^0.0.1-alpha.317",
70
70
  "astro": "^5.13.2",
71
71
  "vite": "^6.3.5"
72
72
  }