Use Coder marketplace (#44) · patrickgwsmith/code-server@c384dfb · GitHub
Skip to content

Commit c384dfb

Browse files
code-asherkylecarbs
authored andcommitted
Use Coder marketplace (coder#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 06855ad commit c384dfb

9 files changed

Lines changed: 315 additions & 7 deletions

File tree

packages/vscode/package.json

Lines changed: 4 additions & 2 deletions

packages/vscode/src/fill/product.ts

Lines changed: 3 additions & 5 deletions
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

Lines changed: 187 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 85 additions & 0 deletions

0 commit comments

Comments
 (0)