-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
How to improve nested requires? #9323
Comments
Furthermore, it would be great to raise an issue to design a solution for our dirty requires. |
I could look at this task. We are a group of 5 students from KTH in Stockholm and we have a task to look at refactoring issues in open source projects. |
@davisfreimanis Sure 👍 Just writing down the steps for you how to tackle this task:
If you have any questions, ping me in slack. |
Hello! I'm one of the other students from @KTH mentioned by @davisfreimanis above (the others are @dsalathe, @steinnp, and @hannahfloeter). We've looked at the options a bit and think the simplest solution is to use a global function An example usage is here. One thing we aren't sure about is where we could define the global function to have it be visible from tests as well? And do you think this seems like a good solution? |
@ernstwi Hey, thanks for coming back. I'll reply tomorrow 👋 |
Just sharing some options i went through. I'll look into this tomorrow again. If you find anything else, please share. Before we can make a decision we have to get a clear overview of currently available options and upcoming options.
|
Thank you. I don't think I have enough node experience to offer a good opinion on which of these solutions is the best, but we did try the We replaced all the relative paths in |
@ernstwi Thanks for coming back :) Could you pls swing by our slack channel and ping me in the help channel. Thanks! 👋 |
In case it could be useful in future, here's a script to rewrite the require paths using the current directory as root. |
What do you think about patching example usage // index.js (entrypoint)
const registerRequirePrefix = require('register-require-prefix')
registerRequirePrefix('models:', __dirname + '/models');
registerRequirePrefix('ghost:', __dirname); // some other file
const SomeModel = require('models:thing'); // equivalent of requiring __dirname/models/thing
// OR
const SomeModel = require('ghost:models/thing'); // same as above |
@allouis Thanks for getting involved. It's a nice idea, but it also forces us to override the |
We would like to figure out how to improve requiring modules.
e.g. take a look at this - we have to go back in the folder tree to be able to require the logging module.
The same problem exists in our test env, see.
global require function
One option could be to add a
global.requireSomething
fn, which is able to read modules from a defined root path.e.g.
requireRoot('services')
- would require a module from thecore/server
folder.e.g.
requireLib('errors')
- would require a module insidecore/server/lib
other options?
Wait that Node supports
import/export
and a similar module like ember-resolve. So you can do:import * from 'ghost/services'
- that would be so cool 🙊The text was updated successfully, but these errors were encountered: