-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Discrepancy in use between require() and rechoir.load() #10
Comments
Heya! I'm not 100% sure I follow the line of reasoning here--would you mind submitting a failing test case for this scenario? |
Well it is not so much of a bug but rather an inconvenience. Say, you have the following project structure
Instead of using require() I'd like to use rechoir.load() instead. With require and from the lib/ level, I can use relative paths, e.g. require('./forms/form'). And from within forms/form.iced.md I would then be able to require util/string, again using relative paths, e.g. require('../util/string'). With rechoir.load(), however, I would have to use paths relative to the process' cwd, which would for example be that of the parent directory of the lib folder, so instead of '../util/string' I would have to load('./src/util/string'). See also the existing test case for load() and requireFor().
Here, require takes a different path to the module than registerFor does, simply because it is not aware of the nesting level or rather the cwd(), which will be adjusted for every module being required. With the presented API change, this could be streamlined, e.g.
A failing test case for this scenario would be
|
I have made a temporary branch over at my clone, see 5f87f7e The branch is actually called failing-on-relative-paths. |
Pretty swamped here today, I will review this stuff first thing tomorrow. Thanks for the detailed examples! |
@tkellen just use your tools depicted in your avatar ,-) - but then again, you would be swamped in blood and body parts... heck, be careful 😆 |
+100 to this change! |
|
Upon further reflection, I think it's okay to remove |
Good, my initial design for my own library also only provided a function similar to registerFor and let the user use require() for the rest. |
Brilliant! Closing this. |
I just pushed the removal of |
Roger that. It's still referenced in the README. |
Missed the usage, good catch |
When using require() one can use relative paths, e.g. './foo.bar'. When using rechoir.load() from with the very same context, one must use paths relative to the process' cwd instead.
Since rechoir.load() uses a different require() than the module from which it is being called, this actually makes sense.
As such, passing in relative paths to rechoir.load() should be prevented and the user calling that function must first path.resolve() the filepath before calling rechoir.load().
Consequently, the fix introduced with #7 will not work at all.
Should we deprecate the load function or make it require absolute paths to be passed in instead?
Or perhaps, change the API so that upon
one must pass in the module for which rechoir is being required for. That way, rechoir could customize itself so that it uses the correct require() function and so on...
The text was updated successfully, but these errors were encountered: