Skip to content

Configuration is not loaded in prompt-cli #100

Closed
@mgtitimoli

Description

@mgtitimoli

Hi,

Before going forward I want to thank you, I have been using the suite (config-angular, cli, prompt-cli) for a long time, it's amazing, great work!

Today I finally decided to update to latest (4.2.0), and then at the time to commit, I noticed prompt-cli was no longer providing valid types when I hit tab.

TL;DR config is not loaded because no options.cwd is provided to @commitlint/core load and defaults to "" (empty string) so rules are not loaded and therefore there is no info to autocomplete.

Below is the flow executed to load the config so you can see that none of the steps is providing options.cwd

  1. @commitlint/prompt-cli calls prompt from @commitlint/prompt without args (here)
  2. @commitlint/prompt calls load from @commitlint/core without args (here)
  3. @commitlint/core load 2nd param, options, defaults to {cwd: ''} (here)
  4. @commitlint/core load uses options.cwd to load the config (here)

Since no options are provided to @commitlint/core load, then it uses defaults, and therefore no config is loaded as it tries to load using options.cwd which is an empty string.

After having detected this I was wondering why @commitlint/cli is not having the same issue, and the answer is here, that as you can see it uses process.cwd() as the default instead of an empty string.

So finally and as an attempt to solve the issue I replicated the logic in @commitlint/cli, so I set options.cwd default in @commitlint/core load to process.cwd() as follows:

export default async (seed = {}, options = {cwd: process.cwd()}) => {
  // ...
}

And indeed this worked.

Another alternative would be to pass {cwd: process.cwd()} when prompt calls load...

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions