tailwind-styled-v4 5.0.7 → 5.0.8

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/dist/next.mjs CHANGED
@@ -114,7 +114,7 @@ function resolveLoaderPath(loaderBasename, importMetaUrl) {
114
114
  }).path;
115
115
  }
116
116
 
117
- // packages/domain/shared/src/native-resolution.ts
117
+ // packages/domain/shared/src/index.ts
118
118
  var isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
119
119
  var nodeModuleRef = null;
120
120
  function getNodeModuleRef() {
@@ -129,211 +129,17 @@ function getNodeModuleRef() {
129
129
  return null;
130
130
  }
131
131
  }
132
- var _nodeFs = null;
133
- var _nodePath = null;
134
- var _require = null;
135
- function getNodeFs() {
136
- if (isBrowser2) return { existsSync: () => false };
137
- const nodeRequire = getNodeModuleRef();
138
- if (!nodeRequire) return { existsSync: () => false };
139
- if (!_nodeFs) _nodeFs = nodeRequire.createRequire(import.meta.url)("node:fs");
140
- return _nodeFs;
141
- }
142
- function getNodePath() {
143
- if (isBrowser2) return { resolve: () => "", dirname: "" };
144
- const nodeRequire = getNodeModuleRef();
145
- if (!nodeRequire) return { resolve: () => "", dirname: "" };
146
- if (!_nodePath) _nodePath = nodeRequire.createRequire(import.meta.url)("node:path");
147
- return _nodePath;
148
- }
149
- function getRequire(_importMetaUrl) {
150
- if (isBrowser2) return () => {
151
- throw new Error("node:module not available");
152
- };
153
- const nodeRequire = getNodeModuleRef();
154
- if (!nodeRequire) return () => {
155
- throw new Error("require not available");
156
- };
157
- if (!_require) _require = nodeRequire.createRequire(_importMetaUrl);
158
- return _require;
159
- }
160
- var PLATFORM_MAP = {
161
- "linux-x64": ["@tailwind-styled/native-linux-x64"],
162
- "linux-arm64": ["@tailwind-styled/native-linux-arm64"],
163
- "darwin-x64": ["@tailwind-styled/native-darwin-x64"],
164
- "darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
165
- "win32-x64": ["@tailwind-styled/native-win32-x64"],
166
- "win32-arm64": ["@tailwind-styled/native-win32-arm64"]
167
- };
168
- function platformKey() {
169
- if (isBrowser2) return "browser";
170
- return `${process.platform}-${process.arch}`;
171
- }
172
- function resolveNativeBinary(runtimeDir) {
173
- const platform = platformKey();
174
- const tried = [];
175
- if (isBrowser2) {
176
- return { path: null, source: "not-found", platform, tried: ["not available in browser"] };
177
- }
178
- const fs2 = getNodeFs();
179
- const path2 = getNodePath();
180
- const _req = getRequire(import.meta.url);
181
- const envPath = process.env.TW_NATIVE_PATH?.trim();
182
- if (envPath) {
183
- if (fs2.existsSync(envPath)) {
184
- return { path: envPath, source: "env", platform, tried };
185
- }
186
- tried.push(`env:${envPath} (not found)`);
187
- }
188
- if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1" || process.env.TWS_DISABLE_NATIVE === "1") {
189
- return { path: null, source: "not-found", platform, tried: ["disabled by env"] };
190
- }
191
- const prebuiltPkgs = PLATFORM_MAP[platform] ?? [];
192
- for (const pkg of prebuiltPkgs) {
193
- try {
194
- const candidate = _req.resolve(`${pkg}/tailwind_styled_parser.node`);
195
- if (fs2.existsSync(candidate)) {
196
- return { path: candidate, source: "prebuilt", platform, tried };
197
- }
198
- tried.push(`prebuilt:${pkg} (resolved but missing)`);
199
- } catch {
200
- tried.push(`prebuilt:${pkg} (not installed)`);
201
- }
202
- }
203
- const cwd = process.cwd();
204
- const base = runtimeDir ?? cwd;
205
- const localCandidates = [
206
- path2.resolve(base, "tailwind_styled_parser.node"),
207
- path2.resolve(base, "..", "tailwind_styled_parser.node"),
208
- path2.resolve(cwd, "native", "tailwind_styled_parser.node"),
209
- path2.resolve(cwd, "native", "target", "release", "tailwind_styled_parser.node"),
210
- // napi-rs conventional output
211
- path2.resolve(base, `tailwind_styled_parser.${platform}.node`)
212
- ];
213
- for (const candidate of localCandidates) {
214
- tried.push(`local:${candidate}`);
215
- if (fs2.existsSync(candidate)) {
216
- return { path: candidate, source: "local", platform, tried };
217
- }
218
- }
219
- return { path: null, source: "not-found", platform, tried };
220
- }
221
-
222
- // packages/domain/shared/src/index.ts
223
- var isBrowser3 = typeof window !== "undefined" || typeof document !== "undefined";
224
- var nodeModuleRef2 = null;
225
- function getNodeModuleRef2() {
226
- if (isBrowser3) return null;
227
- if (nodeModuleRef2 !== null) return nodeModuleRef2;
228
- try {
229
- const test = typeof __require === "function" ? __require("module") : null;
230
- nodeModuleRef2 = test;
231
- return test;
232
- } catch {
233
- nodeModuleRef2 = null;
234
- return null;
235
- }
236
- }
237
- var _nodeUrl = null;
238
- function getNodeUrl() {
239
- if (isBrowser3) throw new Error("node:url not available in browser");
240
- const nodeRequire = getNodeModuleRef2();
241
- if (!nodeRequire) throw new Error("require not available");
242
- if (!_nodeUrl) _nodeUrl = nodeRequire.createRequire(import.meta.url)("node:url");
243
- return _nodeUrl;
244
- }
245
- function getRequire2() {
246
- if (isBrowser3) return (() => {
132
+ function getRequire() {
133
+ if (isBrowser2) return (() => {
247
134
  throw new Error("require not available in browser");
248
135
  });
249
- const nodeRequire = getNodeModuleRef2();
136
+ const nodeRequire = getNodeModuleRef();
250
137
  if (!nodeRequire) return (() => {
251
138
  throw new Error("require not available");
252
139
  });
253
140
  return nodeRequire.createRequire(import.meta.url);
254
141
  }
255
- getRequire2();
256
- function resolveRuntimeDir(dir, importMetaUrl) {
257
- if (isBrowser3) return "";
258
- try {
259
- return getNodeUrl().fileURLToPath(importMetaUrl);
260
- } catch {
261
- return process.cwd();
262
- }
263
- }
264
- var log = (...args) => {
265
- if (process.env.DEBUG?.includes("compiler:native")) {
266
- console.log("[compiler:native]", ...args);
267
- }
268
- };
269
- var NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
270
- var nativeBridge = null;
271
- var bridgeLoadAttempted = false;
272
- var bridgeLoadError = null;
273
- var isValidNativeBridge = (mod) => {
274
- const m = mod;
275
- return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
276
- };
277
- var getNativeBridge = () => {
278
- if (nativeBridge) {
279
- return nativeBridge;
280
- }
281
- if (bridgeLoadAttempted) {
282
- if (bridgeLoadError) {
283
- throw bridgeLoadError;
284
- }
285
- throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
286
- }
287
- bridgeLoadAttempted = true;
288
- try {
289
- const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
290
- const require3 = createRequire(import.meta.url);
291
- const result = resolveNativeBinary(runtimeDir);
292
- if (result.path && result.path.endsWith(".node")) {
293
- try {
294
- const binding = require3(result.path);
295
- if (isValidNativeBridge(binding)) {
296
- nativeBridge = binding;
297
- log("Native bridge loaded successfully from:", result.path);
298
- return nativeBridge;
299
- }
300
- } catch (e) {
301
- log("Failed to require native binding:", e);
302
- }
303
- }
304
- throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
305
-
306
- Tried paths: ${result.tried.join("\n")}`);
307
- } catch (err) {
308
- bridgeLoadError = err instanceof Error ? err : new Error(String(err));
309
- log("Failed to load native bridge:", bridgeLoadError.message);
310
- throw bridgeLoadError;
311
- }
312
- };
313
-
314
- // packages/domain/compiler/src/index.ts
315
- var compileCssFromClasses = (classes, prefix) => {
316
- const native = getNativeBridge();
317
- if (!native?.transformSource) {
318
- throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
319
- }
320
- const result = native.transformSource(classes.join(" "), { prefix: "" });
321
- if (!result) {
322
- throw new Error("FATAL: transformSource returned null");
323
- }
324
- return result;
325
- };
326
- var buildStyleTag = (classes) => {
327
- const result = compileCssFromClasses(classes);
328
- return result?.code ? `<style data-tailwind-styled>${result.code}</style>` : "";
329
- };
330
- var _routeClassMap = /* @__PURE__ */ new Map();
331
- var getAllRouteClasses = () => {
332
- return new Map(_routeClassMap);
333
- };
334
- var clearRouteClasses = () => {
335
- _routeClassMap.clear();
336
- };
142
+ getRequire();
337
143
 
338
144
  // packages/presentation/next/src/withTailwindStyled.ts
339
145
  function getDirnameFromUrl2(importMetaUrl) {
@@ -350,12 +156,12 @@ function getDirnameFromUrl2(importMetaUrl) {
350
156
  return lastSlash > 0 ? importMetaUrl.slice(0, lastSlash) : "";
351
157
  }
352
158
  var require2 = createRequire(import.meta.url);
353
- var resolveRuntimeDir2 = () => getDirnameFromUrl2(import.meta.url);
159
+ var resolveRuntimeDir = () => getDirnameFromUrl2(import.meta.url);
354
160
  var resolveLoaderPath2 = (basename) => {
355
161
  try {
356
162
  return resolveLoaderPath(basename, import.meta.url);
357
163
  } catch {
358
- const runtimeDir = resolveRuntimeDir2();
164
+ const runtimeDir = resolveRuntimeDir();
359
165
  const candidates = [
360
166
  path.resolve(runtimeDir, `${basename}.mjs`),
361
167
  path.resolve(runtimeDir, `${basename}.js`),
@@ -442,15 +248,14 @@ var applyWebpackRule = (config, options, loaderPath) => {
442
248
  "@tailwind-styled/theme",
443
249
  "@tailwind-styled/preset"
444
250
  ];
445
- const configAny = config;
446
- if (!configAny.externals) {
447
- configAny.externals = [];
251
+ if (!config.externals) {
252
+ config.externals = [];
448
253
  }
449
- const ext = configAny.externals;
254
+ const ext = config.externals;
450
255
  if (Array.isArray(ext)) {
451
256
  externalPackages.forEach((pkg) => {
452
257
  const found = ext.find(
453
- (e) => typeof e === "string" && e.includes(pkg) || typeof e === "object" && e !== null && Object.keys(e).some((k) => k.includes(pkg))
258
+ (e) => typeof e === "string" && e.includes(pkg) || typeof e === "object" && e !== null && !Array.isArray(e) && Object.keys(e).some((k) => k.includes(pkg))
454
259
  );
455
260
  if (!found) {
456
261
  ext.push(pkg);
@@ -470,9 +275,10 @@ var mergeTurbopackRules = (existingRules, nextRules) => {
470
275
  if (typeof current === "object" && current !== null && "loaders" in current) {
471
276
  const typedCurrent = current;
472
277
  if (Array.isArray(typedCurrent.loaders)) {
278
+ const incomingLoaders = incomingRule.loaders ?? [];
473
279
  merged[pattern] = {
474
280
  ...current,
475
- loaders: [...typedCurrent.loaders, ...incomingRule.loaders]
281
+ loaders: [...typedCurrent.loaders, ...incomingLoaders]
476
282
  };
477
283
  console.warn(
478
284
  `[tailwind-styled] Turbopack rule '${pattern}' already exists. Appending tailwind-styled loader.`
@@ -487,96 +293,6 @@ var mergeTurbopackRules = (existingRules, nextRules) => {
487
293
  }
488
294
  return merged;
489
295
  };
490
- function escapeClassName(cls) {
491
- return cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1");
492
- }
493
- var TwSafelistDevPlugin = class {
494
- outputPath;
495
- lastHash = "";
496
- constructor(cwd) {
497
- this.outputPath = path.resolve(cwd, ".next", "tw-classes", "_webpack-merged.css");
498
- }
499
- apply(compiler) {
500
- const resetClasses = () => {
501
- try {
502
- clearRouteClasses();
503
- } catch {
504
- }
505
- };
506
- compiler.hooks.watchRun.tap("TwSafelistDevPlugin", resetClasses);
507
- compiler.hooks.beforeRun.tap("TwSafelistDevPlugin", resetClasses);
508
- compiler.hooks.afterCompile.tap("TwSafelistDevPlugin", () => {
509
- try {
510
- const routeMap = getAllRouteClasses();
511
- const allClasses = /* @__PURE__ */ new Set();
512
- for (const classes of routeMap.values()) {
513
- for (const cls of classes) allClasses.add(cls);
514
- }
515
- if (allClasses.size === 0) return;
516
- const sorted = [...allClasses].sort();
517
- const hash = sorted.join(",");
518
- if (hash === this.lastHash) return;
519
- this.lastHash = hash;
520
- const css = [
521
- "/* tailwind-styled-v4 safelist \u2014 auto-generated, do not edit */",
522
- "/* @tw-safelist */",
523
- ".tw-safelist {",
524
- sorted.map((cls) => ` /* ${cls} */`).join("\n"),
525
- "}",
526
- // Juga emit sebagai @layer utilities agar v4 langsung generate
527
- "@layer utilities {",
528
- sorted.map((cls) => `.${escapeClassName(cls)} {}`).join("\n"),
529
- "}"
530
- ].join("\n");
531
- const dir = path.dirname(this.outputPath);
532
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
533
- fs.writeFileSync(this.outputPath, css, "utf-8");
534
- } catch {
535
- }
536
- });
537
- }
538
- };
539
- var TwCssManifestPlugin = class {
540
- apply(compiler) {
541
- compiler.hooks.emit.tapAsync("TwCssManifestPlugin", async (compilation, callback) => {
542
- if (compiler.options?.mode === "development") {
543
- callback();
544
- return;
545
- }
546
- try {
547
- const routeMap = getAllRouteClasses();
548
- if (routeMap.size === 0) {
549
- callback();
550
- return;
551
- }
552
- const manifest = {};
553
- for (const [route, classes] of routeMap.entries()) {
554
- if (classes.size === 0) continue;
555
- let css = "";
556
- try {
557
- css = buildStyleTag(Array.from(classes)).replace(/<style[^>]*>/, "").replace(/<\/style>/, "").trim();
558
- } catch {
559
- }
560
- if (!css) continue;
561
- const filename = route === "/" ? "index.css" : route === "__global" ? "_global.css" : `${route.replace(/^\//, "").replace(/\//g, "_")}.css`;
562
- const outputPath = `static/css/tw/${filename}`;
563
- compilation.assets[outputPath] = {
564
- source: () => css,
565
- size: () => css.length
566
- };
567
- manifest[route] = filename;
568
- }
569
- const manifestJson = JSON.stringify({ routes: manifest }, null, 2);
570
- compilation.assets["static/css/tw/css-manifest.json"] = {
571
- source: () => manifestJson,
572
- size: () => manifestJson.length
573
- };
574
- } catch {
575
- }
576
- callback();
577
- });
578
- }
579
- };
580
296
  function withTailwindStyled(options = {}) {
581
297
  checkNextVersion();
582
298
  const normalizedOptions = parseNextAdapterOptions(options);
@@ -585,12 +301,6 @@ function withTailwindStyled(options = {}) {
585
301
  return function wrap(nextConfig = {}) {
586
302
  const previousWebpack = nextConfig.webpack;
587
303
  const loaderOptions = createLoaderOptions(normalizedOptions);
588
- const safelistPath = path.resolve(
589
- typeof process !== "undefined" ? process.cwd() : "",
590
- ".next",
591
- "tailwind-styled-safelist.css"
592
- // used as anchor; loader derives tw-classes/ from dirname
593
- );
594
304
  return {
595
305
  ...nextConfig,
596
306
  webpack(config, webpackOptions) {
@@ -608,15 +318,6 @@ function withTailwindStyled(options = {}) {
608
318
  "@tailwind-styled/plugin": "commonjs2 @tailwind-styled/plugin"
609
319
  });
610
320
  }
611
- if (!finalConfig._twCssPluginAdded) {
612
- const plugins = finalConfig.plugins ?? [];
613
- plugins.push(new TwCssManifestPlugin());
614
- if (webpackOptions.dev) {
615
- plugins.push(new TwSafelistDevPlugin(webpackOptions.dir));
616
- }
617
- finalConfig.plugins = plugins;
618
- finalConfig._twCssPluginAdded = true;
619
- }
620
321
  return finalConfig;
621
322
  };
622
323
  if (typeof previousWebpack !== "function") {
@@ -635,7 +336,7 @@ function withTailwindStyled(options = {}) {
635
336
  ...nextConfig.turbopack ?? {},
636
337
  rules: mergeTurbopackRules(
637
338
  nextConfig.turbopack?.rules ?? {},
638
- buildTurbopackRules(turbopackLoaderPath, { ...loaderOptions, safelistPath })
339
+ buildTurbopackRules(turbopackLoaderPath, loaderOptions)
639
340
  )
640
341
  }
641
342
  };