npm / npm/cli

.npmrc location relative path

Open
#6,697 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

For example logs-dir option accepts relative path as a path specifier and it works properly when runnig npm commands from the directory containing the project specific .npmrc. Unfortunately if I run the npm command with --prefix then the relative path is used against the current folder. This can be interpreted as working as specified and may even be the intended behaviour.

Expected Behavior

I would like to see an ability to interpret the path relative to .npmrc file similar to Windows Batch %~dp0 so that regardless how or from where the npm command is called the path is interpreted the same. Also, please bear in mind that absolute path is not an option as path may not be same across the different machines used in building the codebase (be it developer machine or especially in the case of CI-machine where every build is in a different directory).

Steps To Reproduce
  1. Add relative path to project specific .npmrc, for example logs-dir=_build\build_results\.npm\_logs
  2. Run npm ci from the project directory
  3. Verify that logs are generated to _build directory in the project path
  4. Run npm ci --prefix=PATH_TO_PROJECT from different directory
  5. Logs are generated to current directory, not under project directory
Environment
  • npm: 9.6.7
  • Node.js: 18.17.0
  • OS Name: Window 10 22H2
  • System Model Name: Hyper-V Instance
  • npm config:
; "project" config from .npmrc

logs-dir=..\_build\build_results\.npm\_logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the project-specific .npmrc behavior with a relative logs-dir, first from the project directory and then with npm ci --prefix from another directory. Trace how the CLI resolves this option and define done as resolving the relative path against the .npmrc location in both cases, including the Windows example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.