Skip to content

Commit 4f23692

Browse files
JamesHenryFrozenPandaz
authored andcommitted
chore(core): refactor executors to always read from cached project graph (#6446)
1 parent 749c640 commit 4f23692

File tree

14 files changed

+47
-63
lines changed

14 files changed

+47
-63
lines changed

packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@nrwl/workspace/src/utils/buildable-libs-utils';
1414
import { joinPathFragments } from '@nrwl/devkit';
1515
import { join } from 'path';
16-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
16+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
1717
import { Schema } from '@angular-devkit/build-angular/src/browser/schema';
1818
import { switchMap } from 'rxjs/operators';
1919
import { existsSync } from 'fs';
@@ -80,32 +80,26 @@ function run(
8080
options: BrowserBuilderSchema,
8181
context: BuilderContext
8282
): Observable<BuilderOutput> {
83-
return from(createProjectGraphAsync()).pipe(
84-
switchMap((projGraph) => {
85-
const { target, dependencies } = calculateProjectDependencies(
86-
projGraph,
87-
context
88-
);
83+
const { target, dependencies } = calculateProjectDependencies(
84+
readCachedProjectGraph(),
85+
context
86+
);
8987

90-
options.tsConfig = createTmpTsConfig(
91-
join(context.workspaceRoot, options.tsConfig),
92-
context.workspaceRoot,
93-
target.data.root,
94-
dependencies
95-
);
88+
options.tsConfig = createTmpTsConfig(
89+
join(context.workspaceRoot, options.tsConfig),
90+
context.workspaceRoot,
91+
target.data.root,
92+
dependencies
93+
);
9694

97-
return of(
98-
checkDependentProjectsHaveBeenBuilt(context, dependencies)
99-
).pipe(
100-
switchMap((result) => {
101-
if (result) {
102-
return buildApp(options, context);
103-
} else {
104-
// just pass on the result
105-
return of({ success: false });
106-
}
107-
})
108-
);
95+
return of(checkDependentProjectsHaveBeenBuilt(context, dependencies)).pipe(
96+
switchMap((result) => {
97+
if (result) {
98+
return buildApp(options, context);
99+
} else {
100+
// just pass on the result
101+
return of({ success: false });
102+
}
109103
})
110104
);
111105
}

packages/angular/src/executors/delegate-build/delegate-build.impl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
parseTargetString,
55
runExecutor,
66
} from '@nrwl/devkit';
7-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
7+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
88
import {
99
calculateProjectDependencies,
1010
checkDependentProjectsHaveBeenBuilt,
@@ -16,10 +16,8 @@ export async function* delegateBuildExecutor(
1616
options: DelegateBuildExecutorSchema,
1717
context: ExecutorContext
1818
) {
19-
const projGraph = await createProjectGraphAsync();
20-
2119
const { target, dependencies } = calculateProjectDependencies(
22-
projGraph,
20+
readCachedProjectGraph(),
2321
context.root,
2422
context.projectName,
2523
context.targetName,

packages/angular/src/executors/package/package.impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ng from '@angular/compiler-cli';
22
import type { ExecutorContext } from '@nrwl/devkit';
3-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
3+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
44
import type { DependentBuildableProjectNode } from '@nrwl/workspace/src/utilities/buildable-libs-utils';
55
import {
66
calculateProjectDependencies,
@@ -50,9 +50,8 @@ export function createLibraryExecutor(
5050
options: BuildAngularLibraryExecutorOptions,
5151
context: ExecutorContext
5252
) {
53-
const projGraph = await createProjectGraphAsync();
5453
const { target, dependencies } = calculateProjectDependencies(
55-
projGraph,
54+
readCachedProjectGraph(),
5655
context.root,
5756
context.projectName,
5857
context.targetName,

packages/next/src/executors/build/build.impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { NextBuildBuilderOptions } from '../../utils/types';
1111
import { createPackageJson } from './lib/create-package-json';
1212
import { createNextConfigFile } from './lib/create-next-config-file';
1313
import { directoryExists } from '@nrwl/workspace/src/utilities/fileutils';
14-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
14+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
1515
import {
1616
calculateProjectDependencies,
1717
DependentBuildableProjectNode,
@@ -32,9 +32,8 @@ export default async function buildExecutor(
3232
const root = resolve(context.root, options.root);
3333

3434
if (!options.buildLibsFromSource && context.targetName) {
35-
const projGraph = await createProjectGraphAsync();
3635
const result = calculateProjectDependencies(
37-
projGraph,
36+
readCachedProjectGraph(),
3837
context.root,
3938
context.projectName,
4039
context.targetName,

packages/next/src/executors/build/lib/create-package-json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutorContext } from '@nrwl/devkit';
22

3-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
3+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
44
import { writeJsonFile } from '@nrwl/workspace/src/utilities/fileutils';
55
import { createPackageJson as generatePackageJson } from '@nrwl/workspace/src/utilities/create-package-json';
66

@@ -10,7 +10,7 @@ export async function createPackageJson(
1010
options: NextBuildBuilderOptions,
1111
context: ExecutorContext
1212
) {
13-
const depGraph = await createProjectGraphAsync();
13+
const depGraph = readCachedProjectGraph();
1414
const packageJson = generatePackageJson(context.projectName, depGraph, {
1515
root: context.root,
1616
projectRoot: context.workspace.projects[context.projectName].sourceRoot,

packages/next/src/executors/export/export.impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
NextBuildBuilderOptions,
1313
NextExportBuilderOptions,
1414
} from '../../utils/types';
15-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
15+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
1616
import {
1717
calculateProjectDependencies,
1818
DependentBuildableProjectNode,
@@ -29,9 +29,8 @@ export default async function exportExecutor(
2929
) {
3030
let dependencies: DependentBuildableProjectNode[] = [];
3131
if (!options.buildLibsFromSource) {
32-
const projGraph = await createProjectGraphAsync();
3332
const result = calculateProjectDependencies(
34-
projGraph,
33+
readCachedProjectGraph(),
3534
context.root,
3635
context.projectName,
3736
'build', // this should be generalized

packages/next/src/executors/server/server.impl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from '../../utils/types';
2424
import { customServer } from './lib/custom-server';
2525
import { defaultServer } from './lib/default-server';
26-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
26+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
2727
import {
2828
calculateProjectDependencies,
2929
DependentBuildableProjectNode,
@@ -56,9 +56,8 @@ export default async function* serveExecutor(
5656

5757
const root = resolve(context.root, buildOptions.root);
5858
if (!options.buildLibsFromSource) {
59-
const projGraph = await createProjectGraphAsync();
6059
const result = calculateProjectDependencies(
61-
projGraph,
60+
readCachedProjectGraph(),
6261
context.root,
6362
context.projectName,
6463
'build', // should be generalized

packages/node/src/executors/build/build.impl.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('Node Build Executor', () => {
1717

1818
beforeEach(async () => {
1919
jest
20-
.spyOn(projectGraph, 'createProjectGraphAsync')
21-
.mockReturnValue(Promise.resolve({} as ProjectGraph));
20+
.spyOn(projectGraph, 'readCachedProjectGraph')
21+
.mockReturnValue({} as ProjectGraph);
2222

2323
(<any>runWebpack).mockReturnValue(of({ hasErrors: () => false }));
2424
context = {

packages/node/src/executors/build/build.impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExecutorContext } from '@nrwl/devkit';
22

3-
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
3+
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
44
import {
55
calculateProjectDependencies,
66
checkDependentProjectsHaveBeenBuilt,
@@ -48,7 +48,7 @@ export async function* buildExecutor(
4848
sourceRoot,
4949
root
5050
);
51-
const projGraph = await createProjectGraphAsync();
51+
const projGraph = readCachedProjectGraph();
5252
if (!options.buildLibsFromSource) {
5353
const { target, dependencies } = calculateProjectDependencies(
5454
projGraph,

packages/node/src/executors/package/package.impl.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe('NodePackageBuilder', () => {
8989
describe('Without library dependencies', () => {
9090
beforeEach(() => {
9191
jest
92-
.spyOn(projectGraph, 'createProjectGraphAsync')
93-
.mockImplementation(async () => {
92+
.spyOn(projectGraph, 'readCachedProjectGraph')
93+
.mockImplementation(() => {
9494
return {
9595
nodes: {
9696
nodelib: {
@@ -263,8 +263,8 @@ describe('NodePackageBuilder', () => {
263263
beforeEach(() => {
264264
// fake that dep project has been built
265265
jest
266-
.spyOn(projectGraph, 'createProjectGraphAsync')
267-
.mockImplementation(async () => {
266+
.spyOn(projectGraph, 'readCachedProjectGraph')
267+
.mockImplementation(() => {
268268
return {
269269
nodes: {
270270
nodelib: {

0 commit comments

Comments
 (0)