@@ -31,7 +31,6 @@ const metadataCache = new LRU({
31
31
32
32
const isTestOrDebug = process . env . VUE_CLI_TEST || process . env . VUE_CLI_DEBUG
33
33
34
- const TAOBAO_DIST_URL = 'https://npm.taobao.org/dist'
35
34
const SUPPORTED_PACKAGE_MANAGERS = [ 'yarn' , 'pnpm' , 'npm' ]
36
35
const PACKAGE_MANAGER_PNPM4_CONFIG = {
37
36
install : [ 'install' , '--reporter' , 'silent' , '--shamefully-hoist' ] ,
@@ -114,8 +113,12 @@ class PackageManager {
114
113
} else if ( await shouldUseTaobao ( this . bin ) ) {
115
114
this . _registry = registries . taobao
116
115
} else {
117
- const { stdout } = await execa ( this . bin , [ 'config' , 'get' , 'registry' ] )
118
- this . _registry = stdout
116
+ try {
117
+ this . _registry = ( await execa ( this . bin , [ 'config' , 'get' , 'registry' ] ) ) . stdout
118
+ } catch ( e ) {
119
+ // Yarn 2 uses `npmRegistryServer` instead of `registry`
120
+ this . _registry = ( await execa ( this . bin , [ 'config' , 'get' , 'npmRegistryServer' ] ) ) . stdout
121
+ }
119
122
}
120
123
121
124
return this . _registry
@@ -125,12 +128,45 @@ class PackageManager {
125
128
const registry = await this . getRegistry ( )
126
129
args . push ( `--registry=${ registry } ` )
127
130
128
- if ( registry === registries . taobao ) {
129
- // for node-gyp
130
- process . env . NODEJS_ORG_MIRROR = TAOBAO_DIST_URL
131
+ return args
132
+ }
133
+
134
+ // set mirror urls for users in china
135
+ async setBinaryMirrors ( ) {
136
+ const registry = await this . getRegistry ( )
137
+
138
+ if ( registry !== registries . taobao ) {
139
+ return
131
140
}
132
141
133
- return args
142
+ try {
143
+ // node-sass, chromedriver, etc.
144
+ const binaryMirrorConfig = await this . getMetadata ( 'binary-mirror-config' )
145
+ const mirrors = binaryMirrorConfig . mirrors . china
146
+ for ( const key in mirrors . ENVS ) {
147
+ process . env [ key ] = mirrors . ENVS [ key ]
148
+ }
149
+
150
+ // Cypress
151
+ const cypressMirror = mirrors . cypress
152
+ const defaultPlatforms = {
153
+ darwin : 'osx64' ,
154
+ linux : 'linux64' ,
155
+ win32 : 'win64'
156
+ }
157
+ const platforms = cypressMirror . newPlatforms || defaultPlatforms
158
+ const targetPlatform = platforms [ require ( 'os' ) . platform ( ) ]
159
+ // Do not override user-defined env variable
160
+ // Because we may construct a wrong download url and an escape hatch is necessary
161
+ if ( targetPlatform && ! process . env . CYPRESS_INSTALL_BINARY ) {
162
+ // We only support cypress 3 for the current major version
163
+ const latestCypressVersion = await this . getRemoteVersion ( 'cypress' , '^3' )
164
+ process . env . CYPRESS_INSTALL_BINARY =
165
+ `${ cypressMirror . host } /${ latestCypressVersion } /${ targetPlatform } /cypress.zip`
166
+ }
167
+ } catch ( e ) {
168
+ // get binary mirror config failed
169
+ }
134
170
}
135
171
136
172
async getMetadata ( packageName , { field = '' } = { } ) {
@@ -178,11 +214,13 @@ class PackageManager {
178
214
}
179
215
180
216
async install ( ) {
217
+ await this . setBinaryMirrors ( )
181
218
const args = await this . addRegistryToArgs ( PACKAGE_MANAGER_CONFIG [ this . bin ] . install )
182
219
return executeCommand ( this . bin , args , this . context )
183
220
}
184
221
185
222
async add ( packageName , isDev = true ) {
223
+ await this . setBinaryMirrors ( )
186
224
const args = await this . addRegistryToArgs ( [
187
225
...PACKAGE_MANAGER_CONFIG [ this . bin ] . add ,
188
226
packageName ,
@@ -205,6 +243,7 @@ class PackageManager {
205
243
return
206
244
}
207
245
246
+ await this . setBinaryMirrors ( )
208
247
const args = await this . addRegistryToArgs ( [
209
248
...PACKAGE_MANAGER_CONFIG [ this . bin ] . add ,
210
249
packageName
0 commit comments