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

Commit

Permalink
feat: reset taobao registry to npmmirror
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 7, 2023
1 parent 7d07792 commit 4bf94d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { cac } from "cac";
import { execaCommandSync } from "execa";

import { version } from "./config/index.js";
import { detectPackageManager, updatePackages } from "./utils/index.js";
import {
checkRegistry,
detectPackageManager,
updatePackages,
} from "./utils/index.js";

const cli = cac("vp-update");

Expand All @@ -25,6 +29,8 @@ cli

const packageManager = detectPackageManager();

checkRegistry(packageManager);

const content = readFileSync(packageJSON, { encoding: "utf-8" });

const packageJSONContent = JSON.parse(content);
Expand Down
22 changes: 22 additions & 0 deletions src/utils/checkRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { execaCommandSync } from "execa";

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

const NPM_MIRROR_REGISTRY = "https://registry.npmmirror.com/";

const getUserRegistry = (packageManager: PackageManager): string =>
execaCommandSync(`${packageManager} config get registry`).stdout;

export const checkRegistry = (packageManager: PackageManager): void => {
const userRegistry = getUserRegistry(packageManager);

if (/https:\/\/registry\.npm\.taobao\.org\/?/.test(userRegistry)) {
console.error(
"npm.taobao.org is no longer available, resetting it to npmmirror.com"
);

execaCommandSync(
`${packageManager} config set registry ${NPM_MIRROR_REGISTRY}`
);
}
};
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./checkRegistry.js";
export * from "./packageManager.js";
export * from "./updatePackage.js";

0 comments on commit 4bf94d7

Please sign in to comment.