Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cwd option to es6+ instrument command #1024

Merged

Conversation

AndrewFinlay
Copy link
Contributor

This adds support and tests for the '--cwd' option for the instrument command, it's intended to sit on top of the recent es6+ changes.

Andrew Finlay added 3 commits March 12, 2019 15:48
     - Notes:
        Add instrument command support for the 'cwd' option
        Refactor nyc-integration instrument tests so tests with output folder specified aren't in the no output folder suite
        Refactor instrument.js and instrumentAllFiles command to use modern javascript
        Remove call to deprecated 'process.exit()' in instrument command
        Use file extension as an index to find the correct transform, rather than trying to match a transform name to the rightmost characters of a filename
            * There is another one of these in the code base but it's out of the scope of this PR
        BTW, I'm not going to widen the scope of this PR, this is it!
     - Assumptions:
        If you're instrumenting a single file cwd/a/b/d.js, and specifying an output directory cwd/e, the result will be cwd/e/d.js
        That we want to use file extensions for find transforms, the existing implementation would use the '.js' instrumenter for both '.js' and '.mjs' files, these changes assume that was wrong.
	That the filename in the covered file should be of the form './path/to/file.js'
This is intended to sit on top of the nyc es2015+ commit.  It uses the cwd option and its defaults in nyc to make paths more consistent.
@coveralls
Copy link

coveralls commented Mar 12, 2019

Coverage Status

Coverage remained the same at 96.414% when pulling c454b56 on AndrewFinlay:instrument-es6-cwd-option into 91e02c6 on istanbuljs:master.

@@ -28,6 +29,10 @@ exports.builder = function (yargs) {
type: 'boolean',
description: "should nyc's instrumenter produce source maps?"
})
.option('cwd', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cwd is actually already defined in lib/config-util.js in a way that allows it to be global. I think we should not add the .option to this file but we should update the describe string in lib/config-util.js. Note the current definition of lib/config-util.js often does not result in cwd: process.cwd(). It uses find-up to search for the package.json which owns process.cwd(), then uses the dirname of that package.json.

Existing: working directory used when resolving paths
Maybe change to: base directory of this project

The important thing is that --cwd effects the interpretation of include and exclude. I think it should not effect the interpretation of the input/output positional arguments. Consider this, when you run nyc --cwd=.. ./somescript.js the ./somescript.js is found from $PWD, not from the value of --cwd.

lib/commands/instrument.js Show resolved Hide resolved
index.js Outdated
@@ -193,15 +193,15 @@ NYC.prototype.addAllFiles = function () {
NYC.prototype.instrumentAllFiles = function (input, output, cb) {
let inputDir = '.' + path.sep
const visitor = filename => {
const inFile = path.resolve(inputDir, filename)
const inFile = path.resolve(this.cwd, inputDir, filename)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut reaction is that we these changes to index.js should not happen.

Andrew Finlay added 2 commits March 19, 2019 11:33
All changed, so all this does now is propagate `cwd` so that it can influence `testExclude` and `require` path settings.
@coreyfarrell coreyfarrell merged commit 051d95a into istanbuljs:master Mar 19, 2019
@AndrewFinlay AndrewFinlay deleted the instrument-es6-cwd-option branch March 20, 2019 00:43
@coreyfarrell coreyfarrell mentioned this pull request Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants