Skip to content

Commit

Permalink
feat(core): include non-project files on fileMap and filesToProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Sep 19, 2023
1 parent 05b2d2a commit 6965747
Show file tree
Hide file tree
Showing 29 changed files with 713 additions and 367 deletions.
8 changes: 4 additions & 4 deletions docs/generated/devkit/CreateDependenciesContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Context for [CreateDependencies](../../devkit/documents/CreateDependencies)
### Properties

- [externalNodes](../../devkit/documents/CreateDependenciesContext#externalnodes): Record<string, ProjectGraphExternalNode>
- [fileMap](../../devkit/documents/CreateDependenciesContext#filemap): ProjectFileMap
- [filesToProcess](../../devkit/documents/CreateDependenciesContext#filestoprocess): ProjectFileMap
- [fileMap](../../devkit/documents/CreateDependenciesContext#filemap): FileMap
- [filesToProcess](../../devkit/documents/CreateDependenciesContext#filestoprocess): FileMap
- [nxJsonConfiguration](../../devkit/documents/CreateDependenciesContext#nxjsonconfiguration): NxJsonConfiguration<string[] | "\*">
- [projects](../../devkit/documents/CreateDependenciesContext#projects): Record<string, ProjectConfiguration>
- [workspaceRoot](../../devkit/documents/CreateDependenciesContext#workspaceroot): string
Expand All @@ -25,15 +25,15 @@ The external nodes that have been added to the graph.

### fileMap

`Readonly` **fileMap**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
`Readonly` **fileMap**: `FileMap`

All files in the workspace

---

### filesToProcess

`Readonly` **filesToProcess**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
`Readonly` **filesToProcess**: `FileMap`

Files changes since last invocation

Expand Down
10 changes: 5 additions & 5 deletions docs/generated/devkit/ProjectGraphBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ The ProjectGraphProcessor has been deprecated. Use a [CreateNodes](../../devkit/

### Properties

- [fileMap](../../devkit/documents/ProjectGraphBuilder#filemap): ProjectFileMap
- [graph](../../devkit/documents/ProjectGraphBuilder#graph): ProjectGraph
- [projectFileMap](../../devkit/documents/ProjectGraphBuilder#projectfilemap): ProjectFileMap
- [removedEdges](../../devkit/documents/ProjectGraphBuilder#removededges): Object

### Methods
Expand Down Expand Up @@ -51,15 +51,15 @@ The ProjectGraphProcessor has been deprecated. Use a [CreateNodes](../../devkit/

## Properties

### fileMap
### graph

`Private` `Readonly` **fileMap**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
`Readonly` **graph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph)

---

### graph
### projectFileMap

`Readonly` **graph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph)
`Private` `Readonly` **projectFileMap**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)

---

Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { TaskGraph } from '../../config/task-graph';
import { daemonClient } from '../../daemon/client/client';
import { Server } from 'net';
import { readProjectFileMapCache } from '../../project-graph/nx-deps-cache';
import { readFileMapCache } from '../../project-graph/nx-deps-cache';
import { getAffectedGraphNodes } from '../affected/affected';
import { splitArgsIntoNxArgsAndOverrides } from '../../utils/command-line-utils';

Expand Down Expand Up @@ -576,7 +576,7 @@ async function createDepGraphClientResponse(
let graph = pruneExternalNodes(
await createProjectGraphAsync({ exitOnError: true })
);
let fileMap = readProjectFileMapCache().projectFileMap;
let fileMap = readFileMapCache().fileMap.projectFileMap;
performance.mark('project graph watch calculation:end');
performance.mark('project graph response generation:start');

Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export function fileDataDepType(dep: string | [string, string]) {
return typeof dep === 'string' ? 'static' : dep[1];
}

export interface FileMap {
nonProjectFiles: FileData[];
projectFileMap: ProjectFileMap;
}

/**
* A list of files separated by the project they belong to
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { performance } from 'perf_hooks';
import { projectFileMapWithFiles } from '../project-graph-incremental-recomputation';
import { fileMapWithFiles } from '../project-graph-incremental-recomputation';

export type ChangedFile = {
path: string;
Expand Down Expand Up @@ -38,7 +38,7 @@ export function getProjectsAndGlobalChanges(

const fileToProjectMap: Record<string, string> = {};
for (const [projectName, projectFiles] of Object.entries(
projectFileMapWithFiles?.projectFileMap ?? {}
fileMapWithFiles?.fileMap?.projectFileMap ?? {}
)) {
for (const projectFile of projectFiles) {
fileToProjectMap[projectFile.file] = projectName;
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/daemon/server/handle-hash-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ export async function handleHashTasks(payload: {
}) {
setHashEnv(payload.env);

const { projectGraph, allWorkspaceFiles, projectFileMap } =
const { projectGraph, allWorkspaceFiles, fileMap } =
await getCachedSerializedProjectGraphPromise();
const nxJson = readNxJson();

if (projectGraph !== storedProjectGraph) {
storedProjectGraph = projectGraph;
storedHasher = new InProcessTaskHasher(
projectFileMap,
fileMap?.projectFileMap,
allWorkspaceFiles,
projectGraph,
nxJson,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { performance } from 'perf_hooks';
import {
FileData,
FileMap,
ProjectFileMap,
ProjectGraph,
ProjectGraphExternalNode,
} from '../../config/project-graph';
import { buildProjectGraphUsingProjectFileMap } from '../../project-graph/build-project-graph';
import { updateProjectFileMap } from '../../project-graph/file-map-utils';
import { buildProjectGraphUsingProjectFileMap as buildProjectGraphUsingFileMap } from '../../project-graph/build-project-graph';
import { updateFileMap } from '../../project-graph/file-map-utils';
import {
nxProjectGraph,
ProjectFileMapCache,
readProjectFileMapCache,
FileMapCache,
readFileMapCache,
} from '../../project-graph/nx-deps-cache';
import { fileExists } from '../../utils/fileutils';
import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
Expand All @@ -35,14 +36,14 @@ import {
let cachedSerializedProjectGraphPromise: Promise<{
error: Error | null;
projectGraph: ProjectGraph | null;
projectFileMap: ProjectFileMap | null;
fileMap: FileMap | null;
allWorkspaceFiles: FileData[] | null;
serializedProjectGraph: string | null;
}>;
export let projectFileMapWithFiles:
| { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[] }
export let fileMapWithFiles:
| { fileMap: FileMap; allWorkspaceFiles: FileData[] }
| undefined;
export let currentProjectFileMapCache: ProjectFileMapCache | undefined;
export let currentProjectFileMapCache: FileMapCache | undefined;
export let currentProjectGraph: ProjectGraph | undefined;

const collectedUpdatedFiles = new Set<string>();
Expand Down Expand Up @@ -78,7 +79,7 @@ export async function getCachedSerializedProjectGraphPromise() {
error: e,
serializedProjectGraph: null,
projectGraph: null,
projectFileMap: null,
fileMap: null,
allWorkspaceFiles: null,
};
}
Expand Down Expand Up @@ -197,22 +198,19 @@ async function processCollectedUpdatedAndDeletedFiles() {
if (workspaceConfigHash !== storedWorkspaceConfigHash) {
storedWorkspaceConfigHash = workspaceConfigHash;

({ externalNodes: knownExternalNodes, ...projectFileMapWithFiles } =
({ externalNodes: knownExternalNodes, ...fileMapWithFiles } =
await retrieveWorkspaceFiles(workspaceRoot, nxJson));
} else {
if (projectFileMapWithFiles) {
projectFileMapWithFiles = updateProjectFileMap(
if (fileMapWithFiles) {
fileMapWithFiles = updateFileMap(
projectNodes,
projectFileMapWithFiles.projectFileMap,
projectFileMapWithFiles.allWorkspaceFiles,
fileMapWithFiles.fileMap,
fileMapWithFiles.allWorkspaceFiles,
new Map(Object.entries(updatedFileHashes)),
deletedFiles
);
} else {
projectFileMapWithFiles = await retrieveWorkspaceFiles(
workspaceRoot,
nxJson
);
fileMapWithFiles = await retrieveWorkspaceFiles(workspaceRoot, nxJson);
}
}

Expand Down Expand Up @@ -240,7 +238,7 @@ async function processFilesAndCreateAndSerializeProjectGraph() {
return Promise.resolve({
error: err,
projectGraph: null,
projectFileMap: null,
fileMap: null,
allWorkspaceFiles: null,
serializedProjectGraph: null,
});
Expand All @@ -253,18 +251,21 @@ function copyFileData(d: FileData[]) {
return d.map((t) => ({ ...t }));
}

function copyFileMap(m: ProjectFileMap) {
const c = {};
for (let p of Object.keys(m)) {
c[p] = copyFileData(m[p]);
function copyFileMap(m: FileMap) {
const c: FileMap = {
nonProjectFiles: copyFileData(m.nonProjectFiles),
projectFileMap: {},
};
for (let p of Object.keys(m.projectFileMap)) {
c[p] = copyFileData(m.projectFileMap[p]);
}
return c;
}

async function createAndSerializeProjectGraph(): Promise<{
error: string | null;
projectGraph: ProjectGraph | null;
projectFileMap: ProjectFileMap | null;
fileMap: FileMap | null;
allWorkspaceFiles: FileData[] | null;
serializedProjectGraph: string | null;
}> {
Expand All @@ -274,17 +275,15 @@ async function createAndSerializeProjectGraph(): Promise<{
workspaceRoot,
readNxJson(workspaceRoot)
);
const projectFileMap = copyFileMap(projectFileMapWithFiles.projectFileMap);
const allWorkspaceFiles = copyFileData(
projectFileMapWithFiles.allWorkspaceFiles
);
const fileMap = copyFileMap(fileMapWithFiles.fileMap);
const allWorkspaceFiles = copyFileData(fileMapWithFiles.allWorkspaceFiles);
const { projectGraph, projectFileMapCache } =
await buildProjectGraphUsingProjectFileMap(
await buildProjectGraphUsingFileMap(
projectConfigurations.projectNodes,
knownExternalNodes,
projectFileMap,
fileMap,
allWorkspaceFiles,
currentProjectFileMapCache || readProjectFileMapCache(),
currentProjectFileMapCache || readFileMapCache(),
true
);
currentProjectFileMapCache = projectFileMapCache;
Expand All @@ -309,7 +308,7 @@ async function createAndSerializeProjectGraph(): Promise<{
return {
error: null,
projectGraph,
projectFileMap,
fileMap,
allWorkspaceFiles,
serializedProjectGraph,
};
Expand All @@ -320,7 +319,7 @@ async function createAndSerializeProjectGraph(): Promise<{
return {
error: e,
projectGraph: null,
projectFileMap: null,
fileMap: null,
allWorkspaceFiles: null,
serializedProjectGraph: null,
};
Expand All @@ -329,7 +328,7 @@ async function createAndSerializeProjectGraph(): Promise<{

async function resetInternalState() {
cachedSerializedProjectGraphPromise = undefined;
projectFileMapWithFiles = undefined;
fileMapWithFiles = undefined;
currentProjectFileMapCache = undefined;
currentProjectGraph = undefined;
collectedUpdatedFiles.clear();
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/native/workspace/workspace_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ pub struct NxWorkspaceFiles {
pub external_nodes: HashMap<String, JsObject>,
}

pub struct FileMap {
pub project_file_map: HashMap<String, Vec<FileData>>,
pub non_project_files: Vec<FileData>
}

pub(super) fn get_files<ConfigurationParser>(
globs: Vec<String>,
parse_configurations: ConfigurationParser,
Expand Down
Loading

0 comments on commit 6965747

Please sign in to comment.