Created
February 13, 2020 12:08
-
-
Save acgrid/45b7e566a4b8b1b26a9074701738f404 to your computer and use it in GitHub Desktop.
Migrate yarnpkg to npm.taobao.org (seems yarn2 will resolve this problem)
This file contains hidden or 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
const fs = require('fs') | |
fs.readFile('yarn.lock', { encoding: 'utf8' }, (err, data) => { | |
if (err) { | |
console.error(err) | |
process.exit(1) | |
} else { | |
fs.writeFileSync('yarn.lock', data.replace(/"https:\/\/registry\.yarnpkg\.com\/.+"/g, url => { | |
url = url.replace('registry.yarnpkg.com', 'registry.npm.taobao.org') | |
if (url.includes('/-/')) { | |
const match = url.match(/\/@[^/]+\//) | |
if (match) { | |
url = url.replace('/-/', `/download${match[0]}`) | |
} | |
} | |
console.log(url) | |
return url | |
})) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment