@salty-css/astro 0.1.0-alpha.35 → 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.
@@ -1,12 +1,12 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const N=require("@salty-css/core/compiler/helpers"),H=require("@salty-css/core/compiler/get-function-range"),b=require("@salty-css/core/compiler/salty-compiler"),j=require("@salty-css/core/server"),I=require("@salty-css/core/util"),f=require("fs/promises"),x=require("path"),M=(D,O={})=>{const n=new b.SaltyCompiler(D,{mode:O.mode});return{name:"stylegen",configureServer:function(t){n.importFile=async e=>{const r=Date.now();return t.ssrLoadModule(`${e}?t=${r}`)}},configResolved:async function(){try{await n.generateCss()}catch(t){throw console.error("Error during initial CSS generation:",t),t}},load:async function(t){var e,r;try{if(N.isSaltyFile(t)){const d=await n.getDestDir();if(/.+\?configFile=(\w+).+/.test(t)){const y=new URLSearchParams(t.split("?")[1]).get("configFile");if(!y)return;const m=x.join(d,"astro",y),w=await f.readFile(m,"utf-8");if(!w)return;try{const p=JSON.parse(w),{clientProps:F={},classNames:i="",tagIsComponent:$,tagName:a="div"}=p,C=["import { resolveAstroProps } from '@salty-css/astro/element-props';",...p.imports||[]],R=$?a:`__r.element || ${JSON.stringify(F.element||a)}`;return`---
2
- ${C.join(`
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(F)};
5
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(i)});
6
- const Element = ${R};
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(p){console.error("Error parsing config file:",p);return}}const h=["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"],l=[],s=[],u=await f.readFile(t,"utf-8"),q=await n.compileSaltyFile(t,d),E=Object.entries(q.contents);for(const[o,y]of E){const m=await N.resolveExportValue(y,1);if(!m.generator)continue;if(m.isClassName){const _=m.generator._withBuildContext({callerName:o,isProduction:n.isProduction,config:{}});l.push(`const ${o} = classNameInstance(${JSON.stringify(_.params)});`),s.push(o);continue}const[w,p]=await H.getFunctionRange(u,o),F=u.slice(w,p),i=(r=(e=/styled\(([^,]+),/.exec(F))==null?void 0:e.at(1))==null?void 0:r.trim();if(!i){console.warn(`Could not determine tag name for ${o} in ${t}`);continue}const $=m.generator._withBuildContext({callerName:o,isProduction:n.isProduction,config:{}}),a={componentName:o,tagName:i.replace(/['"`]/g,""),tagIsComponent:!1,classNames:$.classNames,imports:[],clientProps:$.clientProps},S=/^\w+$/.test(i);if(a.tagIsComponent=S,S){const _=E.some(([g])=>g===i),P=u.match(new RegExp(`import[^;]*${i}[^;]*;`));if(_){const g=I.toHash(i),G=`import ${i} from '${t}.astro?configFile=${g}.config';`;a.imports=[G]}else if(P){const g=P.at(0);a.imports=[g]}}const C=x.join(d,"astro");await f.readFile(C,"utf-8").catch(()=>!1)||await f.mkdir(C,{recursive:!0});const v=I.toHash(o),J=x.join(d,"astro",`${v}.config`);await f.writeFile(J,JSON.stringify(a)),h.push(`import ${o} from '${t}.astro?configFile=${v}.config';`),s.push(o)}return`${h.join(`
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
- ${l.join(`
10
+ ${y.join(`
11
11
  `)}
12
- export { ${s.join(", ")} };`}return}catch(c){console.error("Error during file compilation:",c);return}},handleHotUpdate:async function({file:t,server:e,modules:r}){try{if(await j.checkShouldRestart(t))return await n.generateCss(!1);if(!N.isSaltyFile(t))return;const h=await n.getDestDir(),l=[];for(const[s,u]of e.moduleGraph.idToModuleMap)s.startsWith(t+".astro?configFile=")&&(e.moduleGraph.invalidateModule(u),l.push(u));for(const s of e.moduleGraph.urlToModuleMap.values())s.file&&s.file.startsWith(h)&&(e.moduleGraph.invalidateModule(s),l.push(s));return e.ws.send({type:"update",updates:[]}),[...r,...l]}catch(c){console.error("Error during hot update handling:",c)}},watchChange:{handler:async function(t,e){try{N.isSaltyFile(t)&&e.event!=="delete"&&(await j.checkShouldRestart(t)||await n.generateFile(t))}catch(r){console.error("Error during watch change handling:",r)}}}}};exports.default=M;exports.saltyPlugin=M;
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;
@@ -1,135 +1,157 @@
1
- import { isSaltyFile as S, resolveExportValue as A } from "@salty-css/core/compiler/helpers";
2
- import { getFunctionRange as H } from "@salty-css/core/compiler/get-function-range";
3
- import { SaltyCompiler as k } from "@salty-css/core/compiler/salty-compiler";
4
- import { checkShouldRestart as D } from "@salty-css/core/server";
5
- import { toHash as P } from "@salty-css/core/util";
6
- import { readFile as v, mkdir as B, writeFile as L } from "fs/promises";
7
- import { join as x } from "path";
8
- const Q = (M, O = {}) => {
9
- const n = new k(M, { mode: O.mode });
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
- n.importFile = async (o) => {
14
- const r = Date.now();
15
- return t.ssrLoadModule(`${o}?t=${r}`);
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 n.generateCss();
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 o, r;
45
+ var r, a;
27
46
  try {
28
- if (S(t)) {
29
- const f = await n.getDestDir();
47
+ if (M(t, [], !t.includes("configFile="))) {
48
+ const h = await o.getDestDir();
30
49
  if (/.+\?configFile=(\w+).+/.test(t)) {
31
- const h = new URLSearchParams(t.split("?")[1]).get("configFile");
32
- if (!h) return;
33
- const p = x(f, "astro", h), y = await v(p, "utf-8");
34
- if (!y) return;
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 u = JSON.parse(y), { clientProps: w = {}, classNames: i = "", tagIsComponent: $, tagName: a = "div" } = u, F = ["import { resolveAstroProps } from '@salty-css/astro/element-props';", ...u.imports || []], I = $ ? a : `__r.element || ${JSON.stringify(w.element || a)}`;
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
- ${F.join(`
57
+ ${S.join(`
39
58
  `)}
40
- const __gp = ${JSON.stringify(w)};
41
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(i)});
42
- const Element = ${I};
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 (u) {
46
- console.error("Error parsing config file:", u);
64
+ } catch (g) {
65
+ console.error("Error parsing config file:", g);
47
66
  return;
48
67
  }
49
68
  }
50
- const g = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], l = [], s = [], m = await v(t, "utf-8"), j = await n.compileSaltyFile(t, f), E = Object.entries(j.contents);
51
- for (const [e, h] of E) {
52
- const p = await A(h, 1);
53
- if (!p.generator) continue;
54
- if (p.isClassName) {
55
- const _ = p.generator._withBuildContext({
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: n.isProduction,
79
+ isProduction: o.isProduction,
58
80
  config: {}
59
81
  });
60
- l.push(`const ${e} = classNameInstance(${JSON.stringify(_.params)});`), s.push(e);
82
+ w.push(`const ${e} = classNameInstance(${JSON.stringify(E.params)});`), v.push(e);
61
83
  continue;
62
84
  }
63
- const [y, u] = await H(m, e), w = m.slice(y, u), i = (r = (o = /styled\(([^,]+),/.exec(w)) == null ? void 0 : o.at(1)) == null ? void 0 : r.trim();
64
- if (!i) {
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 $ = p.generator._withBuildContext({
90
+ const N = d.generator._withBuildContext({
69
91
  callerName: e,
70
- isProduction: n.isProduction,
92
+ isProduction: o.isProduction,
71
93
  config: {}
72
- }), a = {
94
+ }), m = {
73
95
  componentName: e,
74
- tagName: i.replace(/['"`]/g, ""),
96
+ tagName: c.replace(/['"`]/g, ""),
75
97
  tagIsComponent: !1,
76
- classNames: $.classNames,
98
+ classNames: N.classNames,
77
99
  imports: [],
78
- clientProps: $.clientProps
79
- }, N = /^\w+$/.test(i);
80
- if (a.tagIsComponent = N, N) {
81
- const _ = E.some(([d]) => d === i), R = m.match(new RegExp(`import[^;]*${i}[^;]*;`));
82
- if (_) {
83
- const d = P(i), G = `import ${i} from '${t}.astro?configFile=${d}.config';`;
84
- a.imports = [G];
85
- } else if (R) {
86
- const d = R.at(0);
87
- a.imports = [d];
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 F = x(f, "astro");
91
- await v(F, "utf-8").catch(() => !1) || await B(F, { recursive: !0 });
92
- const C = P(e), J = x(f, "astro", `${C}.config`);
93
- await L(J, JSON.stringify(a)), g.push(`import ${e} from '${t}.astro?configFile=${C}.config';`), s.push(e);
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 `${g.join(`
117
+ return `${i.join(`
96
118
  `)}
97
- ${l.join(`
119
+ ${w.join(`
98
120
  `)}
99
- export { ${s.join(", ")} };`;
121
+ export { ${v.join(", ")} };`;
100
122
  }
101
123
  return;
102
- } catch (c) {
103
- console.error("Error during file compilation:", c);
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: o, modules: r }) {
129
+ handleHotUpdate: async function({ file: t, server: r, modules: a }) {
108
130
  try {
109
- if (await D(t)) return await n.generateCss(!1);
110
- if (!S(t)) return;
111
- const g = await n.getDestDir(), l = [];
112
- for (const [s, m] of o.moduleGraph.idToModuleMap)
113
- s.startsWith(t + ".astro?configFile=") && (o.moduleGraph.invalidateModule(m), l.push(m));
114
- for (const s of o.moduleGraph.urlToModuleMap.values())
115
- s.file && s.file.startsWith(g) && (o.moduleGraph.invalidateModule(s), l.push(s));
116
- return o.ws.send({ type: "update", updates: [] }), [...r, ...l];
117
- } catch (c) {
118
- console.error("Error during hot update handling:", c);
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, o) {
144
+ handler: async function(t, r) {
123
145
  try {
124
- S(t) && o.event !== "delete" && (await D(t) || await n.generateFile(t));
125
- } catch (r) {
126
- console.error("Error during watch change handling:", r);
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
- Q as default,
134
- Q as saltyPlugin
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.35",
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.35",
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
  }