-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): ability to load module boundaries from nx-dotnet config
Signed-off-by: AgentEnder <craigorycoppola@gmail.com>
- Loading branch information
1 parent
3fb8ba4
commit 2618b5d
Showing
10 changed files
with
197 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Tree, writeJson } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import { | ||
CONFIG_FILE_PATH, | ||
ModuleBoundaries, | ||
NxDotnetConfig, | ||
} from '@nx-dotnet/utils'; | ||
|
||
import { | ||
checkModuleBoundariesForProject, | ||
loadModuleBoundaries, | ||
} from './check-module-boundaries'; | ||
import * as checkModule from './check-module-boundaries'; | ||
import * as ESLintNamespace from 'eslint'; | ||
|
||
const MOCK_BOUNDARIES: ModuleBoundaries = [ | ||
{ | ||
onlyDependOnLibsWithTags: ['a', 'shared'], | ||
sourceTag: 'a', | ||
}, | ||
{ | ||
onlyDependOnLibsWithTags: ['b', 'shared'], | ||
sourceTag: 'b', | ||
}, | ||
{ | ||
onlyDependOnLibsWithTags: ['shared'], | ||
sourceTag: 'shared', | ||
}, | ||
]; | ||
|
||
describe('load-module-boundaries', () => { | ||
let appTree: Tree; | ||
|
||
beforeEach(() => { | ||
appTree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should not load eslint if boundaries in config', async () => { | ||
const eslintConstructorSpy = jest.spyOn(ESLintNamespace, 'ESLint'); | ||
writeJson<NxDotnetConfig>(appTree, CONFIG_FILE_PATH, { | ||
moduleBoundaries: MOCK_BOUNDARIES, | ||
nugetPackages: {}, | ||
}); | ||
const boundaries = await loadModuleBoundaries('', appTree); | ||
expect(eslintConstructorSpy).not.toHaveBeenCalled(); | ||
expect(boundaries).toEqual(MOCK_BOUNDARIES); | ||
}); | ||
|
||
it('should load from eslint if boundaries not in config', async () => { | ||
const eslintConfigSpy = jest | ||
.spyOn(ESLintNamespace, 'ESLint') | ||
.mockReturnValue({ | ||
calculateConfigForFile: jest.fn().mockResolvedValue({ | ||
rules: { | ||
'@nrwl/nx/enforce-module-boundaries': [ | ||
1, | ||
{ depConstraints: MOCK_BOUNDARIES }, | ||
], | ||
}, | ||
}), | ||
} as unknown as ESLintNamespace.ESLint); | ||
writeJson<NxDotnetConfig>(appTree, CONFIG_FILE_PATH, { | ||
nugetPackages: {}, | ||
}); | ||
const boundaries = await loadModuleBoundaries('', appTree); | ||
expect(eslintConfigSpy).toHaveBeenCalledTimes(1); | ||
expect(boundaries).toEqual(MOCK_BOUNDARIES); | ||
}); | ||
}); | ||
|
||
describe('enforce-module-boundaries', () => { | ||
it('should exit early if no tags on project', async () => { | ||
const spy = jest.spyOn(checkModule, 'loadModuleBoundaries'); | ||
const results = await checkModuleBoundariesForProject('a', { | ||
version: 2, | ||
projects: { | ||
a: { | ||
tags: [], | ||
targets: {}, | ||
root: '', | ||
}, | ||
}, | ||
}); | ||
expect(spy).not.toHaveBeenCalled(); | ||
expect(results).toHaveLength(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './cmd-line-parameter'; | ||
export * from './nx-dotnet-config.interface'; | ||
export * from './nx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { ModuleBoundaries } from './nx'; | ||
|
||
export interface NxDotnetConfig { | ||
/** | ||
* Map of package -> version, used for Single Version Principle. | ||
*/ | ||
nugetPackages: { | ||
[key: string]: string | undefined; | ||
}; | ||
moduleBoundaries?: ModuleBoundaries; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type ModuleBoundaries = { | ||
sourceTag: '*' | string; | ||
onlyDependOnLibsWithTags: string[]; | ||
}[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters