Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a TypeScript step to create-astro #4179

Merged
merged 3 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-planets-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': minor
---

Add a step to configure how strict TypeScript should be
3 changes: 2 additions & 1 deletion packages/create-astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"files": [
"dist",
"create-astro.js"
"create-astro.js",
"tsconfigs"
],
"dependencies": {
"chalk": "^5.0.1",
Expand Down
52 changes: 52 additions & 0 deletions packages/create-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ora from 'ora';
import os from 'os';
import path from 'path';
import prompts from 'prompts';
import url from 'url';
import detectPackageManager from 'which-pm-runs';
import yargs from 'yargs-parser';
import { loadWithRocketGradient, rocketAscii } from './gradient.js';
Expand Down Expand Up @@ -284,10 +285,61 @@ export async function main() {
ora().info(dim(`--dry-run enabled, skipping.`));
} else if (gitResponse.git) {
await execaCommand('git init', { cwd });
ora().succeed('Git repository created!');
} else {
ora().info(dim(`Sounds good! You can come back and run ${cyan(`git init`)} later.`));
}

const tsResponse = await prompts(
{
type: 'select',
name: 'typescript',
message:
'Astro is a TypeScript-first framework. How strict would you like the typechecking to be?',
choices: [
{
title: 'Relaxed',
description: "Not a big fan of TypeScript? No issues, we'll keep this kind",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: "Not a big fan of TypeScript? No issues, we'll keep this kind",
description: "Not a big fan of TypeScript? No worries, we'll keep things casual",

I LOVE this option! This is such user empathy! 😄

I would suggest adjusting the message a little bit, though. When I read it, I read "kind" expecting "kind of..." So, I thought it was going to say, "We'll keep this kind of...." and then it stopped.

Often designing messages for the widest audience possible, we would try to avoid slang etc. So, you can't go wrong with a very factual description here of what will/won't happen. But, I think if you want to convey this friendliness, there are still some choices that could work. Maybe like....

First part: I think "No worries" is much more common across an international audience than "No issues" (issues might make people think of bugs? or is there an "issue" with this process?) I'd consider "worries" instead.

Second part: this is a little harder, but here are some possibilities that might be a bit more accessible while still being fun, maybe?

  • we'll keep things casual
  • we'll take it easy on you
  • we won't make you use it / you don't have to use it
  • we'll turn off the red squigglies
  • we'll try to help, but won't insist
    ... ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! I used No issues because No worries is used earlier in the steps and my brain immediately went in "Find synonyms" mode 😄

For the second part, we can't say that the user won't have to use it or that it'll disable anything because it effectively doesn't. TypeScript is always enabled, just with friendlier settings. we'll keep things casual seems good to me!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here were my suggestions, lmk what you think! #4179 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thought on formatting: because this is the last question, what if the "don't love typescript" message came after "setup complete!" That way it wouldn't break up the series of prompts mid-way through.

value: 'default',
},
{
title: 'Strict (recommended)',
description: 'Will enable `strict`',
value: 'strict',
},
{
title: 'Stricter',
description: 'Will enable `strict` and some stricter settings',
value: 'stricter',
},
],
},
{
onCancel: () => {
ora().info(
dim(
'Operation cancelled. No worries, your project folder has already been created and TypeScript settings have been set to "Relaxed"'
)
);
process.exit(1);
},
}
);

if (args.dryRun) {
ora().info(dim(`--dry-run enabled, skipping.`));
} else if (tsResponse.typescript) {
fs.copyFileSync(
path.join(
url.fileURLToPath(new URL('..', import.meta.url)),
'tsconfigs',
`tsconfig.${tsResponse.typescript}.json`
),
path.join(cwd, 'tsconfig.json')
);
ora().succeed('TypeScript settings applied!');
}

ora().succeed('Setup complete.');
ora({ text: green('Ready for liftoff!') }).succeed();
await wait(300);
Expand Down
19 changes: 19 additions & 0 deletions packages/create-astro/tsconfigs/tsconfig.strict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
// Enable top-level await, and other modern ESM features.
"target": "ESNext",
"module": "ESNext",
// Enable node-style module resolution, for things like npm package imports.
"moduleResolution": "node",
// Enable JSON imports.
"resolveJsonModule": true,
// Enable stricter transpilation for better output.
"isolatedModules": true,
// Astro will directly run your TypeScript code, no transpilation needed.
"noEmit": true,
// Enable strict type checking.
"strict": true,
// Error when a value import is only used as a type.
"importsNotUsedAsValues": "error"
}
}
33 changes: 33 additions & 0 deletions packages/create-astro/tsconfigs/tsconfig.stricter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
// Enable top-level await, and other modern ESM features.
"target": "ESNext",
"module": "ESNext",
// Enable node-style module resolution, for things like npm package imports.
"moduleResolution": "node",
// Enable JSON imports.
"resolveJsonModule": true,
// Enable stricter transpilation for better output.
"isolatedModules": true,
// Astro will directly run your TypeScript code, no transpilation needed.
"noEmit": true,
// Enable strict type checking.
"strict": true,
// Error when a value import is only used as a type.
"importsNotUsedAsValues": "error",
// Report errors for fallthrough cases in switch statements
"noFallthroughCasesInSwitch": true,
// Force functions designed to override their parent class to be specified as `override`.
"noImplicitOverride": true,
// Force functions to specify that they can return `undefined` if a possibe code path does not return a value.
"noImplicitReturns": true,
// Report an error when a variable is declared but never used.
"noUnusedLocals": true,
// Report an error when a parameter is declared but never used.
"noUnusedParameters": true,
// Force the usage of the indexed syntax to access fields declared using an index signature.
"noUncheckedIndexedAccess": true,
// Report an error when the value `undefined` is given to an optional property that doesn't specify `undefined` as a valid value.
"exactOptionalPropertyTypes": true
}
}