Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sanity check to validate entrypoints #669

Merged
merged 8 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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