@salty-css/astro 0.0.1-alpha.319 → 0.0.1-alpha.321
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 +16 -16
- 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"),
|
|
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"),f=require("fs/promises"),x=require("path"),b=D=>{const m=new J.SaltyCompiler(D);return{name:"stylegen",configureServer(t){m.importFile=async r=>{const a=Date.now();return t.ssrLoadModule(`${r}?t=${a}`)}},buildStart:async()=>{await m.generateCss()},load:async t=>{var a,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 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(c){console.error("Error parsing config file:",c);return}}const R=[],q=[],C=[],
|
|
7
|
+
<Element class:list={["${s}", props.class]} ${l} {...props}><slot/></Element>`}catch(c){console.error("Error parsing config file:",c);return}}const R=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],q=[],C=[],N=await f.readFile(t,"utf-8"),k=await m.compileSaltyFile(t,d),I=Object.entries(k.contents);for(const[e,h]of I){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} = classNameInstance(${JSON.stringify(p.params)});`),C.push(e);continue}const[$,c]=await H.getFunctionRange(N,e),o=N.slice($,c),s=(F=(a=/styled\(([^,]+),/.exec(o))==null?void 0:a.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:{}}),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=I.some(([g])=>g===s),E=N.match(new RegExp(`import[^;]*${s}[^;]*;`));if(p){const g=P.toHash(s),_=`import ${s} from '${t}.astro?configFile=${g}.config';`;n.imports=[_]}else if(E){const g=E.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 v=P.toHash(e),S=x.join(d,"astro",`${v}.config`);await f.writeFile(S,JSON.stringify(n)),R.push(`import ${e} from '${t}.astro?configFile=${v}.config';`),C.push(e)}return`${R.join(`
|
|
8
8
|
`)}
|
|
9
9
|
${q.join(`
|
|
10
10
|
`)}
|
|
11
|
-
export { ${C.join(", ")} };`}},handleHotUpdate:async({file:t,server:r})=>{await
|
|
11
|
+
export { ${C.join(", ")} };`}},handleHotUpdate:async({file:t,server:r})=>{await O.checkShouldRestart(t)&&r.restart()},watchChange:{handler:async(t,r)=>{j.isSaltyFile(t)&&r.event!=="delete"&&(await O.checkShouldRestart(t)||await m.generateFile(t))}}}};exports.default=b;exports.saltyPlugin=b;
|
package/astro-vite-plugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { isSaltyFile as
|
|
2
|
-
import { getFunctionRange as
|
|
3
|
-
import { SaltyCompiler as
|
|
1
|
+
import { isSaltyFile as D, resolveExportValue as A } from "@salty-css/core/compiler/helpers";
|
|
2
|
+
import { getFunctionRange as B } from "@salty-css/core/compiler/get-function-range";
|
|
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
6
|
import { readFile as x, mkdir as L, writeFile as U } from "fs/promises";
|
|
7
7
|
import { join as S } from "path";
|
|
8
8
|
const T = (b) => {
|
|
9
|
-
const m = new
|
|
9
|
+
const m = new H(b);
|
|
10
10
|
return {
|
|
11
11
|
name: "stylegen",
|
|
12
12
|
configureServer(t) {
|
|
@@ -20,7 +20,7 @@ const T = (b) => {
|
|
|
20
20
|
},
|
|
21
21
|
load: async (t) => {
|
|
22
22
|
var a, y;
|
|
23
|
-
if (
|
|
23
|
+
if (D(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");
|
|
@@ -43,9 +43,9 @@ const T = (b) => {
|
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
const R = [], j = [], F = [], C = await x(t, "utf-8"), k = await m.compileSaltyFile(t, u),
|
|
47
|
-
for (const [e, d] of
|
|
48
|
-
const i = await
|
|
46
|
+
const R = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], j = [], F = [], C = await x(t, "utf-8"), k = await m.compileSaltyFile(t, u), I = Object.entries(k.contents);
|
|
47
|
+
for (const [e, d] of I) {
|
|
48
|
+
const i = await A(d, 1);
|
|
49
49
|
if (!i.generator) continue;
|
|
50
50
|
if (i.isClassName) {
|
|
51
51
|
const f = i.generator._withBuildContext({
|
|
@@ -53,10 +53,10 @@ const T = (b) => {
|
|
|
53
53
|
isProduction: !1,
|
|
54
54
|
config: {}
|
|
55
55
|
});
|
|
56
|
-
j.push(`const ${e} =
|
|
56
|
+
j.push(`const ${e} = classNameInstance(${JSON.stringify(f.params)});`), F.push(e);
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
|
-
const [$, c] = await
|
|
59
|
+
const [$, c] = await B(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;
|
|
@@ -74,12 +74,12 @@ const T = (b) => {
|
|
|
74
74
|
clientProps: p.clientProps
|
|
75
75
|
}, w = /^\w+$/.test(o);
|
|
76
76
|
if (n.tagIsComponent = w, w) {
|
|
77
|
-
const f =
|
|
77
|
+
const f = I.some(([g]) => g === o), E = C.match(new RegExp(`import[^;]*${o}[^;]*;`));
|
|
78
78
|
if (f) {
|
|
79
|
-
const g = P(o),
|
|
80
|
-
n.imports = [
|
|
81
|
-
} else if (
|
|
82
|
-
const g =
|
|
79
|
+
const g = P(o), J = `import ${o} from '${t}.astro?configFile=${g}.config';`;
|
|
80
|
+
n.imports = [J];
|
|
81
|
+
} else if (E) {
|
|
82
|
+
const g = E.at(0);
|
|
83
83
|
n.imports = [g];
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -100,7 +100,7 @@ export { ${F.join(", ")} };`;
|
|
|
100
100
|
},
|
|
101
101
|
watchChange: {
|
|
102
102
|
handler: async (t, r) => {
|
|
103
|
-
|
|
103
|
+
D(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.321",
|
|
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.321",
|
|
70
70
|
"astro": "^5.13.2",
|
|
71
71
|
"vite": "^6.3.5"
|
|
72
72
|
}
|