From 1b3cd8e5c1dc93693c014b63b8d05a1506fc03b4 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Wed, 22 Jun 2022 00:54:05 +0900 Subject: [PATCH 1/2] fix: avoid type mismatch with Rollup (fix #7843) TS2430 appears when using `skipLibCheck: false` --- packages/vite/src/node/plugin.ts | 3 ++- packages/vite/tsconfig.check.json | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 40845bf1f2dcfc..053878a826f036 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -37,7 +37,8 @@ import type { ConfigEnv, ResolvedConfig } from './' * If a plugin should be applied only for server or build, a function format * config file can be used to conditional determine the plugins to use. */ -export interface Plugin extends RollupPlugin { +export interface Plugin + extends Omit { /** * Enforce plugin invocation tier similar to webpack loaders. * diff --git a/packages/vite/tsconfig.check.json b/packages/vite/tsconfig.check.json index cd8f8d6eeb3f2c..d1e9f059c9409c 100644 --- a/packages/vite/tsconfig.check.json +++ b/packages/vite/tsconfig.check.json @@ -14,7 +14,9 @@ // indirect: postcss depends on it "source-map-js": ["./node_modules/source-map-js/source-map.d.ts"] }, - "typeRoots": [] + "typeRoots": [], + "strict": true, + "exactOptionalPropertyTypes": true }, "include": ["dist/**/*.d.ts"] } From 6c4fe1fda6300753cb6a799b72c46c2103804899 Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Thu, 23 Jun 2022 22:54:56 +0900 Subject: [PATCH 2/2] types: prefer property and pass isEntry rather than omit https://github.com/vitejs/vite/pull/8701#issuecomment-1164273773 --- packages/vite/src/node/plugin.ts | 16 ++++++++-------- packages/vite/src/node/server/pluginContainer.ts | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/plugin.ts b/packages/vite/src/node/plugin.ts index 053878a826f036..69b19415b0daa7 100644 --- a/packages/vite/src/node/plugin.ts +++ b/packages/vite/src/node/plugin.ts @@ -37,8 +37,7 @@ import type { ConfigEnv, ResolvedConfig } from './' * If a plugin should be applied only for server or build, a function format * config file can be used to conditional determine the plugins to use. */ -export interface Plugin - extends Omit { +export interface Plugin extends RollupPlugin { /** * Enforce plugin invocation tier similar to webpack loaders. * @@ -129,7 +128,7 @@ export interface Plugin /** * extend hooks with ssr flag */ - resolveId?( + resolveId?: ( this: PluginContext, source: string, importer: string | undefined, @@ -140,17 +139,18 @@ export interface Plugin * @internal */ scan?: boolean + isEntry: boolean } - ): Promise | ResolveIdResult - load?( + ) => Promise | ResolveIdResult + load?: ( this: PluginContext, id: string, options?: { ssr?: boolean } - ): Promise | LoadResult - transform?( + ) => Promise | LoadResult + transform?: ( this: TransformPluginContext, code: string, id: string, options?: { ssr?: boolean } - ): Promise | TransformResult + ) => Promise | TransformResult } diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 86dcefe024542f..0a708ed62c4e6c 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -97,6 +97,7 @@ export interface PluginContainer { * @internal */ scan?: boolean + isEntry?: boolean } ): Promise transform( @@ -527,6 +528,7 @@ export async function createPluginContainer( const skip = options?.skip const ssr = options?.ssr const scan = !!options?.scan + const isEntry = !!options?.isEntry const ctx = new Context() ctx.ssr = !!ssr ctx._scan = scan @@ -546,7 +548,7 @@ export async function createPluginContainer( ctx as any, rawId, importer, - { ssr, scan } + { ssr, scan, isEntry } ) if (!result) continue