@salty-css/astro 0.0.1-alpha.303 → 0.0.1-alpha.304

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