Skip to content

Commit

Permalink
Made url in license object optional (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-zon-brainhub authored Dec 3, 2024
1 parent 6fce869 commit d91e825
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/core/src/file-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,25 @@ describe("packageJsonSchema", () => {
}).success,
).toBe(true);
});
test("when license is object and url is missing", () => {
expect(
packageJsonSchema.safeParse({
name: "valid",
license: { type: "MIT" },
}).success,
).toBe(true);
});
test("when licenses are array of string", () => {
expect(
packageJsonSchema.safeParse({ name: "valid", licenses: ["MIT"] })
.success,
).toBe(true);
});
test("when licenses is a string", () => {
expect(
packageJsonSchema.safeParse({ name: "valid", licenses: "MIT" }).success,
).toBe(true);
});

test("when licenses are array of object", () => {
expect(
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ type PackageJsonResult =

const packageLicenseObjectSchema = z.object({
type: z.string(),
url: z.string(),
url: z.string().optional(),
});

const licenseFieldSchema = z.union([z.string(), packageLicenseObjectSchema]);

const licensesFieldSchema = z.union([
z.array(z.string()),
z.array(packageLicenseObjectSchema),
z.string(),
]);

export const packageJsonSchema = z.union([
Expand Down

0 comments on commit d91e825

Please sign in to comment.