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

Support mounting within node_modules directory #3134

Merged
merged 5 commits into from
Apr 19, 2021
Merged

Conversation

FredKSchott
Copy link
Owner

Changes

  • Astro has shown that there are valid use-cases for mounting a directory from a node_modules as source files.
  • This changes our node_modules exclude to only kick in when no mounts are defined. This was the original intended use-case that this support was added for.

Testing

  • Covered by tests.

Docs

  • N/A

@vercel
Copy link

vercel bot commented Apr 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/Ebq5CQEdsPuWUbYYKpTUsQ8xfQV8
✅ Preview: https://snowpack-git-node-modules-exclude-pikapkg.vercel.app

...ALWAYS_EXCLUDE,
// Always ignore the final build directory.
`${config.buildOptions.out}/**`,
// If you've mounted your current working directory, ignore the node_modules directory.
Copy link
Contributor

Choose a reason for hiding this comment

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

I could see this accidentally including node_modules in a multirepo setup (e.g. if we mount ./packages/foo, we probably don't want ./packages/foo/node_modules included).

Ideally, I think we'd still ignore node_modules but only the ones nested under the mount directory. Maybe something like this would do the trick:

    const files = (await new fdir()
      .withFullPaths()
      // Note: exclude() only matches directories, and not files. However, the cost
      // of false positives here is minor, so do this as a quick check to possibly
      // skip scanning into entire folder trees.
-     .exclude((_, dirPath) => foundExcludeMatch(dirPath))
+     .exclude((_, dirPath) => foundExcludeMatch(path.relative(mountKey, dirPath)))
      .crawl(mountKey)
      .withPromise()) as string[];

Copy link
Owner Author

Choose a reason for hiding this comment

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

ah right, we're probably getting this protection for free right now.

I really wanted to avoid making a change to every exclude call, but you're right that this is probably the most clear expression of what we're trying to accomplish here. Mount anything, but never travel down into a nested node_modules within a mount (since those are seen as "third-party" to whatever was just mounted).

Copy link
Owner Author

@FredKSchott FredKSchott Apr 13, 2021

Choose a reason for hiding this comment

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

// if this is mounted:
/Fred/Code/myapp/node_modules/astro/internal": "/internal"

/Fred/Code/myapp/node_modules/astro/internal/node_modules/...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ should not be picked up by our automatic "node_modules" exclusion.
                                            ^^^^^^^^^^^^^^ anything inside of this directory should be ignored.

// "any node_modules that is explictly mounted should not be ignored. otherwise, ignore it."

@FredKSchott
Copy link
Owner Author

@natemoo-re is going to take this PR over while I'm out!

@@ -29,9 +30,14 @@
"url": "/j",
"static": true,
"resolve": false
}
},
"../../../node_modules/explicit-test-pkg": "/dep-explicit"
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

Copy link
Collaborator

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

LGTM

This pull request was closed.
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.

4 participants