( packageName: string, location: string, rootPackage?: string, )
| 18 | } |
| 19 | |
| 20 | export function resolve( |
| 21 | packageName: string, |
| 22 | location: string, |
| 23 | rootPackage?: string, |
| 24 | ): NodeModule | undefined { |
| 25 | rootPackage = rootPackage || packageName; |
| 26 | try { |
| 27 | const packageJsonPath = require.resolve(`${rootPackage}/package.json`, { |
| 28 | paths: [location], |
| 29 | }); |
| 30 | // Do not use require() to read JSON files since it's a potential security |
| 31 | // vulnerability. |
| 32 | const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 33 | const resolvedPath = require.resolve(packageName, { |
| 34 | paths: [location], |
| 35 | }); |
| 36 | return { |
| 37 | name: packageName, |
| 38 | resolvedPath, |
| 39 | version: new Version(packageJson.version), |
| 40 | }; |
| 41 | } catch {} |
| 42 | } |
| 43 | |
| 44 | export class Version { |
| 45 | readonly major: number; |
no test coverage detected