add __web_extension tag for web extensions

This commit is contained in:
Sandeep Somavarapu 2020-08-28 17:56:35 +02:00
parent 789e14b31a
commit 2cd3c14d9d
2 changed files with 26 additions and 14 deletions

View file

@ -74,12 +74,14 @@ export interface IProcessor {
onFile(file: IFile): Promise<IFile>;
onEnd(): Promise<void>;
assets: IAsset[];
tags: string[];
vsix: any;
}
export class BaseProcessor implements IProcessor {
constructor(protected manifest: Manifest) { }
assets: IAsset[] = [];
tags: string[] = [];
vsix: any = Object.create(null);
onFile(file: IFile): Promise<IFile> { return Promise.resolve(file); }
onEnd() { return Promise.resolve(null); }
@ -351,10 +353,10 @@ export class TagsProcessor extends BaseProcessor {
...descriptionKeywords
];
this.vsix.tags = _(tags)
this.tags = _(tags)
.uniq() // deduplicate
.compact() // remove falsey values
.join(',');
.value();
return Promise.resolve(null);
}
@ -672,12 +674,6 @@ export class WebExtensionProcessor extends BaseProcessor {
constructor(manifest: Manifest, options: IPackageOptions) {
super(manifest);
this.isWebKind = options.web && isWebKind(manifest);
if (this.isWebKind) {
this.vsix = {
...this.vsix,
webExtension: true
}
}
}
onFile(file: IFile): Promise<IFile> {
@ -695,6 +691,13 @@ export class WebExtensionProcessor extends BaseProcessor {
if (this.assets.length > 25) {
throw new Error('Cannot pack more than 25 files in a web extension. Use `vsce ls` to see all the files that will be packed and exclude those which are not needed in .vscodeignore.');
}
if (this.isWebKind) {
this.vsix = {
...this.vsix,
webExtension: true
}
this.tags = ['__web_extension'];
}
}
}
@ -960,7 +963,11 @@ export function processFiles(processors: IProcessor[], files: IFile[]): Promise<
return Promise.all(processedFiles).then(files => {
return util.sequence(processors.map(p => () => p.onEnd())).then(() => {
const assets = _.flatten(processors.map(p => p.assets));
const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets });
const tags = _(_.flatten(processors.map(p => p.tags)))
.uniq() // deduplicate
.compact() // remove falsey values
.join(',');
const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets, tags });
return Promise.all([toVsixManifest(vsix), toContentTypes(files)]).then(result => {
return [

View file

@ -70,7 +70,8 @@ function _toVsixManifest(manifest: Manifest, files: IFile[], options: IPackageOp
const processors = createDefaultProcessors(manifest, options);
return processFiles(processors, files).then(() => {
const assets = _.flatten(processors.map(p => p.assets));
const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets });
const tags = _(_.flatten(processors.map(p => p.tags))).join(',');
const vsix = processors.reduce((r, p) => ({ ...r, ...p.vsix }), { assets, tags });
return toVsixManifest(vsix);
});
@ -2040,40 +2041,44 @@ describe('WebExtensionProcessor', () => {
assert.fail('Should fail');
});
it('should include web extension property', async () => {
it('should include web extension property & tag', async () => {
const manifest = createManifest({ extensionKind: ['web'] });
const processor = new WebExtensionProcessor(manifest, { web: true });
await processor.onEnd();
assert.equal(processor.vsix.webExtension, true);
assert.deepEqual(processor.tags, ['__web_extension']);
});
it('should include web extension property when extension kind is not provided', async () => {
it('should include web extension property & tag when extension kind is not provided', async () => {
const manifest = createManifest({ browser: 'browser.js' });
const processor = new WebExtensionProcessor(manifest, { web: true });
await processor.onEnd();
assert.equal(processor.vsix.webExtension, true);
assert.deepEqual(processor.tags, ['__web_extension']);
});
it('should not include web extension property when not asked for', async () => {
it('should not include web extension property & tag when not asked for', async () => {
const manifest = createManifest({ extensionKind: ['web'] });
const processor = new WebExtensionProcessor(manifest, { web: false });
await processor.onEnd();
assert.equal(processor.vsix.webExtension, undefined);
assert.deepEqual(processor.tags, []);
});
it('should not include web extension property for non web extension', async () => {
it('should not include web extension property & tag for non web extension', async () => {
const manifest = createManifest({ extensionKind: ['ui'] });
const processor = new WebExtensionProcessor(manifest, { web: true });
await processor.onEnd();
assert.equal(processor.vsix.webExtension, undefined);
assert.deepEqual(processor.tags, []);
});