MCPcopy Create free account
hub / github.com/adobe/react-spectrum / resolvePackageDir

Function resolvePackageDir

packages/dev/s2-docs/scripts/generateMcpb.mjs:249–269  ·  view source on GitHub ↗
(packageName, fromDir)

Source from the content-addressed store, hash-verified

247}
248
249function 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
271function copyDirectory(from, to) {
272 fs.mkdirSync(path.dirname(to), {recursive: true});

Callers 1

copyDependencyTreeFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected