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

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