Skip to content

Commit

Permalink
refactor: undefined to null
Browse files Browse the repository at this point in the history
Replace undefined with null as return value for splitPackageReference since this is an intentionally missing value.
  • Loading branch information
ComradeVanti committed Sep 29, 2024
1 parent e4cfbdd commit 2d856be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/cli/cmd-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ openupm deps <pkg>@<version>`

const [packageName, requestedVersion] = splitPackageReference(pkg);

if (
requestedVersion !== undefined &&
isZod(requestedVersion, PackageUrl)
) {
if (requestedVersion !== null && isZod(requestedVersion, PackageUrl)) {
log.error("", "cannot get dependencies for url-version");
return process.exit(ResultCodes.Error);
}

const latestVersion =
requestedVersion !== undefined &&
isZod(requestedVersion, SemanticVersion)
requestedVersion !== null && isZod(requestedVersion, SemanticVersion)
? requestedVersion
: (
await queryAllRegistriesLazy(sources, (source) =>
Expand Down
4 changes: 2 additions & 2 deletions src/domain/package-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ export function isPackageReference(s: string): s is PackageReference {
*/
export function splitPackageReference(
reference: PackageReference
): [DomainName, VersionReference | undefined] {
): [DomainName, VersionReference | null] {
const [name, version] = trySplitAtFirstOccurrenceOf(reference, "@") as [
DomainName,
VersionReference | null
];
return [name, version ?? undefined];
return [name, version];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/domain/package-reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("package-reference", () => {
makePackageReference(name, version)
);
expect(actualName).toEqual(name);
expect(actualVersion).toEqual(version);
expect(actualVersion).toEqual(version ?? null);
}

it("should split package without version", () =>
Expand Down

0 comments on commit 2d856be

Please sign in to comment.