ni / javascript-styleguide

JavaScript and TypeScript Style Guide
MIT License
9 stars 9 forks source link

Packages should be using peerDependencies #93

Closed rajsite closed 1 year ago

rajsite commented 2 years ago

For a package.json with the following:

"devDependendencies": {
    "eslint": "<some_version>",
    "@ni/eslint-config-angular": "<some_version>"
}

It is reasonable to expect that dependency resolution will work correctly and all the related dependencies (@ni/eslint-config-typescript, etc) will be installed.

However, because @ni/eslint-config-angular lists @ni/eslint-config-typescript as a dependency instead of a peerDependency, npm is allowed to resolve the package structure as:

Which results in error from the eslint because packages expected to be at the root are not:

[error] Error: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.json#overrides[0] » @ni/eslint-config-angular » @ni/eslint-config-typescript': Cannot find module '@typescript-eslint/eslint-plugin'

The expected module resolution tree should look like:

To achieve that consistently the packages should all move to peer dependencies, ie:

https://github.com/ni/javascript-styleguide/blob/fb056718f8e5d703797e83a3f9b0fe235b39aceb/packages/eslint-config-angular/package.json#L33-L35 https://github.com/ni/javascript-styleguide/blob/fb056718f8e5d703797e83a3f9b0fe235b39aceb/packages/eslint-config-typescript/package.json#L34-L36 https://github.com/ni/javascript-styleguide/blob/fb056718f8e5d703797e83a3f9b0fe235b39aceb/packages/eslint-config-javascript/package.json#L32-L34

As a workaround you can push npm to resolve packages into the root by adding wildcard dependencies for the sub packages until it starts working, i.e.:

"devDependendencies": {
    "eslint": "<some_version>",
    "@ni/eslint-config-angular": "<some_version>",
    "@ni/eslint-config-typescript": "*"
}