Skip to content

Commit

Permalink
Try to resolve from the context of the original request
Browse files Browse the repository at this point in the history
When trying to prove the resolve works, it is good to do it from the
original context of the file which is how webpack will try to resolve
it.
  • Loading branch information
icatalina committed Mar 19, 2020
1 parent fc37932 commit d3b247d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const rewriteCoreJsRequest = (originalRequest: string, lowerVersion = fal
const [,matchedVersion, matchedPath] = originalRequest.match(/core-js\/es(5|6|7)(.*)?/);

const version = matchedVersion;

if (version === '5') {
return null;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function CoreJSUpgradeWebpackPlugin(options: Options) {
options = Object.assign({}, defaultOptions, options || {});

const resolvers = options.resolveFrom ? [].concat(options.resolveFrom).map(r => resolveFrom.bind(null, r)) : [];

return new NormalModuleReplacementPlugin(/core-js/, resource => {
const originalRequest = (resource.userRequest || resource.request) as string;
if (originalRequest.startsWith('./') || originalRequest.startsWith('../')) {
Expand All @@ -96,7 +96,7 @@ export default function CoreJSUpgradeWebpackPlugin(options: Options) {
}

try {
require.resolve(originalRequest);
require.resolve(originalRequest, { paths: [resource.context] });
} catch (originalError) {
let error = true;

Expand All @@ -109,7 +109,7 @@ export default function CoreJSUpgradeWebpackPlugin(options: Options) {
error = false;
} catch (e) {}
}

// attempt to upgrade the path from core-js v2 to v3 from backup
if (error) {
try {
Expand All @@ -118,7 +118,7 @@ export default function CoreJSUpgradeWebpackPlugin(options: Options) {
error = false;
} catch (e) {}
}

// attempt to downgrade the path from es7 to es6 from backup
if (error) {
try {
Expand Down

0 comments on commit d3b247d

Please sign in to comment.