fix(core): fix project configuration typings (#18073)
This commit is contained in:
parent
1bc58c997d
commit
bcb3251ef5
@ -22,6 +22,7 @@ import {
|
||||
retrieveWorkspaceFiles,
|
||||
retrieveProjectConfigurations,
|
||||
} from '../../project-graph/utils/retrieve-workspace-files';
|
||||
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
||||
|
||||
let cachedSerializedProjectGraphPromise: Promise<{
|
||||
error: Error | null;
|
||||
@ -115,8 +116,18 @@ export function addUpdatedAndDeletedFiles(
|
||||
}
|
||||
}
|
||||
|
||||
function computeWorkspaceConfigHash(projectsConfigurations: any) {
|
||||
return hashArray([JSON.stringify(projectsConfigurations)]);
|
||||
function computeWorkspaceConfigHash(
|
||||
projectsConfigurations: Record<string, ProjectConfiguration>
|
||||
) {
|
||||
const projectConfigurationStrings = Object.entries(projectsConfigurations)
|
||||
.sort(([projectNameA], [projectNameB]) =>
|
||||
projectNameA.localeCompare(projectNameB)
|
||||
)
|
||||
.map(
|
||||
([projectName, projectConfig]) =>
|
||||
`${projectName}:${JSON.stringify(projectConfig)}`
|
||||
);
|
||||
return hashArray(projectConfigurationStrings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,24 +1,26 @@
|
||||
import { ProjectType } from '../config/workspace-json-project-json';
|
||||
import { createProjectFileMap, updateProjectFileMap } from './file-map-utils';
|
||||
|
||||
describe('fileMapUtils', () => {
|
||||
describe('createFileMap', () => {
|
||||
it('should map files to projects', () => {
|
||||
const projectsConfigurations = {
|
||||
version: 2,
|
||||
projects: {
|
||||
demo: {
|
||||
root: 'apps/demo',
|
||||
sourceRoot: 'apps/demo/src',
|
||||
projectType: 'application',
|
||||
projectType: 'application' as ProjectType,
|
||||
},
|
||||
'demo-e2e': {
|
||||
root: 'apps/demo-e2e',
|
||||
sourceRoot: 'apps/demo-e2e/src',
|
||||
projectType: 'application',
|
||||
projectType: 'application' as ProjectType,
|
||||
},
|
||||
ui: {
|
||||
root: 'libs/ui',
|
||||
sourceRoot: 'libs/ui/src',
|
||||
projectType: 'library',
|
||||
projectType: 'library' as ProjectType,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -29,7 +31,7 @@ describe('fileMapUtils', () => {
|
||||
{ file: 'tools/myfile.txt', hash: 'some-hash' },
|
||||
];
|
||||
|
||||
const result = createProjectFileMap(projectsConfigurations as any, files);
|
||||
const result = createProjectFileMap(projectsConfigurations, files);
|
||||
|
||||
expect(result).toEqual({
|
||||
projectFileMap: {
|
||||
@ -52,22 +54,20 @@ describe('fileMapUtils', () => {
|
||||
describe('updateFileMap', () => {
|
||||
it('should map files to projects', () => {
|
||||
const projectsConfigurations = {
|
||||
projects: {
|
||||
demo: {
|
||||
root: 'apps/demo',
|
||||
sourceRoot: 'apps/demo/src',
|
||||
projectType: 'application',
|
||||
},
|
||||
'demo-e2e': {
|
||||
root: 'apps/demo-e2e',
|
||||
sourceRoot: 'apps/demo-e2e/src',
|
||||
projectType: 'application',
|
||||
},
|
||||
ui: {
|
||||
root: 'libs/ui',
|
||||
sourceRoot: 'libs/ui/src',
|
||||
projectType: 'library',
|
||||
},
|
||||
demo: {
|
||||
root: 'apps/demo',
|
||||
sourceRoot: 'apps/demo/src',
|
||||
projectType: 'application' as ProjectType,
|
||||
},
|
||||
'demo-e2e': {
|
||||
root: 'apps/demo-e2e',
|
||||
sourceRoot: 'apps/demo-e2e/src',
|
||||
projectType: 'application' as ProjectType,
|
||||
},
|
||||
ui: {
|
||||
root: 'libs/ui',
|
||||
sourceRoot: 'libs/ui/src',
|
||||
projectType: 'library' as ProjectType,
|
||||
},
|
||||
};
|
||||
const files = [
|
||||
@ -87,7 +87,7 @@ describe('fileMapUtils', () => {
|
||||
],
|
||||
};
|
||||
const result = updateProjectFileMap(
|
||||
projectsConfigurations as any,
|
||||
projectsConfigurations,
|
||||
projectFileMap,
|
||||
files,
|
||||
new Map([
|
||||
|
||||
@ -7,7 +7,10 @@ import {
|
||||
createProjectRootMappingsFromProjectConfigurations,
|
||||
findProjectForPath,
|
||||
} from './utils/find-project-for-path';
|
||||
import { ProjectsConfigurations } from '../config/workspace-json-project-json';
|
||||
import {
|
||||
ProjectConfiguration,
|
||||
ProjectsConfigurations,
|
||||
} from '../config/workspace-json-project-json';
|
||||
import { daemonClient } from '../daemon/client/client';
|
||||
import { readProjectsConfigurationFromProjectGraph } from './project-graph';
|
||||
import { fileHasher } from '../hasher/file-hasher';
|
||||
@ -52,16 +55,14 @@ export function createProjectFileMap(
|
||||
}
|
||||
|
||||
export function updateProjectFileMap(
|
||||
projectsConfigurations: ProjectsConfigurations,
|
||||
projectsConfigurations: Record<string, ProjectConfiguration>,
|
||||
projectFileMap: ProjectFileMap,
|
||||
allWorkspaceFiles: FileData[],
|
||||
updatedFiles: Map<string, string>,
|
||||
deletedFiles: string[]
|
||||
): { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[] } {
|
||||
const projectRootMappings =
|
||||
createProjectRootMappingsFromProjectConfigurations(
|
||||
projectsConfigurations.projects
|
||||
);
|
||||
createProjectRootMappingsFromProjectConfigurations(projectsConfigurations);
|
||||
|
||||
for (const f of updatedFiles.keys()) {
|
||||
const matchingProjectFiles =
|
||||
|
||||
@ -84,7 +84,7 @@ export async function retrieveWorkspaceFiles(
|
||||
export async function retrieveProjectConfigurations(
|
||||
workspaceRoot: string,
|
||||
nxJson: NxJsonConfiguration
|
||||
) {
|
||||
): Promise<Record<string, ProjectConfiguration>> {
|
||||
const { getProjectConfigurations } = require('../../native');
|
||||
const globs = await configurationGlobs(workspaceRoot, nxJson);
|
||||
return getProjectConfigurations(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user