Skip to content

Commit 9e5b1bb

Browse files
apply a single rule
1 parent c6ccf77 commit 9e5b1bb

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

packages/cloudflare/src/cli/build/patches/plugins/fetch-cache-wait-until.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from "vitest";
22

33
import { patchCode } from "../ast/util.js";
4-
import { ruleForMinifiedCode, ruleForNonMinifiedCode } from "./fetch-cache-wait-until.js";
4+
import { rule } from "./fetch-cache-wait-until.js";
55

66
describe("patchFetchCacheSetMissingWaitUntil", () => {
77
test("on minified code", () => {
@@ -15,7 +15,7 @@ describe("patchFetchCacheSetMissingWaitUntil", () => {
1515
}).catch((e4) => console.warn("Failed to set fetch cache", u4, e4)).finally(X), a2;
1616
}`;
1717

18-
expect(patchCode(code, ruleForMinifiedCode)).toMatchInlineSnapshot(`
18+
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
1919
"{
2020
let [o4, a2] = (0, d2.cloneResponse)(e3);
2121
globalThis.__openNextAls?.getStore()?.waitUntil?.(o4.arrayBuffer().then(async (e4) => {
@@ -66,7 +66,7 @@ describe("patchFetchCacheSetMissingWaitUntil", () => {
6666
return cloned2;
6767
`;
6868

69-
expect(patchCode(code, ruleForNonMinifiedCode)).toMatchInlineSnapshot(`
69+
expect(patchCode(code, rule)).toMatchInlineSnapshot(`
7070
"// We're cloning the response using this utility because there
7171
// exists a bug in the undici library around response cloning.
7272
// See the following pull request for more details:

packages/cloudflare/src/cli/build/patches/plugins/fetch-cache-wait-until.ts

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,21 @@ export function patchFetchCacheSetMissingWaitUntil(updater: ContentUpdater) {
2424
),
2525
contentFilter: /arrayBuffer\(\)\s*\.then/,
2626
},
27-
({ contents }) => {
28-
contents = patchCode(contents, ruleForMinifiedCode);
29-
return patchCode(contents, ruleForNonMinifiedCode);
30-
}
27+
({ contents }) => patchCode(contents, rule)
3128
);
3229
}
3330

34-
export const ruleForMinifiedCode = `
31+
export const rule = `
3532
rule:
36-
pattern: return $PROMISE, $CLONED2
37-
regex: Failed to set fetch cache
38-
follows:
39-
kind: lexical_declaration
40-
pattern: let [$CLONED1, $CLONED2]
33+
kind: call_expression
34+
pattern: $PROMISE
35+
all:
36+
- has: { pattern: "$$$_.then($$$_)", stopBy: end }
37+
- has: { pattern: "Buffer.from", stopBy: end }
38+
- has: { regex: "CachedRouteKind.FETCH" }
39+
- has: { regex: "finally(.*?)$" }
4140
42-
fix: |
43-
globalThis.__openNextAls?.getStore()?.waitUntil?.($PROMISE);
44-
return $CLONED2;
45-
`;
46-
47-
export const ruleForNonMinifiedCode = `
48-
rule:
49-
regex: Failed to set fetch cache
50-
pattern: $PROMISE;
51-
follows:
52-
kind: comment
53-
follows:
54-
kind: comment
55-
follows:
56-
kind: comment
57-
follows:
58-
kind: lexical_declaration
59-
pattern: const [cloned1, cloned2]
6041
6142
fix: |
62-
globalThis.__openNextAls?.getStore()?.waitUntil?.($PROMISE);
43+
globalThis.__openNextAls.getStore().waitUntil($PROMISE)
6344
`;

0 commit comments

Comments
 (0)