From ac87500c31749df009f170cf82f54e0d4b96d811 Mon Sep 17 00:00:00 2001 From: Joe Rohde Date: Sat, 18 Dec 2021 22:56:38 -0800 Subject: [PATCH 1/7] feat: sanity check to validate entrypoints - For 'main' and 'browser' keys in package.json verify the files will be copied into the vsix. --- src/package.ts | 30 ++++++++++++++++++++++++++++++ src/test/package.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/package.ts b/src/package.ts index 58d7ce13..fdb6cd9f 100644 --- a/src/package.ts +++ b/src/package.ts @@ -916,6 +916,35 @@ class LicenseProcessor extends BaseProcessor { } } +class LaunchEntryPointProcessor extends BaseProcessor { + private entryPoints: Set = new Set(); + + constructor(manifest: Manifest) { + super(manifest); + if (manifest.main) { + this.entryPoints.add(util.normalize(path.join('extension', manifest.main))); + } + if (manifest.browser) { + this.entryPoints.add(util.normalize(path.join('extension', manifest.browser))); + } + } + + onFile(file: IFile): Promise { + const normalizedPath = util.normalize(file.path); + this.entryPoints.delete(normalizedPath); + return Promise.resolve(file); + } + + async onEnd(): Promise { + if (this.entryPoints.size > 0) { + const files: string = [...this.entryPoints].join(',\n '); + return Promise.reject( + new Error(`Extension entrypoint(s) missing: check files exists and does not match .vscodeignore:\n ${files}`) + ); + } + } +} + class IconProcessor extends BaseProcessor { private icon: string | undefined; private didFindIcon = false; @@ -1498,6 +1527,7 @@ export function createDefaultProcessors(manifest: Manifest, options: IPackageOpt new TagsProcessor(manifest), new ReadmeProcessor(manifest, options), new ChangelogProcessor(manifest, options), + new LaunchEntryPointProcessor(manifest), new LicenseProcessor(manifest), new IconProcessor(manifest), new NLSProcessor(manifest), diff --git a/src/test/package.test.ts b/src/test/package.test.ts index bf38cf92..2f5194ce 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -1794,6 +1794,30 @@ describe('toContentTypes', () => { }); }); +describe('LaunchEntryPointProcessor', () => { + it('should detect when declared entrypoint is not in package', async () => { + const manifest = createManifest({ + main: 'main.js', + }); + const files = [{ path: 'extension/browser.js', contents: Buffer.from('') }]; + let expectedError = false; + try { + await _toVsixManifest(manifest, files); + } catch (err: any) { + const error = err as Error; + expectedError = error?.message.includes('entrypoint(s) missing'); + expectedError &&= error?.message.includes('main.js'); + } + assert.ok(expectedError); + }); + + it('should accept manifest if no entrypoints defined', async () => { + const manifest = createManifest({}); + const files = [{ path: 'extension/something.js', contents: Buffer.from('') }]; + await _toVsixManifest(manifest, files); + assert.ok(true); + }); +}); describe('ManifestProcessor', () => { it('should ensure that package.json is writable', async () => { const root = fixture('uuid'); From 2e70569e07badeabd29808387a534cf27106c1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:26 +0100 Subject: [PATCH 2/7] Update src/package.ts --- src/package.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/package.ts b/src/package.ts index fdb6cd9f..4c9d6f58 100644 --- a/src/package.ts +++ b/src/package.ts @@ -938,9 +938,7 @@ class LaunchEntryPointProcessor extends BaseProcessor { async onEnd(): Promise { if (this.entryPoints.size > 0) { const files: string = [...this.entryPoints].join(',\n '); - return Promise.reject( - new Error(`Extension entrypoint(s) missing: check files exists and does not match .vscodeignore:\n ${files}`) - ); + throw new Error(`Extension entrypoint(s) missing. Make sure these files exist and aren't ignored by '.vscodeignore':\n ${files}`); } } } From 2826657d0e3c2c32cd342c18a7402a6935e0e85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:30 +0100 Subject: [PATCH 3/7] Update src/test/package.test.ts --- src/test/package.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 2f5194ce..fa39b224 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -1804,9 +1804,8 @@ describe('LaunchEntryPointProcessor', () => { try { await _toVsixManifest(manifest, files); } catch (err: any) { - const error = err as Error; - expectedError = error?.message.includes('entrypoint(s) missing'); - expectedError &&= error?.message.includes('main.js'); + const message = err.message; + didErr = message.includes('entrypoint(s) missing') && message.includes('main.js'); } assert.ok(expectedError); }); From 6d73fc64d1954b894302c6fc796ea77fb63c8203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:33 +0100 Subject: [PATCH 4/7] Update src/test/package.test.ts --- src/test/package.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/package.test.ts b/src/test/package.test.ts index fa39b224..5938aad0 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -1800,7 +1800,7 @@ describe('LaunchEntryPointProcessor', () => { main: 'main.js', }); const files = [{ path: 'extension/browser.js', contents: Buffer.from('') }]; - let expectedError = false; + let didErr = false; try { await _toVsixManifest(manifest, files); } catch (err: any) { From b9d3575b96ef57a30554cc3c9d0a2153e371d3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:37 +0100 Subject: [PATCH 5/7] Update src/test/package.test.ts --- src/test/package.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 5938aad0..96695608 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -1814,7 +1814,6 @@ describe('LaunchEntryPointProcessor', () => { const manifest = createManifest({}); const files = [{ path: 'extension/something.js', contents: Buffer.from('') }]; await _toVsixManifest(manifest, files); - assert.ok(true); }); }); describe('ManifestProcessor', () => { From 9f7f71b920260da383aa4992be8d8a9061cc74e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:41 +0100 Subject: [PATCH 6/7] Update src/package.ts --- src/package.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/package.ts b/src/package.ts index 4c9d6f58..2d96ff73 100644 --- a/src/package.ts +++ b/src/package.ts @@ -930,8 +930,7 @@ class LaunchEntryPointProcessor extends BaseProcessor { } onFile(file: IFile): Promise { - const normalizedPath = util.normalize(file.path); - this.entryPoints.delete(normalizedPath); + this.entryPoints.delete(util.normalize(file.path)); return Promise.resolve(file); } From 01203ecdbaf9a0922ea7436cfb9c9f7ad6477fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Moreno?= Date: Fri, 31 Dec 2021 12:09:45 +0100 Subject: [PATCH 7/7] Update src/test/package.test.ts --- src/test/package.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/package.test.ts b/src/test/package.test.ts index 96695608..c780af1b 100644 --- a/src/test/package.test.ts +++ b/src/test/package.test.ts @@ -1807,7 +1807,7 @@ describe('LaunchEntryPointProcessor', () => { const message = err.message; didErr = message.includes('entrypoint(s) missing') && message.includes('main.js'); } - assert.ok(expectedError); + assert.ok(didErr); }); it('should accept manifest if no entrypoints defined', async () => {