Skip to content

Commit c47c03a

Browse files
committed
chore: merge main
2 parents 67af25b + c4d5940 commit c47c03a

File tree

8 files changed

+101
-50
lines changed

8 files changed

+101
-50
lines changed

.github/copilot-instructions.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This is a TypeScript project that implements a frontend build tooling called Vite. Please follow these guidelines when contributing:
2+
3+
## Code Standards
4+
5+
### Required Before Each Commit
6+
7+
- Run `pnpm run lint` to ensure that your code adheres to the code standards.
8+
- Run `pnpm run format` to format your code.
9+
10+
### Development Flow
11+
12+
- Build: `pnpm run build`
13+
- Test: `pnpm run test` (uses Vitest and Playwright)
14+
15+
## Repository Structure
16+
17+
- `docs/`: Documentation.
18+
- `packages/create-vite`: Contains the source code for the `create-vite` command.
19+
- `packages/plugin-legacy`: Contains the source code for `@vitejs/plugin-legacy`.
20+
- `packages/vite`: Contains the source code for the Vite core.
21+
- `playground/`: E2E tests
22+
23+
## Key Guidelines
24+
25+
1. Follow TypeScript best practices.
26+
2. Maintain existing code structure and organization.
27+
3. Write tests for new functionality. Prefer unit tests if it can be tested without using mocks. E2E tests should be added in the `playground/` directory.
28+
4. Never write comments that explain what the code does. Instead, write comments that explain why the code does what it does.
29+
5. Suggest changes to the documentation if public API changes are made.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
paths:
5+
- .github/workflows/copilot-setup-steps.yml
6+
pull_request:
7+
paths:
8+
- .github/workflows/copilot-setup-steps.yml
9+
10+
jobs:
11+
copilot-setup-steps:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
21+
22+
- name: Set node version to 22
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 22
26+
cache: "pnpm"
27+
28+
- name: Install deps
29+
run: pnpm install
30+
31+
# Install playwright's binary under custom directory to cache
32+
- name: (non-windows) Set Playwright path and Get playwright version
33+
if: runner.os != 'Windows'
34+
run: |
35+
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
36+
PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies["playwright-chromium"].version')"
37+
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
38+
- name: (windows) Set Playwright path and Get playwright version
39+
if: runner.os == 'Windows'
40+
run: |
41+
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV
42+
$env:PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies["playwright-chromium"].version')"
43+
echo "PLAYWRIGHT_VERSION=$env:PLAYWRIGHT_VERSION" >> $env:GITHUB_ENV
44+
45+
- name: Install Playwright
46+
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
47+
run: pnpm playwright install chromium

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ You may wish to test your locally modified copy of Vite against another package
133133
```json
134134
{
135135
"dependencies": {
136-
"vite": "^6.0.0"
136+
"vite": "^7.0.0"
137137
},
138138
"pnpm": {
139139
"overrides": {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import { EnvironmentModuleGraph } from './moduleGraph'
2222
import type { EnvironmentModuleNode } from './moduleGraph'
2323
import type { HotChannel, NormalizedHotChannel } from './hmr'
2424
import { getShortName, normalizeHotChannel, updateModules } from './hmr'
25-
import type { TransformResult } from './transformRequest'
25+
import type {
26+
TransformOptionsInternal,
27+
TransformResult,
28+
} from './transformRequest'
2629
import { transformRequest } from './transformRequest'
2730
import type { EnvironmentPluginContainer } from './pluginContainer'
2831
import {
@@ -206,8 +209,12 @@ export class DevEnvironment extends BaseEnvironment {
206209
}
207210
}
208211

209-
transformRequest(url: string): Promise<TransformResult | null> {
210-
return transformRequest(this, url)
212+
transformRequest(
213+
url: string,
214+
/** @internal */
215+
options?: TransformOptionsInternal,
216+
): Promise<TransformResult | null> {
217+
return transformRequest(this, url, options)
211218
}
212219

213220
async warmupRequest(url: string): Promise<void> {

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import { ssrTransform } from '../ssr/ssrTransform'
4545
import { reloadOnTsconfigChange } from '../plugins/esbuild'
4646
import { bindCLIShortcuts } from '../shortcuts'
4747
import type { BindCLIShortcutsOptions } from '../shortcuts'
48-
import { ERR_OUTDATED_OPTIMIZED_DEP } from '../../shared/constants'
4948
import {
5049
CLIENT_DIR,
5150
DEFAULT_DEV_PORT,
@@ -67,7 +66,6 @@ import type { MinimalPluginContextWithoutEnvironment } from '../plugin'
6766
import type { PluginContainer } from './pluginContainer'
6867
import {
6968
BasicMinimalPluginContext,
70-
ERR_CLOSED_SERVER,
7169
basePluginContextMeta,
7270
createPluginContainer,
7371
} from './pluginContainer'
@@ -93,12 +91,11 @@ import { timeMiddleware } from './middlewares/time'
9391
import { ModuleGraph } from './mixedModuleGraph'
9492
import type { ModuleNode } from './mixedModuleGraph'
9593
import { notFoundMiddleware } from './middlewares/notFound'
96-
import { buildErrorMessage, errorMiddleware } from './middlewares/error'
94+
import { errorMiddleware } from './middlewares/error'
9795
import type { HmrOptions, NormalizedHotChannel } from './hmr'
9896
import { handleHMRUpdate, updateModules } from './hmr'
9997
import { openBrowser as _openBrowser } from './openBrowser'
10098
import type { TransformOptions, TransformResult } from './transformRequest'
101-
import { transformRequest } from './transformRequest'
10299
import { searchForPackageRoot, searchForWorkspaceRoot } from './searchRoot'
103100
import type { DevEnvironment } from './environment'
104101
import { hostValidationMiddleware } from './middlewares/hostCheck'
@@ -594,41 +591,18 @@ export async function _createServer(
594591
},
595592
})
596593
},
597-
// environment.transformRequest and .warmupRequest don't take an options param for now,
598-
// so the logic and error handling needs to be duplicated here.
599-
// The only param in options that could be important is `html`, but we may remove it as
600-
// that is part of the internal control flow for the vite dev server to be able to bail
601-
// out and do the html fallback
602594
transformRequest(url, options) {
603595
warnFutureDeprecation(
604596
config,
605597
'removeServerTransformRequest',
606598
'server.transformRequest() is deprecated. Use environment.transformRequest() instead.',
607599
)
608600
const environment = server.environments[options?.ssr ? 'ssr' : 'client']
609-
return transformRequest(environment, url, options)
601+
return environment.transformRequest(url)
610602
},
611-
async warmupRequest(url, options) {
612-
try {
613-
const environment = server.environments[options?.ssr ? 'ssr' : 'client']
614-
await transformRequest(environment, url, options)
615-
} catch (e) {
616-
if (
617-
e?.code === ERR_OUTDATED_OPTIMIZED_DEP ||
618-
e?.code === ERR_CLOSED_SERVER
619-
) {
620-
// these are expected errors
621-
return
622-
}
623-
// Unexpected error, log the issue but avoid an unhandled exception
624-
server.config.logger.error(
625-
buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false),
626-
{
627-
error: e,
628-
timestamp: true,
629-
},
630-
)
631-
}
603+
warmupRequest(url, options) {
604+
const environment = server.environments[options?.ssr ? 'ssr' : 'client']
605+
return environment.warmupRequest(url)
632606
},
633607
transformIndexHtml(url, html, originalUrl) {
634608
return devHtmlTransformFn(server, url, html, originalUrl)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ import {
1818
removeTimestampQuery,
1919
} from '../../utils'
2020
import { send } from '../send'
21-
import {
22-
ERR_DENIED_ID,
23-
ERR_LOAD_URL,
24-
transformRequest,
25-
} from '../transformRequest'
21+
import { ERR_DENIED_ID, ERR_LOAD_URL } from '../transformRequest'
2622
import { applySourcemapIgnoreList } from '../sourcemap'
2723
import { isHTMLProxy } from '../../plugins/html'
2824
import {
@@ -262,7 +258,7 @@ export function transformMiddleware(
262258
}
263259

264260
// resolve, load and transform using the plugin container
265-
const result = await transformRequest(environment, url, {
261+
const result = await environment.transformRequest(url, {
266262
allowId(id) {
267263
return (
268264
id.startsWith('\0') ||

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export interface TransformOptions {
5858
* @deprecated inferred from environment
5959
*/
6060
ssr?: boolean
61+
}
62+
63+
export interface TransformOptionsInternal {
6164
/**
6265
* @internal
6366
*/
@@ -74,14 +77,8 @@ export interface TransformOptions {
7477
export function transformRequest(
7578
environment: DevEnvironment,
7679
url: string,
77-
options: TransformOptions = {},
80+
options: TransformOptionsInternal = {},
7881
): Promise<TransformResult | null> {
79-
// Backward compatibility when only `ssr` is passed
80-
if (!options.ssr) {
81-
// Backward compatibility
82-
options = { ...options, ssr: environment.config.consumer === 'server' }
83-
}
84-
8582
if (environment._closing && environment.config.dev.recoverable)
8683
throwClosedServerError()
8784

@@ -152,7 +149,7 @@ export function transformRequest(
152149
async function doTransform(
153150
environment: DevEnvironment,
154151
url: string,
155-
options: TransformOptions,
152+
options: TransformOptionsInternal,
156153
timestamp: number,
157154
) {
158155
url = removeTimestampQuery(url)
@@ -242,7 +239,7 @@ async function loadAndTransform(
242239
environment: DevEnvironment,
243240
id: string,
244241
url: string,
245-
options: TransformOptions,
242+
options: TransformOptionsInternal,
246243
timestamp: number,
247244
mod?: EnvironmentModuleNode,
248245
resolved?: PartialResolvedId,

playground/resolve/vite.config-mainfields-custom-first.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ config.resolve.mainFields = [
33
'custom',
44
...config.resolve.mainFields.filter((f) => f !== 'custom'),
55
]
6+
config.build.outDir = 'dist-mainfields-custom-first'
67
export default config

0 commit comments

Comments
 (0)