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