-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
feat: introduce RunnableDevEnvironment #18190
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
Merged
patak-dev
merged 10 commits into
vitejs:main
from
sheremet-va:feat/runnable-dev-environment
Sep 27, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
faf5148
feat: introduce RunnableDevEnvironment
sheremet-va af9fb34
docs: update
sheremet-va cac982f
chore: cleanup
sheremet-va f5b9612
refactor: remove environment.import
sheremet-va 1182c73
docs: add RunnableDevEnvironment to docs
sheremet-va 13546d5
fix: make "runner" eager
sheremet-va dd6e3d5
fix: allow any environment in isRunnableDevEnvironment
sheremet-va 9ede269
chore: rename "runnerOptions" to "remoteRunner"
sheremet-va 4ca025a
refactor: remove hot from default ssr env
sheremet-va 8d53a09
docs: clarify
sheremet-va File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
packages/vite/src/node/server/environments/nodeEnvironment.ts
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
packages/vite/src/node/server/environments/runnableEnvironment.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { ModuleRunner } from 'vite/module-runner' | ||
import type { ResolvedConfig } from '../../config' | ||
import type { DevEnvironmentContext } from '../environment' | ||
import { DevEnvironment } from '../environment' | ||
import { createServerModuleRunner } from '../../ssr/runtime/serverModuleRunner' | ||
import type { HotChannel } from '../hmr' | ||
import { createServerHotChannel } from '../hmr' | ||
import type { Environment } from '../../environment' | ||
|
||
export function createRunnableDevEnvironment( | ||
name: string, | ||
config: ResolvedConfig, | ||
context: RunnableDevEnvironmentContext = {}, | ||
): DevEnvironment { | ||
if (context.hot == null) { | ||
context.hot = createServerHotChannel() | ||
} | ||
|
||
return new RunnableDevEnvironment(name, config, context) | ||
} | ||
|
||
export interface RunnableDevEnvironmentContext | ||
extends Omit<DevEnvironmentContext, 'hot'> { | ||
runner?: (environment: RunnableDevEnvironment) => ModuleRunner | ||
hot?: false | HotChannel | ||
} | ||
|
||
export function isRunnableDevEnvironment( | ||
environment: Environment, | ||
): environment is RunnableDevEnvironment { | ||
return environment instanceof RunnableDevEnvironment | ||
} | ||
|
||
class RunnableDevEnvironment extends DevEnvironment { | ||
private _runner: ModuleRunner | undefined | ||
private _runnerFactory: | ||
| ((environment: RunnableDevEnvironment) => ModuleRunner) | ||
| undefined | ||
|
||
constructor( | ||
name: string, | ||
config: ResolvedConfig, | ||
context: RunnableDevEnvironmentContext, | ||
) { | ||
super(name, config, context as DevEnvironmentContext) | ||
this._runnerFactory = context.runner | ||
} | ||
|
||
get runner(): ModuleRunner { | ||
if (this._runner) { | ||
return this._runner | ||
} | ||
if (this._runnerFactory) { | ||
this._runner = this._runnerFactory(this) | ||
return this._runner | ||
} | ||
return createServerModuleRunner(this) | ||
} | ||
} | ||
|
||
export type { RunnableDevEnvironment } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.