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