diff --git a/src/cli/cmd-deps.ts b/src/cli/cmd-deps.ts index 7af4cf7a..a8e8fe9a 100644 --- a/src/cli/cmd-deps.ts +++ b/src/cli/cmd-deps.ts @@ -97,17 +97,13 @@ openupm deps @` 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) => diff --git a/src/domain/package-reference.ts b/src/domain/package-reference.ts index cc4f6f94..4c01171a 100644 --- a/src/domain/package-reference.ts +++ b/src/domain/package-reference.ts @@ -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]; } /** diff --git a/test/unit/domain/package-reference.test.ts b/test/unit/domain/package-reference.test.ts index 0997905a..86285317 100644 --- a/test/unit/domain/package-reference.test.ts +++ b/test/unit/domain/package-reference.test.ts @@ -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", () =>