Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
fix: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 13, 2023
1 parent 2d6a154 commit eb74fb4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";

import { cac } from "cac";
import { execaCommandSync } from "execa";

Expand Down Expand Up @@ -37,10 +38,10 @@ cli

await Promise.all([
packageJSONContent.dependencies
? updatePackages(packageJSONContent.dependencies)
? updatePackages(packageManager, packageJSONContent.dependencies)
: Promise.resolve(),
packageJSONContent.devDependencies
? updatePackages(packageJSONContent.devDependencies)
? updatePackages(packageManager, packageJSONContent.devDependencies)
: Promise.resolve(),
]);

Expand Down
6 changes: 5 additions & 1 deletion src/utils/getVersion.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { get } from "node:https";

import semver from "semver";

import { getRegistry } from "./registry.js";
import { type PackageManager } from "./packageManager.js";

export const getVersion = async (
packageManager: PackageManager,
packageName: string,
tag: "latest" | "next" | "auto" = "auto",
retries = 3
): Promise<string> => {
const registry = getRegistry();
const registry = getRegistry(packageManager);
const infoUrl = `${registry}-/package/${packageName}/dist-tags`;

const getVersionInfo = (): Promise<Record<string, string>> =>
Expand Down
15 changes: 8 additions & 7 deletions src/utils/packageManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { existsSync } from "node:fs";
import { existsSync, readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";

import { execaCommandSync } from "execa";

export type PackageManager = "npm" | "yarn" | "yarn1" | "pnpm";
Expand Down Expand Up @@ -62,9 +63,9 @@ export const getTypeofLockFile = (
}

if (existsSync(resolve(cwd, YARN_LOCK))) {
const packageManager = fs
.readFileSync(resolve(cwd, YARN_LOCK), { encoding: "utf-8" })
.includes("yarn lockfile v1")
const packageManager = readFileSync(resolve(cwd, YARN_LOCK), {
encoding: "utf-8",
}).includes("yarn lockfile v1")
? "yarn1"
: "yarn";

Expand Down Expand Up @@ -92,9 +93,9 @@ export const getTypeofLockFile = (
}

if (existsSync(resolve(dir, YARN_LOCK))) {
const packageManager = fs
.readFileSync(resolve(dir, YARN_LOCK), { encoding: "utf-8" })
.includes("yarn lockfile v1")
const packageManager = readFileSync(resolve(dir, YARN_LOCK), {
encoding: "utf-8",
}).includes("yarn lockfile v1")
? "yarn1"
: "yarn";

Expand Down
5 changes: 1 addition & 4 deletions src/utils/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export const checkTaobaoRegistry = (packageManager: PackageManager): void => {
"npm.taobao.org is no longer available, resetting it to npmmirror.com"
);

if (
packageManager === "yarn" &&
!execaCommandSync(`${packageManager} --version`).stdout.startsWith("1")
) {
if (packageManager === "yarn") {
execaCommandSync(
`${packageManager} config set npmRegistryServer ${NPM_MIRROR_REGISTRY}`
);
Expand Down
26 changes: 22 additions & 4 deletions src/utils/updatePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,41 @@ import {
VUE_RELATED_PACKAGES,
} from "../config/index.js";
import { getVersion } from "./getVersion.js";
import { PackageManager } from "./packageManager.js";

export const updatePackages = async (
packageManager: PackageManager,
dependencies: Record<string, string>
): Promise<void> => {
await Promise.all(
Object.keys(dependencies).map(async (dependency) => {
if (VUE_RELATED_PACKAGES.includes(dependency)) {
dependencies[dependency] = `^${await getVersion(dependency, "latest")}`;
dependencies[dependency] = `^${await getVersion(
packageManager,
dependency,
"latest"
)}`;
} else if (OFFICIAL_PACKAGES.includes(dependency)) {
dependencies[dependency] = await getVersion(dependency, "next");
dependencies[dependency] = await getVersion(
packageManager,
dependency,
"next"
);
} else if (OFFICIAL_PLUGINS.includes(dependency)) {
dependencies[dependency] = await getVersion(dependency, "next");
dependencies[dependency] = await getVersion(
packageManager,
dependency,
"next"
);
} else if (
THIRD_PARTY_PLUGINS.test(dependency) ||
THIRD_PARTY_THEMES.test(dependency)
) {
dependencies[dependency] = await getVersion(dependency, "auto");
dependencies[dependency] = await getVersion(
packageManager,
dependency,
"auto"
);
}
})
);
Expand Down

0 comments on commit eb74fb4

Please sign in to comment.