Konubinix' opinionated web of thoughts

Yarn

Fleeting

deduplicate with hardlinks and –link-duplicates

yarn install –link-duplicates

Create hardlinks to the repeated modules in node_modules.

https://classic.yarnpkg.com/lang/en/docs/cli/install/

workspace

  • External reference: https://classic.yarnpkg.com/en/docs/workspaces

    Allows using only one node_modules shared among sub projects (called workspaces). symlinks will be created to link workspace together and thus allowing more practical way of linking workspaces.

    dependencies can be linked together, which means that your workspaces can depend on one another while always using the most up-to-date code available. This is also a better mechanism than yarn link since it only affects your workspace tree rather than your whole system.

    https://classic.yarnpkg.com/en/docs/workspaces

    Why would you want to do this?

    • Your dependencies can be linked together, which means that your workspaces can depend on one another while always using the most up-to-date code available. This is also a better mechanism than yarn link since it only affects your workspace tree rather than your whole system.
    • All your project dependencies will be installed together, giving Yarn more latitude to better optimize them.
    • Yarn will use a single lockfile rather than a different one for each project, which means fewer conflicts and easier reviews.

    https://classic.yarnpkg.com/en/docs/workspaces

    private: true is required! Workspaces are not meant to be published

    https://classic.yarnpkg.com/en/docs/workspaces

when using workspaces, create symlinks in workspace node_modules to root node_modules

how to use “nohoist” in Yarn workspaces?

dealing with intra dependencies

note the fact that /workspace-a is aliased as /node_modules/workspace-a via a symlink. That’s the trick that allows you to require the package as if it was a normal one

https://classic.yarnpkg.com/en/docs/workspaces

beware the hoisting

For instance, if you are working on a project that is a workspace. Then its node_modules will be partially filled. You will not be able to get a fully running project by simply copy/pasting the workspace folder.

The package layout will be different between your workspace and what your users will get (the workspace dependencies will be hoisted higher into the filesystem hierarchy). Making assumptions about this layout was already hazardous since the hoisting process is not standardized, so theoretically nothing new here.

https://classic.yarnpkg.com/en/docs/workspaces

careful when publishing packages in a workspace. If you are preparing your next release and you decided to use a new dependency but forgot to declare it in the package.json file, your tests might still pass locally if another package already downloaded that dependency into the workspace root. However, it will be broken for consumers that pull it from a registry, since the dependency list is now incomplete so they have no way to download the new dependency. Currently there is no way to throw a warning in this scenario.

https://classic.yarnpkg.com/en/docs/workspaces

plug and play

  • External reference: https://classic.yarnpkg.com/en/docs/pnp

    way regular installs work is simple: Yarn generates a node_modules directory that Node is then able to consume. In this context, Node doesn’t know the first thing about what a package is: it only reasons in terms of files. “Does this file exist here? No? Let’s look in the parent node_modules then. Does it exist here? Still no? Too bad… parent folder it is!” - and it does this until it matches something that matches one of the possibilities.

    https://classic.yarnpkg.com/en/docs/pnp

    what Plug’n’Play (abbreviated PnP) is. Instead of generating a node_modules directory and leaving the resolution to Node, we now generate a single .pnp.js file and let Yarn tell us where to find our packages

    https://classic.yarnpkg.com/en/docs/pnp

link

Notes linking here