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 globs inside a node module folder #1

Open
markhicken opened this issue Mar 22, 2019 · 3 comments
Open

Support globs inside a node module folder #1

markhicken opened this issue Mar 22, 2019 · 3 comments

Comments

@markhicken
Copy link

We have a need to import all files in a folder that exist in a child installed node module.

We expect this...

import intlMessages from '@scopeName/packageName/intl/*.json';

...to resolve to here...

currentWorkingDirectory/node_modules/@scopeName/packageName/intl/*.json

...but instead, it tries to resolve to here...

currentWorkingDirectory/sourceFilePath/@scopeName/packageName/intl/*.json

...which of course breaks because the path doesn't exist.

One simple fix might be to do the following in index.js...

let files = glob.sync(pattern, {strict: true, nodir: true});
if (files.length === 0) {
  pattern = 'node_modules/' + path.node.source.value;
  files = glob.sync(pattern, {strict: true, nodir: true});
}

I've tested this locally and it appears to work against relative paths, regular node module paths, and scoped npm package paths.


  1. I'm happy to submit a PR if you don't have time to make this change. Would you consider a PR if I submit one?
  2. Is there anything else we'd need to test?

Thanks!

@jhicken Thanks for the help digging into this issue!

markhicken added a commit to markhicken/babel-plugin-transform-glob-import that referenced this issue Mar 22, 2019
@pineaulo
Copy link

Since the developer do not answer, how can we use the fixed version of the module with npm (or yarn) ?

@markhicken
Copy link
Author

We just forked it and referenced my fork directly in our package.json...
https://github.com/markhicken/babel-plugin-transform-glob-import

"babel-plugin-transform-glob-import": "git+https://github.com/markhicken/babel-plugin-transform-glob-import.git#glob-inside-node-module",

I just made a PR so you can see the code diff though.

@pineaulo
Copy link

Thank you !

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

2 participants