@salty-css/webpack 0.0.1-alpha.2 → 0.0.1-alpha.4

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/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";const _=require("esbuild"),P=require("winston");require("child_process");const a=require("path"),d=require("fs"),q=require("fs/promises");function S(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const E=S(_),f=S(P),F=e=>String.fromCharCode(e+(e>25?39:97)),v=(e,s)=>{let t="",n;for(n=Math.abs(e);n>52;n=n/52|0)t=F(n%52)+t;return t=F(n%52)+t,t.length<s?t=t.padStart(s,"a"):t.length>s&&(t=t.slice(-s)),t},R=(e,s)=>{let t=s.length;for(;t;)e=e*33^s.charCodeAt(--t);return e},x=(e,s=3)=>{const t=R(5381,JSON.stringify(e))>>>0;return v(t,s)};f.createLogger({level:"info",format:f.format.combine(f.format.colorize(),f.format.cli()),transports:[new f.transports.Console({})]});const k=e=>a.join(e,"./saltygen"),z=["salty","css","styles","styled"],C=e=>new RegExp(`\\.(${z.join("|")})\\.`).test(e),N=async(e,s)=>{const t=x(e),n=a.join(s,"js",t+".js");await E.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const r=Date.now();return await import(`${n}?t=${r}`)},O=async e=>{const s=k(e),t=a.join(s,"salty-config.js"),{config:n}=await import(t);return n},A=async(e,s)=>{try{const t=[],n=a.join(e,"./saltygen"),r=a.join(n,"index.css");if(C(s)){const y=await O(e),m=await N(s,n);Object.entries(m).forEach(([c,u])=>{if(!u.generator)return;const g=u.generator._withBuildContext({name:c,config:y}),p=`${g.hash}-${g.priority}.css`,w=`css/${p}`,j=a.join(n,w);t.push(p),d.writeFileSync(j,g.css)});const o=d.readFileSync(r,"utf8").split(`
2
+ `),h=t.map(c=>`@import url('../saltygen/css/${c}');`),l=[...new Set([...o,...h])].join(`
3
+ `);d.writeFileSync(r,l)}}catch(t){console.error(t)}},H=async(e,s)=>{try{const t=a.join(e,"./saltygen");if(C(s)){let r=d.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await q.writeFile(s,r);const y=await O(e),m=await N(s,t);let o=r;Object.entries(m).forEach(([i,l])=>{var b;if(l.isKeyframes){console.log("value",l);return}if(!l.generator)return;const c=l.generator._withBuildContext({name:i,config:y}),u=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!u)return console.error("Could not find the original declaration");const g=(b=u.at(1))==null?void 0:b.trim(),{element:p,variantKeys:w}=c.props,j=`${i} = styled(${g}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(p)}, ${JSON.stringify(w)});`,D=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");o=o.replace(D,j)});const h=x(s,6);return y.importStrategy==="component"&&(o=`import '../../saltygen/css/${h}.css';
4
+ ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(t){console.error(t)}};async function J(){const{dir:e}=this.getOptions(),{resourcePath:s,hot:t}=this;return t&&await A(e,s),await H(e,s)}module.exports=J;
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { LoaderContext } from 'webpack';
2
+ interface SaltyLoaderOptions {
3
+ dir: string;
4
+ }
5
+ type WebpackLoaderThis = LoaderContext<SaltyLoaderOptions>;
6
+ export default function (this: WebpackLoaderThis): Promise<string | undefined>;
7
+ export {};
package/index.js ADDED
@@ -0,0 +1,103 @@
1
+ import * as O from "esbuild";
2
+ import * as p from "winston";
3
+ import "child_process";
4
+ import { join as a } from "path";
5
+ import { writeFileSync as F, readFileSync as C } from "fs";
6
+ import { writeFile as P } from "fs/promises";
7
+ const S = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), v = (e, s) => {
8
+ let t = "", n;
9
+ for (n = Math.abs(e); n > 52; n = n / 52 | 0) t = S(n % 52) + t;
10
+ return t = S(n % 52) + t, t.length < s ? t = t.padStart(s, "a") : t.length > s && (t = t.slice(-s)), t;
11
+ }, R = (e, s) => {
12
+ let t = s.length;
13
+ for (; t; ) e = e * 33 ^ s.charCodeAt(--t);
14
+ return e;
15
+ }, N = (e, s = 3) => {
16
+ const t = R(5381, JSON.stringify(e)) >>> 0;
17
+ return v(t, s);
18
+ };
19
+ p.createLogger({
20
+ level: "info",
21
+ format: p.format.combine(p.format.colorize(), p.format.cli()),
22
+ transports: [new p.transports.Console({})]
23
+ });
24
+ const A = (e) => a(e, "./saltygen"), H = ["salty", "css", "styles", "styled"], b = (e) => new RegExp(`\\.(${H.join("|")})\\.`).test(e), j = async (e, s) => {
25
+ const t = N(e), n = a(s, "js", t + ".js");
26
+ await O.build({
27
+ entryPoints: [e],
28
+ minify: !0,
29
+ treeShaking: !0,
30
+ bundle: !0,
31
+ outfile: n,
32
+ format: "esm",
33
+ target: ["es2022"],
34
+ keepNames: !0,
35
+ external: ["react"]
36
+ });
37
+ const r = Date.now();
38
+ return await import(`${n}?t=${r}`);
39
+ }, D = async (e) => {
40
+ const s = A(e), t = a(s, "salty-config.js"), { config: n } = await import(t);
41
+ return n;
42
+ }, J = async (e, s) => {
43
+ try {
44
+ const t = [], n = a(e, "./saltygen"), r = a(n, "index.css");
45
+ if (b(s)) {
46
+ const y = await D(e), d = await j(s, n);
47
+ Object.entries(d).forEach(([c, g]) => {
48
+ if (!g.generator) return;
49
+ const f = g.generator._withBuildContext({
50
+ name: c,
51
+ config: y
52
+ }), m = `${f.hash}-${f.priority}.css`, h = `css/${m}`, w = a(n, h);
53
+ t.push(m), F(w, f.css);
54
+ });
55
+ const o = C(r, "utf8").split(`
56
+ `), u = t.map((c) => `@import url('../saltygen/css/${c}');`), l = [.../* @__PURE__ */ new Set([...o, ...u])].join(`
57
+ `);
58
+ F(r, l);
59
+ }
60
+ } catch (t) {
61
+ console.error(t);
62
+ }
63
+ }, _ = async (e, s) => {
64
+ try {
65
+ const t = a(e, "./saltygen");
66
+ if (b(s)) {
67
+ let r = C(s, "utf8");
68
+ r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await P(s, r);
69
+ const y = await D(e), d = await j(s, t);
70
+ let o = r;
71
+ Object.entries(d).forEach(([i, l]) => {
72
+ var x;
73
+ if (l.isKeyframes) {
74
+ console.log("value", l);
75
+ return;
76
+ }
77
+ if (!l.generator) return;
78
+ const c = l.generator._withBuildContext({
79
+ name: i,
80
+ config: y
81
+ }), g = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
82
+ if (!g)
83
+ return console.error("Could not find the original declaration");
84
+ const f = (x = g.at(1)) == null ? void 0 : x.trim(), { element: m, variantKeys: h } = c.props, w = `${i} = styled(${f}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(
85
+ h
86
+ )});`, E = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
87
+ o = o.replace(E, w);
88
+ });
89
+ const u = N(s, 6);
90
+ return y.importStrategy === "component" && (o = `import '../../saltygen/css/${u}.css';
91
+ ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
92
+ }
93
+ } catch (t) {
94
+ console.error(t);
95
+ }
96
+ };
97
+ async function I() {
98
+ const { dir: e } = this.getOptions(), { resourcePath: s, hot: t } = this;
99
+ return t && await J(e, s), await _(e, s);
100
+ }
101
+ export {
102
+ I as default
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "url": "https://github.com/margarita-form/salty-css/issues"
16
16
  },
17
17
  "files": [
18
- "dist",
18
+ "**/*",
19
19
  "!**/*.tsbuildinfo"
20
20
  ],
21
21
  "nx": {