@theia/remote 1.43.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 (142) hide show
  1. package/README.md +61 -0
  2. package/lib/electron-browser/remote-electron-file-dialog-service.d.ts +14 -0
  3. package/lib/electron-browser/remote-electron-file-dialog-service.d.ts.map +1 -0
  4. package/lib/electron-browser/remote-electron-file-dialog-service.js +58 -0
  5. package/lib/electron-browser/remote-electron-file-dialog-service.js.map +1 -0
  6. package/lib/electron-browser/remote-frontend-contribution.d.ts +26 -0
  7. package/lib/electron-browser/remote-frontend-contribution.d.ts.map +1 -0
  8. package/lib/electron-browser/remote-frontend-contribution.js +165 -0
  9. package/lib/electron-browser/remote-frontend-contribution.js.map +1 -0
  10. package/lib/electron-browser/remote-frontend-module.d.ts +4 -0
  11. package/lib/electron-browser/remote-frontend-module.d.ts.map +1 -0
  12. package/lib/electron-browser/remote-frontend-module.js +43 -0
  13. package/lib/electron-browser/remote-frontend-module.js.map +1 -0
  14. package/lib/electron-browser/remote-preferences.d.ts +11 -0
  15. package/lib/electron-browser/remote-preferences.d.ts.map +1 -0
  16. package/lib/electron-browser/remote-preferences.js +49 -0
  17. package/lib/electron-browser/remote-preferences.js.map +1 -0
  18. package/lib/electron-browser/remote-registry-contribution.d.ts +19 -0
  19. package/lib/electron-browser/remote-registry-contribution.d.ts.map +1 -0
  20. package/lib/electron-browser/remote-registry-contribution.js +75 -0
  21. package/lib/electron-browser/remote-registry-contribution.js.map +1 -0
  22. package/lib/electron-browser/remote-service.d.ts +6 -0
  23. package/lib/electron-browser/remote-service.d.ts.map +1 -0
  24. package/lib/electron-browser/remote-service.js +38 -0
  25. package/lib/electron-browser/remote-service.js.map +1 -0
  26. package/lib/electron-browser/remote-ssh-contribution.d.ts +18 -0
  27. package/lib/electron-browser/remote-ssh-contribution.d.ts.map +1 -0
  28. package/lib/electron-browser/remote-ssh-contribution.js +118 -0
  29. package/lib/electron-browser/remote-ssh-contribution.js.map +1 -0
  30. package/lib/electron-common/remote-ssh-connection-provider.d.ts +11 -0
  31. package/lib/electron-common/remote-ssh-connection-provider.d.ts.map +1 -0
  32. package/lib/electron-common/remote-ssh-connection-provider.js +21 -0
  33. package/lib/electron-common/remote-ssh-connection-provider.js.map +1 -0
  34. package/lib/electron-common/remote-status-service.d.ts +15 -0
  35. package/lib/electron-common/remote-status-service.d.ts.map +1 -0
  36. package/lib/electron-common/remote-status-service.js +21 -0
  37. package/lib/electron-common/remote-status-service.js.map +1 -0
  38. package/lib/electron-node/backend-remote-service-impl.d.ts +12 -0
  39. package/lib/electron-node/backend-remote-service-impl.d.ts.map +1 -0
  40. package/lib/electron-node/backend-remote-service-impl.js +51 -0
  41. package/lib/electron-node/backend-remote-service-impl.js.map +1 -0
  42. package/lib/electron-node/remote-backend-module.d.ts +5 -0
  43. package/lib/electron-node/remote-backend-module.d.ts.map +1 -0
  44. package/lib/electron-node/remote-backend-module.js +75 -0
  45. package/lib/electron-node/remote-backend-module.js.map +1 -0
  46. package/lib/electron-node/remote-connection-service.d.ts +15 -0
  47. package/lib/electron-node/remote-connection-service.d.ts.map +1 -0
  48. package/lib/electron-node/remote-connection-service.js +66 -0
  49. package/lib/electron-node/remote-connection-service.js.map +1 -0
  50. package/lib/electron-node/remote-connection-socket-provider.d.ts +9 -0
  51. package/lib/electron-node/remote-connection-socket-provider.d.ts.map +1 -0
  52. package/lib/electron-node/remote-connection-socket-provider.js +38 -0
  53. package/lib/electron-node/remote-connection-socket-provider.js.map +1 -0
  54. package/lib/electron-node/remote-proxy-server-provider.d.ts +6 -0
  55. package/lib/electron-node/remote-proxy-server-provider.d.ts.map +1 -0
  56. package/lib/electron-node/remote-proxy-server-provider.js +44 -0
  57. package/lib/electron-node/remote-proxy-server-provider.js.map +1 -0
  58. package/lib/electron-node/remote-status-service.d.ts +7 -0
  59. package/lib/electron-node/remote-status-service.d.ts.map +1 -0
  60. package/lib/electron-node/remote-status-service.js +55 -0
  61. package/lib/electron-node/remote-status-service.js.map +1 -0
  62. package/lib/electron-node/remote-types.d.ts +35 -0
  63. package/lib/electron-node/remote-types.d.ts.map +1 -0
  64. package/lib/electron-node/remote-types.js +18 -0
  65. package/lib/electron-node/remote-types.js.map +1 -0
  66. package/lib/electron-node/setup/app-native-dependency-contribution.d.ts +8 -0
  67. package/lib/electron-node/setup/app-native-dependency-contribution.d.ts.map +1 -0
  68. package/lib/electron-node/setup/app-native-dependency-contribution.js +58 -0
  69. package/lib/electron-node/setup/app-native-dependency-contribution.js.map +1 -0
  70. package/lib/electron-node/setup/main-copy-contribution.d.ts +5 -0
  71. package/lib/electron-node/setup/main-copy-contribution.d.ts.map +1 -0
  72. package/lib/electron-node/setup/main-copy-contribution.js +38 -0
  73. package/lib/electron-node/setup/main-copy-contribution.js.map +1 -0
  74. package/lib/electron-node/setup/remote-copy-contribution.d.ts +29 -0
  75. package/lib/electron-node/setup/remote-copy-contribution.d.ts.map +1 -0
  76. package/lib/electron-node/setup/remote-copy-contribution.js +79 -0
  77. package/lib/electron-node/setup/remote-copy-contribution.js.map +1 -0
  78. package/lib/electron-node/setup/remote-copy-service.d.ts +19 -0
  79. package/lib/electron-node/setup/remote-copy-service.d.ts.map +1 -0
  80. package/lib/electron-node/setup/remote-copy-service.js +127 -0
  81. package/lib/electron-node/setup/remote-copy-service.js.map +1 -0
  82. package/lib/electron-node/setup/remote-native-dependency-contribution.d.ts +35 -0
  83. package/lib/electron-node/setup/remote-native-dependency-contribution.d.ts.map +1 -0
  84. package/lib/electron-node/setup/remote-native-dependency-contribution.js +35 -0
  85. package/lib/electron-node/setup/remote-native-dependency-contribution.js.map +1 -0
  86. package/lib/electron-node/setup/remote-native-dependency-service.d.ts +24 -0
  87. package/lib/electron-node/setup/remote-native-dependency-service.d.ts.map +1 -0
  88. package/lib/electron-node/setup/remote-native-dependency-service.js +119 -0
  89. package/lib/electron-node/setup/remote-native-dependency-service.js.map +1 -0
  90. package/lib/electron-node/setup/remote-node-setup-service.d.ts +23 -0
  91. package/lib/electron-node/setup/remote-node-setup-service.d.ts.map +1 -0
  92. package/lib/electron-node/setup/remote-node-setup-service.js +133 -0
  93. package/lib/electron-node/setup/remote-node-setup-service.js.map +1 -0
  94. package/lib/electron-node/setup/remote-setup-script-service.d.ts +41 -0
  95. package/lib/electron-node/setup/remote-setup-script-service.d.ts.map +1 -0
  96. package/lib/electron-node/setup/remote-setup-script-service.js +133 -0
  97. package/lib/electron-node/setup/remote-setup-script-service.js.map +1 -0
  98. package/lib/electron-node/setup/remote-setup-service.d.ts +29 -0
  99. package/lib/electron-node/setup/remote-setup-service.d.ts.map +1 -0
  100. package/lib/electron-node/setup/remote-setup-service.js +199 -0
  101. package/lib/electron-node/setup/remote-setup-service.js.map +1 -0
  102. package/lib/electron-node/ssh/remote-ssh-connection-provider.d.ts +56 -0
  103. package/lib/electron-node/ssh/remote-ssh-connection-provider.d.ts.map +1 -0
  104. package/lib/electron-node/ssh/remote-ssh-connection-provider.js +343 -0
  105. package/lib/electron-node/ssh/remote-ssh-connection-provider.js.map +1 -0
  106. package/lib/electron-node/ssh/ssh-identity-file-collector.d.ts +13 -0
  107. package/lib/electron-node/ssh/ssh-identity-file-collector.d.ts.map +1 -0
  108. package/lib/electron-node/ssh/ssh-identity-file-collector.js +132 -0
  109. package/lib/electron-node/ssh/ssh-identity-file-collector.js.map +1 -0
  110. package/lib/package.spec.d.ts +1 -0
  111. package/lib/package.spec.d.ts.map +1 -0
  112. package/lib/package.spec.js +26 -0
  113. package/lib/package.spec.js.map +1 -0
  114. package/package.json +67 -0
  115. package/src/electron-browser/remote-electron-file-dialog-service.ts +47 -0
  116. package/src/electron-browser/remote-frontend-contribution.ts +145 -0
  117. package/src/electron-browser/remote-frontend-module.ts +49 -0
  118. package/src/electron-browser/remote-preferences.ts +62 -0
  119. package/src/electron-browser/remote-registry-contribution.ts +70 -0
  120. package/src/electron-browser/remote-service.ts +31 -0
  121. package/src/electron-browser/remote-ssh-contribution.ts +102 -0
  122. package/src/electron-common/remote-ssh-connection-provider.ts +29 -0
  123. package/src/electron-common/remote-status-service.ts +35 -0
  124. package/src/electron-node/backend-remote-service-impl.ts +45 -0
  125. package/src/electron-node/remote-backend-module.ts +80 -0
  126. package/src/electron-node/remote-connection-service.ts +55 -0
  127. package/src/electron-node/remote-connection-socket-provider.ts +34 -0
  128. package/src/electron-node/remote-proxy-server-provider.ts +37 -0
  129. package/src/electron-node/remote-status-service.ts +41 -0
  130. package/src/electron-node/remote-types.ts +56 -0
  131. package/src/electron-node/setup/app-native-dependency-contribution.ts +48 -0
  132. package/src/electron-node/setup/main-copy-contribution.ts +28 -0
  133. package/src/electron-node/setup/remote-copy-contribution.ts +90 -0
  134. package/src/electron-node/setup/remote-copy-service.ts +114 -0
  135. package/src/electron-node/setup/remote-native-dependency-contribution.ts +63 -0
  136. package/src/electron-node/setup/remote-native-dependency-service.ts +111 -0
  137. package/src/electron-node/setup/remote-node-setup-service.ts +123 -0
  138. package/src/electron-node/setup/remote-setup-script-service.ts +146 -0
  139. package/src/electron-node/setup/remote-setup-service.ts +197 -0
  140. package/src/electron-node/ssh/remote-ssh-connection-provider.ts +356 -0
  141. package/src/electron-node/ssh/ssh-identity-file-collector.ts +137 -0
  142. package/src/package.spec.ts +29 -0
@@ -0,0 +1,90 @@
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
+ import { ApplicationPackage } from '@theia/core/shared/@theia/application-package';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { glob as globCallback } from 'glob';
20
+ import { promisify } from 'util';
21
+ import * as path from 'path';
22
+ import { MaybePromise } from '@theia/core';
23
+
24
+ const promiseGlob = promisify(globCallback);
25
+
26
+ export const RemoteCopyContribution = Symbol('RemoteCopyContribution');
27
+
28
+ export interface RemoteCopyContribution {
29
+ copy(registry: RemoteCopyRegistry): MaybePromise<void>
30
+ }
31
+
32
+ export interface RemoteCopyOptions {
33
+ /**
34
+ * The mode that the file should be set to once copied to the remote.
35
+ *
36
+ * Only relevant for POSIX-like systems
37
+ */
38
+ mode?: number;
39
+ }
40
+
41
+ export interface RemoteFile {
42
+ path: string
43
+ target: string
44
+ options?: RemoteCopyOptions;
45
+ }
46
+
47
+ @injectable()
48
+ export class RemoteCopyRegistry {
49
+
50
+ @inject(ApplicationPackage)
51
+ protected readonly applicationPackage: ApplicationPackage;
52
+
53
+ protected readonly files: RemoteFile[] = [];
54
+
55
+ getFiles(): RemoteFile[] {
56
+ return this.files.slice();
57
+ }
58
+
59
+ async glob(pattern: string, target?: string): Promise<void> {
60
+ const projectPath = this.applicationPackage.projectPath;
61
+ const globResult = await promiseGlob(pattern, {
62
+ cwd: projectPath
63
+ });
64
+ const relativeFiles = globResult.map(file => path.relative(projectPath, file));
65
+ for (const file of relativeFiles) {
66
+ const targetFile = this.withTarget(file, target);
67
+ this.files.push({
68
+ path: file,
69
+ target: targetFile
70
+ });
71
+ }
72
+ }
73
+
74
+ file(file: string, target?: string, options?: RemoteCopyOptions): void {
75
+ const targetFile = this.withTarget(file, target);
76
+ this.files.push({
77
+ path: file,
78
+ target: targetFile,
79
+ options
80
+ });
81
+ }
82
+
83
+ async directory(dir: string, target?: string): Promise<void> {
84
+ return this.glob(dir + '/**', target);
85
+ }
86
+
87
+ protected withTarget(file: string, target?: string): string {
88
+ return target ? path.join(target, file) : file;
89
+ }
90
+ }
@@ -0,0 +1,114 @@
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
+ import * as archiver from 'archiver';
18
+ import * as path from 'path';
19
+ import * as fs from 'fs';
20
+ import * as os from 'os';
21
+ import { ApplicationPackage } from '@theia/core/shared/@theia/application-package';
22
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
23
+ import { RemoteConnection, RemotePlatform } from '../remote-types';
24
+ import { RemoteNativeDependencyService } from './remote-native-dependency-service';
25
+ import { ContributionProvider } from '@theia/core';
26
+ import { RemoteCopyContribution, RemoteCopyRegistry, RemoteFile } from './remote-copy-contribution';
27
+
28
+ @injectable()
29
+ export class RemoteCopyService {
30
+
31
+ @inject(ApplicationPackage)
32
+ protected readonly applicationPackage: ApplicationPackage;
33
+
34
+ @inject(RemoteCopyRegistry)
35
+ protected readonly copyRegistry: RemoteCopyRegistry;
36
+
37
+ @inject(RemoteNativeDependencyService)
38
+ protected readonly nativeDependencyService: RemoteNativeDependencyService;
39
+
40
+ @inject(ContributionProvider) @named(RemoteCopyContribution)
41
+ protected readonly copyContributions: ContributionProvider<RemoteCopyContribution>;
42
+
43
+ protected initialized = false;
44
+
45
+ async copyToRemote(remote: RemoteConnection, remotePlatform: RemotePlatform, destination: string): Promise<void> {
46
+ const zipName = path.basename(destination);
47
+ const projectPath = this.applicationPackage.projectPath;
48
+ const tempDir = await this.getTempDir();
49
+ const zipPath = path.join(tempDir, zipName);
50
+ const files = await this.getFiles(remotePlatform, tempDir);
51
+ // We stream to a file here and then copy it because it is faster
52
+ // Copying files via sftp is 4x times faster compared to readable streams
53
+ const stream = fs.createWriteStream(zipPath);
54
+ const archive = archiver('tar', {
55
+ gzip: true
56
+ });
57
+ archive.pipe(stream);
58
+ for (const file of files) {
59
+ const filePath = path.isAbsolute(file.path)
60
+ ? file.path
61
+ : path.join(projectPath, file.path);
62
+
63
+ archive.file(filePath, {
64
+ name: file.target,
65
+ mode: file.options?.mode
66
+ });
67
+ }
68
+ await archive.finalize();
69
+ await remote.copy(zipPath, destination);
70
+ await fs.promises.rm(tempDir, {
71
+ recursive: true,
72
+ force: true
73
+ });
74
+ }
75
+
76
+ protected async getFiles(remotePlatform: RemotePlatform, tempDir: string): Promise<RemoteFile[]> {
77
+ const [localFiles, nativeDependencies] = await Promise.all([
78
+ this.loadCopyContributions(),
79
+ this.loadNativeDependencies(remotePlatform, tempDir)
80
+ ]);
81
+ return [...localFiles, ...nativeDependencies];
82
+ }
83
+
84
+ protected async loadCopyContributions(): Promise<RemoteFile[]> {
85
+ if (this.initialized) {
86
+ return this.copyRegistry.getFiles();
87
+ }
88
+ await Promise.all(this.copyContributions.getContributions()
89
+ .map(copyContribution => copyContribution.copy(this.copyRegistry)));
90
+ this.initialized = true;
91
+ return this.copyRegistry.getFiles();
92
+ }
93
+
94
+ protected async loadNativeDependencies(remotePlatform: RemotePlatform, tempDir: string): Promise<RemoteFile[]> {
95
+ const dependencyFiles = await this.nativeDependencyService.downloadDependencies(remotePlatform, tempDir);
96
+ return dependencyFiles.map(file => ({
97
+ path: file.path,
98
+ target: file.target,
99
+ options: {
100
+ mode: file.mode
101
+ }
102
+ }));
103
+ }
104
+
105
+ protected async getTempDir(): Promise<string> {
106
+ const dir = path.join(os.tmpdir(), 'theia-remote-');
107
+ const tempDir = await fs.promises.mkdtemp(dir);
108
+ return tempDir;
109
+ }
110
+
111
+ protected async getRemoteDownloadLocation(): Promise<string | undefined> {
112
+ return undefined;
113
+ }
114
+ }
@@ -0,0 +1,63 @@
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
+ import { isObject } from '@theia/core';
18
+ import { RequestOptions } from '@theia/core/shared/@theia/request';
19
+ import { RemotePlatform } from '../remote-types';
20
+
21
+ export interface FileDependencyResult {
22
+ path: string;
23
+ mode?: number;
24
+ }
25
+
26
+ export type DependencyDownload = FileDependencyDownload | DirectoryDependencyDownload;
27
+
28
+ export interface FileDependencyDownload {
29
+ file: FileDependencyResult
30
+ buffer: Buffer
31
+ }
32
+
33
+ export namespace FileDependencyResult {
34
+ export function is(item: unknown): item is FileDependencyDownload {
35
+ return isObject(item) && 'buffer' in item && 'file' in item;
36
+ }
37
+ }
38
+
39
+ export interface DirectoryDependencyDownload {
40
+ archive: 'tar' | 'zip' | 'tgz'
41
+ buffer: Buffer
42
+ }
43
+
44
+ export namespace DirectoryDependencyDownload {
45
+ export function is(item: unknown): item is DirectoryDependencyDownload {
46
+ return isObject(item) && 'buffer' in item && 'archive' in item;
47
+ }
48
+ }
49
+
50
+ export interface DownloadOptions {
51
+ remotePlatform: RemotePlatform
52
+ theiaVersion: string;
53
+ download: (requestInfo: string | RequestOptions) => Promise<Buffer>
54
+ }
55
+
56
+ export const RemoteNativeDependencyContribution = Symbol('RemoteNativeDependencyContribution');
57
+
58
+ /**
59
+ * contribution used for downloading prebuild native dependency when connecting to a remote machine with a different system
60
+ */
61
+ export interface RemoteNativeDependencyContribution {
62
+ download(options: DownloadOptions): Promise<DependencyDownload>;
63
+ }
@@ -0,0 +1,111 @@
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
+ import { ContributionProvider, THEIA_VERSION } from '@theia/core';
18
+ import { inject, injectable, named } from '@theia/core/shared/inversify';
19
+ import { RequestContext, RequestService, RequestOptions } from '@theia/core/shared/@theia/request';
20
+ import * as decompress from 'decompress';
21
+ import * as path from 'path';
22
+ import * as fs from 'fs/promises';
23
+ import { DependencyDownload, DirectoryDependencyDownload, RemoteNativeDependencyContribution } from './remote-native-dependency-contribution';
24
+ import { RemotePlatform } from '../remote-types';
25
+
26
+ const decompressTar = require('decompress-tar');
27
+ const decompressTargz = require('decompress-targz');
28
+ const decompressUnzip = require('decompress-unzip');
29
+
30
+ export const DEFAULT_HTTP_OPTIONS = {
31
+ method: 'GET',
32
+ headers: {
33
+ Accept: 'application/octet-stream'
34
+ },
35
+ };
36
+
37
+ export interface NativeDependencyFile {
38
+ path: string;
39
+ target: string;
40
+ mode?: number;
41
+ }
42
+
43
+ @injectable()
44
+ export class RemoteNativeDependencyService {
45
+
46
+ @inject(ContributionProvider) @named(RemoteNativeDependencyContribution)
47
+ protected nativeDependencyContributions: ContributionProvider<RemoteNativeDependencyContribution>;
48
+
49
+ @inject(RequestService)
50
+ protected requestService: RequestService;
51
+
52
+ async downloadDependencies(remotePlatform: RemotePlatform, directory: string): Promise<NativeDependencyFile[]> {
53
+ const contributionResults = await Promise.all(this.nativeDependencyContributions.getContributions()
54
+ .map(async contribution => {
55
+ const result = await contribution.download({
56
+ remotePlatform,
57
+ theiaVersion: THEIA_VERSION,
58
+ download: requestInfo => this.downloadDependency(requestInfo)
59
+ });
60
+ const dependency = await this.storeDependency(result, directory);
61
+ return dependency;
62
+ }));
63
+ return contributionResults.flat();
64
+ }
65
+
66
+ protected async downloadDependency(downloadURI: string | RequestOptions): Promise<Buffer> {
67
+ const options = typeof downloadURI === 'string'
68
+ ? { url: downloadURI, ...DEFAULT_HTTP_OPTIONS }
69
+ : { ...DEFAULT_HTTP_OPTIONS, ...downloadURI };
70
+ const req = await this.requestService.request(options);
71
+ if (RequestContext.isSuccess(req)) {
72
+ return Buffer.from(req.buffer);
73
+ } else {
74
+ throw new Error('Server error while downloading native dependency from: ' + options.url);
75
+ }
76
+ }
77
+
78
+ protected async storeDependency(dependency: DependencyDownload, directory: string): Promise<NativeDependencyFile[]> {
79
+ if (DirectoryDependencyDownload.is(dependency)) {
80
+ const archiveBuffer = dependency.buffer;
81
+ const plugins: unknown[] = [];
82
+ if (dependency.archive === 'tar') {
83
+ plugins.push(decompressTar());
84
+ } else if (dependency.archive === 'tgz') {
85
+ plugins.push(decompressTargz());
86
+ } else if (dependency.archive === 'zip') {
87
+ plugins.push(decompressUnzip());
88
+ }
89
+ const files = await decompress(archiveBuffer, directory, { plugins });
90
+ const result: NativeDependencyFile[] = await Promise.all(files.map(async file => {
91
+ const localPath = path.join(directory, file.path);
92
+ return {
93
+ path: localPath,
94
+ target: file.path,
95
+ mode: file.mode
96
+ };
97
+ }));
98
+ return result;
99
+ } else {
100
+ const fileName = path.basename(dependency.file.path);
101
+ const localPath = path.join(directory, fileName);
102
+ await fs.writeFile(localPath, dependency.buffer);
103
+ return [{
104
+ path: localPath,
105
+ target: dependency.file.path,
106
+ mode: dependency.file.mode
107
+ }];
108
+ }
109
+ }
110
+
111
+ }
@@ -0,0 +1,123 @@
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
+ import * as path from 'path';
18
+ import * as fs from '@theia/core/shared/fs-extra';
19
+ import * as os from 'os';
20
+
21
+ import { inject, injectable } from '@theia/core/shared/inversify';
22
+ import { RequestService } from '@theia/core/shared/@theia/request';
23
+ import { RemoteSetupScriptService } from './remote-setup-script-service';
24
+ import { RemotePlatform } from '../remote-types';
25
+ import { OS } from '@theia/core';
26
+
27
+ /**
28
+ * The current node version that Theia recommends.
29
+ *
30
+ * Native dependencies are compiled against this version.
31
+ */
32
+ export const REMOTE_NODE_VERSION = '18.17.0';
33
+
34
+ @injectable()
35
+ export class RemoteNodeSetupService {
36
+
37
+ @inject(RequestService)
38
+ protected readonly requestService: RequestService;
39
+
40
+ @inject(RemoteSetupScriptService)
41
+ protected readonly scriptService: RemoteSetupScriptService;
42
+
43
+ getNodeDirectoryName(platform: RemotePlatform): string {
44
+ return `node-v${REMOTE_NODE_VERSION}-${this.getPlatformName(platform)}-${platform.arch}`;
45
+ }
46
+
47
+ protected getPlatformName(platform: RemotePlatform): string {
48
+ let platformId: string;
49
+ if (platform.os === OS.Type.Windows) {
50
+ platformId = 'win';
51
+ } else if (platform.os === OS.Type.OSX) {
52
+ platformId = 'darwin';
53
+ } else {
54
+ platformId = 'linux';
55
+ }
56
+ return platformId;
57
+ }
58
+
59
+ protected validatePlatform(platform: RemotePlatform): void {
60
+ if (platform.os === OS.Type.Windows && !platform.arch.match(/^x(64|86)$/)) {
61
+ this.throwPlatformError(platform, 'x64 and x86');
62
+ } else if (platform.os === OS.Type.Linux && !platform.arch.match(/^(x64|armv7l|arm64)$/)) {
63
+ this.throwPlatformError(platform, 'x64, armv7l and arm64');
64
+ } else if (platform.os === OS.Type.OSX && !platform.arch.match(/^(x64|arm64)$/)) {
65
+ this.throwPlatformError(platform, 'x64 and arm64');
66
+ }
67
+ }
68
+
69
+ protected throwPlatformError(platform: RemotePlatform, supportedArch: string): never {
70
+ throw new Error(`Invalid architecture for ${platform.os}: '${platform.arch}'. Only ${supportedArch} are supported.`);
71
+ }
72
+
73
+ protected getNodeFileExtension(platform: RemotePlatform): string {
74
+ let fileExtension: string;
75
+ if (platform.os === OS.Type.Windows) {
76
+ fileExtension = 'zip';
77
+ } else if (platform.os === OS.Type.OSX) {
78
+ fileExtension = 'tar.gz';
79
+ } else {
80
+ fileExtension = 'tar.xz';
81
+ }
82
+ return fileExtension;
83
+ }
84
+
85
+ getNodeFileName(platform: RemotePlatform): string {
86
+ return `${this.getNodeDirectoryName(platform)}.${this.getNodeFileExtension(platform)}`;
87
+ }
88
+
89
+ async downloadNode(platform: RemotePlatform, downloadTemplate?: string): Promise<string> {
90
+ this.validatePlatform(platform);
91
+ const fileName = this.getNodeFileName(platform);
92
+ const tmpdir = os.tmpdir();
93
+ const localPath = path.join(tmpdir, fileName);
94
+ if (!await fs.pathExists(localPath)) {
95
+ const downloadPath = this.getDownloadPath(platform, downloadTemplate);
96
+ const downloadResult = await this.requestService.request({
97
+ url: downloadPath
98
+ });
99
+ await fs.writeFile(localPath, downloadResult.buffer);
100
+ }
101
+ return localPath;
102
+ }
103
+
104
+ generateDownloadScript(platform: RemotePlatform, targetPath: string, downloadTemplate?: string): string {
105
+ this.validatePlatform(platform);
106
+ const fileName = this.getNodeFileName(platform);
107
+ const downloadPath = this.getDownloadPath(platform, downloadTemplate);
108
+ const zipPath = this.scriptService.joinPath(platform, targetPath, fileName);
109
+ const download = this.scriptService.downloadFile(platform, downloadPath, zipPath);
110
+ const unzip = this.scriptService.unzip(platform, zipPath, targetPath);
111
+ return this.scriptService.joinScript(platform, download, unzip);
112
+ }
113
+
114
+ protected getDownloadPath(platform: RemotePlatform, downloadTemplate?: string): string {
115
+ const template = downloadTemplate || 'https://nodejs.org/dist/v{version}/node-v{version}-{os}-{arch}.{ext}';
116
+ const downloadPath = template
117
+ .replace(/{version}/g, REMOTE_NODE_VERSION)
118
+ .replace(/{os}/g, this.getPlatformName(platform))
119
+ .replace(/{arch}/g, platform.arch)
120
+ .replace(/{ext}/g, this.getNodeFileExtension(platform));
121
+ return downloadPath;
122
+ }
123
+ }
@@ -0,0 +1,146 @@
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
+ import { OS } from '@theia/core';
18
+ import { inject, injectable } from '@theia/core/shared/inversify';
19
+ import { RemotePlatform } from '../remote-types';
20
+
21
+ export interface RemoteScriptStrategy {
22
+ exec(): string;
23
+ downloadFile(url: string, output: string): string;
24
+ unzip(file: string, directory: string): string;
25
+ mkdir(path: string): string;
26
+ home(): string;
27
+ joinPath(...segments: string[]): string;
28
+ joinScript(...segments: string[]): string;
29
+ }
30
+
31
+ @injectable()
32
+ export class RemoteWindowsScriptStrategy implements RemoteScriptStrategy {
33
+
34
+ home(): string {
35
+ return 'PowerShell -Command $HOME';
36
+ }
37
+
38
+ exec(): string {
39
+ return 'PowerShell -Command';
40
+ }
41
+
42
+ downloadFile(url: string, output: string): string {
43
+ return `PowerShell -Command Invoke-WebRequest -Uri "${url}" -OutFile ${output}`;
44
+ }
45
+
46
+ unzip(file: string, directory: string): string {
47
+ return `tar -xf "${file}" -C "${directory}"`;
48
+ }
49
+
50
+ mkdir(path: string): string {
51
+ return `PowerShell -Command New-Item -Force -itemType Directory -Path "${path}"`;
52
+ }
53
+
54
+ joinPath(...segments: string[]): string {
55
+ return segments.join('\\');
56
+ }
57
+
58
+ joinScript(...segments: string[]): string {
59
+ return segments.join('\r\n');
60
+ }
61
+ }
62
+
63
+ @injectable()
64
+ export class RemotePosixScriptStrategy implements RemoteScriptStrategy {
65
+
66
+ home(): string {
67
+ return 'eval echo ~';
68
+ }
69
+
70
+ exec(): string {
71
+ return 'sh -c';
72
+ }
73
+
74
+ downloadFile(url: string, output: string): string {
75
+ return `
76
+ if [ "$(command -v wget)" ]; then
77
+ echo "Downloading using wget"
78
+ wget -O "${output}" "${url}"
79
+ elif [ "$(command -v curl)" ]; then
80
+ echo "Downloading using curl"
81
+ curl "${url}" --output "${output}"
82
+ else
83
+ echo "Failed to find wget or curl."
84
+ exit 1
85
+ fi
86
+ `.trim();
87
+ }
88
+
89
+ unzip(file: string, directory: string): string {
90
+ return `tar -xf "${file}" -C "${directory}"`;
91
+ }
92
+
93
+ mkdir(path: string): string {
94
+ return `mkdir -p "${path}"`;
95
+ }
96
+
97
+ joinPath(...segments: string[]): string {
98
+ return segments.join('/');
99
+ }
100
+
101
+ joinScript(...segments: string[]): string {
102
+ return segments.join('\n');
103
+ }
104
+ }
105
+
106
+ @injectable()
107
+ export class RemoteSetupScriptService {
108
+
109
+ @inject(RemoteWindowsScriptStrategy)
110
+ protected windowsStrategy: RemoteWindowsScriptStrategy;
111
+
112
+ @inject(RemotePosixScriptStrategy)
113
+ protected posixStrategy: RemotePosixScriptStrategy;
114
+
115
+ protected getStrategy(platform: RemotePlatform): RemoteScriptStrategy {
116
+ return platform.os === OS.Type.Windows ? this.windowsStrategy : this.posixStrategy;
117
+ }
118
+
119
+ home(platform: RemotePlatform): string {
120
+ return this.getStrategy(platform).home();
121
+ }
122
+
123
+ exec(platform: RemotePlatform): string {
124
+ return this.getStrategy(platform).exec();
125
+ }
126
+
127
+ downloadFile(platform: RemotePlatform, url: string, output: string): string {
128
+ return this.getStrategy(platform).downloadFile(url, output);
129
+ }
130
+
131
+ unzip(platform: RemotePlatform, file: string, directory: string): string {
132
+ return this.getStrategy(platform).unzip(file, directory);
133
+ }
134
+
135
+ mkdir(platform: RemotePlatform, path: string): string {
136
+ return this.getStrategy(platform).mkdir(path);
137
+ }
138
+
139
+ joinPath(platform: RemotePlatform, ...segments: string[]): string {
140
+ return this.getStrategy(platform).joinPath(...segments);
141
+ }
142
+
143
+ joinScript(platform: RemotePlatform, ...segments: string[]): string {
144
+ return this.getStrategy(platform).joinScript(...segments);
145
+ }
146
+ }