修改后台权限
This commit is contained in:
81
node_modules/wsl-utils/index.d.ts
generated
vendored
Normal file
81
node_modules/wsl-utils/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
Check if the current environment is Windows Subsystem for Linux (WSL).
|
||||
*/
|
||||
export const isWsl: boolean;
|
||||
|
||||
/**
|
||||
Get the PowerShell executable path in WSL environment.
|
||||
*/
|
||||
export function powerShellPathFromWsl(): Promise<string>;
|
||||
|
||||
/**
|
||||
Get the PowerShell executable path for the current environment.
|
||||
|
||||
Returns WSL path if in WSL, otherwise returns Windows path.
|
||||
*/
|
||||
export function powerShellPath(): Promise<string>;
|
||||
|
||||
/**
|
||||
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.
|
||||
*/
|
||||
export function wslDrivesMountPoint(): Promise<string>;
|
||||
|
||||
/**
|
||||
Convert a WSL Linux path to a Windows-accessible path.
|
||||
|
||||
URLs (strings starting with a protocol like `https://`) are returned unchanged.
|
||||
|
||||
@param path - The WSL path to convert (e.g., `/home/user/file.html`).
|
||||
@returns The Windows-accessible path (e.g., `\\wsl.localhost\Ubuntu\home\user\file.html`) or the original path if conversion fails.
|
||||
|
||||
@example
|
||||
```
|
||||
import {convertWslPathToWindows} from 'wsl-utils';
|
||||
|
||||
// Convert a Linux path
|
||||
const windowsPath = await convertWslPathToWindows('/home/user/file.html');
|
||||
//=> '\\wsl.localhost\Ubuntu\home\user\file.html'
|
||||
|
||||
// URLs are not converted
|
||||
const url = await convertWslPathToWindows('https://example.com');
|
||||
//=> 'https://example.com'
|
||||
```
|
||||
*/
|
||||
export function convertWslPathToWindows(path: string): Promise<string>;
|
||||
98
node_modules/wsl-utils/index.js
generated
vendored
Normal file
98
node_modules/wsl-utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
import {promisify} from 'node:util';
|
||||
import childProcess from 'node:child_process';
|
||||
import fs, {constants as fsConstants} from 'node:fs/promises';
|
||||
import isWsl from 'is-wsl';
|
||||
import {powerShellPath as windowsPowerShellPath, executePowerShell} from 'powershell-utils';
|
||||
import {parseMountPointFromConfig} from './utilities.js';
|
||||
|
||||
const execFile = promisify(childProcess.execFile);
|
||||
|
||||
export const wslDrivesMountPoint = (() => {
|
||||
// Default value for "root" param
|
||||
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
|
||||
const defaultMountPoint = '/mnt/';
|
||||
|
||||
let mountPoint;
|
||||
|
||||
return async function () {
|
||||
if (mountPoint) {
|
||||
// Return memoized mount point value
|
||||
return mountPoint;
|
||||
}
|
||||
|
||||
const configFilePath = '/etc/wsl.conf';
|
||||
|
||||
let isConfigFileExists = false;
|
||||
try {
|
||||
await fs.access(configFilePath, fsConstants.F_OK);
|
||||
isConfigFileExists = true;
|
||||
} catch {}
|
||||
|
||||
if (!isConfigFileExists) {
|
||||
return defaultMountPoint;
|
||||
}
|
||||
|
||||
const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'});
|
||||
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
||||
|
||||
if (parsedMountPoint === undefined) {
|
||||
return defaultMountPoint;
|
||||
}
|
||||
|
||||
mountPoint = parsedMountPoint;
|
||||
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
||||
|
||||
return mountPoint;
|
||||
};
|
||||
})();
|
||||
|
||||
export const powerShellPathFromWsl = async () => {
|
||||
const mountPoint = await wslDrivesMountPoint();
|
||||
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
||||
};
|
||||
|
||||
export const powerShellPath = isWsl ? powerShellPathFromWsl : windowsPowerShellPath;
|
||||
|
||||
// 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 => {
|
||||
// Don't convert URLs
|
||||
if (/^[a-z]+:\/\//i.test(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
try {
|
||||
const {stdout} = await execFile('wslpath', ['-aw', path], {encoding: 'utf8'});
|
||||
return stdout.trim();
|
||||
} catch {
|
||||
// If wslpath fails, return the original path
|
||||
return path;
|
||||
}
|
||||
};
|
||||
|
||||
export {default as isWsl} from 'is-wsl';
|
||||
9
node_modules/wsl-utils/license
generated
vendored
Normal file
9
node_modules/wsl-utils/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
48
node_modules/wsl-utils/package.json
generated
vendored
Normal file
48
node_modules/wsl-utils/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "wsl-utils",
|
||||
"version": "0.3.1",
|
||||
"description": "Utilities for working with Windows Subsystem for Linux (WSL)",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/wsl-utils",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsc index.d.ts --skipLibCheck"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"utilities.js"
|
||||
],
|
||||
"keywords": [
|
||||
"wsl",
|
||||
"windows",
|
||||
"subsystem",
|
||||
"linux",
|
||||
"powershell",
|
||||
"mount",
|
||||
"utilities"
|
||||
],
|
||||
"dependencies": {
|
||||
"is-wsl": "^3.1.0",
|
||||
"powershell-utils": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^6.4.1",
|
||||
"typescript": "^5.9.3",
|
||||
"xo": "^1.2.3"
|
||||
}
|
||||
}
|
||||
111
node_modules/wsl-utils/readme.md
generated
vendored
Normal file
111
node_modules/wsl-utils/readme.md
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
# wsl-utils
|
||||
|
||||
> Utilities for working with [Windows Subsystem for Linux (WSL)](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install wsl-utils
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import {isWsl, powerShellPathFromWsl} from 'wsl-utils';
|
||||
|
||||
// Check if running in WSL
|
||||
console.log('Is WSL:', isWsl);
|
||||
|
||||
// Get PowerShell path from WSL
|
||||
console.log('PowerShell path:', await powerShellPathFromWsl());
|
||||
//=> '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### isWsl
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Check if the current environment is Windows Subsystem for Linux (WSL).
|
||||
|
||||
### powerShellPathFromWsl()
|
||||
|
||||
Returns: `Promise<string>`
|
||||
|
||||
Get the PowerShell executable path in WSL environment.
|
||||
|
||||
### powerShellPath()
|
||||
|
||||
Returns: `Promise<string>`
|
||||
|
||||
Get the PowerShell executable path for the current environment.
|
||||
|
||||
Returns WSL path if in WSL, otherwise returns Windows path.
|
||||
|
||||
### 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()
|
||||
|
||||
Returns: `Promise<string>`
|
||||
|
||||
Get the mount point for fixed drives in WSL.
|
||||
|
||||
### convertWslPathToWindows(path)
|
||||
|
||||
Returns: `Promise<string>`
|
||||
|
||||
Convert a WSL Linux path to a Windows-accessible path.
|
||||
|
||||
URLs (strings starting with a protocol like `https://`) are returned unchanged.
|
||||
|
||||
```js
|
||||
import {convertWslPathToWindows} from 'wsl-utils';
|
||||
|
||||
// Convert a Linux path
|
||||
const windowsPath = await convertWslPathToWindows('/home/user/file.html');
|
||||
//=> '\\wsl.localhost\Ubuntu\home\user\file.html'
|
||||
|
||||
// URLs are not converted
|
||||
const url = await convertWslPathToWindows('https://example.com');
|
||||
//=> 'https://example.com'
|
||||
```
|
||||
|
||||
#### path
|
||||
|
||||
Type: `string`
|
||||
|
||||
The WSL path to convert (e.g., `/home/user/file.html`).
|
||||
19
node_modules/wsl-utils/utilities.js
generated
vendored
Normal file
19
node_modules/wsl-utils/utilities.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
export function parseMountPointFromConfig(content) {
|
||||
for (const line of content.split('\n')) {
|
||||
// Skip comment lines
|
||||
if (/^\s*#/.test(line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Match root at start of line (after optional whitespace)
|
||||
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return match.groups.mountPoint
|
||||
.trim()
|
||||
// Strip surrounding quotes
|
||||
.replaceAll(/^["']|["']$/g, '');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user