Skip to content

Commit

Permalink
extensions: allow built-in extensions on different qualities (#89199)
Browse files Browse the repository at this point in the history
Adds a new optional `forQualities` property to built-in extensions,
and filters that as appropriate for different builds.
  • Loading branch information
connor4312 committed Jan 24, 2020
1 parent 1d93480 commit 7ad58a9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 10 deletions.
16 changes: 16 additions & 0 deletions build/builtInExtensions.json
Expand Up @@ -43,5 +43,21 @@
},
"publisherDisplayName": "Microsoft"
}
},
{
"name": "ms-vscode.js-debug-nightly",
"version": "latest",
"forQualities": ["insider"],
"repo": "https://github.com/Microsoft/vscode-js-debug",
"metadata": {
"id": "7acbb4ce-c85a-49d4-8d95-a8054406ae97",
"publisherId": {
"publisherId": "5f5636e7-69ed-4afe-b5d6-8d231fb3d3ee",
"publisherName": "ms-vscode",
"displayName": "Microsoft",
"flags": "verified"
},
"publisherDisplayName": "Microsoft"
}
}
]
8 changes: 7 additions & 1 deletion build/builtin/browser-main.js
Expand Up @@ -10,6 +10,7 @@ const os = require('os');
const { remote } = require('electron');
const dialog = remote.dialog;

const productJsonPath = path.join(__dirname, '..', '..', 'product.json');
const builtInExtensionsPath = path.join(__dirname, '..', 'builtInExtensions.json');
const controlFilePath = path.join(os.homedir(), '.vscode-oss-dev', 'extensions', 'control.json');

Expand Down Expand Up @@ -51,6 +52,7 @@ function render(el, state) {
}

const ul = document.createElement('ul');
const { quality } = readJson(productJsonPath);
const { builtin, control } = state;

for (const ext of builtin) {
Expand All @@ -61,6 +63,10 @@ function render(el, state) {

const name = document.createElement('code');
name.textContent = ext.name;
if (quality && ext.forQualities && !ext.forQualities.includes(quality)) {
name.textContent += ` (only on ${ext.forQualities.join(', ')})`;
}

li.appendChild(name);

const form = document.createElement('form');
Expand Down Expand Up @@ -123,4 +129,4 @@ function main() {
render(el, { builtin, control });
}

window.onload = main;
window.onload = main;
6 changes: 5 additions & 1 deletion build/lib/extensions.ts
Expand Up @@ -27,6 +27,7 @@ const util = require('./util');
const root = path.dirname(path.dirname(__dirname));
const commit = util.getVersion(root);
const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${commit}`;
const product = require('../../product.json');

function fromLocal(extensionPath: string): Stream {
const webpackFilename = path.join(extensionPath, 'extension.webpack.config.js');
Expand Down Expand Up @@ -219,16 +220,19 @@ const excludedExtensions = [
'vscode-test-resolver',
'ms-vscode.node-debug',
'ms-vscode.node-debug2',
'ms.vscode.js-debug-nightly'
];

interface IBuiltInExtension {
name: string;
version: string;
repo: string;
forQualities?: ReadonlyArray<string>;
metadata: any;
}

const builtInExtensions: IBuiltInExtension[] = require('../builtInExtensions.json');
const builtInExtensions = (<IBuiltInExtension[]>require('../builtInExtensions.json'))
.filter(({ forQualities }) => !product.quality || forQualities?.includes?.(product.quality) !== false);

export function packageLocalExtensionsStream(): NodeJS.ReadWriteStream {
const localExtensionDescriptions = (<string[]>glob.sync('extensions/*/package.json'))
Expand Down
Expand Up @@ -116,4 +116,25 @@ export function getMaliciousExtensionsSet(report: IReportedExtension[]): Set<str
}

return result;
}
}

export interface IBuiltInExtension {
name: string;
version: string;
repo: string;
forQualities?: ReadonlyArray<string>;
metadata: any;
}

/**
* Parses the built-in extension JSON data and filters it down to the
* extensions built into this product quality.
*/
export function parseBuiltInExtensions(rawJson: string, productQuality: string | undefined) {
const parsed: IBuiltInExtension[] = JSON.parse(rawJson);
if (!productQuality) {
return parsed;
}

return parsed.filter(ext => ext.forQualities?.indexOf?.(productQuality) !== -1);
}
Expand Up @@ -21,7 +21,7 @@ import {
INSTALL_ERROR_MALICIOUS,
INSTALL_ERROR_INCOMPATIBLE
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { areSameExtensions, getGalleryExtensionId, groupByExtension, getMaliciousExtensionsSet, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, ExtensionIdentifierWithVersion } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { areSameExtensions, getGalleryExtensionId, groupByExtension, getMaliciousExtensionsSet, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, ExtensionIdentifierWithVersion, parseBuiltInExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { localizeManifest } from '../common/extensionNls';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { Limiter, createCancelablePromise, CancelablePromise, Queue } from 'vs/base/common/async';
Expand All @@ -45,6 +45,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { getPathFromAmdModule } from 'vs/base/common/amd';
import { getManifest } from 'vs/platform/extensionManagement/node/extensionManagementUtil';
import { IExtensionManifest, ExtensionType } from 'vs/platform/extensions/common/extensions';
import { IProductService } from 'vs/platform/product/common/productService';

const ERROR_SCANNING_SYS_EXTENSIONS = 'scanningSystem';
const ERROR_SCANNING_USER_EXTENSIONS = 'scanningUser';
Expand Down Expand Up @@ -132,6 +133,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
@ILogService private readonly logService: ILogService,
@optional(IDownloadService) private downloadService: IDownloadService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IProductService private readonly productService: IProductService,
) {
super();
this.systemExtensionsPath = environmentService.builtinExtensionsPath;
Expand Down Expand Up @@ -954,10 +956,7 @@ export class ExtensionManagementService extends Disposable implements IExtension

private getDevSystemExtensionsList(): Promise<string[]> {
return pfs.readFile(this.devSystemExtensionsFilePath, 'utf8')
.then<string[]>(raw => {
const parsed: { name: string }[] = JSON.parse(raw);
return parsed.map(({ name }) => name);
});
.then(data => parseBuiltInExtensions(data, this.productService.quality).map(ext => ext.name));
}

private toNonCancellablePromise<T>(promise: Promise<T>): Promise<T> {
Expand Down
Expand Up @@ -22,6 +22,8 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { ExtensionScanner, ExtensionScannerInput, IExtensionReference, IExtensionResolver, IRelaxedExtensionDescription } from 'vs/workbench/services/extensions/node/extensionPoints';
import { Translations, ILog } from 'vs/workbench/services/extensions/common/extensionPoints';
import { IProductService } from 'vs/platform/product/common/productService';
import { parseBuiltInExtensions } from 'vs/platform/extensionManagement/common/extensionManagementUtil';

interface IExtensionCacheData {
input: ExtensionScannerInput;
Expand Down Expand Up @@ -56,6 +58,7 @@ export class CachedExtensionScanner {
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
@IWorkbenchExtensionEnablementService private readonly _extensionEnablementService: IWorkbenchExtensionEnablementService,
@IHostService private readonly _hostService: IHostService,
@IProductService private readonly _productService: IProductService,
) {
this.scannedExtensions = new Promise<IExtensionDescription[]>((resolve, reject) => {
this._scannedExtensionsResolve = resolve;
Expand All @@ -78,7 +81,7 @@ export class CachedExtensionScanner {
public async startScanningExtensions(log: ILog): Promise<void> {
try {
const translations = await this.translationConfig;
const { system, user, development } = await CachedExtensionScanner._scanInstalledExtensions(this._hostService, this._notificationService, this._environmentService, this._extensionEnablementService, log, translations);
const { system, user, development } = await CachedExtensionScanner._scanInstalledExtensions(this._hostService, this._notificationService, this._environmentService, this._extensionEnablementService, this._productService, log, translations);

let result = new Map<string, IExtensionDescription>();
system.forEach((systemExtension) => {
Expand Down Expand Up @@ -238,6 +241,7 @@ export class CachedExtensionScanner {
notificationService: INotificationService,
environmentService: IEnvironmentService,
extensionEnablementService: IWorkbenchExtensionEnablementService,
productService: IProductService,
log: ILog,
translations: Translations
): Promise<{ system: IExtensionDescription[], user: IExtensionDescription[], development: IExtensionDescription[] }> {
Expand All @@ -261,7 +265,7 @@ export class CachedExtensionScanner {
if (devMode) {
const builtInExtensionsFilePath = path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'build', 'builtInExtensions.json'));
const builtInExtensions = pfs.readFile(builtInExtensionsFilePath, 'utf8')
.then<IBuiltInExtension[]>(raw => JSON.parse(raw));
.then(raw => parseBuiltInExtensions(raw, productService.quality));

const controlFilePath = path.join(os.homedir(), '.vscode-oss-dev', 'extensions', 'control.json');
const controlFile = pfs.readFile(controlFilePath, 'utf8')
Expand Down Expand Up @@ -321,6 +325,7 @@ interface IBuiltInExtension {
name: string;
version: string;
repo: string;
forQualities?: ReadonlyArray<string>;
}

interface IBuiltInExtensionControl {
Expand Down

2 comments on commit 7ad58a9

@bpasero
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@connor4312 make sure to compile all, I think you are missing changes from build/lib/extensions.js

@connor4312
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks, I didn't realize we committed those compiled files. Will put a fix in master.

Please sign in to comment.