@salty-css/next 0.1.0-alpha.33 → 0.1.0-alpha.35

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 CHANGED
@@ -617,6 +617,8 @@ And note: steps 2 & 3 are just to show how get new components up and running, st
617
617
  - **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
618
618
  - **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
619
619
 
620
+ Both Webpack and Turbopack are supported. `withSaltyCss` auto-detects which bundler Next.js is using (`next dev --turbopack` sets `process.env.TURBOPACK=1`), so no extra config is required. To force a specific bundler, pass `{ bundler: 'webpack' | 'turbopack' }` as the second argument.
621
+
620
622
  4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
621
623
  5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
622
624
  6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
@@ -0,0 +1,12 @@
1
+ import { SaltyCompilerMode } from '@salty-css/core/compiler/salty-compiler';
2
+ export type Bundler = 'webpack' | 'turbopack';
3
+ export type BundlerOption = Bundler | 'auto';
4
+ export declare const resolveBundler: (option: BundlerOption | undefined) => Bundler;
5
+ export type TurbopackLoaderRule = {
6
+ loaders: Array<{
7
+ loader: string;
8
+ options: Record<string, unknown>;
9
+ }>;
10
+ as: string;
11
+ };
12
+ export declare const buildSaltyTurbopackRules: (dir: string, mode?: SaltyCompilerMode) => Record<string, TurbopackLoaderRule>;
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("@salty-css/webpack"),s=(a,u={})=>{const{webpack:e,...i}=a;return{...i,webpack(t,r){const{dir:l,isServer:c}=r;return n.saltyPlugin(t,l,c,!1,{mode:u.mode}),e&&typeof e=="function"&&e(t,r),t}}};exports.default=s;exports.withSaltyCss=s;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("@salty-css/core/compiler/helpers"),d=require("@salty-css/webpack"),b=require("fs"),p=require("path"),y=require("@salty-css/core/compiler/salty-compiler"),k=require("@salty-css/core/server"),m=e=>e&&e!=="auto"?e:process.env.TURBOPACK!==void 0?"turbopack":"webpack",w=(e,t)=>{const r={},s={dir:e};t!==void 0&&(s.mode=t);const o={loader:"@salty-css/webpack/loader",options:s};for(const a of u.saltyFileExtensions)r[`**/*.${a}.ts`]={loaders:[o],as:"*.ts"},r[`**/*.${a}.tsx`]={loaders:[o],as:"*.tsx"};return r},f=(e,t={})=>{const{webpack:r,...s}=e;return{...s,webpack(o,a){const{dir:c,isServer:l}=a;return d.saltyPlugin(o,c,l,!1,{mode:t.mode}),r&&typeof r=="function"&&r(o,a),o}}},n=new Map,h=(e,t)=>{const r=`${e}|${t??""}`;if(n.get(r))return;n.set(r,!0);const s=new y.SaltyCompiler(e,{mode:t});s.generateCss().then(()=>{b.watch(e,{recursive:!0},async(o,a)=>{if(!a)return;const c=p.resolve(e,a.toString());await k.checkShouldRestart(c)?await s.generateCss():u.isSaltyFile(c)&&await s.generateFile(c)})}).catch(o=>{n.set(r,!1),console.error("[salty-css/next] failed to initialize Turbopack runtime:",o)})},S=(e,t={})=>{const r=e.turbopack??{},s=t.dir??r.root??process.cwd(),o=w(s,t.mode),c={...r.rules??{},...o};return h(s,t.mode),{...e,turbopack:{...r,rules:c}}},i=(e,t={})=>m(t.bundler)==="turbopack"?S(e,{mode:t.mode,dir:t.dir}):f(e,{mode:t.mode});exports.default=i;exports.withSaltyCss=i;
package/index.d.ts CHANGED
@@ -1,12 +1,30 @@
1
1
  import { SaltyCompilerMode } from '@salty-css/core/compiler/salty-compiler';
2
+ import { BundlerOption } from './detect-bundler';
2
3
  type AnyRecord = Record<any, any>;
4
+ export type { Bundler, BundlerOption } from './detect-bundler';
3
5
  export interface SaltyNextOptions {
4
6
  /**
5
7
  * Explicit build mode. Defaults to NODE_ENV-based detection.
6
8
  */
7
9
  mode?: SaltyCompilerMode;
10
+ /**
11
+ * Force a specific bundler integration. Defaults to 'auto', which picks
12
+ * turbopack when `process.env.TURBOPACK === '1'` (set by `next dev --turbopack`)
13
+ * and webpack otherwise.
14
+ */
15
+ bundler?: BundlerOption;
16
+ /**
17
+ * Project root directory used by the Turbopack runtime (the webpack path
18
+ * receives `dir` from Next.js itself). Defaults to `nextConfig.turbopack.root`
19
+ * or `process.cwd()`.
20
+ */
21
+ dir?: string;
8
22
  }
9
- export declare const withSaltyCss: <T extends AnyRecord>(nextConfig: T, saltyOptions?: SaltyNextOptions) => Omit<T, "webpack"> & {
10
- webpack(config: any, options: any): any;
11
- };
23
+ export declare const withSaltyCss: <T extends AnyRecord>(nextConfig: T, options?: SaltyNextOptions) => (T & {
24
+ turbopack: {
25
+ rules: any;
26
+ };
27
+ }) | (Omit<T, "webpack"> & {
28
+ webpack(config: any, webpackOptions: any): any;
29
+ });
12
30
  export default withSaltyCss;
package/index.js CHANGED
@@ -1,15 +1,50 @@
1
- import { saltyPlugin as i } from "@salty-css/webpack";
2
- const m = (s, a = {}) => {
3
- const { webpack: e, ...n } = s;
1
+ import { saltyFileExtensions as u, isSaltyFile as i } from "@salty-css/core/compiler/helpers";
2
+ import { saltyPlugin as d } from "@salty-css/webpack";
3
+ import { watch as m } from "fs";
4
+ import { resolve as p } from "path";
5
+ import { SaltyCompiler as b } from "@salty-css/core/compiler/salty-compiler";
6
+ import { checkShouldRestart as f } from "@salty-css/core/server";
7
+ const k = (e) => e && e !== "auto" ? e : process.env.TURBOPACK !== void 0 ? "turbopack" : "webpack", y = (e, t) => {
8
+ const r = {}, s = { dir: e };
9
+ t !== void 0 && (s.mode = t);
10
+ const o = { loader: "@salty-css/webpack/loader", options: s };
11
+ for (const a of u)
12
+ r[`**/*.${a}.ts`] = { loaders: [o], as: "*.ts" }, r[`**/*.${a}.tsx`] = { loaders: [o], as: "*.tsx" };
13
+ return r;
14
+ }, w = (e, t = {}) => {
15
+ const { webpack: r, ...s } = e;
4
16
  return {
5
- ...n,
6
- webpack(t, r) {
7
- const { dir: o, isServer: c } = r;
8
- return i(t, o, c, !1, { mode: a.mode }), e && typeof e == "function" && e(t, r), t;
17
+ ...s,
18
+ webpack(o, a) {
19
+ const { dir: c, isServer: l } = a;
20
+ return d(o, c, l, !1, { mode: t.mode }), r && typeof r == "function" && r(o, a), o;
9
21
  }
10
22
  };
11
- };
23
+ }, n = /* @__PURE__ */ new Map(), h = (e, t) => {
24
+ const r = `${e}|${t ?? ""}`;
25
+ if (n.get(r)) return;
26
+ n.set(r, !0);
27
+ const s = new b(e, { mode: t });
28
+ s.generateCss().then(() => {
29
+ m(e, { recursive: !0 }, async (o, a) => {
30
+ if (!a) return;
31
+ const c = p(e, a.toString());
32
+ await f(c) ? await s.generateCss() : i(c) && await s.generateFile(c);
33
+ });
34
+ }).catch((o) => {
35
+ n.set(r, !1), console.error("[salty-css/next] failed to initialize Turbopack runtime:", o);
36
+ });
37
+ }, S = (e, t = {}) => {
38
+ const r = e.turbopack ?? {}, s = t.dir ?? r.root ?? process.cwd(), o = y(s, t.mode), c = { ...r.rules ?? {}, ...o };
39
+ return h(s, t.mode), {
40
+ ...e,
41
+ turbopack: {
42
+ ...r,
43
+ rules: c
44
+ }
45
+ };
46
+ }, C = (e, t = {}) => k(t.bundler) === "turbopack" ? S(e, { mode: t.mode, dir: t.dir }) : w(e, { mode: t.mode });
12
47
  export {
13
- m as default,
14
- m as withSaltyCss
48
+ C as default,
49
+ C as withSaltyCss
15
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/next",
3
- "version": "0.1.0-alpha.33",
3
+ "version": "0.1.0-alpha.35",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "0.1.0-alpha.33",
38
- "@salty-css/webpack": "0.1.0-alpha.33"
37
+ "@salty-css/core": "0.1.0-alpha.35",
38
+ "@salty-css/webpack": "0.1.0-alpha.35"
39
39
  }
40
40
  }
@@ -0,0 +1,13 @@
1
+ import { SaltyCompilerMode } from '@salty-css/core/compiler/salty-compiler';
2
+ type AnyRecord = Record<any, any>;
3
+ export interface SaltyTurbopackWrapperOptions {
4
+ mode?: SaltyCompilerMode;
5
+ dir?: string;
6
+ }
7
+ export declare const __resetSaltyTurbopackRuntimeForTests: () => void;
8
+ export declare const withSaltyTurbopack: <T extends AnyRecord>(nextConfig: T, options?: SaltyTurbopackWrapperOptions) => T & {
9
+ turbopack: {
10
+ rules: any;
11
+ };
12
+ };
13
+ export {};
@@ -0,0 +1,9 @@
1
+ import { SaltyCompilerMode } from '@salty-css/core/compiler/salty-compiler';
2
+ type AnyRecord = Record<any, any>;
3
+ export interface SaltyWebpackWrapperOptions {
4
+ mode?: SaltyCompilerMode;
5
+ }
6
+ export declare const withSaltyWebpack: <T extends AnyRecord>(nextConfig: T, options?: SaltyWebpackWrapperOptions) => Omit<T, "webpack"> & {
7
+ webpack(config: any, webpackOptions: any): any;
8
+ };
9
+ export {};