Skip to content

Config files possibly read multiple times and in inconsistent order #949

@jgoz

Description

@jgoz

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

If cwd is a subdirectory of $HOME, .npmrc and .yarnrc files will be read multiple times and in the wrong order.

This is because of these lines. Before that block, possibilities will be [global, home, local]. But after that block, possibilities will be [global, home, local, local, ..., home, ...] with possibilites from intermediate directories (if any).

This is incorrect. Not only will the config files be read multiple times, but values from home will override those from local because it read last.

One solution might be as follows:

  1. Populate possibilities with [global, home] initially
  2. Look for local files starting with cwd, but add them in reverse order such that a file located in cwd is last in the possibilities array
  3. Only add a config file if it is not already contained in the array

That way we avoid unnecessary reading/parsing and the values have the correct precedence.

If the current behavior is a bug, please provide the steps to reproduce.

  • In $HOME/.npmrc set registry=https://registry-a.com
  • In $HOME/repo/.npmrc set registry=https://registry-b.com
  • In $HOME/repo run yarn

Requests will be pulled from https://registry-a.com.

What is the expected behavior?

Requests should be pulled from https://registry-b.com.

Please mention your node.js, yarn and operating system version.
Node: v4.6.0
Yarn: master
OS: Windows 10 x64

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