I'm migrating to pnpm to manage a monorepo from lerna. However, in the CI, there was a legacy command using the --since option of lerna.
lerna run lint --since origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...
From what I understand, it allows you to run the tasks affected by the PR. What is the equivalent option for pnpm?
Same option exists in PNPM using --filter "[<since>]":
pnpm --filter "...[origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME]" lint
Related
I'm using modern Yarn (v3.2.4 to be exact) which differs from Yarn Classic.
I'm using the nodeLinker: node-modules option in .yarnrc.yml so /node_modules are created, and dependencies are not saved to the repo.
I want to install only production dependencies (no devDependencies) but the --production flag isn't support in in Yarn 3. How can I do this?
You can use the yarn workspaces focus --production command. Check out the documentation here.
As user Bobby mentioned in the other answer, it is possible to install only production dependencies by using the Yarn Workspace plugin.
This requires that the plugn be installed first: yarn plugin import workspace-tools.
Then install with: yarn workspaces focus --production.
I have just started using pnpm thanks to this cool template https://github.com/NiGhTTraX/ts-monorepo
and at one point, I cleaned all node_module folders with the command
find . -name "node_modules" | xargs rm -rf
Now when I run pnpm install && pnpm run build, I get the following output about rimraf not being found :(
dean#Deans-MacBook-Pro typescript % pnpm run build
> ts-monorepo# build /Users/dean/workspace/gazehealth/gazehealth/typescript
> lerna run build
lerna notice cli v4.0.0
lerna info versioning independent
lerna info Executing command in 9 packages: "pnpm run build"
lerna ERR! pnpm run build exited 1 in '#nighttrax/apiUsers'
lerna ERR! pnpm run build stdout:
> #nighttrax/apiUsers#1.0.0 build /Users/dean/workspace/gazehealth/gazehealth/typescript/libraries/apiUsers
> pnpm run clean && pnpm run compile
> #nighttrax/apiUsers#1.0.0 clean /Users/dean/workspace/gazehealth/gazehealth/typescript/libraries/apiUsers
> rimraf -rf ./dist
ERROR Command failed.
ERROR Command failed with exit code 1.
lerna ERR! pnpm run build stderr:
sh: rimraf: command not found
lerna ERR! pnpm run build exited 1 in '#nighttrax/apiUsers'
lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
ERROR Command failed with exit code 1.
How to fix this? Ideally 'not' with a global install so other developers systems will work when they git clone the repo (ideally developers should not have to install stuff much like gradle & it's gradle wrapper did for java)
I'm using lerna in combination with yarn workspaces.
In that case, all the package hoisting and symlinking is handled by yarn workspaces.
In that particular case, what's the role of the lerna bootsrap command?
Does it bring anything more compared to a raw yarn install?
Should we use it or simply use yarn install?
When it comes solely to the lerna bootstrap command in combination with yarn there is no real benefit as it just calls yarn install.
On the other hand in certain scenarios it can make perfectly sense to combine those two, e.g. when you want to use some lerna helper commands or publish packages from your monorepo.
I have npm scripts that use environment variables. Here is an excerpt of package.json:
"scripts": {
"staging": "npm run deploy -env=staging",
"deploy": "winrs /r:intranet /d:F:\\wwwintranet\\deploy npm run build -env=%npm_config_env%",
Until now, -env=%npm_config_env% was expanded to -env=staging or whatever. Suddenly it stopped working. Probably this is due to an update to npm from 6.x to 7.x.
When I test with "deploy": "set & winrs /r:intranet /d:F:\\wwwintranet\\deploy npm run build -env=%npm_config_env%", I can confirm that the variable is still set.
As a temporary solution, downgrading npm to version 6.x (npm install -g npm#6) helped. Nevertheless, I need a solution that will work also in the future.
How can I enable variable expansion again for npm 7.x ? Or what are the alternatives for passing environment variables with npm 7.x ?
Edit
This was a bug in npm 7.5.x. It is fixed in npm 7.7.0 and above (see https://github.com/npm/cli/issues/2731)
Failure to expand environment variables on Windows appears to be a recent high-priority known bug in the npm CLI.
There are several options to use as a workarounds until a fix is released.
You can downgrade to version 6.x until this is fixed.
This won't work for your specific case (see below), but for most cases, you can use npx to use npm#6:
npx -p npm#6 npm run deploy
You can try downgrading to an earlier version of 7.x to see if the bug has always existed in 7.x or not. Start with 7.0.0 and go from there.
The npx suggestion won't work here because deploy invokes npm itself and that will use npm from your PATH which is npm#7. But for generic cases where you need to invoke an old version of npm in narrow cases, that will work.
I see with yarn berry I get the plug'n'play feature instead of node_modules/
I couldn't find anything to suggest it supports running from installed packages.
For example with npm a workflow might be to run the installed version of webpack:
$ npm install --save-dev webpack
$ node node_modules/webpack/bin/webpack ...
A globally installed webpack might not be the same version. Worse yet, during Docker deployment, I get what's installed locally, the only node and npm are available globally. I thought I can do a preinstall script that does npm install -g yarn; yarn set version berry but then I'm not sure how to do webpack, jest, babel, etc, and the thought that I should have to install them all globally during the same preinstall hackaround seems like several steps backwards.
Is there some way to run from locally-installed packages that I'm missing?
I saw this possibly related question - Yarn Berry - Run a Node Script Directly
But the answer there seems a bit off the point - I'm not running any js, I'm trying to type in a package.json script, i.e. something that can run from the shell.
Why not just use yarn run <bin> (or simply yarn <bin>)? If you are in a repository set to use yarn berry, that will run any package bin file.
yarn node <file> will run any .js file with Plug n' Play set up. No need to install those dependencies globally, except for maybe yarn classic.
I was trying to do yarn some-bin and kept getting:
Couldn't find a script named "some-bin".
I eventually figured out it was because the package that provides some-bin is installed inside a workspace and not at the root of my project. So instead I had to run:
yarn workspace my-workspace some-bin
And that worked.