From f9d10df52d341c3c9be3aef4f3d4cfd4929e2eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=8C=AF=E5=AE=87?= <> Date: Fri, 7 Feb 2025 16:53:17 +0800 Subject: [PATCH] fix(lint): enhance ESLint configuration handling and improve caching for npm and yarn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙振宇 <> --- .../src/com/freeleaps/devops/DependenciesResolver.groovy | 4 ++-- .../src/com/freeleaps/devops/lint/ESLint.groovy | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy index 1eec141b..b747148d 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy @@ -65,7 +65,7 @@ class DependenciesResolver { if (cachingEnabled) { steps.dir(this.workspace) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache']]) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache', cacheValidityDecidingFile: 'package-lock.json']]) { steps.sh "npm install --cache .npm-cache" } } @@ -87,7 +87,7 @@ class DependenciesResolver { if (cachingEnabled) { steps.dir(this.workspace) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache']]) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache', cacheValidityDecidingFile: 'yarn.lock']]) { steps.sh "yarn install --cache-folder .yarn-cache" } } diff --git a/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy b/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy index b954e558..52c96047 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy @@ -23,6 +23,12 @@ class ESLint extends LinterBase { steps.dir(workspace) { steps.log.info("${linterType.linter}", "Install eslint dependencies...") steps.sh("npm install -g ${deps.join(' ')}") + // check if given config file is not end with .json + if (!configs.endsWith('.json')) { + steps.log.warn("${linterType.linter}", "Invalid eslint configuration file, must be a JSON file, convert file as valid JSON file...") + steps.sh("mv ${configs} ${configs}.json") + configs = "${configs}.json" + } steps.log.info("${linterType.linter}", "Running eslint...") steps.sh("eslint --config ${configs} ${workspace}") }