+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, ''); | ||
| } | ||
| } |
+4
-3
@@ -6,2 +6,3 @@ import {promisify} from 'node:util'; | ||
| import {powerShellPath as windowsPowerShellPath, executePowerShell} from 'powershell-utils'; | ||
| import {parseMountPointFromConfig} from './utilities.js'; | ||
@@ -36,9 +37,9 @@ const execFile = promisify(childProcess.execFile); | ||
| const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'}); | ||
| const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent); | ||
| const parsedMountPoint = parseMountPointFromConfig(configContent); | ||
| if (!configMountPoint) { | ||
| if (parsedMountPoint === undefined) { | ||
| return defaultMountPoint; | ||
| } | ||
| mountPoint = configMountPoint.groups.mountPoint.trim(); | ||
| mountPoint = parsedMountPoint; | ||
| mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`; | ||
@@ -45,0 +46,0 @@ |
+3
-2
| { | ||
| "name": "wsl-utils", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "Utilities for working with Windows Subsystem for Linux (WSL)", | ||
@@ -27,3 +27,4 @@ "license": "MIT", | ||
| "index.js", | ||
| "index.d.ts" | ||
| "index.d.ts", | ||
| "utilities.js" | ||
| ], | ||
@@ -30,0 +31,0 @@ "keywords": [ |
10178
5.21%6
20%155
13.14%