Skip to content

Commit

Permalink
feat(builder): add cacheStrategy option (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelss95 committed Jun 7, 2021
1 parent fb81948 commit 427a9f5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -62,7 +62,7 @@
"@nrwl/tao": "11.2.10",
"@nrwl/workspace": "11.2.10",
"@schematics/angular": "12.0.0",
"@types/eslint": "^7.2.0",
"@types/eslint": "^7.2.1",
"@types/eslint-scope": "^3.7.0",
"@types/jest": "^26.0.15",
"@types/node": "^10.12.2",
Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/schema.d.ts
Expand Up @@ -10,6 +10,7 @@ export interface Schema extends JsonObject {
fix: boolean;
cache: boolean;
cacheLocation: string | null;
cacheStrategy: 'content' | 'metadata' | null;
eslintConfig: string | null;
ignorePath: string | null;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/src/schema.json
Expand Up @@ -22,6 +22,12 @@
"type": "string",
"description": "Path to the cache file or directory."
},
"cacheStrategy": {
"type": "string",
"description": "Strategy to use for detecting changed files in the cache.",
"default": "metadata",
"enum": ["metadata", "content"]
},
"force": {
"type": "boolean",
"description": "Succeeds even if there was linting errors.",
Expand Down
1 change: 1 addition & 0 deletions packages/builder/src/utils/eslint-utils.ts
Expand Up @@ -26,6 +26,7 @@ export async function lint(
fix: !!options.fix,
cache: !!options.cache,
cacheLocation: options.cacheLocation || undefined,
cacheStrategy: options.cacheStrategy || undefined,
/**
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
* when no target files are found.
Expand Down
5 changes: 4 additions & 1 deletion packages/builder/tests/index.test.ts
Expand Up @@ -6,7 +6,7 @@
*/
import { Architect } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { logging, schema, json } from '@angular-devkit/core';
import { json, logging, schema } from '@angular-devkit/core';
import type { ESLint } from 'eslint';
import { resolve } from 'path';
import type { Schema } from '../src/schema';
Expand Down Expand Up @@ -60,6 +60,7 @@ function createValidRunBuilderOptions(
fix: true,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'content',
format: 'stylish',
force: false,
quiet: false,
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('Linter Builder', () => {
quiet: false,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'content',
format: 'stylish',
force: false,
silent: false,
Expand All @@ -164,6 +166,7 @@ describe('Linter Builder', () => {
quiet: false,
cache: true,
cacheLocation: 'cacheLocation1',
cacheStrategy: 'content',
format: 'stylish',
force: false,
silent: false,
Expand Down
8 changes: 6 additions & 2 deletions packages/builder/tests/utils/eslint-utils.test.ts
Expand Up @@ -17,10 +17,11 @@ describe('eslint-utils', () => {
});

it('should create the ESLint instance with the proper parameters', async () => {
await lint('/root', './.eslintrc.json', <unknown>{
await lint('/root', './.eslintrc.json', {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
// eslint-disable-next-line @typescript-eslint/no-empty-function
}).catch(() => {});

Expand All @@ -29,17 +30,19 @@ describe('eslint-utils', () => {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
});
});

it('should create the ESLint instance with the proper parameters', async () => {
await lint('/root', undefined, <unknown>{
await lint('/root', undefined, {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
// eslint-disable-next-line @typescript-eslint/no-empty-function
}).catch(() => {});

Expand All @@ -48,6 +51,7 @@ describe('eslint-utils', () => {
fix: true,
cache: true,
cacheLocation: '/root/cache',
cacheStrategy: 'content',
ignorePath: undefined,
useEslintrc: true,
errorOnUnmatchedPattern: false,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -3511,10 +3511,10 @@
"@types/eslint" "*"
"@types/estree" "*"

"@types/eslint@*", "@types/eslint@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.0.tgz#eb5c5b575237334df24c53195e37b53d66478d7b"
integrity sha512-LpUXkr7fnmPXWGxB0ZuLEzNeTURuHPavkC5zuU4sg62/TgL5ZEjamr5Y8b6AftwHtx2bPJasI+CL0TT2JwQ7aA==
"@types/eslint@*", "@types/eslint@^7.2.1":
version "7.2.13"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.13.tgz#e0ca7219ba5ded402062ad6f926d491ebb29dd53"
integrity sha512-LKmQCWAlnVHvvXq4oasNUMTJJb2GwSyTY8+1C7OH5ILR8mPLaljv1jxL1bXW3xB3jFbQxTKxJAvI8PyjB09aBg==
dependencies:
"@types/estree" "*"
"@types/json-schema" "*"
Expand Down

0 comments on commit 427a9f5

Please sign in to comment.