@salty-css/astro 0.1.0-alpha.34 → 0.1.0-alpha.36
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 +8 -8
- package/astro-vite-plugin.js +100 -78
- package/framework-registry.d.ts +12 -0
- package/package.json +10 -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
|
|
2
|
-
${
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const _=require("@salty-css/core/compiler/helpers"),b=require("@salty-css/core/compiler/get-function-range"),A=require("@salty-css/core/compiler/salty-compiler"),O=require("@salty-css/core/server"),P=require("@salty-css/core/util"),F=require("fs/promises"),k=require("path"),L=[{name:"react",importMarkers:[/['"]@salty-css\/react(\/[^'"]*)?['"]/],loadTransform:async s=>{const n="@salty-css/react/transform-salty-file";return(s?await s(n):await import(n)).transformSaltyFile}}],q=new Map,B=(s,n)=>{const l=q.get(s.name);if(l)return l;const e=s.loadTransform(n);return q.set(s.name,e),e},U=s=>{for(const n of L)for(const l of n.importMarkers)if(l.test(s))return n},J=(s,n={})=>{let l;const e=new A.SaltyCompiler(s,{mode:n.mode});return{name:"stylegen",configureServer:function(t){e.importFile=async o=>{const a=Date.now();return l=t.ssrLoadModule,t.ssrLoadModule(`${o}?t=${a}`)}},configResolved:async function(){try{await e.generateCss()}catch(t){throw console.error("Error during initial CSS generation:",t),t}},load:async function(t){var o,a;try{if(_.isSaltyFile(t,[],!t.includes("configFile="))){const h=await e.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const C=new URLSearchParams(t.split("?")[1]).get("configFile");if(!C)return;const f=k.join(h,"astro",C),S=await F.readFile(f,"utf-8");if(!S)return;try{const g=JSON.parse(S),{clientProps:$={},classNames:c="",tagIsComponent:N,tagName:m="div"}=g,v=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...g.imports||[]],I=N?m:`__r.element || ${JSON.stringify($.element||m)}`;return`---
|
|
2
|
+
${v.join(`
|
|
3
3
|
`)}
|
|
4
|
-
const __gp = ${JSON.stringify(
|
|
5
|
-
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(
|
|
6
|
-
const Element = ${
|
|
4
|
+
const __gp = ${JSON.stringify($)};
|
|
5
|
+
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(c)});
|
|
6
|
+
const Element = ${I};
|
|
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(g){console.error("Error parsing config file:",g);return}}const d=await F.readFile(t,"utf-8"),p=U(d);if(p)return await(await B(p,l))(e,t);const i=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],y=[],M=[],T=await e.compileSaltyFile(t,h),j=Object.entries(T.contents);for(const[r,C]of j){const f=await _.resolveExportValue(C,1);if(!f.generator)continue;if(f.isClassName){const E=f.generator._withBuildContext({callerName:r,isProduction:e.isProduction,config:{}});y.push(`const ${r} = classNameInstance(${JSON.stringify(E.params)});`),M.push(r);continue}const[S,g]=await b.getFunctionRange(d,r),$=d.slice(S,g),c=(a=(o=/styled\(([^,]+),/.exec($))==null?void 0:o.at(1))==null?void 0:a.trim();if(!c){console.warn(`Could not determine tag name for ${r} in ${t}`);continue}const N=f.generator._withBuildContext({callerName:r,isProduction:e.isProduction,config:{}}),m={componentName:r,tagName:c.replace(/['"`]/g,""),tagIsComponent:!1,classNames:N.classNames,imports:[],clientProps:N.clientProps},R=/^\w+$/.test(c);if(m.tagIsComponent=R,R){const E=j.some(([w])=>w===c),D=d.match(new RegExp(`import[^;]*${c}[^;]*;`));if(E){const w=P.toHash(c),H=`import ${c} from '${t}.astro?configFile=${w}.config';`;m.imports=[H]}else if(D){const w=D.at(0);m.imports=[w]}}const v=k.join(h,"astro");await F.readFile(v,"utf-8").catch(()=>!1)||await F.mkdir(v,{recursive:!0});const x=P.toHash(r),G=k.join(h,"astro",`${x}.config`);await F.writeFile(G,JSON.stringify(m)),i.push(`import ${r} from '${t}.astro?configFile=${x}.config';`),M.push(r)}return`${i.join(`
|
|
9
9
|
`)}
|
|
10
|
-
${
|
|
10
|
+
${y.join(`
|
|
11
11
|
`)}
|
|
12
|
-
export { ${
|
|
12
|
+
export { ${M.join(", ")} };`}return}catch(u){console.error("Error during file compilation:",u);return}},handleHotUpdate:async function({file:t,server:o,modules:a}){try{if(await O.checkShouldRestart(t))return await e.generateCss(!1);if(!_.isSaltyFile(t))return;const d=await e.getDestDir(),p=[];for(const[i,y]of o.moduleGraph.idToModuleMap)i.startsWith(t+".astro?configFile=")&&(o.moduleGraph.invalidateModule(y),p.push(y));for(const i of o.moduleGraph.urlToModuleMap.values())i.file&&i.file.startsWith(d)&&(o.moduleGraph.invalidateModule(i),p.push(i));return o.ws.send({type:"update",updates:[]}),[...a,...p]}catch(u){console.error("Error during hot update handling:",u)}},watchChange:{handler:async function(t,o){try{_.isSaltyFile(t)&&o.event!=="delete"&&(await O.checkShouldRestart(t)||await e.generateFile(t))}catch(a){console.error("Error during watch change handling:",a)}}}}};exports.default=J;exports.saltyPlugin=J;
|
package/astro-vite-plugin.js
CHANGED
|
@@ -1,135 +1,157 @@
|
|
|
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
|
-
|
|
1
|
+
import { isSaltyFile as M, resolveExportValue as H } from "@salty-css/core/compiler/helpers";
|
|
2
|
+
import { getFunctionRange as L } from "@salty-css/core/compiler/get-function-range";
|
|
3
|
+
import { SaltyCompiler as B } from "@salty-css/core/compiler/salty-compiler";
|
|
4
|
+
import { checkShouldRestart as j } from "@salty-css/core/server";
|
|
5
|
+
import { toHash as J } from "@salty-css/core/util";
|
|
6
|
+
import { readFile as R, mkdir as U, writeFile as W } from "fs/promises";
|
|
7
|
+
import { join as k } from "path";
|
|
8
|
+
const b = [
|
|
9
|
+
{
|
|
10
|
+
name: "react",
|
|
11
|
+
importMarkers: [/['"]@salty-css\/react(\/[^'"]*)?['"]/],
|
|
12
|
+
loadTransform: async (s) => {
|
|
13
|
+
const n = "@salty-css/react/transform-salty-file";
|
|
14
|
+
return (s ? await s(n) : await import(n)).transformSaltyFile;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
], P = /* @__PURE__ */ new Map(), V = (s, n) => {
|
|
18
|
+
const l = P.get(s.name);
|
|
19
|
+
if (l) return l;
|
|
20
|
+
const o = s.loadTransform(n);
|
|
21
|
+
return P.set(s.name, o), o;
|
|
22
|
+
}, q = (s) => {
|
|
23
|
+
for (const n of b)
|
|
24
|
+
for (const l of n.importMarkers)
|
|
25
|
+
if (l.test(s)) return n;
|
|
26
|
+
}, rt = (s, n = {}) => {
|
|
27
|
+
let l;
|
|
28
|
+
const o = new B(s, { mode: n.mode });
|
|
10
29
|
return {
|
|
11
30
|
name: "stylegen",
|
|
12
31
|
configureServer: function(t) {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
return t.ssrLoadModule(`${
|
|
32
|
+
o.importFile = async (r) => {
|
|
33
|
+
const a = Date.now();
|
|
34
|
+
return l = t.ssrLoadModule, t.ssrLoadModule(`${r}?t=${a}`);
|
|
16
35
|
};
|
|
17
36
|
},
|
|
18
37
|
configResolved: async function() {
|
|
19
38
|
try {
|
|
20
|
-
await
|
|
39
|
+
await o.generateCss();
|
|
21
40
|
} catch (t) {
|
|
22
41
|
throw console.error("Error during initial CSS generation:", t), t;
|
|
23
42
|
}
|
|
24
43
|
},
|
|
25
44
|
load: async function(t) {
|
|
26
|
-
var
|
|
45
|
+
var r, a;
|
|
27
46
|
try {
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
47
|
+
if (M(t, [], !t.includes("configFile="))) {
|
|
48
|
+
const h = await o.getDestDir();
|
|
30
49
|
if (/.+\?configFile=(\w+).+/.test(t)) {
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
50
|
+
const F = new URLSearchParams(t.split("?")[1]).get("configFile");
|
|
51
|
+
if (!F) return;
|
|
52
|
+
const d = k(h, "astro", F), $ = await R(d, "utf-8");
|
|
53
|
+
if (!$) return;
|
|
35
54
|
try {
|
|
36
|
-
const
|
|
55
|
+
const g = JSON.parse($), { clientProps: C = {}, classNames: c = "", tagIsComponent: N, tagName: m = "div" } = g, S = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...g.imports || []], D = N ? m : `__r.element || ${JSON.stringify(C.element || m)}`;
|
|
37
56
|
return `---
|
|
38
|
-
${
|
|
57
|
+
${S.join(`
|
|
39
58
|
`)}
|
|
40
|
-
const __gp = ${JSON.stringify(
|
|
41
|
-
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(
|
|
42
|
-
const Element = ${
|
|
59
|
+
const __gp = ${JSON.stringify(C)};
|
|
60
|
+
const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(c)});
|
|
61
|
+
const Element = ${D};
|
|
43
62
|
---
|
|
44
63
|
<Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`;
|
|
45
|
-
} catch (
|
|
46
|
-
console.error("Error parsing config file:",
|
|
64
|
+
} catch (g) {
|
|
65
|
+
console.error("Error parsing config file:", g);
|
|
47
66
|
return;
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
const p = await R(t, "utf-8"), u = q(p);
|
|
70
|
+
if (u)
|
|
71
|
+
return await (await V(u, l))(o, t);
|
|
72
|
+
const i = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], w = [], v = [], G = await o.compileSaltyFile(t, h), I = Object.entries(G.contents);
|
|
73
|
+
for (const [e, F] of I) {
|
|
74
|
+
const d = await H(F, 1);
|
|
75
|
+
if (!d.generator) continue;
|
|
76
|
+
if (d.isClassName) {
|
|
77
|
+
const E = d.generator._withBuildContext({
|
|
56
78
|
callerName: e,
|
|
57
|
-
isProduction:
|
|
79
|
+
isProduction: o.isProduction,
|
|
58
80
|
config: {}
|
|
59
81
|
});
|
|
60
|
-
|
|
82
|
+
w.push(`const ${e} = classNameInstance(${JSON.stringify(E.params)});`), v.push(e);
|
|
61
83
|
continue;
|
|
62
84
|
}
|
|
63
|
-
const [
|
|
64
|
-
if (!
|
|
85
|
+
const [$, g] = await L(p, e), C = p.slice($, g), c = (a = (r = /styled\(([^,]+),/.exec(C)) == null ? void 0 : r.at(1)) == null ? void 0 : a.trim();
|
|
86
|
+
if (!c) {
|
|
65
87
|
console.warn(`Could not determine tag name for ${e} in ${t}`);
|
|
66
88
|
continue;
|
|
67
89
|
}
|
|
68
|
-
const
|
|
90
|
+
const N = d.generator._withBuildContext({
|
|
69
91
|
callerName: e,
|
|
70
|
-
isProduction:
|
|
92
|
+
isProduction: o.isProduction,
|
|
71
93
|
config: {}
|
|
72
|
-
}),
|
|
94
|
+
}), m = {
|
|
73
95
|
componentName: e,
|
|
74
|
-
tagName:
|
|
96
|
+
tagName: c.replace(/['"`]/g, ""),
|
|
75
97
|
tagIsComponent: !1,
|
|
76
|
-
classNames:
|
|
98
|
+
classNames: N.classNames,
|
|
77
99
|
imports: [],
|
|
78
|
-
clientProps:
|
|
79
|
-
},
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
} else if (
|
|
86
|
-
const
|
|
87
|
-
|
|
100
|
+
clientProps: N.clientProps
|
|
101
|
+
}, _ = /^\w+$/.test(c);
|
|
102
|
+
if (m.tagIsComponent = _, _) {
|
|
103
|
+
const E = I.some(([y]) => y === c), O = p.match(new RegExp(`import[^;]*${c}[^;]*;`));
|
|
104
|
+
if (E) {
|
|
105
|
+
const y = J(c), A = `import ${c} from '${t}.astro?configFile=${y}.config';`;
|
|
106
|
+
m.imports = [A];
|
|
107
|
+
} else if (O) {
|
|
108
|
+
const y = O.at(0);
|
|
109
|
+
m.imports = [y];
|
|
88
110
|
}
|
|
89
111
|
}
|
|
90
|
-
const
|
|
91
|
-
await
|
|
92
|
-
const
|
|
93
|
-
await
|
|
112
|
+
const S = k(h, "astro");
|
|
113
|
+
await R(S, "utf-8").catch(() => !1) || await U(S, { recursive: !0 });
|
|
114
|
+
const x = J(e), T = k(h, "astro", `${x}.config`);
|
|
115
|
+
await W(T, JSON.stringify(m)), i.push(`import ${e} from '${t}.astro?configFile=${x}.config';`), v.push(e);
|
|
94
116
|
}
|
|
95
|
-
return `${
|
|
117
|
+
return `${i.join(`
|
|
96
118
|
`)}
|
|
97
|
-
${
|
|
119
|
+
${w.join(`
|
|
98
120
|
`)}
|
|
99
|
-
export { ${
|
|
121
|
+
export { ${v.join(", ")} };`;
|
|
100
122
|
}
|
|
101
123
|
return;
|
|
102
|
-
} catch (
|
|
103
|
-
console.error("Error during file compilation:",
|
|
124
|
+
} catch (f) {
|
|
125
|
+
console.error("Error during file compilation:", f);
|
|
104
126
|
return;
|
|
105
127
|
}
|
|
106
128
|
},
|
|
107
|
-
handleHotUpdate: async function({ file: t, server:
|
|
129
|
+
handleHotUpdate: async function({ file: t, server: r, modules: a }) {
|
|
108
130
|
try {
|
|
109
|
-
if (await
|
|
110
|
-
if (!
|
|
111
|
-
const
|
|
112
|
-
for (const [
|
|
113
|
-
|
|
114
|
-
for (const
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
} catch (
|
|
118
|
-
console.error("Error during hot update handling:",
|
|
131
|
+
if (await j(t)) return await o.generateCss(!1);
|
|
132
|
+
if (!M(t)) return;
|
|
133
|
+
const p = await o.getDestDir(), u = [];
|
|
134
|
+
for (const [i, w] of r.moduleGraph.idToModuleMap)
|
|
135
|
+
i.startsWith(t + ".astro?configFile=") && (r.moduleGraph.invalidateModule(w), u.push(w));
|
|
136
|
+
for (const i of r.moduleGraph.urlToModuleMap.values())
|
|
137
|
+
i.file && i.file.startsWith(p) && (r.moduleGraph.invalidateModule(i), u.push(i));
|
|
138
|
+
return r.ws.send({ type: "update", updates: [] }), [...a, ...u];
|
|
139
|
+
} catch (f) {
|
|
140
|
+
console.error("Error during hot update handling:", f);
|
|
119
141
|
}
|
|
120
142
|
},
|
|
121
143
|
watchChange: {
|
|
122
|
-
handler: async function(t,
|
|
144
|
+
handler: async function(t, r) {
|
|
123
145
|
try {
|
|
124
|
-
|
|
125
|
-
} catch (
|
|
126
|
-
console.error("Error during watch change handling:",
|
|
146
|
+
M(t) && r.event !== "delete" && (await j(t) || await o.generateFile(t));
|
|
147
|
+
} catch (a) {
|
|
148
|
+
console.error("Error during watch change handling:", a);
|
|
127
149
|
}
|
|
128
150
|
}
|
|
129
151
|
}
|
|
130
152
|
};
|
|
131
153
|
};
|
|
132
154
|
export {
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
rt as default,
|
|
156
|
+
rt as saltyPlugin
|
|
135
157
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SaltyCompiler } from '@salty-css/core/compiler/salty-compiler';
|
|
2
|
+
type Importer = undefined | ((path: string) => Promise<any>);
|
|
3
|
+
export type SaltyFileTransform = (compiler: SaltyCompiler, file: string) => Promise<string | undefined>;
|
|
4
|
+
export interface FrameworkEntry {
|
|
5
|
+
name: string;
|
|
6
|
+
importMarkers: RegExp[];
|
|
7
|
+
loadTransform: (importer: Importer) => Promise<SaltyFileTransform>;
|
|
8
|
+
}
|
|
9
|
+
export declare const frameworkRegistry: FrameworkEntry[];
|
|
10
|
+
export declare const getFrameworkTransform: (entry: FrameworkEntry, importer: Importer) => Promise<SaltyFileTransform>;
|
|
11
|
+
export declare const detectFramework: (source: string) => FrameworkEntry | undefined;
|
|
12
|
+
export {};
|
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.36",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -74,8 +74,16 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@salty-css/core": "0.1.0-alpha.
|
|
77
|
+
"@salty-css/core": "0.1.0-alpha.36",
|
|
78
78
|
"astro": "^5.13.2",
|
|
79
79
|
"vite": "^6.3.5"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"@salty-css/react": "0.1.0-alpha.36"
|
|
83
|
+
},
|
|
84
|
+
"peerDependenciesMeta": {
|
|
85
|
+
"@salty-css/react": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
80
88
|
}
|
|
81
89
|
}
|