$ show sindresorhus/is-wsl
is-wsl is a Node.js utility package that detects whether the current process is running inside Windows Subsystem for Linux (WSL). The core logic in index.js checks multiple indicators: platform must be Linux, kernel release string containing 'microsoft', presence of WSL-specific filesystem paths (/proc/sys/fs/binfmt_misc/WSLInterop or /run/WSL), and containerization status via the is-inside-container dependency. It handles WSL 1, WSL 2, custom kernels, and edge cases like WSL running inside a container (which returns false). The package is designed as a simple, reusable dependency with zero configuration. It exports a boolean value (or a function in test mode) and includes TypeScript definitions, comprehensive tests using AVA and esmock for mocking, and a CI workflow testing Node.js 16 and 18. The implementation demonstrates careful consideration of WSL detection nuances without over-engineering. As a focused utility solving a specific environmental detection problem, it exemplifies craftsmanship in small, self-contained modules. The code is minimal, dependency-light, and highly testable, making it suitable for extraction into other projects needing WSL awareness.
The LLM identified 1 files worth highlighting for reuse:
The index.js file exports a WSL detection function that checks platform, kernel release strings, filesystem paths, and container status. It handles WSL 1/2, custom kernels, and containerized WSL scenarios. The function is self-contained, depends only on is-inside-container (for container checks) and Node.js built-ins, making it easily extractable with minimal modification. It demonstrates non-obvious skill in balancing accuracy with simplicity for a niche but common environment detection problem.