Skip to content

Commit 8f22461

Browse files
committed
fix caching
1 parent 73e11cf commit 8f22461

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/wrangler/src/type-generation/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const typesCommand = createCommand({
179179
outFile: outputPath || undefined,
180180
});
181181
header.push(runtimeHeader);
182-
types.push(runtimeTypes);
182+
types.push(`// Begin runtime types\n${runtimeTypes}`);
183183
}
184184

185185
fs.writeFileSync(

packages/wrangler/src/type-generation/runtime/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ export async function generateRuntimeTypes({
4949
const header = `// Runtime types generated with workerd@${version} ${compatibility_date} ${compatibility_flags.join(",")}`;
5050

5151
try {
52-
const existingTypes = await readFile(outFile, "utf8");
53-
if (existingTypes.split("\n")[0] === header) {
52+
const file = (await readFile(outFile, "utf8")).split("\n");
53+
const existingHeader = file.find((line) =>
54+
line.startsWith("// Runtime types generated with workerd@")
55+
);
56+
const existingTypesStart = file.findIndex(
57+
(line) => line === "// Begin runtime types"
58+
);
59+
if (existingHeader === header && existingTypesStart !== -1) {
5460
logger.debug("Using cached runtime types: ", header);
61+
5562
return {
5663
runtimeHeader: header,
57-
runtimeTypes: existingTypes.split("\n").slice(1).join("\n"),
64+
runtimeTypes: file.slice(existingTypesStart).join("\n"),
5865
};
5966
}
6067
} catch (e) {

packages/wrangler/src/type-generation/runtime/log-runtime-types-message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function logRuntimeTypesMessage(
5151
logAction("Install types@node");
5252
logger.log(
5353
chalk.dim(
54-
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev @types/node${isWorkersTypesInstalled ? '@20.8.3". For more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '".'}`
54+
`Since you have the \`nodejs_compat\` flag, you should install Node.js types by running "npm i --save-dev @types/node${isWorkersTypesInstalled ? '@20.8.3".\nFor more details: https://developers.cloudflare.com/workers/languages/typescript/#known-issues' : '".'}`
5555
)
5656
);
5757
logger.log("");

0 commit comments

Comments
 (0)