Skip to content

Commit e53c78d

Browse files
fix: entrypoint validation without js tag (#676)
* fix: entrypoint validation without js tag * fix: remove `describe.only` * style: 💄 clean up tests Co-authored-by: Joao Moreno <[email protected]>
1 parent dc68cc8 commit e53c78d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Diff for: src/package.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -922,13 +922,20 @@ class LaunchEntryPointProcessor extends BaseProcessor {
922922
constructor(manifest: Manifest) {
923923
super(manifest);
924924
if (manifest.main) {
925-
this.entryPoints.add(util.normalize(path.join('extension', manifest.main)));
925+
this.entryPoints.add(util.normalize(path.join('extension', this.appendJSExt(manifest.main))));
926926
}
927927
if (manifest.browser) {
928-
this.entryPoints.add(util.normalize(path.join('extension', manifest.browser)));
928+
this.entryPoints.add(util.normalize(path.join('extension', this.appendJSExt(manifest.browser))));
929929
}
930930
}
931931

932+
appendJSExt(filePath: string): string {
933+
if (filePath.endsWith('.js')) {
934+
return filePath;
935+
}
936+
return filePath + '.js';
937+
}
938+
932939
onFile(file: IFile): Promise<IFile> {
933940
this.entryPoints.delete(util.normalize(file.path));
934941
return Promise.resolve(file);
@@ -937,7 +944,9 @@ class LaunchEntryPointProcessor extends BaseProcessor {
937944
async onEnd(): Promise<void> {
938945
if (this.entryPoints.size > 0) {
939946
const files: string = [...this.entryPoints].join(',\n ');
940-
throw new Error(`Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':\n ${files}`);
947+
throw new Error(
948+
`Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':\n ${files}`
949+
);
941950
}
942951
}
943952
}

Diff for: src/test/package.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1796,20 +1796,27 @@ describe('toContentTypes', () => {
17961796

17971797
describe('LaunchEntryPointProcessor', () => {
17981798
it('should detect when declared entrypoint is not in package', async () => {
1799-
const manifest = createManifest({
1800-
main: 'main.js',
1801-
});
1799+
const manifest = createManifest({ main: 'main.js' });
18021800
const files = [{ path: 'extension/browser.js', contents: Buffer.from('') }];
1801+
18031802
let didErr = false;
1803+
18041804
try {
18051805
await _toVsixManifest(manifest, files);
18061806
} catch (err: any) {
18071807
const message = err.message;
18081808
didErr = message.includes('entrypoint(s) missing') && message.includes('main.js');
18091809
}
1810+
18101811
assert.ok(didErr);
18111812
});
18121813

1814+
it('should work even if .js extension is not used', async () => {
1815+
const manifest = createManifest({ main: 'out/src/extension' });
1816+
const files = [{ path: 'extension/out/src/extension.js', contents: Buffer.from('') }];
1817+
await _toVsixManifest(manifest, files);
1818+
});
1819+
18131820
it('should accept manifest if no entrypoints defined', async () => {
18141821
const manifest = createManifest({});
18151822
const files = [{ path: 'extension/something.js', contents: Buffer.from('') }];

0 commit comments

Comments
 (0)