UNPKG

1.83 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.updateEslintrcJson = void 0;
4const devkit_1 = require("@nrwl/devkit");
5const path_1 = require("path");
6function offsetFilePath(project, pathToFile, offset) {
7 if (!pathToFile.startsWith('..')) {
8 // not a relative path
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 * Update the .eslintrc file of the project if it exists.
16 *
17 * @param schema The options provided to the schematic
18 */
19function updateEslintrcJson(tree, schema, project) {
20 const eslintRcPath = (0, path_1.join)(schema.relativeToRootDestination, '.eslintrc.json');
21 if (!tree.exists(eslintRcPath)) {
22 // no .eslintrc found. nothing to do
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}
43exports.updateEslintrcJson = updateEslintrcJson;
44//# sourceMappingURL=update-eslintrc-json.js.map
\No newline at end of file