diff --git a/packages/rust/src/graph.ts b/packages/rust/src/graph.ts index 88b5e7e..a673c6b 100644 --- a/packages/rust/src/graph.ts +++ b/packages/rust/src/graph.ts @@ -35,8 +35,10 @@ export const createNodes: CreateNodes = [ }, new Map()); for (const pkg of cargoPackages) { - if (!isExternal(pkg)) { - const root = normalizePath(dirname(relative(ctx.workspaceRoot, pkg.manifest_path))); + if (!isExternal(pkg, ctx.workspaceRoot)) { + const root = normalizePath( + dirname(relative(ctx.workspaceRoot, pkg.manifest_path)) + ); projects[root] = { root, name: pkg.name, @@ -45,7 +47,7 @@ export const createNodes: CreateNodes = [ }; } for (const dep of pkg.dependencies) { - if (isExternal(dep)) { + if (isExternal(dep, ctx.workspaceRoot)) { const externalDepName = `cargo:${dep.name}`; if (!externalNodes?.[externalDepName]) { externalNodes[externalDepName] = { diff --git a/packages/rust/src/utils/cargo.ts b/packages/rust/src/utils/cargo.ts index 0d24c57..d919b8e 100644 --- a/packages/rust/src/utils/cargo.ts +++ b/packages/rust/src/utils/cargo.ts @@ -1,4 +1,5 @@ import chalk from 'chalk'; +import { relative } from 'path'; import { ChildProcess, execSync, spawn, StdioOptions } from 'child_process'; import { runProcess } from './run-process'; import { CargoMetadata, Dependency, Package } from '../models/cargo-metadata'; @@ -75,7 +76,7 @@ export function cargoCommandSync( windowsHide: true, stdio: normalizedOptions.stdio, env: normalizedOptions.env, - maxBuffer: 1024 * 1024 * 10 + maxBuffer: 1024 * 1024 * 10, }), success: true, }; @@ -99,6 +100,15 @@ export function cargoMetadata(): CargoMetadata | null { return JSON.parse(output.output) as CargoMetadata; } -export function isExternal(packageOrDep: Package | Dependency) { - return packageOrDep.source?.startsWith('registry+') ?? false; +export function isExternal( + packageOrDep: Package | Dependency, + workspaceRoot: string +) { + const isRegistry = packageOrDep.source?.startsWith('registry+') ?? false; + const isGit = packageOrDep.source?.startsWith('git+') ?? false; + const isOutsideWorkspace = + 'path' in packageOrDep && + relative(workspaceRoot, packageOrDep.path).startsWith('..'); + + return isRegistry || isGit || isOutsideWorkspace; }