Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builder): add cacheStrategy option #520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Schema extends JsonObject {
fix: boolean;
cache: boolean;
cacheLocation: string | null;
cacheStrategy: 'content' | 'metadata' | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't null be undefined here? Same as cacheLocation above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the Schema extends JsonObject, which doesn't accept undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can optional property ?: be used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it has the same effect of | undefined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean add it into JsonObject.

eslintConfig: string | null;
ignorePath: string | null;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/builder/src/schema.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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