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

chore(pkglint): rule to ensure that only allowed packages are public #11317

Merged
merged 1 commit into from
Nov 11, 2020
Merged
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
45 changes: 32 additions & 13 deletions tools/pkglint/lib/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,24 +1460,43 @@ export class JestSetup extends ValidationRule {

export class UbergenPackageVisibility extends ValidationRule {
public readonly name = 'ubergen/package-visibility';
private readonly publicPackages = ['aws-cdk-lib', 'cdk', 'aws-cdk', 'awslint'];

public validate(pkg: PackageJson): void {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const releaseJson = require(`${__dirname}/../../../release.json`);
if (releaseJson.majorVersion === 2) {
// skip in v2 for now
return;
}
if (pkg.json.private && !pkg.json.ubergen?.exclude) {
pkg.report({
ruleName: this.name,
message: 'ubergen.exclude must be configured for private packages',
fix: () => {
pkg.json.ubergen = {
exclude: true,
};
},
});
// Only packages in the publicPackages list should be "public". Everything else should be private.
if (this.publicPackages.includes(pkg.json.name) && pkg.json.private === true) {
pkg.report({
ruleName: this.name,
message: 'Package must be public',
fix: () => {
delete pkg.json.private;
},
});
} else if (!this.publicPackages.includes(pkg.json.name) && pkg.json.private !== true) {
pkg.report({
ruleName: this.name,
message: 'Package must not be public',
fix: () => {
delete pkg.json.private;
pkg.json.private = true;
},
});
}
} else {
if (pkg.json.private && !pkg.json.ubergen?.exclude) {
pkg.report({
ruleName: this.name,
message: 'ubergen.exclude must be configured for private packages',
fix: () => {
pkg.json.ubergen = {
exclude: true,
};
},
});
}
}
}
}
Expand Down