Skip to content

Commit

Permalink
feat: enable features.typescript only when typescript is installe…
Browse files Browse the repository at this point in the history
…d locally, fix #437
  • Loading branch information
antfu committed Jul 27, 2024
1 parent ebc8f2c commit 77bc797
Show file tree
Hide file tree
Showing 6 changed files with 450 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-vue": "^9.27.0",
"globals": "^15.8.0",
"local-pkg": "^0.5.0",
"pathe": "^1.1.2",
"tslib": "^2.6.3",
"vue-eslint-parser": "^9.4.3"
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config/src/flat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function createConfigForNuxt(
ignores(),
javascript(),
// Make these imports async, as they are optional and imports plugins
import('./configs/typescript').then(m => m.default(resolved)),
resolved.features.typescript !== false
? import('./configs/typescript').then(m => m.default(resolved))
: undefined,
import('./configs/vue').then(m => m.default(resolved)),
import('./configs/import').then(m => m.default(resolved)),
)
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/flat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export interface NuxtESLintFeaturesOptions {
stylistic?: boolean | StylisticCustomizeOptions<true>

/**
* Options for TypeScript setup
* Enable TypeScript support. Can also be an object to config the options.
*
* @default true
* By default it enables automatic when `typescript` is installed in the project.
*/
typescript?: boolean | {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/src/flat/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isPackageExists } from 'local-pkg'
import type { NuxtESLintConfigOptions, NuxtESLintConfigOptionsResolved } from '../flat'

export function removeUndefined<T extends object>(obj: T): T {
Expand Down Expand Up @@ -31,7 +32,7 @@ export function resolveOptions(
features: {
standalone: true,
stylistic: false,
typescript: true,
typescript: isPackageExists('typescript'),
tooling: false,
...config.features,
},
Expand Down
5 changes: 5 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ export default defineNuxtConfig({
modules: [
'../packages/module/src/module',
],

devtools: {
enabled: true,
},

components: [
'~/components',
{ path: '~/components-prefixed', prefix: 'Prefix' },
],

eslint: {
config: {
stylistic: true,
Expand All @@ -18,4 +21,6 @@ export default defineNuxtConfig({
fix: true,
},
},

compatibilityDate: '2024-07-27',
})
Loading

1 comment on commit 77bc797

@Revadike
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.