Is there a way to exclude a specific package from hoisting in PNPM? - pnpm

YARN has a nohoist option to prevent from hoisting a specific package.
Does PNPM have an equivalent option?

The top answer is outdated.
Since v7.12.0, you can exclude patterns from hoisting using !.
For example:
.npmrc
hoist-pattern[]=*types*
hoist-pattern[]=!#types/react
Via the docs: https://pnpm.io/npmrc#hoist-pattern

As of pnpm v6.7, pnpm does not allow to exclude from hoisting. With pnpm you define which package should be hoisted not which should not be hoisted.
To hoist nothing, you may set hoist=false in .npmrc.
To hoist only the babel packages, you may set hoist-pattern[]=#babel/*

Related

Is there an equivalent of 'yarn why' for pnpm?

There is a particular sub-dependency of my project that is failing to install properly in pnpm. I'm not sure why the dependency (es5-ext) is required.
When using yarn, I can ask "yarn why [package-name]" to find out why a package is needed.
Is there an equivalent in pnpm?
pnpm why es5-ext will work with pnpm. See the docs: https://pnpm.io/cli/why

How do I avoid lock file conflicts with PNPM?

Our team uses PNPM and a recurring problem is that we seem to have different versions of the pnpm command installed, causing lock files git conflicts when adding or updating packages. PNPM is a global tool, so I am not totally sure how to handle this situation. Some Node tools have a global CLI interface (Grunt), but utilize a locally installed package to avoid this issue. Does PNPM have a way to ensure consistent behavior across the team to avoid lock file conflicts and such?
The current recommended approach is to declare which pnpm version should be used in the project. It may be done via the engines field of packages.json. For instance, if your project should be used with pnpm v6, add this to package.json:
{
"engines": {
"pnpm": "6"
}
}
If someone will run pnpm install using a different version of pnpm, an error will be thrown.
In the future we might automatically download the right version of pnpm and use it. Kind of how Yarn does it with version policies.

How do I uninstall a package in Elm?

If I have installed a package with elm install *package name* how do I then uninstall it?
There is no way with the included elm tool, though elm-json is a common tool that can do that.
You can also just remove the dependency from your elm.json file (though elm-json will take care of indirect dependencies that might be affected).

Yarn 2 and dart sass with create react app

I've been trying to update a Create React App to use yarn 2 and plug and play (PNP). When I do use nodeLinker: node-modules in the .yarnrc.yml, I can successfully start the dev-server. Without it, I end up with
./src/App.scss (./.yarn/$$virtual/css-loader-virtual-fe3fa7be11/0/cache/css-loader-npm-3.4.2-300ee159b3-2.zip/node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./.yarn/cache/postcss-loader-npm-3.0.0-f4ab99b685-2.zip/node_modules/postcss-loader/src??postcss!./.yarn/cache/resolve-url-loader-npm-3.1.1-cf1a268137-2.zip/node_modules/resolve-url-loader??ref--6-oneOf-5-3!./.yarn/unplugged/sass-loader-virtual-14ae4e1150/node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/App.scss)
Error: A package is trying to access a peer dependency that should be provided by its direct ancestor but isn't
Required package: node-sass (via "node-sass")
Required by: sass-loader#virtual:74ba539c0b6c6c8346ea151c91664bff0bef13782983a6f90ddf1a26160140360771dcf40d0863b46ff7add674bc2c42a37daea25f24f4ea96f7843786460ecd#npm:8.0.2 (via /Users/me/color-contrast-matrix/.yarn/unplugged/sass-loader-virtual-14ae4e1150/node_modules/sass-loader/dist/)
It looks like yarn 2 provides a way of overriding a packages dependencies. You have to provide the missing dependency, at least in this case.
From the docs current link:
Some packages may have been specified incorrectly with regard to their
dependencies - for example with one dependency being missing, causing
Yarn to refuse it the access. The packageExtensions fields offer a way
to extend the existing package definitions with additional
information. If you use it, consider sending a PR upstream and
contributing your extension to the plugin-compat database.
After installing node-sass and adding this config, compilation succeeded.
# .yarnrc.yml
packageExtensions:
'sass-loader#*':
optionalDependencies:
node-sass: '*'
Building on wegry's answer, a better way would be to fix up react-scripts, since that's where the missing peer dependency is.
#.yarnrc.yml
packageExtensions:
'react-scripts#*':
peerDependencies:
node-sass: ^4.0.0 || ^5.0.0' # Or sass: ^1.3.0'
I'm using versions that match the peerDependency of the version of sass-loader that is currently depended on by react-scripts. (I hope by the time the next version of react-scripts comes out, they'll have fixed this bug.)
What this is doing, is telling Yarn that react-scripts really should have peer-depended on sass (and also node-sass for that matter), so that sass-loader can use them.
sass-loader itself has defined its dependencies correctly.

Go Modules does not recognize files under GOPATH

I was trying to set up GO Modules in intellij and was trying import a package under GOPATH. When I use Go Modules, it doesnt seem to 'import' the packages from GOPATH. Any ideas on what I could be doing wrong?
Below is a screenshot. Left pic: GoModules, which doesnt recognize the package. Right Pic: Simple GO project, which recognized the packages.
I tried doing sync package, with no luck.
Go version - 1.12.3
.
The two supported modes ("GOPATH mode" and "module-aware mode") are mutually exclusive modes. This means you can't have both, you can't mix modules and GOPATH.
Quoting from Command go: GOPATH and Modules:
When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).
And also Command go: Preliminary module support:
For more fine-grained control, the module support in Go 1.11 respects a temporary environment variable, GO111MODULE, which can be set to one of three string values: off, on, or auto (the default). If GO111MODULE=off, then the go command never uses the new module support. Instead it looks in vendor directories and GOPATH to find dependencies; we now refer to this as "GOPATH mode." If GO111MODULE=on, then the go command requires the use of modules, never consulting GOPATH. We refer to this as the command being module-aware or running in "module-aware mode". If GO111MODULE=auto or is unset, then the go command enables or disables module support based on the current directory. Module support is enabled only when the current directory is outside GOPATH/src and itself contains a go.mod file or is below a directory containing a go.mod file.
In module-aware mode, GOPATH no longer defines the meaning of imports during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod) and installed commands (in GOPATH/bin, unless GOBIN is set).
If you wish to use packages located on your disk, see How to use a module that is outside of "GOPATH" in another module?
I faced this problem, and I use this setting for each project, and it solved my problem.
But I'm still looking for a global GO module configuration.

Resources