Skip to content

Commit

Permalink
refactor: keep the "runner" option in runnable dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 4, 2024
1 parent c7bf649 commit 2151347
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function createRunnableDevEnvironment(

export interface RunnableDevEnvironmentContext
extends Omit<DevEnvironmentContext, 'hot'> {
runner?: (
environment: RunnableDevEnvironment,
options?: ServerModuleRunnerOptions,
) => ModuleRunner
runnerOptions?: ServerModuleRunnerOptions
hot?: false | HotChannel
}
Expand All @@ -34,6 +38,12 @@ export function isRunnableDevEnvironment(

class RunnableDevEnvironment extends DevEnvironment {
private _runner: ModuleRunner | undefined
private _runnerFactory:
| ((
environment: RunnableDevEnvironment,
options?: ServerModuleRunnerOptions,
) => ModuleRunner)
| undefined
private _runnerOptions: ServerModuleRunnerOptions | undefined

constructor(
Expand All @@ -42,14 +52,16 @@ class RunnableDevEnvironment extends DevEnvironment {
context: RunnableDevEnvironmentContext,
) {
super(name, config, context as DevEnvironmentContext)
this._runnerFactory = context.runner
this._runnerOptions = context.runnerOptions
}

get runner(): ModuleRunner {
if (this._runner) {
return this._runner
}
this._runner = createServerModuleRunner(this, this._runnerOptions)
const factory = this._runnerFactory || createServerModuleRunner
this._runner = factory(this, this._runnerOptions)
return this._runner
}
}
Expand Down

0 comments on commit 2151347

Please sign in to comment.