index.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. Check if the current environment is Windows Subsystem for Linux (WSL).
  3. */
  4. export const isWsl: boolean;
  5. /**
  6. Get the PowerShell executable path in WSL environment.
  7. */
  8. export function powerShellPathFromWsl(): Promise<string>;
  9. /**
  10. Get the PowerShell executable path for the current environment.
  11. Returns WSL path if in WSL, otherwise returns Windows path.
  12. */
  13. export function powerShellPath(): Promise<string>;
  14. /**
  15. Check if PowerShell is accessible in the current environment.
  16. 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`.
  17. @returns A promise that resolves to `true` if PowerShell is accessible, `false` otherwise.
  18. @example
  19. ```
  20. import {canAccessPowerShell} from 'wsl-utils';
  21. if (await canAccessPowerShell()) {
  22. // Use Windows integration features
  23. console.log('PowerShell is accessible');
  24. } else {
  25. // Fall back to Linux-native behavior
  26. console.log('PowerShell is not accessible');
  27. }
  28. ```
  29. */
  30. export function canAccessPowerShell(): Promise<boolean>;
  31. /**
  32. Get the default browser in WSL.
  33. @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'`).
  34. @example
  35. ```
  36. import {wslDefaultBrowser} from 'wsl-utils';
  37. const progId = await wslDefaultBrowser();
  38. //=> 'ChromeHTML'
  39. ```
  40. */
  41. export function wslDefaultBrowser(): Promise<string>;
  42. /**
  43. Get the mount point for fixed drives in WSL.
  44. */
  45. export function wslDrivesMountPoint(): Promise<string>;
  46. /**
  47. Convert a WSL Linux path to a Windows-accessible path.
  48. URLs (strings starting with a protocol like `https://`) are returned unchanged.
  49. @param path - The WSL path to convert (e.g., `/home/user/file.html`).
  50. @returns The Windows-accessible path (e.g., `\\wsl.localhost\Ubuntu\home\user\file.html`) or the original path if conversion fails.
  51. @example
  52. ```
  53. import {convertWslPathToWindows} from 'wsl-utils';
  54. // Convert a Linux path
  55. const windowsPath = await convertWslPathToWindows('/home/user/file.html');
  56. //=> '\\wsl.localhost\Ubuntu\home\user\file.html'
  57. // URLs are not converted
  58. const url = await convertWslPathToWindows('https://example.com');
  59. //=> 'https://example.com'
  60. ```
  61. */
  62. export function convertWslPathToWindows(path: string): Promise<string>;
  63. /**
  64. Convert multiple WSL Linux paths to Windows-accessible paths.
  65. URLs (strings starting with a protocol like `https://`) are returned unchanged.
  66. @param paths - The WSL paths to convert.
  67. @returns The Windows-accessible paths in the same order, or the original paths if conversion fails.
  68. @example
  69. ```
  70. import {convertWslPathToWindows} from 'wsl-utils';
  71. const windowsPaths = await convertWslPathToWindows([
  72. '/home/user/file.html',
  73. '/mnt/c/Users/file.txt',
  74. 'https://example.com'
  75. ]);
  76. //=> ['\\wsl.localhost\Ubuntu\home\user\file.html', 'C:\Users\file.txt', 'https://example.com']
  77. ```
  78. */
  79. export function convertWslPathToWindows(paths: string[]): Promise<string[]>;
  80. /**
  81. Check if a Windows path is a UNC path (e.g., `\\wsl.localhost\...` or `\\wsl$\...`).
  82. UNC paths indicate the file resides on the WSL Linux filesystem rather than a Windows drive.
  83. @param path - The Windows path to check.
  84. @returns `true` if the path is a UNC path, `false` otherwise.
  85. @example
  86. ```
  87. import {isUncPath} from 'wsl-utils';
  88. isUncPath('\\\\wsl.localhost\\Ubuntu\\home\\user');
  89. //=> true
  90. isUncPath('C:\\Users\\file.txt');
  91. //=> false
  92. ```
  93. */
  94. export function isUncPath(path: string): boolean;
  95. /**
  96. Check if a WSL path maps to the Windows filesystem.
  97. This converts the path and checks if it's on a Windows drive (e.g., `/mnt/c/...` → `C:\...`) rather than the Linux filesystem (e.g., `/home/...` → `\\wsl$\...`).
  98. @param path - The WSL path to check.
  99. @returns `true` if the path is on a Windows drive, `false` if it's on the Linux filesystem.
  100. @example
  101. ```
  102. import {isPathOnWindowsFilesystem} from 'wsl-utils';
  103. await isPathOnWindowsFilesystem('/mnt/c/Users/file.txt');
  104. //=> true
  105. await isPathOnWindowsFilesystem('/home/user/file.txt');
  106. //=> false
  107. ```
  108. */
  109. export function isPathOnWindowsFilesystem(path: string): Promise<boolean>;
  110. /**
  111. Convert a Windows path to a WSL Linux path.
  112. @param path - The Windows path to convert (e.g., `C:\Users\file.txt`).
  113. @returns The WSL path (e.g., `/mnt/c/Users/file.txt`) or the original path if conversion fails.
  114. @example
  115. ```
  116. import {convertWindowsPathToWsl} from 'wsl-utils';
  117. const wslPath = await convertWindowsPathToWsl('C:\\Users\\file.txt');
  118. //=> '/mnt/c/Users/file.txt'
  119. ```
  120. */
  121. export function convertWindowsPathToWsl(path: string): Promise<string>;
  122. /**
  123. Convert multiple Windows paths to WSL Linux paths.
  124. @param paths - The Windows paths to convert.
  125. @returns The WSL paths in the same order, or the original paths if conversion fails.
  126. @example
  127. ```
  128. import {convertWindowsPathToWsl} from 'wsl-utils';
  129. const wslPaths = await convertWindowsPathToWsl([
  130. 'C:\\Users\\file.txt',
  131. 'D:\\Projects\\app'
  132. ]);
  133. //=> ['/mnt/c/Users/file.txt', '/mnt/d/Projects/app']
  134. ```
  135. */
  136. export function convertWindowsPathToWsl(paths: string[]): Promise<string[]>;