From dbce88b7cca8b27f5460dee1c5828b2834cbd5ab Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Jan 2020 16:00:29 +0800 Subject: [PATCH 1/3] fix: correctly calculate cacheIdentifier from lockfiles follow up of #3865 fixes #4438 --- packages/@vue/cli-service/lib/PluginAPI.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/@vue/cli-service/lib/PluginAPI.js b/packages/@vue/cli-service/lib/PluginAPI.js index adc4f700e0..4984770a43 100644 --- a/packages/@vue/cli-service/lib/PluginAPI.js +++ b/packages/@vue/cli-service/lib/PluginAPI.js @@ -175,11 +175,6 @@ class PluginAPI { if (!Array.isArray(configFiles)) { configFiles = [configFiles] } - configFiles = configFiles.concat([ - 'package-lock.json', - 'yarn.lock', - 'pnpm-lock.yaml' - ]) const readConfig = file => { const absolutePath = this.resolve(file) @@ -207,6 +202,18 @@ class PluginAPI { } } + const lockfiles = [ + 'package-lock.json', + 'yarn.lock', + 'pnpm-lock.yaml', + // technically not a lockfile, but should also be taken into account + 'package.json' + ] + variables.dependencies = lockfiles.map(f => { + const content = readConfig(f) + return content && content.replace(/\r\n?/g, '\n') + }) + const cacheIdentifier = hash(variables) return { cacheDirectory, cacheIdentifier } } From 3eb5c4018510c97aad640e6480a99ec8971c3f6e Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Jan 2020 18:04:37 +0800 Subject: [PATCH 2/3] Revert "fix: correctly calculate cacheIdentifier from lockfiles" This reverts commit dbce88b7cca8b27f5460dee1c5828b2834cbd5ab. --- packages/@vue/cli-service/lib/PluginAPI.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/@vue/cli-service/lib/PluginAPI.js b/packages/@vue/cli-service/lib/PluginAPI.js index 4984770a43..adc4f700e0 100644 --- a/packages/@vue/cli-service/lib/PluginAPI.js +++ b/packages/@vue/cli-service/lib/PluginAPI.js @@ -175,6 +175,11 @@ class PluginAPI { if (!Array.isArray(configFiles)) { configFiles = [configFiles] } + configFiles = configFiles.concat([ + 'package-lock.json', + 'yarn.lock', + 'pnpm-lock.yaml' + ]) const readConfig = file => { const absolutePath = this.resolve(file) @@ -202,18 +207,6 @@ class PluginAPI { } } - const lockfiles = [ - 'package-lock.json', - 'yarn.lock', - 'pnpm-lock.yaml', - // technically not a lockfile, but should also be taken into account - 'package.json' - ] - variables.dependencies = lockfiles.map(f => { - const content = readConfig(f) - return content && content.replace(/\r\n?/g, '\n') - }) - const cacheIdentifier = hash(variables) return { cacheDirectory, cacheIdentifier } } From be4ac6d2cc6ad9bad0dd9f0b1c8dff7da8c9b743 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 28 Jan 2020 18:05:20 +0800 Subject: [PATCH 3/3] fix: should take all configFiles and lockfiles into account The previous implementation is based on the assumption that config files have precendences, e.g. `.eslintrc.js` will take higher precendence over `.eslintrc`, and only one will take effect. This is not accurate however. For example, babel relies on both babel config and browserslist config, so we need to deal with 2 config files. --- packages/@vue/cli-service/lib/PluginAPI.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/@vue/cli-service/lib/PluginAPI.js b/packages/@vue/cli-service/lib/PluginAPI.js index adc4f700e0..fb20fc6393 100644 --- a/packages/@vue/cli-service/lib/PluginAPI.js +++ b/packages/@vue/cli-service/lib/PluginAPI.js @@ -199,13 +199,10 @@ class PluginAPI { } } - for (const file of configFiles) { + variables.configFiles = configFiles.map(file => { const content = readConfig(file) - if (content) { - variables.configFiles = content.replace(/\r\n?/g, '\n') - break - } - } + return content && content.replace(/\r\n?/g, '\n') + }) const cacheIdentifier = hash(variables) return { cacheDirectory, cacheIdentifier }