Open tehhowch opened 3 years ago
@tehhowch I just hit this same exact issue as well in my monorepo. Were you able to work around this issue? The tasksdir
change that you suggested worked well for me.
FYI, I've opened a PR based on the suggested fix above for discussion https://github.com/gruntjs/grunt/pull/1762
@micellius Since you were the original developer that added this support, do you have any idea's on a potential fix?
@redonkulus nope, never worked around it
When a dependency has been symlinked into a monorepo application, and this dependency is hoisted to the monorepo root, the dependency's
tasks/
folder cannot be located bygrunt.loadNpmTasks
due to an incorrect assumption made when determining the root filepath.The core issue is that the
name
parameter thatloadNpmTasks
is invoked with is not required to be a valid path part due to symlinks. Consider the example directory layout:As a Good Company, scopes are used to guard internal packages from dependency squatting, and thus
neato-task-plugins
is published internally with the@mycorp
scope. Its tasks are loaded from theteam-app-1
package Gruntfile withgrunt.loadNpmTasks('@mycorp/neato-task-plugins');
All is well, until one tries to develop a new corp-wide task and symlinks the task package by running e.g.
yarn link '@mycorp/neato-task-plugins'
from themy-team-monorepo
directory.Now, running the previously working grunt tasks fail with an error logged from here: https://github.com/gruntjs/grunt/blob/ee722d15ed214c824d2925d04afef10f217338c3/lib/grunt/task.js#L412-L417 e.g.
>> Local Npm module "@mycorp/neato-task-plugins" not found. Is it installed?
And caused by the setting of
root
here: https://github.com/gruntjs/grunt/blob/ee722d15ed214c824d2925d04afef10f217338c3/lib/grunt/task.js#L384Where the variables have values like:
However, we even after we fix the calculation of
root
, e.g. by doing something like slicing off 2 (or 3 for scoped packages) path elements, the code still fails to computetasksdir
correctly, looking for/Users/me/dev/corp-utils-monorepo/applications/@mycorp/neato-task-plugins/tasks
instead of/Users/me/dev/corp-utils-monorepo/applications/neato-task-plugins/tasks
.I think the best solution is to use relative paths from the resolved
pkgfile
, rather than attempt to usepath.join
with varied arguments ofroot
,name
, ornode_modules
:I'm not sure what the behavior should be for "collection plugins" that are symlinked, as I'm not familiar with those.