Skip to content

Commit b6e0c8a

Browse files
committed
fixup! feat(cloudflare): Add wranglerConfigPath to Vite options
1 parent 5d3d065 commit b6e0c8a

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

packages/cloudflare/src/vite/autoInstrument.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { basename } from 'node:path';
12
import { collectAgentCandidates, detectAgentClasses, type ModuleResolver } from './agentClass';
23
import { buildOptionsImport, ENV_FALLBACK_OPTIONS_FN, resolveInstrumentFile } from './instrumentFile';
34
import { applyAutoInstrumentTransforms, type ClassWrapperKind, type ProgramBody } from './transform';
@@ -32,7 +33,7 @@ export function sentryCloudflareAutoInstrumentPlugin(options: { wranglerConfigPa
3233
// `configPath` handed to @cloudflare/vite-plugin) are discoverable.
3334
config.logger?.warn(
3435
options.wranglerConfigPath
35-
? `[sentry] Could not find or parse the wrangler config at "${options.wranglerConfigPath}" ` +
36+
? `[sentry] Could not find or parse the wrangler config "${basename(options.wranglerConfigPath)}" ` +
3637
'(resolved against the Vite root) — auto-instrumentation disabled.'
3738
: '[sentry] No parseable wrangler config found — auto-instrumentation disabled. ' +
3839
'Set `wranglerConfigPath` if your config uses a custom name.',

packages/cloudflare/test/vite/autoInstrument.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,16 @@ describe('wranglerConfigPath option', () => {
391391
expect(await tx(join(dir, 'src/agent.ts'))).toBeDefined();
392392
});
393393

394-
it('warns with the explicit path when it cannot be read', () => {
394+
it('warns with only the basename when the explicit path cannot be read', () => {
395395
const dir = writeTempDir({});
396396
const warnings: string[] = [];
397-
const plugin = sentryCloudflareAutoInstrumentPlugin({ wranglerConfigPath: './wrangler.agent.jsonc' });
397+
const plugin = sentryCloudflareAutoInstrumentPlugin({ wranglerConfigPath: 'nested/dir/wrangler.agent.jsonc' });
398398
plugin.configResolved({ root: dir, logger: { warn: msg => warnings.push(msg) } });
399399

400400
expect(warnings).toHaveLength(1);
401-
expect(warnings[0]).toContain('./wrangler.agent.jsonc');
401+
expect(warnings[0]).toContain('wrangler.agent.jsonc');
402+
// The full path may leak a location the user doesn't want in build logs.
403+
expect(warnings[0]).not.toContain('nested/dir');
402404
});
403405

404406
it('hints at the option when no default-named config is found', () => {

0 commit comments

Comments
 (0)