(packageName, fromDir)
| 247 | } |
| 248 | |
| 249 | function resolvePackageDir(packageName, fromDir) { |
| 250 | let currentDir = fromDir; |
| 251 | const root = path.parse(currentDir).root; |
| 252 | |
| 253 | while (true) { |
| 254 | const packageJsonPath = path.join(currentDir, 'node_modules', packageName, 'package.json'); |
| 255 | if (fs.existsSync(packageJsonPath)) { |
| 256 | const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 257 | if (packageJson.name === packageName) { |
| 258 | return path.dirname(packageJsonPath); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if (currentDir === root) { |
| 263 | break; |
| 264 | } |
| 265 | currentDir = path.dirname(currentDir); |
| 266 | } |
| 267 | |
| 268 | throw new Error(`Could not resolve the package directory for ${packageName}`); |
| 269 | } |
| 270 | |
| 271 | function copyDirectory(from, to) { |
| 272 | fs.mkdirSync(path.dirname(to), {recursive: true}); |
no test coverage detected