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