Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): refactor executors to always read from cached project graph #6446

Merged
merged 1 commit into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,7 +13,7 @@ import {
} from '@nrwl/workspace/src/utils/buildable-libs-utils';
import { joinPathFragments } from '@nrwl/devkit';
import { join } from 'path';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { Schema } from '@angular-devkit/build-angular/src/browser/schema';
import { switchMap } from 'rxjs/operators';
import { existsSync } from 'fs';
Expand Down Expand Up @@ -80,32 +80,26 @@ function run(
options: BrowserBuilderSchema,
context: BuilderContext
): Observable<BuilderOutput> {
return from(createProjectGraphAsync()).pipe(
switchMap((projGraph) => {
const { target, dependencies } = calculateProjectDependencies(
projGraph,
context
);
const { target, dependencies } = calculateProjectDependencies(
readCachedProjectGraph(),
context
);

options.tsConfig = createTmpTsConfig(
join(context.workspaceRoot, options.tsConfig),
context.workspaceRoot,
target.data.root,
dependencies
);
options.tsConfig = createTmpTsConfig(
join(context.workspaceRoot, options.tsConfig),
context.workspaceRoot,
target.data.root,
dependencies
);

return of(
checkDependentProjectsHaveBeenBuilt(context, dependencies)
).pipe(
switchMap((result) => {
if (result) {
return buildApp(options, context);
} else {
// just pass on the result
return of({ success: false });
}
})
);
return of(checkDependentProjectsHaveBeenBuilt(context, dependencies)).pipe(
switchMap((result) => {
if (result) {
return buildApp(options, context);
} else {
// just pass on the result
return of({ success: false });
}
})
);
}
Expand Down
Expand Up @@ -4,7 +4,7 @@ import {
parseTargetString,
runExecutor,
} from '@nrwl/devkit';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
Expand All @@ -16,10 +16,8 @@ export async function* delegateBuildExecutor(
options: DelegateBuildExecutorSchema,
context: ExecutorContext
) {
const projGraph = await createProjectGraphAsync();

const { target, dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down
5 changes: 2 additions & 3 deletions packages/angular/src/executors/package/package.impl.ts
@@ -1,6 +1,6 @@
import * as ng from '@angular/compiler-cli';
import type { ExecutorContext } from '@nrwl/devkit';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import type { DependentBuildableProjectNode } from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import {
calculateProjectDependencies,
Expand Down Expand Up @@ -50,9 +50,8 @@ export function createLibraryExecutor(
options: BuildAngularLibraryExecutorOptions,
context: ExecutorContext
) {
const projGraph = await createProjectGraphAsync();
const { target, dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/executors/build/build.impl.ts
Expand Up @@ -11,7 +11,7 @@ import { NextBuildBuilderOptions } from '../../utils/types';
import { createPackageJson } from './lib/create-package-json';
import { createNextConfigFile } from './lib/create-next-config-file';
import { directoryExists } from '@nrwl/workspace/src/utilities/fileutils';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
DependentBuildableProjectNode,
Expand All @@ -32,9 +32,8 @@ export default async function buildExecutor(
const root = resolve(context.root, options.root);

if (!options.buildLibsFromSource && context.targetName) {
const projGraph = await createProjectGraphAsync();
const result = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down
@@ -1,6 +1,6 @@
import { ExecutorContext } from '@nrwl/devkit';

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

Expand All @@ -10,7 +10,7 @@ export async function createPackageJson(
options: NextBuildBuilderOptions,
context: ExecutorContext
) {
const depGraph = await createProjectGraphAsync();
const depGraph = readCachedProjectGraph();
const packageJson = generatePackageJson(context.projectName, depGraph, {
root: context.root,
projectRoot: context.workspace.projects[context.projectName].sourceRoot,
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/executors/export/export.impl.ts
Expand Up @@ -12,7 +12,7 @@ import {
NextBuildBuilderOptions,
NextExportBuilderOptions,
} from '../../utils/types';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
DependentBuildableProjectNode,
Expand All @@ -29,9 +29,8 @@ export default async function exportExecutor(
) {
let dependencies: DependentBuildableProjectNode[] = [];
if (!options.buildLibsFromSource) {
const projGraph = await createProjectGraphAsync();
const result = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
'build', // this should be generalized
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/executors/server/server.impl.ts
Expand Up @@ -23,7 +23,7 @@ import {
} from '../../utils/types';
import { customServer } from './lib/custom-server';
import { defaultServer } from './lib/default-server';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
DependentBuildableProjectNode,
Expand Down Expand Up @@ -56,9 +56,8 @@ export default async function* serveExecutor(

const root = resolve(context.root, buildOptions.root);
if (!options.buildLibsFromSource) {
const projGraph = await createProjectGraphAsync();
const result = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
'build', // should be generalized
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/executors/build/build.impl.spec.ts
Expand Up @@ -17,8 +17,8 @@ describe('Node Build Executor', () => {

beforeEach(async () => {
jest
.spyOn(projectGraph, 'createProjectGraphAsync')
.mockReturnValue(Promise.resolve({} as ProjectGraph));
.spyOn(projectGraph, 'readCachedProjectGraph')
.mockReturnValue({} as ProjectGraph);

(<any>runWebpack).mockReturnValue(of({ hasErrors: () => false }));
context = {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/executors/build/build.impl.ts
@@ -1,6 +1,6 @@
import { ExecutorContext } from '@nrwl/devkit';

import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function* buildExecutor(
sourceRoot,
root
);
const projGraph = await createProjectGraphAsync();
const projGraph = readCachedProjectGraph();
if (!options.buildLibsFromSource) {
const { target, dependencies } = calculateProjectDependencies(
projGraph,
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/executors/package/package.impl.spec.ts
Expand Up @@ -89,8 +89,8 @@ describe('NodePackageBuilder', () => {
describe('Without library dependencies', () => {
beforeEach(() => {
jest
.spyOn(projectGraph, 'createProjectGraphAsync')
.mockImplementation(async () => {
.spyOn(projectGraph, 'readCachedProjectGraph')
.mockImplementation(() => {
return {
nodes: {
nodelib: {
Expand Down Expand Up @@ -263,8 +263,8 @@ describe('NodePackageBuilder', () => {
beforeEach(() => {
// fake that dep project has been built
jest
.spyOn(projectGraph, 'createProjectGraphAsync')
.mockImplementation(async () => {
.spyOn(projectGraph, 'readCachedProjectGraph')
.mockImplementation(() => {
return {
nodes: {
nodelib: {
Expand Down
5 changes: 2 additions & 3 deletions packages/node/src/executors/package/package.impl.ts
@@ -1,5 +1,5 @@
import { ExecutorContext } from '@nrwl/devkit';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { copyAssetFiles } from '@nrwl/workspace/src/utilities/assets';
import {
calculateProjectDependencies,
Expand All @@ -16,11 +16,10 @@ export async function packageExecutor(
options: NodePackageBuilderOptions,
context: ExecutorContext
) {
const projGraph = await createProjectGraphAsync();
const libRoot = context.workspace.projects[context.projectName].root;
const normalizedOptions = normalizeOptions(options, context, libRoot);
const { target, dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down
5 changes: 2 additions & 3 deletions packages/web/src/executors/build/build.impl.ts
Expand Up @@ -7,7 +7,7 @@ import { execSync } from 'child_process';
import { Range, satisfies } from 'semver';
import { basename, join } from 'path';

import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
Expand Down Expand Up @@ -137,9 +137,8 @@ export async function* run(
const metadata = context.workspace.projects[context.projectName];

if (!options.buildLibsFromSource && context.targetName) {
const projGraph = await createProjectGraphAsync();
const { dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down
5 changes: 2 additions & 3 deletions packages/web/src/executors/dev-server/dev-server.impl.ts
Expand Up @@ -20,7 +20,7 @@ import {
calculateProjectDependencies,
createTmpTsConfig,
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';

export interface WebDevServerOptions {
host: string;
Expand Down Expand Up @@ -67,9 +67,8 @@ export default async function* devServerExecutor(
}

if (!buildOptions.buildLibsFromSource) {
const projGraph = await createProjectGraphAsync();
const { target, dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
'build', // should be generalized
Expand Down
5 changes: 2 additions & 3 deletions packages/web/src/executors/package/package.impl.ts
Expand Up @@ -22,7 +22,7 @@ import { catchError, concatMap, last, tap } from 'rxjs/operators';
import { eachValueFrom } from 'rxjs-for-await';
import * as autoprefixer from 'autoprefixer';

import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
Expand Down Expand Up @@ -58,9 +58,8 @@ export default async function* run(
) {
const project = context.workspace.projects[context.projectName];
const sourceRoot = project.sourceRoot;
const projGraph = await createProjectGraphAsync();
const { target, dependencies } = calculateProjectDependencies(
projGraph,
readCachedProjectGraph(),
context.root,
context.projectName,
context.targetName,
Expand Down