hudochenkov / stylelint-order

A plugin pack of order related linting rules for Stylelint.
MIT License
916 stars 61 forks source link

Move stylelint from dependencies to peerDependencies #40

Closed ybiquitous closed 7 years ago

ybiquitous commented 7 years ago

If package.json is below,

{
  "devDependencies": {
    "stylelint": "^8.0.0",
    "stylelint-config-standard": "^17.0.0",
    "stylelint-order": "0.5.0"
  }
}

then two different versions of stylelint are installed.

$ npm install
# ...
$ npm ls | grep stylelint@
├─┬ stylelint@8.0.0
  └─┬ stylelint@7.13.0
hudochenkov commented 7 years ago

Use stylelint-order@0.6.0. It's updated for stylelint@8.0.0.

ybiquitous commented 7 years ago

@hudochenkov

Thanks a lot for your rapid response.

Like stylelint-config-standard, I think that all stylelint plugins and configs should have as peerDependencies not as dependencies.

If stylelint will be updated to 9.0.0 in future, then unexpectedly two different versions of stylelint will be installed. (like when it updated to 8.0.0 recently)

https://github.com/stylelint/stylelint-config-standard/blob/9fb357825ae3b7d3c31935f7254674b035dd2875/package.json#L36

{
  "peerDependencies": {
    "stylelint": "^8.0.0"
  }
}

What do you think about this?

hudochenkov commented 7 years ago

@ybiquitous stylelint plugins are coupled tighter to stylelint itself then config. For example, to update from v7 to v8 there were more changes than just updating package.json. So it's not safe to list stylelint as a peer dependency for stylelint plugins.

ybiquitous commented 7 years ago

@hudochenkov

I can understand your thoughts, but the peerDependencies method can ensure safety.

For example, stylelint-scss plugin uses peerDependencies.

https://github.com/kristerkari/stylelint-scss/blob/ac23d7b6a762cb8f6831280321574c849533d80f/package.json#L42

{
  "peerDependencies": {
    "stylelint": "^8.0.0"
  }
}

To list as peerDependencies makes it possible that plugin's user will specify any version of stylelint.

Additionally when plugin's user will install a different version from version of peerDependencies, npm will output warning.

$ npm install
npm WARN stylelint-order@0.6.0 requires a peer of stylelint@^8.0.0 but none was installed.

Quoted from the npm official documentation:

In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.

ESLint also adopts this peerDependencies method. (see http://eslint.org/docs/developer-guide/working-with-plugins#peer-dependency)

ntwb commented 7 years ago

Sounds like we should document this in the stylelint docs https://github.com/stylelint/stylelint

@ybiquitous Can you create a stylelint issue for this also please?

ybiquitous commented 7 years ago

@ntwb I created stylelint/stylelint#2812. Please check it! 😄

hudochenkov commented 7 years ago

@ybiquitous Just released 0.7.0 with stylelint in peerDependencies. Sorry I didn't listen to you earlier.

ybiquitous commented 7 years ago

@hudochenkov Thanks a lot! 😄 👏