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