preactjs / next-plugin-preact

Next.js plugin for preact X
396 stars 9 forks source link

#validateDependencies doesn't work well with monorepo environment #42

Open bmstefanski opened 3 years ago

bmstefanski commented 3 years ago

Hi guys, great library, it definitely saved me some time! 👍🏻

I encountered one issue while implementing it to the large mono-repo app: the validateDependencies method does not respect dependencies inheritance. So, if our application has the following structure:

<root>
packages/
  someService/package.json
  someOtherService/package.json
package.json

and both someService and someOtherService inherit the dependencies from the root's package.json. It will exit with process.exit(-1) and display [preact] Missing/incorrect dependencies.. That is because neither of these packages has preact, next-plugin-preact, or any required library in the package.json - it is inherited from the root.

What's troubling me is the result of process.cwd(). It points to packages/someService/, but we run the start command from the root level, so it might be a bad lerna configuration 🤔 .

Anyhow, I managed to fix this by replacing join(process.cwd(), 'package.json') with join(__dirname, '..', '..', 'package.json'); https://github.com/preactjs/next-plugin-preact/blob/9dd2bc845fd2b8c082b08d13d4a0a952c75506b1/packages/next-plugin-preact/index.js#L123