@@ -9,6 +9,7 @@ const semver = require('semver')
9
9
const globby = require ( 'globby' )
10
10
const { execSync } = require ( 'child_process' )
11
11
const inquirer = require ( 'inquirer' )
12
+ const readline = require ( 'readline' )
12
13
13
14
const externalVueScopedPackages = {
14
15
'@vue/test-utils' : true ,
@@ -47,16 +48,38 @@ const checkUpdate = (pkg, filePath, local, remote) => {
47
48
if ( ! isNewer ) {
48
49
return false
49
50
}
50
- const isCompat = semver . intersects ( `^${ local } ` , `^${ remote } ` )
51
- console . log (
52
- `${ chalk . cyan ( pkg ) } : ${ local } => ${ remote } ` +
53
- ( isCompat ? `` : chalk . red . bold ( `maybe breaking ` ) ) +
54
- chalk . gray ( `(${ path . relative ( process . cwd ( ) , filePath ) } )` )
55
- )
51
+ const maybeBreaking = ! semver . intersects ( `^${ local } ` , `^${ remote } ` )
52
+ console . log ( genUpdateString ( pkg , filePath , local , remote , maybeBreaking ) )
56
53
return true
57
54
}
58
55
}
59
56
57
+ const checkUpdateAsync = async ( pkg , filePath , local , remote ) => {
58
+ if ( remote !== local ) {
59
+ const isNewer = semver . gt ( remote , local )
60
+ if ( ! isNewer ) {
61
+ return false
62
+ }
63
+ const maybeBreaking = ! semver . intersects ( `^${ local } ` , `^${ remote } ` )
64
+ if ( ! maybeBreaking ) {
65
+ return true
66
+ }
67
+ const { shouldUpdate } = await inquirer . prompt ( [ {
68
+ name : 'shouldUpdate' ,
69
+ type : 'confirm' ,
70
+ message : genUpdateString ( pkg , filePath , local , remote , maybeBreaking ) + `\n` +
71
+ `Update this dependency?`
72
+ } ] )
73
+ return shouldUpdate
74
+ }
75
+ }
76
+
77
+ function genUpdateString ( pkg , filePath , local , remote , maybeBreaking ) {
78
+ return `${ chalk . cyan ( pkg ) } : ${ local } => ${ remote } ` +
79
+ ( maybeBreaking ? chalk . red . bold ( `maybe breaking ` ) : `` ) +
80
+ chalk . gray ( `(${ path . relative ( process . cwd ( ) , filePath ) } )` )
81
+ }
82
+
60
83
const writeCache = { }
61
84
const bufferWrite = ( file , content ) => {
62
85
writeCache [ file ] = content
@@ -74,15 +97,15 @@ async function syncDeps ({ local, version, skipPrompt }) {
74
97
if ( ! local ) {
75
98
console . log ( 'Syncing remote deps...' )
76
99
const packages = await globby ( [ 'packages/@vue/*/package.json' ] )
77
- await Promise . all ( packages . filter ( filePath => {
100
+ const resolvedPackages = ( await Promise . all ( packages . filter ( filePath => {
78
101
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 / )
79
102
} ) . concat ( 'package.json' ) . map ( async ( filePath ) => {
80
103
const pkg = require ( path . resolve ( __dirname , '../' , filePath ) )
81
104
if ( ! pkg . dependencies ) {
82
105
return
83
106
}
84
- let isUpdated = false
85
107
const deps = pkg . dependencies
108
+ const resolvedDeps = [ ]
86
109
for ( const dep in deps ) {
87
110
if ( dep . match ( / ^ @ v u e / ) && ! externalVueScopedPackages [ dep ] ) {
88
111
continue
@@ -92,17 +115,36 @@ async function syncDeps ({ local, version, skipPrompt }) {
92
115
continue
93
116
}
94
117
local = local . replace ( / ^ \^ / , '' )
118
+ readline . clearLine ( process . stdout )
119
+ readline . cursorTo ( process . stdout , 0 )
120
+ process . stdout . write ( dep )
95
121
const remote = await getRemoteVersion ( dep )
96
- if ( remote && checkUpdate ( dep , filePath , local , remote ) ) {
97
- deps [ dep ] = `^${ remote } `
122
+ resolvedDeps . push ( {
123
+ dep,
124
+ local,
125
+ remote
126
+ } )
127
+ }
128
+ return {
129
+ pkg,
130
+ filePath,
131
+ resolvedDeps
132
+ }
133
+ } ) ) ) . filter ( _ => _ )
134
+
135
+ for ( const { pkg, filePath, resolvedDeps } of resolvedPackages ) {
136
+ let isUpdated = false
137
+ for ( const { dep, local, remote } of resolvedDeps ) {
138
+ if ( remote && await checkUpdateAsync ( dep , filePath , local , remote ) ) {
139
+ pkg . dependencies [ dep ] = `^${ remote } `
98
140
updatedDeps . add ( dep )
99
141
isUpdated = true
100
142
}
101
143
}
102
144
if ( isUpdated ) {
103
145
bufferWrite ( filePath , JSON . stringify ( pkg , null , 2 ) + '\n' )
104
146
}
105
- } ) )
147
+ }
106
148
}
107
149
108
150
console . log ( 'Syncing local deps...' )
0 commit comments