Prevent callback from firing multiple times #12
Merged
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.
Took me a little to figure this out, but the solution was pretty simple actually.
When
tsconfig-paths
returned with an error the original code would invoke the callback but it would then fall-through to still try doResolve which would in turn invoke the callback again.The different between Webpack 3 and Webpack 4 is that in version 3 they used
async
to wrap their callbacks but with version 4 this was replaced byneo-async
which prevents you from calling the same callback multiple times.I refactored it for both versions so that the callback is invoked and returned early. Knowing that
tsconfig-paths
already errored there is no reason to even try and resolve.I also slightly changed both inner callbacks to be more consistent as I spotted a potential issue (I wrote some comments to explain).
Hopefully this fixes #11 (Although it will probably just show an error from
tsconfig-paths
now, but that should hopefully be solvable ;-))