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