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
Hi there. What's the reason for wanting to add a package to another? using @yarnpkg/core might be a little too low level for what you need, it's essentially reimplementing how yarn installs/resolves modules in your own app.
If it sounds like what you need, then take a look at this test in the yarnpkg/core directory. It includes making a temporary directory, downloading the package to it, and modifying the target package. github.com/yarnpkg/berry/blob/mast....
It sounds like you want to use the
patch:
protocol. After installing the package (defined in your package.json), then your patch will modify the package. yarnpkg.com/features/protocols#patch. This is a lot simpler than the above.good luck!