Skip to content

Commit ada9dcf

Browse files
committed
Revert "feat: start can now watch ts files (#246) (#276)"
This reverts commit b6935b4.
1 parent 01def16 commit ada9dcf

15 files changed

+60
-255
lines changed

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,4 @@ test.sock
5252
# test artifacts
5353
test/workdir
5454
test/fixtures/*.js
55-
test/fixtures/*.ts
5655
.vscode/launch.json
57-
58-
# ts compiled
59-
dist

args.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function parseArgs (args) {
99
},
1010
number: ['port', 'inspect-port', 'body-limit', 'plugin-timeout'],
1111
boolean: ['pretty-logs', 'options', 'watch', 'debug'],
12-
string: ['log-level', 'address', 'socket', 'prefix', 'ignore-watch', 'logging-module', 'debug-host', 'lang', 'tsconfig'],
12+
string: ['log-level', 'address', 'socket', 'prefix', 'ignore-watch', 'logging-module', 'debug-host', 'lang'],
1313
envPrefix: 'FASTIFY_',
1414
alias: {
1515
port: ['p'],
@@ -35,8 +35,7 @@ module.exports = function parseArgs (args) {
3535
'ignore-watch': 'node_modules build dist .git bower_components logs .swp',
3636
options: false,
3737
'plugin-timeout': 10 * 1000, // everything should load in 10 seconds
38-
lang: 'js',
39-
tsconfig: 'tsconfig.json'
38+
lang: 'js'
4039
}
4140
})
4241

@@ -62,7 +61,6 @@ module.exports = function parseArgs (args) {
6261
socket: parsedArgs.socket,
6362
prefix: parsedArgs.prefix,
6463
loggingModule: parsedArgs.loggingModule,
65-
lang: parsedArgs.lang,
66-
tsconfig: parsedArgs.tsconfig
64+
lang: parsedArgs.lang
6765
}
6866
}

examples/plugin.ts

-10
This file was deleted.

generate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const typescriptTemplate = {
4747
test: 'npm run build:ts && tsc -p test/tsconfig.test.json && tap test/**/*.test.ts',
4848
start: 'npm run build:ts && fastify start -l info dist/app.js',
4949
'build:ts': 'tsc',
50-
dev: 'fastify start -w -l info -P src/app.ts'
50+
dev: 'tsc && concurrently -k -p "[{name}]" -n "TypeScript,App" -c "yellow.bold,cyan.bold" "tsc -w" "fastify start -w -l info -P dist/app.js"'
5151
},
5252
dependencies: {
5353
fastify: cliPkg.dependencies.fastify,
@@ -58,6 +58,7 @@ const typescriptTemplate = {
5858
devDependencies: {
5959
'@types/node': cliPkg.devDependencies['@types/node'],
6060
'@types/tap': cliPkg.devDependencies['@types/tap'],
61+
concurrently: cliPkg.devDependencies.concurrently,
6162
'fastify-tsconfig': cliPkg.devDependencies['fastify-tsconfig'],
6263
tap: cliPkg.devDependencies.tap,
6364
typescript: cliPkg.devDependencies.typescript

lib/watch/tsc-watcher.js

-104
This file was deleted.

start.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ let Fastify = null
1919

2020
function loadModules (opts) {
2121
try {
22-
const app = opts._[0]
23-
const { module: fastifyModule } = requireFastifyForModule(app)
22+
const { module: fastifyModule } = requireFastifyForModule(opts._[0])
2423

2524
Fastify = fastifyModule
2625
} catch (e) {
@@ -30,7 +29,6 @@ function loadModules (opts) {
3029

3130
async function start (args) {
3231
const opts = parseArgs(args)
33-
3432
if (opts.help) {
3533
return showHelpForCommand('start')
3634
}
@@ -43,10 +41,6 @@ async function start (args) {
4341
// we start crashing on unhandledRejection
4442
require('make-promises-safe')
4543

46-
if (path.extname(opts._[0]) === '.ts') {
47-
return require('./lib/watch/tsc-watcher')(args, opts)
48-
}
49-
5044
loadModules(opts)
5145

5246
if (opts.watch) {

templates/app-ts/src/routes/example/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FastifyPluginAsync } from "fastify"
22

3-
const example: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
3+
const example: FastifyPluginAsync =async (fastify, opts): Promise<void> => {
44
fastify.get('/', async function (request, reply) {
55
return 'this is an example'
66
})

templates/app-ts/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "fastify-tsconfig",
33
"compilerOptions": {
4-
"esModuleInterop": true,
54
"outDir": "dist"
65
},
76
"include": ["src/**/*.ts"]

test/args.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ test('should parse args correctly', t => {
4444
debugPort: 1111,
4545
debugHost: '1.1.1.1',
4646
loggingModule: './custom-logger.js',
47-
lang: 'js',
48-
tsconfig: 'tsconfig.json'
47+
lang: 'js'
4948
})
5049
})
5150

@@ -91,8 +90,7 @@ test('should parse args with = assignment correctly', t => {
9190
debugPort: 1111,
9291
debugHost: '1.1.1.1',
9392
loggingModule: './custom-logger.js',
94-
lang: 'js',
95-
tsconfig: 'tsconfig.json'
93+
lang: 'js'
9694
})
9795
})
9896

@@ -153,8 +151,7 @@ test('should parse env vars correctly', t => {
153151
debugPort: 1111,
154152
debugHost: '1.1.1.1',
155153
loggingModule: './custom-logger.js',
156-
lang: 'js',
157-
tsconfig: 'tsconfig.json'
154+
lang: 'js'
158155
})
159156
})
160157

@@ -233,7 +230,6 @@ test('should parse custom plugin options', t => {
233230
debugPort: 1111,
234231
debugHost: '1.1.1.1',
235232
loggingModule: './custom-logger.js',
236-
lang: 'js',
237-
tsconfig: 'tsconfig.json'
233+
lang: 'js'
238234
})
239235
})

test/generate-typescript.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function define (t) {
104104
})
105105

106106
test('should finish succesfully with typescript template', async (t) => {
107-
t.plan(20 + Object.keys(expected).length)
107+
t.plan(21 + Object.keys(expected).length)
108108
try {
109109
await generate(workdir, typescriptTemplate)
110110
await verifyPkg(t)
@@ -132,12 +132,13 @@ function define (t) {
132132
t.equal(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.test.json && tap test/**/*.test.ts')
133133
t.equal(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js')
134134
t.equal(pkg.scripts['build:ts'], 'tsc')
135-
t.equal(pkg.scripts.dev, 'fastify start -w -l info -P src/app.ts')
135+
t.equal(pkg.scripts.dev, 'tsc && concurrently -k -p "[{name}]" -n "TypeScript,App" -c "yellow.bold,cyan.bold" "tsc -w" "fastify start -w -l info -P dist/app.js"')
136136
t.equal(pkg.dependencies['fastify-cli'], '^' + cliPkg.version)
137137
t.equal(pkg.dependencies.fastify, cliPkg.dependencies.fastify)
138138
t.equal(pkg.dependencies['fastify-plugin'], cliPkg.devDependencies['fastify-plugin'] || cliPkg.dependencies['fastify-plugin'])
139139
t.equal(pkg.dependencies['fastify-autoload'], cliPkg.devDependencies['fastify-autoload'])
140140
t.equal(pkg.devDependencies['@types/node'], cliPkg.devDependencies['@types/node'])
141+
t.equal(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently)
141142
t.equal(pkg.devDependencies.tap, cliPkg.devDependencies.tap)
142143
t.equal(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript)
143144

test/start-typescript.test.js

-54
This file was deleted.

0 commit comments

Comments
 (0)