Skip to content

Commit f684d4c

Browse files
patak-devsheremet-vahi-ogawasapphi-redjay-es
authored
feat: environment api (#16129)
Co-authored-by: Vladimir Sheremet <[email protected]> Co-authored-by: Hiroshi Ogawa <[email protected]> Co-authored-by: 翠 / green <[email protected]> Co-authored-by: Jun Shindo <[email protected]> Co-authored-by: Greg T. Wallace <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Caven <[email protected]> Co-authored-by: sapphi-red <[email protected]> Co-authored-by: Matyáš Racek <[email protected]> Co-authored-by: bluwy <[email protected]>
1 parent b41895c commit f684d4c

File tree

121 files changed

+5730
-2542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+5730
-2542
lines changed

docs/config/build-options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,18 @@ When set to `true`, the build will also generate an SSR manifest for determining
192192

193193
Produce SSR-oriented build. The value can be a string to directly specify the SSR entry, or `true`, which requires specifying the SSR entry via `rollupOptions.input`.
194194

195+
## build.emitAssets
196+
197+
- **Type:** `boolean`
198+
- **Default:** `false`
199+
200+
During non-client builds, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in other environments build. It is responsibility of the framework to merge the assets with a post build step.
201+
195202
## build.ssrEmitAssets
196203

197204
- **Type:** `boolean`
198205
- **Default:** `false`
206+
- **Deprecated:** use `build.emitAssets`
199207

200208
During the SSR build, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in both the client and SSR build. It is responsibility of the framework to merge the assets with a post build step.
201209

docs/guide/api-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ interface ViteDevServer {
135135
/**
136136
* Programmatically resolve, load and transform a URL and get the result
137137
* without going through the http request pipeline.
138+
* @deprecated use environment.transformRequest
138139
*/
139140
transformRequest(
140141
url: string,

docs/guide/api-vite-runtime.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ export class ViteRuntime {
2626
/**
2727
* URL to execute. Accepts file path, server path, or id relative to the root.
2828
*/
29-
public async executeUrl<T = any>(url: string): Promise<T>
30-
/**
31-
* Entry point URL to execute. Accepts file path, server path or id relative to the root.
32-
* In the case of a full reload triggered by HMR, this is the module that will be reloaded.
33-
* If this method is called multiple times, all entry points will be reloaded one at a time.
34-
*/
35-
public async executeEntrypoint<T = any>(url: string): Promise<T>
29+
public async import<T = any>(url: string): Promise<T>
3630
/**
3731
* Clear all caches including HMR listeners.
3832
*/
@@ -57,7 +51,7 @@ The `ViteRuntime` class requires `root` and `fetchModule` options when initiated
5751

5852
Runner in `ViteRuntime` is responsible for executing the code. Vite exports `ESModulesRunner` out of the box, it uses `new AsyncFunction` to run the code. You can provide your own implementation if your JavaScript runtime doesn't support unsafe evaluation.
5953

60-
The two main methods that runtime exposes are `executeUrl` and `executeEntrypoint`. The only difference between them is that all modules executed by `executeEntrypoint` will be reexecuted if HMR triggers `full-reload` event. Be aware that Vite Runtime doesn't update `exports` object when this happens (it overrides it), you would need to run `executeUrl` or get the module from `moduleCache` again if you rely on having the latest `exports` object.
54+
Module runner exposes `import` method. When Vite server triggers `full-reload` HMR event, all affected modules will be re-executed. Be aware that Module Runner doesn't update `exports` object when this happens (it overrides it), you would need to run `import` or get the module from `moduleCache` again if you rely on having the latest `exports` object.
6155

6256
**Example Usage:**
6357

@@ -74,7 +68,7 @@ const runtime = new ViteRuntime(
7468
new ESModulesRunner(),
7569
)
7670

77-
await runtime.executeEntrypoint('/src/entry-point.js')
71+
await runtime.import('/src/entry-point.js')
7872
```
7973

8074
## `ViteRuntimeOptions`
@@ -209,7 +203,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url))
209203
await server.listen()
210204
211205
const runtime = await createViteRuntime(server)
212-
await runtime.executeEntrypoint('/src/entry-point.js')
206+
await runtime.import('/src/entry-point.js')
213207
})()
214208
```
215209

packages/vite/CHANGELOG.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,114 @@
1+
## 6.0.0-alpha.2 (2024-04-09)
2+
3+
* chore: update ([46c8910](https://github.com/vitejs/vite/commit/46c8910))
4+
* feat: environment aware define ([9f9a716](https://github.com/vitejs/vite/commit/9f9a716))
5+
* feat: rework more ssr.target webworker branches ([1f644d0](https://github.com/vitejs/vite/commit/1f644d0))
6+
7+
8+
9+
## 6.0.0-alpha.1 (2024-04-08)
10+
11+
* fix: `fsp.rm` removing files does not take effect (#16032) ([b05c405](https://github.com/vitejs/vite/commit/b05c405)), closes [#16032](https://github.com/vitejs/vite/issues/16032)
12+
* fix: csp nonce injection when no closing tag (#16281) (#16282) ([67a74f8](https://github.com/vitejs/vite/commit/67a74f8)), closes [#16281](https://github.com/vitejs/vite/issues/16281) [#16282](https://github.com/vitejs/vite/issues/16282)
13+
* fix: do not access document in `/@vite/client` when not defined (#16318) ([6c5536b](https://github.com/vitejs/vite/commit/6c5536b)), closes [#16318](https://github.com/vitejs/vite/issues/16318)
14+
* fix: fix sourcemap when using object as `define` value (#15805) ([9699ba3](https://github.com/vitejs/vite/commit/9699ba3)), closes [#15805](https://github.com/vitejs/vite/issues/15805)
15+
* fix: package types ([bdf13bb](https://github.com/vitejs/vite/commit/bdf13bb))
16+
* fix(deps): update all non-major dependencies (#16376) ([58a2938](https://github.com/vitejs/vite/commit/58a2938)), closes [#16376](https://github.com/vitejs/vite/issues/16376)
17+
* fix(environment): use `environments.client.build.outDir` for preview (#16301) ([8621c3f](https://github.com/vitejs/vite/commit/8621c3f)), closes [#16301](https://github.com/vitejs/vite/issues/16301)
18+
* feat: async createEnvironment ([d15a157](https://github.com/vitejs/vite/commit/d15a157))
19+
* feat: dedupe/preserveSymlinks ([3ba9214](https://github.com/vitejs/vite/commit/3ba9214))
20+
* refactor: environment.dev.recoverable ([ea1c7eb](https://github.com/vitejs/vite/commit/ea1c7eb))
21+
* refactor: isFileServingAllowed load fallback for SSR ([d91714b](https://github.com/vitejs/vite/commit/d91714b))
22+
* refactor: lib options ([70731ce](https://github.com/vitejs/vite/commit/70731ce))
23+
* chore: merge ([bcac048](https://github.com/vitejs/vite/commit/bcac048))
24+
* chore: merge ([833dabf](https://github.com/vitejs/vite/commit/833dabf))
25+
* chore: remove ssr.target use ([0ea8be9](https://github.com/vitejs/vite/commit/0ea8be9))
26+
* chore: remove ssrConfig ([27371dc](https://github.com/vitejs/vite/commit/27371dc))
27+
* chore: update region comment (#16380) ([77562c3](https://github.com/vitejs/vite/commit/77562c3)), closes [#16380](https://github.com/vitejs/vite/issues/16380)
28+
* chore(deps): update all non-major dependencies (#16325) ([c7efec4](https://github.com/vitejs/vite/commit/c7efec4)), closes [#16325](https://github.com/vitejs/vite/issues/16325)
29+
* perf: reduce size of injected __vite__mapDeps code (#16184) ([a9bf430](https://github.com/vitejs/vite/commit/a9bf430)), closes [#16184](https://github.com/vitejs/vite/issues/16184)
30+
* perf: reduce size of injected __vite__mapDeps code (#16184) ([c0ec6be](https://github.com/vitejs/vite/commit/c0ec6be)), closes [#16184](https://github.com/vitejs/vite/issues/16184)
31+
* perf(css): only replace empty chunk if imported (#16349) ([f61d8b1](https://github.com/vitejs/vite/commit/f61d8b1)), closes [#16349](https://github.com/vitejs/vite/issues/16349)
32+
33+
34+
35+
## 6.0.0-alpha.0 (2024-04-05)
36+
37+
* feat: abstract moduleGraph into ModuleExecutionEnvironment ([5f5e0ec](https://github.com/vitejs/vite/commit/5f5e0ec))
38+
* feat: add `hot` property to environments ([e966ba0](https://github.com/vitejs/vite/commit/e966ba0))
39+
* feat: build.ssrEmitAssets -> build.emitAssets ([ef8c9b9](https://github.com/vitejs/vite/commit/ef8c9b9))
40+
* feat: builder config, runBuildTasks option ([f4789a3](https://github.com/vitejs/vite/commit/f4789a3))
41+
* feat: configureDevEnvironments + configureBuildEnvironments ([88fea3b](https://github.com/vitejs/vite/commit/88fea3b))
42+
* feat: environment aware createIdResolver ([f1dcd2c](https://github.com/vitejs/vite/commit/f1dcd2c))
43+
* feat: environment aware createResolver and resolvePlugin ([dd6332e](https://github.com/vitejs/vite/commit/dd6332e))
44+
* feat: environment aware depsOptimizer ([a7e52aa](https://github.com/vitejs/vite/commit/a7e52aa))
45+
* feat: environment id resolver for css plugin ([0bec1b9](https://github.com/vitejs/vite/commit/0bec1b9))
46+
* feat: environment in hooks, context vs param (#16261) ([fbe6361](https://github.com/vitejs/vite/commit/fbe6361)), closes [#16261](https://github.com/vitejs/vite/issues/16261)
47+
* feat: environment.transformRequest ([fcebb7d](https://github.com/vitejs/vite/commit/fcebb7d))
48+
* feat: inject environment in build hooks ([cef1091](https://github.com/vitejs/vite/commit/cef1091))
49+
* feat: separate module graphs per environment ([83068fe](https://github.com/vitejs/vite/commit/83068fe))
50+
* feat: server.runHmrTasks ([7f94c03](https://github.com/vitejs/vite/commit/7f94c03))
51+
* feat: ssr.external/noExternal -> resolve.external/noExternal ([2a0b524](https://github.com/vitejs/vite/commit/2a0b524))
52+
* feat: ssr.target -> environment.webCompatible ([1a7d290](https://github.com/vitejs/vite/commit/1a7d290))
53+
* feat: support transport options to communicate between the environment and the runner (#16209) ([dbcc375](https://github.com/vitejs/vite/commit/dbcc375)), closes [#16209](https://github.com/vitejs/vite/issues/16209)
54+
* feat: vite runtime renamed to module runner (#16137) ([60f7f2b](https://github.com/vitejs/vite/commit/60f7f2b)), closes [#16137](https://github.com/vitejs/vite/issues/16137)
55+
* feat(hmr): call `hotUpdate` hook with file create/delete (#16249) ([3d37ac1](https://github.com/vitejs/vite/commit/3d37ac1)), closes [#16249](https://github.com/vitejs/vite/issues/16249)
56+
* refactor: allow custom connections in node module runner ([9005841](https://github.com/vitejs/vite/commit/9005841))
57+
* refactor: base environment.config + environment.options ([c7e4da2](https://github.com/vitejs/vite/commit/c7e4da2))
58+
* refactor: buildEnvironments + hmrEnvironments ([c1fc111](https://github.com/vitejs/vite/commit/c1fc111))
59+
* refactor: clientEnvironment instead of browserEnvironment (#16194) ([ccf3de4](https://github.com/vitejs/vite/commit/ccf3de4)), closes [#16194](https://github.com/vitejs/vite/issues/16194)
60+
* refactor: configEnvironment hook + enviroment config resolving ([fee54ea](https://github.com/vitejs/vite/commit/fee54ea))
61+
* refactor: environment id,type -> name + fixes ([29f1b7b](https://github.com/vitejs/vite/commit/29f1b7b))
62+
* refactor: environments array to plain object ([a7a06fe](https://github.com/vitejs/vite/commit/a7a06fe))
63+
* refactor: environments as array instead of map (#16193) ([f1d660c](https://github.com/vitejs/vite/commit/f1d660c)), closes [#16193](https://github.com/vitejs/vite/issues/16193)
64+
* refactor: hooks get an environment object instead of a string ([5e60d8a](https://github.com/vitejs/vite/commit/5e60d8a))
65+
* refactor: hooks to config for creating environments ([3e6216c](https://github.com/vitejs/vite/commit/3e6216c))
66+
* refactor: isolate back compat module graph in its own module ([8000e8e](https://github.com/vitejs/vite/commit/8000e8e))
67+
* refactor: ModuleExecutionEnvironment -> DevEnvironment ([6e71b24](https://github.com/vitejs/vite/commit/6e71b24))
68+
* refactor: move safeModulesPath set to server ([95ae29b](https://github.com/vitejs/vite/commit/95ae29b))
69+
* refactor: move transport to properties ([9cfa916](https://github.com/vitejs/vite/commit/9cfa916))
70+
* refactor: node -> ssr for default environment ([e03bac8](https://github.com/vitejs/vite/commit/e03bac8))
71+
* refactor: options and environment are required when calling container.hook ([e30b858](https://github.com/vitejs/vite/commit/e30b858))
72+
* refactor: pass down name to the environment factory ([52edfc9](https://github.com/vitejs/vite/commit/52edfc9))
73+
* refactor: remove default nodeModuleRunner because it's not used anywhere ([f29e95a](https://github.com/vitejs/vite/commit/f29e95a))
74+
* refactor: remove environment name from the hmr context ([a183a0f](https://github.com/vitejs/vite/commit/a183a0f))
75+
* refactor: rename "hmrEnvironments" to "hotUpdateEnvironments" ([a0b7edb](https://github.com/vitejs/vite/commit/a0b7edb))
76+
* refactor: rename createSsrEnvironment to createNodeEnvironment ([c9abcfc](https://github.com/vitejs/vite/commit/c9abcfc))
77+
* refactor: rename ssrInvalidates to invalidates ([72fe84e](https://github.com/vitejs/vite/commit/72fe84e))
78+
* refactor: rework resolveId in ModuleExecutionEnvironment constructor ([03d3889](https://github.com/vitejs/vite/commit/03d3889))
79+
* refactor: ssrConfig.optimizeDeps.include/exclude ([5bd8e95](https://github.com/vitejs/vite/commit/5bd8e95))
80+
* refactor: use ssr environment module graph in ssrFixStacktrace ([5477972](https://github.com/vitejs/vite/commit/5477972))
81+
* fix: add auto complete to server.environments ([a160a1b](https://github.com/vitejs/vite/commit/a160a1b))
82+
* fix: call updateModules for each environmnet ([281cf97](https://github.com/vitejs/vite/commit/281cf97))
83+
* fix: fine-grained hmr ([31e1d3a](https://github.com/vitejs/vite/commit/31e1d3a))
84+
* fix: HotContext only gets ModuleExecutionEnvironment ([30be775](https://github.com/vitejs/vite/commit/30be775))
85+
* fix: injectEnvironmentInContext ([a1d385c](https://github.com/vitejs/vite/commit/a1d385c))
86+
* fix: injectEnvironmentToHooks ([681ccd4](https://github.com/vitejs/vite/commit/681ccd4))
87+
* fix: missing externalConditions back compat ([beb40ef](https://github.com/vitejs/vite/commit/beb40ef))
88+
* fix: optimizeDeps backward compatibility layer ([3806fe6](https://github.com/vitejs/vite/commit/3806fe6))
89+
* fix: partial backward compat for config.ssr ([85ada0d](https://github.com/vitejs/vite/commit/85ada0d))
90+
* fix: resolve.externalConditions ([fb9365c](https://github.com/vitejs/vite/commit/fb9365c))
91+
* fix: use "register" event for remote environment transport ([c4f4dfb](https://github.com/vitejs/vite/commit/c4f4dfb))
92+
* fix(css): unknown file error happened with lightningcss (#16306) ([01af308](https://github.com/vitejs/vite/commit/01af308)), closes [#16306](https://github.com/vitejs/vite/issues/16306)
93+
* fix(hmr): multiple updates happened when invalidate is called while multiple tabs open (#16307) ([21cc10b](https://github.com/vitejs/vite/commit/21cc10b)), closes [#16307](https://github.com/vitejs/vite/issues/16307)
94+
* fix(scanner): duplicate modules for same id if glob is used in html-like types (#16305) ([eca68fa](https://github.com/vitejs/vite/commit/eca68fa)), closes [#16305](https://github.com/vitejs/vite/issues/16305)
95+
* test: add test for worker transport ([a5ef42e](https://github.com/vitejs/vite/commit/a5ef42e))
96+
* test: fix after merge ([d9ed857](https://github.com/vitejs/vite/commit/d9ed857))
97+
* test(environment): add environment playground (#16299) ([a5c7e4f](https://github.com/vitejs/vite/commit/a5c7e4f)), closes [#16299](https://github.com/vitejs/vite/issues/16299)
98+
* chore: fix lint ([b4e46fe](https://github.com/vitejs/vite/commit/b4e46fe))
99+
* chore: fix lint ([6040ab3](https://github.com/vitejs/vite/commit/6040ab3))
100+
* chore: lint ([8785f4f](https://github.com/vitejs/vite/commit/8785f4f))
101+
* chore: lint ([92eccf9](https://github.com/vitejs/vite/commit/92eccf9))
102+
* chore: lint ([f927702](https://github.com/vitejs/vite/commit/f927702))
103+
* chore: rename module and error back to ssrModule and ssrError ([d8ff12a](https://github.com/vitejs/vite/commit/d8ff12a))
104+
* chore: rename server environment to node environment ([4808b27](https://github.com/vitejs/vite/commit/4808b27))
105+
* chore: run prettier on environment file ([1fe63b1](https://github.com/vitejs/vite/commit/1fe63b1))
106+
* chore: update ([9a600fe](https://github.com/vitejs/vite/commit/9a600fe))
107+
* chore: update environment.server.config ([2ddf28e](https://github.com/vitejs/vite/commit/2ddf28e))
108+
* wip: environment config overrides ([81abf6e](https://github.com/vitejs/vite/commit/81abf6e))
109+
110+
111+
1112
## <small>5.2.9 (2024-04-15)</small>
2113

3114
* fix: `fsp.rm` removing files does not take effect (#16032) ([b05c405](https://github.com/vitejs/vite/commit/b05c405)), closes [#16032](https://github.com/vitejs/vite/issues/16032)
@@ -9,6 +120,18 @@
9120

10121

11122

123+
## <small>5.2.8 (2024-04-03)</small>
124+
125+
* release: v5.2.8 ([8b8d402](https://github.com/vitejs/vite/commit/8b8d402))
126+
* fix: csp nonce injection when no closing tag (#16281) (#16282) ([3c85c6b](https://github.com/vitejs/vite/commit/3c85c6b)), closes [#16281](https://github.com/vitejs/vite/issues/16281) [#16282](https://github.com/vitejs/vite/issues/16282)
127+
* fix: do not access document in `/@vite/client` when not defined (#16318) ([646319c](https://github.com/vitejs/vite/commit/646319c)), closes [#16318](https://github.com/vitejs/vite/issues/16318)
128+
* fix: fix sourcemap when using object as `define` value (#15805) ([445c4f2](https://github.com/vitejs/vite/commit/445c4f2)), closes [#15805](https://github.com/vitejs/vite/issues/15805)
129+
* chore(deps): update all non-major dependencies (#16325) ([a78e265](https://github.com/vitejs/vite/commit/a78e265)), closes [#16325](https://github.com/vitejs/vite/issues/16325)
130+
* refactor: use types from sass instead of @types/sass (#16340) ([4581e83](https://github.com/vitejs/vite/commit/4581e83)), closes [#16340](https://github.com/vitejs/vite/issues/16340)
131+
132+
133+
134+
12135
## <small>5.2.8 (2024-04-03)</small>
13136

14137
* fix: csp nonce injection when no closing tag (#16281) (#16282) ([3c85c6b](https://github.com/vitejs/vite/commit/3c85c6b)), closes [#16281](https://github.com/vitejs/vite/issues/16281) [#16282](https://github.com/vitejs/vite/issues/16282)

packages/vite/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite",
3-
"version": "5.2.9",
3+
"version": "6.0.0-alpha.2",
44
"type": "module",
55
"license": "MIT",
66
"author": "Evan You",
@@ -32,9 +32,9 @@
3232
"./client": {
3333
"types": "./client.d.ts"
3434
},
35-
"./runtime": {
36-
"types": "./dist/node/runtime.d.ts",
37-
"import": "./dist/node/runtime.js"
35+
"./module-runner": {
36+
"types": "./dist/node/module-runner.d.ts",
37+
"import": "./dist/node/module-runner.js"
3838
},
3939
"./dist/client/*": "./dist/client/*",
4040
"./types/*": {
@@ -44,8 +44,8 @@
4444
},
4545
"typesVersions": {
4646
"*": {
47-
"runtime": [
48-
"dist/node/runtime.d.ts"
47+
"module-runner": [
48+
"dist/node/module-runner.d.ts"
4949
]
5050
}
5151
},

packages/vite/rollup.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ function createNodeConfig(isProduction: boolean) {
177177
})
178178
}
179179

180-
function createRuntimeConfig(isProduction: boolean) {
180+
function createModuleRunnerConfig(isProduction: boolean) {
181181
return defineConfig({
182182
...sharedNodeOptions,
183183
input: {
184-
runtime: path.resolve(__dirname, 'src/runtime/index.ts'),
184+
'module-runner': path.resolve(__dirname, 'src/module-runner/index.ts'),
185185
},
186186
output: {
187187
...sharedNodeOptions.output,
@@ -202,7 +202,7 @@ function createRuntimeConfig(isProduction: boolean) {
202202
isProduction ? false : './dist/node',
203203
),
204204
esbuildMinifyPlugin({ minify: false, minifySyntax: true }),
205-
bundleSizeLimit(45),
205+
bundleSizeLimit(47),
206206
],
207207
})
208208
}
@@ -240,7 +240,7 @@ export default (commandLineArgs: any): RollupOptions[] => {
240240
envConfig,
241241
clientConfig,
242242
createNodeConfig(isProduction),
243-
createRuntimeConfig(isProduction),
243+
createModuleRunnerConfig(isProduction),
244244
createCjsConfig(isProduction),
245245
])
246246
}
@@ -332,10 +332,10 @@ const __require = require;
332332
name: 'cjs-chunk-patch',
333333
renderChunk(code, chunk) {
334334
if (!chunk.fileName.includes('chunks/dep-')) return
335-
// don't patch runtime utils chunk because it should stay lightweight and we know it doesn't use require
335+
// don't patch runner utils chunk because it should stay lightweight and we know it doesn't use require
336336
if (
337337
chunk.name === 'utils' &&
338-
chunk.moduleIds.some((id) => id.endsWith('/ssr/runtime/utils.ts'))
338+
chunk.moduleIds.some((id) => id.endsWith('/ssr/module-runner/utils.ts'))
339339
)
340340
return
341341
const match = code.match(/^(?:import[\s\S]*?;\s*)+/)

0 commit comments

Comments
 (0)