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