Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support binary mirrors for taobao registry #4767

Merged
merged 3 commits into from
Nov 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: support binary mirrors for taobao registry
fixes issues like #4718
  • Loading branch information
haoqunjiang committed Oct 29, 2019
commit 8471070ba4a55fce7ad212bbe149611783dcffc3
50 changes: 43 additions & 7 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const metadataCache = new LRU({

const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG

const TAOBAO_DIST_URL = 'https://npm.taobao.org/dist'
const SUPPORTED_PACKAGE_MANAGERS = ['yarn', 'pnpm', 'npm']
const PACKAGE_MANAGER_PNPM4_CONFIG = {
install: ['install', '--reporter', 'silent', '--shamefully-hoist'],
Expand Down Expand Up @@ -114,8 +113,12 @@ class PackageManager {
} else if (await shouldUseTaobao(this.bin)) {
this._registry = registries.taobao
} else {
const { stdout } = await execa(this.bin, ['config', 'get', 'registry'])
this._registry = stdout
try {
this._registry = (await execa(this.bin, ['config', 'get', 'registry'])).stdout
} catch (e) {
// Yarn 2 uses `npmRegistryServer` instead of `registry`
this._registry = (await execa(this.bin, ['config', 'get', 'npmRegistryServer'])).stdout
}
}

return this._registry
Expand All @@ -125,12 +128,42 @@ class PackageManager {
const registry = await this.getRegistry()
args.push(`--registry=${registry}`)

if (registry === registries.taobao) {
// for node-gyp
process.env.NODEJS_ORG_MIRROR = TAOBAO_DIST_URL
return args
}

// set mirror urls for users in china
async setBinaryMirrors () {
const registry = await this.getRegistry()

if (registry !== registries.taobao) {
return
}

return args
try {
// node-sass, chromedriver, etc.
const binaryMirrorConfig = await this.getMetadata('binary-mirror-config')
const mirrors = binaryMirrorConfig.mirrors.china
for (const key in mirrors.ENVS) {
process.env[key] = mirrors.ENVS[key]
}

// Cypress
const cypressMirror = mirrors.cypress
const defaultPlatforms = {
darwin: 'osx64',
linux: 'linux64',
win32: 'win64'
}
const platforms = cypressMirror.newPlatforms || defaultPlatforms
const targetPlatform = platforms[require('os').platform()]
if (targetPlatform) {
const latestCypressVersion = await this.getRemoteVersion('cypress')
process.env.CYPRESS_INSTALL_BINARY =
`${cypressMirror.host}/${latestCypressVersion}/${targetPlatform}/cypress.zip`
}
} catch (e) {
// get binary mirror config failed
}
}

async getMetadata (packageName, { field = '' } = {}) {
Expand Down Expand Up @@ -178,11 +211,13 @@ class PackageManager {
}

async install () {
await this.setBinaryMirrors()
const args = await this.addRegistryToArgs(PACKAGE_MANAGER_CONFIG[this.bin].install)
return executeCommand(this.bin, args, this.context)
}

async add (packageName, isDev = true) {
await this.setBinaryMirrors()
const args = await this.addRegistryToArgs([
...PACKAGE_MANAGER_CONFIG[this.bin].add,
packageName,
Expand All @@ -205,6 +240,7 @@ class PackageManager {
return
}

await this.setBinaryMirrors()
const args = await this.addRegistryToArgs([
...PACKAGE_MANAGER_CONFIG[this.bin].add,
packageName
Expand Down