Skip to content

Commit 07171ef

Browse files
committed
[Fix] no-duplicates: do not unconditionally require typescript
Fixes #2665
1 parent 167f16c commit 07171ef

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
66

77
## [Unreleased]
88

9+
### Fixed
10+
- [`no-duplicates`]: do not unconditionally require `typescript` ([#2665])
11+
912
## [2.27.1] - 2023-01-11
1013

1114
### Fixed
@@ -1361,6 +1364,7 @@ for info on changes for earlier releases.
13611364
[#211]: https://github.com/import-js/eslint-plugin-import/pull/211
13621365
[#164]: https://github.com/import-js/eslint-plugin-import/pull/164
13631366
[#157]: https://github.com/import-js/eslint-plugin-import/pull/157
1367+
[#2665]: https://github.com/import-js/eslint-plugin-import/issues/2665
13641368
[#2444]: https://github.com/import-js/eslint-plugin-import/issues/2444
13651369
[#2412]: https://github.com/import-js/eslint-plugin-import/issues/2412
13661370
[#2392]: https://github.com/import-js/eslint-plugin-import/issues/2392

src/rules/no-duplicates.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import resolve from 'eslint-module-utils/resolve';
22
import docsUrl from '../docsUrl';
33
import semver from 'semver';
4-
import typescriptPkg from 'typescript/package.json';
4+
5+
let typescriptPkg;
6+
try {
7+
typescriptPkg = require('typescript/package.json');
8+
} catch (e) { /**/ }
59

610
function checkImports(imported, context) {
711
for (const [module, nodes] of imported.entries()) {
@@ -114,7 +118,7 @@ function getFix(first, rest, sourceCode, context) {
114118

115119
const preferInline = context.options[0] && context.options[0]['prefer-inline'];
116120
// a user might set prefer-inline but not have a supporting TypeScript version. Flow does not support inline types so this should fail in that case as well.
117-
if (preferInline && !semver.satisfies(typescriptPkg.version, '>= 4.5')) {
121+
if (preferInline && (!typescriptPkg || !semver.satisfies(typescriptPkg.version, '>= 4.5'))) {
118122
throw new Error('Your version of TypeScript does not support inline type imports.');
119123
}
120124

0 commit comments

Comments
 (0)