@salty-css/astro 0.1.0-alpha.8 → 0.1.0-feat-define-font.0

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 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(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const N=require("@salty-css/core/compiler/helpers"),H=require("@salty-css/core/compiler/get-function-range"),b=require("@salty-css/core/compiler/salty-compiler"),j=require("@salty-css/core/server"),I=require("@salty-css/core/util"),f=require("fs/promises"),x=require("path"),M=(D,O={})=>{const n=new b.SaltyCompiler(D,{mode:O.mode});return{name:"stylegen",configureServer:function(t){n.importFile=async e=>{const r=Date.now();return t.ssrLoadModule(`${e}?t=${r}`)}},configResolved:async function(){try{await n.generateCss()}catch(t){throw console.error("Error during initial CSS generation:",t),t}},load:async function(t){var e,r;try{if(N.isSaltyFile(t)){const d=await n.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const y=new URLSearchParams(t.split("?")[1]).get("configFile");if(!y)return;const m=x.join(d,"astro",y),w=await f.readFile(m,"utf-8");if(!w)return;try{const p=JSON.parse(w),{clientProps:F={},classNames:i="",tagIsComponent:$,tagName:a="div"}=p,C=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...p.imports||[]],R=$?a:`__r.element || ${JSON.stringify(F.element||a)}`;return`---
2
+ ${C.join(`
3
3
  `)}
4
- const __gp = ${JSON.stringify(f)};
5
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(s)});
6
- const Element = ${j};
4
+ const __gp = ${JSON.stringify(F)};
5
+ const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(i)});
6
+ const Element = ${R};
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 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(`
8
+ <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(p){console.error("Error parsing config file:",p);return}}const h=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],l=[],s=[],u=await f.readFile(t,"utf-8"),q=await n.compileSaltyFile(t,d),E=Object.entries(q.contents);for(const[o,y]of E){const m=await N.resolveExportValue(y,1);if(!m.generator)continue;if(m.isClassName){const _=m.generator._withBuildContext({callerName:o,isProduction:n.isProduction,config:{}});l.push(`const ${o} = classNameInstance(${JSON.stringify(_.params)});`),s.push(o);continue}const[w,p]=await H.getFunctionRange(u,o),F=u.slice(w,p),i=(r=(e=/styled\(([^,]+),/.exec(F))==null?void 0:e.at(1))==null?void 0:r.trim();if(!i){console.warn(`Could not determine tag name for ${o} in ${t}`);continue}const $=m.generator._withBuildContext({callerName:o,isProduction:n.isProduction,config:{}}),a={componentName:o,tagName:i.replace(/['"`]/g,""),tagIsComponent:!1,classNames:$.classNames,imports:[],clientProps:$.clientProps},S=/^\w+$/.test(i);if(a.tagIsComponent=S,S){const _=E.some(([g])=>g===i),P=u.match(new RegExp(`import[^;]*${i}[^;]*;`));if(_){const g=I.toHash(i),G=`import ${i} from '${t}.astro?configFile=${g}.config';`;a.imports=[G]}else if(P){const g=P.at(0);a.imports=[g]}}const C=x.join(d,"astro");await f.readFile(C,"utf-8").catch(()=>!1)||await f.mkdir(C,{recursive:!0});const v=I.toHash(o),J=x.join(d,"astro",`${v}.config`);await f.writeFile(J,JSON.stringify(a)),h.push(`import ${o} from '${t}.astro?configFile=${v}.config';`),s.push(o)}return`${h.join(`
9
9
  `)}
10
- ${x.join(`
10
+ ${l.join(`
11
11
  `)}
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;
12
+ export { ${s.join(", ")} };`}return}catch(c){console.error("Error during file compilation:",c);return}},handleHotUpdate:async function({file:t,server:e,modules:r}){try{if(await j.checkShouldRestart(t))return await n.generateCss(!1);if(!N.isSaltyFile(t))return;const h=await n.getDestDir(),l=[];for(const[s,u]of e.moduleGraph.idToModuleMap)s.startsWith(t+".astro?configFile=")&&(e.moduleGraph.invalidateModule(u),l.push(u));for(const s of e.moduleGraph.urlToModuleMap.values())s.file&&s.file.startsWith(h)&&(e.moduleGraph.invalidateModule(s),l.push(s));return e.ws.send({type:"update",updates:[]}),[...r,...l]}catch(c){console.error("Error during hot update handling:",c)}},watchChange:{handler:async function(t,e){try{N.isSaltyFile(t)&&e.event!=="delete"&&(await j.checkShouldRestart(t)||await n.generateFile(t))}catch(r){console.error("Error during watch change handling:",r)}}}}};exports.default=M;exports.saltyPlugin=M;
@@ -1,3 +1,10 @@
1
+ import { SaltyCompilerMode } from '@salty-css/core/compiler/salty-compiler';
1
2
  import { PluginOption } from 'vite';
2
- export declare const saltyPlugin: (dir: string) => PluginOption;
3
+ export interface SaltyAstroPluginOptions {
4
+ /**
5
+ * Explicit build mode. Defaults to NODE_ENV-based detection.
6
+ */
7
+ mode?: SaltyCompilerMode;
8
+ }
9
+ export declare const saltyPlugin: (dir: string, options?: SaltyAstroPluginOptions) => PluginOption;
3
10
  export default saltyPlugin;
@@ -1,107 +1,130 @@
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";
4
- import { checkShouldRestart as O } from "@salty-css/core/server";
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 Q = (J) => {
9
- const c = new B(J);
1
+ import { isSaltyFile as S, resolveExportValue as A } from "@salty-css/core/compiler/helpers";
2
+ import { getFunctionRange as H } from "@salty-css/core/compiler/get-function-range";
3
+ import { SaltyCompiler as k } from "@salty-css/core/compiler/salty-compiler";
4
+ import { checkShouldRestart as D } from "@salty-css/core/server";
5
+ import { toHash as P } from "@salty-css/core/util";
6
+ import { readFile as v, mkdir as B, writeFile as L } from "fs/promises";
7
+ import { join as x } from "path";
8
+ const Q = (M, O = {}) => {
9
+ const n = new k(M, { mode: O.mode });
10
10
  return {
11
11
  name: "stylegen",
12
- configureServer(t) {
13
- c.importFile = async (r) => {
14
- const a = Date.now();
15
- return t.ssrLoadModule(`${r}?t=${a}`);
12
+ configureServer: function(t) {
13
+ n.importFile = async (o) => {
14
+ const r = Date.now();
15
+ return t.ssrLoadModule(`${o}?t=${r}`);
16
16
  };
17
17
  },
18
- buildStart: async () => {
19
- await c.generateCss();
18
+ configResolved: async function() {
19
+ try {
20
+ await n.generateCss();
21
+ } catch (t) {
22
+ throw console.error("Error during initial CSS generation:", t), t;
23
+ }
20
24
  },
21
25
  load: async function(t) {
22
- var a, y;
23
- if (E(t)) {
24
- const m = await c.getDestDir();
25
- if (/.+\?configFile=(\w+).+/.test(t)) {
26
- const p = new URLSearchParams(t.split("?")[1]).get("configFile");
27
- if (!p) return;
28
- const o = _(m, "astro", p);
29
- this.addWatchFile(o);
30
- const f = await C(o, "utf-8");
31
- if (!f) return;
32
- try {
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)}`;
34
- return `---
35
- ${d.join(`
26
+ var o, r;
27
+ try {
28
+ if (S(t)) {
29
+ const f = await n.getDestDir();
30
+ if (/.+\?configFile=(\w+).+/.test(t)) {
31
+ const h = new URLSearchParams(t.split("?")[1]).get("configFile");
32
+ if (!h) return;
33
+ const p = x(f, "astro", h), y = await v(p, "utf-8");
34
+ if (!y) return;
35
+ try {
36
+ const u = JSON.parse(y), { clientProps: w = {}, classNames: i = "", tagIsComponent: $, tagName: a = "div" } = u, F = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...u.imports || []], I = $ ? a : `__r.element || ${JSON.stringify(w.element || a)}`;
37
+ return `---
38
+ ${F.join(`
36
39
  `)}
37
- const __gp = ${JSON.stringify(g)};
38
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(e)});
40
+ const __gp = ${JSON.stringify(w)};
41
+ const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(i)});
39
42
  const Element = ${I};
40
43
  ---
41
44
  <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`;
42
- } catch (i) {
43
- console.error("Error parsing config file:", i);
44
- return;
45
+ } catch (u) {
46
+ console.error("Error parsing config file:", u);
47
+ return;
48
+ }
45
49
  }
46
- }
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);
48
- for (const [s, p] of x) {
49
- const o = await b(p, 1);
50
- if (!o.generator) continue;
51
- if (o.isClassName) {
52
- const F = o.generator._withBuildContext({
53
- callerName: s,
54
- isProduction: !1,
50
+ const g = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], l = [], s = [], m = await v(t, "utf-8"), j = await n.compileSaltyFile(t, f), E = Object.entries(j.contents);
51
+ for (const [e, h] of E) {
52
+ const p = await A(h, 1);
53
+ if (!p.generator) continue;
54
+ if (p.isClassName) {
55
+ const _ = p.generator._withBuildContext({
56
+ callerName: e,
57
+ isProduction: n.isProduction,
58
+ config: {}
59
+ });
60
+ l.push(`const ${e} = classNameInstance(${JSON.stringify(_.params)});`), s.push(e);
61
+ continue;
62
+ }
63
+ const [y, u] = await H(m, e), w = m.slice(y, u), i = (r = (o = /styled\(([^,]+),/.exec(w)) == null ? void 0 : o.at(1)) == null ? void 0 : r.trim();
64
+ if (!i) {
65
+ console.warn(`Could not determine tag name for ${e} in ${t}`);
66
+ continue;
67
+ }
68
+ const $ = p.generator._withBuildContext({
69
+ callerName: e,
70
+ isProduction: n.isProduction,
55
71
  config: {}
56
- });
57
- v.push(`const ${s} = classNameInstance(${JSON.stringify(F.params)});`), h.push(s);
58
- continue;
59
- }
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();
61
- if (!e) {
62
- console.warn(`Could not determine tag name for ${s} in ${t}`);
63
- continue;
64
- }
65
- const u = o.generator._withBuildContext({
66
- callerName: s,
67
- isProduction: !1,
68
- config: {}
69
- }), n = {
70
- componentName: s,
71
- tagName: e.replace(/['"`]/g, ""),
72
- tagIsComponent: !1,
73
- classNames: u.classNames,
74
- imports: [],
75
- clientProps: u.clientProps
76
- }, $ = /^\w+$/.test(e);
77
- if (n.tagIsComponent = $, $) {
78
- const F = x.some(([l]) => l === e), R = w.match(new RegExp(`import[^;]*${e}[^;]*;`));
79
- if (F) {
80
- const l = j(e), A = `import ${e} from '${t}.astro?configFile=${l}.config';`;
81
- n.imports = [A];
82
- } else if (R) {
83
- const l = R.at(0);
84
- n.imports = [l];
72
+ }), a = {
73
+ componentName: e,
74
+ tagName: i.replace(/['"`]/g, ""),
75
+ tagIsComponent: !1,
76
+ classNames: $.classNames,
77
+ imports: [],
78
+ clientProps: $.clientProps
79
+ }, N = /^\w+$/.test(i);
80
+ if (a.tagIsComponent = N, N) {
81
+ const _ = E.some(([d]) => d === i), R = m.match(new RegExp(`import[^;]*${i}[^;]*;`));
82
+ if (_) {
83
+ const d = P(i), G = `import ${i} from '${t}.astro?configFile=${d}.config';`;
84
+ a.imports = [G];
85
+ } else if (R) {
86
+ const d = R.at(0);
87
+ a.imports = [d];
88
+ }
85
89
  }
90
+ const F = x(f, "astro");
91
+ await v(F, "utf-8").catch(() => !1) || await B(F, { recursive: !0 });
92
+ const C = P(e), J = x(f, "astro", `${C}.config`);
93
+ await L(J, JSON.stringify(a)), g.push(`import ${e} from '${t}.astro?configFile=${C}.config';`), s.push(e);
86
94
  }
87
- const d = _(m, "astro");
88
- await C(d, "utf-8").catch(() => !1) || await H(d, { recursive: !0 });
89
- const N = j(s), D = _(m, "astro", `${N}.config`);
90
- await L(D, JSON.stringify(n)), S.push(`import ${s} from '${t}.astro?configFile=${N}.config';`), h.push(s);
91
- }
92
- return `${S.join(`
95
+ return `${g.join(`
93
96
  `)}
94
- ${v.join(`
97
+ ${l.join(`
95
98
  `)}
96
- export { ${h.join(", ")} };`;
99
+ export { ${s.join(", ")} };`;
100
+ }
101
+ return;
102
+ } catch (c) {
103
+ console.error("Error during file compilation:", c);
104
+ return;
97
105
  }
98
106
  },
99
- handleHotUpdate: async ({ file: t, server: r }) => {
100
- await O(t) && r.restart();
107
+ handleHotUpdate: async function({ file: t, server: o, modules: r }) {
108
+ try {
109
+ if (await D(t)) return await n.generateCss(!1);
110
+ if (!S(t)) return;
111
+ const g = await n.getDestDir(), l = [];
112
+ for (const [s, m] of o.moduleGraph.idToModuleMap)
113
+ s.startsWith(t + ".astro?configFile=") && (o.moduleGraph.invalidateModule(m), l.push(m));
114
+ for (const s of o.moduleGraph.urlToModuleMap.values())
115
+ s.file && s.file.startsWith(g) && (o.moduleGraph.invalidateModule(s), l.push(s));
116
+ return o.ws.send({ type: "update", updates: [] }), [...r, ...l];
117
+ } catch (c) {
118
+ console.error("Error during hot update handling:", c);
119
+ }
101
120
  },
102
121
  watchChange: {
103
- handler: async (t, r) => {
104
- E(t) && r.event !== "delete" && (await O(t) || await c.generateFile(t));
122
+ handler: async function(t, o) {
123
+ try {
124
+ S(t) && o.event !== "delete" && (await D(t) || await n.generateFile(t));
125
+ } catch (r) {
126
+ console.error("Error during watch change handling:", r);
127
+ }
105
128
  }
106
129
  }
107
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/astro",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.1.0-feat-define-font.0",
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.8",
81
+ "@salty-css/core": "^0.1.0-feat-define-font.0",
82
82
  "astro": "^5.13.2",
83
83
  "vite": "^6.3.5"
84
84
  }