New Project
All checks were successful
BeijingMediaOfficialWebsite-ZhaoJian/BeijingMediaOfficialWebsite-ZhaoJian/pipeline/head This commit looks good
All checks were successful
BeijingMediaOfficialWebsite-ZhaoJian/BeijingMediaOfficialWebsite-ZhaoJian/pipeline/head This commit looks good
This commit is contained in:
57
web/node_modules/wsl-utils/index.js
generated
vendored
Normal file
57
web/node_modules/wsl-utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import process from 'node:process';
|
||||
import fs, {constants as fsConstants} from 'node:fs/promises';
|
||||
import isWsl from 'is-wsl';
|
||||
|
||||
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 configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
||||
|
||||
if (!configMountPoint) {
|
||||
return defaultMountPoint;
|
||||
}
|
||||
|
||||
mountPoint = configMountPoint.groups.mountPoint.trim();
|
||||
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 = async () => {
|
||||
if (isWsl) {
|
||||
return powerShellPathFromWsl();
|
||||
}
|
||||
|
||||
return `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
||||
};
|
||||
|
||||
export {default as isWsl} from 'is-wsl';
|
||||
Reference in New Issue
Block a user