Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Only emit __esModule properties in CJS modules when there is a default export #15018

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), '.
export function makeBaseNPMConfig(options = {}) {
const {
entrypoints = ['src/index.ts'],
esModuleInterop = false,
hasBundles = false,
packageSpecificConfig = {},
sucrase = {},
Expand All @@ -56,9 +55,8 @@ export function makeBaseNPMConfig(options = {}) {

sourcemap: true,

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

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

// Equivalent to `esModuleInterop` in tsconfig.
// Controls whether rollup emits helpers to handle special cases where turning
// `import * as dogs from 'dogs'`
// into
// `const dogs = require('dogs')`
// doesn't work.
//
// `auto` -> emit helpers
// `esModule` -> don't emit helpers
interop: esModuleInterop ? 'auto' : 'esModule',
interop: 'esModule',
},

plugins: [
Expand Down
1 change: 0 additions & 1 deletion packages/react/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu

export default makeNPMConfigVariants(
makeBaseNPMConfig({
esModuleInterop: true,
packageSpecificConfig: {
external: ['react', 'react/jsx-runtime'],
},
Expand Down
7 changes: 7 additions & 0 deletions packages/react/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import * as SentryBrowser from '@sentry/browser';
import { version } from 'react';
import { init } from '../src/sdk';

jest.mock('@sentry/browser', () => {
return {
__esModule: true,
...jest.requireActual('@sentry/browser'),
};
});

describe('init', () => {
it('sets the React version (if available) in the global scope', () => {
const setContextSpy = jest.spyOn(SentryBrowser, 'setContext');
Expand Down
7 changes: 7 additions & 0 deletions packages/remix/test/index.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import * as SentryReact from '@sentry/react';

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

jest.mock('@sentry/react', () => {
return {
__esModule: true,
...jest.requireActual('@sentry/react'),
};
});

const reactInit = jest.spyOn(SentryReact, 'init');

describe('Client init()', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/remix/test/index.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import * as SentryNode from '@sentry/node';

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

jest.mock('@sentry/node', () => {
return {
__esModule: true,
...jest.requireActual('@sentry/node'),
};
});

const nodeInit = jest.spyOn(SentryNode, 'init');

describe('Server init()', () => {
Expand Down
Loading