Skip to content

Commit 5e5bd44

Browse files
authored
feat: Only emit __esModule properties in CJS modules when there is a default export (#15018)
1 parent aaf7d53 commit 5e5bd44

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), '.
3030
export function makeBaseNPMConfig(options = {}) {
3131
const {
3232
entrypoints = ['src/index.ts'],
33-
esModuleInterop = false,
3433
hasBundles = false,
3534
packageSpecificConfig = {},
3635
sucrase = {},
@@ -56,9 +55,8 @@ export function makeBaseNPMConfig(options = {}) {
5655

5756
sourcemap: true,
5857

59-
// Include __esModule property when generating exports
60-
// Before the upgrade to Rollup 4 this was included by default and when it was gone it broke tests
61-
esModule: true,
58+
// Include __esModule property when there is a default prop
59+
esModule: 'if-default-prop',
6260

6361
// output individual files rather than one big bundle
6462
preserveModules: true,
@@ -84,16 +82,7 @@ export function makeBaseNPMConfig(options = {}) {
8482
// (We don't need it, so why waste the bytes?)
8583
freeze: false,
8684

87-
// Equivalent to `esModuleInterop` in tsconfig.
88-
// Controls whether rollup emits helpers to handle special cases where turning
89-
// `import * as dogs from 'dogs'`
90-
// into
91-
// `const dogs = require('dogs')`
92-
// doesn't work.
93-
//
94-
// `auto` -> emit helpers
95-
// `esModule` -> don't emit helpers
96-
interop: esModuleInterop ? 'auto' : 'esModule',
85+
interop: 'esModule',
9786
},
9887

9988
plugins: [

packages/react/rollup.npm.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu
22

33
export default makeNPMConfigVariants(
44
makeBaseNPMConfig({
5-
esModuleInterop: true,
65
packageSpecificConfig: {
76
external: ['react', 'react/jsx-runtime'],
87
},

packages/react/test/sdk.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import * as SentryBrowser from '@sentry/browser';
22
import { version } from 'react';
33
import { init } from '../src/sdk';
44

5+
jest.mock('@sentry/browser', () => {
6+
return {
7+
__esModule: true,
8+
...jest.requireActual('@sentry/browser'),
9+
};
10+
});
11+
512
describe('init', () => {
613
it('sets the React version (if available) in the global scope', () => {
714
const setContextSpy = jest.spyOn(SentryBrowser, 'setContext');

packages/remix/test/index.client.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import * as SentryReact from '@sentry/react';
22

33
import { init } from '../src/index.client';
44

5+
jest.mock('@sentry/react', () => {
6+
return {
7+
__esModule: true,
8+
...jest.requireActual('@sentry/react'),
9+
};
10+
});
11+
512
const reactInit = jest.spyOn(SentryReact, 'init');
613

714
describe('Client init()', () => {

packages/remix/test/index.server.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import * as SentryNode from '@sentry/node';
22

33
import { init } from '../src/index.server';
44

5+
jest.mock('@sentry/node', () => {
6+
return {
7+
__esModule: true,
8+
...jest.requireActual('@sentry/node'),
9+
};
10+
});
11+
512
const nodeInit = jest.spyOn(SentryNode, 'init');
613

714
describe('Server init()', () => {

0 commit comments

Comments
 (0)