Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

local dependencies have confusing edge cases #6363

@othiym23

Description

@othiym23

(tapping in @dylang, because local dependencies were his contribution, and @timoxley, because linklocal forces the issue a bit)

@iarna and I figured out that local dependencies, as they're currently implemented, conflate

  • when relative paths to local dependencies are used on the command line, when it makes the most sense to install them relative to the current working directory, and
  • when local dependencies are saved in package.json, when you want them to be relative to directory in which the package.json file is stored.

npm's implementation doesn't make it easy to determine which execution path led to a given relative path, so @iarna resolved this by treating file: and ./relative/path paths differently to capture the two use cases.

Because npm i -S ../local/dependency normalizes the paths to file: URLs when saving them into package.json, this isn't generally an issue in npm. However, this is a subtle solution to the problem, and it may cover up other edge cases we haven't hit yet.

As I see it, there are a few alternatives open to us:

  1. Do nothing; the current solution works well enough for those who rely on it (if @dylang and @timoxley agree with @iarna's solution, this is probably good enough for now).
  2. Disallow relative paths? This was @isaacs's solution when I first outlined this problem to him, although we quickly agreed that limited the usefulness of local dependencies unacceptably.
  3. Always normalize to absolute paths? This is a slightly less draconian version of 1.
  4. Always interpret relative paths to be relative to the current working directory? This makes it exceedingly tough to nest local dependencies.
  5. Always interpret relative paths to be relative to package.json? This is the most consistent, but it breaks a bunch of npm's existing tests, and is a breaking change to how installing from a path worked before this feature was added.

I'd like to get this worked out before people have invested a lot of time building builds or tooling around local dependencies.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions