Skip to content

Commit 9f200a5

Browse files
committed
fixes #531
1 parent b910d54 commit 9f200a5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/package.ts

+16
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,22 @@ export function validateManifest(manifest: Manifest): Manifest {
880880

881881
validateEngineCompatibility(manifest.engines['vscode']);
882882

883+
const hasActivationEvents = !!manifest.activationEvents;
884+
const hasMain = !!manifest.main;
885+
const hasBrowser = !!manifest.browser;
886+
887+
if (hasActivationEvents) {
888+
if (!hasMain && !hasBrowser) {
889+
throw new Error(
890+
"Manifest needs either a 'main' or 'browser' property, given it has a 'activationEvents' property."
891+
);
892+
}
893+
} else if (hasMain) {
894+
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'main' property.");
895+
} else if (hasBrowser) {
896+
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'browser' property.");
897+
}
898+
883899
if (manifest.devDependencies && manifest.devDependencies['@types/vscode']) {
884900
validateVSCodeTypesCompatibility(manifest.engines['vscode'], manifest.devDependencies['@types/vscode']);
885901
}

src/test/package.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ describe('validateManifest', () => {
377377
);
378378
});
379379
});
380+
381+
it('should validate activationEvents against main and browser', () => {
382+
assert.throws(() => validateManifest(createManifest({ activationEvents: ['any'] })));
383+
assert.throws(() => validateManifest(createManifest({ main: 'main.js' })));
384+
assert.throws(() => validateManifest(createManifest({ browser: 'browser.js' })));
385+
assert.throws(() => validateManifest(createManifest({ main: 'main.js', browser: 'browser.js' })));
386+
validateManifest(createManifest({ activationEvents: ['any'], main: 'main.js' }));
387+
validateManifest(createManifest({ activationEvents: ['any'], browser: 'browser.js' }));
388+
validateManifest(createManifest({ activationEvents: ['any'], main: 'main.js', browser: 'browser.js' }));
389+
});
380390
});
381391

382392
describe('toVsixManifest', () => {

0 commit comments

Comments
 (0)