-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore: remove peerDep on typescript #443
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
Conversation
Just interesting, why is |
I left the ESLint peer dep in because that is a hard peer dependency for us, which we do not check at runtime (though nothing will actually work if they don't install it, so it's not really necessary to list it). On the other hand, we have runtime checks for Typescript in the form of imports (which will hard fail if it's not installed), and also the unsupported version log message. IIRC - we don't list it as a full dependency so that we don't accidentally create additional versions in the module folder tree. In regards to CRA - eslint is installed by default by CRA, so that will never warn - but typescript is only installed if it's used. Which means for non-ts users of CRA, they'll continually see the peer dep warning, even though they don't actually need it as a dep. |
Thank you for elaboration.
and others. |
On the other hand, our packages are used from ESLint, but these don't import |
Yeah exactly! We have a hard dependency on typescript from within all 3 packages IIRC (eslint-plugin, parser and typescript-eslint). However we purposely do not list it as a dependency so we don't force users onto a specific version, and so we don't cause two versions to be installed into the tree. If the end user tries to use any package without typescript installed, every package will hard fail on them. Considering it was a peerDependency, it is already optional in yarn/npm's eyes, so it means there's no a big difference between listing it and not. So the only difference between listing it as a peerDependency and not is this: if we list it, yarn/npm will log a warning at install time (which most people ignore anyways). |
Ahh, I had misunderstood what you are saying. I understand now. Thank you! |
One consequence of this change is that
However, I don't believe NPM respects this field (yet?), so the warning would still be there for NPM users. |
@edsrzf - are you sure? Reading the documentation for pnp: https://yarnpkg.com/en/docs/pnp/troubleshooting
Ofc it does mention that
It's a shame that we can't "properly" support it, but if we specify the peer dep explicitly then npm consumers of tools like react-create-app would still get warnings. |
I confirm what @edsrzf says; this change breaks the support for Yarn PNP :
I'm trying to understand the reasoning here. It seems, according to this thread there are two options:
And your conclusion is to break the package for all those who rely on Yarn PNP ? @edsrzf offered a solution that would display the warning only if the users uses NPM and don't use TypeScript. It's not perfect as it still shows the warning to these users, but at least it doesn't break the package on purpose for others... Can you please revert this change ? |
According to the linked yarn pnp docs, if it is listed in the dependencies of your package, then pnp should allow it to work.
Like I said before; if (/when) NPM implements this mechanism; then we can definitely add it in and revert this change with it. |
In the case of yarn workspaces the top-level might not have a dependency to typescript as in this context the app is most likely a sub-package. |
Otherwise, would it be possible to give an instance of TypeScript as an option to the rule that would be passed around ? |
couldn't you just For example, the only package in this repo that references the We could potentially add an option to pass in the pre-required typescript module, though I think it would only ever be useful in this specific case. |
In my specific case, I created a shared ESLint configuration that doesn't need the plugins installed in the root package as they are embedded (https://github.com/swissquote/crafty/tree/master/packages/eslint-plugin-swissquote, more specifically : https://github.com/swissquote/crafty/blob/master/packages/eslint-plugin-swissquote/src/utils.js#L1-L17 and https://github.com/swissquote/crafty/blob/master/packages/eslint-plugin-swissquote/src/best-practices.js#L92-L95 ) So that means that when someone installs this shared config/plugin, they get all the dependencies installed with it as it is expected for most npm packages. There are many tools that accept receiving plugins/ libraries as options, for example webpack's loader configuration, ts-loader's TypeScript configuration, Jest transformers, ESLint's parsers |
Wait, why wouldn't |
looking at your repo - why did you create a plugin for it, instead of just a config? The problem with creating a plugin which absorbs the rules like you've done is that people could configure rules twice - once with the real rule name, and once with your namespaced rule name, because those packages are available to npm regardless. In this case though, people should have typescript installed as a direct dependency of their project, because they will need access to the typescript compiler locally. In which case |
True, I could have made a config, but I currently expose the rules of the other plugins, and the difference is, to my knowledge, only semantic
I'm well aware that this is not an ideal solution, and the However I'm waiting for release of ESLint 6 containing eslint/eslint#11388 discussed in eslint/rfcs#7 to loading plugins and configurations relative to where they are defined. Which removes the need to add the dependency to the plugin in addition to the config
Yes it's a very useful feature to modify a dependency, but can only be of used if the dependency is here, it won't help if the dependency isn't specified |
See: facebook/create-react-app#6834