Skip to content

Commit dd5df5b

Browse files
committed
cleanup runtime log output
1 parent 2b99075 commit dd5df5b

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed
Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { existsSync } from "node:fs";
2+
import chalk from "chalk";
13
import { dedent } from "ts-dedent";
2-
import { configFileName } from "../../config";
34
import { logger } from "../../logger";
45

56
/**
@@ -8,53 +9,60 @@ import { logger } from "../../logger";
89
export function logRuntimeTypesMessage(
910
outFile: string,
1011
tsconfigTypes: string[],
11-
isNodeCompat = false,
12-
configPath: string | undefined
12+
isNodeCompat = false
1313
) {
1414
const isWorkersTypesInstalled = tsconfigTypes.find((type) =>
1515
type.startsWith("@cloudflare/workers-types")
1616
);
1717
const isNodeTypesInstalled = tsconfigTypes.find((type) => type === "node");
1818
const updatedTypesString = buildUpdatedTypesString(tsconfigTypes, outFile);
19-
20-
logger.info(`✨ Runtime types written to ${outFile}`);
21-
19+
const maybeHasOldRuntimeFile = existsSync("./.wrangler/types/runtime.d.ts");
20+
if (maybeHasOldRuntimeFile) {
21+
logAction("Remove the old runtime.d.ts file");
22+
logger.log(
23+
chalk.dim(
24+
"`wrangler types` now outputs runtime and Env types in one file.\nYou can now delete the ./.wrangler/types/runtime.d.ts and update your tsconfig.json`"
25+
)
26+
);
27+
logger.log("");
28+
}
29+
if (isWorkersTypesInstalled) {
30+
logAction(
31+
"Migrate from @cloudflare/workers-types to generated runtime types"
32+
);
33+
logger.log(
34+
chalk.dim(
35+
"`wrangler types` now generates runtime types and supersedes @cloudflare/workers-types.\nYou should now uninstall @cloudflare/workers-types and remove it from your tsconfig.json."
36+
)
37+
);
38+
logger.log("");
39+
}
2240
if (updatedTypesString) {
23-
logger.info(dedent`
24-
📣 Add the generated types to the types array in your tsconfig.json:
25-
41+
logAction(`Update your tsconfig.json to include the generated types`);
42+
logger.log(
43+
chalk.dim(dedent`
2644
{
2745
"compilerOptions": {
28-
...
2946
"types": ${updatedTypesString}
30-
...
3147
}
3248
}
33-
34-
`);
35-
} else if (isWorkersTypesInstalled) {
36-
logger.info(dedent`
37-
📣 Replace the existing "@cloudflare/workers-types" entry with the generated types path:
38-
{
39-
"compilerOptions": {
40-
...
41-
"types": ${updatedTypesString}
42-
...
43-
}
44-
}
45-
46-
`);
47-
}
48-
if (isWorkersTypesInstalled) {
49-
logger.info('📣 You can now uninstall "@cloudflare/workers-types".');
49+
`)
50+
);
51+
logger.log("");
5052
}
5153
if (isNodeCompat && !isNodeTypesInstalled) {
52-
logger.info(
53-
'📣 Since you have Node.js compatibility mode enabled, you should consider adding Node.js for TypeScript by running "npm i --save-dev @types/[email protected]". Please see the docs for more details: https://developers.cloudflare.com/workers/languages/typescript/#transitive-loading-of-typesnode-overrides-cloudflareworkers-types'
54+
logAction("Install types@node");
55+
logger.log(
56+
chalk.dim(
57+
`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' : '".'}`
58+
)
5459
);
60+
logger.log("");
5561
}
56-
logger.info(
57-
`📣 Remember to run 'wrangler types --x-include-runtime' again if you change 'compatibility_date' or 'compatibility_flags' in your ${configFileName(configPath)} file.\n`
62+
63+
logger.log(
64+
`📖 Read about runtime types\n` +
65+
`${chalk.dim("https://developers.cloudflare.com/workers/languages/typescript/#generate-runtime-types")}`
5866
);
5967
}
6068

@@ -66,13 +74,21 @@ function buildUpdatedTypesString(
6674
types: string[],
6775
newTypesPath: string
6876
): string | null {
69-
if (types.some((type) => type.includes(".wrangler/types/runtime"))) {
77+
if (types.some((type) => type.includes(newTypesPath))) {
7078
return null;
7179
}
7280

7381
const updatedTypesArray = types
74-
.filter((type) => !type.startsWith("@cloudflare/workers-types"))
82+
.filter(
83+
(type) =>
84+
!type.startsWith("@cloudflare/workers-types") &&
85+
!type.includes("./wrangler/types/runtime.d.ts")
86+
)
7587
.concat([newTypesPath]);
7688

7789
return JSON.stringify(updatedTypesArray);
7890
}
91+
92+
const logAction = (msg: string) => {
93+
logger.log(chalk.hex("#BD5B08").bold("Action required"), msg);
94+
};

0 commit comments

Comments
 (0)