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

[jest-resolve] Add support for packageFilter for custom resolvers #10393

Merged
merged 9 commits into from
Aug 12, 2020

Conversation

scinos
Copy link
Contributor

@scinos scinos commented Aug 11, 2020

Summary

Forwards option packageFilter to resolve. This is useful in case a custom resolver wants to use it. The best example is #2702 (in particular, #2702 (comment))

Fixes #2702

Test plan

Write a custom resolver like

module.exports = ( request, options ) => {
	return options.defaultResolver( request, {
		...options,
		...{
			packageFilter: ( pkg ) => {
				return {
					...pkg,
					main: pkg.module || pkg.main,
				};
			},
		},
	} );
};

Then, in any jest test, when importing package X, it will try to load it from the field module first, with fallback to main if module doesn't exist.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This needs a test and an example in the docs for how this would be used to check the module prop

packages/jest-resolve/src/defaultResolver.ts Outdated Show resolved Hide resolved
};
});

const mockResolveSync = <
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full disclosure: I've never used Jest+TS, I don't know if there is a better way of doing this.

@scinos scinos requested a review from SimenB August 11, 2020 22:17
@scinos scinos requested a review from SimenB August 12, 2020 20:36
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SimenB
Copy link
Member

SimenB commented Aug 12, 2020

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support the "module" package.json field
3 participants