@angular-eslint/schematics 4.1.0-tmp.2 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.2.0](https://github.com/angular-eslint/angular-eslint/compare/v4.1.0...v4.2.0) (2021-04-28)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **schematics:** add add-eslint-to-project schematic ([#426](https://github.com/angular-eslint/angular-eslint/issues/426)) ([7ae557d](https://github.com/angular-eslint/angular-eslint/commit/7ae557d94f53833fbfbf5128d39f64c7bb1c3c5f))
|
|
11
|
+
|
|
12
|
+
# [4.1.0](https://github.com/angular-eslint/angular-eslint/compare/v4.0.0...v4.1.0) (2021-04-28)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **schematics:** support workspaces which use targets alias ([#424](https://github.com/angular-eslint/angular-eslint/issues/424)) ([da6bcf7](https://github.com/angular-eslint/angular-eslint/commit/da6bcf70027cc4b339ef2e825a931ec882d4711f))
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
- **schematics:** dynamically install tslint-to-eslint-config as needed ([#425](https://github.com/angular-eslint/angular-eslint/issues/425)) ([27ca474](https://github.com/angular-eslint/angular-eslint/commit/27ca474419defb79b552b233689a2dbf31b8ad92))
|
|
21
|
+
|
|
6
22
|
# [4.0.0](https://github.com/angular-eslint/angular-eslint/compare/v3.0.1...v4.0.0) (2021-04-18)
|
|
7
23
|
|
|
8
24
|
### Features
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function addESLintToProject(schema) {
|
|
6
|
+
return (tree) => {
|
|
7
|
+
const projectName = utils_1.determineTargetProjectName(tree, schema.project);
|
|
8
|
+
if (!projectName) {
|
|
9
|
+
throw new Error('\n' +
|
|
10
|
+
`
|
|
11
|
+
Error: You must specify a project to add ESLint to because you have multiple projects in your angular.json
|
|
12
|
+
|
|
13
|
+
E.g. npx ng g @angular-eslint/schematics:add-eslint-to-project {{YOUR_PROJECT_NAME_GOES_HERE}}
|
|
14
|
+
`.trim());
|
|
15
|
+
}
|
|
16
|
+
return schematics_1.chain([
|
|
17
|
+
// Set the lint builder and config in angular.json
|
|
18
|
+
utils_1.addESLintTargetToProject(projectName, 'lint'),
|
|
19
|
+
// Create the ESLint config file for the project
|
|
20
|
+
utils_1.createESLintConfigForProject(projectName),
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.default = addESLintToProject;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "add-eslint-to-project",
|
|
4
|
+
"title": "Add ESLint to an Angular CLI project",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"project": {
|
|
8
|
+
"description": "The name of the project to add ESLint to.",
|
|
9
|
+
"type": "string",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"required": []
|
|
17
|
+
}
|
package/dist/collection.json
CHANGED
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"factory": "./library",
|
|
29
29
|
"schema": "./library/schema.json",
|
|
30
30
|
"description": "Generate a library project for Angular."
|
|
31
|
+
},
|
|
32
|
+
"add-eslint-to-project": {
|
|
33
|
+
"factory": "./add-eslint-to-project",
|
|
34
|
+
"schema": "./add-eslint-to-project/schema.json",
|
|
35
|
+
"description": "Add ESLint to an Angular CLI project"
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -14,33 +14,18 @@ const eslintPluginConfigBaseOriginal = eslint_plugin_1.default.configs.base;
|
|
|
14
14
|
const eslintPluginConfigNgCliCompatOriginal = eslint_plugin_1.default.configs['ng-cli-compat'];
|
|
15
15
|
const eslintPluginConfigNgCliCompatFormattingAddOnOriginal = eslint_plugin_1.default.configs['ng-cli-compat--formatting-add-on'];
|
|
16
16
|
const eslintPluginTemplateConfigRecommendedOriginal = eslint_plugin_template_1.default.configs.recommended;
|
|
17
|
-
/**
|
|
18
|
-
* To make the conversion more ergonomic, if the user does not specify a project
|
|
19
|
-
* to convert and only has a single project in their angular.json we will just go
|
|
20
|
-
* ahead and convert that one.
|
|
21
|
-
*/
|
|
22
|
-
function determineProjectToConvert(tree, maybeProject) {
|
|
23
|
-
if (maybeProject) {
|
|
24
|
-
return maybeProject;
|
|
25
|
-
}
|
|
26
|
-
const workspaceJson = utils_1.readJsonInTree(tree, utils_1.getWorkspacePath(tree));
|
|
27
|
-
const projects = Object.keys(workspaceJson.projects);
|
|
28
|
-
if (projects.length === 1) {
|
|
29
|
-
return projects[0];
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
17
|
function convert(schema) {
|
|
34
18
|
return (tree) => {
|
|
35
19
|
if (tree.exists('tsconfig.base.json')) {
|
|
36
20
|
throw new Error('\nError: Angular CLI v10.1.0 and later (and no `tsconfig.base.json`) is required in order to run this schematic. Please update your workspace and try again.\n');
|
|
37
21
|
}
|
|
38
|
-
const projectName =
|
|
22
|
+
const projectName = utils_1.determineTargetProjectName(tree, schema.project);
|
|
39
23
|
if (!projectName) {
|
|
40
24
|
throw new Error('\n' +
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
`
|
|
26
|
+
Error: You must specify a project to convert because you have multiple projects in your angular.json
|
|
27
|
+
|
|
28
|
+
E.g. npx ng g @angular-eslint/schematics:convert-tslint-to-eslint {{YOUR_PROJECT_NAME_GOES_HERE}}
|
|
44
29
|
`.trim());
|
|
45
30
|
}
|
|
46
31
|
const { root: projectRoot, projectType } = utils_1.getProjectConfig(tree, projectName);
|
|
@@ -58,9 +43,16 @@ function convert(schema) {
|
|
|
58
43
|
isRootAngularProject || schema.ignoreExistingTslintConfig
|
|
59
44
|
? schematics_1.noop()
|
|
60
45
|
: removeExtendsFromProjectTSLintConfigBeforeConverting(tree, projectTSLintJsonPath),
|
|
61
|
-
isRootAngularProject
|
|
46
|
+
isRootAngularProject
|
|
62
47
|
? schematics_1.noop()
|
|
63
|
-
:
|
|
48
|
+
: schema.ignoreExistingTslintConfig
|
|
49
|
+
? schematics_1.chain([
|
|
50
|
+
// Create the latest recommended ESLint config file for the project
|
|
51
|
+
utils_1.createESLintConfigForProject(projectName),
|
|
52
|
+
// Delete the TSLint config file for the project
|
|
53
|
+
utils_1.removeTSLintJSONForProject(projectName),
|
|
54
|
+
])
|
|
55
|
+
: convertNonRootTSLintConfig(schema, projectRoot, projectType, projectTSLintJsonPath, rootESLintrcJsonPath),
|
|
64
56
|
function cleanUpTSLintIfNoLongerInUse(tree) {
|
|
65
57
|
if (schema.removeTslintIfNoMoreTslintTargets &&
|
|
66
58
|
!utils_1.isTSLintUsedInWorkspace(tree)) {
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.determineTargetProjectName = exports.sortObjectByKeys = exports.removeTSLintJSONForProject = exports.createESLintConfigForProject = exports.createRootESLintConfig = exports.setESLintProjectBasedOnProjectType = exports.visitNotIgnoredFiles = exports.addESLintTargetToProject = exports.updateWorkspaceInTree = exports.offsetFromRoot = exports.getProjectConfig = exports.isTSLintUsedInWorkspace = exports.getWorkspacePath = exports.updateJsonInTree = exports.readJsonInTree = void 0;
|
|
7
7
|
const core_1 = require("@angular-devkit/core");
|
|
8
8
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
9
9
|
const ignore_1 = __importDefault(require("ignore"));
|
|
@@ -273,11 +273,10 @@ function createESLintConfigForProject(projectName) {
|
|
|
273
273
|
const { root: projectRoot, projectType, prefix } = angularJSON.projects[projectName];
|
|
274
274
|
/**
|
|
275
275
|
* If the root is an empty string it must be the initial project created at the
|
|
276
|
-
* root by the Angular CLI's workspace schematic
|
|
277
|
-
* config in our own workspace schematic.
|
|
276
|
+
* root by the Angular CLI's workspace schematic
|
|
278
277
|
*/
|
|
279
278
|
if (projectRoot === '') {
|
|
280
|
-
return;
|
|
279
|
+
return createRootESLintConfigFile(projectName);
|
|
281
280
|
}
|
|
282
281
|
return updateJsonInTree(core_1.join(core_1.normalize(projectRoot), '.eslintrc.json'), () => createProjectESLintConfig(tree.root.path, projectRoot, projectType, prefix));
|
|
283
282
|
};
|
|
@@ -287,23 +286,25 @@ function removeTSLintJSONForProject(projectName) {
|
|
|
287
286
|
return (tree) => {
|
|
288
287
|
const angularJSON = readJsonInTree(tree, 'angular.json');
|
|
289
288
|
const { root: projectRoot } = angularJSON.projects[projectName];
|
|
290
|
-
|
|
289
|
+
const tslintJsonPath = core_1.join(core_1.normalize(projectRoot || '/'), 'tslint.json');
|
|
290
|
+
if (tree.exists(tslintJsonPath)) {
|
|
291
|
+
tree.delete(tslintJsonPath);
|
|
292
|
+
}
|
|
291
293
|
};
|
|
292
294
|
}
|
|
293
295
|
exports.removeTSLintJSONForProject = removeTSLintJSONForProject;
|
|
294
|
-
function createRootESLintConfigFile(
|
|
296
|
+
function createRootESLintConfigFile(projectName) {
|
|
295
297
|
return (tree) => {
|
|
296
298
|
var _a;
|
|
297
|
-
const angularJSON = readJsonInTree(tree,
|
|
299
|
+
const angularJSON = readJsonInTree(tree, getWorkspacePath(tree));
|
|
298
300
|
let lintPrefix = null;
|
|
299
|
-
if ((_a = angularJSON.projects) === null || _a === void 0 ? void 0 : _a[
|
|
300
|
-
const { prefix } = angularJSON.projects[
|
|
301
|
+
if ((_a = angularJSON.projects) === null || _a === void 0 ? void 0 : _a[projectName]) {
|
|
302
|
+
const { prefix } = angularJSON.projects[projectName];
|
|
301
303
|
lintPrefix = prefix;
|
|
302
304
|
}
|
|
303
|
-
return updateJsonInTree(
|
|
305
|
+
return updateJsonInTree('.eslintrc.json', () => createRootESLintConfig(lintPrefix));
|
|
304
306
|
};
|
|
305
307
|
}
|
|
306
|
-
exports.createRootESLintConfigFile = createRootESLintConfigFile;
|
|
307
308
|
function sortObjectByKeys(obj) {
|
|
308
309
|
return Object.keys(obj)
|
|
309
310
|
.sort()
|
|
@@ -312,3 +313,19 @@ function sortObjectByKeys(obj) {
|
|
|
312
313
|
}, {});
|
|
313
314
|
}
|
|
314
315
|
exports.sortObjectByKeys = sortObjectByKeys;
|
|
316
|
+
/**
|
|
317
|
+
* To make certain schematic usage conversion more ergonomic, if the user does not specify a project
|
|
318
|
+
* and only has a single project in their angular.json we will just go ahead and use that one.
|
|
319
|
+
*/
|
|
320
|
+
function determineTargetProjectName(tree, maybeProject) {
|
|
321
|
+
if (maybeProject) {
|
|
322
|
+
return maybeProject;
|
|
323
|
+
}
|
|
324
|
+
const workspaceJson = readJsonInTree(tree, getWorkspacePath(tree));
|
|
325
|
+
const projects = Object.keys(workspaceJson.projects);
|
|
326
|
+
if (projects.length === 1) {
|
|
327
|
+
return projects[0];
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
exports.determineTargetProjectName = determineTargetProjectName;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/schematics",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Angular Schematics for angular-eslint",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"prebuild": "ncp ../../node_modules/@schematics/angular/application/schema.json src/application/schema.json && ncp ../../node_modules/@schematics/angular/library/schema.json src/library/schema.json",
|
|
10
|
-
"build": "rimraf ./dist && tsc -p tsconfig.json && ncp src/collection.json dist/collection.json && ncp src/migrations.json dist/migrations.json && ncp src/ng-add/schema.json dist/ng-add/schema.json && ncp src/convert-tslint-to-eslint/schema.json dist/convert-tslint-to-eslint/schema.json && ncp src/application/schema.json dist/application/schema.json && ncp src/library/schema.json dist/library/schema.json && ncp src/workspace/schema.json dist/workspace/schema.json",
|
|
10
|
+
"build": "rimraf ./dist && tsc -p tsconfig.json && ncp src/collection.json dist/collection.json && ncp src/migrations.json dist/migrations.json && ncp src/ng-add/schema.json dist/ng-add/schema.json && ncp src/convert-tslint-to-eslint/schema.json dist/convert-tslint-to-eslint/schema.json && ncp src/application/schema.json dist/application/schema.json && ncp src/library/schema.json dist/library/schema.json && ncp src/workspace/schema.json dist/workspace/schema.json && ncp src/add-eslint-to-project/schema.json dist/add-eslint-to-project/schema.json",
|
|
11
11
|
"test": "jest --coverage",
|
|
12
12
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
13
13
|
"clean": "rimraf ./dist"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"save": "devDependencies"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@angular-eslint/eslint-plugin": "
|
|
35
|
-
"@angular-eslint/eslint-plugin-template": "
|
|
34
|
+
"@angular-eslint/eslint-plugin": "4.2.0",
|
|
35
|
+
"@angular-eslint/eslint-plugin-template": "4.2.0",
|
|
36
36
|
"ignore": "5.1.8",
|
|
37
37
|
"strip-json-comments": "3.1.1",
|
|
38
38
|
"tmp": "0.2.1"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@angular/cli": ">= 11.2.0 < 12.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "e1af184da7fbb88902635cd539223ecdaa88c0b8"
|
|
50
50
|
}
|