Skip to content

Instantly share code, notes, and snippets.

View arcanis's full-sized avatar
:octocat:

Maël Nison arcanis

:octocat:
View GitHub Profile
@arcanis
arcanis / variants.yml
Last active September 14, 2020 17:26
# 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.
#
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);
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"
dependencies:
babel-runtime: "npm:^6.26.0"
dom-align: "npm:^1.7.0"
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;
});
module.exports = {
name: `berry-plugin-is-yarn`,
factory: () => ({
default: {
hooks: {
setupScriptEnvironment(project, env, makePathWrapper) {
env.IS_YARN = `1`;
},
},
},
resolveModuleNames: (moduleNames, containingFile) => {
try {
const pnpModuleNames = moduleNames.map(moduleName => {
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: https://yarnpkg.com/en/docs/install

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

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