Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add missing types in env API docs #1750

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions 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,
)

/**
* URL を id に解決してロードし、プラグインパイプラインを使ってコードを処理する。
* モジュールグラフも更新されます。
*/
async transformRequest(url: string): TransformResult
async transformRequest(url: string): Promise<TransformResult | null>

/**
* 低い優先度で処理されるリクエストを登録します。ウォーターフォールを回避するのに
* 役立ちます。Vite サーバーは他のリクエストによってインポートされたモジュールに関する
* 情報を持っているため、モジュールがリクエストされたときにすでに処理されているよう、
* モジュールグラフをウォームアップできます。
*/
async warmupRequest(url: string): void
async warmupRequest(url: string): Promise<void>
}
```

`TransformResult` は次のようになります:
`DevEnvironmentContext` は次のようになります:

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

そして `TransformResult` は:

```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 guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function createWorkerdDevEnvironment(
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>
/** 下記参照 */
type ModuleRunnerTransport = unknown

// ---cut---
interface ModuleRunnerOptions {
/**
* プロジェクトのルート
*/
Expand Down Expand Up @@ -206,7 +219,13 @@ export interface ModuleRunnerOptions {

**型シグネチャー:**

```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 {
/**
* 変換後のコードに含まれるプレフィックスの行数。
Expand Down Expand Up @@ -237,7 +256,11 @@ Vite はデフォルトでこのインターフェイスを実装した `ESModul

**型シグネチャー:**

```ts
```ts twoslash
import type { ModuleRunnerTransportHandlers } from 'vite/module-runner'
/** オブジェクト */
type HotPayload = unknown
// ---cut---
interface ModuleRunnerTransport {
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
disconnect?(): Promise<void> | void
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"devDependencies": {
"@shikijs/vitepress-twoslash": "^1.23.1",
"@type-challenges/utils": "^0.1.1",
"@types/express": "^4.17.21",
"@types/node": "^20.17.1",
"feed": "^4.2.2",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.