Skip to content

Commit 94addb4

Browse files
authored
Merge pull request #5 from Anxhul10/feat/affected-pkg
feat: add affected pkg fn from `dag-rs`
2 parents 2e2c828 + 0a52fff commit 94addb4

File tree

8 files changed

+200
-28
lines changed

8 files changed

+200
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# dag
2-
31
## 0.2.1
42

3+
## 0.3.0
4+
5+
### Minor Changes
6+
7+
- add getAffectedPkg function which return the dependents including direct, transitive and circular dependency
8+
59
### Patch Changes
610

711
- docs: fix import dag

README.md

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,148 @@ yarn add dag-rs
1212
```
1313

1414
## Usage
15+
16+
### CommonJS
1517
```
16-
import dag from 'dag-rs';
18+
const { dag, getAffectedPkg } = require('dag-rs');
1719
1820
for (const obj of dag()) {
1921
console.log(obj);
2022
}
23+
24+
for (const obj of getAffectedPkg("@rocket.chat/fuselage")) {
25+
console.log(obj);
26+
}
2127
```
2228

23-
## Example Output `(dependent → dependency)`:
29+
### ESM
30+
```
31+
import { dag, getAffectedPkg } from 'dag-rs';
32+
33+
for (const obj of dag()) {
34+
console.log(obj);
35+
}
36+
37+
for (const obj of getAffectedPkg("@rocket.chat/fuselage")) {
38+
console.log(obj);
39+
}
40+
```
41+
42+
## Example Output :
43+
### getAffectedPkg("@rocket.chat/fuselage") → returns all the direct , transitive , circular dependency
44+
```
45+
// dependents of @rocket.chat/fuselage package
46+
47+
@rocket.chat/layout
48+
@rocket.chat/fuselage-toastbar
49+
@rocket.chat/fuselage-forms
50+
@rocket.chat/onboarding-ui
51+
2452
```
25-
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage' }
26-
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage-hooks' }
27-
{ '@rocket.chat/onboarding-ui': '@rocket.chat/icons' }
28-
{ '@rocket.chat/onboarding-ui': '@rocket.chat/layout' }
2953

54+
## Example Output:
55+
### dag() → returns all packages in the project
56+
57+
```
58+
// dependent : dependency
59+
60+
{ '@rocket.chat/fuselage-monorepo': '@rocket.chat/prettier-config' }
61+
{ '@rocket.chat/fuselage-monorepo': 'update-readme' }
62+
{ '@rocket.chat/css-in-js': '@rocket.chat/css-supports' }
63+
{ '@rocket.chat/css-in-js': '@rocket.chat/memo' }
64+
{
65+
'@rocket.chat/css-in-js': '@rocket.chat/stylis-logical-props-middleware'
66+
}
67+
{ '@rocket.chat/css-in-js': 'lint-all' }
68+
{ '@rocket.chat/css-supports': '@rocket.chat/memo' }
69+
{ '@rocket.chat/css-supports': 'lint-all' }
70+
{ '@rocket.chat/emitter': 'lint-all' }
71+
{ '@rocket.chat/fuselage': '@rocket.chat/css-in-js' }
72+
{ '@rocket.chat/fuselage': '@rocket.chat/css-supports' }
73+
{ '@rocket.chat/fuselage': '@rocket.chat/fuselage-tokens' }
74+
{ '@rocket.chat/fuselage': '@rocket.chat/memo' }
75+
{ '@rocket.chat/fuselage': '@rocket.chat/styled' }
76+
{ '@rocket.chat/fuselage': '@rocket.chat/fuselage-hooks' }
77+
{ '@rocket.chat/fuselage': '@rocket.chat/icons' }
78+
{ '@rocket.chat/fuselage': '@rocket.chat/fuselage-hooks' }
79+
{ '@rocket.chat/fuselage': '@rocket.chat/icons' }
80+
{ '@rocket.chat/fuselage': '@rocket.chat/storybook-dark-mode' }
3081
{ '@rocket.chat/fuselage': 'lint-all' }
3182
{ '@rocket.chat/fuselage': 'testing-utils' }
32-
3383
{ '@rocket.chat/fuselage-forms': '@rocket.chat/emitter' }
3484
{ '@rocket.chat/fuselage-forms': '@rocket.chat/fuselage' }
3585
{ '@rocket.chat/fuselage-forms': '@rocket.chat/fuselage-hooks' }
86+
{ '@rocket.chat/fuselage-forms': '@rocket.chat/fuselage' }
3687
{ '@rocket.chat/fuselage-forms': '@rocket.chat/fuselage-tokens' }
88+
{ '@rocket.chat/fuselage-forms': '@rocket.chat/storybook-dark-mode' }
3789
{ '@rocket.chat/fuselage-forms': 'lint-all' }
90+
{ '@rocket.chat/fuselage-hooks': '@rocket.chat/emitter' }
91+
{ '@rocket.chat/fuselage-hooks': '@rocket.chat/fuselage-tokens' }
92+
{ '@rocket.chat/fuselage-hooks': '@rocket.chat/emitter' }
93+
{ '@rocket.chat/fuselage-hooks': '@rocket.chat/fuselage-tokens' }
94+
{ '@rocket.chat/fuselage-hooks': 'lint-all' }
95+
{ '@rocket.chat/fuselage-hooks': 'testing-utils' }
96+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/fuselage' }
97+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/fuselage-hooks' }
98+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/styled' }
99+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/fuselage' }
100+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/fuselage-hooks' }
101+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/fuselage-tokens' }
102+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/layout' }
103+
{
104+
'@rocket.chat/fuselage-toastbar': '@rocket.chat/storybook-dark-mode'
105+
}
106+
{ '@rocket.chat/fuselage-toastbar': '@rocket.chat/styled' }
107+
{ '@rocket.chat/fuselage-toastbar': 'lint-all' }
108+
{ '@rocket.chat/fuselage-tokens': 'build-design-tokens' }
109+
{ '@rocket.chat/fuselage-tokens': 'lint-all' }
110+
{ '@rocket.chat/icons': 'build-icons' }
111+
{ '@rocket.chat/icons': 'lint-all' }
112+
{ '@rocket.chat/layout': '@rocket.chat/fuselage' }
113+
{ '@rocket.chat/layout': '@rocket.chat/fuselage' }
114+
{ '@rocket.chat/layout': '@rocket.chat/fuselage-tokens' }
115+
{ '@rocket.chat/layout': '@rocket.chat/storybook-dark-mode' }
116+
{ '@rocket.chat/layout': 'lint-all' }
117+
{ '@rocket.chat/logo': '@rocket.chat/fuselage-hooks' }
118+
{ '@rocket.chat/logo': '@rocket.chat/styled' }
119+
{ '@rocket.chat/logo': '@rocket.chat/fuselage-tokens' }
120+
{ '@rocket.chat/logo': 'build-logo' }
121+
{ '@rocket.chat/logo': 'lint-all' }
122+
{ '@rocket.chat/memo': 'lint-all' }
123+
{ '@rocket.chat/mp3-encoder': 'lint-all' }
124+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage' }
125+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage-hooks' }
126+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/icons' }
127+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/layout' }
128+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/logo' }
129+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/styled' }
130+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage' }
131+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage-hooks' }
132+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/fuselage-tokens' }
133+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/icons' }
134+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/layout' }
135+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/logo' }
136+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/storybook-dark-mode' }
137+
{ '@rocket.chat/onboarding-ui': '@rocket.chat/styled' }
138+
{ '@rocket.chat/onboarding-ui': 'lint-all' }
139+
{ '@rocket.chat/prettier-config': 'lint-all' }
140+
{ '@rocket.chat/storybook-dark-mode': 'lint-all' }
141+
{ '@rocket.chat/string-helpers': 'lint-all' }
142+
{ '@rocket.chat/styled': '@rocket.chat/css-in-js' }
143+
{ '@rocket.chat/styled': 'lint-all' }
144+
{
145+
'@rocket.chat/stylis-logical-props-middleware': '@rocket.chat/css-supports'
146+
}
147+
{ '@rocket.chat/stylis-logical-props-middleware': 'lint-all' }
148+
{ 'build-design-tokens': 'tools-utils' }
149+
{ 'build-design-tokens': 'lint-all' }
150+
{ 'build-icons': 'tools-utils' }
151+
{ 'build-icons': 'lint-all' }
152+
{ 'build-logo': 'lint-all' }
153+
{ 'build-logo': 'tools-utils' }
154+
{ 'testing-utils': 'lint-all' }
155+
{ 'tools-utils': 'lint-all' }
156+
{ 'update-readme': 'lint-all' }
38157
```
39158

40159
## Building dag-rs
@@ -50,19 +169,6 @@ $ yarn build
50169

51170
## Project Layout
52171

53-
The directory structure of this project is:
54-
55-
```
56-
dag/
57-
├── Cargo.toml
58-
├── README.md
59-
├── src/
60-
| └── lib.rs
61-
├── index.node
62-
├── package.json
63-
└── target/
64-
```
65-
66172
| Entry | Purpose |
67173
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
68174
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
@@ -73,4 +179,5 @@ dag/
73179
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
74180
| `target/` | Binary artifacts generated by the Rust build. |
75181

76-
182+
## Contribution
183+
All forms of contribution are welcome!

index.node

37.3 KB
Binary file not shown.

lib/index.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const native = require('../index.node');
2+
3+
module.exports = {
4+
dag: native.dag,
5+
getAffectedPkg: native.getAffectedPkg
6+
};

lib/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/index.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cjs from './index.cjs';
2+
3+
export const dag = cjs.dag;
4+
export const getAffectedPkg = cjs.getAffectedPkg;
5+
6+
export default cjs;

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dag-rs",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "",
55
"main": "lib/index.js",
66
"publishConfig": {
@@ -10,6 +10,12 @@
1010
"lib",
1111
"*.node"
1212
],
13+
"exports": {
14+
".": {
15+
"require": "./lib/index.cjs",
16+
"import": "./lib/index.mjs"
17+
}
18+
},
1319
"scripts": {
1420
"test": "cargo test",
1521
"cargo-build": "cargo build --message-format=json-render-diagnostics > cargo.log",

src/lib.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod find_pkg_json;
22
mod utils;
33
use neon::prelude::*;
4-
4+
use std::collections::HashSet;
55
use serde_json::Value;
66

77
fn get_pkg_name(path: String) -> String {
@@ -48,6 +48,52 @@ fn get_dependents(path: &str, pkg_names: &[String]) -> Vec<(String, String)>{
4848
graph
4949
}
5050

51+
fn get_dependents_recursively(pkg_name: String, res: Vec<(String, String)>, duplicate_dependents:&mut Vec<String>) {
52+
for (_i, (dependent, dependency)) in res.clone().into_iter().enumerate() {
53+
if dependency == pkg_name {
54+
duplicate_dependents.push(dependent.clone());
55+
get_dependents_recursively(dependent.clone(), res.clone(),duplicate_dependents);
56+
}
57+
}
58+
return;
59+
}
60+
61+
#[neon::export]
62+
fn get_affected_pkg<'a>(cx: &mut FunctionContext<'a>, pkg_name: String) -> JsResult<'a, JsArray>{
63+
let filter = vec![".yarn", "node_modules"];
64+
let paths = find_pkg_json::find_pkg_json(filter);
65+
let mut res: Vec<(String, String)> = Vec::new();
66+
let mut pkg_names = Vec::new();
67+
let mut unique_dependents = HashSet::<String>::new();
68+
let mut duplicate_dependents = Vec::new();
69+
let mut dependents = Vec::new();
70+
let dependents_js = JsArray::new(cx, 0);
71+
72+
for path in paths.clone() {
73+
pkg_names.push(get_pkg_name(path.clone()));
74+
}
75+
76+
for path in paths.clone() {
77+
let mut r = get_dependents(&path, &pkg_names);
78+
res.append(&mut r);
79+
}
80+
81+
get_dependents_recursively(pkg_name, res,&mut duplicate_dependents);
82+
83+
for pkg in duplicate_dependents {
84+
unique_dependents.insert(pkg);
85+
}
86+
for pkg in unique_dependents.clone() {
87+
dependents.push(pkg);
88+
}
89+
90+
for (i, s) in unique_dependents.iter().enumerate() {
91+
let v = cx.string(s);
92+
dependents_js.set(cx, i as u32, v)?;
93+
}
94+
Ok(dependents_js)
95+
}
96+
5197
#[neon::export]
5298
fn dag<'a>(cx: &mut FunctionContext<'a>) -> JsResult<'a, JsArray> {
5399
let js_array = JsArray::new(cx, 0);

0 commit comments

Comments
 (0)