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

fix: kit compatibility #546

Merged
merged 7 commits into from
Dec 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-pandas-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/vite-plugin-svelte': patch
---

improve detection of sveltekit in inspector plugin to be compatible to latest changes
2 changes: 1 addition & 1 deletion packages/e2e-tests/inspector-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/kit": "^1.0.0-next.572",
"@sveltejs/kit": "^1.0.0-next.582",
"svelte": "^3.54.0",
"vite": "^4.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/inspector-kit/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.png" />
%sveltekit.head%
</head>
<body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions packages/e2e-tests/kit-node/__tests__/kit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,6 @@ describe('kit-node', () => {
expect(await getText('button')).toBe('Clicks: 0');
});
});
describe('config file update', () => {
it('should auto refresh', async () => {
const button = await getEl('button');
await button.click();
expect(await getText('button')).toBe('Clicks: 1');
editFile('svelte.config.js', (config) => config + '\n');
await waitForNavigation({ waitUntil: 'networkidle' });
// clicks should reset, means the browser refreshed
expect(await getText('button')).toBe('Clicks: 0');
});
});
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/kit-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-node": "^1.0.0-next.102",
"@sveltejs/kit": "^1.0.0-next.572",
"@sveltejs/adapter-node": "^1.0.0-next.104",
"@sveltejs/kit": "^1.0.0-next.582",
"e2e-test-dep-svelte-api-only": "file:../_test_dependencies/svelte-api-only",
"e2e-test-dep-vite-plugins": "file:../_test_dependencies/vite-plugins",
"svelte": "^3.54.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/big-component-library-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "1.0.0-next.90",
"@sveltejs/kit": "^1.0.0-next.572",
"@sveltejs/kit": "^1.0.0-next.582",
"carbon-components-svelte": "^0.70.12",
"carbon-icons-svelte": "^11.4.0",
"carbon-preprocess-svelte": "^0.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/kit-demo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@fontsource/fira-mono": "^4.5.10",
"@neoconfetti/svelte": "^1.0.0",
"@sveltejs/adapter-auto": "^1.0.0-next.90",
"@sveltejs/kit": "^1.0.0-next.572",
"@sveltejs/kit": "^1.0.0-next.582",
"@types/cookie": "^0.5.1",
"svelte": "^3.54.0",
"svelte-check": "^2.10.1",
Expand Down
27 changes: 14 additions & 13 deletions packages/vite-plugin-svelte/src/ui/inspector/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ export function svelteInspector(): Plugin {

configResolved(config) {
const vps = config.plugins.find((p) => p.name === 'vite-plugin-svelte');
if (vps?.api?.options?.experimental?.inspector) {
inspectorOptions = {
...defaultInspectorOptions,
...vps.api.options.experimental.inspector
};
}
if (!vps || !inspectorOptions) {
const options = vps?.api?.options?.experimental?.inspector;
if (!vps || !options) {
log.debug('inspector disabled, could not find config');
disabled = true;
} else {
if (vps.api.options.kit && !inspectorOptions.appendTo) {
const out_dir = path.basename(vps.api.options.kit.outDir || '.svelte-kit');
inspectorOptions.appendTo = `${out_dir}/generated/root.svelte`;
}
appendTo = inspectorOptions.appendTo;
return;
}
inspectorOptions = {
...defaultInspectorOptions,
...options
};
const isSvelteKit = config.plugins.some((p) => p.name.startsWith('vite-plugin-sveltekit'));
if (isSvelteKit && !inspectorOptions.appendTo) {
// this could append twice if a user had a file that ends with /generated/root.svelte
// but that should be rare and inspector doesn't execute twice
inspectorOptions.appendTo = `/generated/root.svelte`;
}
appendTo = inspectorOptions.appendTo;
},

async resolveId(importee: string, importer, options) {
Expand Down
91 changes: 52 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.