This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddd32b5
commit 9a51d5a
Showing
6 changed files
with
72 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from "./checkRegistry.js"; | ||
export * from "./registry.js"; | ||
export * from "./packageManager.js"; | ||
export * from "./updatePackage.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { execaCommandSync } from "execa"; | ||
|
||
import { type PackageManager } from "./packageManager.js"; | ||
|
||
const NPM_MIRROR_REGISTRY = "https://registry.npmmirror.com/"; | ||
|
||
export const getRegistry = (packageManager: PackageManager): string => { | ||
if ( | ||
packageManager === "yarn" && | ||
!execaCommandSync(`${packageManager} --version`).stdout.startsWith("1") | ||
) | ||
return execaCommandSync( | ||
`${packageManager} config get npmRegistryServer` | ||
).stdout.replace(/\/?$/, "/"); | ||
|
||
return execaCommandSync( | ||
`${packageManager} config get registry` | ||
).stdout.replace(/\/?$/, "/"); | ||
}; | ||
|
||
export const checkTaobaoRegistry = (packageManager: PackageManager): void => { | ||
const userRegistry = getRegistry(packageManager); | ||
|
||
if (/https:\/\/registry\.npm\.taobao\.org\/?/.test(userRegistry)) { | ||
console.error( | ||
"npm.taobao.org is no longer available, resetting it to npmmirror.com" | ||
); | ||
|
||
if ( | ||
packageManager === "yarn" && | ||
!execaCommandSync(`${packageManager} --version`).stdout.startsWith("1") | ||
) { | ||
execaCommandSync( | ||
`${packageManager} config set npmRegistryServer ${NPM_MIRROR_REGISTRY}` | ||
); | ||
} else { | ||
execaCommandSync( | ||
`${packageManager} config set registry ${NPM_MIRROR_REGISTRY}` | ||
); | ||
} | ||
} | ||
}; |