istanbuljs / nyc

the Istanbul command line interface
https://istanbul.js.org/
ISC License
5.55k stars 353 forks source link

nyc instrument does not properly handle cwd option #1485

Open loidy opened 1 year ago

loidy commented 1 year ago

Link to bug demonstration repository

https://github.com/loidy/nyccwd - or any other initial angular project

Steps to reproduce

  1. npm install
  2. npm run dev or ng build --configuration development
  3. nyc instrument --complete-copy --delete --source-map=true --cwd dist/nyccwd . instrumented

Expected Behavior

When --cwd option is used, I expect that input is relative to provided --cwd path.

Observed Behavior

Input is still relative to current directory regardless of --cwd option. However, cwd is still used when considering if file should be instrumented. In combination with --complete-copy it results in complete copy of the input (relative to current directory, not cwd) directory without instrumenting any file.

Troubleshooting steps

-

Environment Information

  System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 AMD Ryzen 7 5800HS with Radeon Graphics
    Memory: 10.61 GB / 39.41 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.17 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    nyc: git+https://github.com/loidy/nyc.git#cwd-fix => 15.1.0
    typescript: ~4.7.2 => 4.7.4

Proposed Solution

https://github.com/istanbuljs/nyc/pull/1484

Additional Information

I needed to instrument code with relative paths to --cwd directory, because I have to run it on different system. For this I provided relative path to transform function instead of absolute. Without correct --cwd behavior I was not able to run command from project root directory and still access original source files to remap sources.

sw-tracker commented 1 year ago

I am having the same problem. Did you find a workaround? Essentially, I have 2 yarn workspaces and I need to point nyc one folder level up: "cwd" : "../". However, this causes nyc not to find any files at all.

loidy commented 1 year ago

@sw-tracker Here is fix: https://github.com/istanbuljs/nyc/pull/1484 And I'm using my fixed fork when installing with npm: https://github.com/loidy/nyc

sw-tracker commented 1 year ago

How can I use your version? I cant find it in npmjs...

loidy commented 1 year ago

@sw-tracker npm install --save-dev git+https://github.com/loidy/nyc.git