Skip to content

Commit

Permalink
fix(rust): Consider git and outside local source as external when bui…
Browse files Browse the repository at this point in the history
…lding the graph (#43)
  • Loading branch information
pulasthibandara authored Feb 7, 2024
1 parent e626ead commit dde9153
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/rust/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export const createNodes: CreateNodes = [
}, new Map<string, Package>());

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,
Expand All @@ -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] = {
Expand Down
16 changes: 13 additions & 3 deletions packages/rust/src/utils/cargo.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
};
Expand All @@ -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;
}

0 comments on commit dde9153

Please sign in to comment.