-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathresolver.cjs
29 lines (26 loc) · 1007 Bytes
/
resolver.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// @ts-check
const { dirname, resolve } = require('path');
const resolveFrom = require('resolve-from');
/**
* @typedef {{
* basedir: string;
* conditions?: Array<string>;
* defaultResolver: (path: string, options: ResolverOptions) => string;
* extensions?: Array<string>;
* moduleDirectory?: Array<string>;
* paths?: Array<string>;
* packageFilter?: (pkg: any, file: string, dir: string) => any;
* pathFilter?: (pkg: any, path: string, relativePath: string) => string;
* rootDir?: string;
* }} ResolverOptions
* */
/** @type {(path: string, options: ResolverOptions) => string} */
module.exports = (path, options) => {
// workaround for https://github.com/facebook/jest/issues/12270
if (path === '#ansi-styles' || path === '#supports-color') {
const chalkRoot = resolve(dirname(resolveFrom(options.basedir, 'chalk')), '../');
const subPkgName = path.slice(1);
return `${chalkRoot}/source/vendor/${subPkgName}/index.js`;
}
return options.defaultResolver(path, options);
};