1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.updateEslintrcJson = void 0;
|
4 | const devkit_1 = require("@nrwl/devkit");
|
5 | const path_1 = require("path");
|
6 | function offsetFilePath(project, pathToFile, offset) {
|
7 | if (!pathToFile.startsWith('..')) {
|
8 |
|
9 | return pathToFile;
|
10 | }
|
11 | const pathFromRoot = (0, path_1.join)(project.root, pathToFile);
|
12 | return (0, devkit_1.joinPathFragments)(offset, pathFromRoot);
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function updateEslintrcJson(tree, schema, project) {
|
20 | const eslintRcPath = (0, path_1.join)(schema.relativeToRootDestination, '.eslintrc.json');
|
21 | if (!tree.exists(eslintRcPath)) {
|
22 |
|
23 | return;
|
24 | }
|
25 | const offset = (0, devkit_1.offsetFromRoot)(schema.relativeToRootDestination);
|
26 | (0, devkit_1.updateJson)(tree, eslintRcPath, (eslintRcJson) => {
|
27 | var _a;
|
28 | if (typeof eslintRcJson.extends === 'string') {
|
29 | eslintRcJson.extends = offsetFilePath(project, eslintRcJson.extends, offset);
|
30 | }
|
31 | else {
|
32 | eslintRcJson.extends = eslintRcJson.extends.map((extend) => offsetFilePath(project, extend, offset));
|
33 | }
|
34 | (_a = eslintRcJson.overrides) === null || _a === void 0 ? void 0 : _a.forEach((o) => {
|
35 | var _a;
|
36 | if ((_a = o.parserOptions) === null || _a === void 0 ? void 0 : _a.project) {
|
37 | o.parserOptions.project = o.parserOptions.project.map((p) => p.replace(project.root, schema.relativeToRootDestination));
|
38 | }
|
39 | });
|
40 | return eslintRcJson;
|
41 | });
|
42 | }
|
43 | exports.updateEslintrcJson = updateEslintrcJson;
|
44 |
|
\ | No newline at end of file |