Skip to content

Commit

Permalink
feat: option to disable next types plugin (#76300)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Feb 21, 2025
1 parent 74c99d2 commit 1708497
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/next/src/server/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ function createServer(
'typescript' in options &&
'version' in (options as any).typescript
) {
return require('./next-typescript').createTSPlugin(options)
const pluginMod: typeof import('./next-typescript') = require('./next-typescript')
return pluginMod.createTSPlugin(
options as any
) as unknown as NextWrapperServer
}

if (options == null) {
Expand Down
11 changes: 11 additions & 0 deletions packages/next/src/server/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import metadata from './rules/metadata'
import errorEntry from './rules/error'
import type tsModule from 'typescript/lib/tsserverlibrary'

type NextTypePluginOptions = {
enabled?: boolean
}

export const createTSPlugin: tsModule.server.PluginModuleFactory = ({
typescript: ts,
}) => {
Expand All @@ -44,6 +48,13 @@ export const createTSPlugin: tsModule.server.PluginModuleFactory = ({
proxy[k] = (...args: Array<{}>) => x.apply(info.languageService, args)
}

const pluginOptions: NextTypePluginOptions = info.config ?? {
enabled: true,
}
if (!pluginOptions.enabled) {
return proxy
}

// Auto completion
proxy.getCompletionsAtPosition = (
fileName: string,
Expand Down

0 comments on commit 1708497

Please # to comment.