Background
Prior to yarn 1.0, the packaged version of yarn made it possible to access yarn's internals programmatically. This is useful for projects like Dependabot, which effectively use yarn as a library.
Specifically,
Since yarn is now distributed as a single file (cli.js
), accessing internals is no longer possible.
Shelling out to yarn's CLI would get us some of the way there. But for tools that integrate deeply with yarn (such as Dependabot), having access to the internals means we can build a far more robust integration.
There are a couple of options that could enable this:
I'm also aware of #3397, which seems to be what triggered the creation of @yarnpkg/lockfile.
I'd love to hear your thoughts!
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
You can no longer require
yarn internals (e.g. const { Install } = require("yarn/lib/cli/commands/install");
), so yarn can't be used as a library.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
const { Install } = require("yarn/lib/cli/commands/install");
works.
Please mention your node.js, yarn and operating system version.
Node 8.2, macOS Sierra.
I'm also wondering if I can access yarn
programmatically. For example:
const sh = require('shelljs');
const yarn = require('yarn');
yarn.install(sh.pwd());
would love to use it programmatically from within electron 馃憤 馃榿
Any progress on this?
bump. see also https://github.com/yarnpkg/yarn/issues/906
Yarn 2 core will be usable as API
https://github.com/yarnpkg/berry/blob/master/README.md#generic-packages
Most helpful comment
I'm also wondering if I can access
yarn
programmatically. For example: