Skip to content

Commit

Permalink
fix: entrypoint validation without js tag (#676)
Browse files Browse the repository at this point in the history
* fix: entrypoint validation without js tag

* fix: remove `describe.only`

* style: 💄 clean up tests

Co-authored-by: Joao Moreno <[email protected]>
  • Loading branch information
ritwickdey and joaomoreno authored Jan 3, 2022
1 parent dc68cc8 commit e53c78d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,20 @@ class LaunchEntryPointProcessor extends BaseProcessor {
constructor(manifest: Manifest) {
super(manifest);
if (manifest.main) {
this.entryPoints.add(util.normalize(path.join('extension', manifest.main)));
this.entryPoints.add(util.normalize(path.join('extension', this.appendJSExt(manifest.main))));
}
if (manifest.browser) {
this.entryPoints.add(util.normalize(path.join('extension', manifest.browser)));
this.entryPoints.add(util.normalize(path.join('extension', this.appendJSExt(manifest.browser))));
}
}

appendJSExt(filePath: string): string {
if (filePath.endsWith('.js')) {
return filePath;
}
return filePath + '.js';
}

onFile(file: IFile): Promise<IFile> {
this.entryPoints.delete(util.normalize(file.path));
return Promise.resolve(file);
Expand All @@ -937,7 +944,9 @@ class LaunchEntryPointProcessor extends BaseProcessor {
async onEnd(): Promise<void> {
if (this.entryPoints.size > 0) {
const files: string = [...this.entryPoints].join(',\n ');
throw new Error(`Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':\n ${files}`);
throw new Error(
`Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':\n ${files}`
);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1796,20 +1796,27 @@ describe('toContentTypes', () => {

describe('LaunchEntryPointProcessor', () => {
it('should detect when declared entrypoint is not in package', async () => {
const manifest = createManifest({
main: 'main.js',
});
const manifest = createManifest({ main: 'main.js' });
const files = [{ path: 'extension/browser.js', contents: Buffer.from('') }];

let didErr = false;

try {
await _toVsixManifest(manifest, files);
} catch (err: any) {
const message = err.message;
didErr = message.includes('entrypoint(s) missing') && message.includes('main.js');
}

assert.ok(didErr);
});

it('should work even if .js extension is not used', async () => {
const manifest = createManifest({ main: 'out/src/extension' });
const files = [{ path: 'extension/out/src/extension.js', contents: Buffer.from('') }];
await _toVsixManifest(manifest, files);
});

it('should accept manifest if no entrypoints defined', async () => {
const manifest = createManifest({});
const files = [{ path: 'extension/something.js', contents: Buffer.from('') }];
Expand Down

0 comments on commit e53c78d

Please sign in to comment.