Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Fix compatibility with `react-native-legal` ([#5253](https://github.com/getsentry/sentry-react-native/pull/5253))
- The licenses json file is correctly generated and placed into the `res/` folder now
- Handle missing shouldAddToIgnoreList callback in Metro ([#5260](https://github.com/getsentry/sentry-react-native/pull/5260))

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/js/tools/vendor/metro/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Please check the version of Metro you are using and report the issue at http://w
// Always generate source maps, can't use Sentry without source maps
const map = sourceMapStringFunction([...preModules, ...getSortedModules(graph, options)], {
processModuleFilter: options.processModuleFilter,
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
shouldAddToIgnoreList: options.shouldAddToIgnoreList || (() => false),
});
return { code, map };
};
Expand Down
55 changes: 40 additions & 15 deletions packages/core/test/tools/sentryMetroSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,48 @@ describe('Sentry Metro Serializer', () => {
expect(bundle.code).toEqual(fs.readFileSync(`${__dirname}/fixtures/bundleWithPrelude.js.fixture`, 'utf8'));
expect(bundle.map).toEqual(fs.readFileSync(`${__dirname}/fixtures/bundleWithPrelude.js.fixture.map`, 'utf8'));
});

test('works when shouldAddToIgnoreList is undefined', async () => {
const serializer = createSentryMetroSerializer();
const args = mockMinSerializerArgs({ shouldAddToIgnoreList: undefined });

const bundle = await serializer(...args);

expect(bundle).toBeDefined();
if (typeof bundle !== 'string') {
expect(bundle.code).toBeDefined();
expect(bundle.map).toBeDefined();
const debugId = determineDebugIdFromBundleSource(bundle.code);
expect(debugId).toMatch(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/);
}
});
});

function mockMinSerializerArgs(): Parameters<MetroSerializer> {
function mockMinSerializerArgs(options?: {
shouldAddToIgnoreList?: ((module: Module<MixedOutput>) => boolean) | undefined;
}): Parameters<MetroSerializer> {
let modulesCounter = 0;

const baseOptions: Record<string, any> = {
asyncRequireModulePath: 'asyncRequire',
createModuleId: (_filePath: string): number => modulesCounter++,
dev: false,
getRunModuleStatement: (_moduleId: string | number): string => '',
includeAsyncPaths: false,
modulesOnly: false,
processModuleFilter: (_module: Module<MixedOutput>) => true,
projectRoot: '/project/root',
runBeforeMainModule: [],
runModule: false,
serverRoot: '/server/root',
};

if (options && 'shouldAddToIgnoreList' in options) {
baseOptions.shouldAddToIgnoreList = options.shouldAddToIgnoreList;
} else {
baseOptions.shouldAddToIgnoreList = (_module: Module<MixedOutput>) => false;
}

return [
'index.js',
[],
Expand All @@ -68,20 +106,7 @@ function mockMinSerializerArgs(): Parameters<MetroSerializer> {
unstable_transformProfile: 'hermes-stable',
},
},
{
asyncRequireModulePath: 'asyncRequire',
createModuleId: (_filePath: string): number => modulesCounter++,
dev: false,
getRunModuleStatement: (_moduleId: string | number): string => '',
includeAsyncPaths: false,
modulesOnly: false,
processModuleFilter: (_module: Module<MixedOutput>) => true,
projectRoot: '/project/root',
runBeforeMainModule: [],
runModule: false,
serverRoot: '/server/root',
shouldAddToIgnoreList: (_module: Module<MixedOutput>) => false,
},
baseOptions as any,
];
}

Expand Down
Loading