Skip to content

Commit e3692a4

Browse files
authored
Add cloudflare adapter detection and path generation (#15603)
Before submitting a pull request, please take a look at our [Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md) guidelines and verify: - [x] If you've added code that should be tested, please add tests. - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). This PR expands upon #14672 by adding detection of the @sveltejs/adapter-cloudflare adapter and defining it's output directory (cloudflare as opposed to output). I've tested it with a Cloudflare Pages project and it was successful in building and uploading sourcemaps, whereas relying on 'other' caused an infinite loop and an OOM when trying to upload sourcemaps.
1 parent e68cbec commit e3692a4

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

packages/sveltekit/src/vite/detectAdapter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Package } from '@sentry/core';
55
/**
66
* Supported @sveltejs/adapters-[adapter] SvelteKit adapters
77
*/
8-
export type SupportedSvelteKitAdapters = 'node' | 'auto' | 'vercel' | 'other';
8+
export type SupportedSvelteKitAdapters = 'node' | 'auto' | 'vercel' | 'cloudflare' | 'other';
99

1010
/**
1111
* Tries to detect the used adapter for SvelteKit by looking at the dependencies.
@@ -21,6 +21,8 @@ export async function detectAdapter(debug?: boolean): Promise<SupportedSvelteKit
2121
adapter = 'vercel';
2222
} else if (allDependencies['@sveltejs/adapter-node']) {
2323
adapter = 'node';
24+
} else if (allDependencies['@sveltejs/adapter-cloudflare']) {
25+
adapter = 'cloudflare';
2426
} else if (allDependencies['@sveltejs/adapter-auto']) {
2527
adapter = 'auto';
2628
}

packages/sveltekit/src/vite/svelteConfig.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export async function getAdapterOutputDir(svelteConfig: Config, adapter: Support
5252
if (adapter === 'node') {
5353
return getNodeAdapterOutputDir(svelteConfig);
5454
}
55+
if (adapter === 'cloudflare') {
56+
// Cloudflare outputs to outDir\cloudflare as the output dir
57+
return path.join(svelteConfig.kit?.outDir || '.svelte-kit', 'cloudflare');
58+
}
5559

5660
// Auto and Vercel adapters simply use config.kit.outDir
5761
// Let's also use this directory for the 'other' case

packages/sveltekit/test/vite/detectAdapter.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('detectAdapter', () => {
2727
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
2828
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
2929

30-
it.each(['auto', 'vercel', 'node'])(
30+
it.each(['auto', 'vercel', 'node', 'cloudflare'])(
3131
'returns the adapter name (adapter %s) and logs it to the console',
3232
async adapter => {
3333
pkgJson.dependencies[`@sveltejs/adapter-${adapter}`] = '1.0.0';
@@ -68,12 +68,16 @@ describe('detectAdapter', () => {
6868
pkgJson.dependencies['@sveltejs/adapter-auto'] = '1.0.0';
6969
pkgJson.dependencies['@sveltejs/adapter-vercel'] = '1.0.0';
7070
pkgJson.dependencies['@sveltejs/adapter-node'] = '1.0.0';
71+
pkgJson.dependencies['@sveltejs/adapter-cloudflare'] = '1.0.0';
7172

7273
const detectedAdapter = await detectAdapter();
7374
expect(detectedAdapter).toEqual('vercel');
7475

7576
delete pkgJson.dependencies['@sveltejs/adapter-vercel'];
7677
const detectedAdapter2 = await detectAdapter();
7778
expect(detectedAdapter2).toEqual('node');
79+
delete pkgJson.dependencies['@sveltejs/adapter-node'];
80+
const detectedAdapter3 = await detectAdapter();
81+
expect(detectedAdapter3).toEqual('cloudflare');
7882
});
7983
});

packages/sveltekit/test/vite/svelteConfig.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ describe('getAdapterOutputDir', () => {
6868
expect(outputDir).toEqual('customBuildDir');
6969
});
7070

71+
it('returns the output directory of the Cloudflare adapter', async () => {
72+
const outputDir = await getAdapterOutputDir({ kit: { outDir: 'customOutDir' } }, 'cloudflare');
73+
expect(outputDir).toEqual('customOutDir/cloudflare');
74+
});
75+
7176
it.each(['vercel', 'auto', 'other'] as SupportedSvelteKitAdapters[])(
7277
'returns the config.kit.outdir directory for adapter-%s',
7378
async adapter => {

0 commit comments

Comments
 (0)