Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

environmentalDependencyCommands #1081

Open
appsforartists opened this issue Mar 21, 2024 · 2 comments
Open

environmentalDependencyCommands #1081

appsforartists opened this issue Mar 21, 2024 · 2 comments

Comments

@appsforartists
Copy link
Member

Sometimes metadata about the environment is an important input to the build process (for instance, to include a Built at c9e6ee2 comment at the top of a bundled file).

Presently, wireit will return a cached output if the input files haven't changed, even if the environment has. There's no way to declare an explicit dependency on the environment. I propose we change that, with something like this:

{
  "wireit": {
    "build": {
      "command": "vite build",
      "files": [
        "dist/**/index.html",
        "dist/**/*.js",
        "vite.config.ts"
      ],
      "environmentalDependencyCommands": [
        "git rev-parse HEAD"
      ]
    }
  } 
}

where the results of each entry in environmentalDependencyCommands would be cached, and a rebuild would be triggered if any of them changed (just like any other dependency).

In this case, making a git commit would change HEAD, which would invalidate the build even if the enumerated files haven't changed.

@rictic
Copy link
Member

rictic commented Mar 21, 2024

You could support this use case within the existing API by declaring the command as a script that outputs to a file, has no deps and declares its output. The build script could depend on on the other env command script with cascade: false and add the env script's output file as one of its input files.

And git rev-parse HEAD specifically I think you could just depend on the file .git/ORIG_HEAD

@appsforartists
Copy link
Member Author

ahh, yes, i meant to include that too. here was @aomarks workaround:

{
  "wireit": {
    "generate-git-hash": {
      "command": "git rev-parse HEAD > .head"
    },
    "git-hash": {
      "dependencies": [
        {
          "script": "generate-git-hash",
          "cascade": false
        }
      ],
      "files": [
        ".head"
      ],
      "output": []
    },
    "build": {
      "command": "vite",
      "dependencies": [
        "git-hash"
      ]
    }
  } 
}

thanks for the tip on ORIG_HEAD! looks like HEAD is refs/heads/macbook for me (which is unlikely to change), but ORIG_HEAD is effectively HEAD^, which may be a good, if imperfect, signal that a rebuild is due (especially if it's always a commit).

https://stackoverflow.com/questions/964876/head-and-orig-head-in-git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants