Skip to content

nyc instrument does not properly handle cwd option #1485

@loidy

Description

@loidy

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

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions