Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

feat: automatically detect workspace roots #28

Merged
merged 1 commit into from
Jan 26, 2022
Merged

Conversation

nlf
Copy link
Contributor

@nlf nlf commented Jan 20, 2022

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

@nlf nlf requested a review from a team as a code owner January 20, 2022 00:20
@nlf nlf force-pushed the nlf/auto-workspace-root branch 2 times, most recently from 2b6bd1e to f884edc Compare January 20, 2022 18:12

// if workspaces are disabled, return now
if (cliWorkspaces === false) {
return
Copy link
Member

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?

Copy link
Member

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.

@ruyadorno
Copy link
Contributor

relates to: npm/rfcs#343

@ruyadorno ruyadorno mentioned this pull request Jan 25, 2022
4 tasks
Comment on lines +551 to +557
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)
Copy link
Contributor

@ruyadorno ruyadorno Jan 25, 2022

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:

ref: https://github.com/npm/cli/blob/latest/workspaces/arborist/lib/arborist/build-ideal-tree.js#L384

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

None yet

3 participants