Skip to content

Commit dc68cc8

Browse files
joerohdejoaomoreno
andauthored
feat: sanity check to validate entrypoints (#669)
* feat: sanity check to validate entrypoints - For 'main' and 'browser' keys in package.json verify the files will be copied into the vsix. * Update src/package.ts * Update src/test/package.test.ts * Update src/test/package.test.ts * Update src/test/package.test.ts * Update src/package.ts * Update src/test/package.test.ts Co-authored-by: João Moreno <mail@joaomoreno.com> Co-authored-by: João Moreno <joao.moreno@microsoft.com>
1 parent f4a8264 commit dc68cc8

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/package.ts

+27
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,32 @@ class LicenseProcessor extends BaseProcessor {
916916
}
917917
}
918918

919+
class LaunchEntryPointProcessor extends BaseProcessor {
920+
private entryPoints: Set<string> = new Set<string>();
921+
922+
constructor(manifest: Manifest) {
923+
super(manifest);
924+
if (manifest.main) {
925+
this.entryPoints.add(util.normalize(path.join('extension', manifest.main)));
926+
}
927+
if (manifest.browser) {
928+
this.entryPoints.add(util.normalize(path.join('extension', manifest.browser)));
929+
}
930+
}
931+
932+
onFile(file: IFile): Promise<IFile> {
933+
this.entryPoints.delete(util.normalize(file.path));
934+
return Promise.resolve(file);
935+
}
936+
937+
async onEnd(): Promise<void> {
938+
if (this.entryPoints.size > 0) {
939+
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}`);
941+
}
942+
}
943+
}
944+
919945
class IconProcessor extends BaseProcessor {
920946
private icon: string | undefined;
921947
private didFindIcon = false;
@@ -1498,6 +1524,7 @@ export function createDefaultProcessors(manifest: Manifest, options: IPackageOpt
14981524
new TagsProcessor(manifest),
14991525
new ReadmeProcessor(manifest, options),
15001526
new ChangelogProcessor(manifest, options),
1527+
new LaunchEntryPointProcessor(manifest),
15011528
new LicenseProcessor(manifest),
15021529
new IconProcessor(manifest),
15031530
new NLSProcessor(manifest),

src/test/package.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,28 @@ describe('toContentTypes', () => {
17941794
});
17951795
});
17961796

1797+
describe('LaunchEntryPointProcessor', () => {
1798+
it('should detect when declared entrypoint is not in package', async () => {
1799+
const manifest = createManifest({
1800+
main: 'main.js',
1801+
});
1802+
const files = [{ path: 'extension/browser.js', contents: Buffer.from('') }];
1803+
let didErr = false;
1804+
try {
1805+
await _toVsixManifest(manifest, files);
1806+
} catch (err: any) {
1807+
const message = err.message;
1808+
didErr = message.includes('entrypoint(s) missing') && message.includes('main.js');
1809+
}
1810+
assert.ok(didErr);
1811+
});
1812+
1813+
it('should accept manifest if no entrypoints defined', async () => {
1814+
const manifest = createManifest({});
1815+
const files = [{ path: 'extension/something.js', contents: Buffer.from('') }];
1816+
await _toVsixManifest(manifest, files);
1817+
});
1818+
});
17971819
describe('ManifestProcessor', () => {
17981820
it('should ensure that package.json is writable', async () => {
17991821
const root = fixture('uuid');

0 commit comments

Comments
 (0)