Skip to content

Commit 2c289a4

Browse files
code-asherkylecarbs
authored andcommitted
Use Coder marketplace (#44)
* Allow setting marketplace URL * Add zip fill * Comment out CSP for now * Fill zip on client as well Probably will need it for client-side extensions. * Don't use itemUrl (it's undefined) * Remove extension rating * Hide ratings with CSS instead of patching them out * Add hard-coded fallback for service URL * Only use coder-develop for extapi if env is explicitly development * Don't use coder-develop at all for extapi If you need it, you can set SERVICE_URL.
1 parent 5734a18 commit 2c289a4

File tree

9 files changed

+315
-7
lines changed

9 files changed

+315
-7
lines changed

packages/vscode/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
"description": "VS Code implementation of the browser-based IDE client.",
44
"main": "src/index.ts",
55
"scripts": {
6-
"build:bootstrap-fork": "cross-env UV_THREADPOOL_SIZE=100 node --max-old-space-size=32384 ../../node_modules/webpack/bin/webpack.js --config ./webpack.bootstrap.config.js"
6+
"build:bootstrap-fork": "cross-env UV_THREADPOOL_SIZE=100 node --max-old-space-size=32384 ../../node_modules/webpack/bin/webpack.js --config ./webpack.bootstrap.config.js"
77
},
88
"dependencies": {
99
"iconv-lite": "^0.4.24",
1010
"onigasm": "^2.2.1",
1111
"spdlog": "^0.7.2",
12-
"string-replace-loader": "^2.1.1"
12+
"string-replace-loader": "^2.1.1",
13+
"tar-stream": "^2.0.1"
1314
},
1415
"devDependencies": {
16+
"@types/tar-stream": "^1.6.0",
1517
"vscode-textmate": "^4.0.1"
1618
}
1719
}

packages/vscode/src/fill/product.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ const product = {
55
nameLong: "code-server",
66
dataFolderName: ".code-server",
77
extensionsGallery: {
8-
serviceUrl: "https://marketplace.visualstudio.com/_apis/public/gallery",
9-
cacheUrl: "https://vscode.blob.core.windows.net/gallery/index",
10-
itemUrl: "https://marketplace.visualstudio.com/items",
11-
controlUrl: "https://az764295.vo.msecnd.net/extensions/marketplace.json",
12-
recommendationsUrl: "https://az764295.vo.msecnd.net/extensions/workspaceRecommendations.json.gz",
8+
serviceUrl: global && global.process && global.process.env.SERVICE_URL
9+
|| process.env.SERVICE_URL
10+
|| "https://v1.extapi.coder.com",
1311
},
1412
extensionExecutionEnvironments: {
1513
"wayou.vscode-todo-highlight": "worker",

packages/vscode/src/fill/zip.ts

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
6+
import * as nls from "vs/nls";
7+
import * as fs from "fs";
8+
import * as path from "path";
9+
import * as tarStream from "tar-stream";
10+
import { promisify } from "util";
11+
import { ILogService } from "vs/platform/log/common/log";
12+
import { CancellationToken } from "vs/base/common/cancellation";
13+
import { mkdirp } from "vs/base/node/pfs";
14+
15+
export interface IExtractOptions {
16+
overwrite?: boolean;
17+
18+
/**
19+
* Source path within the ZIP archive. Only the files contained in this
20+
* path will be extracted.
21+
*/
22+
sourcePath?: string;
23+
}
24+
25+
export interface IFile {
26+
path: string;
27+
contents?: Buffer | string;
28+
localPath?: string;
29+
}
30+
31+
export function zip(tarPath: string, files: IFile[]): Promise<string> {
32+
return new Promise<string>((c, e) => {
33+
const pack = tarStream.pack();
34+
const chunks: Buffer[] = [];
35+
const ended = new Promise<Buffer>((res, rej) => {
36+
pack.on("end", () => {
37+
res(Buffer.concat(chunks));
38+
});
39+
});
40+
pack.on("data", (chunk) => {
41+
chunks.push(chunk as Buffer);
42+
});
43+
for (let i = 0; i < files.length; i++) {
44+
const file = files[i];
45+
pack.entry({
46+
name: file.path,
47+
}, file.contents);
48+
}
49+
pack.finalize();
50+
51+
ended.then((buffer) => {
52+
return promisify(fs.writeFile)(tarPath, buffer);
53+
}).then(() => {
54+
c(tarPath);
55+
}).catch((ex) => {
56+
e(ex);
57+
});
58+
});
59+
}
60+
61+
export async function extract(tarPath: string, targetPath: string, options: IExtractOptions = {}, logService: ILogService, token: CancellationToken): Promise<void> {
62+
const sourcePathRegex = new RegExp(options.sourcePath ? `^${options.sourcePath}` : '');
63+
64+
return new Promise<void>(async (c, e) => {
65+
const buffer = await promisify(fs.readFile)(tarPath);
66+
const extractor = tarStream.extract();
67+
extractor.once('error', e);
68+
extractor.on('entry', (header, stream, next) => {
69+
const rawName = header.name;
70+
71+
const nextEntry = (): void => {
72+
stream.resume();
73+
next();
74+
};
75+
76+
if (token.isCancellationRequested) {
77+
return nextEntry();
78+
}
79+
80+
if (!sourcePathRegex.test(rawName)) {
81+
return nextEntry();
82+
}
83+
84+
const fileName = rawName.replace(sourcePathRegex, '');
85+
86+
const targetFileName = path.join(targetPath, fileName);
87+
if (/\/$/.test(fileName)) {
88+
stream.resume();
89+
mkdirp(targetFileName).then(() => {
90+
next();
91+
}, e);
92+
return;
93+
}
94+
95+
const dirName = path.dirname(fileName);
96+
const targetDirName = path.join(targetPath, dirName);
97+
if (targetDirName.indexOf(targetPath) !== 0) {
98+
e(nls.localize('invalid file', "Error extracting {0}. Invalid file.", fileName));
99+
return nextEntry();
100+
}
101+
102+
mkdirp(targetDirName, void 0, token).then(() => {
103+
const fstream = fs.createWriteStream(targetFileName, { mode: header.mode });
104+
fstream.once('close', () => {
105+
next();
106+
});
107+
fstream.once('error', (err) => {
108+
e(err);
109+
});
110+
stream.pipe(fstream);
111+
stream.resume();
112+
});
113+
});
114+
extractor.once('finish', () => {
115+
c();
116+
});
117+
extractor.write(buffer);
118+
extractor.end();
119+
});
120+
}
121+
122+
export function buffer(tarPath: string, filePath: string): Promise<Buffer> {
123+
return new Promise<Buffer>(async (c, e) => {
124+
let done: boolean = false;
125+
extractAssets(tarPath, new RegExp(filePath), (path: string, data: Buffer) => {
126+
if (path === filePath) {
127+
done = true;
128+
c(data);
129+
}
130+
}).then(() => {
131+
if (!done) {
132+
e("couldnt find asset " + filePath);
133+
}
134+
}).catch((ex) => {
135+
e(ex);
136+
});
137+
});
138+
}
139+
140+
async function extractAssets(tarPath: string, match: RegExp, callback: (path: string, data: Buffer) => void): Promise<void> {
141+
const buffer = await promisify(fs.readFile)(tarPath);
142+
const extractor = tarStream.extract();
143+
let callbackResolve: () => void;
144+
let callbackReject: (ex?) => void;
145+
const complete = new Promise<void>((r, rej) => {
146+
callbackResolve = r;
147+
callbackReject = rej;
148+
});
149+
extractor.once("error", (err) => {
150+
callbackReject(err);
151+
});
152+
extractor.on("entry", (header, stream, next) => {
153+
const name = header.name;
154+
if (match.test(name)) {
155+
extractData(stream).then((data) => {
156+
callback(name, data);
157+
next();
158+
});
159+
stream.resume();
160+
} else {
161+
stream.on("end", () => {
162+
next();
163+
});
164+
stream.resume();
165+
}
166+
});
167+
extractor.on("finish", () => {
168+
callbackResolve();
169+
});
170+
extractor.write(buffer);
171+
extractor.end();
172+
return complete;
173+
}
174+
175+
async function extractData(stream: NodeJS.ReadableStream): Promise<Buffer> {
176+
return new Promise<Buffer>((res, rej) => {
177+
const fileData: Buffer[] = [];
178+
stream.on('data', (data) => fileData.push(data));
179+
stream.on('end', () => {
180+
const fd = Buffer.concat(fileData);
181+
res(fd);
182+
});
183+
stream.on('error', (err) => {
184+
rej(err);
185+
});
186+
});
187+
}

packages/vscode/src/vscode.scss

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
margin-left: initial;
2020
}
2121

22+
// We don't have rating data.
23+
.extension-ratings {
24+
display: none !important;
25+
}
26+
2227
// Using @supports to keep the Firefox fixes completely separate from vscode's
2328
// CSS that is tailored for Chrome.
2429
@supports (-moz-appearance:none) {

packages/vscode/webpack.bootstrap.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = merge(
5959
"vs/base/node/paths": path.resolve(vsFills, "paths.ts"),
6060
"vs/platform/node/package": path.resolve(vsFills, "package.ts"),
6161
"vs/platform/node/product": path.resolve(vsFills, "product.ts"),
62+
"vs/platform/node/zip": path.resolve(vsFills, "zip.ts"),
6263
"vs": path.resolve(root, "lib/vscode/src/vs"),
6364
},
6465
},

packages/vscode/yarn.lock

+85
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# yarn lockfile v1
33

44

5+
"@types/node@*":
6+
version "11.9.6"
7+
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.9.6.tgz#c632bbcc780a1349673a6e2e9b9dfa8c369d3c74"
8+
integrity sha512-4hS2K4gwo9/aXIcoYxCtHpdgd8XUeDmo1siRCAH3RziXB65JlPqUFMtfy9VPj+og7dp3w1TFjGwYga4e0m9GwA==
9+
10+
"@types/tar-stream@^1.6.0":
11+
version "1.6.0"
12+
resolved "https://registry.yarnpkg.com/@types/tar-stream/-/tar-stream-1.6.0.tgz#e19893886625c4ec1c7c30a353b8dc10e205c742"
13+
integrity sha512-XG7FGVmxUvC5NW4h63K3PbB0xdC21xZBfoqmEz7YP2DdiTeYKmYAg8quSHMndNP3iXfs7C73rg4Q0W1dOPHBXQ==
14+
dependencies:
15+
"@types/node" "*"
16+
517
ajv-keywords@^3.1.0:
618
version "3.2.0"
719
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.2.0.tgz#e86b819c602cf8821ad637413698f1dec021847a"
@@ -27,11 +39,25 @@ bindings@^1.3.0:
2739
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.1.tgz#21fc7c6d67c18516ec5aaa2815b145ff77b26ea5"
2840
integrity sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==
2941

42+
bl@^3.0.0:
43+
version "3.0.0"
44+
resolved "https://registry.yarnpkg.com/bl/-/bl-3.0.0.tgz#3611ec00579fd18561754360b21e9f784500ff88"
45+
integrity sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==
46+
dependencies:
47+
readable-stream "^3.0.1"
48+
3049
emojis-list@^2.0.0:
3150
version "2.1.0"
3251
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
3352
integrity sha1-TapNnbAPmBmIDHn6RXrlsJof04k=
3453

54+
end-of-stream@^1.4.1:
55+
version "1.4.1"
56+
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
57+
integrity sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==
58+
dependencies:
59+
once "^1.4.0"
60+
3561
fast-deep-equal@^2.0.1:
3662
version "2.0.1"
3763
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
@@ -42,13 +68,23 @@ fast-json-stable-stringify@^2.0.0:
4268
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
4369
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
4470

71+
fs-constants@^1.0.0:
72+
version "1.0.0"
73+
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
74+
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
75+
4576
iconv-lite@^0.4.24:
4677
version "0.4.24"
4778
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
4879
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
4980
dependencies:
5081
safer-buffer ">= 2.1.2 < 3"
5182

83+
inherits@^2.0.3:
84+
version "2.0.3"
85+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
86+
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
87+
5288
json-schema-traverse@^0.4.1:
5389
version "0.4.1"
5490
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
@@ -100,6 +136,13 @@ nan@^2.10.0, nan@^2.8.0:
100136
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
101137
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
102138

139+
once@^1.4.0:
140+
version "1.4.0"
141+
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
142+
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
143+
dependencies:
144+
wrappy "1"
145+
103146
onigasm@^2.2.1:
104147
version "2.2.1"
105148
resolved "https://registry.yarnpkg.com/onigasm/-/onigasm-2.2.1.tgz#d56da809d63d3bb25510e8b8e447ffe98e56bebb"
@@ -124,6 +167,20 @@ punycode@^2.1.0:
124167
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
125168
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
126169

170+
readable-stream@^3.0.1, readable-stream@^3.1.1:
171+
version "3.2.0"
172+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.2.0.tgz#de17f229864c120a9f56945756e4f32c4045245d"
173+
integrity sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==
174+
dependencies:
175+
inherits "^2.0.3"
176+
string_decoder "^1.1.1"
177+
util-deprecate "^1.0.1"
178+
179+
safe-buffer@~5.1.0:
180+
version "5.1.2"
181+
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
182+
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
183+
127184
"safer-buffer@>= 2.1.2 < 3":
128185
version "2.1.2"
129186
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
@@ -154,20 +211,48 @@ string-replace-loader@^2.1.1:
154211
loader-utils "^1.1.0"
155212
schema-utils "^0.4.5"
156213

214+
string_decoder@^1.1.1:
215+
version "1.2.0"
216+
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.2.0.tgz#fe86e738b19544afe70469243b2a1ee9240eae8d"
217+
integrity sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==
218+
dependencies:
219+
safe-buffer "~5.1.0"
220+
221+
tar-stream@^2.0.1:
222+
version "2.0.1"
223+
resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.0.1.tgz#42fbe41cd1cc5e6657c813e7d98e7afca2858a8c"
224+
integrity sha512-I6OJF7wE62BC6zNPdHDtseK0D0187PBjbKSLYY4ffvVkBM6tyBn2O9plDvVM2229/mozfEL/X3++qSvYYQE2xw==
225+
dependencies:
226+
bl "^3.0.0"
227+
end-of-stream "^1.4.1"
228+
fs-constants "^1.0.0"
229+
inherits "^2.0.3"
230+
readable-stream "^3.1.1"
231+
157232
uri-js@^4.2.2:
158233
version "4.2.2"
159234
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"
160235
integrity sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==
161236
dependencies:
162237
punycode "^2.1.0"
163238

239+
util-deprecate@^1.0.1:
240+
version "1.0.2"
241+
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
242+
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=
243+
164244
vscode-textmate@^4.0.1:
165245
version "4.0.1"
166246
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-4.0.1.tgz#6c36f28e9059ce12bc34907f7a33ea43166b26a8"
167247
integrity sha512-gHTXTj04TUgbjB8y7pkVwxOiuCuD6aU5gnFzIByQuqdgFpe/bJaaEIS4geGjbjWbd1XJh6zG1EthLfpNaXEqUw==
168248
dependencies:
169249
oniguruma "^7.0.0"
170250

251+
wrappy@1:
252+
version "1.0.2"
253+
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
254+
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
255+
171256
yallist@^2.1.2:
172257
version "2.1.2"
173258
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"

0 commit comments

Comments
 (0)