Skip to content

Commit db697ef

Browse files
authored
docs: add missing types in env API docs (#18767)
1 parent 6252c60 commit db697ef

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

docs/guide/api-environment-instances.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,43 @@ class DevEnvironment {
6464
*/
6565
config: ResolvedConfig & ResolvedDevEnvironmentOptions
6666

67-
constructor(name, config, { hot, options }: DevEnvironmentSetup)
67+
constructor(
68+
name: string,
69+
config: ResolvedConfig,
70+
context: DevEnvironmentContext,
71+
)
6872

6973
/**
7074
* Resolve the URL to an id, load it, and process the code using the
7175
* plugins pipeline. The module graph is also updated.
7276
*/
73-
async transformRequest(url: string): TransformResult
77+
async transformRequest(url: string): Promise<TransformResult | null>
7478

7579
/**
7680
* Register a request to be processed with low priority. This is useful
7781
* to avoid waterfalls. The Vite server has information about the
7882
* imported modules by other requests, so it can warmup the module graph
7983
* so the modules are already processed when they are requested.
8084
*/
81-
async warmupRequest(url: string): void
85+
async warmupRequest(url: string): Promise<void>
8286
}
8387
```
8488

85-
With `TransformResult` being:
89+
With `DevEnvironmentContext` being:
90+
91+
```ts
92+
interface DevEnvironmentContext {
93+
hot: boolean
94+
transport?: HotChannel | WebSocketServer
95+
options?: EnvironmentOptions
96+
remoteRunner?: {
97+
inlineSourceMap?: boolean
98+
}
99+
depsOptimizer?: DepsOptimizer
100+
}
101+
```
102+
103+
and with `TransformResult` being:
86104

87105
```ts
88106
interface TransformResult {
@@ -156,10 +174,14 @@ export class EnvironmentModuleGraph {
156174
rawUrl: string,
157175
): Promise<EnvironmentModuleNode | undefined>
158176

177+
getModuleById(id: string): EnvironmentModuleNode | undefined
178+
159179
getModulesByFile(file: string): Set<EnvironmentModuleNode> | undefined
160180

161181
onFileChange(file: string): void
162182

183+
onFileDelete(file: string): void
184+
163185
invalidateModule(
164186
mod: EnvironmentModuleNode,
165187
seen: Set<EnvironmentModuleNode> = new Set(),

docs/guide/api-environment-runtimes.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ A module runner is instantiated in the target runtime. All APIs in the next sect
118118
export class ModuleRunner {
119119
constructor(
120120
public options: ModuleRunnerOptions,
121-
public evaluator: ModuleEvaluator,
121+
public evaluator: ModuleEvaluator = new ESModulesEvaluator(),
122122
private debug?: ModuleRunnerDebugger,
123123
) {}
124124
/**
@@ -165,8 +165,21 @@ await moduleRunner.import('/src/entry-point.js')
165165

166166
## `ModuleRunnerOptions`
167167

168-
```ts
169-
export interface ModuleRunnerOptions {
168+
```ts twoslash
169+
import type {
170+
InterceptorOptions as InterceptorOptionsRaw,
171+
ModuleRunnerHmr as ModuleRunnerHmrRaw,
172+
EvaluatedModules,
173+
} from 'vite/module-runner'
174+
import type { Debug } from '@type-challenges/utils'
175+
176+
type InterceptorOptions = Debug<InterceptorOptionsRaw>
177+
type ModuleRunnerHmr = Debug<ModuleRunnerHmrRaw>
178+
/** see below */
179+
type ModuleRunnerTransport = unknown
180+
181+
// ---cut---
182+
interface ModuleRunnerOptions {
170183
/**
171184
* Root of the project
172185
*/
@@ -206,7 +219,13 @@ export interface ModuleRunnerOptions {
206219

207220
**Type Signature:**
208221

209-
```ts
222+
```ts twoslash
223+
import type { ModuleRunnerContext as ModuleRunnerContextRaw } from 'vite/module-runner'
224+
import type { Debug } from '@type-challenges/utils'
225+
226+
type ModuleRunnerContext = Debug<ModuleRunnerContextRaw>
227+
228+
// ---cut---
210229
export interface ModuleEvaluator {
211230
/**
212231
* Number of prefixed lines in the transformed code.
@@ -237,7 +256,11 @@ Vite exports `ESModulesEvaluator` that implements this interface by default. It
237256

238257
**Type Signature:**
239258

240-
```ts
259+
```ts twoslash
260+
import type { ModuleRunnerTransportHandlers } from 'vite/module-runner'
261+
/** an object */
262+
type HotPayload = unknown
263+
// ---cut---
241264
interface ModuleRunnerTransport {
242265
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
243266
disconnect?(): Promise<void> | void

0 commit comments

Comments
 (0)