Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Feb 19, 2025
2 parents c684ba8 + ccac73d commit e4533fa
Show file tree
Hide file tree
Showing 35 changed files with 1,303 additions and 932 deletions.
6 changes: 0 additions & 6 deletions docs/.vitepress/theme/composables/sponsor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ const viteSponsors: Pick<Sponsors, 'special' | 'gold'> = {
url: 'https://nuxtlabs.com',
img: '/nuxtlabs.svg',
},
// sponsors bluwy
{
name: 'Astro',
url: 'https://astro.build',
img: '/astro.svg',
},
],
gold: [
// now automated via sponsors.vuejs.org too
Expand Down
2 changes: 1 addition & 1 deletion docs/_data/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const core = [
avatar: 'https://github.com/bluwy.png',
name: 'Bjorn Lu',
title: 'Open Source Developer',
desc: 'Vite, Astro, and Svelte core team member.',
desc: 'Building tools for fun.',
links: [
{ icon: 'github', link: 'https://github.com/bluwy' },
{ icon: 'bluesky', link: 'https://bsky.app/profile/bluwy.me' },
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"docs-serve": "vitepress serve"
},
"devDependencies": {
"@shikijs/vitepress-twoslash": "^2.3.2",
"@shikijs/vitepress-twoslash": "^2.5.0",
"@types/express": "^4.17.21",
"feed": "^4.2.2",
"vitepress": "^1.6.3",
"vitepress-plugin-group-icons": "^1.3.5",
"vitepress-plugin-group-icons": "^1.3.6",
"vue": "^3.5.13"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
"rollup-plugin-esbuild": "^6.2.0",
"simple-git-hooks": "^2.11.1",
"tslib": "^2.8.1",
"tsx": "^4.19.2",
"tsx": "^4.19.3",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.0",
"typescript-eslint": "^8.24.1",
"vite": "workspace:*",
"vitest": "^3.0.5"
"vitest": "^3.0.6"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false"
Expand All @@ -102,7 +102,7 @@
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"[email protected].0": "patches/[email protected].0.patch",
"[email protected].1": "patches/[email protected].1.patch",
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"preact": "^10.25.4"
"preact": "^10.26.2"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"preact": "^10.25.4"
"preact": "^10.26.2"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-vite/template-react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.20.1",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^15.15.0",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.0",
"typescript-eslint": "^8.24.1",
"vite": "^6.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/create-vite/template-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.20.1",
"eslint-plugin-react": "^7.37.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@tsconfig/svelte": "^5.0.4",
"svelte": "^5.20.0",
"svelte": "^5.20.2",
"svelte-check": "^4.1.4",
"typescript": "~5.7.2",
"vite": "^6.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"svelte": "^5.20.0",
"svelte": "^5.20.2",
"vite": "^6.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"@vue/tsconfig": "^0.7.0",
"typescript": "~5.7.2",
"vite": "^6.1.0",
"vue-tsc": "^2.2.0"
"vue-tsc": "^2.2.2"
}
}
4 changes: 2 additions & 2 deletions packages/plugin-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
"funding": "https://github.com/vitejs/vite?sponsor=1",
"dependencies": {
"@babel/core": "^7.26.8",
"@babel/preset-env": "^7.26.8",
"@babel/core": "^7.26.9",
"@babel/preset-env": "^7.26.9",
"browserslist": "^4.24.4",
"browserslist-to-esbuild": "^2.1.1",
"core-js": "^3.40.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"devDependencies": {
"@ampproject/remapping": "^2.3.0",
"@babel/parser": "^7.26.8",
"@babel/parser": "^7.26.9",
"@jridgewell/trace-mapping": "^0.3.25",
"@polka/compression": "^1.0.0-next.25",
"@rollup/plugin-alias": "^5.1.1",
Expand All @@ -121,12 +121,12 @@
"estree-walker": "^3.0.3",
"etag": "^1.8.1",
"http-proxy": "^1.18.1",
"launch-editor-middleware": "^2.9.1",
"launch-editor-middleware": "^2.10.0",
"lightningcss": "^1.29.1",
"magic-string": "^0.30.17",
"mlly": "^1.7.4",
"mrmime": "^2.0.0",
"nanoid": "^5.0.9",
"mrmime": "^2.0.1",
"nanoid": "^5.1.0",
"open": "^10.1.0",
"parse5": "^7.2.1",
"pathe": "^2.0.3",
Expand All @@ -139,14 +139,14 @@
"resolve.exports": "^2.0.3",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.2.0",
"rollup-plugin-license": "^3.5.3",
"sass": "^1.84.0",
"sass-embedded": "^1.83.4",
"sirv": "^3.0.0",
"rollup-plugin-license": "^3.6.0",
"sass": "^1.85.0",
"sass-embedded": "^1.85.0",
"sirv": "^3.0.1",
"source-map-support": "^0.5.21",
"strip-literal": "^3.0.0",
"terser": "^5.39.0",
"tinyglobby": "^0.2.10",
"tinyglobby": "^0.2.11",
"tsconfck": "^3.1.5",
"tslib": "^2.8.1",
"types": "link:./types",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,21 @@ worker.addEventListener('message', (ev) => text('.simple-worker-url', JSON.strin
'Expected object spread to be used before the definition of the type property. Vite needs a static value for the type property to correctly infer it.',
)
})

test('find closing parenthesis correctly', async () => {
expect(
await transform(
`(() => { new Worker(new URL('./worker', import.meta.url)); repro({ test: "foo", }); })();`,
),
).toMatchInlineSnapshot(
`"(() => { new Worker(new URL(/* @vite-ignore */ "/worker?worker_file&type=classic", import.meta.url)); repro({ test: "foo", }); })();"`,
)
expect(
await transform(
`repro(new Worker(new URL('./worker', import.meta.url)), { type: "module" })`,
),
).toMatchInlineSnapshot(
`"repro(new Worker(new URL(/* @vite-ignore */ "/worker?worker_file&type=classic", import.meta.url)), { type: "module" })"`,
)
})
})
2 changes: 0 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export function registerCustomMime(): void {
mrmime.mimes['flac'] = 'audio/flac'
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
mrmime.mimes['eot'] = 'application/vnd.ms-fontobject'
// https://github.com/lukeed/mrmime/issues/10
mrmime.mimes['jxl'] = 'image/jxl'
}

export function renderAssetUrlInJS(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/workerImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function err(e: string, pos: number) {
function findClosingParen(input: string, fromIndex: number) {
let count = 1

for (let i = fromIndex + 1; i < input.length; i++) {
for (let i = fromIndex; i < input.length; i++) {
if (input[i] === '(') count++
if (input[i] === ')') count--
if (count === 0) return i
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
withTrailingSlash,
} from '../../../shared/utils'

const knownJavascriptExtensionRE = /\.[tj]sx?$/
const knownJavascriptExtensionRE = /\.(?:[tj]sx?|[cm][tj]s)$/

const sirvOptions = ({
getHeaders,
Expand All @@ -38,9 +38,9 @@ const sirvOptions = ({
etag: true,
extensions: [],
setHeaders(res, pathname) {
// Matches js, jsx, ts, tsx.
// The reason this is done, is that the .ts file extension is reserved
// for the MIME type video/mp2t. In almost all cases, we can expect
// Matches js, jsx, ts, tsx, mts, mjs, cjs, cts, ctx, mtx
// The reason this is done, is that the .ts and .mts file extensions are
// reserved for the MIME type video/mp2t. In almost all cases, we can expect
// these files to be TypeScript files, and for Vite to serve them with
// this Content-Type.
if (knownJavascriptExtensionRE.test(pathname)) {
Expand Down
86 changes: 86 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
diff --git a/build.js b/build.js
index 0c6ed8e2c0949c93978dd1a244baa9bf2448e9b8..08a9347cfdca06e6a97077ea4582c5b0922ecb2d 100644
--- a/build.js
+++ b/build.js
@@ -35,7 +35,7 @@ function viaCache(cache, uri, extns) {
}
}

-function viaLocal(dir, isEtag, uri, extns) {
+function viaLocal(dir, isEtag, uri, extns, shouldServe) {
let i=0, arr=toAssume(uri, extns);
let abs, stats, name, headers;
for (; i < arr.length; i++) {
@@ -43,6 +43,7 @@ function viaLocal(dir, isEtag, uri, extns) {
if (abs.startsWith(dir) && fs.existsSync(abs)) {
stats = fs.statSync(abs);
if (stats.isDirectory()) continue;
+ if (shouldServe && !shouldServe(abs)) continue;
headers = toHeaders(name, stats, isEtag);
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
return { abs, stats, headers };
@@ -176,7 +177,7 @@ module.exports = function (dir, opts={}) {
catch (err) { /* malform uri */ }
}

- let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
+ let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
if (!data) return next ? next() : isNotFound(req, res);

if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
diff --git a/build.mjs b/build.mjs
index 3ad14d45630a8627b93842a04a96465120d3f223..8451277c015b56a7d2cb99aaee3a318d9c0893dd 100644
--- a/build.mjs
+++ b/build.mjs
@@ -35,7 +35,7 @@ function viaCache(cache, uri, extns) {
}
}

-function viaLocal(dir, isEtag, uri, extns) {
+function viaLocal(dir, isEtag, uri, extns, shouldServe) {
let i=0, arr=toAssume(uri, extns);
let abs, stats, name, headers;
for (; i < arr.length; i++) {
@@ -43,6 +43,7 @@ function viaLocal(dir, isEtag, uri, extns) {
if (abs.startsWith(dir) && fs.existsSync(abs)) {
stats = fs.statSync(abs);
if (stats.isDirectory()) continue;
+ if (shouldServe && !shouldServe(abs)) continue;
headers = toHeaders(name, stats, isEtag);
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
return { abs, stats, headers };
@@ -176,7 +177,7 @@ export default function (dir, opts={}) {
catch (err) { /* malform uri */ }
}

- let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
+ let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
if (!data) return next ? next() : isNotFound(req, res);

if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
diff --git a/index.d.mts b/index.d.mts
index 8bfe364f1db2d1382c56a9b75a014579083cfa70..a8dfa1c473ff15c979bbfbc28c3630a12e222c3a 100644
--- a/index.d.mts
+++ b/index.d.mts
@@ -24,6 +24,8 @@ export interface Options {
gzip?: boolean;
onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void;
setHeaders?: (res: ServerResponse, pathname: string, stats: Stats) => void;
+ /** patched */
+ shouldServe?: (absoluteFilePath: string) => void;
}

export default function (dir?: string, opts?: Options): RequestHandler;
diff --git a/index.d.ts b/index.d.ts
index 96cc63e7ee1ccdd7266e9193252b799068ef2e3c..9e298d627002cd0b073073aa13528b7492541b5b 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -25,6 +25,8 @@ declare namespace sirv {
gzip?: boolean;
onNoMatch?: (req: IncomingMessage, res: ServerResponse) => void;
setHeaders?: (res: ServerResponse, pathname: string, stats: Stats) => void;
+ /** patched */
+ shouldServe?: (absoluteFilePath: string) => void;
}
}

41 changes: 41 additions & 0 deletions playground/assets/__tests__/assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,47 @@ describe('asset imports from js', () => {
'[success] Raw js from /public loaded'
"
`)
expect(await page.textContent('.public-js-import-content-type')).toMatch(
'text/javascript',
)
})

test('from /public (ts)', async () => {
expect(await page.textContent('.public-ts-import')).toMatch(
'/foo/bar/raw.ts',
)
expect(await page.textContent('.public-ts-import-content'))
.toMatchInlineSnapshot(`
"export default function other() {
return 1 + 2
}
"
`)
// NOTE: users should configure the mime type for .ts files for preview server
if (isServe) {
expect(await page.textContent('.public-ts-import-content-type')).toMatch(
'text/javascript',
)
}
})

test('from /public (mts)', async () => {
expect(await page.textContent('.public-mts-import')).toMatch(
'/foo/bar/raw.mts',
)
expect(await page.textContent('.public-mts-import-content'))
.toMatchInlineSnapshot(`
"export default function foobar() {
return 1 + 2
}
"
`)
// NOTE: users should configure the mime type for .ts files for preview server
if (isServe) {
expect(await page.textContent('.public-mts-import-content-type')).toMatch(
'text/javascript',
)
}
})
})

Expand Down
Loading

0 comments on commit e4533fa

Please sign in to comment.