How to use @yarnpkg/core?

Костя Третяк - Feb 27 '21 - - Dev Community

I see that on yarn repository mentions about @yarnpkg/core:

allows any application to manipulate a project programmatically.

Okay, that's what I need! But how to use it? I also found the API documentation, but I don't understand how to programmatically install a package from npmjs.com, for example.

Pseudocode of what I want:

import { someUtil } from '@yarnpkg/core';

async function myTest(packageName: string) {
  await someUtil.add(packageName); // Installing from npmjs.com
  const package = await import(packageName); // Load the newly installed package from node_modules.
  package.doSomething(); // Work with the package
}

myTest('somePackage'); // Imagine that I run this function from an HTTP request
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . .
Terabox Video Player