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

yarn support #67

Open
JLarky opened this issue Jan 27, 2023 · 0 comments
Open

yarn support #67

JLarky opened this issue Jan 27, 2023 · 0 comments

Comments

@JLarky
Copy link

JLarky commented Jan 27, 2023

I played with this a bit and there's a way to make this package work with yarn, so if someone wants to work on it, I just want to leave what code I tried:

diff --git a/src/helpers.js b/src/helpers.js
index c157a54..97eabd8 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -59,8 +59,20 @@ let setup = (includeDev) => {
     Adds them with --include-dev
 */
 let getDependencyTree = () => {
-  let result = syncExec(`npm ls --json ${productionModifier}`);
-  return JSON.parse(result.stdout).dependencies;
+  let result = syncExec(`yarn list --json`);
+  const transform = (packages) => {
+    const out = {};
+    packages.forEach((x) => {
+      const names = x.name.split("@");
+      const name = names[0] || "@" + names[1];
+      out[name] = { name };
+      if ("children" in x) {
+        out[name].dependencies = transform(x.children);
+      }
+    });
+    return out;
+  };
+  return transform(JSON.parse(result.stdout).data.trees);
 }; 

p.s. this doesn't work for my project because it has the same issue as in #66
p.p.s. I'm trying out analyze-module-size for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant