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.
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.
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"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")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"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"
// ]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)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)}`);
});
});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;
}
});The normalization process:
This ensures consistent, predictable path handling across all platforms and environments.
tessl i tessl/npm-tailwindcss--node@4.1.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10