Skip to content

Commit 4f74b27

Browse files
authored
fix: should invalidate cache when lockfiles have updated (#3865)
closes #3635
1 parent 41f9dcf commit 4f74b27

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

packages/@vue/cli-service/lib/PluginAPI.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class PluginAPI {
131131
/**
132132
* Generate a cache identifier from a number of variables
133133
*/
134-
genCacheConfig (id, partialIdentifier, configFiles) {
134+
genCacheConfig (id, partialIdentifier, configFiles = []) {
135135
const fs = require('fs')
136136
const cacheDirectory = this.resolve(`node_modules/.cache/${id}`)
137137

@@ -155,31 +155,38 @@ class PluginAPI {
155155
]
156156
}
157157

158-
if (configFiles) {
159-
const readConfig = file => {
160-
const absolutePath = this.resolve(file)
161-
if (fs.existsSync(absolutePath)) {
162-
if (absolutePath.endsWith('.js')) {
163-
// should evaluate config scripts to reflect environment variable changes
164-
try {
165-
return JSON.stringify(require(absolutePath))
166-
} catch (e) {
167-
return fs.readFileSync(absolutePath, 'utf-8')
168-
}
169-
} else {
170-
return fs.readFileSync(absolutePath, 'utf-8')
171-
}
172-
}
173-
}
174-
if (!Array.isArray(configFiles)) {
175-
configFiles = [configFiles]
158+
if (!Array.isArray(configFiles)) {
159+
configFiles = [configFiles]
160+
}
161+
configFiles = configFiles.concat([
162+
'package-lock.json',
163+
'yarn.lock',
164+
'pnpm-lock.yaml'
165+
])
166+
167+
const readConfig = file => {
168+
const absolutePath = this.resolve(file)
169+
if (!fs.existsSync(absolutePath)) {
170+
return
176171
}
177-
for (const file of configFiles) {
178-
const content = readConfig(file)
179-
if (content) {
180-
variables.configFiles = content.replace(/\r\n?/g, '\n')
181-
break
172+
173+
if (absolutePath.endsWith('.js')) {
174+
// should evaluate config scripts to reflect environment variable changes
175+
try {
176+
return JSON.stringify(require(absolutePath))
177+
} catch (e) {
178+
return fs.readFileSync(absolutePath, 'utf-8')
182179
}
180+
} else {
181+
return fs.readFileSync(absolutePath, 'utf-8')
182+
}
183+
}
184+
185+
for (const file of configFiles) {
186+
const content = readConfig(file)
187+
if (content) {
188+
variables.configFiles = content.replace(/\r\n?/g, '\n')
189+
break
183190
}
184191
}
185192

0 commit comments

Comments
 (0)