fix(js): esbuild should not throw when a project depends on non-js dependencies (#19057)
This commit is contained in:
parent
822fb12c3f
commit
ca3fd3cb65
@ -12,20 +12,20 @@ import {
|
|||||||
getOutputsForTargetAndConfiguration,
|
getOutputsForTargetAndConfiguration,
|
||||||
joinPathFragments,
|
joinPathFragments,
|
||||||
ProjectFileMap,
|
ProjectFileMap,
|
||||||
|
ProjectGraph,
|
||||||
|
ProjectGraphExternalNode,
|
||||||
ProjectGraphProjectNode,
|
ProjectGraphProjectNode,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
writeJsonFile,
|
writeJsonFile,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { DependentBuildableProjectNode } from '../buildable-libs-utils';
|
import { DependentBuildableProjectNode } from '../buildable-libs-utils';
|
||||||
import { basename, join, parse, relative } from 'path';
|
import { basename, join, parse } from 'path';
|
||||||
import { writeFileSync } from 'fs-extra';
|
import { writeFileSync } from 'fs-extra';
|
||||||
import { isNpmProject } from 'nx/src/project-graph/operators';
|
|
||||||
import { fileExists } from 'nx/src/utils/fileutils';
|
import { fileExists } from 'nx/src/utils/fileutils';
|
||||||
import type { PackageJson } from 'nx/src/utils/package-json';
|
import type { PackageJson } from 'nx/src/utils/package-json';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { readProjectFileMapCache } from 'nx/src/project-graph/nx-deps-cache';
|
import { readProjectFileMapCache } from 'nx/src/project-graph/nx-deps-cache';
|
||||||
import * as fastGlob from 'fast-glob';
|
|
||||||
|
|
||||||
import { getRelativeDirectoryToProjectRoot } from '../get-main-file-dir';
|
import { getRelativeDirectoryToProjectRoot } from '../get-main-file-dir';
|
||||||
|
|
||||||
@ -117,9 +117,29 @@ export function updatePackageJson(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNpmNode(
|
||||||
|
node: ProjectGraphProjectNode | ProjectGraphExternalNode,
|
||||||
|
graph: ProjectGraph
|
||||||
|
): node is ProjectGraphExternalNode {
|
||||||
|
return !!(graph.externalNodes[node.name]?.type === 'npm');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isWorkspaceProject(
|
||||||
|
node: ProjectGraphProjectNode | ProjectGraphExternalNode,
|
||||||
|
graph: ProjectGraph
|
||||||
|
): node is ProjectGraphProjectNode {
|
||||||
|
return !!graph.nodes[node.name];
|
||||||
|
}
|
||||||
|
|
||||||
function addMissingDependencies(
|
function addMissingDependencies(
|
||||||
packageJson: PackageJson,
|
packageJson: PackageJson,
|
||||||
{ projectName, targetName, configurationName, root }: ExecutorContext,
|
{
|
||||||
|
projectName,
|
||||||
|
targetName,
|
||||||
|
configurationName,
|
||||||
|
root,
|
||||||
|
projectGraph,
|
||||||
|
}: ExecutorContext,
|
||||||
dependencies: DependentBuildableProjectNode[],
|
dependencies: DependentBuildableProjectNode[],
|
||||||
propType: 'dependencies' | 'peerDependencies' = 'dependencies'
|
propType: 'dependencies' | 'peerDependencies' = 'dependencies'
|
||||||
) {
|
) {
|
||||||
@ -127,7 +147,7 @@ function addMissingDependencies(
|
|||||||
joinPathFragments(workspaceRoot, 'package.json')
|
joinPathFragments(workspaceRoot, 'package.json')
|
||||||
);
|
);
|
||||||
dependencies.forEach((entry) => {
|
dependencies.forEach((entry) => {
|
||||||
if (isNpmProject(entry.node)) {
|
if (isNpmNode(entry.node, projectGraph)) {
|
||||||
const { packageName, version } = entry.node.data;
|
const { packageName, version } = entry.node.data;
|
||||||
if (
|
if (
|
||||||
packageJson.dependencies?.[packageName] ||
|
packageJson.dependencies?.[packageName] ||
|
||||||
@ -142,7 +162,7 @@ function addMissingDependencies(
|
|||||||
|
|
||||||
packageJson[propType] ??= {};
|
packageJson[propType] ??= {};
|
||||||
packageJson[propType][packageName] = version;
|
packageJson[propType][packageName] = version;
|
||||||
} else {
|
} else if (isWorkspaceProject(entry.node, projectGraph)) {
|
||||||
const packageName = entry.name;
|
const packageName = entry.name;
|
||||||
if (!!workspacePackageJson.devDependencies?.[packageName]) {
|
if (!!workspacePackageJson.devDependencies?.[packageName]) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user