Skip to content

Commit 75e6f97

Browse files
committed
Flesh out protocol clean up. WIP
1 parent 137eb0b commit 75e6f97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1976
-1610
lines changed

ci/build/build-vscode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ main() {
1010
cd "$(dirname "${0}")/../.."
1111
cd lib/vscode
1212

13-
yarn gulp compile-build compile-extensions-build
13+
yarn gulp compile-build compile-web compile-extensions-build
1414
yarn gulp optimize --gulpfile ./coder.js
1515
if [[ $MINIFY ]]; then
1616
yarn gulp minify --gulpfile ./coder.js

ci/dev/watch.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function main(): Promise<void> {
88
try {
99
const watcher = new Watcher()
1010
await watcher.watch()
11-
} catch (error) {
11+
} catch (error: any) {
1212
console.error(error.message)
1313
process.exit(1)
1414
}
@@ -38,6 +38,9 @@ class Watcher {
3838
}
3939

4040
const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath })
41+
42+
const vscodeWebExtensions = cp.spawn("yarn", ["watch-web"], { cwd: this.vscodeSourcePath })
43+
4144
const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath })
4245
const plugin = process.env.PLUGIN_DIR
4346
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
@@ -48,6 +51,10 @@ class Watcher {
4851
vscode.removeAllListeners()
4952
vscode.kill()
5053

54+
Watcher.log("killing vs code web extension watcher")
55+
vscodeWebExtensions.removeAllListeners()
56+
vscodeWebExtensions.kill()
57+
5158
Watcher.log("killing tsc")
5259
tsc.removeAllListeners()
5360
tsc.kill()
@@ -75,19 +82,28 @@ class Watcher {
7582
Watcher.log("vs code watcher terminated unexpectedly")
7683
cleanup(code)
7784
})
85+
86+
vscodeWebExtensions.on("exit", (code) => {
87+
Watcher.log("vs code extension watcher terminated unexpectedly")
88+
cleanup(code)
89+
})
90+
7891
tsc.on("exit", (code) => {
7992
Watcher.log("tsc terminated unexpectedly")
8093
cleanup(code)
8194
})
95+
8296
if (plugin) {
8397
plugin.on("exit", (code) => {
8498
Watcher.log("plugin terminated unexpectedly")
8599
cleanup(code)
86100
})
87101
}
88102

103+
vscodeWebExtensions.stderr.on("data", (d) => process.stderr.write(d))
89104
vscode.stderr.on("data", (d) => process.stderr.write(d))
90105
tsc.stderr.on("data", (d) => process.stderr.write(d))
106+
91107
if (plugin) {
92108
plugin.stderr.on("data", (d) => process.stderr.write(d))
93109
}

lib/vscode/package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dependencies": {
6161
"applicationinsights": "1.0.8",
6262
"chokidar": "3.5.1",
63+
"express": "^5.0.0-alpha.8",
6364
"graceful-fs": "4.2.6",
6465
"http-proxy-agent": "^2.1.0",
6566
"https-proxy-agent": "^2.2.3",
@@ -91,23 +92,23 @@
9192
"yazl": "^2.4.3"
9293
},
9394
"devDependencies": {
94-
"7zip": "0.0.6",
95-
"@types/proxy-from-env": "^1.0.1",
96-
"@types/tar-stream": "^2.2.1",
9795
"@types/applicationinsights": "0.20.0",
9896
"@types/chokidar": "2.1.3",
9997
"@types/cookie": "^0.3.3",
10098
"@types/copy-webpack-plugin": "^6.0.3",
10199
"@types/cssnano": "^4.0.0",
102100
"@types/debug": "4.1.5",
101+
"@types/express": "^4.17.8",
103102
"@types/graceful-fs": "4.1.2",
104103
"@types/gulp-postcss": "^8.0.0",
105104
"@types/http-proxy-agent": "^2.0.1",
106105
"@types/keytar": "^4.4.0",
107106
"@types/minimist": "^1.2.1",
108107
"@types/mocha": "^8.2.0",
109108
"@types/node": "14.x",
109+
"@types/proxy-from-env": "^1.0.1",
110110
"@types/sinon": "^1.16.36",
111+
"@types/tar-stream": "^2.2.1",
111112
"@types/trusted-types": "^1.0.6",
112113
"@types/vscode-windows-registry": "^1.0.0",
113114
"@types/webpack": "^4.41.25",
@@ -120,6 +121,7 @@
120121
"@types/yazl": "^2.4.2",
121122
"@typescript-eslint/eslint-plugin": "3.2.0",
122123
"@typescript-eslint/parser": "^3.3.0",
124+
"7zip": "0.0.6",
123125
"ansi-colors": "^3.2.3",
124126
"asar": "^3.0.3",
125127
"chromium-pickle-js": "^0.2.0",
@@ -129,14 +131,13 @@
129131
"cssnano": "^5.0.2",
130132
"debounce": "^1.0.0",
131133
"deemon": "^1.4.0",
132-
"eslint": "6.8.0",
133134
"eslint-plugin-jsdoc": "^19.1.0",
135+
"eslint": "6.8.0",
134136
"event-stream": "3.3.4",
135137
"fancy-log": "^1.3.3",
136138
"fast-plist": "0.1.2",
137139
"file-loader": "^4.2.0",
138140
"glob": "^5.0.13",
139-
"gulp": "^4.0.0",
140141
"gulp-bom": "^3.0.0",
141142
"gulp-buffer": "0.0.2",
142143
"gulp-concat": "^2.6.1",
@@ -155,6 +156,7 @@
155156
"gulp-sourcemaps": "^3.0.0",
156157
"gulp-tsb": "4.0.6",
157158
"gulp-vinyl-zip": "^2.1.2",
159+
"gulp": "^4.0.0",
158160
"husky": "^0.13.1",
159161
"innosetup": "6.0.5",
160162
"is": "^3.1.0",
@@ -170,9 +172,9 @@
170172
"minimatch": "^3.0.4",
171173
"minimist": "^1.2.5",
172174
"mkdirp": "^1.0.4",
173-
"mocha": "^8.2.1",
174175
"mocha-junit-reporter": "^2.0.0",
175176
"mocha-multi-reporters": "^1.5.1",
177+
"mocha": "^8.2.1",
176178
"npm-run-all": "^4.1.5",
177179
"opn": "^6.0.0",
178180
"optimist": "0.3.5",
@@ -184,22 +186,22 @@
184186
"rcedit": "^1.1.0",
185187
"request": "^2.85.0",
186188
"sinon": "^1.17.2",
187-
"source-map": "0.6.1",
188189
"source-map-support": "^0.3.2",
190+
"source-map": "0.6.1",
189191
"style-loader": "^1.0.0",
190192
"ts-loader": "^6.2.1",
191193
"tsec": "0.1.4",
192-
"typescript": "^4.4.0-dev.20210528",
193194
"typescript-formatter": "7.1.0",
195+
"typescript": "^4.4.0-dev.20210528",
194196
"underscore": "^1.12.1",
195-
"vinyl": "^2.0.0",
196197
"vinyl-fs": "^3.0.0",
198+
"vinyl": "^2.0.0",
197199
"vscode-debugprotocol": "1.47.0",
198200
"vscode-nls-dev": "^3.3.1",
199201
"vscode-telemetry-extractor": "^1.7.0",
200-
"webpack": "^4.43.0",
201202
"webpack-cli": "^3.3.12",
202203
"webpack-stream": "^5.2.1",
204+
"webpack": "^4.43.0",
203205
"xml2js": "^0.4.17",
204206
"yaserver": "^0.2.0"
205207
},

lib/vscode/resources/web/code-web.d.ts

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

lib/vscode/resources/web/code-web.js

Lines changed: 25 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the MIT License. See License.txt in the project root for license information.
66
*--------------------------------------------------------------------------------------------*/
7-
Object.defineProperty(exports, '__esModule', { value: true });
87

98
// @ts-check
109

@@ -42,17 +41,15 @@ const WEB_PLAYGROUND_VERSION = '0.0.10';
4241

4342
const args = minimist(process.argv, {
4443
boolean: [
45-
'launch',
44+
'no-launch',
4645
'help',
4746
'verbose',
4847
'wrap-iframe',
4948
'enable-sync',
5049
],
5150
string: [
52-
'server',
5351
'scheme',
5452
'host',
55-
'remote-authority',
5653
'port',
5754
'local_port',
5855
'extension',
@@ -63,13 +60,12 @@ const args = minimist(process.argv, {
6360
if (args.help) {
6461
console.log(
6562
'yarn web [options]\n' +
66-
' --launch Open VSCode web in the browser\n' +
63+
' --no-launch Do not open VSCode web in the browser\n' +
6764
' --wrap-iframe Wrap the Web Worker Extension Host in an iframe\n' +
6865
' --enable-sync Enable sync by default\n' +
6966
' --scheme Protocol (https or http)\n' +
7067
' --host Remote host\n' +
7168
' --port Remote/Local port\n' +
72-
' --remote-authority Remote auth\n' +
7369
' --local_port Local port override\n' +
7470
' --secondary-port Secondary port\n' +
7571
' --extension Path of an extension to include\n' +
@@ -225,10 +221,8 @@ const mapCallbackUriToRequestId = new Map();
225221
/**
226222
* @param req {http.IncomingMessage}
227223
* @param res {http.ServerResponse}
228-
* @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
229-
* @param webConfigJSON undefined
230224
*/
231-
const requestHandler = (req, res, webConfigJSON) => {
225+
const requestHandler = (req, res) => {
232226
const parsedUrl = url.parse(req.url, true);
233227
const pathname = parsedUrl.pathname;
234228

@@ -259,9 +253,6 @@ const requestHandler = (req, res, webConfigJSON) => {
259253
return handleExtension(req, res, parsedUrl);
260254
}
261255
if (pathname === '/') {
262-
if (args.server) {
263-
return handleRootFromServer(req, res, webConfigJSON);
264-
}
265256
// main web
266257
return handleRoot(req, res);
267258
} else if (pathname === '/callback') {
@@ -270,11 +261,8 @@ const requestHandler = (req, res, webConfigJSON) => {
270261
} else if (pathname === '/fetch-callback') {
271262
// callback fetch support
272263
return handleFetchCallback(req, res, parsedUrl);
273-
} else if (pathname === '/vscode-remote-resource') {
274-
// callback fetch support
275-
return handleRemoteResource(req, res, parsedUrl);
276264
} else if (pathname === '/builtin') {
277-
// builtin extensions JSON
265+
// builtin extnesions JSON
278266
return handleBuiltInExtensions(req, res, parsedUrl);
279267
}
280268

@@ -286,28 +274,26 @@ const requestHandler = (req, res, webConfigJSON) => {
286274
}
287275
};
288276

289-
if (!args.server) {
290-
const server = http.createServer(requestHandler);
291-
server.listen(LOCAL_PORT, () => {
292-
if (LOCAL_PORT !== PORT) {
293-
console.log(`Operating location at http://0.0.0.0:${LOCAL_PORT}`);
294-
}
295-
console.log(`Web UI available at ${SCHEME}://${AUTHORITY}`);
296-
});
297-
server.on('error', err => {
298-
console.error(`Error occurred in server:`);
299-
console.error(err);
300-
});
277+
const server = http.createServer(requestHandler);
278+
server.listen(LOCAL_PORT, () => {
279+
if (LOCAL_PORT !== PORT) {
280+
console.log(`Operating location at http://0.0.0.0:${LOCAL_PORT}`);
281+
}
282+
console.log(`Web UI available at ${SCHEME}://${AUTHORITY}`);
283+
});
284+
server.on('error', err => {
285+
console.error(`Error occurred in server:`);
286+
console.error(err);
287+
});
301288

302-
const secondaryServer = http.createServer(requestHandler);
303-
secondaryServer.listen(SECONDARY_PORT, () => {
304-
console.log(`Secondary server available at ${SCHEME}://${HOST}:${SECONDARY_PORT}`);
305-
});
306-
secondaryServer.on('error', err => {
307-
console.error(`Error occurred in server:`);
308-
console.error(err);
309-
});
310-
}
289+
const secondaryServer = http.createServer(requestHandler);
290+
secondaryServer.listen(SECONDARY_PORT, () => {
291+
console.log(`Secondary server available at ${SCHEME}://${HOST}:${SECONDARY_PORT}`);
292+
});
293+
secondaryServer.on('error', err => {
294+
console.error(`Error occurred in server:`);
295+
console.error(err);
296+
});
311297

312298
/**
313299
* @param {import('http').IncomingMessage} req
@@ -331,20 +317,6 @@ async function handleBuiltInExtensions(req, res, parsedUrl) {
331317
return res.end(JSON.stringify(extensions));
332318
}
333319

334-
/**
335-
* @param {import('http').IncomingMessage} req
336-
* @param {import('http').ServerResponse} res
337-
* @param {import('url').UrlWithParsedQuery} parsedUrl
338-
*/
339-
async function handleRemoteResource(req, res, parsedUrl) {
340-
const { path } = parsedUrl.query;
341-
342-
if (path) {
343-
res.setHeader('Content-Type', getMediaMime(path));
344-
res.end(await readFile(path));
345-
}
346-
}
347-
348320
/**
349321
* @param {import('http').IncomingMessage} req
350322
* @param {import('http').ServerResponse} res
@@ -448,7 +420,6 @@ async function handleRoot(req, res) {
448420
? req.headers['host'].replace(':' + PORT, ':' + SECONDARY_PORT)
449421
: `${HOST}:${SECONDARY_PORT}`
450422
);
451-
452423
const webConfigJSON = {
453424
folderUri: folderUri,
454425
staticExtensions,
@@ -486,37 +457,6 @@ async function handleRoot(req, res) {
486457
return res.end(data);
487458
}
488459

489-
/**
490-
* @param {import('http').IncomingMessage} req
491-
* @param {import('http').ServerResponse} res
492-
* @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
493-
*/
494-
async function handleRootFromServer(req, res, webConfigJSON) {
495-
if (args.verbose) {
496-
fancyLog(`${ansiColors.magenta('BuiltIn extensions')}: ${dedupedBuiltInExtensions.map(e => path.basename(e.extensionPath)).join(', ')}`);
497-
fancyLog(`${ansiColors.magenta('Additional extensions')}: ${additionalBuiltinExtensions.map(e => path.basename(e.extensionLocation.path)).join(', ') || 'None'}`);
498-
}
499-
500-
if (req.headers['x-forwarded-host']) {
501-
// support for running in codespace => no iframe wrapping
502-
delete webConfigJSON.webWorkerExtensionHostIframeSrc;
503-
}
504-
const authSessionInfo = undefined;
505-
506-
const data = (await readFile(WEB_MAIN)).toString()
507-
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', () => escapeAttribute(JSON.stringify(webConfigJSON))) // use a replace function to avoid that regexp replace patterns ($&, $0, ...) are applied
508-
.replace('{{WORKBENCH_AUTH_SESSION}}', () => authSessionInfo ? escapeAttribute(JSON.stringify(authSessionInfo)) : '')
509-
.replace('{{WEBVIEW_ENDPOINT}}', '');
510-
511-
const headers = {
512-
'Content-Type': 'text/html',
513-
'Content-Security-Policy': 'require-trusted-types-for \'script\';'
514-
};
515-
516-
res.writeHead(200, headers);
517-
return res.end(data);
518-
}
519-
520460
/**
521461
* Handle HTTP requests for /callback
522462
* @param {import('http').IncomingMessage} req
@@ -676,7 +616,7 @@ const mapExtToMediaMimes = {
676616
function getMediaMime(forPath) {
677617
const ext = path.extname(forPath);
678618

679-
return mapExtToMediaMimes[ext.toLowerCase()] || 'text/plain';
619+
return mapExtToMediaMimes[ext.toLowerCase()];
680620
}
681621

682622
/**
@@ -717,6 +657,4 @@ async function serveFile(req, res, filePath, responseHeaders = Object.create(nul
717657

718658
if (args.launch !== false) {
719659
opn(`${SCHEME}://${HOST}:${PORT}`);
720-
}
721-
722-
exports.requestHandler = requestHandler;
660+
}

0 commit comments

Comments
 (0)