From 4a79466049dcba29adaee7562a70e5d6db991b5b Mon Sep 17 00:00:00 2001 From: Othmane KINANE <15254824+OKinane@users.noreply.github.com> Date: Thu, 14 Oct 2021 22:12:40 +0000 Subject: [PATCH 1/4] fix: support --cache-strategy ESLint argument --- packages/next/cli/next-lint.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/next/cli/next-lint.ts b/packages/next/cli/next-lint.ts index 9f2be2e96abb0..432d9a5a484f7 100755 --- a/packages/next/cli/next-lint.ts +++ b/packages/next/cli/next-lint.ts @@ -67,6 +67,7 @@ const nextLint: cliCommand = async (argv) => { '--cache': Boolean, // Although cache is enabled by default, this dummy flag still exists to not cause any breaking changes '--no-cache': Boolean, '--cache-location': String, + '--cache-strategy': String, '--error-on-unmatched-pattern': Boolean, '--format': String, @@ -134,6 +135,7 @@ const nextLint: cliCommand = async (argv) => { Caching: --no-cache Disable caching --cache-location path::String Path to the cache file or directory - default: .eslintcache + --cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata Miscellaneous: --error-on-unmatched-pattern Show errors when any file patterns are unmatched - default: false From f9b10191b55cd5c9a32edfc13c342fa3c18cb317 Mon Sep 17 00:00:00 2001 From: Othmane KINANE <15254824+OKinane@users.noreply.github.com> Date: Tue, 26 Oct 2021 22:14:53 +0000 Subject: [PATCH 2/4] add integration tests for --cache-strategy --- test/integration/eslint/test/index.test.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/integration/eslint/test/index.test.js b/test/integration/eslint/test/index.test.js index 715f9f4a9dd5e..9549e62b73218 100644 --- a/test/integration/eslint/test/index.test.js +++ b/test/integration/eslint/test/index.test.js @@ -507,6 +507,47 @@ describe('ESLint', () => { expect(fs.existsSync(cacheFile)).toBe(true) }) + const getEslintCacheContent = async (cacheDir) => { + const eslintCacheDir = join(cacheDir, 'eslint/') + let files = await fs.readdir(eslintCacheDir) + let cacheFiles = files.filter((f) => /\.cache/.test(f)) + expect(cacheFiles.length).toBe(1) + const cacheFile = join(eslintCacheDir, cacheFiles[0]) + return await fs.readFile(cacheFile, 'utf8') + } + + test('the default eslint caching strategy is metadata', async () => { + const cacheDir = join(dirEslintCache, '.next', 'cache') + + await fs.remove(cacheDir) + await nextLint(dirEslintCache) + + const defaultStrategyCache = await getEslintCacheContent(cacheDir) + + await fs.remove(cacheDir) + await nextLint(dirEslintCache, ['--cache-strategy', 'metadata']) + + const metadataStrategyCache = await getEslintCacheContent(cacheDir) + + expect(metadataStrategyCache).toBe(defaultStrategyCache) + }) + + test('cache with content strategy is different from the one with default strategy', async () => { + const cacheDir = join(dirEslintCache, '.next', 'cache') + + await fs.remove(cacheDir) + await nextLint(dirEslintCache) + + const defaultStrategyCache = await getEslintCacheContent(cacheDir) + + await fs.remove(cacheDir) + await nextLint(dirEslintCache, ['--cache-strategy', 'content']) + + const contentStrategyCache = await getEslintCacheContent(cacheDir) + + expect(contentStrategyCache).not.toBe(defaultStrategyCache) + }) + test('file flag can selectively lint only a single file', async () => { const { stdout, stderr } = await nextLint( dirFileLinting, From 87e5f9bd654509aadff385404671d4cac226eefe Mon Sep 17 00:00:00 2001 From: Othmane KINANE <15254824+OKinane@users.noreply.github.com> Date: Tue, 26 Oct 2021 22:15:46 +0000 Subject: [PATCH 3/4] fix: add cacheStrategy to eslintOptions --- packages/next/cli/next-lint.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/next/cli/next-lint.ts b/packages/next/cli/next-lint.ts index 432d9a5a484f7..ab91e0dbb6d4e 100755 --- a/packages/next/cli/next-lint.ts +++ b/packages/next/cli/next-lint.ts @@ -30,6 +30,7 @@ const eslintOptions = (args: arg.Spec, defaultCacheLocation: string) => ({ args['--report-unused-disable-directives'] || null, cache: !Boolean(args['--no-cache']), cacheLocation: args['--cache-location'] || defaultCacheLocation, + cacheStrategy: args['--cache-strategy'] || 'metadata', errorOnUnmatchedPattern: args['--error-on-unmatched-pattern'] ? Boolean(args['--error-on-unmatched-pattern']) : false, From 43dfdc405dddca30e533b20c5b128f9dbc3b1861 Mon Sep 17 00:00:00 2001 From: Othmane KINANE <15254824+OKinane@users.noreply.github.com> Date: Mon, 1 Nov 2021 23:44:06 +0100 Subject: [PATCH 4/4] minor adjustments in next lint help message for --cache-strategy Co-authored-by: Steven --- packages/next/cli/next-lint.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/cli/next-lint.ts b/packages/next/cli/next-lint.ts index ab91e0dbb6d4e..a225753a8174f 100755 --- a/packages/next/cli/next-lint.ts +++ b/packages/next/cli/next-lint.ts @@ -136,7 +136,7 @@ const nextLint: cliCommand = async (argv) => { Caching: --no-cache Disable caching --cache-location path::String Path to the cache file or directory - default: .eslintcache - --cache-strategy String Strategy to use for detecting changed files in the cache - either: metadata or content - default: metadata + --cache-strategy String Strategy to use for detecting changed files in the cache, either metadata or content - default: metadata Miscellaneous: --error-on-unmatched-pattern Show errors when any file patterns are unmatched - default: false