wsl-utils 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +4 -3
  2. package/package.json +3 -2
  3. package/utilities.js +19 -0
package/index.js CHANGED
@@ -3,6 +3,7 @@ import childProcess from 'node:child_process';
3
3
  import fs, {constants as fsConstants} from 'node:fs/promises';
4
4
  import isWsl from 'is-wsl';
5
5
  import {powerShellPath as windowsPowerShellPath, executePowerShell} from 'powershell-utils';
6
+ import {parseMountPointFromConfig} from './utilities.js';
6
7
 
7
8
  const execFile = promisify(childProcess.execFile);
8
9
 
@@ -32,13 +33,13 @@ export const wslDrivesMountPoint = (() => {
32
33
  }
33
34
 
34
35
  const configContent = await fs.readFile(configFilePath, {encoding: 'utf8'});
35
- const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
36
+ const parsedMountPoint = parseMountPointFromConfig(configContent);
36
37
 
37
- if (!configMountPoint) {
38
+ if (parsedMountPoint === undefined) {
38
39
  return defaultMountPoint;
39
40
  }
40
41
 
41
- mountPoint = configMountPoint.groups.mountPoint.trim();
42
+ mountPoint = parsedMountPoint;
42
43
  mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
43
44
 
44
45
  return mountPoint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wsl-utils",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Utilities for working with Windows Subsystem for Linux (WSL)",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/wsl-utils",
@@ -24,7 +24,8 @@
24
24
  },
25
25
  "files": [
26
26
  "index.js",
27
- "index.d.ts"
27
+ "index.d.ts",
28
+ "utilities.js"
28
29
  ],
29
30
  "keywords": [
30
31
  "wsl",
package/utilities.js ADDED
@@ -0,0 +1,19 @@
1
+ export function parseMountPointFromConfig(content) {
2
+ for (const line of content.split('\n')) {
3
+ // Skip comment lines
4
+ if (/^\s*#/.test(line)) {
5
+ continue;
6
+ }
7
+
8
+ // Match root at start of line (after optional whitespace)
9
+ const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
10
+ if (!match) {
11
+ continue;
12
+ }
13
+
14
+ return match.groups.mountPoint
15
+ .trim()
16
+ // Strip surrounding quotes
17
+ .replaceAll(/^["']|["']$/g, '');
18
+ }
19
+ }