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