Skip to content

Commit

Permalink
feat(core): restore cached dependencies from non-project-files
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Sep 18, 2023
1 parent 1286c7a commit 3c24412
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 79 deletions.
30 changes: 30 additions & 0 deletions docs/generated/devkit/BaseFileData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Interface: BaseFileData

Some metadata about a file

## Hierarchy

- **`BaseFileData`**

[`ProjectFileData`](../../devkit/documents/ProjectFileData)

[`NonProjectFileData`](../../devkit/documents/NonProjectFileData)

## Table of contents

### Properties

- [file](../../devkit/documents/BaseFileData#file): string
- [hash](../../devkit/documents/BaseFileData#hash): string

## Properties

### file

**file**: `string`

---

### hash

**hash**: `string`
30 changes: 2 additions & 28 deletions docs/generated/devkit/FileData.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
# Interface: FileData
# Type alias: FileData

Some metadata about a file

## Table of contents

### Properties

- [deps](../../devkit/documents/FileData#deps): (string | [string, string])[]
- [file](../../devkit/documents/FileData#file): string
- [hash](../../devkit/documents/FileData#hash): string

## Properties

### deps

`Optional` **deps**: (`string` \| [`string`, `string`])[]

---

### file

**file**: `string`

---

### hash

**hash**: `string`
Ƭ **FileData**: [`ProjectFileData`](../../devkit/documents/ProjectFileData) \| [`NonProjectFileData`](../../devkit/documents/NonProjectFileData)
45 changes: 45 additions & 0 deletions docs/generated/devkit/NonProjectFileData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Interface: NonProjectFileData

Represents metadata about a file that **does not** belong to a project.

## Hierarchy

- [`BaseFileData`](../../devkit/documents/BaseFileData)

**`NonProjectFileData`**

## Table of contents

### Properties

- [deps](../../devkit/documents/NonProjectFileData#deps): ProjectGraphDependency[]
- [file](../../devkit/documents/NonProjectFileData#file): string
- [hash](../../devkit/documents/NonProjectFileData#hash): string

## Properties

### deps

`Optional` **deps**: [`ProjectGraphDependency`](../../devkit/documents/ProjectGraphDependency)[]

Dependencies which were created with this file as the source file.

---

### file

**file**: `string`

#### Inherited from

[BaseFileData](../../devkit/documents/BaseFileData).[file](../../devkit/documents/BaseFileData#file)

---

### hash

**hash**: `string`

#### Inherited from

[BaseFileData](../../devkit/documents/BaseFileData).[hash](../../devkit/documents/BaseFileData#hash)
48 changes: 48 additions & 0 deletions docs/generated/devkit/ProjectFileData.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Interface: ProjectFileData

Represents metadata about a file that belongs to a project.

## Hierarchy

- [`BaseFileData`](../../devkit/documents/BaseFileData)

**`ProjectFileData`**

## Table of contents

### Properties

- [deps](../../devkit/documents/ProjectFileData#deps): (string | [target: string, type: string])[]
- [file](../../devkit/documents/ProjectFileData#file): string
- [hash](../../devkit/documents/ProjectFileData#hash): string

## Properties

### deps

`Optional` **deps**: (`string` \| [target: string, type: string])[]

An array of dependencies. If an element is just a string,
the dependency is assumed to be a static dependency targetting
that string. If the element is a tuple, the first element inside of it
is the target project, with the second element being the type of dependency.

---

### file

**file**: `string`

#### Inherited from

[BaseFileData](../../devkit/documents/BaseFileData).[file](../../devkit/documents/BaseFileData#file)

---

### hash

**hash**: `string`

#### Inherited from

[BaseFileData](../../devkit/documents/BaseFileData).[hash](../../devkit/documents/BaseFileData#hash)
2 changes: 1 addition & 1 deletion docs/generated/devkit/ProjectFileMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ A list of files separated by the project they belong to

## Indexable

[projectName: `string`]: [`FileData`](../../devkit/documents/FileData)[]
[projectName: `string`]: [`ProjectFileData`](../../devkit/documents/ProjectFileData)[]
25 changes: 20 additions & 5 deletions docs/generated/devkit/ProjectGraphBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ The ProjectGraphProcessor has been deprecated. Use a [CreateNodes](../../devkit/

### Properties

- [allWorkspaceFiles](../../devkit/documents/ProjectGraphBuilder#allworkspacefiles): FileData[]
- [graph](../../devkit/documents/ProjectGraphBuilder#graph): ProjectGraph
- [nonProjectFiles](../../devkit/documents/ProjectGraphBuilder#nonprojectfiles): NonProjectFileData[]
- [projectFileMap](../../devkit/documents/ProjectGraphBuilder#projectfilemap): ProjectFileMap
- [removedEdges](../../devkit/documents/ProjectGraphBuilder#removededges): Object

Expand All @@ -40,23 +42,36 @@ The ProjectGraphProcessor has been deprecated. Use a [CreateNodes](../../devkit/

### constructor

**new ProjectGraphBuilder**(`graph?`, `fileMap?`)
**new ProjectGraphBuilder**(`graph?`, `projectFileMap?`, `nonProjectFiles?`)

#### Parameters

| Name | Type |
| :--------- | :-------------------------------------------------------- |
| `graph?` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
| `fileMap?` | [`ProjectFileMap`](../../devkit/documents/ProjectFileMap) |
| Name | Type |
| :----------------- | :------------------------------------------------------------------ |
| `graph?` | [`ProjectGraph`](../../devkit/documents/ProjectGraph) |
| `projectFileMap?` | [`ProjectFileMap`](../../devkit/documents/ProjectFileMap) |
| `nonProjectFiles?` | [`NonProjectFileData`](../../devkit/documents/NonProjectFileData)[] |

## Properties

### allWorkspaceFiles

`Private` `Readonly` **allWorkspaceFiles**: [`FileData`](../../devkit/documents/FileData)[]

---

### graph

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

---

### nonProjectFiles

`Private` `Readonly` **nonProjectFiles**: [`NonProjectFileData`](../../devkit/documents/NonProjectFileData)[]

---

### projectFileMap

`Private` `Readonly` **projectFileMap**: [`ProjectFileMap`](../../devkit/documents/ProjectFileMap)
Expand Down
5 changes: 4 additions & 1 deletion docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ It only uses language primitives and immutable objects

### Interfaces

- [BaseFileData](../../devkit/documents/BaseFileData)
- [CreateDependenciesContext](../../devkit/documents/CreateDependenciesContext)
- [CreateNodesContext](../../devkit/documents/CreateNodesContext)
- [DefaultTasksRunnerOptions](../../devkit/documents/DefaultTasksRunnerOptions)
- [ExecutorContext](../../devkit/documents/ExecutorContext)
- [ExecutorsJson](../../devkit/documents/ExecutorsJson)
- [FileChange](../../devkit/documents/FileChange)
- [FileData](../../devkit/documents/FileData)
- [GeneratorsJson](../../devkit/documents/GeneratorsJson)
- [Hash](../../devkit/documents/Hash)
- [HasherContext](../../devkit/documents/HasherContext)
- [ImplicitJsonSubsetDependency](../../devkit/documents/ImplicitJsonSubsetDependency)
- [JsonParseOptions](../../devkit/documents/JsonParseOptions)
- [JsonSerializeOptions](../../devkit/documents/JsonSerializeOptions)
- [MigrationsJson](../../devkit/documents/MigrationsJson)
- [NonProjectFileData](../../devkit/documents/NonProjectFileData)
- [NxAffectedConfig](../../devkit/documents/NxAffectedConfig)
- [NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration)
- [ProjectConfiguration](../../devkit/documents/ProjectConfiguration)
- [ProjectFileData](../../devkit/documents/ProjectFileData)
- [ProjectFileMap](../../devkit/documents/ProjectFileMap)
- [ProjectGraph](../../devkit/documents/ProjectGraph)
- [ProjectGraphDependency](../../devkit/documents/ProjectGraphDependency)
Expand Down Expand Up @@ -67,6 +69,7 @@ It only uses language primitives and immutable objects
- [CustomHasher](../../devkit/documents/CustomHasher)
- [DynamicDependency](../../devkit/documents/DynamicDependency)
- [Executor](../../devkit/documents/Executor)
- [FileData](../../devkit/documents/FileData)
- [Generator](../../devkit/documents/Generator)
- [GeneratorCallback](../../devkit/documents/GeneratorCallback)
- [Hasher](../../devkit/documents/Hasher)
Expand Down
5 changes: 4 additions & 1 deletion docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@ It only uses language primitives and immutable objects

### Interfaces

- [BaseFileData](../../devkit/documents/BaseFileData)
- [CreateDependenciesContext](../../devkit/documents/CreateDependenciesContext)
- [CreateNodesContext](../../devkit/documents/CreateNodesContext)
- [DefaultTasksRunnerOptions](../../devkit/documents/DefaultTasksRunnerOptions)
- [ExecutorContext](../../devkit/documents/ExecutorContext)
- [ExecutorsJson](../../devkit/documents/ExecutorsJson)
- [FileChange](../../devkit/documents/FileChange)
- [FileData](../../devkit/documents/FileData)
- [GeneratorsJson](../../devkit/documents/GeneratorsJson)
- [Hash](../../devkit/documents/Hash)
- [HasherContext](../../devkit/documents/HasherContext)
- [ImplicitJsonSubsetDependency](../../devkit/documents/ImplicitJsonSubsetDependency)
- [JsonParseOptions](../../devkit/documents/JsonParseOptions)
- [JsonSerializeOptions](../../devkit/documents/JsonSerializeOptions)
- [MigrationsJson](../../devkit/documents/MigrationsJson)
- [NonProjectFileData](../../devkit/documents/NonProjectFileData)
- [NxAffectedConfig](../../devkit/documents/NxAffectedConfig)
- [NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration)
- [ProjectConfiguration](../../devkit/documents/ProjectConfiguration)
- [ProjectFileData](../../devkit/documents/ProjectFileData)
- [ProjectFileMap](../../devkit/documents/ProjectFileMap)
- [ProjectGraph](../../devkit/documents/ProjectGraph)
- [ProjectGraphDependency](../../devkit/documents/ProjectGraphDependency)
Expand Down Expand Up @@ -67,6 +69,7 @@ It only uses language primitives and immutable objects
- [CustomHasher](../../devkit/documents/CustomHasher)
- [DynamicDependency](../../devkit/documents/DynamicDependency)
- [Executor](../../devkit/documents/Executor)
- [FileData](../../devkit/documents/FileData)
- [Generator](../../devkit/documents/Generator)
- [GeneratorCallback](../../devkit/documents/GeneratorCallback)
- [Hasher](../../devkit/documents/Hasher)
Expand Down
4 changes: 2 additions & 2 deletions packages/js/src/utils/package-json/update-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { writeFileSync } from 'fs-extra';
import { fileExists } from 'nx/src/utils/fileutils';
import type { PackageJson } from 'nx/src/utils/package-json';
import { existsSync } from 'fs';
import { readProjectFileMapCache } from 'nx/src/project-graph/nx-deps-cache';
import { readFileMapCache } from 'nx/src/project-graph/nx-deps-cache';

import { getRelativeDirectoryToProjectRoot } from '../get-main-file-dir';

Expand Down Expand Up @@ -57,7 +57,7 @@ export function updatePackageJson(
): void {
let packageJson: PackageJson;
if (fileMap == null) {
fileMap = readProjectFileMapCache()?.projectFileMap || {};
fileMap = readFileMapCache()?.fileMap?.projectFileMap || {};
}

if (options.updateBuildableProjectDepsInPackageJson) {
Expand Down
32 changes: 28 additions & 4 deletions packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@ import { NxJsonConfiguration } from './nx-json';
/**
* Some metadata about a file
*/
export interface FileData {
export interface BaseFileData {
file: string;
hash: string;
deps?: (string | [string, string])[];
}

/**
* Represents metadata about a file that belongs to a project.
*/
export interface ProjectFileData extends BaseFileData {
/**
* An array of dependencies. If an element is just a string,
* the dependency is assumed to be a static dependency targetting
* that string. If the element is a tuple, the first element inside of it
* is the target project, with the second element being the type of dependency.
*/
deps?: (string | [target: string, type: string])[];
}

/**
* Represents metadata about a file that **does not** belong to a project.
*/
export interface NonProjectFileData extends BaseFileData {
/**
* Dependencies which were created with this file as the source file.
*/
deps?: ProjectGraphDependency[];
}

export type FileData = ProjectFileData | NonProjectFileData;

export function fileDataDepTarget(dep: string | [string, string]) {
return typeof dep === 'string' ? dep : dep[0];
}
Expand All @@ -23,15 +47,15 @@ export function fileDataDepType(dep: string | [string, string]) {
}

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

/**
* A list of files separated by the project they belong to
*/
export interface ProjectFileMap {
[projectName: string]: FileData[];
[projectName: string]: ProjectFileData[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function processFilesAndCreateAndSerializeProjectGraph() {
}
}

function copyFileData(d: FileData[]) {
function copyFileData<T extends FileData>(d: T[]) {
return d.map((t) => ({ ...t }));
}

Expand Down
3 changes: 3 additions & 0 deletions packages/nx/src/devkit-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export {
export type {
ProjectFileMap,
FileData,
ProjectFileData,
BaseFileData,
NonProjectFileData,
ProjectGraph,
ProjectGraphDependency,
ProjectGraphNode,
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/project-graph/build-project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { performance } from 'perf_hooks';
import { assertWorkspaceValidity } from '../utils/assert-workspace-validity';
import { FileData } from './file-utils';
import {
CachedFileData,
createProjectFileMapCache,
extractCachedFileData,
FileMapCache,
Expand Down Expand Up @@ -155,7 +156,7 @@ async function buildProjectGraphUsingContext(
nxJson: NxJsonConfiguration,
knownExternalNodes: Record<string, ProjectGraphExternalNode>,
ctx: CreateDependenciesContext,
cachedFileData: { [project: string]: { [file: string]: FileData } },
cachedFileData: CachedFileData,
projectGraphVersion: string
) {
performance.mark('build project graph:start');
Expand Down
Loading

0 comments on commit 3c24412

Please sign in to comment.