Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c (#8525)

* Merge from vscode a5cf1da01d5db3d2557132be8d30f89c38019f6c

* remove files we don't want

* fix hygiene

* update distro

* update distro

* fix hygiene

* fix strict nulls

* distro

* distro

* fix tests

* fix tests

* add another edit

* fix viewlet icon

* fix azure dialog

* fix some padding

* fix more padding issues
This commit is contained in:
Anthony Dresser
2019-12-04 19:28:22 -08:00
committed by GitHub
parent a8818ab0df
commit f5ce7fb2a5
1507 changed files with 42813 additions and 27370 deletions

View File

@@ -16,15 +16,43 @@ const opn = require('opn');
const minimist = require('vscode-minimist');
const APP_ROOT = path.dirname(__dirname);
const EXTENSIONS_ROOT = path.join(APP_ROOT, 'extensions');
const WEB_MAIN = path.join(APP_ROOT, 'src', 'vs', 'code', 'browser', 'workbench', 'workbench-dev.html');
const PORT = 8080;
const args = minimist(process.argv, {
boolean: [
'no-launch',
'help'
],
string: [
'no-launch'
]
'scheme',
'host',
'port',
'local_port'
],
});
if (args.help) {
console.log(
'yarn web [options]\n' +
' --no-launch Do not open VSCode web in the browser\n' +
' --scheme Protocol (https or http)\n' +
' --host Remote host\n' +
' --port Remote/Local port\n' +
' --local_port Local port override\n' +
' --help\n' +
'[Example]\n' +
' yarn web --scheme https --host example.com --port 8080 --local_port 30000'
);
process.exit(0);
}
const PORT = args.port || process.env.PORT || 8080;
const LOCAL_PORT = args.local_port || process.env.LOCAL_PORT || PORT;
const SCHEME = args.scheme || process.env.VSCODE_SCHEME || 'http';
const HOST = args.host || 'localhost';
const AUTHORITY = process.env.VSCODE_AUTHORITY || `${HOST}:${PORT}`;
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
const pathname = parsedUrl.pathname;
@@ -55,8 +83,11 @@ const server = http.createServer((req, res) => {
}
});
server.listen(PORT, () => {
console.log(`Web UI available at http://localhost:${PORT}`);
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 => {
@@ -87,7 +118,7 @@ function handleStaticExtension(req, res, parsedUrl) {
// Strip `/static-extension/` from the path
const relativeFilePath = path.normalize(decodeURIComponent(parsedUrl.pathname.substr('/static-extension/'.length)));
const filePath = path.join(APP_ROOT, 'extensions', relativeFilePath);
const filePath = path.join(EXTENSIONS_ROOT, relativeFilePath);
return serveFile(req, res, filePath);
}
@@ -97,12 +128,12 @@ function handleStaticExtension(req, res, parsedUrl) {
* @param {import('http').ServerResponse} res
*/
async function handleRoot(req, res) {
const extensionFolders = await util.promisify(fs.readdir)(path.join(APP_ROOT, 'extensions'));
const extensionFolders = await util.promisify(fs.readdir)(EXTENSIONS_ROOT);
const mapExtensionFolderToExtensionPackageJSON = new Map();
await Promise.all(extensionFolders.map(async extensionFolder => {
try {
const packageJSON = JSON.parse((await util.promisify(fs.readFile)(path.join(APP_ROOT, 'extensions', extensionFolder, 'package.json'))).toString());
const packageJSON = JSON.parse((await util.promisify(fs.readFile)(path.join(EXTENSIONS_ROOT, extensionFolder, 'package.json'))).toString());
if (packageJSON.main && packageJSON.name !== 'vscode-api-tests') {
return; // unsupported
}
@@ -111,7 +142,7 @@ async function handleRoot(req, res) {
return; // seems to fail to JSON.parse()?!
}
packageJSON.extensionKind = 'web'; // enable for Web
packageJSON.extensionKind = ['web']; // enable for Web
mapExtensionFolderToExtensionPackageJSON.set(extensionFolder, packageJSON);
} catch (error) {
@@ -125,14 +156,14 @@ async function handleRoot(req, res) {
mapExtensionFolderToExtensionPackageJSON.forEach((packageJSON, extensionFolder) => {
staticExtensions.push({
packageJSON,
extensionLocation: { scheme: 'http', authority: `localhost:${PORT}`, path: `/static-extension/${extensionFolder}` }
extensionLocation: { scheme: SCHEME, authority: AUTHORITY, path: `/static-extension/${extensionFolder}` }
});
});
const data = (await util.promisify(fs.readFile)(WEB_MAIN)).toString()
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', escapeAttribute(JSON.stringify({
staticExtensions,
folderUri: { scheme: 'memfs', path: `/` }
folderUri: { scheme: 'memfs', path: `/sample-folder` }
})))
.replace('{{WEBVIEW_ENDPOINT}}', '')
.replace('{{REMOTE_USER_DATA_URI}}', '');
@@ -196,6 +227,14 @@ function getMediaMime(forPath) {
*/
async function serveFile(req, res, filePath, responseHeaders = Object.create(null)) {
try {
// Sanity checks
filePath = path.normalize(filePath); // ensure no "." and ".."
if (filePath.indexOf(`${APP_ROOT}${path.sep}`) !== 0) {
// invalid location outside of APP_ROOT
return serveError(req, res, 400, `Bad request.`);
}
const stat = await util.promisify(fs.stat)(filePath);
// Check if file modified since
@@ -221,5 +260,5 @@ async function serveFile(req, res, filePath, responseHeaders = Object.create(nul
}
if (args.launch !== false) {
opn(`http://localhost:${PORT}`);
opn(`${SCHEME}://${HOST}:${PORT}`);
}