Merge from vscode cfbd1999769f4f08dce29629fb92fdc0fac53829

This commit is contained in:
ADS Merger
2020-08-06 07:08:52 +00:00
parent 9c67832880
commit 540046ba00
362 changed files with 7588 additions and 6584 deletions

View File

@@ -64,56 +64,25 @@ const AUTHORITY = process.env.VSCODE_AUTHORITY || `${HOST}:${PORT}`;
const exists = (path) => util.promisify(fs.exists)(path);
const readFile = (path) => util.promisify(fs.readFile)(path);
const readdir = (path) => util.promisify(fs.readdir)(path);
const readdirWithFileTypes = (path) => util.promisify(fs.readdir)(path, { withFileTypes: true });
async function getBuiltInExtensionInfos() {
const extensions = [];
const allExtensions = [];
/** @type {Object.<string, string>} */
const locations = {};
for (const extensionsRoot of [BUILTIN_EXTENSIONS_ROOT, BUILTIN_MARKETPLACE_EXTENSIONS_ROOT]) {
if (await exists(extensionsRoot)) {
const children = await readdirWithFileTypes(extensionsRoot);
await Promise.all(children.map(async child => {
if (child.isDirectory()) {
const extensionPath = path.join(extensionsRoot, child.name);
const info = await getBuiltInExtensionInfo(extensionPath);
if (info) {
extensions.push(info);
locations[path.basename(extensionPath)] = extensionPath;
}
}
}));
}
const [localExtensions, marketplaceExtensions] = await Promise.all([
extensions.scanBuiltinExtensions(BUILTIN_EXTENSIONS_ROOT),
extensions.scanBuiltinExtensions(BUILTIN_MARKETPLACE_EXTENSIONS_ROOT),
]);
for (const ext of localExtensions) {
allExtensions.push(ext);
locations[ext.extensionPath] = path.join(BUILTIN_EXTENSIONS_ROOT, ext.extensionPath);
}
return { extensions, locations };
}
async function getBuiltInExtensionInfo(extensionPath) {
const packageJSON = await getExtensionPackageJSON(extensionPath);
if (!packageJSON) {
return undefined;
for (const ext of marketplaceExtensions) {
allExtensions.push(ext);
locations[ext.extensionPath] = path.join(BUILTIN_MARKETPLACE_EXTENSIONS_ROOT, ext.extensionPath);
}
const builtInExtensionPath = path.basename(extensionPath);
let children = [];
try {
children = await readdir(extensionPath);
} catch (error) {
console.log(`Can not read extension folder ${extensionPath}: ${error}`);
return;
}
const readme = children.find(child => /^readme(\.txt|\.md|)$/i.test(child));
const changelog = children.find(child => /^changelog(\.txt|\.md|)$/i.test(child));
const packageJSONNLS = children.find(child => /^package.nls.json$/i.test(child));
return {
extensionPath: builtInExtensionPath,
packageJSON,
packageNLSPath: packageJSONNLS ? `${builtInExtensionPath}/${packageJSONNLS}` : undefined,
readmePath: readme ? `${builtInExtensionPath}/${readme}` : undefined,
changelogPath: changelog ? `${builtInExtensionPath}/${changelog}` : undefined
};
return { extensions: allExtensions, locations };
}
async function getDefaultExtensionInfos() {
@@ -124,7 +93,7 @@ async function getDefaultExtensionInfos() {
let extensionArg = args['extension'];
if (!extensionArg) {
return { extensions, locations }
return { extensions, locations };
}
const extensionPaths = Array.isArray(extensionArg) ? extensionArg : [extensionArg];
@@ -154,8 +123,6 @@ async function getExtensionPackageJSON(extensionPath) {
}
if (packageJSON.browser) {
packageJSON.main = packageJSON.browser;
let mainFilePath = path.join(extensionPath, packageJSON.browser);
if (path.extname(mainFilePath) !== '.js') {
mainFilePath += '.js';
@@ -164,7 +131,6 @@ async function getExtensionPackageJSON(extensionPath) {
fancyLog(`${ansiColors.yellow('Warning')}: Could not find ${mainFilePath}. Use ${ansiColors.cyan('yarn gulp watch-web')} to build the built-in extensions.`);
}
}
packageJSON.extensionKind = ['web']; // enable for Web
const packageNLSPath = path.join(extensionPath, 'package.nls.json');
const packageNLSExists = await exists(packageNLSPath);
@@ -273,7 +239,9 @@ async function handleExtension(req, res, parsedUrl) {
if (!filePath) {
return serveError(req, res, 400, `Bad request.`);
}
return serveFile(req, res, filePath);
return serveFile(req, res, filePath, {
'Access-Control-Allow-Origin': '*'
});
}
/**
@@ -288,7 +256,9 @@ async function handleBuiltInExtension(req, res, parsedUrl) {
if (!filePath) {
return serveError(req, res, 400, `Bad request.`);
}
return serveFile(req, res, filePath);
return serveFile(req, res, filePath, {
'Access-Control-Allow-Origin': '*'
});
}
/**
@@ -309,7 +279,8 @@ async function handleRoot(req, res) {
}
const [owner, repo, ...branch] = gh.split('/', 3);
folderUri = { scheme: 'github', authority: branch.join('/') || 'HEAD', path: `/${owner}/${repo}` };
const ref = branch.join('/');
folderUri = { scheme: 'github', authority: `${owner}+${repo}${ref ? `+${ref}` : ''}`, path: '/' };
} else {
let cs = qs.get('cs');
if (cs) {
@@ -318,7 +289,8 @@ async function handleRoot(req, res) {
}
const [owner, repo, ...branch] = cs.split('/');
folderUri = { scheme: 'codespace', authority: branch.join('/') || 'HEAD', path: `/${owner}/${repo}` };
const ref = branch.join('/');
folderUri = { scheme: 'codespace', authority: `${owner}+${repo}${ref ? `+${ref}` : ''}`, path: '/' };
}
}
}