-
Notifications
You must be signed in to change notification settings - Fork 99
Set up build-time code for TypeScript development #288
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
Conversation
|
"test:node": "mocha -r register-ts-node 'ts/tests/**/*.{ts,js}'", | ||
"test:all": "ember try:each", | ||
"prepublishOnly": "yarn tsc --project ts --noEmit false", | ||
"postpublish": "rimraf js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This will help tremendously with:
This could lead to a pretty frustrating DX if one of us happens to have files sitting around in js/ and doesn't realize it.
I'll review this and play with it today |
@jamescdavis Since you suggest we use both TSLint and ESLint -- Are we truly in a situation where one of these two tools cannot do the whole job? I typically use TSLint, and have never been able to get the |
I think @jamescdavis was noting that it's possible to do that (and that OSF is), but not saying we should do it. My overall take is that we should just use ESLint, including doing whatever work is necessary to make that easy to use, in part because ESLint just seems to be on a better foundation and seems to be much more actively developed and it keeps us better in sync with the rest of the Ember ecosystem's defaults… and, frankly, ESLint is a lot less opinionated than TSLint is. |
I suspect the I do think coming up with a (preferably push-button) recommendation for linting runtime TS code for the community would be a good thing for us to do, but I see that as out of scope here 🙂
I know that's the norm in TS, and honestly it drives me batty 😉. I'd lean toward 2-space, since that's the norm for JS in the Ember community (as well as TS in Ember itself), but also not a hill I'm gonna die on.
Entirely possible this is just me, but I think I already assume when I see I'd love to somehow convey that this is the source for portions of the addon that execute as part of the host's build rather than the runtime stuff that gets shipped to the browser (which would be in (...I accidentally hit 'comment and close' instead of focusing the text input to keep typing) Has anyone had a chance to actually take this branch out for a spin yet? I'm happy to spend time discussing stuff like linting and naming, but I'd also love to get feedback on the practical DX and make sure that this seems sane when it's actually in use 🙂 |
3 space indents with a 90-character maximum! :ahem: Yes, that is my extremely unusual personal preference, but no I would never fight someone for it. 😆 re: 4 spaces—that's mostly because TS started very much in a C♯-and-Java-adjacent space. My opinion is that idiomatic TS should be written like idiomatic JS, not like C♯ or Java. Also not a hill I'd die on, but there you have it. Re: |
I think I'd expect anything in |
Yeah, fair. 🤔 |
aaadd25
to
9cbb681
Compare
In the same vein, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, seems to work well from my quick testing.
RE: the follow-on issues, all reasonable options that have been proposed are fine with me
Ok, I'm going to merge this in and start work on getting the Babel integration to a place where folks can begin playing with it. Here's a summary of where things landed:
|
"testdouble": "^3.5.0", | ||
"typescript": "^2.7.2" | ||
"ts-node": "^7.0.1", | ||
"typescript": "^2.7.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion for follow-up: given this is for us, let's update soon to use latest TS here. It fixes quite a few bugs in the type system from what I've seen, and while we're unlikely to hit most of them outside Ember code.
Fixes some links to the `tsconfig.json` blueprint. These files were moved in typed-ember#288
@dwickern @jamescdavis @mike-north
Overview
This is extracted from prototyping I've been doing with Babel 7 off and on. At a high level, it enables us to begin writing addon node-land code in TypeScript. In development, TypeScript files are loaded via
ts-node
, whereas in CI and in the published package, the transpiled JS is used instead.This doesn't fully supercede #35, as it doesn't actually convert any meaningful amount of code to TS (just one small utility to ensure everything works end-to-end), but it should make it simple to do so in the future. As mentioned in #287, if we adopt the Babel plugin for managing transpilation, much of our existing code will no longer be needed, so converting that likely wouldn't be a wise time investment. However, this will allow us to write all new code with TS and convert what remains (e.g. the default blueprint and commands) when time permits.
I've aimed to break the change into a set of self-contained commits that build on one another in a way that's easy to review.
Open Questions
What kind of linting do we want for
.ts
files? Currently there's none set up, but the two immediate options I see are TSLint or ESLint +typescript-eslint-parser
and maybeeslint-plugin-typescript
. There seems to be a bit of a leaning toward the latter in the Ember + TS community at this point (and I know Chris is an advocate of that approach), but do y'all have strong opinions?Where should the source and transpiled output live? Most of the appealing options for input directory names already have meaning to Ember CLI (e.g.
addon
andsrc
), so I took a cue fromember-auto-import
and usedts
for the input andjs
for the output. These names are nice and terse, but without the force of being any kind of established convention so far, they don't communicate a lot of information. Any better suggestions?Does the behavior in our
index.js
entry point represent our ideal ergonomics? Currently the code inindex.js
will prefer transpiled output over the source.ts
files if it's present. This could lead to a pretty frustrating DX if one of us happens to have files sitting around injs/
and doesn't realize it. I could imagine either:isDevelopingAddon
is true but we're running from a.js
fileIn principle either of these approaches could work, since the
.ts
files wouldn't be present when testing in CI or production (thets/
directory is deleted before running tests in CI and excluded from the tarball that gets pushed to npm).