Skip to content

Commit 77bc797

Browse files
committedJul 27, 2024··
feat: enable features.typescript only when typescript is installed locally, fix #437
1 parent ebc8f2c commit 77bc797

File tree

6 files changed

+450
-23
lines changed

6 files changed

+450
-23
lines changed
 

‎packages/eslint-config/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"eslint-plugin-unicorn": "^55.0.0",
6666
"eslint-plugin-vue": "^9.27.0",
6767
"globals": "^15.8.0",
68+
"local-pkg": "^0.5.0",
6869
"pathe": "^1.1.2",
6970
"tslib": "^2.6.3",
7071
"vue-eslint-parser": "^9.4.3"

‎packages/eslint-config/src/flat/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export function createConfigForNuxt(
4646
ignores(),
4747
javascript(),
4848
// Make these imports async, as they are optional and imports plugins
49-
import('./configs/typescript').then(m => m.default(resolved)),
49+
resolved.features.typescript !== false
50+
? import('./configs/typescript').then(m => m.default(resolved))
51+
: undefined,
5052
import('./configs/vue').then(m => m.default(resolved)),
5153
import('./configs/import').then(m => m.default(resolved)),
5254
)

‎packages/eslint-config/src/flat/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export interface NuxtESLintFeaturesOptions {
5050
stylistic?: boolean | StylisticCustomizeOptions<true>
5151

5252
/**
53-
* Options for TypeScript setup
53+
* Enable TypeScript support. Can also be an object to config the options.
5454
*
55-
* @default true
55+
* By default it enables automatic when `typescript` is installed in the project.
5656
*/
5757
typescript?: boolean | {
5858
/**

‎packages/eslint-config/src/flat/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isPackageExists } from 'local-pkg'
12
import type { NuxtESLintConfigOptions, NuxtESLintConfigOptionsResolved } from '../flat'
23

34
export function removeUndefined<T extends object>(obj: T): T {
@@ -31,7 +32,7 @@ export function resolveOptions(
3132
features: {
3233
standalone: true,
3334
stylistic: false,
34-
typescript: true,
35+
typescript: isPackageExists('typescript'),
3536
tooling: false,
3637
...config.features,
3738
},

‎playground/nuxt.config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ export default defineNuxtConfig({
22
modules: [
33
'../packages/module/src/module',
44
],
5+
56
devtools: {
67
enabled: true,
78
},
9+
810
components: [
911
'~/components',
1012
{ path: '~/components-prefixed', prefix: 'Prefix' },
1113
],
14+
1215
eslint: {
1316
config: {
1417
stylistic: true,
@@ -18,4 +21,6 @@ export default defineNuxtConfig({
1821
fix: true,
1922
},
2023
},
24+
25+
compatibilityDate: '2024-07-27',
2126
})

‎pnpm-lock.yaml

+437-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

1 commit comments

Comments
 (1)

Revadike commented on Aug 22, 2024

@Revadike
Please sign in to comment.