Skip to content

Commit

Permalink
cleanup(core): create type instead of repeating Record<...> all over …
Browse files Browse the repository at this point in the history
…the place
  • Loading branch information
MaxKless committed Nov 15, 2023
1 parent fb61ec1 commit cc4dd4f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TargetConfiguration,
} from '../../config/workspace-json-project-json';
import {
ConfigurationSourceMaps,
SourceInformation,
mergeProjectConfigurationIntoRootMap,
mergeTargetConfigurations,
Expand Down Expand Up @@ -547,7 +548,7 @@ describe('project-configuration-utils', () => {
describe('source map', () => {
it('should add new project info', () => {
const rootMap = new RootMapBuilder().getRootMap();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -655,7 +656,7 @@ describe('project-configuration-utils', () => {

it('should merge root level properties', () => {
const rootMap = new Map();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -693,7 +694,7 @@ describe('project-configuration-utils', () => {

it('should merge target properties for compatible targets', () => {
const rootMap = new RootMapBuilder().getRootMap();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -771,7 +772,7 @@ describe('project-configuration-utils', () => {

it('should override target options & configurations for incompatible targets', () => {
const rootMap = new RootMapBuilder().getRootMap();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -843,7 +844,7 @@ describe('project-configuration-utils', () => {

it('should not merge top level properties for incompatible targets', () => {
const rootMap = new RootMapBuilder().getRootMap();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -889,7 +890,7 @@ describe('project-configuration-utils', () => {

it('should merge generator property', () => {
const rootMap = new RootMapBuilder().getRootMap();
const sourceMap: Record<string, Record<string, SourceInformation>> = {
const sourceMap: ConfigurationSourceMaps = {
'libs/lib-a': {},
};
mergeProjectConfigurationIntoRootMap(
Expand Down Expand Up @@ -1011,7 +1012,7 @@ class RootMapBuilder {
}

function assertCorrectKeysInSourceMap(
sourceMaps: Record<string, Record<string, SourceInformation>>,
sourceMaps: ConfigurationSourceMaps,
root: string,
...tuples: [string, string][]
) {
Expand Down
20 changes: 12 additions & 8 deletions packages/nx/src/project-graph/utils/project-configuration-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import { output } from '../../utils/output';
import minimatch = require('minimatch');

export type SourceInformation = [string, string];
export type ConfigurationSourceMaps = Record<
string,
Record<string, SourceInformation>
>;

export function mergeProjectConfigurationIntoRootMap(
projectRootMap: Map<string, ProjectConfiguration>,
project: ProjectConfiguration,
projectConfigSourceMaps?: Record<string, Record<string, SourceInformation>>,
configurationSourceMaps?: ConfigurationSourceMaps,
sourceInformation?: SourceInformation
): void {
if (projectConfigSourceMaps && !projectConfigSourceMaps[project.root]) {
projectConfigSourceMaps[project.root] = {};
if (configurationSourceMaps && !configurationSourceMaps[project.root]) {
configurationSourceMaps[project.root] = {};
}
const sourceMap = projectConfigSourceMaps?.[project.root];
const sourceMap = configurationSourceMaps?.[project.root];

let matchingProject = projectRootMap.get(project.root);

Expand Down Expand Up @@ -160,7 +164,7 @@ type ConfigurationResult = {
projects: Record<string, ProjectConfiguration>;
externalNodes: Record<string, ProjectGraphExternalNode>;
rootMap: Record<string, string>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
};

/**
Expand Down Expand Up @@ -230,7 +234,7 @@ function combineSyncConfigurationResults(
): ConfigurationResult {
const projectRootMap: Map<string, ProjectConfiguration> = new Map();
const externalNodes: Record<string, ProjectGraphExternalNode> = {};
const projectRootSourceMaps: Record<
const configurationSourceMaps: Record<
string,
Record<string, SourceInformation>
> = {};
Expand Down Expand Up @@ -259,7 +263,7 @@ function combineSyncConfigurationResults(
root: node,
...projectNodes[node],
},
projectRootSourceMaps,
configurationSourceMaps,
[pluginName, file]
);
}
Expand All @@ -272,7 +276,7 @@ function combineSyncConfigurationResults(
projects: readProjectConfigurationsFromRootMap(projectRootMap),
externalNodes,
rootMap,
sourceMaps: projectRootSourceMaps,
sourceMaps: configurationSourceMaps,
};
}

Expand Down
13 changes: 7 additions & 6 deletions packages/nx/src/project-graph/utils/retrieve-workspace-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getNxPackageJsonWorkspacesPlugin,
} from '../../../plugins/package-json-workspaces';
import {
ConfigurationSourceMaps,
SourceInformation,
buildProjectsConfigurationsFromProjectPathsAndPlugins,
} from './project-configuration-utils';
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function retrieveWorkspaceFiles(
performance.mark('get-workspace-files:start');
let projects: Record<string, ProjectConfiguration>;
let externalNodes: Record<string, ProjectGraphExternalNode>;
let sourceMaps: Record<string, Record<string, SourceInformation>>;
let sourceMaps: ConfigurationSourceMaps;

const { projectFileMap, globalFiles } = (await getNxWorkspaceFilesFromContext(
workspaceRoot,
Expand Down Expand Up @@ -113,7 +114,7 @@ export async function retrieveProjectConfigurations(
): Promise<{
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
}> {
const plugins = await loadNxPlugins(
nxJson?.plugins ?? [],
Expand All @@ -131,7 +132,7 @@ export async function retrieveProjectConfigurationsWithAngularProjects(
): Promise<{
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
}> {
const plugins = await loadNxPlugins(
nxJson?.plugins ?? [],
Expand All @@ -158,12 +159,12 @@ function _retrieveProjectConfigurations(
): Promise<{
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
}> {
let result: {
externalNodes: Record<string, ProjectGraphExternalNode>;
projectNodes: Record<string, ProjectConfiguration>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
};
return getProjectConfigurationsFromContext(
workspaceRoot,
Expand Down Expand Up @@ -274,7 +275,7 @@ export async function createProjectConfigurations(
projects: Record<string, ProjectConfiguration>;
externalNodes: Record<string, ProjectGraphExternalNode>;
rootMap: Record<string, string>;
sourceMaps: Record<string, Record<string, SourceInformation>>;
sourceMaps: ConfigurationSourceMaps;
}> {
performance.mark('build-project-configs:start');

Expand Down

0 comments on commit cc4dd4f

Please sign in to comment.