Proposal: JSON configuration file to control plugins #74
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.
This PR contains a proposal for a JSON configuration file format for ts-migrate, as well as a basic implementation of the proposal. If the proposal is acceptable, I can write documentation and add further validation to the implementation, if necessary.
I'm completely happy to receive feedback on any level of this proposal. Don't worry about my feelings too much. 馃榾
Context
I see these problems with ts-migrate:
It should be easy to run repeatable migrations and it should be easy to tweak plugin configurations to get the desired results.
There is currently limited ability to configure plugins, and doing it purely from the command line can be cumbersome. We can add more command-line flags to increase configurability, but this makes it more cumbersome.
It should be possible to control which plugins run and the order in which they run.
Currently the only way to do this is running multiple
ts-migrate migrate --plugin $plugin
commands.There should be a way to load custom or third-party plugins.
See #41. This proposal does not aim to solve this problem, but it's a step towards solving the problem.
Solution
I propose adding a JSON configuration format for ts-migrate that allows specifying which plugins run, in what order, and the options passed to them.
The
migrate
command has a new flag,--config/-c
, which specifies the path to the configuration file. If a configuration file is specified, other flags are ignored.The top-level configuration object has two properties:
plugins
- a JSON array of plugins to run. Each plugin is a JSON object, described below.globalOptions
(optional) - a JSON object of options which are passed to all plugins. Typically this is whereanyAlias
andanyFunctionAlias
would be defined, but technically any option may be defined here.A plugin object has two properties:
name
: The name of the plugin. For example,strip-ts-ignore
.options
(optional): The options to be passed to the plugin. Options specified here overrideglobalOptions
.Downsides
reignore
command cannot be expressed in terms of a configuration object due to the "higher-order" plugins it uses. (withChangeTracking
,eslintFixChangedPlugin
)Schema
Here is a basic JSON schema which describes the structure of the configuration object. See also the defined TypeScript types in the implementation.
Example
The configuration for the default
migrate
command would look like this: