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

feat: allow globs in node_modules when pattern is explicit #6056

Merged
merged 3 commits into from
Jan 12, 2022

Conversation

frandiox
Copy link
Contributor

@frandiox frandiox commented Dec 10, 2021

Description

Currently, we cannot use import.meta.glob for files in node_modules. This can be useful sometimes in development environments, especially considering that Vite treats relative and absolute paths differently.
This PR prevents ignoring node_modules in globs when the pattern is explicitly checking it.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@Shinigami92 Shinigami92 added the p2-nice-to-have Not breaking anything but nice to have (priority) label Dec 11, 2021
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I'm not entirely clear of the usecase for globbing into node_modules. Usually those are pre-bundled, though globbing on package assets like CSS, SVGs might make sense, but I think the package should have an API to do that by default either ways.

@patak-dev
Copy link
Member

@frandiox is this something that is blocking your team at Hydrogen? We can check with the team tomorrow, but as @bluwy said, it would help to have a detailed use case to justify the feat

@frandiox
Copy link
Contributor Author

@patak-dev @bluwy Thanks for checking!
So this came up when creating a separate Vite plugin for React Server Components (source here). Not sure if you are familiar with that but basically we need to use globs to find all the components that end in *.client.js. The problem is that some of these components might not be located in the user's src, but might come from a library in node_modules (like Hydrogen).

On top of that, in Hydrogen we use Yarn v1 workspaces (monorepo) and we are hoisting components to the root node_modules for local development. However, the importer file (the file that contains the import.meta.glob code) is located in a non-hoisted node_modules/.vite cache directory. Therefore, at some point we are trying to do import.meta.glob('../../../node_modules/@shopify/hydrogen/components/**.client.js') and this returns nothing without the change in this PR 😅

This is not blocking us right now but it will if that PR I linked is merged/released -- so feel free to take time to ask the team or suggest other ideas 👍

@patak-dev
Copy link
Member

@frandiox could you resolve the conflicts? We talked with the team and we can merge the PR 👍🏼

@frandiox
Copy link
Contributor Author

@patak-dev Done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants