Skip to content

Commit 6ce7c52

Browse files
committed
add --quite option
1 parent a46212f commit 6ce7c52

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

src/bin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const devFlags = {
8282
'cls',
8383
'exit-child',
8484
'error-recompile',
85+
'quite',
8586
'rs',
8687
],
8788
string: [
@@ -111,12 +112,13 @@ type DevOptions = {
111112
cls: boolean
112113
'ignore-watch': string
113114
'all-deps': boolean
114-
['deps-level']: string
115+
'deps-level': string
115116
'compile-timeout': string
116117
'exec-check': boolean
117118
'exit-child': boolean
118119
'cache-directory': string
119120
'error-recompile': boolean
121+
quite: boolean
120122
'tree-kill': boolean
121123
}
122124

@@ -135,7 +137,7 @@ const opts = minimist(devArgs, {
135137
'prefer-ts-exts': 'prefer-ts',
136138
},
137139
default: {
138-
fork: true
140+
fork: true,
139141
},
140142
unknown: function (arg) {
141143
unknown.push(arg)

src/cfg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type Config = {
2323
ignore: string[]
2424
respawn: boolean
2525
debug: boolean
26+
quite: boolean
2627
extensions: Record<string, string>
2728
}
2829

@@ -49,7 +50,6 @@ export const makeCfg = (main: string, opts: Partial<Options>): Config => {
4950
.concat(opts['ignore-watch'] as string)
5051
.map((_) => _.trim())
5152
: []
52-
5353
const ignoreWatch: string[] = ignoreWatchItems.concat(c.ignore || [])
5454
opts.debug && console.log('Ignore watch:', ignoreWatch)
5555
const ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath))
@@ -64,6 +64,7 @@ export const makeCfg = (main: string, opts: Partial<Options>): Config => {
6464
ignore: ignore,
6565
respawn: c.respawn || false,
6666
debug: !!opts.debug,
67+
quite: !!opts.quite,
6768
extensions: c.extensions,
6869
}
6970
}

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export const makeCompiler = (
259259
try {
260260
_compile()
261261
} catch (e) {
262-
console.log('Compilation error in', fileName)
262+
console.error('Compilation error in', fileName)
263263
const errorCode =
264264
'throw ' + 'new Error(' + JSON.stringify(e.message) + ')' + ';'
265265
writeCompiled(errorCode)

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ export const runDev = (
8888
})
8989
}
9090

91-
console.log(
92-
'ts-node-dev ver. ' + version + ' (using ts-node ver.',
93-
tsNodeVersion + ', typescript ver.',
94-
tsVersion + ')'
91+
log.info(
92+
'ts-node-dev ver. ' +
93+
version +
94+
' (using ts-node ver. ' +
95+
tsNodeVersion +
96+
', typescript ver. ' +
97+
tsVersion +
98+
')'
9599
)
96100

97101
/**

src/log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type LogLevel = keyof typeof colors
2626
*/
2727
export const makeLog = function (cfg: Config) {
2828
function log(msg: string, level: LogLevel) {
29+
if (cfg.quite && level === 'info') return
2930
if (cfg.timestamp) msg = color(fmt(cfg.timestamp), '30;1') + ' ' + msg
3031
const c = colors[level.toLowerCase() as LogLevel] || '32'
3132
console.log('[' + color(level.toUpperCase(), c) + '] ' + msg)
@@ -42,8 +43,7 @@ export const makeLog = function (cfg: Config) {
4243
if (!cfg.debug) return
4344
log(util.format.apply(util, arguments), 'debug')
4445
}
45-
46-
log.info = function () {
46+
log.info = function () {
4747
log(util.format.apply(util, arguments), 'info')
4848
}
4949

test/tsnd.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ describe('ts-node-dev', function () {
8080
await replaceText('with-error.ts', '1', `'1'`)
8181
})
8282

83+
it.only('should not output INFO messages with --quite', async () => {
84+
const ps = spawnTsNodeDev('--respawn --poll --quite simple.ts')
85+
await ps.waitForLine(/v1/)
86+
setTimeout(() => replaceText('dep.ts', 'v1', 'v2'), 250)
87+
await ps.waitForLine(/v2/)
88+
89+
await ps.exit()
90+
91+
t.equal(ps.getStdout(), ['v1', 'v2', ''].join('\n'))
92+
93+
await replaceText('dep.ts', 'v2', 'v1')
94+
})
95+
8396
it('should report an error with --log-error and continue to work', async () => {
8497
const ps = spawnTsNodeDev('--respawn --log-error with-error.ts')
8598
await ps.waitForErrorLine(/error/)

0 commit comments

Comments
 (0)