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: start can now watch ts files (#246) #276

Merged
merged 3 commits into from
Oct 15, 2020
Merged

Conversation

alemagio
Copy link
Contributor

@alemagio alemagio commented Oct 9, 2020

Checklist

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 uses concurrently so we basically have 2 watchers running together: one for ts files and one for the compiled dist 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.

const appFile = resolve(configFile.compilerOptions.outDir, basename(opts._[0]).replace(/.ts$/, '.js'))
args.splice(args.length - 1, 1, appFile)

host.afterProgramCreate = async program => {
Copy link
Member

Choose a reason for hiding this comment

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

why is this async?

Copy link
Contributor Author

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


// FIXME
// paths are relative to the root of the project
// this can be run only from there
Copy link
Member

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?

Copy link
Contributor Author

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.

const test = t.test
const sgetOriginal = require('simple-get').concat
const sget = (opts, cb) => {
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

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

please use promisify instead.

Copy link
Contributor Author

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')
Copy link
Member

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.

@alemagio alemagio marked this pull request as ready for review October 15, 2020 07:03
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina requested a review from a team October 15, 2020 07:37
Copy link
Member

@L2jLiga L2jLiga left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@fox1t fox1t left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina merged commit b6935b4 into fastify:master Oct 15, 2020
mcollina added a commit that referenced this pull request Oct 19, 2020
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.

4 participants