@theia/remote-wsl 1.62.0

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 (47) hide show
  1. package/README.md +31 -0
  2. package/lib/electron-browser/remote-wsl-frontend-module.d.ts +4 -0
  3. package/lib/electron-browser/remote-wsl-frontend-module.d.ts.map +1 -0
  4. package/lib/electron-browser/remote-wsl-frontend-module.js +30 -0
  5. package/lib/electron-browser/remote-wsl-frontend-module.js.map +1 -0
  6. package/lib/electron-browser/wsl-connection-contribution.d.ts +29 -0
  7. package/lib/electron-browser/wsl-connection-contribution.d.ts.map +1 -0
  8. package/lib/electron-browser/wsl-connection-contribution.js +179 -0
  9. package/lib/electron-browser/wsl-connection-contribution.js.map +1 -0
  10. package/lib/electron-common/remote-wsl-connection-provider.d.ts +20 -0
  11. package/lib/electron-common/remote-wsl-connection-provider.d.ts.map +1 -0
  12. package/lib/electron-common/remote-wsl-connection-provider.js +21 -0
  13. package/lib/electron-common/remote-wsl-connection-provider.js.map +1 -0
  14. package/lib/electron-common/wsl-workspaces.d.ts +2 -0
  15. package/lib/electron-common/wsl-workspaces.d.ts.map +1 -0
  16. package/lib/electron-common/wsl-workspaces.js +20 -0
  17. package/lib/electron-common/wsl-workspaces.js.map +1 -0
  18. package/lib/electron-node/remote-wsl-backend-module.d.ts +5 -0
  19. package/lib/electron-node/remote-wsl-backend-module.d.ts.map +1 -0
  20. package/lib/electron-node/remote-wsl-backend-module.js +39 -0
  21. package/lib/electron-node/remote-wsl-backend-module.js.map +1 -0
  22. package/lib/electron-node/remote-wsl-connection-provider.d.ts +25 -0
  23. package/lib/electron-node/remote-wsl-connection-provider.d.ts.map +1 -0
  24. package/lib/electron-node/remote-wsl-connection-provider.js +121 -0
  25. package/lib/electron-node/remote-wsl-connection-provider.js.map +1 -0
  26. package/lib/electron-node/remote-wsl-connection.d.ts +31 -0
  27. package/lib/electron-node/remote-wsl-connection.d.ts.map +1 -0
  28. package/lib/electron-node/remote-wsl-connection.js +138 -0
  29. package/lib/electron-node/remote-wsl-connection.js.map +1 -0
  30. package/lib/electron-node/wsl-workspace-handler.d.ts +8 -0
  31. package/lib/electron-node/wsl-workspace-handler.d.ts.map +1 -0
  32. package/lib/electron-node/wsl-workspace-handler.js +23 -0
  33. package/lib/electron-node/wsl-workspace-handler.js.map +1 -0
  34. package/lib/package.spec.d.ts +1 -0
  35. package/lib/package.spec.d.ts.map +1 -0
  36. package/lib/package.spec.js +26 -0
  37. package/lib/package.spec.js.map +1 -0
  38. package/package.json +48 -0
  39. package/src/electron-browser/remote-wsl-frontend-module.ts +32 -0
  40. package/src/electron-browser/wsl-connection-contribution.ts +180 -0
  41. package/src/electron-common/remote-wsl-connection-provider.ts +39 -0
  42. package/src/electron-common/wsl-workspaces.ts +17 -0
  43. package/src/electron-node/remote-wsl-backend-module.ts +41 -0
  44. package/src/electron-node/remote-wsl-connection-provider.ts +123 -0
  45. package/src/electron-node/remote-wsl-connection.ts +161 -0
  46. package/src/electron-node/wsl-workspace-handler.ts +38 -0
  47. package/src/package.spec.ts +29 -0
@@ -0,0 +1,123 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { inject, injectable } from '@theia/core/shared/inversify';
18
+ import { RemoteWslConnectionProvider, WslDistribution, WslConnectionOptions, WslConnectionResult } from '../electron-common/remote-wsl-connection-provider';
19
+ import { RemoteConnectionService } from '@theia/remote/lib/electron-node/remote-connection-service';
20
+ import { RemoteSetupService } from '@theia/remote/lib/electron-node/setup/remote-setup-service';
21
+ import { exec } from 'child_process';
22
+ import { MessageService, generateUuid } from '@theia/core';
23
+ import { RemoteWslConnection } from './remote-wsl-connection';
24
+
25
+ @injectable()
26
+ export class RemoteWslConnectionProviderImpl implements RemoteWslConnectionProvider {
27
+
28
+ @inject(RemoteConnectionService)
29
+ protected readonly remoteConnectionService: RemoteConnectionService;
30
+
31
+ @inject(RemoteSetupService)
32
+ protected readonly remoteSetup: RemoteSetupService;
33
+
34
+ @inject(MessageService)
35
+ protected readonly messageService: MessageService;
36
+
37
+ dispose(): void {
38
+ }
39
+
40
+ /**
41
+ * executes `wsl.exe --list` to get the list of WSL distributions.
42
+ * The Output format look like this:
43
+ * ```
44
+ * NAME STATE VERSION
45
+ * * Ubuntu Stopped 2
46
+ * Other Distro Stopped 2
47
+ * ```
48
+ * so we split the output by lines and then by whitespace. The * indicates the default distribution so this has to be handled slightly different.
49
+ *
50
+ * @returns a list of WslDistribution objects, each containing the name, default status, and version.
51
+ */
52
+ async getWslDistributions(): Promise<WslDistribution[]> {
53
+ return new Promise<WslDistribution[]>((resolve, reject) => {
54
+ exec('wsl.exe --list --verbose --all', (error, stdout, stderr) => {
55
+ if (error) {
56
+ const errorMessage = `Error executing wsl.exe: ${error} \n ${stderr}`;
57
+ console.error(errorMessage);
58
+ reject(errorMessage);
59
+ return;
60
+ }
61
+
62
+ const lines = stdout
63
+ .replace(/\0/g, '')
64
+ .split('\n')
65
+ .map(line => line.replace('\r', '').trim())
66
+ .filter(line => line.length > 0)
67
+ .slice(1); // Skip header line
68
+
69
+ resolve(lines.map(line => {
70
+ const parts = line.split(/\s+/);
71
+ const isDefault = parts[0] === '*';
72
+ const name = isDefault ? parts[1] : parts[0];
73
+ const version = isDefault ? parts[3] : parts[2];
74
+ return {
75
+ name,
76
+ default: isDefault,
77
+ version
78
+ };
79
+ }));
80
+ });
81
+ });
82
+ }
83
+
84
+ async connectToWsl(options: WslConnectionOptions): Promise<WslConnectionResult> {
85
+ const progress = await this.messageService.showProgress({
86
+ text: 'Connecting to WSL'
87
+ });
88
+
89
+ try {
90
+ const connection = new RemoteWslConnection({
91
+ id: generateUuid(),
92
+ name: options.distribution,
93
+ type: 'WSL',
94
+ distribution: options.distribution,
95
+ });
96
+
97
+ const report: (message: string) => void = message => progress.report({ message });
98
+ report('Setting up remote environment...');
99
+
100
+ await this.remoteSetup.setup({
101
+ connection,
102
+ report,
103
+ nodeDownloadTemplate: options.nodeDownloadTemplate
104
+ });
105
+
106
+ const registration = this.remoteConnectionService.register(connection);
107
+
108
+ connection.onDidDisconnect(() => {
109
+ registration.dispose();
110
+ });
111
+
112
+ return {
113
+ port: connection.remotePort,
114
+ };
115
+ } catch (e) {
116
+ this.messageService.error(`Failed to connect to WSL: ${e.message}`);
117
+ throw e;
118
+ } finally {
119
+ progress.cancel();
120
+ }
121
+ }
122
+ }
123
+
@@ -0,0 +1,161 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Emitter, Event } from '@theia/core';
18
+ import { RemoteConnection, RemoteExecOptions, RemoteExecResult, RemoteExecTester } from '@theia/remote/lib/electron-node/remote-types';
19
+ import { Socket } from 'net';
20
+ import { exec, spawn } from 'child_process';
21
+ import { Deferred } from '@theia/core/lib/common/promise-util';
22
+ import * as fs from 'fs';
23
+
24
+ export interface RemoteWslConnectionOptions {
25
+ id: string;
26
+ name: string;
27
+ type: string;
28
+ distribution: string;
29
+ }
30
+
31
+ export class RemoteWslConnection implements RemoteConnection {
32
+ id: string;
33
+ name: string;
34
+ type: string;
35
+ remotePort: number;
36
+ distribution: string;
37
+
38
+ get localPort(): number {
39
+ return this.remotePort;
40
+ }
41
+
42
+ protected readonly onDidDisconnectEmitter = new Emitter<void>();
43
+ onDidDisconnect: Event<void> = this.onDidDisconnectEmitter.event;
44
+
45
+ constructor(options: RemoteWslConnectionOptions) {
46
+ this.id = options.id;
47
+ this.name = options.name;
48
+ this.type = options.type;
49
+ this.distribution = options.distribution;
50
+ }
51
+
52
+ async forwardOut(socket: Socket, port: number): Promise<void> {
53
+ new Socket().connect(port, 'localhost', () => {
54
+ socket.pipe(new Socket().connect(port, 'localhost'));
55
+ });
56
+ }
57
+
58
+ async exec(cmd: string, args?: string[], options?: RemoteExecOptions): Promise<RemoteExecResult> {
59
+ const deferred = new Deferred<RemoteExecResult>();
60
+ const fullCommand = `wsl -d ${this.distribution} ${cmd} ${args?.join(' ') ?? ''}`;
61
+
62
+ try {
63
+ exec(fullCommand, { env: options?.env }, (error, stdout, stderr) => {
64
+ deferred.resolve({ stdout, stderr });
65
+ });
66
+ } catch (e) {
67
+ deferred.reject(e);
68
+ }
69
+
70
+ return deferred.promise;
71
+ }
72
+
73
+ async execPartial(cmd: string, tester: RemoteExecTester, args?: string[], options?: RemoteExecOptions): Promise<RemoteExecResult> {
74
+ const deferred = new Deferred<RemoteExecResult>();
75
+
76
+ try {
77
+ let cdPath = undefined;
78
+ if (cmd.startsWith('cd') && cmd.includes(';')) {
79
+ const parts = cmd.split(';');
80
+ cdPath = parts[0].replace('cd', '').trim();
81
+ cmd = parts[1];
82
+ }
83
+ const fullCommand = `wsl -d ${this.distribution} ${cdPath ? `--cd ${cdPath} ${cmd}` : cmd} ${args?.join(' ') ?? ''}`;
84
+
85
+ const process = spawn(fullCommand, { env: options?.env, shell: 'powershell' });
86
+
87
+ let stdoutBuffer = '';
88
+ let stderrBuffer = '';
89
+
90
+ process.stdout.on('data', (data: Buffer) => {
91
+ if (deferred.state === 'unresolved') {
92
+ stdoutBuffer += data.toString();
93
+ if (tester(stdoutBuffer, stderrBuffer)) {
94
+ deferred.resolve({ stdout: stdoutBuffer, stderr: stderrBuffer });
95
+ }
96
+ }
97
+ });
98
+
99
+ process.stderr.on('data', (data: Buffer) => {
100
+ if (deferred.state === 'unresolved') {
101
+ stderrBuffer += data.toString();
102
+ if (tester(stdoutBuffer, stderrBuffer)) {
103
+ deferred.resolve({ stdout: stdoutBuffer, stderr: stderrBuffer });
104
+ }
105
+ }
106
+ });
107
+
108
+ process.on('close', () => {
109
+ if (deferred.state === 'unresolved') {
110
+ deferred.resolve({ stdout: stdoutBuffer, stderr: stderrBuffer });
111
+ }
112
+ });
113
+
114
+ process.on('error', error => {
115
+ deferred.reject(error);
116
+ });
117
+ } catch (e) {
118
+ deferred.reject(e);
119
+ }
120
+
121
+ return deferred.promise;
122
+ }
123
+
124
+ async copy(localPath: string | Buffer | NodeJS.ReadableStream, remotePath: string): Promise<void> {
125
+ const deferred = new Deferred<void>();
126
+ const wslPath = `\\\\wsl$\\${this.distribution}\\${remotePath}`;
127
+
128
+ if (typeof localPath === 'string') {
129
+ exec(`copy "${localPath}" "${wslPath}"`, error => {
130
+ if (error) {
131
+ deferred.reject(error);
132
+ } else {
133
+ deferred.resolve();
134
+ }
135
+ });
136
+ } else if (Buffer.isBuffer(localPath)) {
137
+ fs.writeFile(wslPath, localPath, (error: Error) => {
138
+ if (error) {
139
+ deferred.reject(error);
140
+ } else {
141
+ deferred.resolve();
142
+ }
143
+ });
144
+ } else {
145
+ const writeStream = fs.createWriteStream(wslPath);
146
+ localPath.pipe(writeStream);
147
+ writeStream.on('finish', () => deferred.resolve());
148
+ writeStream.on('error', (error: Error) => deferred.reject(error));
149
+ }
150
+
151
+ return deferred.promise;
152
+ }
153
+
154
+ dispose(): void {
155
+ this.onDidDisconnectEmitter.dispose();
156
+ }
157
+
158
+ disposeSync(): void {
159
+ // No special cleanup needed for WSL
160
+ }
161
+ }
@@ -0,0 +1,38 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2025 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // ****************************************************************************
16
+ import { URI } from '@theia/core';
17
+ import * as fs from '@theia/core/shared/fs-extra';
18
+ import { WorkspaceHandlerContribution } from '@theia/workspace/lib/node/default-workspace-server';
19
+
20
+ export class WslWorkspaceHandler implements WorkspaceHandlerContribution {
21
+ canHandle(uri: URI): boolean {
22
+ return uri.scheme === 'wsl';
23
+ }
24
+ workspaceStillExists(uri: URI): Promise<boolean> {
25
+ return fs.pathExists(this.toWindowsPath(uri.path.toString()));
26
+ }
27
+
28
+ private toWindowsPath(path: string): string {
29
+ const match = path.match(/^\/mnt\/([a-z])\/(.*)/i);
30
+ if (match) {
31
+ const driveLetter = match[1].toUpperCase();
32
+ const windowsPath = match[2].replace(/\//g, '\\');
33
+ return `${driveLetter}:\\${windowsPath}`;
34
+ }
35
+ return path;
36
+ }
37
+
38
+ }
@@ -0,0 +1,29 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /* note: this bogus test file is required so that
18
+ we are able to run mocha unit tests on this
19
+ package, without having any actual unit tests in it.
20
+ This way a coverage report will be generated,
21
+ showing 0% coverage, instead of no report.
22
+ This file can be removed once we have real unit
23
+ tests in place. */
24
+
25
+ describe('remote-wsl package', () => {
26
+
27
+ it('support code coverage statistics', () => true);
28
+
29
+ });