Skip to content

Commit

Permalink
refactor: rename createSsrEnvironment to createNodeEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Mar 25, 2024
1 parent f29e95a commit c9abcfc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
18 changes: 13 additions & 5 deletions packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ export { optimizeDeps } from './optimizer'
export { formatPostcssSourceMap, preprocessCSS } from './plugins/css'
export { transformWithEsbuild } from './plugins/esbuild'
export { buildErrorMessage } from './server/middlewares/error'
export { fetchModule } from './ssr/fetchModule'
export type { FetchModuleOptions } from './ssr/fetchModule'

export { RemoteEnvironmentTransport } from './server/environmentTransport'
export { createNodeEnvironment } from './server/environments/nodeEnvironment'
export {
DevEnvironment,
type DevEnvironmentOptions,
} from './server/environment'
export { BuildEnvironment } from './build'

export { fetchModule, type FetchModuleOptions } from './ssr/fetchModule'
export { createServerModuleRunner } from './ssr/runtime/serverModuleRunner'
export { ServerHMRConnector } from './ssr/runtime/serverHmrConnector'

export * from './publicUtils'

// additional types
Expand Down Expand Up @@ -118,7 +129,6 @@ export type {
EnvironmentModuleNode,
ResolvedUrl,
} from './server/moduleGraph'
export { RemoteEnvironmentTransport } from './server/environmentTransport'
export type { SendOptions } from './server/send'
export type { ProxyOptions } from './server/middlewares/proxy'
export type {
Expand All @@ -135,9 +145,7 @@ export type {
} from './server/hmr'

export type { FetchFunction, FetchResult } from 'vite/module-runner'
export { createServerModuleRunner } from './ssr/runtime/serverModuleRunner'
export type { ServerModuleRunnerOptions } from './ssr/runtime/serverModuleRunner'
export { ServerHMRConnector } from './ssr/runtime/serverHmrConnector'

export type { BindCLIShortcutsOptions, CLIShortcut } from './shortcuts'

Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import type { TransformResult } from './transformRequest'
import { ERR_CLOSED_SERVER } from './pluginContainer'
import type { RemoteEnvironmentTransport } from './environmentTransport'

export interface DevEnvironmentOptions {
hot?: false | HMRChannel
config?: DevEnvironmentConfig
runner?: FetchModuleOptions & {
transport?: RemoteEnvironmentTransport
}
}

// Maybe we will rename this to DevEnvironment
export class DevEnvironment extends Environment {
mode = 'dev' as const // TODO: should this be 'serve'?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { DevEnvironmentOptions } from '../environment';
import { DevEnvironment } from '../environment'
import type { ServerHMRChannel } from '../hmr'
import type { ViteDevServer } from '../index'
import { asyncFunctionDeclarationPaddingLineCount } from '../../../shared/utils'

export function createSsrEnvironment(
export function createNodeEnvironment(
server: ViteDevServer,
name: string,
hotChannel: ServerHMRChannel,
options?: DevEnvironmentOptions,
): DevEnvironment {
return new DevEnvironment(server, name, {
hot: hotChannel,
...options,
runner: {
processSourceMap(map) {
// this assumes that "new AsyncFunction" is used to create the module
Expand All @@ -18,6 +18,7 @@ export function createSsrEnvironment(
';'.repeat(asyncFunctionDeclarationPaddingLineCount) + map.mappings,
})
},
...options?.runner,
},
})
}
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { transformRequest } from './transformRequest'
import { searchForWorkspaceRoot } from './searchRoot'
import { warmupFiles } from './warmup'
import { DevEnvironment } from './environment'
import { createSsrEnvironment } from './environments/ssrEnvironment'
import { createNodeEnvironment } from './environments/nodeEnvironment'

export interface ServerOptions extends CommonServerOptions {
/**
Expand Down Expand Up @@ -775,7 +775,7 @@ export async function _createServer(
const ssr_createEnvironment =
config.environments.ssr?.dev?.createEnvironment ??
((server: ViteDevServer, name: string) =>
createSsrEnvironment(server, name, ssrHotChannel))
createNodeEnvironment(server, name, { hot: ssrHotChannel }))

environments.ssr = ssr_createEnvironment(server, 'ssr')

Expand Down

0 comments on commit c9abcfc

Please sign in to comment.