node-app-root-path icon indicating copy to clipboard operation
node-app-root-path copied to clipboard

`resolve` function should behave as `path.resolve`

Open Andreyco opened this issue 5 years ago • 3 comments

I strongly believe appRoot.resolve should behave as path.resolve does. It means:

  • given relative path, resolve absolute path relative to the app root
  • given absolute path, resolve given absolute path

Andreyco avatar May 20 '20 00:05 Andreyco

Codecov Report

:exclamation: No coverage uploaded for pull request base (master@54d06fe). Click here to learn what that means. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #46   +/-   ##
=========================================
  Coverage          ?   87.09%           
=========================================
  Files             ?        2           
  Lines             ?       62           
  Branches          ?        0           
=========================================
  Hits              ?       54           
  Misses            ?        8           
  Partials          ?        0           
Impacted Files Coverage Δ
lib/app-root-path.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 54d06fe...828d91a. Read the comment docs.

codecov-commenter avatar May 20 '20 00:05 codecov-commenter

Hm. This makes sense. Can you explain what issue you bumped into that made you open the PR? This is a breaking change and would push us to 4.0, so I want to understand where/when it's necessary.

inxilpro avatar May 20 '20 01:05 inxilpro

Sure, here is the use case.

  • A dependency relay on loading certain file, let's say it's a configuration JSON file for a lib (lib uses this package as resolver)
  • A dependency reads environment variable for certain variable, e.g. {LIB}_CONFIGURATION_PATH.

Given it's a relative path (essentially means configuration file is in scope of host application directory), it should be resolved to host application root. This scenario works well.

The problem is with absolute path. A file could be outside of host application directory or inside (but referenced by absolute path). The path is not resolved correctly in this case and results in following output: {applicationRootPath}/{absolutePaht}

I fully understand this is breaking change and thus your concerns.

Andreyco avatar May 20 '20 22:05 Andreyco