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

Inconsistent import.meta.glob behaviour #11

Open
isneezy opened this issue Jul 26, 2022 · 0 comments
Open

Inconsistent import.meta.glob behaviour #11

isneezy opened this issue Jul 26, 2022 · 0 comments

Comments

@isneezy
Copy link

isneezy commented Jul 26, 2022

  • babel-preset-vite version: 1.0.4
  • babel-plugin-transform-vite-meta-env version: 1.0.3
  • babel-plugin-transform-vite-meta-glob version: 1.0.3
  • @babel/core version: 7.18.9
  • node version: v14.19.3
  • yarn version: 1.22.19

Relevant code or config:

Reproducible repo: https://codesandbox.io/s/beautiful-roman-sjjvdg?file=/test/Posts.spec.tsx

What you did:

I was trying to unit test my vite, react, typescript project which has a working file based routing, done by leveraging the import.meta.glob feature.
I used this library to replace the occurrence of import.meta.glob, but it is not behaving like vite's implementation since it is not supported outside the vite environment, jest in this case.

What happened:

While the code is working well with vite (dev server and production build), under tests it is always returning an empty object
unless the glob pattern is changed to be relative to the test file that will import it.

Reproduction:

Reproducible repo: https://codesandbox.io/s/beautiful-roman-sjjvdg?file=/test/Posts.spec.tsx

Problem description:

  • It seems like the glob implementation of this library doesn't take the root project path as the root of the glob search
  • The search is done relative to the root script/the script that used the import.meta.glob instead of being relative to the script that used import.meta.glob.

Suggested solution:

  • if the glob pattern starts with / the glob pattern must be applied to the project directory instead of the root of the file system.
  • if the glob pattern starts with . the pattern must be applied to the folder where the file that declared import.meta.glob resides instead of the file that imported, but this isn't important since vite doesn't support this yet.
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

No branches or pull requests

1 participant