Skip to content

Commit 7a01742

Browse files
authored
feat(nextjs): Remove transpileClientSDK (#11978)
I dropped the ball on this a bit to deprecate but removing it now should still be fine.
1 parent 1098627 commit 7a01742

File tree

3 files changed

+6
-102
lines changed

3 files changed

+6
-102
lines changed

MIGRATION.md

+6
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,12 @@ in order to inject the `sentry.(server|edge).config.ts` files into the server-si
866866
possible in the future, we are doing ourselves a favor and doing things the way Next.js intends us to do them -
867867
hopefully reducing bugs and jank.
868868

869+
#### Removal of `transpileClientSDK`
870+
871+
Since we are dropping support for Internet Explorer 11 and other other older browser versions, we are also removing the
872+
`transpileClientSDK` option from the Next.js SDK. If you need to support these browser versions, please configure
873+
Webpack and Next.js to down-compile the SDK.
874+
869875
### Astro SDK
870876

871877
- [Removal of `trackHeaders` option for Astro middleware](./MIGRATION.md#removal-of-trackheaders-option-for-astro-middleware)

packages/nextjs/src/config/types.ts

-6
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ export type SentryBuildOptions = {
334334
*/
335335
hideSourceMaps?: boolean;
336336

337-
/**
338-
* Instructs webpack to apply the same transpilation rules to the SDK code as apply to user code. Helpful when
339-
* targeting older browsers which don't support ES6 (or ES6+ features like object spread).
340-
*/
341-
transpileClientSDK?: boolean;
342-
343337
/**
344338
* Include Next.js-internal code and code from dependencies when uploading source maps.
345339
*

packages/nextjs/src/config/webpack.ts

-96
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {
2020
WebpackConfigObject,
2121
WebpackConfigObjectWithModuleRules,
2222
WebpackEntryProperty,
23-
WebpackModuleRule,
2423
} from './types';
2524
import { getWebpackPluginOptions } from './webpackPluginOptions';
2625

@@ -305,35 +304,6 @@ export function constructWebpackConfigFunction(
305304
}
306305
}
307306

308-
// TODO(v8): Remove this logic since we are deprecating es5.
309-
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
310-
// who want to support such browsers, `transpileClientSDK` allows them to force the SDK code to go through the same
311-
// transpilation that their code goes through. We don't turn this on by default because it increases bundle size
312-
// fairly massively.
313-
if (!isServer && userSentryOptions?.transpileClientSDK) {
314-
// Find all loaders which apply transpilation to user code
315-
const transpilationRules = findTranspilationRules(newConfig.module?.rules, projectDir);
316-
317-
// For each matching rule, wrap its `exclude` function so that it won't exclude SDK files, even though they're in
318-
// `node_modules` (which is otherwise excluded)
319-
transpilationRules.forEach(rule => {
320-
// All matching rules will necessarily have an `exclude` property, but this keeps TS happy
321-
if (rule.exclude && typeof rule.exclude === 'function') {
322-
const origExclude = rule.exclude;
323-
324-
const newExclude = (filepath: string): boolean => {
325-
if (filepath.includes('@sentry')) {
326-
// `false` in this case means "don't exclude it"
327-
return false;
328-
}
329-
return origExclude(filepath);
330-
};
331-
332-
rule.exclude = newExclude;
333-
}
334-
});
335-
}
336-
337307
if (!isServer) {
338308
// Tell webpack to inject the client config files (containing the client-side `Sentry.init()` call) into the appropriate output
339309
// bundles. Store a separate reference to the original `entry` value to avoid an infinite loop. (If we don't do
@@ -385,72 +355,6 @@ export function constructWebpackConfigFunction(
385355
};
386356
}
387357

388-
/**
389-
* Determine if this `module.rules` entry is one which will transpile user code
390-
*
391-
* @param rule The rule to check
392-
* @param projectDir The path to the user's project directory
393-
* @returns True if the rule transpiles user code, and false otherwise
394-
*/
395-
function isMatchingRule(rule: WebpackModuleRule, projectDir: string): boolean {
396-
// We want to run our SDK code through the same transformations the user's code will go through, so we test against a
397-
// sample user code path
398-
const samplePagePath = path.resolve(projectDir, 'pageFile.js');
399-
if (rule.test && rule.test instanceof RegExp && !rule.test.test(samplePagePath)) {
400-
return false;
401-
}
402-
if (Array.isArray(rule.include) && !rule.include.includes(projectDir)) {
403-
return false;
404-
}
405-
406-
// `rule.use` can be an object or an array of objects. For simplicity, force it to be an array.
407-
const useEntries = arrayify(rule.use);
408-
409-
// Depending on the version of nextjs we're talking about, the loader which does the transpiling is either
410-
//
411-
// 'next-babel-loader' (next 10),
412-
// '/abs/path/to/node_modules/next/more/path/babel/even/more/path/loader/yet/more/path/index.js' (next 11), or
413-
// 'next-swc-loader' (next 12).
414-
//
415-
// The next 11 option is ugly, but thankfully 'next', 'babel', and 'loader' do appear in it in the same order as in
416-
// 'next-babel-loader', so we can use the same regex to test for both.
417-
if (!useEntries.some(entry => entry?.loader && /next.*(babel|swc).*loader/.test(entry.loader))) {
418-
return false;
419-
}
420-
421-
return true;
422-
}
423-
424-
/**
425-
* Find all rules in `module.rules` which transpile user code.
426-
*
427-
* @param rules The `module.rules` value
428-
* @param projectDir The path to the user's project directory
429-
* @returns An array of matching rules
430-
*/
431-
function findTranspilationRules(rules: WebpackModuleRule[] | undefined, projectDir: string): WebpackModuleRule[] {
432-
if (!rules) {
433-
return [];
434-
}
435-
436-
const matchingRules: WebpackModuleRule[] = [];
437-
438-
// Each entry in `module.rules` is either a rule in and of itself or an object with a `oneOf` property, whose value is
439-
// an array of rules
440-
rules.forEach(rule => {
441-
// if (rule.oneOf) {
442-
if (isMatchingRule(rule, projectDir)) {
443-
matchingRules.push(rule);
444-
} else if (rule.oneOf) {
445-
const matchingOneOfRules = rule.oneOf.filter(oneOfRule => isMatchingRule(oneOfRule, projectDir));
446-
matchingRules.push(...matchingOneOfRules);
447-
// } else if (isMatchingRule(rule, projectDir)) {
448-
}
449-
});
450-
451-
return matchingRules;
452-
}
453-
454358
/**
455359
* Modify the webpack `entry` property so that the code in `sentry.client.config.js` is
456360
* included in the the necessary bundles.

0 commit comments

Comments
 (0)