Skip to content

Commit 0ba2c7c

Browse files
yeoularujohn-royal
andauthored
fix(cloudflare): skip config file validation during svelte check & sync (#1336)
Co-authored-by: John Royal <34844819+john-royal@users.noreply.github.com>
1 parent 3e12381 commit 0ba2c7c

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

alchemy/src/cloudflare/sveltekit/plugin.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ import adapter, { type AdapterOptions } from "@sveltejs/adapter-cloudflare";
22
import type { Adapter } from "@sveltejs/kit";
33
import { getPlatformProxyOptions } from "../cloudflare-env-proxy.ts";
44

5-
const isSvelteLanguageServer = !!process.argv.find((arg) =>
6-
arg.includes("svelte-language-server"),
7-
);
8-
95
export default (options?: AdapterOptions): Adapter => {
10-
if (isSvelteLanguageServer) {
11-
// the svelte language server runs from the root and therefore may be running in a different cwd than the `Website.cwd`
12-
// for now, we work around this by returning a noop adapter to avoid breaking svelte intellisense
6+
if (shouldDisable()) {
137
return {
14-
adapt() {},
158
name: "alchemy-noop",
9+
adapt() {},
1610
};
1711
}
1812
const { platformProxy: proxyOptions, ...config } = options ?? {};
@@ -23,3 +17,18 @@ export default (options?: AdapterOptions): Adapter => {
2317
...config,
2418
});
2519
};
20+
21+
/**
22+
* Return true for `svelte-language-server`, `svelte-check`, and `svelte-kit sync`. This is because:
23+
* - The svelte language server runs from the root and therefore may be running in a different cwd than the `Website.cwd`, so disable to avoid breaking intellisense
24+
* - The `svelte-check` and `svelte-kit sync` commands do not require Cloudflare-specific configuration, so disable to avoid breaking the commands
25+
*/
26+
function shouldDisable(argv = process.argv): boolean {
27+
return (
28+
argv.some(
29+
(arg) =>
30+
arg.includes("svelte-check") || arg.includes("svelte-language-server"),
31+
) ||
32+
(argv.some((arg) => arg.includes("svelte-kit")) && argv.includes("sync"))
33+
);
34+
}

alchemy/src/cloudflare/vite/vite.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "pathe";
22
import { getPackageManagerRunner } from "../../util/detect-package-manager.ts";
33
import type { Assets } from "../assets.ts";
44
import type { Bindings } from "../bindings.ts";
5+
import { withSkipPathValidation } from "../miniflare/paths.ts";
56
import {
67
spreadBuildProps,
78
spreadDevProps,
@@ -34,8 +35,9 @@ export async function Vite<B extends Bindings>(
3435
port = args[index + 1];
3536
} else {
3637
try {
37-
const config = await import(
38-
path.resolve(props.cwd ?? process.cwd(), "vite.config.ts")
38+
const config = await withSkipPathValidation(
39+
() =>
40+
import(path.resolve(props.cwd ?? process.cwd(), "vite.config.ts")),
3941
);
4042
port = config.default?.server?.port ?? 5173;
4143
} catch {}

0 commit comments

Comments
 (0)