Skip to content

Commit b1e9535

Browse files
committed
STASH
1 parent 7dc6216 commit b1e9535

File tree

3 files changed

+90
-17
lines changed

3 files changed

+90
-17
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type WebpackConfigFunction = (config: WebpackConfigObject, options: Build
4141
export type WebpackConfigObject = {
4242
devtool?: string;
4343
plugins?: Array<WebpackPluginInstance | SentryWebpackPlugin>;
44+
// plugins?: Array<WebpackPluginInstance & { options?: SentryWebpackPluginOptions }>;
4445
entry: WebpackEntryProperty;
4546
output: { filename: string; path: string };
4647
target: string;

packages/nextjs/src/config/webpack.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getSentryRelease } from '@sentry/node';
22
import { dropUndefinedKeys, logger } from '@sentry/utils';
3+
// import * as SentryWebpackPlugin from '@sentry/webpack-plugin';
34
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
45
import * as fs from 'fs';
56
import * as path from 'path';
@@ -85,6 +86,9 @@ export function constructWebpackConfigFunction(
8586
newConfig.plugins = newConfig.plugins || [];
8687

8788
const definePluginInstance = findWebpackPlugin(newConfig, 'DefinePlugin') as DefinePlugin;
89+
// const definePluginInstance = newConfig.plugins.find(
90+
// plugin => plugin.constructor.name === 'DefinePlugin',
91+
// ) as DefinePlugin;
8892

8993
if (definePluginInstance) {
9094
definePluginInstance.definitions['__rewriteFramesDistDir__'] = distDir;

packages/nextjs/test/config.test.ts

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs';
22
import * as os from 'os';
33
import * as path from 'path';
44
import * as rimraf from 'rimraf';
5+
import { DefinePlugin } from 'webpack';
56

67
import { withSentryConfig } from '../src/config';
78
import {
@@ -326,6 +327,43 @@ describe('webpack config', () => {
326327
);
327328
});
328329
});
330+
331+
describe.only('`distDir` value in default server-side `RewriteFrames` integration', () => {
332+
describe('`DefinePlugin` existence and inclusion of `__rewriteFramesDistDir__` definition', () => {
333+
it.each([
334+
['no custom `distDir`, pre-existing `DefinePlugin`', undefined, true],
335+
['no custom `distDir`, no pre-existing `DefinePlugin`', undefined, false],
336+
['custom `distDir`, pre-existing `DefinePlugin`', 'some/output/directory', true],
337+
['custom `distDir`, no pre-existing `DefinePlugin`', 'some/output/directory', false],
338+
])(
339+
'%s',
340+
async (_testTitle: string, customDistDir: string | undefined, existingDefinePlugin: boolean): Promise<void> => {
341+
const userNextConfigMaybeWithDistDir = {
342+
...userNextConfig,
343+
...(customDistDir && { distDir: customDistDir }),
344+
};
345+
const serverWebpackConfigMaybeWithDefinePlugin = {
346+
...serverWebpackConfig,
347+
...(existingDefinePlugin && { plugins: [new DefinePlugin({ __dogName__: 'Maisey' })] }),
348+
};
349+
350+
const finalWebpackConfig = await materializeFinalWebpackConfig({
351+
userNextConfig: userNextConfigMaybeWithDistDir,
352+
incomingWebpackConfig: serverWebpackConfigMaybeWithDefinePlugin,
353+
incomingWebpackBuildContext: getBuildContext('server', userNextConfigMaybeWithDistDir),
354+
});
355+
356+
expect(finalWebpackConfig.plugins).toEqual(expect.arrayContaining([expect.any(DefinePlugin)]));
357+
358+
const definePluginInstance = findWebpackPlugin(finalWebpackConfig, 'DefinePlugin') as DefinePlugin;
359+
expect(definePluginInstance.definitions.__rewriteFramesDistDir__).toEqual(customDistDir);
360+
},
361+
);
362+
});
363+
describe('`RewriteFrames` ends up with correct `distDir` value', () => {
364+
// TODO: this, along with any number of other parts of the build process, should be tested with an integration test
365+
});
366+
});
329367
});
330368

331369
describe('Sentry webpack plugin config', () => {
@@ -337,6 +375,7 @@ describe('Sentry webpack plugin config', () => {
337375
incomingWebpackConfig: serverWebpackConfig,
338376
incomingWebpackBuildContext: serverBuildContext,
339377
});
378+
340379
const sentryWebpackPluginInstance = findWebpackPlugin(
341380
finalWebpackConfig,
342381
'SentryCliPlugin',
@@ -366,7 +405,12 @@ describe('Sentry webpack plugin config', () => {
366405
incomingWebpackBuildContext: serverBuildContext,
367406
});
368407

369-
expect((finalWebpackConfig.plugins?.[0].options as SentryWebpackPluginOptions).debug).toEqual(true);
408+
const sentryWebpackPluginInstance = findWebpackPlugin(
409+
finalWebpackConfig,
410+
'SentryCliPlugin',
411+
) as SentryWebpackPluginType;
412+
413+
expect(sentryWebpackPluginInstance.options.debug).toEqual(true);
370414
});
371415

372416
it('warns when overriding certain default values', () => {
@@ -385,9 +429,12 @@ describe('Sentry webpack plugin config', () => {
385429
incomingWebpackBuildContext: clientBuildContext,
386430
});
387431

388-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
432+
const sentryWebpackPluginInstance = findWebpackPlugin(
433+
finalWebpackConfig,
434+
'SentryCliPlugin',
435+
) as SentryWebpackPluginType;
389436

390-
expect(sentryWebpackPlugin.options?.include).toEqual([
437+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
391438
{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' },
392439
]);
393440
});
@@ -402,9 +449,12 @@ describe('Sentry webpack plugin config', () => {
402449
incomingWebpackBuildContext: getBuildContext('server', userNextConfigServerless),
403450
});
404451

405-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
452+
const sentryWebpackPluginInstance = findWebpackPlugin(
453+
finalWebpackConfig,
454+
'SentryCliPlugin',
455+
) as SentryWebpackPluginType;
406456

407-
expect(sentryWebpackPlugin.options?.include).toEqual([
457+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
408458
{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' },
409459
]);
410460
});
@@ -419,9 +469,12 @@ describe('Sentry webpack plugin config', () => {
419469
incomingWebpackBuildContext: serverBuildContextWebpack4,
420470
});
421471

422-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
472+
const sentryWebpackPluginInstance = findWebpackPlugin(
473+
finalWebpackConfig,
474+
'SentryCliPlugin',
475+
) as SentryWebpackPluginType;
423476

424-
expect(sentryWebpackPlugin.options?.include).toEqual([
477+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
425478
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
426479
]);
427480
});
@@ -433,9 +486,12 @@ describe('Sentry webpack plugin config', () => {
433486
incomingWebpackBuildContext: serverBuildContext,
434487
});
435488

436-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
489+
const sentryWebpackPluginInstance = findWebpackPlugin(
490+
finalWebpackConfig,
491+
'SentryCliPlugin',
492+
) as SentryWebpackPluginType;
437493

438-
expect(sentryWebpackPlugin.options?.include).toEqual([
494+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
439495
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
440496
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
441497
]);
@@ -455,9 +511,12 @@ describe('Sentry webpack plugin config', () => {
455511
incomingWebpackBuildContext: getBuildContext('client', userNextConfigWithBasePath),
456512
});
457513

458-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
514+
const sentryWebpackPluginInstance = findWebpackPlugin(
515+
finalWebpackConfig,
516+
'SentryCliPlugin',
517+
) as SentryWebpackPluginType;
459518

460-
expect(sentryWebpackPlugin.options?.include).toEqual([
519+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
461520
{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/city-park/_next/static/chunks/pages' },
462521
]);
463522
});
@@ -472,9 +531,12 @@ describe('Sentry webpack plugin config', () => {
472531
incomingWebpackBuildContext: getBuildContext('server', userNextConfigServerless),
473532
});
474533

475-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
534+
const sentryWebpackPluginInstance = findWebpackPlugin(
535+
finalWebpackConfig,
536+
'SentryCliPlugin',
537+
) as SentryWebpackPluginType;
476538

477-
expect(sentryWebpackPlugin.options?.include).toEqual([
539+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
478540
{ paths: ['.next/serverless/'], urlPrefix: '~/city-park/_next/serverless' },
479541
]);
480542
});
@@ -489,9 +551,12 @@ describe('Sentry webpack plugin config', () => {
489551
incomingWebpackBuildContext: serverBuildContextWebpack4,
490552
});
491553

492-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
554+
const sentryWebpackPluginInstance = findWebpackPlugin(
555+
finalWebpackConfig,
556+
'SentryCliPlugin',
557+
) as SentryWebpackPluginType;
493558

494-
expect(sentryWebpackPlugin.options?.include).toEqual([
559+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
495560
{ paths: ['.next/server/pages/'], urlPrefix: '~/city-park/_next/server/pages' },
496561
]);
497562
});
@@ -503,9 +568,12 @@ describe('Sentry webpack plugin config', () => {
503568
incomingWebpackBuildContext: getBuildContext('server', userNextConfigWithBasePath),
504569
});
505570

506-
const sentryWebpackPlugin = finalWebpackConfig.plugins?.[0] as SentryWebpackPluginType;
571+
const sentryWebpackPluginInstance = findWebpackPlugin(
572+
finalWebpackConfig,
573+
'SentryCliPlugin',
574+
) as SentryWebpackPluginType;
507575

508-
expect(sentryWebpackPlugin.options?.include).toEqual([
576+
expect(sentryWebpackPluginInstance.options?.include).toEqual([
509577
{ paths: ['.next/server/pages/'], urlPrefix: '~/city-park/_next/server/pages' },
510578
{ paths: ['.next/server/chunks/'], urlPrefix: '~/city-park/_next/server/chunks' },
511579
]);

0 commit comments

Comments
 (0)