Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Configuration file support #31

Closed
urish opened this issue Mar 17, 2018 · 6 comments
Closed

Configuration file support #31

urish opened this issue Mar 17, 2018 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@urish
Copy link
Collaborator

urish commented Mar 17, 2018

Once #27 is merged, or #29 is implemented, it will make sense to have some configuration file to toggle these behaviors. A few more things the user may want to configure:

  • Whether to instrument arrow functions
  • Whether to detect the shapes of objects (once Expand object? #19 is implemented)

And I am pretty sure we will have more down the road. This also paves the road to adding experimental features, which will be turned off by default, but available for adventurous users.

@urish urish added help wanted Extra attention is needed good first issue Good for newcomers discussion For direction and implementation discussions labels Mar 17, 2018
@zoehneto
Copy link
Contributor

I'm thinking about implementing this since I just switched my build to typewiz-webpack and I really want to take advantage of the newer features which aren't enabled by default. I imagine the following:

Config File

typewiz.json

  • options from IInstrumentOptions
  • options from ICompilerOptions
  • options from IApplyTypesOptions

the result would look something like:

{
    /**
     * If given, all the file paths in the collected type info will be resolved relative to this directory.
     */
    rootDir?: string;

    /**
     * Path to your project's tsconfig file
     */
    tsConfig?: string;

    // You probably never need to touch these two - they are used by the integration tests to setup
    // a virtual file system for TS:
    tsConfigHost?: ts.ParseConfigHost;
    tsCompilerHost?: ts.CompilerHost;

    instrumentCallExpressions: boolean;
    instrumentImplicitThis: boolean;

   /**
     * A prefix that will be added in front of each type applied. You can use a javascript comment
     * to mark the automatically added types. The prefix will be added after the colon character,
     * just before the actual type.
     */
    prefix?: string;
}

Plugin Integration

typewiz-webpack

We can pass the config path to the loader:

use: [
    {
        loader: 'typewiz-webpack',
        options: {
            config: 'some/path/typewiz.json'
        }
    },
    'ts-loader'
],

and to the plugin:

plugins: [
    new TypewizPlugin('some/path/typewiz.json')
]

typewiz-node

We could pass the config path to the normal command or detect it automatically, the former might be difficult when using it with mocha though.

Internal Handling

This leaves the question what the config file actually does. Do we want a central config file handling in typewiz (with instrument() and applyTypes() using this config object) or should the individual plugin interpret the config file and pass the correct options to the existing functions? If the former is chosen, what does this mean for people using the api directly?

@urish urish added this to the TypeWiz 0.8.0 milestone Mar 26, 2018
@urish
Copy link
Collaborator Author

urish commented Apr 1, 2018

Great write up @zoehneto, pretty much summarizes my thoughts :)

As for the internal handling part, I see two approaches:

  1. Divide the config file into sections, e.g.
{
  "common": {
     "rootDir": "...",
     "tsConfig": "..."
  },
  "instrument": {
     "instrumentCallExpressions": true,
     "instrumentImplicitThis": true
   },
   "applyTypes": {
      "prefix": "TypeWiz |"
   }
}

Then you can just pass the appropriate section to each of the functions, merged with the "common" section.

Another approach would be to create helper functions that only return the relevant part of configurations for each of the functions, e.g. applyTypesConfig() that will get a typewiz configuration (in any format we decide on), and return the relevant options for applyTypes. This will allow much more flexibility in the config file format.

Thoughts?

@zoehneto
Copy link
Contributor

zoehneto commented Apr 1, 2018

I like the splitting into different sections from approach 1 since it nicely represents the stages of the typewiz process and also makes it more clear what options do / where they are used ('prefix' by its self doesn't tell you when its used). But we should probably still create the helper functions so we can decouple the config file properties from the options passed to the individual functions.

@zoehneto zoehneto mentioned this issue Apr 1, 2018
4 tasks
@zoehneto
Copy link
Contributor

zoehneto commented Apr 9, 2018

Basic config file support is merged, here are the tasks left for full support:

  • Add support for applying types with config to typewiz-webpack (potentially as part of CLI [RFC] #53 )
  • Update urish/typewiz-webpack-demo
  • Add schema to Schema Store for editor support
  • Update typewiz-webpack and typewiz-node dependency on typewiz-core to the correct (published) version
  • Document typewiz.json

@urish urish modified the milestones: TypeWiz 0.8.0, TypeWiz 1.0.0 Apr 11, 2018
@zoehneto
Copy link
Contributor

I created a PR for Schema Store at SchemaStore/schemastore#433

@zoehneto
Copy link
Contributor

I just submitted a PR for urish/typewiz-webpack-demo. That means that once all relevant PRs are merged this issue is resolved.

@urish urish added enhancement New feature or request and removed good first issue Good for newcomers discussion For direction and implementation discussions help wanted Extra attention is needed labels Apr 16, 2018
@urish urish closed this as completed Apr 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants