google / wireit

Wireit upgrades your npm/pnpm/yarn scripts to make them smarter and more efficient.
Apache License 2.0
5.42k stars 95 forks source link

Add clean command #28

Open aomarks opened 2 years ago

jpzwarte commented 2 years ago

How could you do this without having to create a wireit cli script? (wireit clean)

I just created a custom clean script:

    "clean": {
      "command": "rimraf \"**/*.tsbuildinfo\" \"**/.wireit\" dist docs/dist \"packages/*/dist\" \"packages/*/dist-docs\""
    },
aomarks commented 2 years ago

It could be invoked like this:

npm run build clean
jpzwarte commented 2 years ago

I know the watch syntax is similar, but it kinda looks weird? Why not npm run build --clean, so "build" is different from the clean argument?

aomarks commented 2 years ago

There are a few things that "clean" could mean, by the way:

  1. Bust the cache for the given script (i.e. delete .wireit directory, or part of it), to force an execution.

  2. Delete all declared output files for the given script.

  3. Delete every file that isn't tracked by Git. Wireit won't do this, but git clean -dfx is a good way to do it generally.

And then for any of those options, there is the question of whether it should apply just to the given script, or also to all transitive dependencies.

I'm currently thinking that npm run foo clean should be both [1] and [2]. I'm unsure about whether it should be recursive. Perhaps a --recursive flag to make it recursive.

aomarks commented 2 years ago

I know the watch syntax is similar, but it kinda looks weird? Why not npm run build --clean, so "build" is different from the clean argument?

It's because npm treats arguments without a leading dash as arguments for the underlying command. npm run build foo will pass foo to the command, but npm run build --foo will interpret --foo as an argument to npm itself. So the options were either npm run build watch or npm run build -- --watch, and the former seemed much nicer.

alyahmedaly commented 1 year ago

I found myself using 1 and 2 most of the time

vdegenne commented 1 year ago

I am rather new to wireit and this is the first missing feature I ran into.
Just to add to what was said, npm run build --clean was the first thing I typed in the terminal to see if that feature was implemented because I saw npm run build --watch in the doc. My goal was to just delete the files referenced in the output option, and this is what most user would expect. So maybe --clean would be the best choice to implement [2]. And then for [1] and [3] have variant arguments (e.g. --clean-cache).

Just sharing some ideas.

cefn commented 1 year ago

My pipeline has a target qa which runs all the things, a target qa:watch which does the same with a watch and a target qa:clean which removes all the .wireit caches, like this...

    "qa": "wireit",
    "qa:clean": "find . -iname '.wireit' -type d | xargs -I{} rm -rf {}",
    "qa:watch": "npm run qa --watch",

I don't feel the need for anything else, particularly, since I can clean out non-versioned files (dist, coverage etc.) with a git clean -fdx.

I am most often running npm run qa:clean && npm run qa while finalising a feature. I will let the qa run without a clean a lot of the time, until it's time to finalise and release.