File size: 607 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import * as imr from 'import-meta-resolve';
import { pathToFileURL } from 'node:url';

/**
 * Resolve a dependency relative to the current working directory,
 * rather than relative to this package
 * @param {string} dependency
 */
export function resolve_peer_dependency(dependency) {
	try {
		// @ts-expect-error the types are wrong
		const resolved = imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js'));
		return import(resolved);
	} catch {
		throw new Error(
			`Could not resolve peer dependency "${dependency}" relative to your project — please install it and try again.`
		);
	}
}