@salty-css/astro 0.0.1-alpha.309 → 0.0.1-alpha.311

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