@salty-css/core 0.4.3 → 0.4.4-alpha.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.
- package/README.md +16 -0
- package/dist/bin/index.cjs +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/bin/main.cjs +1 -1
- package/dist/bin/main.js +1 -1
- package/dist/compiler/get-function-range.cjs +1 -1
- package/dist/compiler/get-function-range.d.ts.map +1 -1
- package/dist/compiler/get-function-range.js +33 -15
- package/dist/compiler/load-typescript.d.ts +39 -0
- package/dist/compiler/load-typescript.d.ts.map +1 -0
- package/dist/compiler/salty-compiler.cjs +1 -1
- package/dist/compiler/salty-compiler.js +1 -1
- package/dist/{main-Qfdn58GZ.js → main-C0AayR7r.js} +1 -1
- package/dist/{main-DbVNicPd.cjs → main-DXui4Hd4.cjs} +1 -1
- package/dist/{salty-compiler-CMeLd60u.js → salty-compiler-B0T--c_m.js} +1 -1
- package/dist/{salty-compiler-B12U4A0a.cjs → salty-compiler-D65uRACA.cjs} +1 -1
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -530,6 +530,22 @@ Options: `srcDir` (defaults to `'src'`), `rootDir` (defaults to the Astro config
|
|
|
530
530
|
|
|
531
531
|
---
|
|
532
532
|
|
|
533
|
+
## Troubleshooting
|
|
534
|
+
|
|
535
|
+
### TypeScript 7: `Cannot read properties of undefined (reading 'Latest')`
|
|
536
|
+
|
|
537
|
+
TypeScript 7 (the Go-native compiler) does not ship the programmatic compiler API that Salty CSS uses to parse style files — it returns in TS 7.1. Salty CSS feature-detects a working API at runtime:
|
|
538
|
+
|
|
539
|
+
| Your TypeScript | What to install | What happens |
|
|
540
|
+
| --- | --- | --- |
|
|
541
|
+
| 4.x / 5.x / 6.x | Nothing | Works as-is, using your own `typescript` |
|
|
542
|
+
| 7.0.x | `npm install -D @typescript/typescript6` | Salty parses with the 6.x API; `tsc` stays the fast native compiler |
|
|
543
|
+
| 7.1+ (once the stable API ships) | Nothing | Detection picks up the main package again automatically |
|
|
544
|
+
|
|
545
|
+
`@typescript/typescript6` is Microsoft's official side-by-side compatibility package, designed to coexist with TS 7 during the transition.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
533
549
|
## Support
|
|
534
550
|
|
|
535
551
|
Help, questions, or feedback → [Join the Salty CSS Discord](https://discord.gg/R6kr4KxMhP). Bug reports → [GitHub issues](https://github.com/margarita-form/salty-css/issues).
|
package/dist/bin/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require("../main-
|
|
2
|
+
require("../main-DXui4Hd4.cjs").t().catch(e=>console.error(e));
|
package/dist/bin/index.js
CHANGED
package/dist/bin/main.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../main-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../main-DXui4Hd4.cjs");exports.main=e.t;
|
package/dist/bin/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../main-
|
|
1
|
+
import { t as e } from "../main-C0AayR7r.js";
|
|
2
2
|
export { e as main };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=[`typescript`,`@typescript/typescript6`],t=e=>{let t=e;return typeof t?.createSourceFile==`function`&&typeof t?.ScriptTarget?.Latest==`number`},n,r=()=>(n||=i(),n),i=async()=>{let n;for(let r of e)try{let e=await import(r),i=e?.default??e;if(t(i))return i;typeof i?.version==`string`&&(n=i.version)}catch{}let r=n?` (found typescript ${n}, which does not include the compiler API)`:``;throw Error(`Salty CSS could not find a TypeScript compiler API${r}. TypeScript 7 does not ship the programmatic API that Salty CSS uses to parse style files. Install the official side-by-side compatibility package to fix this: npm install -D @typescript/typescript6`)},a=async(e,t)=>{let n=await r();return new Promise((r,i)=>{let a=setTimeout(()=>{i(Error(`Timeout`))},100),o=n.createSourceFile(`temp.ts`,e,n.ScriptTarget.Latest,!0);function s(e){if(n.isVariableDeclaration(e)&&e.name?.getText()===t){let t=e.getStart(),n=e.getEnd();clearTimeout(a),r([t,n])}e.forEachChild(s)}s(o)})};exports.getFunctionRange=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-function-range.d.ts","sourceRoot":"","sources":["../../src/compiler/get-function-range.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"get-function-range.d.ts","sourceRoot":"","sources":["../../src/compiler/get-function-range.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,GAAU,UAAU,MAAM,EAAE,MAAM,MAAM,KAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CA6B/F,CAAC"}
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//#region src/compiler/load-typescript.ts
|
|
2
|
+
var e = ["typescript", "@typescript/typescript6"], t = (e) => {
|
|
3
|
+
let t = e;
|
|
4
|
+
return typeof t?.createSourceFile == "function" && typeof t?.ScriptTarget?.Latest == "number";
|
|
5
|
+
}, n, r = () => (n ||= i(), n), i = async () => {
|
|
6
|
+
let n;
|
|
7
|
+
for (let r of e) try {
|
|
8
|
+
let e = await import(
|
|
9
|
+
/* @vite-ignore */
|
|
10
|
+
/* webpackIgnore: true */
|
|
11
|
+
r
|
|
12
|
+
), i = e?.default ?? e;
|
|
13
|
+
if (t(i)) return i;
|
|
14
|
+
typeof i?.version == "string" && (n = i.version);
|
|
15
|
+
} catch {}
|
|
16
|
+
let r = n ? ` (found typescript ${n}, which does not include the compiler API)` : "";
|
|
17
|
+
throw Error(`Salty CSS could not find a TypeScript compiler API${r}. TypeScript 7 does not ship the programmatic API that Salty CSS uses to parse style files. Install the official side-by-side compatibility package to fix this: npm install -D @typescript/typescript6`);
|
|
18
|
+
}, a = async (e, t) => {
|
|
19
|
+
let n = await r();
|
|
20
|
+
return new Promise((r, i) => {
|
|
21
|
+
let a = setTimeout(() => {
|
|
22
|
+
i(/* @__PURE__ */ Error("Timeout"));
|
|
23
|
+
}, 100), o = n.createSourceFile("temp.ts", e, n.ScriptTarget.Latest, !0);
|
|
24
|
+
function s(e) {
|
|
25
|
+
if (n.isVariableDeclaration(e) && e.name?.getText() === t) {
|
|
26
|
+
let t = e.getStart(), n = e.getEnd();
|
|
27
|
+
clearTimeout(a), r([t, n]);
|
|
28
|
+
}
|
|
29
|
+
e.forEachChild(s);
|
|
11
30
|
}
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
});
|
|
31
|
+
s(o);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
16
34
|
//#endregion
|
|
17
|
-
export {
|
|
35
|
+
export { a as getFunctionRange };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a TypeScript module that actually exposes the compiler API
|
|
3
|
+
* (createSourceFile, ScriptTarget, node predicates, etc).
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: TypeScript 7 is the Go-native compiler. Its npm package's
|
|
6
|
+
* JS entry point only exports `version` and `versionMajorMinor` — the whole
|
|
7
|
+
* programmatic compiler API is gone until TS 7.1 ships a stable API. So
|
|
8
|
+
* `import ts from 'typescript'` in a TS 7 project gives you an object where
|
|
9
|
+
* `ts.ScriptTarget` is undefined and `ts.createSourceFile` doesn't exist.
|
|
10
|
+
*
|
|
11
|
+
* Strategy: feature-detect instead of version-detect. Try candidates in
|
|
12
|
+
* order and use the first module that actually has the API we need:
|
|
13
|
+
*
|
|
14
|
+
* 1. `typescript` — works for every project on TS <= 6.x (and will work
|
|
15
|
+
* again on TS >= 7.1 if the stable API lands under the same names).
|
|
16
|
+
* 2. `@typescript/typescript6` — Microsoft's official side-by-side compat
|
|
17
|
+
* package for TS 7 projects. Re-exports the full 6.x API.
|
|
18
|
+
*
|
|
19
|
+
* If neither works, throw an error that tells the user exactly what to install.
|
|
20
|
+
*/
|
|
21
|
+
export interface TsCompilerApi {
|
|
22
|
+
version: string;
|
|
23
|
+
ScriptTarget: {
|
|
24
|
+
Latest: number;
|
|
25
|
+
};
|
|
26
|
+
createSourceFile: (fileName: string, sourceText: string, languageVersion: number, setParentNodes?: boolean) => TsSourceFile;
|
|
27
|
+
isVariableDeclaration: (node: TsNode) => boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface TsNode {
|
|
30
|
+
getStart(): number;
|
|
31
|
+
getEnd(): number;
|
|
32
|
+
forEachChild(cb: (node: TsNode) => void): void;
|
|
33
|
+
name?: {
|
|
34
|
+
getText(): string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export type TsSourceFile = TsNode;
|
|
38
|
+
export declare const loadTypeScript: () => Promise<TsCompilerApi>;
|
|
39
|
+
//# sourceMappingURL=load-typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-typescript.d.ts","sourceRoot":"","sources":["../../src/compiler/load-typescript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,KAAK,YAAY,CAAC;IAC5H,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD;AAED,MAAM,WAAW,MAAM;IACrB,QAAQ,IAAI,MAAM,CAAC;IACnB,MAAM,IAAI,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAC/C,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,MAAM,CAAA;KAAE,CAAC;CAC9B;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAWlC,eAAO,MAAM,cAAc,QAAO,OAAO,CAAC,aAAa,CAGtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../salty-compiler-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../salty-compiler-D65uRACA.cjs");exports.SaltyCompiler=e.t;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../salty-compiler-
|
|
1
|
+
import { t as e } from "../salty-compiler-B0T--c_m.js";
|
|
2
2
|
export { e as SaltyCompiler };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as e, r as t, t as n } from "./salty-compiler-
|
|
1
|
+
import { n as e, r as t, t as n } from "./salty-compiler-B0T--c_m.js";
|
|
2
2
|
import { isSaltyFile as r } from "./compiler/helpers.js";
|
|
3
3
|
import { pascalCase as i } from "./util/index.js";
|
|
4
4
|
import { checkShouldRestart as a } from "./server/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require("./chunk-CMqjfN_6.cjs"),t=require("./salty-compiler-
|
|
1
|
+
const e=require("./chunk-CMqjfN_6.cjs"),t=require("./salty-compiler-D65uRACA.cjs"),n=require("./compiler/helpers.cjs"),r=require("./util/index.cjs"),i=require("./server/index.cjs");let a=require("commander"),o=require("fs"),s=require("path"),c=require("fs/promises"),l=require("child_process"),u=require("ora");u=e.t(u,1);let d=require("ejs");d=e.t(d,1);let f=require("readline/promises");var p=(0,s.join)(process.cwd(),`package.json`),m=async(e=p)=>{let t=await(0,c.readFile)(e,`utf-8`).then(JSON.parse).catch(()=>void 0);if(!t)throw`Could not read package.json file!`;return t},h=async(e,t=p)=>{typeof e==`object`&&(e=JSON.stringify(e,null,2)),await(0,c.writeFile)(t,e)},g=async()=>m(new URL(`../package.json`,``+{}.url)),_={core:e=>`@salty-css/core@${e}`,eslintConfigCore:e=>`@salty-css/eslint-config-core@${e}`},v=e=>{e.scripts||={};let t=e.scripts.prepare;if(t){if(t.includes(`salty-css`))return{changed:!1,pkg:e};e.scripts.prepare=t+` && npx salty-css build`}else e.scripts.prepare=`npx salty-css build`;return{changed:!0,pkg:e}},y=e=>new Promise((t,n)=>{(0,l.exec)(e,e=>{if(e)return n(e);t()})}),b=async(...e)=>{let t=e.map(e=>e.replace(`-D`,``).split(`@`).slice(0,-1).join(`@`).trim()).join(`, `),n=(0,u.default)(`Installing packages: ${t}`).start();await y(`npm install ${e.join(` `)}`),n.succeed(`Installed packages: ${t}`)},x=()=>(0,o.existsSync)((0,s.join)(process.cwd(),`node_modules`,`.bin`,`prettier`));async function S(e){try{if(!x())return;await y(`./node_modules/.bin/prettier --write "${e}"`),t.r.info(`Formatted ${e} with Prettier`)}catch(n){t.r.error(`Error formatting ${e} with Prettier:`,n)}}var C=(e=process.cwd())=>(0,s.join)(e,`.saltyrc.json`),w=async(e=process.cwd())=>await(0,c.readFile)(C(e),`utf-8`).then(JSON.parse).catch(()=>({})),T=async(e=process.cwd())=>(0,c.readFile)(C(e),`utf-8`).catch(()=>void 0),E=async(e=process.cwd())=>(await w(e)).defaultProject,D=(e,t,n,r={})=>{let i=(0,s.join)(t,n.srcDirectory),a={dir:i,framework:n.name,...r};if(e===void 0)return{content:JSON.stringify({$schema:`./node_modules/@salty-css/core/.saltyrc.schema.json`,info:`This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.`,defaultProject:i,projects:[a]},null,2),changed:!0,created:!0};let o=JSON.parse(e),c=o.projects||[];if(c.some(e=>e.dir===i))return{content:e,changed:!1,created:!1};c.push(a),o.projects=[...c];let l=JSON.stringify(o,null,2);return{content:l,changed:l!==e,created:!1}},O=async(e,n,r,i={})=>{let a=C(e),{content:o,changed:s,created:l}=D(await T(e),n,r,i);return s?(l?t.r.info(`Creating file: `+a):t.r.info(`Edit file: `+a),await(0,c.writeFile)(a,o),await S(a),!0):!1},ee=(e,t)=>(e.projects||[]).find(e=>e.dir===t)?.framework,k=(e,t=process.cwd())=>(0,s.join)(t,e===`.`?``:e),A=async e=>{let t=process.cwd(),n=k(e.dir,t),r=(0,s.relative)(t,n)||`.`,i=await m().catch(()=>void 0);if(e.requirePackageJson!==!1&&!i)throw Error(`Salty CSS project must be initialized in a directory with a package.json file.`);return{cwd:t,projectDir:n,relativeProjectPath:r,packageJson:i,rcFile:await w(t),cliVersion:(await g()).version||`0.0.0`,skipInstall:!!e.skipInstall,yes:!!e.yes}},j=(e,r)=>{e.command(`build [directory]`).alias(`b`).description(`Build the Salty-CSS project.`).option(`-d, --dir <dir>`,`Project directory to build the project in.`).option(`--watch`,`Watch for changes and rebuild the project.`).option(`--mode <mode>`,`Build mode: "production" or "development". Defaults to NODE_ENV-based detection.`).action(async function(e=r){t.r.info(`Building the Salty-CSS project...`);let{dir:a=e,watch:s,mode:c}=this.opts();if(c!==void 0&&c!==`production`&&c!==`development`)return t.n(`Invalid --mode "${c}". Expected "production" or "development".`);let l=a??await E();if(!l)return t.n(`Project directory must be provided. Add it as the first argument after build command or use the --dir option.`);let u=k(l),d=new t.t(u,{mode:c});await d.generateCss(),s&&(t.r.info(`Watching for changes in the project directory...`),(0,o.watch)(u,{recursive:!0},async(e,t)=>{if(!t)return console.warn(`File path not provided for change event`);await i.checkShouldRestart(t)?await d.generateCss(!1):n.isSaltyFile(t)&&await d.generateFile(t)}))})},M=[`astro.config.mjs`,`astro.config.ts`,`astro.config.js`,`astro.config.cjs`],N=e=>{for(let t of M){let n=(0,s.join)(e,t);if((0,o.existsSync)(n))return n}return null},te=e=>{let t=e.packageJson;if(!t)return!1;let n={...t.dependencies,...t.devDependencies};return Object.prototype.hasOwnProperty.call(n,`astro`)},P={name:`astro`,srcDirectory:`src`,detect:e=>!!N(e.projectDir)||te(e),runtimePackage:e=>`@salty-css/astro@${e}`,templates:{styled:`astro/styled-file.ts`,component:{styled:`astro/styled-file.ts`,wrapper:`astro/component.astro`,wrapperExt:`.astro`}}},F={name:`react`,srcDirectory:``,detect:()=>!0,runtimePackage:e=>`@salty-css/react@${e}`,templates:{styled:`react/styled-file.ts`,component:{styled:`react/styled-file.ts`,wrapper:`react/vanilla-file.ts`,wrapperExt:`.tsx`}}},I=[P,F],L={astro:P,react:F},R=async e=>{for(let t of I)if(await t.detect(e))return t;return F},z=e=>{if(e)return L[e]},B={"salty.config.ts":()=>Promise.resolve().then(()=>require("./salty.config-B0ZiRpHR.cjs")),"saltygen/index.css":()=>Promise.resolve().then(()=>require("./templates-BGHLaAOm.cjs")),"react/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-BCbAEzBB.cjs")),"react/vanilla-file.ts":()=>Promise.resolve().then(()=>require("./vanilla-file-Z3VsOa_U.cjs")),"astro/styled-file.ts":()=>Promise.resolve().then(()=>require("./styled-file-DorArlCk.cjs")),"astro/component.astro":()=>Promise.resolve().then(()=>require("./astro-component-r0qEcF1p.cjs"))},V=async(e,t)=>{let{default:n}=await B[e]();return{fileName:e,content:d.default.render(n,t)}},H=(e,n)=>{e.command(`generate [file] [directory]`).alias(`g`).description(`Generate a new component file.`).option(`-f, --file <file>`,`File to generate.`).option(`-d, --dir <dir>`,`Project directory to generate the file in.`).option(`-t, --tag <tag>`,`HTML tag of the component.`,`div`).option(`-n, --name <name>`,`Name of the component.`).option(`-c, --className <className>`,`CSS class of the component.`).option(`-r, --reactComponent`,`Generate a wrapper component file alongside the styled definition.`).action(async function(e,i=n){let{file:a=e,dir:o=i,tag:l,name:u,className:d,reactComponent:f=!1}=this.opts();if(!a)return t.n(`File to generate must be provided. Add it as the first argument after generate command or use the --file option.`);if(!o)return t.n(`Project directory must be provided. Add it as the second argument after generate command or use the --dir option.`);let p;try{p=await A({dir:o,requirePackageJson:!1})}catch(e){return t.n(e instanceof Error?e.message:String(e))}let m=z(ee(p.rcFile,p.relativeProjectPath))??await R(p),h=a.split(`/`).slice(0,-1).join(`/`);h&&await(0,c.mkdir)((0,s.join)(p.projectDir,h),{recursive:!0});let g=(0,s.parse)((0,s.join)(p.projectDir,a));g.ext||=`.ts`,g.name.endsWith(`.css`)||(g.name+=`.css`),g.base=g.name+g.ext;let _=(0,s.format)(g);if(await(0,c.readFile)(_,`utf-8`).catch(()=>void 0)!==void 0){t.r.error(`File already exists: `+_);return}let v=r.pascalCase(u||g.base.replace(/\.css\.\w+$/,``));if(f){if(!m.templates.component)return t.n(`--reactComponent is not supported for the ${m.name} framework.`);let e=v+`Component`;v+=`Wrapper`;let n=g.base.replace(/\.css\.\w+$/,``),{content:r}=await V(m.templates.component.wrapper,{tag:l,componentName:e,styledComponentName:v,className:d,fileName:n});g.name=n.replace(/\.css$/,``),g.ext=m.templates.component.wrapperExt,g.base=g.name+g.ext;let i=(0,s.format)(g);t.r.info(`Generating a new file: `+i),await(0,c.writeFile)(i,r),await S(i)}let{content:y}=await V(f&&m.templates.component?m.templates.component.styled:m.templates.styled,{tag:l,name:v,className:d});t.r.info(`Generating a new file: `+_),await(0,c.writeFile)(_,y),await S(_)})},U=e=>{let t=e.trim();return t.startsWith(`-D `)?`${t.slice(3).trim()} (dev)`:t},W=e=>e.map(e=>` + ${U(e)}`).join(`
|
|
2
2
|
`),G=async(e,t,n={})=>{if(t||e.length===0)return;let r=n.input??process.stdin,i=n.output??process.stdout;if(!(n.isTTY??process.stdin.isTTY??!1))throw Error(`Cannot prompt for install confirmation: stdin is not a TTY. Re-run with --yes to install the listed packages without prompting.`);i.write(`The following packages will be installed:\n${W(e)}\n`);let a=(0,f.createInterface)({input:r,output:i,terminal:!1});try{let e=(await a.question(`Proceed? (y/N) `)).trim().toLowerCase();if(e!==`y`&&e!==`yes`)throw Error(`Install cancelled by user.`)}finally{a.close()}},K=async(e,t={})=>{if(t.yes)return!0;let n=t.input??process.stdin,r=t.output??process.stdout;if(!(t.isTTY??process.stdin.isTTY??!1))return!1;let i=t.defaultYes?`(Y/n)`:`(y/N)`,a=(0,f.createInterface)({input:n,output:r,terminal:!1});try{let n=(await a.question(`${e} ${i} `)).trim().toLowerCase();return n===``?!!t.defaultYes:n===`y`||n===`yes`}finally{a.close()}},q=[`src`,`public`,`assets`,`styles`,`css`,`app`],J=[`styles`,`css`,`app`,`pages`],Y=[`index`,`styles`,`main`,`app`,`global`,`globals`],X=[`.css`,`.scss`,`.sass`],Z=async e=>{for(let t of q)for(let n of Y)for(let r of X){let i=(0,s.join)(e,t,n+r);if(await(0,c.readFile)(i,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,i);for(let i of J){let a=(0,s.join)(e,t,i,n+r);if(await(0,c.readFile)(a,`utf-8`).catch(()=>void 0)!==void 0)return(0,s.relative)(e,a)}}},Q=e=>`@salty-css/astro@${e}`,ne=`import saltyIntegration from '@salty-css/astro/integration';
|
|
3
3
|
`,re=e=>{if(e.includes(`@salty-css/astro`))return{content:null};let t=e,n=!1;return/integrations\s*:\s*\[/.test(t)?(t=t.replace(/integrations\s*:\s*\[/,e=>`${e}saltyIntegration(),`),n=!0):/defineConfig\s*\(\s*\{/.test(t)&&(t=t.replace(/defineConfig\s*\(\s*\{/,e=>`${e}\n integrations: [saltyIntegration()],`),n=!0),n?{content:ne+t}:{content:null,warning:`Could not find a place to add saltyIntegration() in the Astro config. Please add it manually.`}},ie={name:`astro`,detect:e=>N(e.projectDir),plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return null;let i=re(r);if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[`-D ${Q(e.cliVersion)}`],execute:async()=>(t.r.info(`Adding Salty-CSS integration to Astro config: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},ae=[[`projectJs`,`eslint.config.js`],[`rootJs`,`eslint.config.js`],[`projectMjs`,`eslint.config.mjs`],[`rootMjs`,`eslint.config.mjs`],[`projectJson`,`.eslintrc.json`],[`rootJson`,`.eslintrc.json`]],oe=(e,t)=>ae.map(([n,r])=>(0,s.join)(n.startsWith(`root`)?t:e,r)),se=(e,t)=>{if(e.includes(`salty-css`))return{content:null};if(t){let t=`import saltyCss from "@salty-css/eslint-config-core/flat";\n${e}`;if(e.includes(`typescript-eslint`))if(t.includes(`.config(`))t=t.replace(`.config(`,`.config(saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};else if(t.includes(`export default [`))t=t.replace(`export default [`,`export default [ saltyCss,`);else if(t.includes(`eslintConfig = [`))t=t.replace(`eslintConfig = [`,`eslintConfig = [ saltyCss,`);else return{content:null,warning:`Could not find the correct place to add the Salty-CSS config for ESLint. Please add it manually.`};return{content:t}}let n=JSON.parse(e);return n.extends||=[],n.extends.includes(`@salty-css/core`)||n.extends.push(`@salty-css/core`),{content:JSON.stringify(n,null,2)}},ce={name:`eslint`,detect:e=>oe(e.projectDir,e.cwd).find(e=>(0,o.existsSync)(e))??null,plan:async(e,n)=>{let r=await(0,c.readFile)(n,`utf-8`).catch(()=>void 0);if(r===void 0)return t.r.error(`Could not read ESLint config file.`),null;let i=se(r,n.endsWith(`js`));if(i.warning&&t.r.warn(i.warning),i.content===null)return null;let a=i.content;return{packages:[_.eslintConfigCore(e.cliVersion)],execute:async()=>(t.r.info(`Edit file: `+n),await(0,c.writeFile)(n,a),await S(n),{changed:!0})}}},le=[`next.config.js`,`next.config.cjs`,`next.config.ts`,`next.config.mjs`],ue=e=>`@salty-css/next@${e}`,de=e=>{if(e.includes(`withSaltyCss`))return{content:null};let t=e,n=!1;/\splugins([^=]*)=[^[]\[/.test(t)&&(t=t.replace(/\splugins([^=]*)=[^[]\[/,(e,t)=>` plugins${t}= [withSaltyCss,`),n=!0);let r=t.includes(`module.exports`),i=r?`const { withSaltyCss } = require('@salty-css/next');
|
|
4
4
|
`:`import { withSaltyCss } from '@salty-css/next';
|
|
@@ -244,7 +244,7 @@ var X = {
|
|
|
244
244
|
let A = c.map((e) => `@import url('./css/${e}');`).join("\n"), j = `/*!
|
|
245
245
|
* Generated with Salty CSS (https://salty-css.dev)
|
|
246
246
|
* Do not edit this file directly
|
|
247
|
-
* Version 0.4.
|
|
247
|
+
* Version 0.4.4-alpha.0
|
|
248
248
|
*/
|
|
249
249
|
@layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[
|
|
250
250
|
"_imports.css",
|
|
@@ -3,7 +3,7 @@ const e=require("./chunk-CMqjfN_6.cjs"),t=require("./compiler/helpers.cjs"),n=re
|
|
|
3
3
|
`),S=`/*!
|
|
4
4
|
* Generated with Salty CSS (https://salty-css.dev)
|
|
5
5
|
* Do not edit this file directly
|
|
6
|
-
* Version 0.4.
|
|
6
|
+
* Version 0.4.4-alpha.0
|
|
7
7
|
*/
|
|
8
8
|
@layer imports, reset, global, templates, fonts, l0, l1, l2, l3, l4, l5, l6, l7, l8;\n\n${[`_imports.css`,`_variables.css`,`_reset.css`,`_global.css`,`_templates.css`,`_fonts.css`].filter(e=>{try{return(0,c.readFileSync)((0,u.join)(o,`css`,e),`utf8`).length>0}catch{return!1}}).map(e=>`@import url('./css/${e}')${e===`_imports.css`?` layer(imports)`:``};`).join(`
|
|
9
9
|
`)}\n${x}`;if(y.importStrategy!==`component`){let e=a.reduce((e,t,r)=>{let i=t.reduce((e,t)=>{let r=(0,u.join)(o,`css`,t),i=(0,c.readFileSync)(r,`utf8`),a=/.*-([^-]+)-\d+.css/.exec(t)?.at(1)||n.toHash(r,6);return e.includes(a)?e:`${e}\n/*start:${a}-${t}*/\n${i}\n/*end:${a}*/\n`},``),a=`l_${r}.css`;return(0,c.writeFileSync)((0,u.join)(o,`css`,a),`@layer l${r} { ${i}\n }`),`${e}\n@import url('./css/${a}');`},``);S+=e}(0,c.writeFileSync)(s,S);let C=Date.now()-r,w=C<200?`🔥`:C<500?`🚀`:C<1e3?`🎉`:C<2e3?`🚗`:C<5e3?`🤔`:`🥴`;h.info(`Generated CSS in ${C}ms! ${w}`)}catch(e){console.error(e)}};generateConfigStyles=async e=>{let t=await this.getDestDir(),o={mediaQueries:[],globalStyles:[],variables:[],templates:[],imports:[],fonts:[]};await Promise.all([...e].map(async e=>{let{contents:n,outputFilePath:r}=await this.compileSaltyFile(e,t);Object.entries(n).forEach(([t,n])=>{n.isMedia?o.mediaQueries.push([t,n]):n.isGlobalDefine?o.globalStyles.push(n):n.isDefineVariables?o.variables.push(n):n.isDefineTemplates?o.templates.push(n._setPath(`${t};;${r}`)):n.isDefineImport?o.imports.push(n._setPath(e)):n.isDefineFont&&o.fonts.push(n)})}));let{config:l,path:d}=await this.generateConfig(),f={...l},{mediaQueries:p}=o;f.mediaQueries=Object.fromEntries(p.map(([e,t])=>[`@${e}`,t]));let m=p.map(([e])=>`'@${e}'`).join(` | `),g=new Set,_=async(e,t=[])=>{if(!e)return[];let r=Object.entries(e).map(async([e,r])=>{let a=async r=>{if(!r)return;if(r instanceof Promise)return await a(await r);if(typeof r==`function`)return await a(await r());if(typeof r==`object`)return await _(r,[...t,e]);let o=O(e),s=n.dashCase(e),c=[...t,o].join(`.`);g.add(`"${c}"`);let l=[...t.map(n.dashCase),s].join(`-`),u=i.s(r);return u?`--${l}: ${u.transformed};`:`--${l}: ${r};`};return await a(r)});return(await Promise.all(r)).flat()},v=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=await _(t);return e===`base`?n.join(``):f.mediaQueries[e]?`${f.mediaQueries[e]} { ${n.join(``)} }`:`${e} { ${n.join(``)} }`});return(await Promise.all(t)).flat()},y=async e=>{if(!e)return[];let t=Object.entries(e).map(async([e,t])=>{let n=Object.entries(t).map(async([t,n])=>{let r=await _(n,[e]);return`${`.${e}-${t}, [data-${e}="${t}"]`} { ${r.join(``)} }`});return(await Promise.all(n)).flat()});return(await Promise.all(t)).flat()},b=(e={})=>({...e,responsive:void 0,conditional:void 0}),x=e=>o.variables.map(t=>e===`static`?b(t._current):t._current[e]),S=a.mergeObjects(b(l.variables),x(`static`)),C=await _(S),T=await v(a.mergeObjects(l.variables?.responsive,x(`responsive`))),E=await y(a.mergeObjects(l.variables?.conditional,x(`conditional`)));(0,c.writeFileSync)((0,u.join)(t,`css/_variables.css`),`:root { ${C.join(``)} ${T.join(``)} } ${E.join(``)}`),f.staticVariables=S,(0,c.writeFileSync)((0,u.join)(t,`css/_global.css`),`@layer global { ${await i.t(a.mergeObjects(l.global,o.globalStyles),``)} }`);let D=(0,u.join)(t,`css/_reset.css`);(0,c.writeFileSync)(D,`@layer reset { ${await i.t(l.reset===`none`?{}:typeof l.reset==`object`?l.reset:k,``)} }`);let A=(0,u.join)(t,`css/_templates.css`),j=a.mergeObjects(l.templates,o.templates),M=await s.parseTemplates(j),N=s.getTemplateTypes(j),P=s.getTemplateVariantMaps(j);(0,c.writeFileSync)(A,`@layer templates { ${M} }`),f.templates=j;let F=(0,u.join)(t,`css/_imports.css`),I=[];for(let e of o.imports){let n=e._path;if(n)for(let r of e._current)try{let{rule:e}=w(r,n,t);I.push(e)}catch(e){let t=typeof r==`string`?r:r.url;h.error(`Failed to resolve defineImport(${JSON.stringify(t)}) from ${n}: ${e.message}`)}}(0,c.writeFileSync)(F,I.join(`
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/margarita-form/salty-css/issues"
|
|
17
17
|
},
|
|
18
|
-
"version": "0.4.
|
|
18
|
+
"version": "0.4.4-alpha.0",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "vite build",
|
|
@@ -32,6 +32,14 @@
|
|
|
32
32
|
"typescript": ">=5.x",
|
|
33
33
|
"winston": ">=3.x"
|
|
34
34
|
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@typescript/typescript6": ">=6.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@typescript/typescript6": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
35
43
|
"nx": {
|
|
36
44
|
"targets": {
|
|
37
45
|
"build": {
|