Skip to content

Commit c27f005

Browse files
authored
disallow setting version when prefix is set (#13)
1 parent 32651f9 commit c27f005

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

dist/index.js

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

src/__tests__/main.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ describe("deleteCache", () => {
154154
).rejects.toThrow("Cache key cannot be empty unless prefix is true");
155155
});
156156

157+
it("should fail if version is specified with prefix", async () => {
158+
await expect(
159+
deleteCache({
160+
cacheKey: "npm-cache",
161+
cacheVersion: "v1.0",
162+
prefix: true,
163+
...defaultParams,
164+
})
165+
).rejects.toThrow("Cannot specify version when using prefix");
166+
});
167+
157168
it("should handle 404 response", async () => {
158169
mockedFetch.mockResolvedValue({
159170
ok: false,

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export async function deleteCache({
2929
if (cacheVersion && !cacheKey) {
3030
throw new Error("Cannot specify version when using empty key");
3131
}
32+
if (prefix && cacheVersion) {
33+
throw new Error("Cannot specify version when using prefix");
34+
}
3235

3336
const resource = cacheVersion ? `${cacheKey}/${cacheVersion}` : cacheKey;
3437
const url = `${baseUrl}/caches/${resource}`;

0 commit comments

Comments
 (0)