-
Notifications
You must be signed in to change notification settings - Fork 163
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: start can now watch ts files (#246) #276
Conversation
lib/watch/tsc-watcher.js
Outdated
const appFile = resolve(configFile.compilerOptions.outDir, basename(opts._[0]).replace(/.ts$/, '.js')) | ||
args.splice(args.length - 1, 1, appFile) | ||
|
||
host.afterProgramCreate = async program => { |
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.
why is this async?
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.
remaining of experiments
fixed now
test/start-typescript.test.js
Outdated
|
||
// FIXME | ||
// paths are relative to the root of the project | ||
// this can be run only from there |
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.
what does this mean? Can you create an issue or fix it here?
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 is present in start.test.js too, sure, I'll fix it.
test/start-typescript.test.js
Outdated
const test = t.test | ||
const sgetOriginal = require('simple-get').concat | ||
const sget = (opts, cb) => { | ||
return new Promise((resolve, reject) => { |
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.
please use promisify instead.
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.
I used promisify.custom because, I think, it is not possible to simply use promisify if the callback has more than one param plus the err, in this case (err, response, body)
.
Am I wrong?
start.js
Outdated
@@ -12,14 +12,16 @@ const pump = require('pump') | |||
const isDocker = require('is-docker') | |||
const listenAddressDocker = '0.0.0.0' | |||
const watch = require('./lib/watch') | |||
const tsWatch = require('./lib/watch/tsc-watcher') |
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.
can you load this only on demand? We are loading the entirety of typescript even if it's not a ts project.
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.
lgtm
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.
lgtm
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.
LGTM
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
The idea is that we should make the user run
fastify start...
on .ts files and watch for changes on those files.At the moment the
npm run dev
script in ts project template usesconcurrently
so we basically have 2 watchers running together: one for ts files and one for the compileddist
files.This is not ideal.
This approach uses only the tsc API to watch for .ts files changes. Every time it detects a change it kills fastify process, re-compiles changed files, restarts fastify.
Note: for the moment I assumed that if the target file is a .ts file we always want to watch it even without
-w
option.Note: [docs](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-
Any suggestion is well accepted.