yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.48k stars 1.12k forks source link

[Case Study] Provide examples and more explanations for @yarnpkg/core node api #1654

Open fengzilong opened 4 years ago

fengzilong commented 4 years ago

What package is covered by this investigations?

@yarnpkg/core

Describe the goal of the investigation

the api website for @yarnpkg/core is too hard to read and understand with so many classes/functions, and some of them may be internally used or without any explanation

can we provide some basic examples for @yarnpkg/core node api, to help us better understand the usage of it

Investigation report

more examples and explanations please, if there is already one please point out

fengzilong commented 4 years ago

https://yarnpkg.com/api/classes/yarnpkg_core.manifest.html

for example, I don't know what Manifest is, when and how to use it

missing1984 commented 4 years ago

+1. I've spent a lot of time to read the code and guess how things work. I would love to see better documentation for yarn programming API.

KostyaTretyak commented 3 years ago

As far as I understand, the API for @yarnpkg/core has existed for more than two years, and it is very surprising that even README is not on github.

Please, help me. I want users to be able to add npm packages to an already running web application. That is, that they add npm package on the fly without having to restart the application.

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

How can I use the @yarnpkg/core API to implement this functionality?

KaivnD commented 3 years ago

+1