denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.02k stars 5.39k forks source link

Add support for wildcards in `deno task` #26944

Open bartlomieju opened 3 days ago

bartlomieju commented 3 days ago

It would be great if one could do deno task build:* to run all tasks that start with build:.

Eg:

{
    "tasks": {
        "build:frontend": "...",
        "build:server": "...",
        "build:queue": "...",
        "serve": "..."
    }
}

running deno task build:* would match build:frontend, build:server and build:queue and run them all in parallel.

Somewhat related to https://github.com/denoland/deno/issues/26462

justinfagnani commented 2 days ago

fwiw, we found that we didn't need this so much in Wireit since you usually have a plain build task that depends on the others:

{
    "tasks": {
        "build": {
          "dependencies": ["build:frontend", "build:server", "build:queue"]
        },
        "build:frontend": "...",
        "build:server": "...",
        "build:queue": "...",
        "serve": "..."
    }
}

One case where we have wanted some wildcard like functionality is in running the same script in a monorepo dependencies instead of having to list each dependency out again in the Wireit config. ie, the "build" script for A runs the "build" script for B, C, and D, automatically if those are local monorepo dependencies with "build" scripts:

So instead of:

packages/a/package.json

{
  "tasks": {
    "build": {
      "dependencies": ["../b:build", "../c:build", "../d:build"]
    }
  }
}

you'd have: packages/a/package.json

{
  "tasks": {
    "build": {
      "dependencies": [
        {
          "script": "build",
          "packages": "dependencies"
        }
      ]
    }
  }
}

See https://github.com/google/wireit/issues/23

bartlomieju commented 1 day ago

Thanks for comment @justinfagnani. Would something like this work for you?

{
    "tasks": {
        "build": {
            "command": "...",
            "dependencies": ["./packages/*:<task_name>"]
        }
    }
}

That way we don't have to develop two separate features - just need to accept wildcards in "cross-package" dependencies.

justinfagnani commented 1 day ago

@bartlomieju

Thanks for comment @justinfagnani. Would something like this work for you?

note that I'm not a potential user here, I'm just relaying my experience with Wireit :)

{
    "tasks": {
        "build": {
            "command": "...",
            "dependencies": ["./packages/*:<task_name>"]
        }
    }
}

That way we don't have to develop two separate features - just need to accept wildcards in "cross-package" dependencies.

This is semantically differently than running scripts in dependencies. Here you're saying to run scripts in every package under packages/*. What the proposed new Wireit dependency type is saying to do is run the script in local dependencies or the current package.

The more complete example config would be:

{
  "tasks": {
    "build": {
      "dependencies": [
        {
          "script": "build",
          "packages": "dependencies"
        }
      ]
    }
  },
  "dependencies": {
    "@foo/b": "^1.0.0",
    "@foo/c": "^1.0.0",
    "@foo/d": "^1.0.0"
  }
}

Where @foo/{a,b,c} are all packages in the local monorepo. This would not run the build script in packages/e, etc.

Running scripts in dependencies has been the main use case for wildcard-like functionality, because without that feature the config has to repeat data already in package dependencies. I would personally suggest starting with that rather than a general wildcard feature.