From 6810be5cd8a9dbacdc1a8997042ad91f7e187942 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 17:10:18 +0800 Subject: [PATCH] fix(lint): improve caching logic for npm and yarn installations and ensure ESLint config is a JS file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙振宇 <> --- .../src/com/freeleaps/devops/DependenciesResolver.groovy | 8 ++++++-- .../src/com/freeleaps/devops/lint/ESLint.groovy | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy index b747148d..1c8a338c 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/DependenciesResolver.groovy @@ -65,7 +65,9 @@ class DependenciesResolver { if (cachingEnabled) { steps.dir(this.workspace) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache', cacheValidityDecidingFile: 'package-lock.json']]) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.npm-cache', cacheValidityDecidingFile: 'package-lock.json']]) + def cacheExists = steps.fileExists('.npm-cache') + if (!cacheExists) { steps.sh "npm install --cache .npm-cache" } } @@ -87,7 +89,9 @@ class DependenciesResolver { if (cachingEnabled) { steps.dir(this.workspace) { - steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache', cacheValidityDecidingFile: 'yarn.lock']]) { + steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', includes: '**/*', path: '.yarn-cache', cacheValidityDecidingFile: 'yarn.lock']]) + def cacheExists = steps.fileExists('.yarn-cache') + if (!cacheExists) { 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 5c70be49..ff4be472 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/lint/ESLint.groovy @@ -27,7 +27,7 @@ class ESLint extends LinterBase { if (!configs.endsWith('.js')) { steps.log.warn("${linterType.linter}", "Invalid eslint configuration file, must be a JS file, convert file as valid JS file...") steps.sh("mv ${configs} ${configs}.js") - configs = "${configs}.json" + configs = "${configs}.js" } steps.log.info("${linterType.linter}", "Running eslint...") steps.sh("eslint --config ${configs} ${workspace}")