Skip to content

Commit

Permalink
fix(core): make eslint optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jan 31, 2023
1 parent f8be153 commit 43eee12
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 7 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
"peerDependencies": {
"@nrwl/devkit": ">14.0.0-beta.1",
"@nrwl/workspace": ">14.0.0-beta.1",
"nx": ">14.0.0-beta.1"
"nx": ">14.0.0-beta.1",
"eslint": ">8.0.0"
},
"peerDependenciesMeta": {
"eslint": {
"optional": true
}
},
"devDependencies": {
"@nrwl/cli": "*"
Expand Down
27 changes: 16 additions & 11 deletions packages/core/src/tasks/check-module-boundaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Workspaces,
} from '@nrwl/devkit';

import { ESLint } from 'eslint';
import { relative } from 'path';

import {
Expand Down Expand Up @@ -69,16 +68,22 @@ export async function loadModuleBoundaries(
): Promise<ModuleBoundaries> {
const configured = readConfig(host).moduleBoundaries;
if (!configured) {
const result = await new ESLint()
.calculateConfigForFile(`${root}/non-existant.ts`)
.catch(() =>
Promise.resolve({
rules: { '@nrwl/nx/enforce-module-boundaries': [] },
}),
);
const [, moduleBoundaryConfig] =
result.rules['@nrwl/nx/enforce-module-boundaries'] || [];
return moduleBoundaryConfig?.depConstraints ?? [];
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ESLint }: typeof import('eslint') = require('eslint');
const result = await new ESLint()
.calculateConfigForFile(`${root}/non-existant.ts`)
.catch(() =>
Promise.resolve({
rules: { '@nrwl/nx/enforce-module-boundaries': [] },
}),
);
const [, moduleBoundaryConfig] =
result.rules['@nrwl/nx/enforce-module-boundaries'] || [];
return moduleBoundaryConfig?.depConstraints ?? [];
} catch {
return [];
}
} else {
return configured;
}
Expand Down

0 comments on commit 43eee12

Please sign in to comment.