From cd81a2061eeaf309d4c05a109429748b968440b8 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 11 Mar 2022 14:43:34 -0500 Subject: [PATCH] fix(react): update package.json only with shallow dependencies (#9297) --- .../web/src/executors/rollup/rollup.impl.ts | 13 ++-------- .../src/utilities/buildable-libs-utils.ts | 26 +++++++++---------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/web/src/executors/rollup/rollup.impl.ts b/packages/web/src/executors/rollup/rollup.impl.ts index c98492157e541..833b5c7009136 100644 --- a/packages/web/src/executors/rollup/rollup.impl.ts +++ b/packages/web/src/executors/rollup/rollup.impl.ts @@ -55,18 +55,9 @@ export default async function* rollupExecutor( context.root, context.projectName, context.targetName, - context.configurationName + context.configurationName, + true ); - if ( - !checkDependentProjectsHaveBeenBuilt( - context.root, - context.projectName, - context.targetName, - dependencies - ) - ) { - throw new Error(); - } const options = normalizeWebRollupOptions( rawOptions, diff --git a/packages/workspace/src/utilities/buildable-libs-utils.ts b/packages/workspace/src/utilities/buildable-libs-utils.ts index 407da3d47f76c..6c01431bfa8f0 100644 --- a/packages/workspace/src/utilities/buildable-libs-utils.ts +++ b/packages/workspace/src/utilities/buildable-libs-utils.ts @@ -1,13 +1,13 @@ import { isNpmProject, ProjectType } from '../core/project-graph'; -import { join, resolve, dirname, relative } from 'path'; +import { dirname, join, relative, resolve } from 'path'; import { directoryExists } from './fileutils'; +import type { ProjectGraph, ProjectGraphProjectNode } from '@nrwl/devkit'; import { - stripIndents, + ProjectGraphExternalNode, readJsonFile, + stripIndents, writeJsonFile, - ProjectGraphExternalNode, } from '@nrwl/devkit'; -import type { ProjectGraph, ProjectGraphProjectNode } from '@nrwl/devkit'; import { getOutputsForTargetAndConfiguration } from '../tasks-runner/utils'; import * as ts from 'typescript'; import { unlinkSync } from 'fs'; @@ -32,7 +32,8 @@ export function calculateProjectDependencies( root: string, projectName: string, targetName: string, - configurationName: string + configurationName: string, + shallow?: boolean ): { target: ProjectGraphProjectNode; dependencies: DependentBuildableProjectNode[]; @@ -41,11 +42,7 @@ export function calculateProjectDependencies( const target = projGraph.nodes[projectName]; // gather the library dependencies const nonBuildableDependencies = []; - const dependencies = recursivelyCollectDependencies( - projectName, - projGraph, - [] - ) + const dependencies = collectDependencies(projectName, projGraph, [], shallow) .map((dep) => { const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep]; if (depNode.type === ProjectType.lib) { @@ -86,15 +83,18 @@ export function calculateProjectDependencies( return { target, dependencies, nonBuildableDependencies }; } -function recursivelyCollectDependencies( +function collectDependencies( project: string, projGraph: ProjectGraph, - acc: string[] + acc: string[], + shallow?: boolean ) { (projGraph.dependencies[project] || []).forEach((dependency) => { if (acc.indexOf(dependency.target) === -1) { acc.push(dependency.target); - recursivelyCollectDependencies(dependency.target, projGraph, acc); + if (!shallow) { + collectDependencies(dependency.target, projGraph, acc); + } } }); return acc;