Open molant opened 4 years ago
I believe the issue is that .nycrc
has a higher priority than package.json. So hint/package.json
is being loaded, the extends
is processed, but then .nycrc
is found and overwrites your branches value again. Can you please try creating hint/.nycrc
containing {}
? This would block the root .nycrc
from being found from within the hint
directory. Another option is to just move your nyc options from hint/package.json
to hint/.nycrc
. I believe this should resolve the conflict.
Regarding what you see in the README I think the wording is not perfect. You can add options that overwrite the configuration being extended but they will overwrite (rather than merge). This is of particular interest if you are dealing with say @istanbuljs/nyc-config-babel
which sets require: ['@babel/register']
. Extending the babel config then setting require: ['ts-node/register']
would replace @babel/register
.
Thanks @coreyfarrell for the suggestions, but unfortunately none seem to work or I don't know what I'm doing wrong 😞
packages/hint/.nycrc
with { }
and current content in packages/hint/package.json
failspackages/hint/.nycrc
with the following content and removing the nyc
property from packages/hint/package.json
fails as well:{
"branches": 75,
"extends": "../../.nycrc"
}
During theses tests I've seen that nyc will go up the tree until it finds a .nycrc
file, which is pretty cool. Will remove a bunch of properties from other packages 😊
I'm seeing this problem too - again coming from the monorepo approach and trying to solve this from a few different angles.
The behaviour of extends seems to be broken since it takes the values coming from "extends" over any values defined in the config file.
package.json
"nyc": {
"extends": "path/to/.nycrc",
"all": true,
"per-file": true,
"lines": 80
}
path/to/.nycrc
{
"lines": 100,
"per-file": false
}
The resulting config that nyc loads looks like this
{
"lines": 100,
"per-file": false,
"all": true
}
This needs to be fixed in https://github.com/istanbuljs/load-nyc-config and would probably be counted as another breaking change.
Having this problem too, just to confirm as a non-monorepo-usecase. We have multiple separate packages that use a shared nycrc.yaml that we add as a node_module:
extends: "@internal/nyc-config"
branches: 0
I can manually edit the extended config and nyc is definitely picking it up, but I can't override any of its options...
I was able to work around this by creating an nyc.config.js
file at the root of my project and applying my overrides there.
nyc.config.js
:
const settings = require('path/to/nyc-config');
settings.exclude = settings.exclude.concat([
'nyc.config.js',
'tools/**'
]);
settings.lines = 80;
module.exports = settings;
I am also experiencing this issue in "15.1.0"
. The common config file that we are reusing across projects is .nycrc
, which makes it inconvenient to refactor (I would have to change in all other projects)
I believe the issue is in here. It overwrites the configuration with extended configuration but it should be the other way around.
For anyone else trying to work around this for a monorepo scenario, I was able to do so by adding my extends
clause in a local package.json
and putting the overrides in a local .nycrc
. Both get picked up and the local .nycrc
is applied last so the overrides still take effect.
See https://github.com/webhintio/hint/pull/4734/commits/cca423d228b57e89a59da4ab1d62c8d15a5b5214
Link to bug demonstration repository
We are trying to update to v15 in https://github.com/webhintio/hint, the PR is https://github.com/webhintio/hint/pull/3513
And the relevant output of CI is here
Expected Behavior
webhint uses a monorepo approach where we have a common
.nycrc
file in the root of the project. In that file we set the minimum threshold to 80 for branches. Some packages might override the default configuration.packages/hint
is one of those where thepackage.json
has annyc
property that sets"branches": 75
.Unfortunately, it seems like with the newest nyc version, properties in the
extends
file cannot be override.Observed Behavior
I've tried:
80
from extends and having75
in the package: test pass (expected as the coverage is 75.66%)80
from extends and having80
in the package: test fail (expected)80
by90
in the extends. Test fail saying the minimum threshold of 90 is not meetThis does not happen with previous nyc versions.
The documentation says:
(emphasis is mine) which maybe believe this might be intentional, but seems like a huge step back (ie.: having to have to set the coverage in each project).
Troubleshooting steps
cache: false
in my nyc configEnvironment Information