Skip to content

Instantly share code, notes, and snippets.

Writing the open-source software that you may be using everyday

Maël Nison arcanis

Writing the open-source software that you may be using everyday
View GitHub Profile
View variants.yml
# The general idea is that maintainers would publish "meta-packages" that would describe
# where to find the specific implementations for a given set of parameters (defined by a
# template string). The template string would be resolved based on the known parameter (after
# checking that the active parameters are compatible with the supported ones), and the package
# used instead of the original one.
# One nice thing is that it would degrade nicely on package managers that wouldn't support this
# spec: they would simply ignore the `variants` field, and thus would use the package itself,
# with everything it contains - including a potential fallback.
View yarn-plugin-license.js
module.exports = {
name: `yarn-plugin-license`,
factory: require => {
const {BaseCommand} = require(`@yarnpkg/cli`);
const {Cache, Configuration, Manifest, Project, StreamReport, miscUtils, structUtils} = require(`@yarnpkg/core`);
class LicenseCommand extends BaseCommand {
async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project, workspace} = await Project.find(configuration, this.context.cwd);
View antd.yml.diff
diff --git a/yarn.lock b/yarn.lock
index 391dbc4..7204d18 100644
--- a/yarn.lock
+++ b/yarn.lock
"rc-align@npm:^2.4.0, rc-align@npm:^2.4.1":
version: 2.4.5
resolution: "rc-align@npm:2.4.5"
babel-runtime: "npm:^6.26.0"
dom-align: "npm:^1.7.0"
View findDependents.ts
const locator = structUtils.makeLocator(`debug`, `npm:1.0.0`);
for (const pkg of project.storedPackages) {
const dependencies = Array.from(pkg.dependencies.values());
const isDependent = dependencies.some(dependency => {
const resolution = project.storedResolutions.get(dependency.descriptorHash)!;
return resolution === locator.locatorHash;
View my-plugin.js
module.exports = {
name: `berry-plugin-is-yarn`,
factory: () => ({
default: {
hooks: {
setupScriptEnvironment(project, env, makePathWrapper) {
env.IS_YARN = `1`;
View foo.js
resolveModuleNames: (moduleNames, containingFile) => {
try {
const pnpModuleNames = => {
const [, prefix, rest] = moduleName.match(/^((?:!.*!)?)(.*)/);
const unqualified = require('pnpapi').resolveToUnqualified(rest, containingFile);
return unqualified !== null ? prefix + unqualified : moduleName;
const tsResolutions = resolveModuleNames(resolveSync, moduleResolutionHost, appendTsSuffixTo, appendTsxSuffixTo, scriptRegex, instance, pnpModuleNames, containingFile, getResolutionStrategy);
for (let t = 0; t < tsResolutions.length; ++t)

Getting Started With Plug'n'Play

If you use create-react-app, #5136 (released with the 2.0) implements a --use-pnp option that allows you to easily create a new project using PnP! In this case, just use create-react-app --use-pnp together with Yarn 1.12, and you're good to go! 👍

Plug'n'Play is a new initiative from Yarn that aims to remove the need for node_modules. It's already available, and has proved being effective even on large-scale infrastructures. This document describes in a few steps how to quickly get started with it. Spoiler alert: it's quite easy 🙂

First, download a package manager that supports it. Yarn 1.12 already does, so that's what we're going to use! To install it, just follow the instructions on our website:

If everything is ok, running yarn --version should give you v1.12.1 or higher. If you don't get this result maybe a

View test.js
class EfficientPrinter {
constructor() {
this.lines = null;
render(text) {
View requestIdle.js
let refCount = 0;
let resolvers = [];
function resolveAll() {
for (let resolve of resolvers)
resolvers = [];