@@ -14,7 +14,6 @@ const _gitProjects = new LRU({
14
14
max : 10 ,
15
15
maxAge : 1000
16
16
} )
17
- let _hasPnpm
18
17
19
18
// env detection
20
19
exports . hasYarn = ( ) => {
@@ -79,25 +78,51 @@ exports.hasProjectGit = (cwd) => {
79
78
return result
80
79
}
81
80
82
- exports . hasPnpm = ( ) => {
81
+ let _hasPnpm
82
+ let _hasPnpm3orLater
83
+ const _pnpmProjects = new LRU ( {
84
+ max : 10 ,
85
+ maxAge : 1000
86
+ } )
87
+
88
+ exports . hasPnpm3OrLater = ( ) => {
83
89
if ( process . env . VUE_CLI_TEST ) {
84
90
return true
85
91
}
86
- if ( _hasPnpm != null ) {
87
- return _hasPnpm
92
+ if ( _hasPnpm3orLater != null ) {
93
+ return _hasPnpm3orLater
88
94
}
89
95
try {
90
96
const pnpmVersion = execSync ( 'pnpm --version' ) . toString ( )
91
97
// there's a critical bug in pnpm 2
92
98
// https://github.com/pnpm/pnpm/issues/1678#issuecomment-469981972
93
99
// so we only support pnpm >= 3.0.0
94
- _hasPnpm = semver . gte ( pnpmVersion , '3.0.0' )
95
- return _hasPnpm
100
+ _hasPnpm = true
101
+ _hasPnpm3orLater = semver . gte ( pnpmVersion , '3.0.0' )
102
+ return _hasPnpm3orLater
96
103
} catch ( e ) {
97
- return ( _hasPnpm = false )
104
+ return ( _hasPnpm3orLater = false )
98
105
}
99
106
}
100
107
108
+ exports . hasProjectPnpm = ( cwd ) => {
109
+ if ( _pnpmProjects . has ( cwd ) ) {
110
+ return checkPnpm ( _pnpmProjects . get ( cwd ) )
111
+ }
112
+
113
+ const lockFile = path . join ( cwd , 'pnpm-lock.yaml' )
114
+ const result = fs . existsSync ( lockFile )
115
+ _pnpmProjects . set ( cwd , result )
116
+ return checkPnpm ( result )
117
+ }
118
+
119
+ function checkPnpm ( result ) {
120
+ if ( result && ! exports . hasPnpm3OrLater ( ) ) {
121
+ throw new Error ( `The project seems to require pnpm${ _hasPnpm ? ' >= 3' : '' } but it's not installed.` )
122
+ }
123
+ return result
124
+ }
125
+
101
126
// OS
102
127
exports . isWindows = process . platform === 'win32'
103
128
exports . isMacintosh = process . platform === 'darwin'
0 commit comments