@salty-css/astro 0.0.1-alpha.302 → 0.0.1-alpha.304

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