Skip to content

Commit 3ef3139

Browse files
committed
use value injection on instrument-client
1 parent 8beaa4e commit 3ef3139

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ function addValueInjectionLoader(
744744
});
745745
} else {
746746
newConfig.module.rules.push({
747-
test: /sentry\.client\.config\.(jsx?|tsx?)/,
747+
test: /(?:sentry\.client\.config\.(jsx?|tsx?)|(?:src[\\/])?instrumentation-client\.(js|ts))$/,
748748
use: [
749749
{
750750
loader: path.resolve(__dirname, 'loaders/valueInjectionLoader.js'),

packages/nextjs/test/config/loaders.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe('webpack loaders', () => {
240240
});
241241

242242
expect(finalWebpackConfig.module.rules).toContainEqual({
243-
test: /sentry\.client\.config\.(jsx?|tsx?)/,
243+
test: /(?:sentry\.client\.config\.(jsx?|tsx?)|(?:src[\\/])?instrumentation-client\.(js|ts))$/,
244244
use: [
245245
{
246246
loader: expect.stringMatching(/valueInjectionLoader\.js$/),

packages/nextjs/test/config/valueInjectionLoader.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,70 @@ describe('valueInjectionLoader', () => {
3535
expect(result).toMatch(';globalThis["foo"] = "bar";');
3636
});
3737

38+
it('should work with instrumentation-client.js files', () => {
39+
const instrumentationLoaderThis = {
40+
...loaderThis,
41+
resourcePath: './instrumentation-client.js',
42+
};
43+
44+
const userCode = `
45+
import * as Sentry from '@sentry/nextjs';
46+
Sentry.init();
47+
`;
48+
49+
const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);
50+
51+
expect(result).toMatch(';globalThis["foo"] = "bar";');
52+
});
53+
54+
it('should work with instrumentation-client.ts files', () => {
55+
const instrumentationLoaderThis = {
56+
...loaderThis,
57+
resourcePath: './instrumentation-client.ts',
58+
};
59+
60+
const userCode = `
61+
import * as Sentry from '@sentry/nextjs';
62+
Sentry.init();
63+
`;
64+
65+
const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);
66+
67+
expect(result).toMatch(';globalThis["foo"] = "bar";');
68+
});
69+
70+
it('should work with src/instrumentation-client.js files', () => {
71+
const instrumentationLoaderThis = {
72+
...loaderThis,
73+
resourcePath: './src/instrumentation-client.js',
74+
};
75+
76+
const userCode = `
77+
import * as Sentry from '@sentry/nextjs';
78+
Sentry.init();
79+
`;
80+
81+
const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);
82+
83+
expect(result).toMatch(';globalThis["foo"] = "bar";');
84+
});
85+
86+
it('should work with src/instrumentation-client.ts files', () => {
87+
const instrumentationLoaderThis = {
88+
...loaderThis,
89+
resourcePath: './src/instrumentation-client.ts',
90+
};
91+
92+
const userCode = `
93+
import * as Sentry from '@sentry/nextjs';
94+
Sentry.init();
95+
`;
96+
97+
const result = valueInjectionLoader.call(instrumentationLoaderThis, userCode);
98+
99+
expect(result).toMatch(';globalThis["foo"] = "bar";');
100+
});
101+
38102
it('should correctly insert values with directive', () => {
39103
const userCode = `
40104
"use client"

0 commit comments

Comments
 (0)