Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
This is a TypeScript project that implements a frontend build tooling called Vite. Please follow these guidelines when contributing:

## Code Standards

### Required Before Each Commit

- Run `pnpm run lint` to ensure that your code adheres the code standards.
- Run `pnpm run format` to format your code.

### Development Flow

- Build: `pnpm run build`
- Test: `pnpm run test` (uses Vitest and Playwright)

## Repository Structure

- `docs/`: Documentation.
- `packages/create-vite`: Contains the source code for the `create-vite` command.
- `packages/plugin-legacy`: Contains the source code for `@vitejs/plugin-legacy`.
- `packages/vite`: Contains the source code for the Vite core.
- `playground/`: E2E tests

## Key Guidelines

1. Follow TypeScript best practices.
2. Maintain existing code structure and organization.
3. Write tests for new functionality. Prefer uni tests if it can be tested without using mocks.
4. Never write comments that explain what the code does. Instead, write comments that explain why the code does what it does.
5. Suggest changes to the documentation if public API changes are made.
47 changes: 47 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml

jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Set node version to 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"

- name: Install deps
run: pnpm install

# Install playwright's binary under custom directory to cache
- name: (non-windows) Set Playwright path and Get playwright version
if: runner.os != 'Windows'
run: |
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies["playwright-chromium"].version')"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: (windows) Set Playwright path and Get playwright version
if: runner.os == 'Windows'
run: |
echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV
$env:PLAYWRIGHT_VERSION="$(pnpm ls --depth 0 --json -w playwright-chromium | jq --raw-output '.[0].devDependencies["playwright-chromium"].version')"
echo "PLAYWRIGHT_VERSION=$env:PLAYWRIGHT_VERSION" >> $env:GITHUB_ENV

- name: Install Playwright
# does not need to explicitly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
run: pnpm playwright install chromium
5 changes: 4 additions & 1 deletion packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export function transformMiddleware(
return async function viteTransformMiddleware(req, res, next) {
const environment = server.environments.client

if (req.method !== 'GET' || knownIgnoreList.has(req.url!)) {
if (
(req.method !== 'GET' && req.method !== 'HEAD') ||
knownIgnoreList.has(req.url!)
) {
return next()
}

Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/server/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export function send(
}

res.statusCode = 200
res.end(content)
if (req.method === 'HEAD') {
res.end()
} else {
res.end(content)
}
return
}
26 changes: 24 additions & 2 deletions playground/resolve/__tests__/resolve.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { expect, test } from 'vitest'
import { isBuild, isWindows, page, testDir, viteTestUrl } from '~utils'
import { describe, expect, test } from 'vitest'
import { isBuild, isServe, isWindows, page, testDir, viteTestUrl } from '~utils'

test('bom import', async () => {
expect(await page.textContent('.utf8-bom')).toMatch('[success]')
Expand Down Expand Up @@ -263,3 +263,25 @@ test.runIf(isBuild)('sideEffects field glob pattern is respected', async () => {
)
expect(sideEffectValues).toStrictEqual(['success'])
})

describe.runIf(isServe)('HEAD request handling', () => {
test('HEAD request to JS file returns correct Content-Type', async () => {
const response = await fetch(new URL('/absolute.js', viteTestUrl), {
method: 'HEAD',
})
expect(response.headers.get('content-type')).toBe('text/javascript')
expect(response.status).toBe(200)
const text = await response.text()
expect(text).toBe('')
})
test('HEAD request to CSS file returns correct Content-Type', async () => {
const response = await fetch(new URL('/style.css', viteTestUrl), {
method: 'HEAD',
headers: {
Accept: 'text/css',
},
})
expect(response.headers.get('content-type')).toBe('text/css')
expect(response.status).toBe(200)
})
})
5 changes: 5 additions & 0 deletions playground/resolve/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Simple CSS for HEAD request testing */
body {
margin: 0;
padding: 0;
}
Loading