folke / ultra-runner

🏃⛰ Ultra fast monorepo script runner and build tool
https://www.npmjs.com/package/ultra-runner
Apache License 2.0
1.2k stars 32 forks source link

Variables are not supported / RFC21 compatibility #184

Open matzeeable opened 3 years ago

matzeeable commented 3 years ago

Hey!

We need to search for an alternative to the yarn berry script runner as it is very slow. I came across this tool, and it looks really promising and it is compatible with Yarn Berry (#137). The scripts are executed very fast! Unfortunately, I stumbled over an issue with variables. Imagine the following:

"scripts": {
    "test1": "echo $COMPOSE_PROJECT_NAME",
    "test2": "COMPOSE_PROJECT_NAME=Hello yarn test1"
}

We need to set the COMPOSE_PROJECT_NAME variable as environment variable because we want to run docker-compose. Is this feature currently not possible or is there another syntax we need to use?

EDIT: I just found out, that you are using cross-spawn to spawn the command to the correct shell. Unfortunately, cross-spawn does not support setting and reading environment variables. For this, cross-env should be used.

RFC 21 compatibility

EDIT: I also noticed that the npm variables like npm_lifecycle_event and npm_package_name are missing. Perhaps it is worth to adopt the coding of @npmcli/run-script to ultra-runner:

  1. Create npm_package_* variables and pass it to the spawn (https://github.com/npm/run-script/blob/47a4d539fb07220e7215cc0e482683b76407ef9b/lib/run-script-pkg.js#L54-L62)
  2. Generate npm_package_* variables (https://github.com/npm/run-script/blob/47a4d539fb07220e7215cc0e482683b76407ef9b/lib/package-envs.js#L7)
  3. Add additional, special variables (https://github.com/npm/run-script/blob/47a4d539fb07220e7215cc0e482683b76407ef9b/lib/make-spawn-args.js#L26-L28)

Regards, Matthew 😊

nodkz commented 3 years ago

I met with the same problem:

"build": "npm run clear && npm run graphql-codegen && NODE_ENV=production next build ./ && npm run intl-build",

Fails with error

Screen Shot 2021-05-13 at 22 38 31
wesselvdv commented 3 years ago

I'd like to see this supported as well! It makes conditional build steps of specific configuration choices based on ENV variables possible!

TheSisb commented 2 years ago

Bumping this as an important feature for us as well.

ghost commented 2 years ago

bumping

Bessonov commented 2 years ago

I think I ran into this issue too:

"build": "NODE_ENV=${NODE_ENV:-production} webpack",
aparajita commented 2 years ago

@nodkz and everyone else, do it like this, this kind of setup works for me:

"builder": "npm run clear && npm run graphql-codegen && next build ./ && npm run intl-build",
"build": "NODE_ENV=production npm run builder"