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

CLI path resolution inconsistent for entry files and -e|--entry vs. -r|--require #1219

Closed
jmm opened this issue Apr 17, 2015 · 6 comments
Closed

Comments

@jmm
Copy link
Collaborator

jmm commented Apr 17, 2015

In browserify 9.0.8 CLI on linux path arguments are resolved inconsistently for entry files / -e / --entry vs -r / --required. Seems counterintuitive. Is there a reason to resolve them differently? Note: triggering it doesn't require an expose argument for the -r files.

# Module files a.js and b.js

# Error: Cannot find module 'b'
browserify a -r b
browserify -e a -r b

# No error, both bundled
browserify a -r ./b
browserify -e a -r ./b
@terinjokes
Copy link
Contributor

I believe entry is really expected to be a file, whereas require is documented as being anything that can be resolved by the node require resolution. I'm not aware of any history for them doing different things, though.

That said, this is method is kinda gnarly, and I should really take some time to clean it up.

@jmm
Copy link
Collaborator Author

jmm commented Apr 17, 2015

@terinjokes Thanks for the reply. I'm not sure I see the distinction -- shouldn't they both just be resolved to a module file starting from some base dir (the same one in the case of these examples)? Unless there's a good reason to do otherwise it seems like it would be ideal for them to perform consistently in terms of the input they can take and how they resolve it to a file. No?

@terinjokes
Copy link
Contributor

@jmm I was hoping our mysterious leader would come by and comment about why they do different things. 😉

@jmm
Copy link
Collaborator Author

jmm commented Apr 17, 2015

@terinjokes Ah, got it, sounds good.

@ghost
Copy link

ghost commented Apr 25, 2015

--require looks up files the require.resolve() way because that's what require() does.

--entry expects file paths like fs.createReadStream() would

It's difficult to do both operations in a single step. Sometimes you can require() a path but other times you can only fs.createReadStream() a path. Sometimes you can do both and sometimes neither one can work. When you do both, it's possible to have 2 different outcomes.

If you have these files:

  • whatever.js
  • node_modules/whatever.js/index.js

Then the string "whatever.js" passed to either option will give back different results.

Resolving the path in --require as a fallback might work but there are some implications for performance and it might be too surprising.

@jmm
Copy link
Collaborator Author

jmm commented Apr 27, 2015

Thanks for explaining that @substack. I see what you guys mean, and that totally makes sense if the 80% case for -e|--entry is files outside of node_modules, and the opposite is the case for -r|--require. I don't know why I was so confused on this, even through your explanation @terinjokes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants