This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Improve error message when .tap() used on an undefined plugin #271
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.
Previously if
.tap()
was called for a plugin that didn't exist, the.tap()
call would succeed, but the.toConfig()
would fail later with:TypeError: Cannot read property '__expression' of undefined
This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using
.has()
before calling.tap()
.Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the
.toConfig()
, where it's much harder to debug the cause.Now the
.tap()
call itself will show the error:Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first
Whilst this error check does technically break the (unlikely) scenario of calling
.tap()
in a preset before the plugin is defined by a later preset, IMO that ordering was already broken, since the.tap()
's args would have been overwritten by the subsequent preset.Fixes #125.