CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-tailwindcss--node

Node.js-specific utilities and runtime functionality for Tailwind CSS v4, providing compilation tools, module dependency analysis, source map handling, path normalization, and optimization utilities.

43%

Overall

Evaluation43%

1.16x

Agent success when using this tile

Overview
Eval results
Files

path-utils.mddocs/

Path Normalization

Cross-platform path normalization utilities for consistent file path handling across Windows and Unix systems. Provides robust path normalization that handles Windows network shares, UNC paths, and various path formats.

Capabilities

Normalize Path Function

Normalizes file paths for cross-platform compatibility with special handling for Windows paths.

/**
 * Normalizes file paths for cross-platform compatibility
 * Handles Windows network shares, UNC paths, and mixed separators
 * @param originalPath - Path string to normalize
 * @returns Normalized path with forward slashes and proper network share handling
 */
function normalizePath(originalPath: string): string;

Usage Examples:

import { normalizePath } from "@tailwindcss/node";

// Basic path normalization
console.log(normalizePath("src\\components\\Button.tsx"));
// Output: "src/components/Button.tsx"

console.log(normalizePath("src/components/Button.tsx"));  
// Output: "src/components/Button.tsx" (already normalized)

// Mixed separators
console.log(normalizePath("src\\components/utils\\helpers.js"));
// Output: "src/components/utils/helpers.js"

// Trailing separators
console.log(normalizePath("dist\\"));
// Output: "dist"

console.log(normalizePath("dist/"));
// Output: "dist"

Windows Network Share Handling

Special handling for Windows network shares and UNC paths:

import { normalizePath } from "@tailwindcss/node";

// Windows network share paths
console.log(normalizePath("\\\\server\\share\\file.txt"));
// Output: "//server/share/file.txt"

console.log(normalizePath("\\\\?\\C:\\Program Files\\App\\file.txt"));
// Output: "//C:/Program Files/App/file.txt"

console.log(normalizePath("\\\\.\\C:\\file.txt"));
// Output: "//C:/file.txt"

// Ensures network shares maintain double leading slashes
console.log(normalizePath("\\\\network-drive\\folder"));
// Output: "//network-drive/folder" (not "/network-drive/folder")

Edge Cases and Special Paths

Handles various edge cases and special path formats:

import { normalizePath } from "@tailwindcss/node";

// Root paths
console.log(normalizePath("\\"));
// Output: "/"

console.log(normalizePath("/"));
// Output: "/"

// Single character paths
console.log(normalizePath("a"));
// Output: "a"

console.log(normalizePath("."));
// Output: "."

// Empty segments
console.log(normalizePath("src//components///Button.tsx"));
// Output: "src/components/Button.tsx"

// Windows drive letters
console.log(normalizePath("C:\\Users\\name\\Documents"));
// Output: "C:/Users/name/Documents"

Build Tool Integration

Common usage patterns in build tools and development workflows:

import { normalizePath } from "@tailwindcss/node";
import path from "path";

// Normalizing resolved paths
function resolveAndNormalize(relativePath: string, basePath: string): string {
  const resolved = path.resolve(basePath, relativePath);
  return normalizePath(resolved);
}

const normalizedPath = resolveAndNormalize("./src/components", process.cwd());
console.log(normalizedPath);

// File watching with normalized paths
const watchPaths = [
  "src\\components\\**\\*.tsx",
  "src/styles/**/*.css",
  "config\\tailwind.config.js"
].map(normalizePath);

console.log(watchPaths);
// Output: [
//   "src/components/**/*.tsx",
//   "src/styles/**/*.css", 
//   "config/tailwind.config.js"
// ]

Error Handling

The function includes proper error handling for invalid inputs:

import { normalizePath } from "@tailwindcss/node";

// Type validation
try {
  normalizePath(null as any);
} catch (error) {
  console.error(error.message); // "expected path to be a string"
}

try {
  normalizePath(123 as any);
} catch (error) {
  console.error(error.message); // "expected path to be a string"
}

// Valid but unusual inputs
console.log(normalizePath(""));
// Output: "" (empty string is valid)

console.log(normalizePath("   "));
// Output: "   " (whitespace is preserved)

Cross-Platform Development

Essential for cross-platform development where paths may come from different sources:

import { normalizePath } from "@tailwindcss/node";

// Configuration files might contain platform-specific paths
const config = {
  contentPaths: [
    "src\\components\\**\\*.tsx",    // Windows developer
    "src/pages/**/*.tsx",            // Unix developer
    "lib\\utils\\*.js"               // Mixed environment
  ]
};

// Normalize all paths for consistent processing
const normalizedPaths = config.contentPaths.map(normalizePath);
console.log(normalizedPaths);
// Output: [
//   "src/components/**/*.tsx",
//   "src/pages/**/*.tsx", 
//   "lib/utils/*.js"
// ]

// Use in file system operations
import fs from "fs";
import glob from "glob";

normalizedPaths.forEach(pattern => {
  const files = glob.sync(pattern);
  files.forEach(file => {
    // Process file...
    console.log(`Processing: ${normalizePath(file)}`);
  });
});

Module Resolution Integration

Commonly used with module resolution systems:

import { normalizePath } from "@tailwindcss/node";

// Custom resolver that normalizes paths
function customResolver(id: string, base: string): string | null {
  if (id.startsWith("@/")) {
    const resolved = path.resolve(base, "src", id.slice(2));
    return normalizePath(resolved);
  }
  
  if (id.startsWith("~/")) {
    const resolved = path.resolve(base, id.slice(2));
    return normalizePath(resolved);
  }
  
  return null;
}

// Usage with compilation
import { compile } from "@tailwindcss/node";

const compiler = await compile(css, {
  base: process.cwd(),
  onDependency: (path) => console.log("Dependency:", normalizePath(path)),
  customCssResolver: async (id, base) => {
    const resolved = customResolver(id, base);
    return resolved ? normalizePath(resolved) : undefined;
  }
});

Implementation Details

The normalization process:

  1. Type Validation: Ensures input is a string
  2. Root Path Handling: Special cases for "/" and ""
  3. Short Path Optimization: Returns paths of length ≤ 1 unchanged
  4. Windows Namespace Detection: Identifies UNC and device paths
  5. Segment Splitting: Splits on both "/" and "" separators
  6. Empty Segment Removal: Removes trailing empty segments
  7. Path Reconstruction: Joins with "/" separators
  8. Network Share Correction: Ensures proper "//" prefix for network paths

This ensures consistent, predictable path handling across all platforms and environments.

tessl i tessl/npm-tailwindcss--node@4.1.0

docs

cache-management.md

compilation.md

index.md

instrumentation.md

module-analysis.md

optimization.md

path-utils.md

source-maps.md

url-processing.md

tile.json