Skip to content

Commit e5478ad

Browse files
authored
fix(nuxt): Use absolute path for client config (#13798)
The `buildDir` can be changed in Nuxt and Adding the client config with a relative path worked so far as the `buildDir` in Nuxt v3 is [`/<rootDir>/.nuxt`](https://nuxt.com/docs/api/nuxt-config#builddir) but the `buildDir` can be modified by the user and is also different in Nuxt v4 ([`/<rootDir>/node_modules/.cache/nuxt/.nuxt`](https://github.com/nuxt/nuxt/blob/f56c05d39de5223c5fa8603ed216e91747937d54/packages/kit/src/loader/config.ts#L54)). By using the absolute path, the client config can be injected correctly with all `buildDir` variations
1 parent 225fb99 commit e5478ad

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/nuxt/src/vite/utils.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ export function findDefaultSdkInitFile(type: 'server' | 'client'): string | unde
2222
}
2323
}
2424

25-
const filePath = filePaths.find(filename => fs.existsSync(filename));
26-
27-
return filePath ? path.basename(filePath) : undefined;
25+
return filePaths.find(filename => fs.existsSync(filename));
2826
}

packages/nuxt/test/vite/utils.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ describe('findDefaultSdkInitFile', () => {
1010
});
1111

1212
it.each(['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'])(
13-
'should return the server file with .%s extension if it exists',
13+
'should return the server file path with .%s extension if it exists',
1414
ext => {
1515
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
1616
return !(filePath instanceof URL) && filePath.includes(`sentry.server.config.${ext}`);
1717
});
1818

1919
const result = findDefaultSdkInitFile('server');
20-
expect(result).toBe(`sentry.server.config.${ext}`);
20+
expect(result).toMatch(`packages/nuxt/sentry.server.config.${ext}`);
2121
},
2222
);
2323

2424
it.each(['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'])(
25-
'should return the client file with .%s extension if it exists',
25+
'should return the client file path with .%s extension if it exists',
2626
ext => {
2727
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
2828
return !(filePath instanceof URL) && filePath.includes(`sentry.client.config.${ext}`);
2929
});
3030

3131
const result = findDefaultSdkInitFile('client');
32-
expect(result).toBe(`sentry.client.config.${ext}`);
32+
expect(result).toMatch(`packages/nuxt/sentry.client.config.${ext}`);
3333
},
3434
);
3535

@@ -47,7 +47,7 @@ describe('findDefaultSdkInitFile', () => {
4747
expect(result).toBeUndefined();
4848
});
4949

50-
it('should return the server config file if server.config and instrument exist', () => {
50+
it('should return the server config file path if server.config and instrument exist', () => {
5151
vi.spyOn(fs, 'existsSync').mockImplementation(filePath => {
5252
return (
5353
!(filePath instanceof URL) &&
@@ -56,6 +56,6 @@ describe('findDefaultSdkInitFile', () => {
5656
});
5757

5858
const result = findDefaultSdkInitFile('server');
59-
expect(result).toBe('sentry.server.config.js');
59+
expect(result).toMatch('packages/nuxt/sentry.server.config.js');
6060
});
6161
});

0 commit comments

Comments
 (0)