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

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 +84 -68
  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 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=[],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 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,80 +1,96 @@
1
- import { generateCss as D, 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 { checkShouldRestart as C } from "@salty-css/core/server";
5
- import { toHash as J } from "@salty-css/core/util";
6
- import { readFile as g, mkdir as U, writeFile as A } from "fs/promises";
7
- 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 `---
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
+ return {
12
+ name: "stylegen",
13
+ configureServer(t) {
14
+ l.importFile = async (s) => {
15
+ const n = Date.now();
16
+ return t.ssrLoadModule(`${s}?t=${n}`);
17
+ };
18
+ },
19
+ buildStart: async () => {
20
+ await l.generateCss();
21
+ },
22
+ load: async (t) => {
23
+ var n, d;
24
+ if (j(t)) {
25
+ const r = await D(u);
26
+ if (/.+\?configFile=(\w+).+/.test(t)) {
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
+ try {
32
+ const o = JSON.parse(c);
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 = [], $ = [], 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
+ console.warn(`Could not determine tag name for ${e} in ${t}`);
51
+ continue;
57
52
  }
53
+ const v = i.generator._withBuildContext({
54
+ callerName: e,
55
+ isProduction: !1,
56
+ config: {}
57
+ }), y = {
58
+ componentName: e,
59
+ tagName: m.replace(/['"`]/g, ""),
60
+ classNames: v.classNames,
61
+ imports: []
62
+ };
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
+ }
69
+ }
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);
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 { ${$.join(", ")} };`;
63
77
  }
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));
78
+ },
79
+ handleHotUpdate: async ({ file: t, server: s }) => {
80
+ await k(t) && s.restart();
74
81
  }
75
- }
76
- });
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
+ // },
91
+ };
92
+ };
77
93
  export {
78
- M as default,
79
- M as saltyPlugin
94
+ G as default,
95
+ G as saltyPlugin
80
96
  };
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.305",
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.305",
46
46
  "vite": "^6.3.5"
47
47
  }
48
48
  }