-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): create function to transform project graph between js and…
… rust
- Loading branch information
1 parent
a7cf272
commit aed6757
Showing
5 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use napi::bindgen_prelude::Either8; | ||
use napi::Either; | ||
use std::collections::HashMap; | ||
|
||
#[napi(object)] | ||
pub struct ExternalNodeData { | ||
pub version: String, | ||
pub hash: String, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct ExternalNode { | ||
pub version: String, | ||
pub hash: String, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct InputsInput { | ||
pub input: String, | ||
pub dependencies: Option<bool>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct FileSetInput { | ||
pub fileset: String, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct RuntimeInput { | ||
pub runtime: String, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct EnvironmentInput { | ||
pub env: String, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct ExternalDependenciesInput { | ||
pub external_dependencies: Vec<String>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct DepsOutputsInput { | ||
pub dependent_tasks_output_files: String, | ||
pub transitive: Option<bool>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct ProjectsInput { | ||
pub projects: Either<String, Vec<String>>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct Target { | ||
pub executor: String, | ||
pub inputs: Option< | ||
Vec< | ||
Either8< | ||
InputsInput, | ||
String, | ||
FileSetInput, | ||
RuntimeInput, | ||
EnvironmentInput, | ||
ExternalDependenciesInput, | ||
DepsOutputsInput, | ||
ProjectsInput, | ||
>, | ||
>, | ||
>, | ||
pub outputs: Option<Vec<String>>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct Project { | ||
pub root: String, | ||
pub named_inputs: Option< | ||
HashMap< | ||
String, | ||
Vec< | ||
Either8< | ||
InputsInput, | ||
String, | ||
FileSetInput, | ||
RuntimeInput, | ||
EnvironmentInput, | ||
ExternalDependenciesInput, | ||
DepsOutputsInput, | ||
ProjectsInput, | ||
>, | ||
>, | ||
>, | ||
>, | ||
pub targets: HashMap<String, Target>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct ProjectGraph { | ||
pub nodes: HashMap<String, Project>, | ||
pub dependencies: HashMap<String, Vec<String>>, | ||
pub external_nodes: HashMap<String, ExternalNode>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ProjectGraph } from '../config/project-graph'; | ||
import { | ||
ExternalNode, | ||
Project, | ||
Target, | ||
ProjectGraph as RustProjectGraph, | ||
} from './index'; | ||
|
||
export function transformProjectGraphForRust( | ||
graph: ProjectGraph | ||
): RustProjectGraph { | ||
const dependencies: Record<string, string[]> = {}; | ||
const nodes: Record<string, Project> = {}; | ||
const externalNodes: Record<string, ExternalNode> = {}; | ||
for (const [projectName, projectNode] of Object.entries(graph.nodes)) { | ||
const targets: Record<string, Target> = {}; | ||
for (const [targetName, targetConfig] of Object.entries( | ||
projectNode.data.targets | ||
)) { | ||
targets[targetName] = { | ||
executor: targetConfig.executor, | ||
inputs: targetConfig.inputs, | ||
outputs: targetConfig.outputs, | ||
}; | ||
} | ||
nodes[projectName] = { | ||
root: projectNode.data.root, | ||
targets, | ||
}; | ||
if (graph.dependencies[projectName]) { | ||
dependencies[projectName] = []; | ||
for (const dep of graph.dependencies[projectName]) { | ||
dependencies[projectName].push(dep.target); | ||
} | ||
} | ||
} | ||
for (const [projectName, externalNode] of Object.entries( | ||
graph.externalNodes | ||
)) { | ||
externalNodes[projectName] = { | ||
hash: externalNode.data.hash, | ||
version: externalNode.data.version, | ||
}; | ||
if (graph.dependencies[projectName]) { | ||
dependencies[projectName] = []; | ||
for (const dep of graph.dependencies[projectName]) { | ||
dependencies[projectName].push(dep.target); | ||
} | ||
} | ||
} | ||
|
||
return { | ||
nodes, | ||
externalNodes, | ||
dependencies, | ||
}; | ||
} |