Skip to content

Commit

Permalink
chore(eslint-config): mark typescript as a peer dependency
Browse files Browse the repository at this point in the history
This isn't _strictly_ necessary, but it is an accurate description of
the requirements of the project. We go with the range of "^3.6.3" to
match the lowest range that we're currently using in any project (which
is found in liferay-js-toolkit), to minimize the risk of introducing
duplicates in a consuming project.

If you have a ".ts" file in your project, you are going to have
`typescript` in your `devDependencies`, and our `overrides`
configuration is going to use `@typescript-eslint/parser`, which in turn
is going to require `typescript`, transitively, in
`@typescript-eslint/typescript-estree` here:

https://github.com/typescript-eslint/typescript-eslint/blob/c5ffe8833da7875e82953de117b0abe6fa8a60b0/packages/typescript-estree/src/parser.ts#L2

And all will work, even though `@typescript-eslint/typescript-estree`
doesn't explicitly declare its hard dependency on `typescript` in its
package.json:

https://github.com/typescript-eslint/typescript-eslint/blob/c5ffe8833da7875e82953de117b0abe6fa8a60b0/packages/typescript-estree/package.json#L41-L49

But if you don't have any ".ts", then you shouldn't need to have
`typescript` in your dependency graph, and we won't use
`@typescript/eslint-parser`. So, it makes sense for us to call this an
`peerDependency` and mark it as `optional` as per these posts:

- https://medium.com/@noamgjacobsonknzi/what-is-peerdependenciesmeta-acea887c32dd
- npm/cli#1247

(Note that the `peerDependenciesMeta` field isn't documented yet.)

You could also argue that this should be under `optionalDependencies`:

https://docs.npmjs.com/files/package.json#optionaldependencies

But I think "optional peer" comes closer to the reality here.
`optionalDependencies` is for things that you can add, but the package
should work if they're not there. That's not the case here. The package
won't work if you have ".ts" files but no `typescript`.

Related: #91 (comment)
  • Loading branch information
wincent committed Oct 5, 2020
1 parent ea369b8 commit 6d37f01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion projects/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"main": "index.js",
"name": "@liferay/eslint-config",
"peerDependencies": {
"eslint": ">=4.1.1"
"eslint": ">=4.1.1",
"typescript": "^3.6.3"
},
"repository": {
"directory": "projects/eslint-config",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16044,6 +16044,11 @@ typescript@4.0.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==

typescript@^3.6.3:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

unc-path-regex@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
Expand Down

0 comments on commit 6d37f01

Please sign in to comment.