@adeira/flow-config-parser

    0.3.0 • Public • Published

    Permissive Flow config parser.

    yarn add @adeira/flow-config-parser
    

    Supported functions

    parse

    Parse function doesn't do any magic. It simply takes the .flowconfig as a first argument and returns object with the config values:

    import { parse } from '@adeira/flow-config-parser';
    
    parse(`
    [version]
    >=0.138.0 <0.140.0
    `);

    Returns:

    {
      "declarations": [],
      "ignore": [],
      "include": [],
      "libs": [],
      "lints": null,
      "options": null,
      "rollouts": null,
      "strict": [],
      "untyped": [],
      "version": ">=0.138.0 <0.140.0"
    }

    merge

    Merge functions merges two configs together and returns the final config:

    const configA = `
      [options]
      emoji=true
      module.file_ext=.foo
      module.file_ext=.bar
    `;
    
    const configB = `
      [options]
      emoji=false
      module.file_ext=.baz
      munge_underscores=false
    `;
    
    merge(configA, configB);

    Returns:

    # ...
    
    [options]
    emoji=false
    module.file_ext=.foo
    module.file_ext=.bar
    module.file_ext=.baz
    munge_underscores=false
    
    # ...
    

    print

    Print function takes the parsed config and prints it into .flowconfig format:

    const parsedConfig = parse(' … '); // original config
    print(parsedConfig);

    Caveats

    This parser supports [rollouts] parsing only partially. Specifically, it omits rollout annotations when parsing. So for example, this config:

    [rollouts]
    formed_exports=80% on, 20% off
    
    [options]
    (formed_exports=on) experimental.well_formed_exports=true
    

    Returns the following object after being parsed (notice the missing (formed_exports=on)):

    {
      "declarations": [],
      "ignore": [],
      "include": [],
      "libs": [],
      "lints": null,
      "options": {
        "experimental.well_formed_exports": true
      },
      "rollouts": {
        "formed_exports": "80% on, 20% off"
      },
      "strict": [],
      "untyped": [],
      "version": null
    }

    It's because we didn't implement the options merging (on purpose). Rollouts seem to be quite internal and not very often used. However, we might change this if there is a real interest.

    Keywords

    none

    Install

    npm i @adeira/flow-config-parser

    DownloadsWeekly Downloads

    5

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    22.9 kB

    Total Files

    17

    Last publish

    Collaborators

    • martin.zlamal
    • adeira-npm-bot