gallery resourceUrlTemplate
This commit is contained in:
parent
242d93851a
commit
2c9c65f49d
4 changed files with 22 additions and 4 deletions
|
@ -68,7 +68,7 @@ export interface IProductConfiguration {
|
|||
readonly extensionsGallery?: {
|
||||
readonly serviceUrl: string;
|
||||
readonly itemUrl: string;
|
||||
readonly resourceUrl?: string;
|
||||
readonly resourceUrlTemplate?: string;
|
||||
readonly controlUrl: string;
|
||||
readonly recommendationsUrl: string;
|
||||
};
|
||||
|
|
|
@ -33,6 +33,12 @@ export function format(value: string, ...args: any[]): string {
|
|||
});
|
||||
}
|
||||
|
||||
const _format2Regexp = /{([^}]+)}/g;
|
||||
|
||||
export function format2(template: string, values: Record<string, unknown>): string {
|
||||
return template.replace(_format2Regexp, (match, group) => (values[group] ?? match) as string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts HTML characters inside the string to use entities instead. Makes the string safe from
|
||||
* being used e.g. in HTMLElement.innerHTML.
|
||||
|
|
|
@ -113,6 +113,17 @@ suite('Strings', () => {
|
|||
assert.strictEqual(strings.format('Foo {0} Bar. {1}', '(foo)', '.test'), 'Foo (foo) Bar. .test');
|
||||
});
|
||||
|
||||
test('format2', () => {
|
||||
assert.strictEqual(strings.format2('Foo Bar', {}), 'Foo Bar');
|
||||
assert.strictEqual(strings.format2('Foo {oops} Bar', {}), 'Foo {oops} Bar');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar', { foo: 'bar' }), 'Foo bar Bar');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar {foo}', { foo: 'bar' }), 'Foo bar Bar bar');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar {bar}{boo}', { foo: 'bar' }), 'Foo bar Bar {bar}{boo}');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar {bar}{boo}', { foo: 'bar', bar: 'undefined' }), 'Foo bar Bar undefined{boo}');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar {bar}{boo}', { foo: 'bar', bar: '5', boo: false }), 'Foo bar Bar 5false');
|
||||
assert.strictEqual(strings.format2('Foo {foo} Bar. {bar}', { foo: '(foo)', bar: '.test' }), 'Foo (foo) Bar. .test');
|
||||
});
|
||||
|
||||
test('lcut', () => {
|
||||
assert.strictEqual(strings.lcut('foo bar', 0), '');
|
||||
assert.strictEqual(strings.lcut('foo bar', 1), 'bar');
|
||||
|
|
|
@ -27,6 +27,7 @@ import { isString, isUndefined } from 'vs/base/common/types';
|
|||
import { getErrorMessage } from 'vs/base/common/errors';
|
||||
import { ResourceMap } from 'vs/base/common/map';
|
||||
import { IProductService } from 'vs/platform/product/common/productService';
|
||||
import { format2 } from 'vs/base/common/strings';
|
||||
|
||||
interface IStoredWebExtension {
|
||||
readonly identifier: IExtensionIdentifier;
|
||||
|
@ -284,7 +285,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
|
|||
if (this.environmentService.options?.assumeGalleryExtensionsAreAddressable) {
|
||||
return true;
|
||||
}
|
||||
return galleryExtension.webExtension && (!!this.productService.extensionsGallery?.resourceUrl || !!galleryExtension.webResource);
|
||||
return galleryExtension.webExtension && (!!this.productService.extensionsGallery?.resourceUrlTemplate || !!galleryExtension.webResource);
|
||||
}
|
||||
|
||||
async addExtensionFromGallery(galleryExtension: IGalleryExtension): Promise<IExtension> {
|
||||
|
@ -331,8 +332,8 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
|
|||
}
|
||||
|
||||
private async toWebExtensionFromGallery(galleryExtension: IGalleryExtension): Promise<IWebExtension> {
|
||||
const extensionLocation = this.productService.extensionsGallery?.resourceUrl
|
||||
? joinPath(URI.parse(this.productService.extensionsGallery?.resourceUrl), galleryExtension.publisherId, galleryExtension.name, galleryExtension.version, 'extension')
|
||||
const extensionLocation = this.productService.extensionsGallery?.resourceUrlTemplate
|
||||
? URI.parse(format2(this.productService.extensionsGallery.resourceUrlTemplate, { publisher: galleryExtension.publisherId, name: galleryExtension.name, version: galleryExtension.version, path: 'extension' }))
|
||||
: joinPath(galleryExtension.assetUri, 'Microsoft.VisualStudio.Code.WebResources', 'extension');
|
||||
const packageNLSUri = joinPath(extensionLocation, 'package.nls.json');
|
||||
const context = await this.requestService.request({ type: 'GET', url: packageNLSUri.toString() }, CancellationToken.None);
|
||||
|
|
Loading…
Reference in a new issue