Skip to content

Commit

Permalink
refactor: rename type
Browse files Browse the repository at this point in the history
Shorten version-name type name to just version, since it no longer conflicts with version-info
  • Loading branch information
ComradeVanti committed Oct 25, 2023
1 parent ebfa04b commit b54c937
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/cmd-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
parseName,
saveManifest,
} from "./core";
import { isUrlVersion } from "./utils/version-name";
import { isUrlVersion } from "./utils/version";

export type AddOptions = {
test: boolean;
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const _deps = async function ({
deep,
}: {
name: PkgName;
version: PkgVersionName | undefined;
version: PkgVersion | undefined;
deep: boolean;
}) {
// eslint-disable-next-line no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import assert from "assert";

type DateString = string;

type TableRow = [PkgName, PkgVersionName, DateString, ""];
type TableRow = [PkgName, PkgVersion, DateString, ""];

export type SearchOptions = {
_global: GlobalOptions;
Expand Down
10 changes: 5 additions & 5 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const parseEnv = async function (
// Parse name to {name, version}
export const parseName = function (pkg: PkgName): {
name: ReverseDomainName;
version: PkgVersionName | undefined;
version: PkgVersion | undefined;
} {
const segs = pkg.split("@");
const name = segs[0];
Expand Down Expand Up @@ -211,7 +211,7 @@ export const fetchPackageDependencies = async function ({
deep,
}: {
name: PkgName;
version: PkgVersionName | undefined;
version: PkgVersion | undefined;
deep: boolean;
}): Promise<[Dependency[], Dependency[]]> {
log.verbose("dependency", `fetch: ${name}@${version} deep=${deep}`);
Expand All @@ -225,7 +225,7 @@ export const fetchPackageDependencies = async function ({
const depsInvalid = [];
// cached dict: {pkg-name: pkgInfo}
const cachedPacakgeInfoDict: Record<
PkgVersionName,
PkgVersion,
{ pkgInfo: PkgInfo; upstream: boolean }
> = {};
while (pendingList.length > 0) {
Expand Down Expand Up @@ -304,7 +304,7 @@ export const fetchPackageDependencies = async function ({
if (depObj.self || deep) {
const deps: NameVersionPair[] = _.toPairs(
pkgInfo.versions[entry.version]["dependencies"]
).map((x: [PkgName, PkgVersionName]): NameVersionPair => {
).map((x: [PkgName, PkgVersion]): NameVersionPair => {
return { name: x[0], version: x[1] };
});
deps.forEach((x) => pendingList.push(x));
Expand All @@ -325,7 +325,7 @@ export const fetchPackageDependencies = async function ({
// Get latest version from package info
export const getLatestVersion = function (
pkgInfo: PkgInfo
): PkgVersionName | undefined {
): PkgVersion | undefined {
if (pkgInfo["dist-tags"]?.["latest"] !== undefined)
return pkgInfo["dist-tags"]["latest"];
else if (pkgInfo.version) return pkgInfo.version;
Expand Down
20 changes: 10 additions & 10 deletions lib/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NpmAuth } from "another-npm-registry-client";

declare global {
type PkgVersionName = string;
type PkgVersion = string;

type ReverseDomainName = string;

type PkgName = ReverseDomainName | `${ReverseDomainName}@${PkgVersionName}`;
type PkgName = ReverseDomainName | `${ReverseDomainName}@${PkgVersion}`;

type Region = "us" | "cn";

Expand Down Expand Up @@ -48,7 +48,7 @@ declare global {
type PkgVersionInfo = {
unity?: string;
unityRelease: string;
dependencies: Record<PkgName, PkgVersionName>;
dependencies: Record<PkgName, PkgVersion>;
license?: string;
displayName: string;
description?: string;
Expand All @@ -59,23 +59,23 @@ declare global {

type PkgInfo = {
name: PkgName;
versions: Record<PkgVersionName, PkgVersionInfo>;
"dist-tags": { latest?: PkgVersionName };
version?: PkgVersionName;
versions: Record<PkgVersion, PkgVersionInfo>;
"dist-tags": { latest?: PkgVersion };
version?: PkgVersion;
description?: string;
keywords?: string[];
time: Record<"created" | "modified" | PkgVersionName, string>;
time: Record<"created" | "modified" | PkgVersion, string>;
date?: Date;
};

type NameVersionPair = {
name: PkgName;
version: PkgVersionName | undefined;
version: PkgVersion | undefined;
};

type Dependency = {
name: PkgName;
version: PkgVersionName | undefined;
version: PkgVersion | undefined;
upstream: boolean;
self: boolean;
internal: boolean;
Expand All @@ -90,7 +90,7 @@ declare global {
};

type PkgManifest = {
dependencies: Record<PkgName, PkgVersionName>;
dependencies: Record<PkgName, PkgVersion>;
scopedRegistries: ScopedRegistry[];
testables: string[];
};
Expand Down
10 changes: 0 additions & 10 deletions lib/utils/version-name.ts

This file was deleted.

7 changes: 7 additions & 0 deletions lib/utils/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const isGit = (version: PkgVersion): boolean => version.startsWith("git");
const isHttp = (version: PkgVersion): boolean => version.startsWith("http");

const isLocal = (version: PkgVersion): boolean => version.startsWith("file");

export const isUrlVersion = (version: PkgVersion): boolean =>
isGit(version) || isHttp(version) || isLocal(version);

0 comments on commit b54c937

Please sign in to comment.