Skip to content

Protocol cleanup WIP #4053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/build/build-vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ main() {
cd "$(dirname "${0}")/../.."
cd lib/vscode

yarn gulp compile-build compile-extensions-build
yarn gulp compile-build compile-web compile-extensions-build
yarn gulp optimize --gulpfile ./coder.js
if [[ $MINIFY ]]; then
yarn gulp minify --gulpfile ./coder.js
Expand Down
18 changes: 17 additions & 1 deletion ci/dev/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function main(): Promise<void> {
try {
const watcher = new Watcher()
await watcher.watch()
} catch (error) {
} catch (error: any) {
console.error(error.message)
process.exit(1)
}
Expand Down Expand Up @@ -38,6 +38,9 @@ class Watcher {
}

const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath })

const vscodeWebExtensions = cp.spawn("yarn", ["watch-web"], { cwd: this.vscodeSourcePath })

const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath })
const plugin = process.env.PLUGIN_DIR
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
Expand All @@ -48,6 +51,10 @@ class Watcher {
vscode.removeAllListeners()
vscode.kill()

Watcher.log("killing vs code web extension watcher")
vscodeWebExtensions.removeAllListeners()
vscodeWebExtensions.kill()

Watcher.log("killing tsc")
tsc.removeAllListeners()
tsc.kill()
Expand Down Expand Up @@ -75,19 +82,28 @@ class Watcher {
Watcher.log("vs code watcher terminated unexpectedly")
cleanup(code)
})

vscodeWebExtensions.on("exit", (code) => {
Watcher.log("vs code extension watcher terminated unexpectedly")
cleanup(code)
})

tsc.on("exit", (code) => {
Watcher.log("tsc terminated unexpectedly")
cleanup(code)
})

if (plugin) {
plugin.on("exit", (code) => {
Watcher.log("plugin terminated unexpectedly")
cleanup(code)
})
}

vscodeWebExtensions.stderr.on("data", (d) => process.stderr.write(d))
vscode.stderr.on("data", (d) => process.stderr.write(d))
tsc.stderr.on("data", (d) => process.stderr.write(d))

if (plugin) {
plugin.stderr.on("data", (d) => process.stderr.write(d))
}
Expand Down
22 changes: 12 additions & 10 deletions lib/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dependencies": {
"applicationinsights": "1.0.8",
"chokidar": "3.5.1",
"express": "^5.0.0-alpha.8",
"graceful-fs": "4.2.6",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.3",
Expand Down Expand Up @@ -91,23 +92,23 @@
"yazl": "^2.4.3"
},
"devDependencies": {
"7zip": "0.0.6",
"@types/proxy-from-env": "^1.0.1",
"@types/tar-stream": "^2.2.1",
"@types/applicationinsights": "0.20.0",
"@types/chokidar": "2.1.3",
"@types/cookie": "^0.3.3",
"@types/copy-webpack-plugin": "^6.0.3",
"@types/cssnano": "^4.0.0",
"@types/debug": "4.1.5",
"@types/express": "^4.17.8",
"@types/graceful-fs": "4.1.2",
"@types/gulp-postcss": "^8.0.0",
"@types/http-proxy-agent": "^2.0.1",
"@types/keytar": "^4.4.0",
"@types/minimist": "^1.2.1",
"@types/mocha": "^8.2.0",
"@types/node": "14.x",
"@types/proxy-from-env": "^1.0.1",
"@types/sinon": "^1.16.36",
"@types/tar-stream": "^2.2.1",
"@types/trusted-types": "^1.0.6",
"@types/vscode-windows-registry": "^1.0.0",
"@types/webpack": "^4.41.25",
Expand All @@ -120,6 +121,7 @@
"@types/yazl": "^2.4.2",
"@typescript-eslint/eslint-plugin": "3.2.0",
"@typescript-eslint/parser": "^3.3.0",
"7zip": "0.0.6",
"ansi-colors": "^3.2.3",
"asar": "^3.0.3",
"chromium-pickle-js": "^0.2.0",
Expand All @@ -129,14 +131,13 @@
"cssnano": "^5.0.2",
"debounce": "^1.0.0",
"deemon": "^1.4.0",
"eslint": "6.8.0",
"eslint-plugin-jsdoc": "^19.1.0",
"eslint": "6.8.0",
"event-stream": "3.3.4",
"fancy-log": "^1.3.3",
"fast-plist": "0.1.2",
"file-loader": "^4.2.0",
"glob": "^5.0.13",
"gulp": "^4.0.0",
"gulp-bom": "^3.0.0",
"gulp-buffer": "0.0.2",
"gulp-concat": "^2.6.1",
Expand All @@ -155,6 +156,7 @@
"gulp-sourcemaps": "^3.0.0",
"gulp-tsb": "4.0.6",
"gulp-vinyl-zip": "^2.1.2",
"gulp": "^4.0.0",
"husky": "^0.13.1",
"innosetup": "6.0.5",
"is": "^3.1.0",
Expand All @@ -170,9 +172,9 @@
"minimatch": "^3.0.4",
"minimist": "^1.2.5",
"mkdirp": "^1.0.4",
"mocha": "^8.2.1",
"mocha-junit-reporter": "^2.0.0",
"mocha-multi-reporters": "^1.5.1",
"mocha": "^8.2.1",
"npm-run-all": "^4.1.5",
"opn": "^6.0.0",
"optimist": "0.3.5",
Expand All @@ -184,22 +186,22 @@
"rcedit": "^1.1.0",
"request": "^2.85.0",
"sinon": "^1.17.2",
"source-map": "0.6.1",
"source-map-support": "^0.3.2",
"source-map": "0.6.1",
"style-loader": "^1.0.0",
"ts-loader": "^6.2.1",
"tsec": "0.1.4",
"typescript": "^4.4.0-dev.20210528",
"typescript-formatter": "7.1.0",
"typescript": "^4.4.0-dev.20210528",
"underscore": "^1.12.1",
"vinyl": "^2.0.0",
"vinyl-fs": "^3.0.0",
"vinyl": "^2.0.0",
"vscode-debugprotocol": "1.47.0",
"vscode-nls-dev": "^3.3.1",
"vscode-telemetry-extractor": "^1.7.0",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-stream": "^5.2.1",
"webpack": "^4.43.0",
"xml2js": "^0.4.17",
"yaserver": "^0.2.0"
},
Expand Down
14 changes: 0 additions & 14 deletions lib/vscode/resources/web/code-web.d.ts

This file was deleted.

112 changes: 25 additions & 87 deletions lib/vscode/resources/web/code-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, '__esModule', { value: true });

// @ts-check

Expand Down Expand Up @@ -42,17 +41,15 @@ const WEB_PLAYGROUND_VERSION = '0.0.10';

const args = minimist(process.argv, {
boolean: [
'launch',
'no-launch',
'help',
'verbose',
'wrap-iframe',
'enable-sync',
],
string: [
'server',
'scheme',
'host',
'remote-authority',
'port',
'local_port',
'extension',
Expand All @@ -63,13 +60,12 @@ const args = minimist(process.argv, {
if (args.help) {
console.log(
'yarn web [options]\n' +
' --launch Open VSCode web in the browser\n' +
' --no-launch Do not open VSCode web in the browser\n' +
' --wrap-iframe Wrap the Web Worker Extension Host in an iframe\n' +
' --enable-sync Enable sync by default\n' +
' --scheme Protocol (https or http)\n' +
' --host Remote host\n' +
' --port Remote/Local port\n' +
' --remote-authority Remote auth\n' +
' --local_port Local port override\n' +
' --secondary-port Secondary port\n' +
' --extension Path of an extension to include\n' +
Expand Down Expand Up @@ -225,10 +221,8 @@ const mapCallbackUriToRequestId = new Map();
/**
* @param req {http.IncomingMessage}
* @param res {http.ServerResponse}
* @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
* @param webConfigJSON undefined
*/
const requestHandler = (req, res, webConfigJSON) => {
const requestHandler = (req, res) => {
const parsedUrl = url.parse(req.url, true);
const pathname = parsedUrl.pathname;

Expand Down Expand Up @@ -259,9 +253,6 @@ const requestHandler = (req, res, webConfigJSON) => {
return handleExtension(req, res, parsedUrl);
}
if (pathname === '/') {
if (args.server) {
return handleRootFromServer(req, res, webConfigJSON);
}
// main web
return handleRoot(req, res);
} else if (pathname === '/callback') {
Expand All @@ -270,11 +261,8 @@ const requestHandler = (req, res, webConfigJSON) => {
} else if (pathname === '/fetch-callback') {
// callback fetch support
return handleFetchCallback(req, res, parsedUrl);
} else if (pathname === '/vscode-remote-resource') {
// callback fetch support
return handleRemoteResource(req, res, parsedUrl);
} else if (pathname === '/builtin') {
// builtin extensions JSON
// builtin extnesions JSON
return handleBuiltInExtensions(req, res, parsedUrl);
}

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

if (!args.server) {
const server = http.createServer(requestHandler);
server.listen(LOCAL_PORT, () => {
if (LOCAL_PORT !== PORT) {
console.log(`Operating location at http://0.0.0.0:${LOCAL_PORT}`);
}
console.log(`Web UI available at ${SCHEME}://${AUTHORITY}`);
});
server.on('error', err => {
console.error(`Error occurred in server:`);
console.error(err);
});
const server = http.createServer(requestHandler);
server.listen(LOCAL_PORT, () => {
if (LOCAL_PORT !== PORT) {
console.log(`Operating location at http://0.0.0.0:${LOCAL_PORT}`);
}
console.log(`Web UI available at ${SCHEME}://${AUTHORITY}`);
});
server.on('error', err => {
console.error(`Error occurred in server:`);
console.error(err);
});

const secondaryServer = http.createServer(requestHandler);
secondaryServer.listen(SECONDARY_PORT, () => {
console.log(`Secondary server available at ${SCHEME}://${HOST}:${SECONDARY_PORT}`);
});
secondaryServer.on('error', err => {
console.error(`Error occurred in server:`);
console.error(err);
});
}
const secondaryServer = http.createServer(requestHandler);
secondaryServer.listen(SECONDARY_PORT, () => {
console.log(`Secondary server available at ${SCHEME}://${HOST}:${SECONDARY_PORT}`);
});
secondaryServer.on('error', err => {
console.error(`Error occurred in server:`);
console.error(err);
});

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

/**
* @param {import('http').IncomingMessage} req
* @param {import('http').ServerResponse} res
* @param {import('url').UrlWithParsedQuery} parsedUrl
*/
async function handleRemoteResource(req, res, parsedUrl) {
const { path } = parsedUrl.query;

if (path) {
res.setHeader('Content-Type', getMediaMime(path));
res.end(await readFile(path));
}
}

/**
* @param {import('http').IncomingMessage} req
* @param {import('http').ServerResponse} res
Expand Down Expand Up @@ -448,7 +420,6 @@ async function handleRoot(req, res) {
? req.headers['host'].replace(':' + PORT, ':' + SECONDARY_PORT)
: `${HOST}:${SECONDARY_PORT}`
);

const webConfigJSON = {
folderUri: folderUri,
staticExtensions,
Expand Down Expand Up @@ -486,37 +457,6 @@ async function handleRoot(req, res) {
return res.end(data);
}

/**
* @param {import('http').IncomingMessage} req
* @param {import('http').ServerResponse} res
* @param webConfigJSON {import('../../src/vs/workbench/workbench.web.api').IServerWorkbenchConstructionOptions}
*/
async function handleRootFromServer(req, res, webConfigJSON) {
if (args.verbose) {
fancyLog(`${ansiColors.magenta('BuiltIn extensions')}: ${dedupedBuiltInExtensions.map(e => path.basename(e.extensionPath)).join(', ')}`);
fancyLog(`${ansiColors.magenta('Additional extensions')}: ${additionalBuiltinExtensions.map(e => path.basename(e.extensionLocation.path)).join(', ') || 'None'}`);
}

if (req.headers['x-forwarded-host']) {
// support for running in codespace => no iframe wrapping
delete webConfigJSON.webWorkerExtensionHostIframeSrc;
}
const authSessionInfo = undefined;

const data = (await readFile(WEB_MAIN)).toString()
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', () => escapeAttribute(JSON.stringify(webConfigJSON))) // use a replace function to avoid that regexp replace patterns ($&, $0, ...) are applied
.replace('{{WORKBENCH_AUTH_SESSION}}', () => authSessionInfo ? escapeAttribute(JSON.stringify(authSessionInfo)) : '')
.replace('{{WEBVIEW_ENDPOINT}}', '');

const headers = {
'Content-Type': 'text/html',
'Content-Security-Policy': 'require-trusted-types-for \'script\';'
};

res.writeHead(200, headers);
return res.end(data);
}

/**
* Handle HTTP requests for /callback
* @param {import('http').IncomingMessage} req
Expand Down Expand Up @@ -676,7 +616,7 @@ const mapExtToMediaMimes = {
function getMediaMime(forPath) {
const ext = path.extname(forPath);

return mapExtToMediaMimes[ext.toLowerCase()] || 'text/plain';
return mapExtToMediaMimes[ext.toLowerCase()];
}

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

if (args.launch !== false) {
opn(`${SCHEME}://${HOST}:${PORT}`);
}

exports.requestHandler = requestHandler;
}
Loading