-
Notifications
You must be signed in to change notification settings - Fork 18
feat: automatically detect workspace roots #28
Conversation
2b6bd1e
to
f884edc
Compare
|
||
// if workspaces are disabled, return now | ||
if (cliWorkspaces === false) { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this inside the for loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it's so that we set localPrefix to the very first walkUp we find no matter what, fencepost issue which I'll back away from slowly cause I'm very bad at them.
relates to: npm/rfcs#343 |
f884edc
to
d2e4ad7
Compare
const hasNodeModules = await stat(resolve(p, 'node_modules')) | ||
.then((st) => st.isDirectory()) | ||
.catch(() => false) | ||
|
||
const hasPackageJson = await stat(resolve(p, 'package.json')) | ||
.then((st) => st.isFile()) | ||
.catch(() => false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about handling root links? tbh I'm not sure what the supported usages are but I'm aware that arborist does support some form of root link node:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we use stat
here instead of lstat
we'll resolve symlinks during the lookups and require that the package.json
or node_modules
correctly resolve to a file or directory, respectively. there's no change in behavior there so i think this should be just fine
this changes our behavior so we continue walking up the directory tree after finding what we believe to be a project. from there, if we find a package.json that has a workspace that matches to our previously found localPrefix, then we set our localPrefix to the new root and set the default workspace config to the first prefix we found.
i also added the ability for
--no-workspaces
passed as a cli argument will disable this lookup