Skip to content

Instantly share code, notes, and snippets.

@acgrid
Created February 13, 2020 12:08
Show Gist options
  • Save acgrid/45b7e566a4b8b1b26a9074701738f404 to your computer and use it in GitHub Desktop.
Save acgrid/45b7e566a4b8b1b26a9074701738f404 to your computer and use it in GitHub Desktop.
Migrate yarnpkg to npm.taobao.org (seems yarn2 will resolve this problem)
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