@nxext/stencil
Version:
Nx plugin for stenciljs
70 lines • 3.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateLintConfig = updateLintConfig;
const devkit_1 = require("@nx/devkit");
const internal_1 = require("@nx/eslint/internal");
const path_1 = require("path");
/**
* When adding storybook we need to inform ESLint
* of the additional tsconfig.json file which will be the only tsconfig
* which includes *.stories files.
*
* For legacy `.eslintrc.json` workspaces this is done by appending to
* `parserOptions.project`. TS-solution workspaces (as scaffolded by
* `create-nx-workspace`) default to flat config, which has no equivalent
* `.eslintrc.json` file to patch at all - use `@nx/eslint/internal`'s flat
* config helpers instead (mirrors `packages/svelte/src/generators/utils/lint.ts`).
*
* Projects with no lint config at all (e.g. `linter: 'none'`, or unit-test
* fixtures that never ran `addLinting`) get neither branch - matches the
* pre-existing legacy-only guard's behavior of silently no-op'ing.
*/
function updateLintConfig(tree, schema) {
const { name: projectName } = schema;
const { root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
if (!(0, internal_1.findEslintFile)(tree, root)) {
return;
}
if ((0, internal_1.useFlatConfig)(tree)) {
(0, internal_1.addOverrideToLintConfig)(tree, root, {
files: ['**/*.stories.ts', '**/*.stories.tsx'],
languageOptions: {
parserOptions: {
project: [(0, path_1.join)(root, '.storybook/tsconfig.json')],
},
},
});
return;
}
if (tree.exists((0, path_1.join)(root, '.eslintrc.json'))) {
(0, devkit_1.updateJson)(tree, (0, path_1.join)(root, '.eslintrc.json'), (json) => {
var _a, _b, _c, _d;
if (typeof ((_a = json.parserOptions) === null || _a === void 0 ? void 0 : _a.project) === 'string') {
json.parserOptions.project = [json.parserOptions.project];
}
if (Array.isArray((_b = json.parserOptions) === null || _b === void 0 ? void 0 : _b.project)) {
json.parserOptions.project = dedupe([
...json.parserOptions.project,
(0, path_1.join)(root, '.storybook/tsconfig.json'),
]);
}
const overrides = json.overrides || [];
for (const o of overrides) {
if (typeof ((_c = o.parserOptions) === null || _c === void 0 ? void 0 : _c.project) === 'string') {
o.parserOptions.project = [o.parserOptions.project];
}
if (Array.isArray((_d = o.parserOptions) === null || _d === void 0 ? void 0 : _d.project)) {
o.parserOptions.project = dedupe([
...o.parserOptions.project,
(0, path_1.join)(root, '.storybook/tsconfig.json'),
]);
}
}
return json;
});
}
}
function dedupe(arr) {
return Array.from(new Set(arr));
}
//# sourceMappingURL=update-lint-config.js.map