Skip to content

Commit

Permalink
feat: sanity check to validate entrypoints (#669)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: João Moreno <[email protected]>
  • Loading branch information
3 people authored Dec 31, 2021
1 parent f4a8264 commit dc68cc8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,32 @@ class LicenseProcessor extends BaseProcessor {
}
}

class LaunchEntryPointProcessor extends BaseProcessor {
private entryPoints: Set<string> = new Set<string>();

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<IFile> {
this.entryPoints.delete(util.normalize(file.path));
return Promise.resolve(file);
}

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}`);
}
}
}

class IconProcessor extends BaseProcessor {
private icon: string | undefined;
private didFindIcon = false;
Expand Down Expand Up @@ -1498,6 +1524,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),
Expand Down
22 changes: 22 additions & 0 deletions src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,28 @@ 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 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 accept manifest if no entrypoints defined', async () => {
const manifest = createManifest({});
const files = [{ path: 'extension/something.js', contents: Buffer.from('') }];
await _toVsixManifest(manifest, files);
});
});
describe('ManifestProcessor', () => {
it('should ensure that package.json is writable', async () => {
const root = fixture('uuid');
Expand Down

0 comments on commit dc68cc8

Please sign in to comment.