Skip to content

Commit

Permalink
docs: add missing types in env API docs (#18767)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 26, 2024
1 parent 6252c60 commit db697ef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
30 changes: 26 additions & 4 deletions docs/guide/api-environment-instances.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,43 @@ class DevEnvironment {
*/
config: ResolvedConfig & ResolvedDevEnvironmentOptions

constructor(name, config, { hot, options }: DevEnvironmentSetup)
constructor(
name: string,
config: ResolvedConfig,
context: DevEnvironmentContext,
)

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

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

With `TransformResult` being:
With `DevEnvironmentContext` being:

```ts
interface DevEnvironmentContext {
hot: boolean
transport?: HotChannel | WebSocketServer
options?: EnvironmentOptions
remoteRunner?: {
inlineSourceMap?: boolean
}
depsOptimizer?: DepsOptimizer
}
```

and with `TransformResult` being:

```ts
interface TransformResult {
Expand Down Expand Up @@ -156,10 +174,14 @@ export class EnvironmentModuleGraph {
rawUrl: string,
): Promise<EnvironmentModuleNode | undefined>

getModuleById(id: string): EnvironmentModuleNode | undefined

getModulesByFile(file: string): Set<EnvironmentModuleNode> | undefined

onFileChange(file: string): void

onFileDelete(file: string): void

invalidateModule(
mod: EnvironmentModuleNode,
seen: Set<EnvironmentModuleNode> = new Set(),
Expand Down
33 changes: 28 additions & 5 deletions docs/guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ A module runner is instantiated in the target runtime. All APIs in the next sect
export class ModuleRunner {
constructor(
public options: ModuleRunnerOptions,
public evaluator: ModuleEvaluator,
public evaluator: ModuleEvaluator = new ESModulesEvaluator(),
private debug?: ModuleRunnerDebugger,
) {}
/**
Expand Down Expand Up @@ -165,8 +165,21 @@ await moduleRunner.import('/src/entry-point.js')

## `ModuleRunnerOptions`

```ts
export interface ModuleRunnerOptions {
```ts twoslash
import type {
InterceptorOptions as InterceptorOptionsRaw,
ModuleRunnerHmr as ModuleRunnerHmrRaw,
EvaluatedModules,
} from 'vite/module-runner'
import type { Debug } from '@type-challenges/utils'

type InterceptorOptions = Debug<InterceptorOptionsRaw>
type ModuleRunnerHmr = Debug<ModuleRunnerHmrRaw>
/** see below */
type ModuleRunnerTransport = unknown

// ---cut---
interface ModuleRunnerOptions {
/**
* Root of the project
*/
Expand Down Expand Up @@ -206,7 +219,13 @@ export interface ModuleRunnerOptions {

**Type Signature:**

```ts
```ts twoslash
import type { ModuleRunnerContext as ModuleRunnerContextRaw } from 'vite/module-runner'
import type { Debug } from '@type-challenges/utils'

type ModuleRunnerContext = Debug<ModuleRunnerContextRaw>

// ---cut---
export interface ModuleEvaluator {
/**
* Number of prefixed lines in the transformed code.
Expand Down Expand Up @@ -237,7 +256,11 @@ Vite exports `ESModulesEvaluator` that implements this interface by default. It

**Type Signature:**

```ts
```ts twoslash
import type { ModuleRunnerTransportHandlers } from 'vite/module-runner'
/** an object */
type HotPayload = unknown
// ---cut---
interface ModuleRunnerTransport {
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
disconnect?(): Promise<void> | void
Expand Down

0 comments on commit db697ef

Please sign in to comment.