Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Vite 2.9 #4468

Merged
merged 2 commits into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-eyes-travel.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Upgrade to Vite 2.9
1 change: 1 addition & 0 deletions packages/adapter-cloudflare/package.json
Expand Up @@ -32,6 +32,7 @@
"esbuild": "^0.14.21"
},
"devDependencies": {
"@types/ws": "^8.5.3",
"typescript": "^4.6.2"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.32",
"sade": "^1.7.4",
"vite": "^2.8.0"
"vite": "^2.9.0"
},
"devDependencies": {
"@playwright/test": "^1.19.1",
Expand Down
33 changes: 11 additions & 22 deletions packages/kit/src/core/dev/plugin.js
Expand Up @@ -62,7 +62,7 @@ export async function create_plugin(config, cwd) {
const url = id.startsWith('..') ? `/@fs${path.posix.resolve(id)}` : `/${id}`;

const module = /** @type {import('types').SSRComponent} */ (
await vite.ssrLoadModule(url)
await vite.ssrLoadModule(url, { fixStacktrace: false })
);
const node = await vite.moduleGraph.getModuleByUrl(url);

Expand All @@ -84,7 +84,7 @@ export async function create_plugin(config, cwd) {
(query.has('svelte') && query.get('type') === 'style')
) {
try {
const mod = await vite.ssrLoadModule(dep.url);
const mod = await vite.ssrLoadModule(dep.url, { fixStacktrace: false });
styles[dep.url] = mod.default;
} catch {
// this can happen with dynamically imported modules, I think
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function create_plugin(config, cwd) {
shadow: route.shadow
? async () => {
const url = path.resolve(cwd, /** @type {string} */ (route.shadow));
return await vite.ssrLoadModule(url);
return await vite.ssrLoadModule(url, { fixStacktrace: false });
}
: null,
a: route.a.map((id) => manifest_data.components.indexOf(id)),
Expand All @@ -133,7 +133,7 @@ export async function create_plugin(config, cwd) {
types,
load: async () => {
const url = path.resolve(cwd, route.file);
return await vite.ssrLoadModule(url);
return await vite.ssrLoadModule(url, { fixStacktrace: false });
}
};
}),
Expand All @@ -144,7 +144,7 @@ export async function create_plugin(config, cwd) {
for (const key in manifest_data.matchers) {
const file = manifest_data.matchers[key];
const url = path.resolve(cwd, file);
const module = await vite.ssrLoadModule(url);
const module = await vite.ssrLoadModule(url, { fixStacktrace: false });

if (module.match) {
matchers[key] = module.match;
Expand All @@ -161,20 +161,7 @@ export async function create_plugin(config, cwd) {

/** @param {Error} error */
function fix_stack_trace(error) {
// TODO https://github.com/vitejs/vite/issues/7045

// ideally vite would expose ssrRewriteStacktrace, but
// in lieu of that, we can implement it ourselves. we
// don't want to mutate the error object, because
// the stack trace could be 'fixed' multiple times,
// and Vite will fix stack traces before we even
// see them if they occur during ssrLoadModule
const original = error.stack;
vite.ssrFixStacktrace(error);
const fixed = error.stack;
error.stack = original;

return fixed;
return error.stack ? vite.ssrRewriteStacktrace(error.stack) : error.stack;
}

update_manifest();
Expand Down Expand Up @@ -220,7 +207,7 @@ export async function create_plugin(config, cwd) {

/** @type {Partial<import('types').Hooks>} */
const user_hooks = resolve_entry(config.kit.files.hooks)
? await vite.ssrLoadModule(`/${config.kit.files.hooks}`)
? await vite.ssrLoadModule(`/${config.kit.files.hooks}`, { fixStacktrace: false })
: {};

const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
Expand Down Expand Up @@ -260,13 +247,15 @@ export async function create_plugin(config, cwd) {
// can get loaded twice via different URLs, which causes failures. Might
// require changes to Vite to fix
const { default: root } = await vite.ssrLoadModule(
`/${posixify(path.relative(cwd, `${config.kit.outDir}/generated/root.svelte`))}`
`/${posixify(path.relative(cwd, `${config.kit.outDir}/generated/root.svelte`))}`,
{ fixStacktrace: false }
);

const paths = await vite.ssrLoadModule(
process.env.BUNDLED
? `/${posixify(path.relative(cwd, `${config.kit.outDir}/runtime/paths.js`))}`
: `/@fs${runtime}/paths.js`
: `/@fs${runtime}/paths.js`,
{ fixStacktrace: false }
);

paths.set_paths({
Expand Down