Is it possible to define Yarn 3 flags as defaults? - yarnpkg

I've added yarn-plugin-outdated to my project. There are some CLI flags supported such as --url, so I can run yarn outdated --url and all outdated packages will be listed with URLs.
Is there any way to set this flag as default, so I don't need to type full command every time?

Related

Update previously patched package with Yarn Berry

I'm using Yarn#3.0.2 in my project.
I have patched a package (#pkg/pkg) with the command yarn patch #pkg/pkg and I am using it as a devDependency with the patch: protocol.
Now I need to make another patch to the same package - but when I run the same command I get Multiple candidate packages found [...].
It works when trying to target the original package (using yarn patch #pkg/pkg#x.x.x), but I can't seem to find a way to target the patched project.
Any skilled yarn developer out there?
(Possibly useful information: I cannot use the resolutions field for the patch since #pkg/pkg is a CLI which does not seem to work with this approach)
The solution was choose the patch suggested with the error and encapsule it in qoutes such as:
yarn patch "patch:..."

Do NPM packages have to be installed globally to access their functionality via the command line?

I am having trouble understanding how the -g flag works in NPM. Specifically I'm struggling to understand how it relates to command-line functionality exposed by NPM modules.
I assumed that the difference between installing a package locally and globally was simply that a local package would not be available outside of the particular project. And of course that a globally installed package would be available in any project. I'm from a Rails background so this for me would be similar to installing a gem into a particular RVM versus installing it into the global RVM. It would simply affect which places it was available.
However there seems to be more significance than just scope in NPM. For packages that have command-line functionality, like wait-on, the package (as far as I can tell) is not available on the command line unless it's installed globally.
Local install doesn't make the command-line functionality available:
$ npm install wait-on
$ wait-on
=> -bash: /usr/local/bin/wait-on: No such file or directory
Global install does expose the command-line functionality
$ npm install wait-on -g
$ wait-on
=> Usage: wait-on {OPTIONS} resource [...resource]
Description:
wait-on is a command line utility which will wait for files, ports,
sockets, and http(s) resources to become available (or not available
using reverse flag). Exits with success code (0) when all resources
are ready. Non-zero exit code if interrupted or timed out.
Options may also be specified in a config file (js or json). For
example --config configFile.js would result in configFile.js being
required and the resulting object will be merged with any
Can you expose the command-line functionality using a local install?
Is it possible to install locally but also get the command line functionality? This would be very helpful for my CI setup as it's far easier to cache local modules than global modules so where possible I'd prefer to install locally.
If you are using npm 5.2.0 or later, the npx command is included by default. It will allow you to run from the local node modules: npx wait-on
For reference: https://www.npmjs.com/package/npx
I think you can access locally installed modules from the command line only if you add them to your "scripts" section of your package.json. So to use the locally installed version of wait-on, you can add an entry in "scripts" section of package.json like so "wait-on": "wait-on". Then to run it, you would have to do npm run wait-on. You can also do "wo": "wait-on" and then do npm run wo basically meaning what comes after the run is the script entry. In node_modules, there is a .bin folder and inside of this folder is all the executables that you can access this way.
Installing locally makes the package available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); or importing a module.
It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.
You can find a pretty decent explanation here.
It is also useful to put commands in the scripts block in package.json as it automatically resolve local commands. That means you could have a script that depended on a package without having an undocumented dependency on the same.
If you need to run it locally on cmd, you have to go inside the node_modules and run from the path.

Setting up Go environment for creating custom Terraform providers

I am getting a stuck while trying to create a Terraform provider. I have been following the advice given on https://www.terraform.io/docs/extend/writing-custom-providers.html but when I go to build my binaries via Go go build -o terraform-provider-example I get several missing packages errors.
So I then work my way down the list of missing packages and use go get ... to get those packages installed in my Go libraries.
I get an error indicating that github.com/hashicorp/hcl/v2 cannot be found. I navigate to the location and sure enough it doesn't exist.
Package not available at install time screen shot
Package not available with go get
So I am getting stuck and unable to build these providers. I have looked for a while now trying to find something which describes how to setup the environment for creating providers but have been unsuccessful so far. Can anyone help get me going?
Terraform Core and Terraform provider development requires using the Go toolchain in the new "modules mode", which in current versions of Go is not the default.
The easiest way to ensure you're working in modules mode is to clone the repository you want to work on outside the $GOPATH/src directory. Development outside of GOPATH is only supported in Modules mode, and so the Go toolchain assumes that you intend to use modules mode if you are working in that way.
One reason why Terraform development requires modules mode (though not the only one) is that it has a dependency on github.com/hashicorp/hcl/v2, which is a module path type that is not supported in the old GOPATH mode because previously the Go toolchain was only able to install from the master branch of a particular remote dependency in a Git repository. The module path github.com/hashicorp/hcl/v2 is the Go Modules way to specify using the second major version of HCL, whereas github.com/hashicorp/hcl is the first major version.
In modules mode, it should be sufficient to just run go build -o terraform-provider-example (or, if you prefer, go install) and it will automatically fetch the dependencies to the local modules cache and use them from there. In modules mode, go get is for changing the dependencies recorded in go.mod rather than for installing existing dependencies.

Why pnpm has two stores when using with nvm?

I did found pnpm is using two stores when installed in nvm environment.
/Users/me/.pnpm-global/1
/Users/me/.nvm/versions/node/v10.15.3/pnpm-global/1
Trying to understand, why it is so.
~/.pnpm-global is not the store. It is the location where the global packages are installed. For instance, when you run pnpm i -g webpack-cli, webpack will be installed into ~/.pnpm-global.
It is probably some bug that you have two of those. There should be one global folder, probably this one only: /Users/me/.nvm/versions/node/v10.15.3/pnpm-global/1
The global store is located at ~/.pnpm-store

Silence 'info fsevents#1.2.4: The platform "linux" is incompatible with this module.'

When running yarn check, I see:
info fsevents#1.2.4: The platform "linux" is incompatible with this module.
info "fsevents#1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
This GitHub comment says that the message can be safely ignored.
Is there a way to prevent it from occurring in the first place?
Not sure about yarn check but for installing/updating: yarn --silent or even better yarn --silent --ignore-optional
yarn --silent installs optional deps, but without the output.
Note: If running with --ignore-optional flag you may be dependent on some of the optional dependencies without realising it. So I recommend deleting your node_modules folder and yarn.lock file and then running yarn --ignore-optional before testing your project. If it turns out there were optional deps you required, then add them as [dev] deps [accordingly].
Although if it was just fsevents and that was never being installed, no worries.
Currently it does not seem possible to prevent messages about optional dependencies which are not explicitly required.
See the following yarn GitHub issues:
[FR] a way to ignore packages #4611
Add flag to ignore individual optional packages #5251

Resources