I'm back inside my code editor still looking at the unresolved function, so we're going to add in some
code here and decide based upon the exact path argument to remember our path is the essentially path
to the file that we are trying to require or import in.
We are going to use that to decide whether or not we want to apply that new Eurail constructor that
we looked at in the end of the last video.
There are still going to do this in a slightly naive way.
We're still not going to have a final solution here that works for all cases.
We're kind of, as you can tell, kind of evolving our code over time and considering all these different
ways that new modules can be imported or required into a project to write above our return statement.
I'm going to add in.
And if and we're going to use this if to decide whether or not we are working on some file that has
a relative path in it.
It's like a file that has a story to do.
So we're going to take a look at args dot path.
We're going to see if it includes, remember, our exact path that right there is like the dot slash
utils or the slash utils.
So we're going to look at that string.
We're going to see if it includes a dot or our exact path includes a dot dot.
If that is the case, then we're going to apply this special new umbrella constructor thing that we
saw at the end of the last video.
One, if you're going to return an object once again with a namespace of just a four right now, again,
we're going to come back and adjust that at some point in time.
And then our path will be new, you are, well, our paths.
And we want to join on or use as the base domain, the importer, the file that tried to import this
thing in our case, that is going to be our export importer.
So for our application, the importer, as we saw inside that control log, would be like the unpackaged
dotcom slash.
Medium test package and then remember, very small critical detail right now is we have to get a Ford
at the end of that base of.
That's going to generate a real object, we don't care about the entire object.
All we care about is that property that has the fully formed URL.
We're going to do a dot HSF on the very end like so.
OK, so this should fix the current problem, but like I said, still kind of a naive approach here.
This still is not quite perfect and is not going to handle all test are all possible cases.
I apologize for this kind of iterative approach that we're going through here.
But honestly, if I just threw the completed code on the screen, you might say like, hey, what is
going on?
Why are there all these possible different cases?
Well, we really have to see all the different ways that new modules can have import statements and
require statements, all the different possible variations, a path to really understand how we're going
to eventually come up with a good solution to this stuff.
Having said that, let's say this, go back to the browser and see how we're doing.
It's going to refresh, submit, and there we go.
Sure enough, we are now able to bundle the entire application.
So we are bundling our indexed JS file, which requires in medium test package and medium test packages.
Indexed JS file in turn is attempting to require in utils.
You'll notice that the very final onload down here.
Remember, OnLoad is, when we are attempting to actually fetch the contents of a file, definitely
is receiving the accurate path, that is definitely the path that we want to get to that utils file.
Again, if we were to take that string right there and try to visit it inside the browser, we see the
utils file load up.
This definitely looks good, definitely works.
But like I said, well, not going to work in all possible cases.
There are still going to be some NPE modules out there that fail with our current kind of path generation
stuff.
So still a couple of very small corner cases that we need to consider.
Let's take a look at one other variation in the next video.