Merge branch 'renovate/all-minor-patch' into 'main'
[ProtonMail-WebClient.git] / packages / srp / jest.resolver.js
blobaf00635d09e15cce67f4c54ae3779342dc79df4d
1 /**
2 * (NB: this resolver is slightly different from the one under each 'applications/' tests, as here we
3 * also need to manually resolve 'browser' exports, probably due to different Jest presets).
5 * Jest seems to never resolve the 'import' or 'browser' conditions from the package.json `exports`,
6 * and instead it only looks for e.g. ['require', 'default', 'node', 'node-addons']
7 * Since we rely on babel to transform ESM file, we can force the resolver to also consider
8 * the 'import' and 'browser' fields, if the default resolution method fails.
9 * However, this means that the CJS conditions always have priority in the module resolution,
10 * which might cause unexpected issues in some packages (but not in the ones we currently use).
12 module.exports = function (request, options) {
13 try {
14 return options.defaultResolver(request, options);
15 } catch (err) {
16 if (options.conditions) {
17 return options.defaultResolver(request, { ...options, conditions: ['browser', 'import'] });