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

Require lowercase package names in notNeededPackages.json #268

Merged
merged 2 commits into from
May 27, 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
2 changes: 1 addition & 1 deletion packages/definitions-parser/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DTMock {
JSON.stringify({
packages: {
angular: {
libraryName: "Angular 2",
libraryName: "angular",
asOfVersion: "1.2.3"
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/definitions-parser/src/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,17 @@ export class NotNeededPackage extends PackageBase {
}

static fromRaw(name: string, raw: NotNeededPackageRaw) {
if (name !== name.toLowerCase()) {
throw new Error(`not-needed package '${name}' must use all lower-case letters.`)
}
for (const key of Object.keys(raw)) {
if (!["libraryName", "sourceRepoURL", "asOfVersion"].includes(key)) {
throw new Error(`Unexpected key in not-needed package: ${key}`);
}
}
if (raw.libraryName !== raw.libraryName.toLowerCase()) {
throw new Error(`not-needed package '${name}' must use a libraryName that is all lower-case letters.`)
}

return new NotNeededPackage(name, raw.libraryName, raw.asOfVersion);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/definitions-parser/test/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ describe(NotNeededPackage, () => {
"This is a stub types definition. real-package provides its own type definitions, so you do not need this installed."
);
});

describe("fromRaw", () => {
it("throws on uppercase package name", () => {
expect(() => NotNeededPackage.fromRaw("noUISlider", { libraryName: "nouislider", asOfVersion: "16.0.0" }))
.toThrow("not-needed package 'noUISlider' must use all lower-case letters.")
})
it("throws on uppercase library name", () => {
expect(() => NotNeededPackage.fromRaw("nouislider", { libraryName: "noUISlider", asOfVersion: "16.0.0" }))
.toThrow("not-needed package 'nouislider' must use a libraryName that is all lower-case letters.")
})
})
});

describe(getLicenseFromPackageJson, () => {
Expand Down