@salty-css/astro 0.3.0 → 0.3.1-fix-astro-react-auto-transform-fix.0

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.
@@ -0,0 +1,10 @@
1
+ let e=require("@salty-css/core/compiler/salty-compiler"),t=require("@salty-css/core/compiler/helpers"),n=require("@salty-css/core/compiler/get-function-range"),r=require("@salty-css/core/util"),i=require("fs/promises"),a=require("path"),o=require("@salty-css/core/server"),s=require("vite-node/server"),c=require("vite-node/client"),l=require("vite-node/source-map");var u=[{name:`react`,importMarkers:[/['"]@salty-css\/react(\/[^'"]*)?['"]/],loadTransform:async()=>(await import(`@salty-css/react/transform-salty-file`)).transformSaltyFile}],d=new Map,f=e=>{let t=d.get(e.name);if(t)return t;let n=e.loadTransform();return d.set(e.name,n),n},p=e=>{for(let t of u)for(let n of t.importMarkers)if(n.test(e))return t},m=async(e,t)=>{let n=await(0,i.readFile)((0,a.join)(e,`astro`,t),`utf-8`);if(n)try{let e=JSON.parse(n),{clientProps:t={},classNames:r=``,tagIsComponent:i,tagName:a=`div`}=e,o=[`import { resolveAstroProps } from '@salty-css/astro/element-props';`,...e.imports||[]],s=i?a:`__r.element || ${JSON.stringify(t.element||a)}`;return`---
2
+ ${o.join(`
3
+ `)}
4
+ const __gp = ${JSON.stringify(t)};
5
+ const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(r)});
6
+ const Element = ${s};
7
+ ---
8
+ <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(e){console.error(`Error parsing config file:`,e);return}},h=async(e,o)=>{let{compiler:s}=e;try{if((0,t.isSaltyFile)(o,[],!o.includes(`configFile=`))){let e=await s.getDestDir();if(/.+\?configFile=(\w+).+/.test(o)){let t=new URLSearchParams(o.split(`?`)[1]).get(`configFile`);return t?await m(e,t):void 0}let c=await(0,i.readFile)(o,`utf-8`),l=p(c);if(l)return await(await f(l))(s,o);let u=[`import { classNameInstance } from '@salty-css/core/instances/classname-instance';`],d=[],h=[],g=await s.compileSaltyFile(o,e),_=Object.entries(g.contents);for(let[l,f]of _){let p=await(0,t.resolveExportValue)(f,1);if(!p.generator)continue;if(p.isClassName){let e=p.generator._withBuildContext({callerName:l,isProduction:s.isProduction,config:{}});d.push(`const ${l} = classNameInstance(${JSON.stringify(e.params)});`),h.push(l);continue}let[m,g]=await(0,n.getFunctionRange)(c,l),v=c.slice(m,g),y=/styled\(([^,]+),/.exec(v)?.at(1)?.trim();if(!y){console.warn(`Could not determine tag name for ${l} in ${o}`);continue}let b=p.generator._withBuildContext({callerName:l,isProduction:s.isProduction,config:{}}),x={componentName:l,tagName:y.replace(/['"`]/g,``),tagIsComponent:!1,classNames:b.classNames,imports:[],clientProps:b.clientProps},S=/^\w+$/.test(y);if(x.tagIsComponent=S,S){let e=_.some(([e])=>e===y),t=c.match(RegExp(`import[^;]*${y}[^;]*;`));e?x.imports=[`import ${y} from '${o}.astro?configFile=${(0,r.toHash)(y)}.config';`]:t&&(x.imports=[t.at(0)])}let C=(0,a.join)(e,`astro`);await(0,i.readFile)(C,`utf-8`).catch(()=>!1)||await(0,i.mkdir)(C,{recursive:!0});let w=(0,r.toHash)(l);await(0,i.writeFile)((0,a.join)(e,`astro`,`${w}.config`),JSON.stringify(x)),u.push(`import ${l} from '${o}.astro?configFile=${w}.config';`),h.push(l)}return`${u.join(`
9
+ `)}\n${d.join(`
10
+ `)}\nexport { ${h.join(`, `)} };`}return}catch(e){console.error(`Error during file compilation:`,e);return}},g=async(e,{file:n,server:r,modules:i})=>{try{if(await(0,o.checkShouldRestart)(n))return await e.generateCss(!1);if(!(0,t.isSaltyFile)(n))return;let a=await e.getDestDir(),s=[];for(let[e,t]of r.moduleGraph.idToModuleMap)e.startsWith(n+`.astro?configFile=`)&&(r.moduleGraph.invalidateModule(t),s.push(t));for(let e of r.moduleGraph.urlToModuleMap.values())e.file&&e.file.startsWith(a)&&(r.moduleGraph.invalidateModule(e),s.push(e));return r.ws.send({type:`update`,updates:[]}),[...i,...s]}catch(e){console.error(`Error during hot update handling:`,e)}},_=async(e,n,r)=>{try{(0,t.isSaltyFile)(n)&&r.event!==`delete`&&(await(0,o.checkShouldRestart)(n)||await e.generateFile(n))}catch(e){console.error(`Error during watch change handling:`,e)}},v=(t,n={})=>{let r,i,a,o,u=new e.SaltyCompiler(t,{mode:n.mode}),d={compiler:u},f=async()=>{if(a&&i&&r)return a;if(!o)throw Error(`[stylegen] vite-node runner requested before configResolved ran`);let{createServer:e,version:t}=await import(`vite`);r=await e({resolve:{alias:o.resolve.alias},server:{middlewareMode:!0,hmr:!1,ws:!1,watch:null},optimizeDeps:{noDiscovery:!0,include:[]}}),Number(t.split(`.`)[0])<6&&await r.pluginContainer.buildStart({});let n=new s.ViteNodeServer(r);return i=n,(0,l.installSourcemapsSupport)({getSourceMap:e=>n.getSourceMap(e)}),a=new c.ViteNodeRunner({root:r.config.root,base:r.config.base,fetchModule:e=>n.fetchModule(e),resolveId:(e,t)=>n.resolveId(e,t)}),a},p=(e,t)=>{let n=e.moduleCache;n.invalidateDepTree?n.invalidateDepTree([t]):n.deleteByModuleId?n.deleteByModuleId(t):n.clear()};u.importFile=async e=>{let t=await f();return p(t,e),t.executeFile(e)};let m=async()=>{let e=r;if(r=void 0,i=void 0,a=void 0,e)try{await e.close()}catch{}},v,y=()=>(v||=u.generateCss().catch(e=>{throw v=void 0,e}),v);return{name:`stylegen`,configResolved:async function(e){o=e,await f();try{await y()}catch(e){throw console.error(`Error during initial CSS generation:`,e),e}},resolveId:function(e){return e.includes(`.astro?configFile=`)?e:null},load:function(e){return h(d,e)},handleHotUpdate:function(e){return g(u,e)},watchChange:{handler:function(e,t){return _(u,e,t)}},closeBundle:async function(){await m()}}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
@@ -12,18 +12,15 @@ import { installSourcemapsSupport as f } from "vite-node/source-map";
12
12
  var p = [{
13
13
  name: "react",
14
14
  importMarkers: [/['"]@salty-css\/react(\/[^'"]*)?['"]/],
15
- loadTransform: async (e) => {
16
- let t = "@salty-css/react/transform-salty-file";
17
- return (e ? await e(t) : await import(
18
- /* @vite-ignore */
19
- t
20
- )).transformSaltyFile;
21
- }
22
- }], m = /* @__PURE__ */ new Map(), h = (e, t) => {
23
- let n = m.get(e.name);
24
- if (n) return n;
25
- let r = e.loadTransform(t);
26
- return m.set(e.name, r), r;
15
+ loadTransform: async () => (await import(
16
+ /* @vite-ignore */
17
+ "@salty-css/react/transform-salty-file"
18
+ )).transformSaltyFile
19
+ }], m = /* @__PURE__ */ new Map(), h = (e) => {
20
+ let t = m.get(e.name);
21
+ if (t) return t;
22
+ let n = e.loadTransform();
23
+ return m.set(e.name, n), n;
27
24
  }, g = (e) => {
28
25
  for (let t of p) for (let n of t.importMarkers) if (n.test(e)) return t;
29
26
  }, _ = async (e, t) => {
@@ -45,37 +42,37 @@ var p = [{
45
42
  let { compiler: u } = e;
46
43
  try {
47
44
  if (t(l, [], !l.includes("configFile="))) {
48
- let t = await u.getDestDir();
45
+ let e = await u.getDestDir();
49
46
  if (/.+\?configFile=(\w+).+/.test(l)) {
50
- let e = new URLSearchParams(l.split("?")[1]).get("configFile");
51
- return e ? await _(t, e) : void 0;
47
+ let t = new URLSearchParams(l.split("?")[1]).get("configFile");
48
+ return t ? await _(e, t) : void 0;
52
49
  }
53
- let d = await o(l, "utf-8"), f = g(d);
54
- if (f) return await (await h(f, e.importer))(u, l);
55
- let p = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], m = [], v = [], y = await u.compileSaltyFile(l, t), b = Object.entries(y.contents);
56
- for (let [e, f] of b) {
57
- let h = await n(f, 1);
58
- if (!h.generator) continue;
59
- if (h.isClassName) {
60
- let t = h.generator._withBuildContext({
61
- callerName: e,
50
+ let t = await o(l, "utf-8"), d = g(t);
51
+ if (d) return await (await h(d))(u, l);
52
+ let f = ["import { classNameInstance } from '@salty-css/core/instances/classname-instance';"], p = [], m = [], v = await u.compileSaltyFile(l, e), y = Object.entries(v.contents);
53
+ for (let [d, h] of y) {
54
+ let g = await n(h, 1);
55
+ if (!g.generator) continue;
56
+ if (g.isClassName) {
57
+ let e = g.generator._withBuildContext({
58
+ callerName: d,
62
59
  isProduction: u.isProduction,
63
60
  config: {}
64
61
  });
65
- m.push(`const ${e} = classNameInstance(${JSON.stringify(t.params)});`), v.push(e);
62
+ p.push(`const ${d} = classNameInstance(${JSON.stringify(e.params)});`), m.push(d);
66
63
  continue;
67
64
  }
68
- let [g, _] = await r(d, e), y = d.slice(g, _), x = /styled\(([^,]+),/.exec(y)?.at(1)?.trim();
65
+ let [_, v] = await r(t, d), b = t.slice(_, v), x = /styled\(([^,]+),/.exec(b)?.at(1)?.trim();
69
66
  if (!x) {
70
- console.warn(`Could not determine tag name for ${e} in ${l}`);
67
+ console.warn(`Could not determine tag name for ${d} in ${l}`);
71
68
  continue;
72
69
  }
73
- let S = h.generator._withBuildContext({
74
- callerName: e,
70
+ let S = g.generator._withBuildContext({
71
+ callerName: d,
75
72
  isProduction: u.isProduction,
76
73
  config: {}
77
74
  }), C = {
78
- componentName: e,
75
+ componentName: d,
79
76
  tagName: x.replace(/['"`]/g, ""),
80
77
  tagIsComponent: !1,
81
78
  classNames: S.classNames,
@@ -83,15 +80,15 @@ var p = [{
83
80
  clientProps: S.clientProps
84
81
  }, w = /^\w+$/.test(x);
85
82
  if (C.tagIsComponent = w, w) {
86
- let e = b.some(([e]) => e === x), t = d.match(RegExp(`import[^;]*${x}[^;]*;`));
87
- e ? C.imports = [`import ${x} from '${l}.astro?configFile=${i(x)}.config';`] : t && (C.imports = [t.at(0)]);
83
+ let e = y.some(([e]) => e === x), n = t.match(RegExp(`import[^;]*${x}[^;]*;`));
84
+ e ? C.imports = [`import ${x} from '${l}.astro?configFile=${i(x)}.config';`] : n && (C.imports = [n.at(0)]);
88
85
  }
89
- let T = c(t, "astro");
86
+ let T = c(e, "astro");
90
87
  await o(T, "utf-8").catch(() => !1) || await a(T, { recursive: !0 });
91
- let E = i(e);
92
- await s(c(t, "astro", `${E}.config`), JSON.stringify(C)), p.push(`import ${e} from '${l}.astro?configFile=${E}.config';`), v.push(e);
88
+ let E = i(d);
89
+ await s(c(e, "astro", `${E}.config`), JSON.stringify(C)), f.push(`import ${d} from '${l}.astro?configFile=${E}.config';`), m.push(d);
93
90
  }
94
- return `${p.join("\n")}\n${m.join("\n")}\nexport { ${v.join(", ")} };`;
91
+ return `${f.join("\n")}\n${p.join("\n")}\nexport { ${m.join(", ")} };`;
95
92
  }
96
93
  return;
97
94
  } catch (e) {
@@ -119,10 +116,7 @@ var p = [{
119
116
  console.error("Error during watch change handling:", e);
120
117
  }
121
118
  }, x = (t, n = {}) => {
122
- let r, i, a, o, s = new e(t, { mode: n.mode }), c = {
123
- compiler: s,
124
- importer: void 0
125
- }, l = async () => {
119
+ let r, i, a, o, s = new e(t, { mode: n.mode }), c = { compiler: s }, l = async () => {
126
120
  if (a && i && r) return a;
127
121
  if (!o) throw Error("[stylegen] vite-node runner requested before configResolved ran");
128
122
  let { createServer: e, version: t } = await import("vite");
@@ -153,7 +147,7 @@ var p = [{
153
147
  s.importFile = async (e) => {
154
148
  let t = await l();
155
149
  return p(t, e), t.executeFile(e);
156
- }, c.importer = s.importFile;
150
+ };
157
151
  let m = async () => {
158
152
  let e = r;
159
153
  if (r = void 0, i = void 0, a = void 0, e) try {
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./astro-vite-plugin-goCXCXLG.cjs");exports.default=e.t,exports.saltyPlugin=e.t;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./astro-vite-plugin-1E5CWsN3.cjs");exports.default=e.t,exports.saltyPlugin=e.t;
@@ -1 +1 @@
1
- {"version":3,"file":"astro-vite-plugin.d.ts","sourceRoot":"","sources":["../src/astro-vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAiC,MAAM,MAAM,CAAC;AAQnE,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAS,uBAA4B,KAAG,YAwMhF,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"astro-vite-plugin.d.ts","sourceRoot":"","sources":["../src/astro-vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAiC,MAAM,MAAM,CAAC;AAQnE,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,UAAS,uBAA4B,KAAG,YAmMhF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,2 +1,2 @@
1
- import { t as e } from "./astro-vite-plugin-DDl_IdJa.js";
1
+ import { t as e } from "./astro-vite-plugin-H1SVOmVT.js";
2
2
  export { e as default, e as saltyPlugin };
@@ -1,12 +1,11 @@
1
1
  import { SaltyCompiler } from '../../core/dist/compiler/salty-compiler';
2
- export type Importer = undefined | ((path: string) => Promise<any>);
3
2
  export type SaltyFileTransform = (compiler: SaltyCompiler, file: string) => Promise<string | undefined>;
4
3
  export interface FrameworkEntry {
5
4
  name: string;
6
5
  importMarkers: RegExp[];
7
- loadTransform: (importer: Importer) => Promise<SaltyFileTransform>;
6
+ loadTransform: () => Promise<SaltyFileTransform>;
8
7
  }
9
8
  export declare const frameworkRegistry: FrameworkEntry[];
10
- export declare const getFrameworkTransform: (entry: FrameworkEntry, importer: Importer) => Promise<SaltyFileTransform>;
9
+ export declare const getFrameworkTransform: (entry: FrameworkEntry) => Promise<SaltyFileTransform>;
11
10
  export declare const detectFramework: (source: string) => FrameworkEntry | undefined;
12
11
  //# sourceMappingURL=framework-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"framework-registry.d.ts","sourceRoot":"","sources":["../src/framework-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAExG,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAU7C,CAAC;AAIF,eAAO,MAAM,qBAAqB,GAAI,OAAO,cAAc,EAAE,UAAU,QAAQ,KAAG,OAAO,CAAC,kBAAkB,CAM3G,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,cAAc,GAAG,SAOjE,CAAC"}
1
+ {"version":3,"file":"framework-registry.d.ts","sourceRoot":"","sources":["../src/framework-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAE7E,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAExG,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClD;AAED,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAa7C,CAAC;AAIF,eAAO,MAAM,qBAAqB,GAAI,OAAO,cAAc,KAAG,OAAO,CAAC,kBAAkB,CAMvF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,cAAc,GAAG,SAOjE,CAAC"}
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./astro-vite-plugin-goCXCXLG.cjs");let t=require("path");var n=(n={})=>({name:`astro-salty-integration`,hooks:{"astro:config:setup":({config:r,updateConfig:i})=>{let{srcDir:a=`src`,rootDir:o=r.root.pathname}=n;i({vite:{plugins:[e.t((0,t.join)(o,a))]}})}}});exports.default=n,exports.saltyIntegration=n;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./astro-vite-plugin-1E5CWsN3.cjs");let t=require("path");var n=(n={})=>({name:`astro-salty-integration`,hooks:{"astro:config:setup":({config:r,updateConfig:i})=>{let{srcDir:a=`src`,rootDir:o=r.root.pathname}=n;i({vite:{plugins:[e.t((0,t.join)(o,a))]}})}}});exports.default=n,exports.saltyIntegration=n;
@@ -1,4 +1,4 @@
1
- import { t as e } from "./astro-vite-plugin-DDl_IdJa.js";
1
+ import { t as e } from "./astro-vite-plugin-H1SVOmVT.js";
2
2
  import { join as t } from "path";
3
3
  //#region src/integration.ts
4
4
  var n = (n = {}) => ({
@@ -1,9 +1,6 @@
1
1
  import { SaltyCompiler } from '../../core/dist/compiler/salty-compiler';
2
- import { Importer } from './framework-registry';
3
2
  export interface AstroPluginContext {
4
3
  compiler: SaltyCompiler;
5
- /** Updated just-in-time by the plugin's importFile, read here for dev transforms. */
6
- importer: Importer;
7
4
  }
8
5
  /**
9
6
  * Vite `load` hook body: resolves stored `.astro` component configs, delegates to
@@ -1 +1 @@
1
- {"version":3,"file":"load-salty-file.d.ts","sourceRoot":"","sources":["../src/load-salty-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAIxE,OAAO,EAA0C,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGxF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,qFAAqF;IACrF,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,KAAK,kBAAkB,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAwGzG,CAAC"}
1
+ {"version":3,"file":"load-salty-file.d.ts","sourceRoot":"","sources":["../src/load-salty-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAOxE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,KAAK,kBAAkB,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAwGzG,CAAC"}
package/package.json CHANGED
@@ -15,15 +15,15 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/margarita-form/salty-css/issues"
17
17
  },
18
- "version": "0.3.0",
18
+ "version": "0.3.1-fix-astro-react-auto-transform-fix.0",
19
19
  "type": "module",
20
20
  "scripts": {
21
21
  "build": "node ../../node_modules/vite-build/bin/vite.js build --config vite.config.ts",
22
22
  "test": "vitest run"
23
23
  },
24
24
  "dependencies": {
25
- "@salty-css/core": "0.3.0",
26
- "@salty-css/react": "0.3.0",
25
+ "@salty-css/core": "0.3.1-fix-astro-react-auto-transform-fix.0",
26
+ "@salty-css/react": "0.3.1-fix-astro-react-auto-transform-fix.0",
27
27
  "vite": "^7.3.5",
28
28
  "vite-node": "^5.3.0"
29
29
  },
@@ -1,10 +0,0 @@
1
- let e=require("@salty-css/core/compiler/salty-compiler"),t=require("@salty-css/core/compiler/helpers"),n=require("@salty-css/core/compiler/get-function-range"),r=require("@salty-css/core/util"),i=require("fs/promises"),a=require("path"),o=require("@salty-css/core/server"),s=require("vite-node/server"),c=require("vite-node/client"),l=require("vite-node/source-map");var u=[{name:`react`,importMarkers:[/['"]@salty-css\/react(\/[^'"]*)?['"]/],loadTransform:async e=>{let t=`@salty-css/react/transform-salty-file`;return(e?await e(t):await import(t)).transformSaltyFile}}],d=new Map,f=(e,t)=>{let n=d.get(e.name);if(n)return n;let r=e.loadTransform(t);return d.set(e.name,r),r},p=e=>{for(let t of u)for(let n of t.importMarkers)if(n.test(e))return t},m=async(e,t)=>{let n=await(0,i.readFile)((0,a.join)(e,`astro`,t),`utf-8`);if(n)try{let e=JSON.parse(n),{clientProps:t={},classNames:r=``,tagIsComponent:i,tagName:a=`div`}=e,o=[`import { resolveAstroProps } from '@salty-css/astro/element-props';`,...e.imports||[]],s=i?a:`__r.element || ${JSON.stringify(t.element||a)}`;return`---
2
- ${o.join(`
3
- `)}
4
- const __gp = ${JSON.stringify(t)};
5
- const __r = resolveAstroProps(Astro.props, __gp, ${JSON.stringify(r)});
6
- const Element = ${s};
7
- ---
8
- <Element class:list={__r.class} style={__r.style} {...__r.rest}><slot/></Element>`}catch(e){console.error(`Error parsing config file:`,e);return}},h=async(e,o)=>{let{compiler:s}=e;try{if((0,t.isSaltyFile)(o,[],!o.includes(`configFile=`))){let c=await s.getDestDir();if(/.+\?configFile=(\w+).+/.test(o)){let e=new URLSearchParams(o.split(`?`)[1]).get(`configFile`);return e?await m(c,e):void 0}let l=await(0,i.readFile)(o,`utf-8`),u=p(l);if(u)return await(await f(u,e.importer))(s,o);let d=[`import { classNameInstance } from '@salty-css/core/instances/classname-instance';`],h=[],g=[],_=await s.compileSaltyFile(o,c),v=Object.entries(_.contents);for(let[e,u]of v){let f=await(0,t.resolveExportValue)(u,1);if(!f.generator)continue;if(f.isClassName){let t=f.generator._withBuildContext({callerName:e,isProduction:s.isProduction,config:{}});h.push(`const ${e} = classNameInstance(${JSON.stringify(t.params)});`),g.push(e);continue}let[p,m]=await(0,n.getFunctionRange)(l,e),_=l.slice(p,m),y=/styled\(([^,]+),/.exec(_)?.at(1)?.trim();if(!y){console.warn(`Could not determine tag name for ${e} in ${o}`);continue}let b=f.generator._withBuildContext({callerName:e,isProduction:s.isProduction,config:{}}),x={componentName:e,tagName:y.replace(/['"`]/g,``),tagIsComponent:!1,classNames:b.classNames,imports:[],clientProps:b.clientProps},S=/^\w+$/.test(y);if(x.tagIsComponent=S,S){let e=v.some(([e])=>e===y),t=l.match(RegExp(`import[^;]*${y}[^;]*;`));e?x.imports=[`import ${y} from '${o}.astro?configFile=${(0,r.toHash)(y)}.config';`]:t&&(x.imports=[t.at(0)])}let C=(0,a.join)(c,`astro`);await(0,i.readFile)(C,`utf-8`).catch(()=>!1)||await(0,i.mkdir)(C,{recursive:!0});let w=(0,r.toHash)(e);await(0,i.writeFile)((0,a.join)(c,`astro`,`${w}.config`),JSON.stringify(x)),d.push(`import ${e} from '${o}.astro?configFile=${w}.config';`),g.push(e)}return`${d.join(`
9
- `)}\n${h.join(`
10
- `)}\nexport { ${g.join(`, `)} };`}return}catch(e){console.error(`Error during file compilation:`,e);return}},g=async(e,{file:n,server:r,modules:i})=>{try{if(await(0,o.checkShouldRestart)(n))return await e.generateCss(!1);if(!(0,t.isSaltyFile)(n))return;let a=await e.getDestDir(),s=[];for(let[e,t]of r.moduleGraph.idToModuleMap)e.startsWith(n+`.astro?configFile=`)&&(r.moduleGraph.invalidateModule(t),s.push(t));for(let e of r.moduleGraph.urlToModuleMap.values())e.file&&e.file.startsWith(a)&&(r.moduleGraph.invalidateModule(e),s.push(e));return r.ws.send({type:`update`,updates:[]}),[...i,...s]}catch(e){console.error(`Error during hot update handling:`,e)}},_=async(e,n,r)=>{try{(0,t.isSaltyFile)(n)&&r.event!==`delete`&&(await(0,o.checkShouldRestart)(n)||await e.generateFile(n))}catch(e){console.error(`Error during watch change handling:`,e)}},v=(t,n={})=>{let r,i,a,o,u=new e.SaltyCompiler(t,{mode:n.mode}),d={compiler:u,importer:void 0},f=async()=>{if(a&&i&&r)return a;if(!o)throw Error(`[stylegen] vite-node runner requested before configResolved ran`);let{createServer:e,version:t}=await import(`vite`);r=await e({resolve:{alias:o.resolve.alias},server:{middlewareMode:!0,hmr:!1,ws:!1,watch:null},optimizeDeps:{noDiscovery:!0,include:[]}}),Number(t.split(`.`)[0])<6&&await r.pluginContainer.buildStart({});let n=new s.ViteNodeServer(r);return i=n,(0,l.installSourcemapsSupport)({getSourceMap:e=>n.getSourceMap(e)}),a=new c.ViteNodeRunner({root:r.config.root,base:r.config.base,fetchModule:e=>n.fetchModule(e),resolveId:(e,t)=>n.resolveId(e,t)}),a},p=(e,t)=>{let n=e.moduleCache;n.invalidateDepTree?n.invalidateDepTree([t]):n.deleteByModuleId?n.deleteByModuleId(t):n.clear()};u.importFile=async e=>{let t=await f();return p(t,e),t.executeFile(e)},d.importer=u.importFile;let m=async()=>{let e=r;if(r=void 0,i=void 0,a=void 0,e)try{await e.close()}catch{}},v,y=()=>(v||=u.generateCss().catch(e=>{throw v=void 0,e}),v);return{name:`stylegen`,configResolved:async function(e){o=e,await f();try{await y()}catch(e){throw console.error(`Error during initial CSS generation:`,e),e}},resolveId:function(e){return e.includes(`.astro?configFile=`)?e:null},load:function(e){return h(d,e)},handleHotUpdate:function(e){return g(u,e)},watchChange:{handler:function(e,t){return _(u,e,t)}},closeBundle:async function(){await m()}}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});