Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

How to resolve main fields #2

Closed
eps1lon opened this issue Aug 2, 2019 · 1 comment · Fixed by #6
Closed

How to resolve main fields #2

eps1lon opened this issue Aug 2, 2019 · 1 comment · Fixed by #6

Comments

@eps1lon
Copy link

eps1lon commented Aug 2, 2019

As of right now this plugin cannot be used as a drop-in for rollup-plugin-node-resolve because it ignores mainfields. It was mentioned in webpack/enhanced-resolve#162 (comment) that this should be done in a separate plugin but mainfields used throughout many packages to identify commonJS and ES module builds while extensions are rarely used to identify these.

Would you consider adding support for a mainFields option to this plugin? I would like to put together a pull request for this.

Right now I'm using this custom jest resolver

/**
 * Uses the specified mainField with PnP resolution
 * @param {string} request
 * @param {string} mainField
 * @param {JestResolverOptions} resolverOptions
 */
function resolveMainField(request, mainField, resolverOptions) {
	const issuer = `${resolverOptions.basedir}/`;
	const location = pnp.resolveToUnqualified(request, issuer, {
		extensions: resolverOptions.extensions,
	});
	/* 
	 * intuitevly packageInformation points to @material-ui/core's package.json
	 * but it returns the workspace root 
	const locator = pnp.findPackageLocator(location);
	const packageInformation = pnp.getPackageInformation(locator); */
	const packageJson = fse.readJsonSync(
		path.resolve(location, './package.json'),
	);

	const resolution = path.resolve(location, packageJson[mainField]);
	return resolution;
}

Overall I feel like I'm missing something because this goes back to resolve-by-filesystem. Shouldn't this information be available via pnpapi?

@crubier
Copy link

crubier commented Oct 17, 2019

Same problem here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants