Try to resolve from the context of the original request #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Use the context of the original request to try and validate some resource is available.
Why?
When trying to prove we can resolve a file, it is good to do it from the
original context of the file which is how webpack will try to resolve
it.
Some background:
In our company, we have a shared build tool which we install, said build tool contains a
webpack.config.js
file which will (hopefully) run this plugin.One of the main reasons we have to use this plugin is to avoid installing core-js@3 in every app that consumes it. We need to redirect requests for
core-js
to the version installed alongside the build tool.Our current
node_modules
looks something like this:Using
require.resolve(originalRequest)
will resolve that request from the context ofbuild-tool
which does containcore-js@3
and will work. But most of the request come from the code babel will inject in our app. Which means they will actually be required from the context of the main app hence trying to usecore-js@2
. Without the{ paths: [] }
options,require.resolve
will succeed while the actual webpack require will fail, this PR solves that issue.Thanks :)