Skip to content

Commit

Permalink
fixes #531
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jan 29, 2021
1 parent b910d54 commit 9f200a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/package.ts
Expand Up @@ -880,6 +880,22 @@ export function validateManifest(manifest: Manifest): Manifest {

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

const hasActivationEvents = !!manifest.activationEvents;
const hasMain = !!manifest.main;
const hasBrowser = !!manifest.browser;

if (hasActivationEvents) {
if (!hasMain && !hasBrowser) {
throw new Error(
"Manifest needs either a 'main' or 'browser' property, given it has a 'activationEvents' property."
);
}
} else if (hasMain) {
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'main' property.");
} else if (hasBrowser) {
throw new Error("Manifest needs the 'activationEvents' property, given it has a 'browser' property.");
}

if (manifest.devDependencies && manifest.devDependencies['@types/vscode']) {
validateVSCodeTypesCompatibility(manifest.engines['vscode'], manifest.devDependencies['@types/vscode']);
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/package.test.ts
Expand Up @@ -377,6 +377,16 @@ describe('validateManifest', () => {
);
});
});

it('should validate activationEvents against main and browser', () => {
assert.throws(() => validateManifest(createManifest({ activationEvents: ['any'] })));
assert.throws(() => validateManifest(createManifest({ main: 'main.js' })));
assert.throws(() => validateManifest(createManifest({ browser: 'browser.js' })));
assert.throws(() => validateManifest(createManifest({ main: 'main.js', browser: 'browser.js' })));
validateManifest(createManifest({ activationEvents: ['any'], main: 'main.js' }));
validateManifest(createManifest({ activationEvents: ['any'], browser: 'browser.js' }));
validateManifest(createManifest({ activationEvents: ['any'], main: 'main.js', browser: 'browser.js' }));
});
});

describe('toVsixManifest', () => {
Expand Down

0 comments on commit 9f200a5

Please sign in to comment.