From 02db6be82497bcd71470871cd47661458d764b76 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Fri, 1 Dec 2023 10:06:49 +0100 Subject: [PATCH] fix: works with npm/yarn/pnpm link Right now we use __dirname to find parent root project. But this wont work in a link situation where __dirname will point to the real folder of the plugin. Now we use `process.cwd()` which will work in whatever folder we are inside the project (which is what we want). plus it will be much faster as most of the time `process.cwd()` will already be the app root folder --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6cccf7e..5934e29 100644 --- a/index.js +++ b/index.js @@ -29,11 +29,10 @@ function findProjectDir(pkgdir) { return process.env.INIT_CWD; } - var candidateDir = pkgdir; + var candidateDir = process.cwd(); var oldCandidateDir = null; while (true) { - candidateDir = path.dirname(candidateDir); if (oldCandidateDir === candidateDir) { return; } @@ -47,6 +46,7 @@ function findProjectDir(pkgdir) { } oldCandidateDir = candidateDir; + candidateDir = path.dirname(candidateDir); } }