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