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

feat: migrate to TypeScript #1134

Merged
merged 6 commits into from
Mar 9, 2023
Merged

feat: migrate to TypeScript #1134

merged 6 commits into from
Mar 9, 2023

Conversation

NiedziolkaMichal
Copy link
Member

This PR adds TypeScript to the project. I intended to make as small amount of changes as possible, so it's easier to review.

  • Added basic dependencies and made ESLint correctly process ts files and ESM
  • @typescript-eslint/recommended has a bit more restrictive rules than what was previously present. Because of that, changes in console-utils.test.js and editable-wat.js were required.
  • I have changed only extensions of lib files to TS. I didn't change extensions of files from editor/js because there are A LOT of errors that would have to be fixed.
  • Compiler has thrown an error about 2 invalid configs from cosmiconfigSync. I have removed them, as cosmicconfig documentation doesn't bring them up and the function works exactly the same way without them.

If everything looks to be fine, I will convert the rest of the files to .ts and add types.

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

  1. You'll want to add a prepack script that runs tsc to automatically transpile TypeScript to JavaScript when packaging. Implicitly this will fail if there are any TypeScript errors. (However, better not add those *.js files to the .gitignore, because it just makes it harder to debug.)
  2. You need to update those scripts that run *.js files to call ts-node with the *.ts file instead.

@NiedziolkaMichal
Copy link
Member Author

@caugner Thank you for the guidance, CI/CD was the hardest part for me to figure out. Could you please recheck, when you have a minute?

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

I think this looks good, and the passing tests confirm this, but maybe @queengooborg could take a second look to make sure I didn't miss anything?

@caugner caugner changed the title feat: Allow to use TypeScript feat: migrate to TypeScript Mar 8, 2023
Copy link
Collaborator

@queengooborg queengooborg left a comment

Choose a reason for hiding this comment

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

Let's take advantage of SWC here as well, help keep things speedy throughout all our repos!

npm i -D @swc/cli @swc/core

And in tsconfig.json:

{
  ...
  "ts-node": {
    "esm": true,
    "files": true,
    "swc": true
  }
}

editor/js/editable-wat.js Outdated Show resolved Hide resolved
@NiedziolkaMichal
Copy link
Member Author

@queengooborg Thanks a lot for all of the suggestions. Could you please recheck?

@queengooborg queengooborg merged commit 9e7b619 into mdn:main Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants