Skip to content

Commit 559b053

Browse files
committed
Upgrade to Vite 4
1 parent 40a68de commit 559b053

File tree

38 files changed

+265
-290
lines changed

38 files changed

+265
-290
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@svitejs/changesets-changelog-github-compact": "^0.1.1",
3030
"playwright": "1.25.0",
3131
"prettier": "^2.7.1",
32-
"rollup": "^2.79.1",
32+
"rollup": "^3.2.5",
3333
"svelte": "^3.52.0",
3434
"tiny-glob": "^0.2.9",
3535
"turbo": "^1.6.1",

packages/adapter-cloudflare-workers/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"dependencies": {
3232
"@cloudflare/workers-types": "^3.18.0",
3333
"@iarna/toml": "^2.2.5",
34-
"esbuild": "^0.15.12"
34+
"esbuild": "^0.15.13"
3535
},
3636
"devDependencies": {
3737
"@cloudflare/kv-asset-handler": "^0.2.0",

packages/adapter-cloudflare/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"dependencies": {
3535
"@cloudflare/workers-types": "^3.18.0",
36-
"esbuild": "^0.15.12",
36+
"esbuild": "^0.15.13",
3737
"worktop": "0.8.0-next.14"
3838
},
3939
"devDependencies": {

packages/adapter-netlify/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"dependencies": {
3535
"@iarna/toml": "^2.2.5",
36-
"esbuild": "^0.15.12",
36+
"esbuild": "^0.15.13",
3737
"set-cookie-parser": "^2.5.1"
3838
},
3939
"devDependencies": {
@@ -45,7 +45,7 @@
4545
"@types/node": "^16.11.68",
4646
"@types/set-cookie-parser": "^2.4.2",
4747
"rimraf": "^3.0.2",
48-
"rollup": "^2.79.1",
48+
"rollup": "^3.2.5",
4949
"typescript": "^4.8.4",
5050
"uvu": "^0.5.6"
5151
}

packages/adapter-node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
"@rollup/plugin-commonjs": "^23.0.2",
4646
"@rollup/plugin-json": "^5.0.1",
4747
"@rollup/plugin-node-resolve": "^15.0.1",
48-
"rollup": "^2.79.1"
48+
"rollup": "^3.2.5"
4949
}
5050
}

packages/adapter-static/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
"svelte": "^3.52.0",
3232
"typescript": "^4.8.4",
3333
"uvu": "^0.5.6",
34-
"vite": "^3.2.1"
34+
"vite": "^4.0.0-alpha.2"
3535
}
3636
}

packages/adapter-static/test/apps/prerendered/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"devDependencies": {
1111
"@sveltejs/kit": "workspace:*",
1212
"svelte": "^3.52.0",
13-
"vite": "^3.2.1"
13+
"vite": "^4.0.0-alpha.2"
1414
},
1515
"type": "module"
1616
}

packages/adapter-static/test/apps/spa/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@sveltejs/kit": "workspace:*",
1313
"sirv-cli": "^2.0.2",
1414
"svelte": "^3.52.0",
15-
"vite": "^3.2.1"
15+
"vite": "^4.0.0-alpha.2"
1616
},
1717
"type": "module"
1818
}

packages/adapter-vercel/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"dependencies": {
3131
"@vercel/nft": "^0.22.1",
32-
"esbuild": "^0.15.12"
32+
"esbuild": "^0.15.13"
3333
},
3434
"devDependencies": {
3535
"@sveltejs/kit": "workspace:*",

packages/create-svelte/templates/default/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-preprocess": "^4.10.7",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module",
2020
"dependencies": {

packages/kit/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
"@types/sade": "^1.7.4",
3333
"@types/set-cookie-parser": "^2.4.2",
3434
"marked": "^4.1.1",
35-
"rollup": "^2.79.1",
35+
"rollup": "^3.2.5",
3636
"svelte": "^3.52.0",
3737
"svelte-preprocess": "^4.10.7",
3838
"typescript": "^4.8.4",
3939
"uvu": "^0.5.6",
40-
"vite": "^3.2.1"
40+
"vite": "^4.0.0-alpha.2"
4141
},
4242
"peerDependencies": {
4343
"svelte": "^3.44.0",

packages/kit/src/exports/vite/dev/index.js

+1-75
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'fs';
22
import colors from 'kleur';
33
import path from 'path';
4-
import sirv from 'sirv';
54
import { URL } from 'url';
65
import { getRequest, setResponse } from '../../../exports/node/index.js';
76
import { installPolyfills } from '../../../exports/node/polyfills.js';
@@ -230,41 +229,6 @@ export async function dev(vite, vite_config, svelte_config) {
230229
});
231230

232231
const assets = svelte_config.kit.paths.assets ? SVELTE_KIT_ASSETS : svelte_config.kit.paths.base;
233-
const asset_server = sirv(svelte_config.kit.files.assets, {
234-
dev: true,
235-
etag: true,
236-
maxAge: 0,
237-
extensions: []
238-
});
239-
240-
vite.middlewares.use(async (req, res, next) => {
241-
try {
242-
const base = `${vite.config.server.https ? 'https' : 'http'}://${
243-
req.headers[':authority'] || req.headers.host
244-
}`;
245-
246-
const decoded = decodeURI(new URL(base + req.url).pathname);
247-
248-
if (decoded.startsWith(assets)) {
249-
const pathname = decoded.slice(assets.length);
250-
const file = svelte_config.kit.files.assets + pathname;
251-
252-
if (fs.existsSync(file) && !fs.statSync(file).isDirectory()) {
253-
if (has_correct_case(file, svelte_config.kit.files.assets)) {
254-
req.url = encodeURI(pathname); // don't need query/hash
255-
asset_server(req, res);
256-
return;
257-
}
258-
}
259-
}
260-
261-
next();
262-
} catch (e) {
263-
const error = coalesce_to_error(e);
264-
res.statusCode = 500;
265-
res.end(fix_stack_trace(error));
266-
}
267-
});
268232

269233
return () => {
270234
const serve_static_middleware = vite.middlewares.stack.find(
@@ -295,13 +259,6 @@ export async function dev(vite, vite_config, svelte_config) {
295259
return;
296260
}
297261

298-
if (!decoded.startsWith(svelte_config.kit.paths.base)) {
299-
return not_found(
300-
res,
301-
`Not found (did you mean ${svelte_config.kit.paths.base + req.url}?)`
302-
);
303-
}
304-
305262
if (decoded === svelte_config.kit.paths.base + '/service-worker.js') {
306263
const resolved = resolve_entry(svelte_config.kit.files.serviceWorker);
307264

@@ -498,21 +455,11 @@ export async function dev(vite, vite_config, svelte_config) {
498455
};
499456
}
500457

501-
/** @param {import('http').ServerResponse} res */
502-
function not_found(res, message = 'Not found') {
503-
res.statusCode = 404;
504-
res.end(message);
505-
}
506-
507458
/**
508459
* @param {import('connect').Server} server
509460
*/
510461
function remove_static_middlewares(server) {
511-
// We don't use viteServePublicMiddleware because of the following issues:
512-
// https://github.com/vitejs/vite/issues/9260
513-
// https://github.com/vitejs/vite/issues/9236
514-
// https://github.com/vitejs/vite/issues/9234
515-
const static_middlewares = ['viteServePublicMiddleware', 'viteServeStaticMiddleware'];
462+
const static_middlewares = ['viteServeStaticMiddleware'];
516463
for (let i = server.stack.length - 1; i > 0; i--) {
517464
// @ts-expect-error using internals
518465
if (static_middlewares.includes(server.stack[i].handle.name)) {
@@ -563,24 +510,3 @@ async function find_deps(vite, node, deps) {
563510

564511
await Promise.all(branches);
565512
}
566-
567-
/**
568-
* Determine if a file is being requested with the correct case,
569-
* to ensure consistent behaviour between dev and prod and across
570-
* operating systems. Note that we can't use realpath here,
571-
* because we don't want to follow symlinks
572-
* @param {string} file
573-
* @param {string} assets
574-
* @returns {boolean}
575-
*/
576-
function has_correct_case(file, assets) {
577-
if (file === assets) return true;
578-
579-
const parent = path.dirname(file);
580-
581-
if (fs.readdirSync(parent).includes(path.basename(file))) {
582-
return has_correct_case(parent, assets);
583-
}
584-
585-
return false;
586-
}

packages/kit/src/exports/vite/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function kit() {
243243
/** @type {import('vite').UserConfig} */
244244
const result = {
245245
appType: 'custom',
246-
base: './',
246+
base: svelte_config.kit.paths.base,
247247
build: {
248248
rollupOptions: {
249249
// Vite dependency crawler needs an explicit JS entry point

packages/kit/src/exports/vite/preview/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export async function preview(vite, vite_config, svelte_config) {
7373
next();
7474
} else {
7575
res.statusCode = 404;
76-
res.end(`Not found (did you mean ${base + pathname}?)`);
76+
res.end(
77+
`The server is configured with a public base URL of ${base} - did you mean to visit <a href="${
78+
base + pathname
79+
}">${base + pathname}</a> instead?`
80+
);
7781
}
7882
});
7983

packages/kit/test/apps/amp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"svelte": "^3.52.0",
2020
"svelte-check": "^2.9.2",
2121
"typescript": "^4.8.4",
22-
"vite": "^3.2.1"
22+
"vite": "^4.0.0-alpha.2"
2323
},
2424
"type": "module"
2525
}

packages/kit/test/apps/basics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"svelte": "^3.52.0",
1919
"svelte-check": "^2.9.2",
2020
"typescript": "^4.8.4",
21-
"vite": "^3.2.1"
21+
"vite": "^4.0.0-alpha.2"
2222
},
2323
"type": "module"
2424
}

packages/kit/test/apps/dev-only/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"svelte": "^3.52.0",
1717
"svelte-check": "^2.9.2",
1818
"typescript": "^4.8.4",
19-
"vite": "^3.2.1"
19+
"vite": "^4.0.0-alpha.2"
2020
},
2121
"type": "module"
2222
}

packages/kit/test/apps/options-2/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"svelte": "^3.52.0",
1919
"svelte-check": "^2.9.2",
2020
"typescript": "^4.8.4",
21-
"vite": "^3.2.1"
21+
"vite": "^4.0.0-alpha.2"
2222
},
2323
"type": "module"
2424
}

packages/kit/test/apps/options/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"svelte": "^3.52.0",
1818
"svelte-check": "^2.9.2",
1919
"typescript": "^4.8.4",
20-
"vite": "^3.2.1"
20+
"vite": "^4.0.0-alpha.2"
2121
},
2222
"type": "module"
2323
}

packages/kit/test/apps/options/test/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ test.describe.configure({ mode: 'parallel' });
77

88
test.describe('base path', () => {
99
test('serves a useful 404 when visiting unprefixed path', async ({ request }) => {
10-
const response = await request.get('/');
10+
const response = await request.get('/slash/', { headers: { Accept: 'text/html' } });
1111
expect(response.status()).toBe(404);
12-
expect(await response.text()).toBe('Not found (did you mean /path-base/?)');
12+
expect(await response.text()).toBe(
13+
'The server is configured with a public base URL of /path-base - did you mean to visit <a href="/path-base/slash/">/path-base/slash/</a> instead?'
14+
);
1315
});
1416

1517
test('serves /', async ({ page, javaScriptEnabled }) => {

packages/kit/test/apps/writes/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"svelte": "^3.52.0",
1919
"svelte-check": "^2.9.2",
2020
"typescript": "^4.8.4",
21-
"vite": "^3.2.1"
21+
"vite": "^4.0.0-alpha.2"
2222
},
2323
"type": "module"
2424
}

packages/kit/test/build-errors/apps/prerenderable-incorrect-fragment/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"check": "svelte-kit sync && tsc && svelte-check"
1010
},
1111
"devDependencies": {
12-
"@sveltejs/kit": "workspace:*",
1312
"@sveltejs/adapter-auto": "workspace:*",
13+
"@sveltejs/kit": "workspace:*",
1414
"svelte": "^3.48.0",
1515
"svelte-check": "^2.7.1",
1616
"typescript": "^4.8.2",
17-
"vite": "^3.1.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/prerenderable-not-prerendered/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/private-dynamic-env-dynamic-import/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/private-dynamic-env/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/private-static-env-dynamic-import/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/private-static-env/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"svelte": "^3.52.0",
1616
"svelte-check": "^2.9.2",
1717
"typescript": "^4.8.4",
18-
"vite": "^3.2.1"
18+
"vite": "^4.0.0-alpha.2"
1919
},
2020
"type": "module"
2121
}

packages/kit/test/build-errors/apps/server-only-folder-dynamic-import/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

packages/kit/test/build-errors/apps/server-only-folder/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"svelte": "^3.52.0",
1515
"svelte-check": "^2.9.2",
1616
"typescript": "^4.8.4",
17-
"vite": "^3.2.1"
17+
"vite": "^4.0.0-alpha.2"
1818
},
1919
"type": "module"
2020
}

0 commit comments

Comments
 (0)