Skip to content

Commit 5af3477

Browse files
authored
feat: support specifying files to use for the cache key (#45)
1 parent d9a5537 commit 5af3477

8 files changed

Lines changed: 274 additions & 22 deletions

File tree

.github/workflows/ci.generate.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as yaml from "https://deno.land/std@0.170.0/encoding/yaml.ts";
22

33
enum OperatingSystem {
4-
Macx86 = "macos-12",
4+
Macx86 = "macos-13",
55
MacArm = "macos-latest",
66
Windows = "windows-latest",
7-
Linux = "ubuntu-20.04",
7+
Linux = "ubuntu-22.04",
88
}
99

1010
interface ProfileData {
@@ -91,6 +91,13 @@ const ci = {
9191
RUST_BACKTRACE: "full",
9292
},
9393
steps: [
94+
{
95+
name: "Prepare git",
96+
run: [
97+
"git config --global core.autocrlf false",
98+
"git config --global core.eol lf",
99+
].join("\n"),
100+
},
94101
{ uses: "actions/checkout@v4" },
95102
{ uses: "dsherret/rust-toolchain-file@v1" },
96103
{

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
config:
23-
- os: macos-12
23+
- os: macos-13
2424
run_tests: 'true'
2525
target: x86_64-apple-darwin
2626
cross: 'false'
@@ -32,23 +32,23 @@ jobs:
3232
run_tests: 'true'
3333
target: x86_64-pc-windows-msvc
3434
cross: 'false'
35-
- os: ubuntu-20.04
35+
- os: ubuntu-22.04
3636
run_tests: 'true'
3737
target: x86_64-unknown-linux-gnu
3838
cross: 'false'
39-
- os: ubuntu-20.04
39+
- os: ubuntu-22.04
4040
run_tests: 'false'
4141
target: x86_64-unknown-linux-musl
4242
cross: 'false'
43-
- os: ubuntu-20.04
43+
- os: ubuntu-22.04
4444
run_tests: 'false'
4545
target: aarch64-unknown-linux-gnu
4646
cross: 'false'
47-
- os: ubuntu-20.04
47+
- os: ubuntu-22.04
4848
run_tests: 'false'
4949
target: aarch64-unknown-linux-musl
5050
cross: 'false'
51-
- os: ubuntu-20.04
51+
- os: ubuntu-22.04
5252
run_tests: 'false'
5353
target: riscv64gc-unknown-linux-gnu
5454
cross: 'true'
@@ -65,6 +65,10 @@ jobs:
6565
CARGO_INCREMENTAL: 0
6666
RUST_BACKTRACE: full
6767
steps:
68+
- name: Prepare git
69+
run: |-
70+
git config --global core.autocrlf false
71+
git config --global core.eol lf
6872
- uses: actions/checkout@v4
6973
- uses: dsherret/rust-toolchain-file@v1
7074
- name: Cache cargo

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dprint-core = { version = "0.67.0", features = ["process"] }
2323
globset = "0.4.14"
2424
handlebars = "5.1.2"
2525
serde = { version = "1.0.204", features = ["derive"] }
26+
sha2 = "0.10.9"
2627
splitty = "1.0.1"
2728
tokio = { version = "1.38.0", features = ["time"] }
2829

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This plugin executes CLI commands to format code via stdin (recommended) or via
4949
General config:
5050

5151
- `cacheKey` - Optional value used to bust dprint's incremental cache (ex. provide `"1"`). This is useful if you want to force formatting to occur because the underlying command's code has changed.
52+
- If you want to automatically calculate the cache key, consider using `command.cacheKeyFiles`.
5253
- `timeout` - Number of seconds to allow an executable format to occur before a timeout error occurs (default: `30`).
5354
- `cwd` - Recommend setting this to `${configDir}` to force it to use the cwd of the current config file.
5455

@@ -61,6 +62,7 @@ Command config:
6162
- You may have associations match multiple binaries in order to format a file with multiple binaries instead of just one. The order in the config file will dictate the order the formatting occurs in.
6263
- `stdin` - If the text should be provided via stdin (default: `true`)
6364
- `cwd` - Current working directory to use when launching this command (default: dprint's cwd or the root `cwd` setting if set)
65+
- `cacheKeyFiles` - A list of paths (relative to `cwd`) to files used to automatically compute a `cacheKey`. This allows automatic invalidation of dprint's incremental cache when any of these files are changed.
6466

6567
Command templates (ex. see the prettier example above):
6668

@@ -118,7 +120,12 @@ Use the `rustfmt` binary so you can format stdin.
118120
"cwd": "${configDir}",
119121
"commands": [{
120122
"command": "rustfmt --edition 2021",
121-
"exts": ["rs"]
123+
"exts": ["rs"],
124+
// add the config files for automatic cache invalidation when the rust version or rustfmt config changes
125+
"cacheKeyFiles": [
126+
"rustfmt.toml",
127+
"rust-toolchain.toml"
128+
]
122129
}]
123130
},
124131
"plugins": [
@@ -139,7 +146,11 @@ Consider using [dprint-plugin-prettier](https://dprint.dev/plugins/prettier/) in
139146
"commands": [{
140147
"command": "prettier --stdin-filepath {{file_path}} --tab-width {{indent_width}} --print-width {{line_width}}",
141148
// add more extensions that prettier should format
142-
"exts": ["js", "ts", "html"]
149+
"exts": ["js", "ts", "html"],
150+
// add the config files for automatic cache invalidation when the prettier config config changes
151+
"cacheKeyFiles": [
152+
".prettierrc.json"
153+
]
143154
}]
144155
},
145156
"plugins": [

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.79.0"
2+
channel = "1.82.0"
33
components = ["clippy", "rustfmt"]

0 commit comments

Comments
 (0)