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