Skip to content

Commit 770e0db

Browse files
committed
Add cli arguments
1 parent 6a35ab1 commit 770e0db

8 files changed

Lines changed: 164 additions & 52 deletions

File tree

channel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { IEnvironmentService } from "vs/platform/environment/common/environment"
1313
import { IExtensionDescription, ExtensionIdentifier } from "vs/platform/extensions/common/extensions";
1414
import { FileDeleteOptions, FileOverwriteOptions, FileType, IStat, IWatchOptions, FileOpenOptions } from "vs/platform/files/common/files";
1515
import { ILogService } from "vs/platform/log/common/log";
16-
import { IProductService } from "vs/platform/product/common/product";
16+
import pkg from "vs/platform/product/node/package";
17+
import product from "vs/platform/product/node/product";
1718
import { IRemoteAgentEnvironment } from "vs/platform/remote/common/remoteAgentEnvironment";
1819
import { ExtensionScanner, ExtensionScannerInput } from "vs/workbench/services/extensions/node/extensionPoints";
1920
import { DiskFileSystemProvider } from "vs/workbench/services/files/node/diskFileSystemProvider";
@@ -200,14 +201,13 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
200201

201202
private async scanExtensions(locale: string): Promise<IExtensionDescription[]> {
202203
const root = getPathFromAmdModule(require, "");
203-
const product = require.__$__nodeRequire(path.resolve(root, "../package.json")) as IProductService;
204204

205205
const translations = {}; // TODO: translations
206206

207207
// TODO: there is also this.environment.extensionDevelopmentLocationURI to look into.
208208
const scanBuiltin = async (): Promise<IExtensionDescription[]> => {
209209
const input = new ExtensionScannerInput(
210-
product.version, product.commit, locale, !!process.env.VSCODE_DEV,
210+
pkg.version, product.commit, locale, !!process.env.VSCODE_DEV,
211211
path.resolve(root, "../extensions"),
212212
true,
213213
false,
@@ -220,7 +220,7 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
220220

221221
const scanInstalled = async (): Promise<IExtensionDescription[]> => {
222222
const input = new ExtensionScannerInput(
223-
product.version, product.commit, locale, !!process.env.VSCODE_DEV,
223+
pkg.version, product.commit, locale, !!process.env.VSCODE_DEV,
224224
this.environment.extensionsPath, false, true, translations,
225225
);
226226
return ExtensionScanner.scanExtensions(input, this.log);

cli.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as os from "os";
2+
import { validatePaths } from "vs/code/node/paths";
3+
import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper";
4+
import { ParsedArgs } from "vs/platform/environment/common/environment";
5+
import { buildHelpMessage, buildVersionMessage } from "vs/platform/environment/node/argv";
6+
import product from "vs/platform/product/node/product";
7+
import pkg from "vs/platform/product/node/package";
8+
import { MainServer, WebviewServer } from "vs/server/server";
9+
import "vs/server/tar";
10+
11+
interface IMainCli {
12+
main: (argv: ParsedArgs) => Promise<void>;
13+
}
14+
15+
const main = async (): Promise<void> => {
16+
const args = validatePaths(parseMainProcessArgv(process.argv));
17+
18+
if (!product.extensionsGallery) {
19+
product.extensionsGallery = {
20+
serviceUrl: process.env.SERVICE_URL || "https://v1.extapi.coder.com",
21+
itemUrl: process.env.ITEM_URL || "",
22+
controlUrl: "",
23+
recommendationsUrl: "",
24+
};
25+
}
26+
27+
if (args.help) {
28+
const executable = `${product.applicationName}${os.platform() === "win32" ? ".exe" : ""}`;
29+
return console.log(buildHelpMessage(product.nameLong, executable, pkg.version));
30+
}
31+
32+
if (args.version) {
33+
return console.log(buildVersionMessage(pkg.version, product.commit));
34+
}
35+
36+
const shouldSpawnCliProcess = (): boolean => {
37+
return !!args["install-source"]
38+
|| !!args["list-extensions"]
39+
|| !!args["install-extension"]
40+
|| !!args["uninstall-extension"]
41+
|| !!args["locate-extension"]
42+
|| !!args["telemetry"];
43+
};
44+
45+
if (shouldSpawnCliProcess()) {
46+
const cli = await new Promise<IMainCli>((c, e) => require(["vs/code/node/cliProcessMain"], c, e));
47+
await cli.main(args);
48+
// There is some WriteStream instance keeping it open so force an exit.
49+
return process.exit(0);
50+
}
51+
52+
const webviewServer = new WebviewServer();
53+
const server = new MainServer(webviewServer, args);
54+
// The main server inserts webview server address to the root HTML, so we'll
55+
// need to wait for it to listen otherwise the address will be null.
56+
await webviewServer.listen(8444);
57+
await server.listen(8443);
58+
console.log(`Main server serving ${server.address}`);
59+
console.log(`Webview server serving ${webviewServer.address}`);
60+
};
61+
62+
main().catch((error) => {
63+
console.error(error);
64+
process.exit(1);
65+
});

entry.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require("../../bootstrap-amd").load("vs/server/entry");
1+
require("../../bootstrap-amd").load("vs/server/cli");

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
"build": "echo TODO && exit 1"
66
},
77
"devDependencies": {
8+
"@types/tar-stream": "^1.6.1",
89
"nodemon": "^1.19.1"
10+
},
11+
"dependencies": {
12+
"tar-stream": "^2.1.0"
13+
},
14+
"resolutions": {
15+
"@types/node": "^10.12.12"
916
}
1017
}

server.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import * as path from "path";
55
import * as util from "util";
66
import * as url from "url";
77

8-
import { getPathFromAmdModule } from "vs/base/common/amd";
98
import { Emitter } from "vs/base/common/event";
109
import { sanitizeFilePath } from "vs/base/common/extpath";
1110
import { getMediaMime } from "vs/base/common/mime";
1211
import { extname } from "vs/base/common/path";
1312
import { UriComponents, URI } from "vs/base/common/uri";
1413
import { IPCServer, ClientConnectionEvent } from "vs/base/parts/ipc/common/ipc";
15-
import { validatePaths } from "vs/code/node/paths";
1614
import { LogsDataCleaner } from "vs/code/electron-browser/sharedProcess/contrib/logsDataCleaner";
17-
import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper";
1815
import { IEnvironmentService, ParsedArgs } from "vs/platform/environment/common/environment";
1916
import { EnvironmentService } from "vs/platform/environment/node/environmentService";
2017
import { InstantiationService } from "vs/platform/instantiation/common/instantiationService";
@@ -23,6 +20,7 @@ import { getLogLevel, ILogService } from "vs/platform/log/common/log";
2320
import { LogLevelSetterChannel } from "vs/platform/log/common/logIpc";
2421
import { SpdLogService } from "vs/platform/log/node/spdlogService";
2522
import { IProductConfiguration } from "vs/platform/product/common/product";
23+
import product from "vs/platform/product/node/product";
2624
import { ConnectionType, ConnectionTypeRequest } from "vs/platform/remote/common/remoteAgentConnection";
2725
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME } from "vs/platform/remote/common/remoteAgentFileSystemChannel";
2826
import { RemoteExtensionLogFileName } from "vs/workbench/services/remote/common/remoteAgentService";
@@ -123,7 +121,7 @@ export class MainServer extends Server {
123121

124122
private readonly services = new ServiceCollection();
125123

126-
public constructor(private readonly webviewServer: WebviewServer) {
124+
public constructor(private readonly webviewServer: WebviewServer, args: ParsedArgs) {
127125
super();
128126

129127
this.server.on("upgrade", async (request, socket) => {
@@ -134,10 +132,6 @@ export class MainServer extends Server {
134132
protocol.dispose(error);
135133
}
136134
});
137-
}
138-
139-
public async listen(port: number): Promise<void> {
140-
const args = validatePaths(parseMainProcessArgv(process.argv));
141135

142136
const environmentService = new EnvironmentService(args, process.execPath);
143137
this.services.set(IEnvironmentService, environmentService);
@@ -163,8 +157,6 @@ export class MainServer extends Server {
163157
new ExtensionEnvironmentChannel(environmentService, logService),
164158
);
165159
});
166-
167-
await super.listen(port);
168160
}
169161

170162
protected async handleRequest(
@@ -203,9 +195,7 @@ export class MainServer extends Server {
203195
REMOTE_USER_DATA_URI: transformer.transformOutgoing(
204196
(this.services.get(IEnvironmentService) as EnvironmentService).webUserDataHome,
205197
),
206-
PRODUCT_CONFIGURATION: require.__$__nodeRequire(
207-
path.resolve(getPathFromAmdModule(require, ""), "../product.json"),
208-
),
198+
PRODUCT_CONFIGURATION: product,
209199
CONNECTION_AUTH_TOKEN: "",
210200
};
211201

tar.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
/*---------------------------------------------------------------------------------------------
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
4-
*--------------------------------------------------------------------------------------------*/
5-
61
import * as nls from "vs/nls";
7-
import * as vszip from "vszip";
2+
import * as vszip from "vs/base/node/zip";
83
import * as fs from "fs";
94
import * as path from "path";
105
import * as tarStream from "tar-stream";
116
import { promisify } from "util";
127
import { CancellationToken } from "vs/base/common/cancellation";
138
import { mkdirp } from "vs/base/node/pfs";
149

10+
// We will be overriding these, so keep a reference to the original.
11+
const vszipExtract = vszip.extract;
12+
const vszipBuffer = vszip.buffer;
13+
1514
export interface IExtractOptions {
1615
overwrite?: boolean;
1716

@@ -29,8 +28,8 @@ export interface IFile {
2928
}
3029

3130
/**
32-
* Override the standard VS Code behavior for zipping
33-
* extensions to use the TAR format instead of ZIP.
31+
* Override the standard VS Code behavior for zipping extensions to use the TAR
32+
* format instead of ZIP.
3433
*/
3534
export const zip = (tarPath: string, files: IFile[]): Promise<string> => {
3635
return new Promise<string>((c, e): void => {
@@ -63,10 +62,9 @@ export const zip = (tarPath: string, files: IFile[]): Promise<string> => {
6362
};
6463

6564
/**
66-
* Override the standard VS Code behavior for extracting
67-
* archives, to first attempt to process the archive as a TAR
68-
* and then fallback on the original implementation, for processing
69-
* ZIPs.
65+
* Override the standard VS Code behavior for extracting archives to first
66+
* attempt to process the archive as a TAR and then fall back to the original
67+
* implementation for processing ZIPs.
7068
*/
7169
export const extract = (archivePath: string, extractPath: string, options: IExtractOptions = {}, token: CancellationToken): Promise<void> => {
7270
return new Promise<void>((c, e): void => {
@@ -76,15 +74,15 @@ export const extract = (archivePath: string, extractPath: string, options: IExtr
7674

7775
return;
7876
}
79-
vszip.extract(archivePath, extractPath, options, token).then(c).catch(e);
77+
vszipExtract(archivePath, extractPath, options, token).then(c).catch(e);
8078
});
8179
});
8280
};
8381

8482
/**
85-
* Override the standard VS Code behavior for buffering
86-
* archives, to first process the Buffer as a TAR and then
87-
* fallback on the original implementation, for processing ZIPs.
83+
* Override the standard VS Code behavior for buffering archives to first
84+
* process the Buffer as a TAR and then fall back to the original
85+
* implementation for processing ZIPs.
8886
*/
8987
export const buffer = (targetPath: string, filePath: string): Promise<Buffer> => {
9088
return new Promise<Buffer>((c, e): void => {
@@ -104,16 +102,16 @@ export const buffer = (targetPath: string, filePath: string): Promise<Buffer> =>
104102

105103
return;
106104
}
107-
vszip.buffer(targetPath, filePath).then(c).catch(e);
105+
vszipBuffer(targetPath, filePath).then(c).catch(e);
108106
});
109107
});
110108
};
111109

112110
/**
113-
* Override the standard VS Code behavior for extracting assets
114-
* from archive Buffers to use the TAR format instead of ZIP.
111+
* Override the standard VS Code behavior for extracting assets from archive
112+
* Buffers to use the TAR format instead of ZIP.
115113
*/
116-
export const extractAssets = (tarPath: string, match: RegExp, callback: (path: string, data: Buffer) => void): Promise<void> => {
114+
const extractAssets = (tarPath: string, match: RegExp, callback: (path: string, data: Buffer) => void): Promise<void> => {
117115
return new Promise<void>(async (c, e): Promise<void> => {
118116
try {
119117
const buffer = await promisify(fs.readFile)(tarPath);
@@ -217,3 +215,9 @@ const extractTar = (tarPath: string, targetPath: string, options: IExtractOption
217215
}
218216
});
219217
};
218+
219+
// Override original functionality so we can use tar instead of zip.
220+
const target = vszip as typeof vszip;
221+
target.zip = zip;
222+
target.extract = extract;
223+
target.buffer = buffer;

0 commit comments

Comments
 (0)