Skip to content

Commit c1279e7

Browse files
authored
feat: add removeServerPluginContainer future deprecation (#20437)
1 parent 8c8f587 commit c1279e7

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

docs/changes/per-environment-apis.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The `Environment` instance was first introduced at `v6.0`. The deprecation of `s
1414
```ts
1515
future: {
1616
removeServerModuleGraph: 'warn',
17+
removeServerPluginContainer: 'warn',
1718
removeServerTransformRequest: 'warn',
1819
removeServerWarmupRequest: 'warn',
1920
}
@@ -30,5 +31,6 @@ In Vite v6, it is now possible to create any number of custom environments (`cli
3031
## Migration Guide
3132

3233
- `server.moduleGraph` -> [`environment.moduleGraph`](/guide/api-environment-instances#separate-module-graphs)
34+
- `server.pluginContainer` -> `environment.pluginContainer`
3335
- `server.transformRequest(url, ssr)` -> `environment.transformRequest(url)`
3436
- `server.warmupRequest(url, ssr)` -> `environment.warmupRequest(url)`

packages/vite/src/node/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ export interface FutureOptions {
483483
removePluginHookSsrArgument?: 'warn'
484484

485485
removeServerModuleGraph?: 'warn'
486+
removeServerPluginContainer?: 'warn'
486487
removeServerHot?: 'warn'
487488
removeServerTransformRequest?: 'warn'
488489
removeServerWarmupRequest?: 'warn'

packages/vite/src/node/deprecations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const deprecationCode = {
88
removePluginHookHandleHotUpdate: 'changes/hotupdate-hook',
99

1010
removeServerModuleGraph: 'changes/per-environment-apis',
11+
removeServerPluginContainer: 'changes/per-environment-apis',
1112
removeServerHot: 'changes/per-environment-apis',
1213
removeServerTransformRequest: 'changes/per-environment-apis',
1314
removeServerWarmupRequest: 'changes/per-environment-apis',
@@ -23,6 +24,8 @@ const deprecationMessages = {
2324

2425
removeServerModuleGraph:
2526
'The `server.moduleGraph` is replaced with `this.environment.moduleGraph`.',
27+
removeServerPluginContainer:
28+
'The `server.pluginContainer` is replaced with `this.environment.pluginContainer`.',
2629
removeServerHot: 'The `server.hot` is replaced with `this.environment.hot`.',
2730
removeServerTransformRequest:
2831
'The `server.transformRequest` is replaced with `this.environment.transformRequest`.',

packages/vite/src/node/server/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ export async function _createServer(
531531
client: () => environments.client.moduleGraph,
532532
ssr: () => environments.ssr.moduleGraph,
533533
})
534-
const pluginContainer = createPluginContainer(environments)
534+
let pluginContainer = createPluginContainer(environments)
535535

536536
const closeHttpServer = createServerCloseFn(httpServer)
537537

@@ -568,7 +568,13 @@ export async function _createServer(
568568
hot: ws,
569569

570570
environments,
571-
pluginContainer,
571+
get pluginContainer() {
572+
warnFutureDeprecation(config, 'removeServerPluginContainer')
573+
return pluginContainer
574+
},
575+
set pluginContainer(p) {
576+
pluginContainer = p
577+
},
572578
get moduleGraph() {
573579
warnFutureDeprecation(config, 'removeServerModuleGraph')
574580
return moduleGraph

packages/vite/src/node/server/middlewares/indexHtml.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ const devHtmlHook: IndexHtmlTransformHook = async (
383383
)
384384
ensureWatchedFile(watcher, mod.file, config.root)
385385

386-
const result = await server!.pluginContainer.transform(code, mod.id!, {
387-
environment: server!.environments.client,
388-
})
386+
const result =
387+
await server!.environments.client.pluginContainer.transform(
388+
code,
389+
mod.id!,
390+
)
389391
let content = ''
390392
if (result.map && 'version' in result.map) {
391393
if (result.map.mappings) {
@@ -408,9 +410,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
408410
)
409411
ensureWatchedFile(watcher, mod.file, config.root)
410412

411-
await server?.pluginContainer.transform(code, mod.id!, {
412-
environment: server!.environments.client,
413-
})
413+
await server?.environments.client.pluginContainer.transform(code, mod.id!)
414414

415415
const hash = getHash(cleanUrl(mod.id!))
416416
const result = htmlProxyResult.get(`${hash}_${index}`)

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function createDevServer() {
1717
noDiscovery: true,
1818
},
1919
})
20-
server.pluginContainer.buildStart({})
20+
server.environments.ssr.pluginContainer.buildStart({})
2121
return server
2222
}
2323

@@ -93,7 +93,7 @@ test('virtual module invalidation simple', async () => {
9393
},
9494
],
9595
})
96-
await server.pluginContainer.buildStart({})
96+
server.environments.ssr.pluginContainer.buildStart({})
9797

9898
const mod1 = await server.ssrLoadModule('virtual:test')
9999
expect(mod1.default).toEqual(1)
@@ -151,7 +151,7 @@ test('virtual module invalidation nested', async () => {
151151
},
152152
],
153153
})
154-
await server.pluginContainer.buildStart({})
154+
server.environments.ssr.pluginContainer.buildStart({})
155155

156156
const mod1 = await server.ssrLoadModule('virtual:test')
157157
expect(mod1.default).toEqual(1)

packages/vite/src/node/ssr/__tests__/ssrStacktrace.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function createDevServer() {
1313
noDiscovery: true,
1414
},
1515
})
16-
server.pluginContainer.buildStart({})
16+
server.environments.ssr.pluginContainer.buildStart({})
1717
return server
1818
}
1919

0 commit comments

Comments
 (0)