@salty-css/astro 0.1.0-alpha.6 → 0.1.0-alpha.8

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 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 r=>{const i=Date.now();return t.ssrLoadModule(`${r}?t=${i}`)}},buildStart:async()=>{await c.generateCss()},load:async function(t){var i,y;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 o=_.join(u,"astro",p);this.addWatchFile(o);const g=await m.readFile(o,"utf-8");if(!g)return;try{const a=JSON.parse(g),{clientProps:f={},classNames:s="",tagIsComponent:d,tagName:n="div"}=a,h=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...a.imports||[]],j=d?n:`__r.element || ${JSON.stringify(f.element||n)}`;return`---
2
+ ${h.join(`
3
3
  `)}
4
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(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 o=await S.resolveExportValue(p,1);if(!o.generator)continue;if(o.isClassName){const C=o.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=(y=(i=/styled\(([^,]+),/.exec(f))==null?void 0:i.at(1))==null?void 0:y.trim();if(!s){console.warn(`Could not determine tag name for ${e} in ${t}`);continue}const d=o.generator._withBuildContext({callerName:e,isProduction:!1,config:{}}),n={componentName:e,tagName:s.replace(/['"`]/g,""),tagIsComponent:!1,classNames:d.classNames,imports:[],clientProps:d.clientProps},F=/^\w+$/.test(s);if(n.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';`;n.imports=[b]}else if(I){const l=I.at(0);n.imports=[l]}}const h=_.join(u,"astro");await m.readFile(h,"utf-8").catch(()=>!1)||await m.mkdir(h,{recursive:!0});const N=P.toHash(e),D=_.join(u,"astro",`${N}.config`);await m.writeFile(D,JSON.stringify(n)),v.push(`import ${e} from '${t}.astro?configFile=${N}.config';`),w.push(e)}return`${v.join(`
9
9
  `)}
10
10
  ${x.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 { ${w.join(", ")} };`}},handleHotUpdate:async({file:t,server:r})=>{await O.checkShouldRestart(t)&&r.restart()},watchChange:{handler:async(t,r)=>{S.isSaltyFile(t)&&r.event!=="delete"&&(await O.checkShouldRestart(t)||await c.generateFile(t))}}}};exports.default=q;exports.saltyPlugin=q;
@@ -5,30 +5,32 @@ import { checkShouldRestart as O } from "@salty-css/core/server";
5
5
  import { toHash as j } from "@salty-css/core/util";
6
6
  import { readFile as C, mkdir as H, writeFile as L } from "fs/promises";
7
7
  import { join as _ } from "path";
8
- const T = (J) => {
8
+ const Q = (J) => {
9
9
  const c = new B(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
+ c.importFile = async (r) => {
14
+ const a = Date.now();
15
+ return t.ssrLoadModule(`${r}?t=${a}`);
16
16
  };
17
17
  },
18
18
  buildStart: async () => {
19
19
  await c.generateCss();
20
20
  },
21
- load: async (t) => {
22
- var r, y;
21
+ load: async function(t) {
22
+ var a, y;
23
23
  if (E(t)) {
24
24
  const m = await c.getDestDir();
25
25
  if (/.+\?configFile=(\w+).+/.test(t)) {
26
26
  const p = new URLSearchParams(t.split("?")[1]).get("configFile");
27
27
  if (!p) return;
28
- const a = _(m, "astro", p), f = await C(a, "utf-8");
28
+ const o = _(m, "astro", p);
29
+ this.addWatchFile(o);
30
+ const f = await C(o, "utf-8");
29
31
  if (!f) 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 i = JSON.parse(f), { clientProps: g = {}, classNames: e = "", tagIsComponent: u, tagName: n = "div" } = i, d = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...i.imports || []], I = u ? n : `__r.element || ${JSON.stringify(g.element || n)}`;
32
34
  return `---
33
35
  ${d.join(`
34
36
  `)}
@@ -42,69 +44,69 @@ const T = (J) => {
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);
47
+ const S = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], v = [], h = [], w = await C(t, "utf-8"), P = await c.compileSaltyFile(t, m), x = Object.entries(P.contents);
46
48
  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({
49
+ const o = await b(p, 1);
50
+ if (!o.generator) continue;
51
+ if (o.isClassName) {
52
+ const F = o.generator._withBuildContext({
51
53
  callerName: s,
52
54
  isProduction: !1,
53
55
  config: {}
54
56
  });
55
- v.push(`const ${s} = classNameInstance(${JSON.stringify(F.params)});`), w.push(s);
57
+ v.push(`const ${s} = classNameInstance(${JSON.stringify(F.params)});`), h.push(s);
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();
60
+ const [f, i] = await k(w, s), g = w.slice(f, i), e = (y = (a = /styled\(([^,]+),/.exec(g)) == null ? void 0 : a.at(1)) == null ? void 0 : y.trim();
59
61
  if (!e) {
60
62
  console.warn(`Could not determine tag name for ${s} in ${t}`);
61
63
  continue;
62
64
  }
63
- const u = a.generator._withBuildContext({
65
+ const u = o.generator._withBuildContext({
64
66
  callerName: s,
65
67
  isProduction: !1,
66
68
  config: {}
67
- }), o = {
69
+ }), n = {
68
70
  componentName: s,
69
71
  tagName: e.replace(/['"`]/g, ""),
70
72
  tagIsComponent: !1,
71
73
  classNames: u.classNames,
72
74
  imports: [],
73
75
  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}[^;]*;`));
76
+ }, $ = /^\w+$/.test(e);
77
+ if (n.tagIsComponent = $, $) {
78
+ const F = x.some(([l]) => l === e), R = w.match(new RegExp(`import[^;]*${e}[^;]*;`));
77
79
  if (F) {
78
80
  const l = j(e), A = `import ${e} from '${t}.astro?configFile=${l}.config';`;
79
- o.imports = [A];
81
+ n.imports = [A];
80
82
  } else if (R) {
81
83
  const l = R.at(0);
82
- o.imports = [l];
84
+ n.imports = [l];
83
85
  }
84
86
  }
85
87
  const d = _(m, "astro");
86
88
  await C(d, "utf-8").catch(() => !1) || await H(d, { recursive: !0 });
87
89
  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);
90
+ await L(D, JSON.stringify(n)), S.push(`import ${s} from '${t}.astro?configFile=${N}.config';`), h.push(s);
89
91
  }
90
92
  return `${S.join(`
91
93
  `)}
92
94
  ${v.join(`
93
95
  `)}
94
- export { ${w.join(", ")} };`;
96
+ export { ${h.join(", ")} };`;
95
97
  }
96
98
  },
97
- handleHotUpdate: async ({ file: t, server: n }) => {
98
- await O(t) && n.restart();
99
+ handleHotUpdate: async ({ file: t, server: r }) => {
100
+ await O(t) && r.restart();
99
101
  },
100
102
  watchChange: {
101
- handler: async (t, n) => {
102
- E(t) && n.event !== "delete" && (await O(t) || await c.generateFile(t));
103
+ handler: async (t, r) => {
104
+ E(t) && r.event !== "delete" && (await O(t) || await c.generateFile(t));
103
105
  }
104
106
  }
105
107
  };
106
108
  };
107
109
  export {
108
- T as default,
109
- T as saltyPlugin
110
+ Q as default,
111
+ Q as saltyPlugin
110
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/astro",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.8",
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.6",
81
+ "@salty-css/core": "^0.1.0-alpha.8",
82
82
  "astro": "^5.13.2",
83
83
  "vite": "^6.3.5"
84
84
  }