diff --git a/guide/api-environment-instances.md b/guide/api-environment-instances.md index 7d078e9d..893b967a 100644 --- a/guide/api-environment-instances.md +++ b/guide/api-environment-instances.md @@ -64,13 +64,17 @@ 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 /** * 低い優先度で処理されるリクエストを登録します。ウォーターフォールを回避するのに @@ -78,11 +82,25 @@ class DevEnvironment { * 情報を持っているため、モジュールがリクエストされたときにすでに処理されているよう、 * モジュールグラフをウォームアップできます。 */ - async warmupRequest(url: string): void + async warmupRequest(url: string): Promise } ``` -`TransformResult` は次のようになります: +`DevEnvironmentContext` は次のようになります: + +```ts +interface DevEnvironmentContext { + hot: boolean + transport?: HotChannel | WebSocketServer + options?: EnvironmentOptions + remoteRunner?: { + inlineSourceMap?: boolean + } + depsOptimizer?: DepsOptimizer +} +``` + +そして `TransformResult` は: ```ts interface TransformResult { @@ -156,10 +174,14 @@ export class EnvironmentModuleGraph { rawUrl: string, ): Promise + getModuleById(id: string): EnvironmentModuleNode | undefined + getModulesByFile(file: string): Set | undefined onFileChange(file: string): void + onFileDelete(file: string): void + invalidateModule( mod: EnvironmentModuleNode, seen: Set = new Set(), diff --git a/guide/api-environment-runtimes.md b/guide/api-environment-runtimes.md index 5c704617..278f8e95 100644 --- a/guide/api-environment-runtimes.md +++ b/guide/api-environment-runtimes.md @@ -118,7 +118,7 @@ function createWorkerdDevEnvironment( export class ModuleRunner { constructor( public options: ModuleRunnerOptions, - public evaluator: ModuleEvaluator, + public evaluator: ModuleEvaluator = new ESModulesEvaluator(), private debug?: ModuleRunnerDebugger, ) {} /** @@ -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 +type ModuleRunnerHmr = Debug +/** 下記参照 */ +type ModuleRunnerTransport = unknown + +// ---cut--- +interface ModuleRunnerOptions { /** * プロジェクトのルート */ @@ -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 + +// ---cut--- export interface ModuleEvaluator { /** * 変換後のコードに含まれるプレフィックスの行数。 @@ -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 disconnect?(): Promise | void diff --git a/package.json b/package.json index dcc0390c..4333f796 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 99ae0b04..f79e4ef6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@shikijs/vitepress-twoslash': specifier: ^1.23.1 version: 1.23.1(typescript@5.4.5) + '@type-challenges/utils': + specifier: ^0.1.1 + version: 0.1.1 '@types/express': specifier: ^4.17.21 version: 4.17.21 @@ -767,6 +770,9 @@ packages: '@textlint/utils@13.4.1': resolution: {integrity: sha512-wX8RT1ejHAPTDmqlzngf0zI5kYoe3QvGDcj+skoTxSv+m/wOs/NyEr92d+ahCP32YqFYzXlqU7aDx2FkULKT+g==} + '@type-challenges/utils@0.1.1': + resolution: {integrity: sha512-A7ljYfBM+FLw+NDyuYvGBJiCEV9c0lPWEAdzfOAkb3JFqfLl0Iv/WhWMMARHiRKlmmiD1g8gz/507yVvHdQUYA==} + '@types/body-parser@1.19.5': resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} @@ -3517,6 +3523,8 @@ snapshots: '@textlint/utils@13.4.1': {} + '@type-challenges/utils@0.1.1': {} + '@types/body-parser@1.19.5': dependencies: '@types/connect': 3.4.38