Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

wsl-utils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wsl-utils - npm Package Compare versions

Comparing version
0.2.0
to
0.3.0
+37
-0
index.d.ts

@@ -19,2 +19,39 @@ /**

/**
Check if PowerShell is accessible in the current environment.
This is useful to determine whether Windows integration features can be used. In sandboxed WSL environments or systems where PowerShell is not accessible, this will return `false`.
@returns A promise that resolves to `true` if PowerShell is accessible, `false` otherwise.
@example
```
import {canAccessPowerShell} from 'wsl-utils';
if (await canAccessPowerShell()) {
// Use Windows integration features
console.log('PowerShell is accessible');
} else {
// Fall back to Linux-native behavior
console.log('PowerShell is not accessible');
}
```
*/
export function canAccessPowerShell(): Promise<boolean>;
/**
Get the default browser in WSL.
@returns A promise that resolves to the [ProgID](https://setuserfta.com/guide-to-understanding-progids-and-file-type-associations/) of the default browser (e.g., `'ChromeHTML'`, `'FirefoxURL'`).
@example
```
import {wslDefaultBrowser} from 'wsl-utils';
const progId = await wslDefaultBrowser();
//=> 'ChromeHTML'
```
*/
export function wslDefaultBrowser(): Promise<string>;
/**
Get the mount point for fixed drives in WSL.

@@ -21,0 +58,0 @@ */

+27
-6

@@ -1,2 +0,1 @@

import process from 'node:process';
import {promisify} from 'node:util';

@@ -6,2 +5,3 @@ import childProcess from 'node:child_process';

import isWsl from 'is-wsl';
import {powerShellPath as windowsPowerShellPath, executePowerShell} from 'powershell-utils';

@@ -54,10 +54,31 @@ const execFile = promisify(childProcess.execFile);

export const powerShellPath = async () => {
if (isWsl) {
return powerShellPathFromWsl();
}
export const powerShellPath = isWsl ? powerShellPathFromWsl : windowsPowerShellPath;
return `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
// Cache for PowerShell accessibility check
let canAccessPowerShellPromise;
export const canAccessPowerShell = async () => {
canAccessPowerShellPromise ??= (async () => {
try {
const psPath = await powerShellPath();
await fs.access(psPath, fsConstants.X_OK);
return true;
} catch {
// PowerShell is not accessible (either doesn't exist, no execute permission, or other error)
return false;
}
})();
return canAccessPowerShellPromise;
};
export const wslDefaultBrowser = async () => {
const psPath = await powerShellPath();
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
const {stdout} = await executePowerShell(command, {powerShellPath: psPath});
return stdout.trim();
};
export const convertWslPathToWindows = async path => {

@@ -64,0 +85,0 @@ // Don't convert URLs

+7
-6
{
"name": "wsl-utils",
"version": "0.2.0",
"version": "0.3.0",
"description": "Utilities for working with Windows Subsystem for Linux (WSL)",

@@ -20,3 +20,3 @@ "license": "MIT",

"engines": {
"node": ">=18"
"node": ">=20"
},

@@ -40,9 +40,10 @@ "scripts": {

"dependencies": {
"is-wsl": "^3.1.0"
"is-wsl": "^3.1.0",
"powershell-utils": "^0.1.0"
},
"devDependencies": {
"ava": "^6.3.0",
"typescript": "^5.8.3",
"xo": "^1.0.0"
"ava": "^6.4.1",
"typescript": "^5.9.3",
"xo": "^1.2.3"
}
}

@@ -46,2 +46,37 @@ # wsl-utils

### canAccessPowerShell()
Returns: `Promise<boolean>`
Check if PowerShell is accessible in the current environment.
This is useful to determine whether Windows integration features can be used. In sandboxed WSL environments or systems where PowerShell is not accessible, this will return `false`.
```js
import {canAccessPowerShell} from 'wsl-utils';
if (await canAccessPowerShell()) {
// Use Windows integration features
console.log('PowerShell is accessible');
} else {
// Fall back to Linux-native behavior
console.log('PowerShell is not accessible');
}
```
### wslDefaultBrowser()
Returns: `Promise<string>`
Get the default browser in WSL.
Returns a promise that resolves to the [ProgID](https://setuserfta.com/guide-to-understanding-progids-and-file-type-associations/) of the default browser (e.g., `'ChromeHTML'`, `'FirefoxURL'`).
```js
import {wslDefaultBrowser} from 'wsl-utils';
const progId = await wslDefaultBrowser();
//=> 'ChromeHTML'
```
### wslDrivesMountPoint()

@@ -48,0 +83,0 @@