Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workspaces run at root #175

Closed
wants to merge 1 commit into from
Closed

fix: workspaces run at root #175

wants to merge 1 commit into from

Conversation

reggi
Copy link
Contributor

@reggi reggi commented Oct 9, 2024

I was looking into npm/cli#7563 where npm run -w packages/workspace doesn't work when the cwd is root / (docker issue).

Turns out it's because this returns false here https://github.com/npm/map-workspaces/blob/main/lib/index.js#L128

minimatch('/packages/workspace','packages/workspace', { partial: true, windowsPathsNoEscape: true })

I wish we could catch these. It is not possible to test this kind of code that uses cwd /.

@reggi reggi requested a review from a team as a code owner October 9, 2024 14:13
@wraithgar
Copy link
Member

I wish we could catch these. It is not possible to test this kind of code that uses cwd /.

We don't "support" running out of root, and there are other issues where we've said that the kinds of bugs folks have from doing so won't be fixed. Running from / is a best-effort deal in npm, and it's possible we need better docs explaining this.

* it's not feasible to test the codepath where cwd is root `/`
* tap doesn't support it and an attempt with mock-fs broke nyc
*/
if (sep[0] === '') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will stream the leading slash off all globs, won't it?

@@ -125,7 +139,7 @@ async function mapWorkspaces (opts = {}) {
const orderedMatches = []
for (const pattern of patterns) {
orderedMatches.push(...matches.filter((m) => {
return minimatch(m, pattern, { partial: true, windowsPathsNoEscape: true })
return minimatch(removeRootPath(m), pattern, { partial: true, windowsPathsNoEscape: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we filter these out of the matches we don't have to call this new function. every time for every pattern.

A .map in line 135 seems appropriate, no?

@reggi reggi closed this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants