Skip to content

Commit

Permalink
fix: entrypoint validation without js tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwickdey committed Jan 2, 2022
1 parent dc68cc8 commit b3f5d8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 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
19 changes: 18 additions & 1 deletion src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ describe('toContentTypes', () => {
});
});

describe('LaunchEntryPointProcessor', () => {
describe.only('LaunchEntryPointProcessor', () => {
it('should detect when declared entrypoint is not in package', async () => {
const manifest = createManifest({
main: 'main.js',
Expand All @@ -1810,6 +1810,23 @@ describe('LaunchEntryPointProcessor', () => {
assert.ok(didErr);
});

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

let didErr = false;

try {
await _toVsixManifest(manifest, files);
didErr = true;
} catch (err: any) {
didErr = false;
}
assert.ok(didErr);
});

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 b3f5d8d

Please sign in to comment.