Skip to content

Commit

Permalink
add more fields to generated tsconfig.json (#142)
Browse files Browse the repository at this point in the history
This PR adds some more fields to the generated `tsconfig.json` from `wrangler init`, particularly for compatibility around esbuild.
- `target`, `module` and `lib` are set to `esnext`, since we're comfortable supporting that on cloudflare, and esbuild handles it just fine (for now)
- `moduleResolution` is set to `node`, but of course
- some useful fields set to true: `esModuleInterop`, `allowJs`, `allowSyntheticDefaultImports`, `resolveJsonModule`
- `isolatedModules` set to true because esbuild can't handle anything else (folks can disable this if they;re using `tsc` themselves, but it's such a smaaaall group of people who do so
-  `noEmit` is `true`; we use esbuild to output code, and no one's using wrangler to generate `.d.ts` files (folks who have custom setups are welcome to do so)
- `jsx: "react"` - I think this may be the default anyway, but it's good to be explicit if people want to change it

I also pinned the version of miniflare (`^` doesn't work with non-semver versions anyway)
  • Loading branch information
threepointone authored Dec 20, 2021
1 parent 9a0f6cf commit 8b6c2d1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-cooks-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add more fields to the `tsconfig.json` generated by `wrangler init`
7 changes: 2 additions & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@cloudflare/pages-functions-compiler": "0.3.8",
"esbuild": "0.14.1",
"miniflare": "^2.0.0-rc.4",
"miniflare": "2.0.0-rc.4",
"semiver": "^1.1.0"
},
"optionalDependencies": {
Expand Down
18 changes: 13 additions & 5 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export async function main(argv: string[]): Promise<void> {
destination,
`compatibility_date = "${compatibilityDate}"` + "\n"
);
console.log(`✨ Succesfully created wrangler.toml`);
console.log(`✨ Successfully created wrangler.toml`);
// TODO: suggest next steps?
} catch (err) {
console.error(`Failed to create wrangler.toml`);
Expand Down Expand Up @@ -260,9 +260,17 @@ export async function main(argv: string[]): Promise<void> {
JSON.stringify(
{
compilerOptions: {
target: "ES2020",
module: "CommonJS",
lib: ["ES2020"],
target: "esnext",
module: "esnext",
moduleResolution: "node",
esModuleInterop: true,
allowJs: true,
allowSyntheticDefaultImports: true,
isolatedModules: true,
noEmit: true,
lib: ["esnext"],
jsx: "react",
resolveJsonModule: true,
types: ["@cloudflare/workers-types"],
},
},
Expand Down Expand Up @@ -1568,7 +1576,7 @@ export async function main(argv: string[]): Promise<void> {
// -- snip, end --

// annoyingly, the API for this one doesn't return the
// data in the 'standard' format. goddamit.
// data in the 'standard' format. goddammit.
// That's why we have the fallthrough response in cfetch.
// Oh well.
console.log(
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
"jsx": "react",
"resolveJsonModule": true
},
"lib": ["esnext"],
"exclude": ["node_modules/", "packages/wrangler/vendor"]
}

0 comments on commit 8b6c2d1

Please sign in to comment.