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