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

fix(core): add cargo and gradle to external graph node type #29610

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/generated/devkit/ProjectGraphExternalNode.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ while allowing tracking of the full tree of different nested versions
### Properties

- [data](../../devkit/documents/ProjectGraphExternalNode#data): Object
- [name](../../devkit/documents/ProjectGraphExternalNode#name): `npm:${string}`
- [type](../../devkit/documents/ProjectGraphExternalNode#type): "npm"
- [name](../../devkit/documents/ProjectGraphExternalNode#name): string
- [type](../../devkit/documents/ProjectGraphExternalNode#type): string

## Properties

Expand All @@ -35,10 +35,10 @@ while allowing tracking of the full tree of different nested versions

### name

• **name**: \`npm:$\{string}\`
• **name**: `string`

---

### type

• **type**: `"npm"`
• **type**: `string`
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
matchImportWithWildcard,
stringifyTags,
} from '../utils/runtime-lint-utils';
import { isProjectGraphProjectNode } from 'nx/src/config/project-graph';

type Options = [
{
Expand Down Expand Up @@ -525,6 +526,11 @@ export default ESLintUtils.RuleCreator(
return;
}

if (!isProjectGraphProjectNode(targetProject)) {
return;
}
targetProject = targetProject as ProjectGraphProjectNode;

// check constraints between libs and apps
// check for circular dependency
const circularPath = checkCircularPath(
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/utils/buildable-libs-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('updatePaths', () => {
const deps: DependentBuildableProjectNode[] = [
{
name: '@proj/lib',
node: { data: { root: 'libs/lib' } } as any,
node: { type: 'lib', data: { root: 'libs/lib' } } as any,
outputs: ['dist/libs/lib'],
},
];
Expand Down
104 changes: 54 additions & 50 deletions packages/js/src/utils/buildable-libs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
parseTargetString,
readJsonFile,
stripIndents,
workspaceRoot,
writeJsonFile,
} from '@nx/devkit';
import { unlinkSync } from 'fs';
Expand All @@ -19,6 +18,10 @@ import { output } from 'nx/src/utils/output';
import { dirname, join, relative, extname, resolve } from 'path';
import type * as ts from 'typescript';
import { readTsConfigPaths } from './typescript/ts-config';
import {
isProjectGraphExternalNode,
isProjectGraphProjectNode,
} from 'nx/src/config/project-graph';

function isBuildable(target: string, node: ProjectGraphProjectNode): boolean {
return (
Expand Down Expand Up @@ -111,7 +114,7 @@ export function calculateProjectDependencies(
.map(({ name: dep, isTopLevel }) => {
let project: DependentBuildableProjectNode = null;
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
if (depNode.type === 'lib') {
if (isProjectGraphProjectNode(depNode) && depNode.type === 'lib') {
if (isBuildable(targetName, depNode)) {
const libPackageJsonPath = join(
root,
Expand All @@ -137,7 +140,7 @@ export function calculateProjectDependencies(
} else {
nonBuildableDependencies.push(dep);
}
} else if (depNode.type === 'npm') {
} else if (isProjectGraphExternalNode(depNode)) {
project = {
name: depNode.data.packageName,
outputs: [],
Expand Down Expand Up @@ -529,54 +532,52 @@ export function updatePaths(
) {
const pathsKeys = Object.keys(paths);
// For each registered dependency
dependencies.forEach((dep) => {
if (dep.node.type === 'npm') {
return;
}

// If there are outputs
if (dep.outputs && dep.outputs.length > 0) {
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
paths[dep.name] = dep.outputs;

// check for secondary entrypoints
// For each registered path
for (const path of pathsKeys) {
const nestedName = `${dep.name}/`;

// If the path points to the current dependency and is nested (/)
if (path.startsWith(nestedName)) {
const nestedPart = path.slice(nestedName.length);

// Bind potential secondary endpoints for ng-packagr projects
let mappedPaths = dep.outputs.map(
(output) => `${output}/${nestedPart}`
);

const { root } = dep.node.data;
// Update nested mappings to point to the dependency's output paths
mappedPaths = mappedPaths.concat(
paths[path].flatMap((p) =>
dep.outputs.flatMap((output) => {
const basePath = p.replace(root, output);
return [
// extension-less path to support compiled output
basePath.replace(
new RegExp(`${extname(basePath)}$`, 'gi'),
''
),
// original path with the root re-mapped to the output path
basePath,
];
})
)
);

paths[path] = mappedPaths;
dependencies
.filter((dep) => isProjectGraphProjectNode(dep.node))
.forEach((dep) => {
// If there are outputs
if (dep.outputs && dep.outputs.length > 0) {
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
paths[dep.name] = dep.outputs;

// check for secondary entrypoints
// For each registered path
for (const path of pathsKeys) {
const nestedName = `${dep.name}/`;

// If the path points to the current dependency and is nested (/)
if (path.startsWith(nestedName)) {
const nestedPart = path.slice(nestedName.length);

// Bind potential secondary endpoints for ng-packagr projects
let mappedPaths = dep.outputs.map(
(output) => `${output}/${nestedPart}`
);

const { root } = (dep.node as ProjectGraphProjectNode).data;
// Update nested mappings to point to the dependency's output paths
mappedPaths = mappedPaths.concat(
paths[path].flatMap((p) =>
dep.outputs.flatMap((output) => {
const basePath = p.replace(root, output);
return [
// extension-less path to support compiled output
basePath.replace(
new RegExp(`${extname(basePath)}$`, 'gi'),
''
),
// original path with the root re-mapped to the output path
basePath,
];
})
)
);

paths[path] = mappedPaths;
}
}
}
}
});
});
}

/**
Expand Down Expand Up @@ -629,7 +630,10 @@ export function updateBuildableProjectPackageJsonDependencies(
) {
try {
let depVersion;
if (entry.node.type === 'lib') {
if (
isProjectGraphProjectNode(entry.node) &&
entry.node.type === 'lib'
) {
const outputs = getOutputsForTargetAndConfiguration(
{
project: projectName,
Expand Down
16 changes: 14 additions & 2 deletions packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export interface ProjectGraphProjectNode {
};
}

export function isProjectGraphProjectNode(
node: ProjectGraphProjectNode | ProjectGraphExternalNode
): node is ProjectGraphProjectNode {
return node.type === 'app' || node.type === 'e2e' || node.type === 'lib';
}

/**
* A node describing an external dependency
* `name` has as form of:
Expand All @@ -114,15 +120,21 @@ export interface ProjectGraphProjectNode {
*
*/
export interface ProjectGraphExternalNode {
type: 'npm';
name: `npm:${string}`;
type: string; // not app, e2e, or lib
name: string;
data: {
version: string;
packageName: string;
hash?: string;
};
}

export function isProjectGraphExternalNode(
node: ProjectGraphProjectNode | ProjectGraphExternalNode
): node is ProjectGraphExternalNode {
return isProjectGraphProjectNode(node) === false;
}

/**
* A dependency between two projects
*/
Expand Down
Loading