npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wsl-path

v4.0.0

Published

Convert Windows paths to WSL (1 & 2) paths and vice versa

Downloads

18

Readme

Build Status

wsl-path

A small node utility for converting file paths from POSIX paths in wsl (Windows Subsystem for Linux) to their counterparts in the Windows Filesystem and vice versa.

How it works

This utility requires the wslpath CLI tool to be installed on the running machine and a wsl environment. Only the base drive letter (Windows) / mount folder (POSIX) is being translated into the windows world, the rest of the path is then appended in the correct form. Base path resolutions are cached, so only the first resolution causes wslpath to be called, while subsequent paths in the same drive/mount folder are resolved by the cache.

The utility checks the mount points for the WSL environment in order to determine cachable paths.

Usage

The following examples are taken from the unit tests:

windowsToWsl(path, options?)

Converts a windows path to a WSL (POSIX) path.

const correctPath = "C:\\Users";

const result = await windowsToWsl(correctPath);

expect(result).toEqual("/mnt/c/Users");

wslToWindows(path, options?)

Converts a WSL (POSIX) Path to a windows path.

const mountedPath = "/mnt/c/Users";

const result = await wslToWindows(mountedPath);

expect(result).toEqual("C:\\Users");

windowsToWslSync(path, options?)

Converts a windows path to a WSL (POSIX) path in a synchronous call.

const correctPath = "C:\\Users";

const result =  windowsToWslSync(correctPath);

expect(result).toEqual("/mnt/c/Users");

wslToWindowsSync(path, options?)

Converts a WSL (POSIX) Path to a windows path in a synchronous call.

const mountedPath = "/mnt/c/Users";

const result = wslToWindowsSync(mountedPath);

expect(result).toEqual("C:\\Users");

Resolving without wslpath

If you want to resolve without having wslpath (or without wanting to spawn a process calling it) you can provide your own cache in the options containing the base path resolution:

const windowsPath = "C:\\Users";

const result1 = await windowsToWsl(windowsPath, {
   basePathCache: { "C:\\": "/mnt/x" }
});

expect(result1).toEqual("/mnt/x/Users");

Using different wsl environments than the default

If you have multiple wsl environments installed, you can use the wslCommand option for setting up the shell that should be used:

const result1 = await windowsToWsl(windowsPath, {
   wslCommand: 'ubuntu run'
});

Building and testing

Install packages: npm install

Build: npm run build

Test: npm run test or npm run test -- --watch

Integration Test, which does not mock wslpath: CALL_WSL_PROCESS=1 npm run test