@@ -10,11 +10,13 @@ const globby = require('globby')
10
10
const { execSync } = require ( 'child_process' )
11
11
const inquirer = require ( 'inquirer' )
12
12
13
+ const argv = process . argv . slice ( 2 )
14
+
13
15
const externalVueScopedPackages = {
14
16
'@vue/test-utils' : true ,
15
17
'@vue/eslint-config' : true
16
18
}
17
- const localPackageRE = / ' ( @ v u e \/ ( c l i | e s l i n t | b a b e l ) [ \w - ] + ) ' : ' \^ ( \d + \. \d + \. \d + ) ' / g
19
+ const localPackageRE = / ' ( @ v u e \/ (?: c l i | e s l i n t | b a b e l ) [ \w - ] + ) ' : ' \^ ( [ \w - . ] + ) ' / g
18
20
19
21
const versionCache = { }
20
22
@@ -71,41 +73,44 @@ const flushWrite = () => {
71
73
; ( async ( ) => {
72
74
// 1. update all package deps
73
75
const updatedDeps = new Set ( )
74
- const packages = await globby ( [ 'packages/@vue/*/package.json' ] )
75
- await Promise . all ( packages . filter ( filePath => {
76
- return filePath . match ( / c l i - s e r v i c e | c l i - p l u g i n | b a b e l - p r e s e t | e s l i n t - c o n f i g / )
77
- } ) . concat ( 'package.json' ) . map ( async ( filePath ) => {
78
- const pkg = require ( path . resolve ( __dirname , '../' , filePath ) )
79
- if ( ! pkg . dependencies ) {
80
- return
81
- }
82
- let isUpdated = false
83
- const deps = pkg . dependencies
84
- for ( const dep in deps ) {
85
- if ( dep . match ( / ^ @ v u e / ) && ! externalVueScopedPackages [ dep ] ) {
86
- continue
76
+
77
+ if ( ! argv . includes ( '--local' ) ) {
78
+ const packages = await globby ( [ 'packages/@vue/*/package.json' ] )
79
+ await Promise . all ( packages . filter ( filePath => {
80
+ return filePath . match ( / c l i - s e r v i c e | c l i - p l u g i n | b a b e l - p r e s e t | e s l i n t - c o n f i g / )
81
+ } ) . concat ( 'package.json' ) . map ( async ( filePath ) => {
82
+ const pkg = require ( path . resolve ( __dirname , '../' , filePath ) )
83
+ if ( ! pkg . dependencies ) {
84
+ return
87
85
}
88
- let local = deps [ dep ]
89
- if ( local . charAt ( 0 ) !== '^' ) {
90
- continue
86
+ let isUpdated = false
87
+ const deps = pkg . dependencies
88
+ for ( const dep in deps ) {
89
+ if ( dep . match ( / ^ @ v u e / ) && ! externalVueScopedPackages [ dep ] ) {
90
+ continue
91
+ }
92
+ let local = deps [ dep ]
93
+ if ( local . charAt ( 0 ) !== '^' ) {
94
+ continue
95
+ }
96
+ local = local . replace ( / ^ \^ / , '' )
97
+ const remote = await getRemoteVersion ( dep )
98
+ if ( remote && checkUpdate ( dep , filePath , local , remote ) ) {
99
+ deps [ dep ] = `^${ remote } `
100
+ updatedDeps . add ( dep )
101
+ isUpdated = true
102
+ }
91
103
}
92
- local = local . replace ( / ^ \^ / , '' )
93
- const remote = await getRemoteVersion ( dep )
94
- if ( remote && checkUpdate ( dep , filePath , local , remote ) ) {
95
- deps [ dep ] = `^${ remote } `
96
- updatedDeps . add ( dep )
97
- isUpdated = true
104
+ if ( isUpdated ) {
105
+ bufferWrite ( filePath , JSON . stringify ( pkg , null , 2 ) + '\n' )
98
106
}
99
- }
100
- if ( isUpdated ) {
101
- bufferWrite ( filePath , JSON . stringify ( pkg , null , 2 ) + '\n' )
102
- }
103
- } ) )
107
+ } ) )
108
+ }
104
109
105
110
const updatedRE = new RegExp ( `'(${ Array . from ( updatedDeps ) . join ( '|' ) } )': '\\^(\\d+\\.\\d+\\.\\d+[^']*)'` )
106
111
const paths = await globby ( [ 'packages/@vue/**/*.js' ] )
107
112
paths
108
- . filter ( p => ! / \/ f i l e s \/ / . test ( p ) )
113
+ . filter ( p => ! / \/ f i l e s \/ / . test ( p ) && ! / \/ n o d e _ m o d u l e s / . test ( p ) )
109
114
. forEach ( filePath => {
110
115
let isUpdated = false
111
116
const makeReplacer = versionGetter => ( _ , pkg , curVersion ) => {
@@ -151,4 +156,7 @@ const flushWrite = () => {
151
156
if ( yes ) {
152
157
flushWrite ( )
153
158
}
154
- } ) ( )
159
+ } ) ( ) . catch ( err => {
160
+ console . log ( err )
161
+ process . exit ( 1 )
162
+ } )
0 commit comments