Skip to content

Commit 7ca6366

Browse files
committed
fix ts-node params, compilcation
1 parent 465fc28 commit 7ca6366

File tree

8 files changed

+150
-143
lines changed

8 files changed

+150
-143
lines changed

.yalcignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

bin/ts-node-dev

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,49 @@ var opts = minimist(devArgs, {
1616
'poll',
1717
'respawn',
1818
'notify',
19-
'fast',
20-
'disableWarnings',
21-
'disable-warnings',
22-
'no-cache',
23-
'cache',
24-
'type-check',
25-
'transpile-only',
26-
'transpileOnly',
19+
'tree-kill',
20+
'clear',
21+
'cls',
22+
'exit-child',
23+
'error-recompile',
24+
// ts-node
25+
'dir',
26+
'scope',
27+
'emit',
2728
'files',
2829
'pretty',
30+
'transpile-only',
31+
'prefer-ts-exts',
2932
'prefer-ts',
3033
'exec-check',
3134
'debug',
3235
'log-error',
33-
'prefer-ts-exts',
34-
'tree-kill',
35-
'clear',
36-
'cls',
37-
'exit-child',
38-
'rs',
39-
'error-recompile',
40-
],
41-
string: [
42-
'compiler',
43-
'project',
44-
'ignore',
4536
'skip-project',
4637
'skip-ignore',
47-
'ignoreWarnings',
48-
'ignore-warnings',
49-
'ignoreDiagnostics',
50-
'ignore-diagnostics',
51-
'cache-directory',
52-
'compilerOptions',
53-
'compiler-options',
38+
'compiler-host',
39+
'script-mode'
40+
],
41+
string: [
5442
'compile-timeout',
5543
'ignore-watch',
5644
'interval',
5745
'debounce',
5846
'watch',
59-
'restart-terminated',
47+
// ts-node
48+
'compiler',
49+
'project',
50+
'ignore',
51+
'ignore-diagnostics',
52+
'compiler-options',
6053
],
6154
alias: {
62-
transpileOnly: 'T',
63-
fast: 'F',
64-
ignoreDiagnostics: 'D',
65-
ignoreWarnings: 'I',
66-
compilerOptions: 'O',
55+
'transpile-only': 'T',
56+
'compiler-host': 'H',
57+
ignore: 'I',
58+
'ignore-diagnostics': 'D',
59+
'compiler-options': 'O',
6760
compiler: 'C',
6861
project: 'P',
69-
'restart-terminated': 'rt',
7062
},
7163
default: { deps: true, notify: true, rs: false, 'type-check': true },
7264
unknown: function (arg) {

lib/child-require-hook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function isFileInNodeModules(fileName) {
8181
}
8282

8383
function registerJsExtension() {
84-
var old = require.extensions['.js']
84+
var old = require.extensions['.js']
8585
// handling preferTs probably redundant after reordering
8686
if (allowJs || preferTs) {
8787
require.extensions['.js'] = function(m, fileName) {

lib/compiler.js

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var register = require('ts-node').register
1+
var tsNode = require('ts-node')
22

33
var fs = require('fs')
44
var path = require('path')
@@ -138,9 +138,9 @@ var compiler = {
138138
tmpDir = options['cache-directory']
139139
? path.resolve(options['cache-directory'])
140140
: fs.mkdtempSync(path.join(os.tmpdir(), '.ts-node'))
141-
141+
142142
compiler.registerTsNode()
143-
143+
144144
/* clean up compiled on each new init*/
145145
rimraf.sync(compiler.getCompiledDir())
146146
compiler.createCompiledDir()
@@ -152,14 +152,31 @@ var compiler = {
152152
extensions.push('.js')
153153
}
154154

155-
compiler.writeChildHookFile(options)
155+
compiler.writeChildHookFile(options)
156156
},
157157
registerTsNode: function () {
158158
var options = compiler.options
159159
extensions.forEach(function (ext) {
160160
require.extensions[ext] = originalJsHandler
161161
})
162162

163+
// var tsNodeOptions = {
164+
// //dir: should add
165+
// emit: options['emit'],
166+
// files: options['files'],
167+
// pretty: options['pretty'],
168+
// transpileOnly: options['transpile-only'],
169+
// ignore: [].concat(options['ignore']),
170+
// preferTsExts: options['prefer-ts-exts'] || options['prefer-ts'],
171+
// logError: options['log-error'],
172+
// project: options['project'],
173+
// skipProject: options['skip-project'],
174+
// skipIgnore: options['skip-ignore'],
175+
// compiler: options['compiler'],
176+
// ignoreDiagnostics: options['ignore-diagnostics'],
177+
// disableWarnings: options['disableWarnings'],
178+
// compilerOptions: options['compiler-options'],
179+
// }
163180
var compilerOptionsArg =
164181
options['compilerOptions'] || options['compiler-options']
165182
var compilerOptions
@@ -179,33 +196,33 @@ var compiler = {
179196
ignore = [ignore]
180197
}
181198

182-
var tsNodeOptions = {
183-
fast: options['fast'],
184-
cache: options['cache'] || !options['no-cache'],
185-
typeCheck: options['type-check'],
186-
transpileOnly: options['transpileOnly'] || options['transpile-only'],
187-
pretty: options['pretty'],
188-
cacheDirectory: options['cache-directory'] || path.join(tmpDir, 'cache'),
189-
compiler: options['compiler'],
190-
project: options['project'],
191-
skipProject: options['skip-project'],
192-
skipIgnore: options['skip-ignore'],
193-
ignore: ignore,
194-
ignoreWarnings:
195-
options['ignoreWarnings'] ||
196-
options['ignoreDiagnostics'] ||
197-
options['ignore-diagnostics'],
198-
ignoreDiagnostics:
199-
options['ignoreDiagnostics'] || options['ignore-diagnostics'],
200-
logError: options['log-error'],
201-
disableWarnings: options['disableWarnings'],
202-
preferTsExts: options['prefer-ts-exts'] || options['prefer-ts'],
203-
compilerOptions: compilerOptions,
204-
files: options['files'] || true,
205-
}
199+
var DEFAULTS = tsNode.DEFAULTS
206200

207201
try {
208-
compiler.service = register(tsNodeOptions)
202+
compiler.service = tsNode.register({
203+
// should add --script-mode
204+
dir: options['dir'] || DEFAULTS.dir,
205+
scope: options['dir'] || DEFAULTS.scope,
206+
emit: options['emit'] || DEFAULTS.emit,
207+
files: options['files'] || DEFAULTS.files,
208+
pretty: options['pretty'] || DEFAULTS.pretty,
209+
transpileOnly: options['transpile-only'] || DEFAULTS.transpileOnly,
210+
ignore: options['ignore']
211+
? tsNode.split(options['ignore']) || options['ignore']
212+
: DEFAULTS.ignore,
213+
preferTsExts:
214+
options['prefer-ts-exts'] ||
215+
options['prefer-ts'] ||
216+
DEFAULTS.preferTsExts,
217+
logError: options['log-error'] || DEFAULTS.logError,
218+
project: options['project'],
219+
skipProject: options['skip-project'],
220+
skipIgnore: options['skip-ignore'],
221+
compiler: options['compiler'] || DEFAULTS.compiler,
222+
compilerHost: options['compiler-host'] || DEFAULTS.compilerHost,
223+
ignoreDiagnostics: options['ignore-diagnostics'],
224+
compilerOptions: tsNode.parse(options['compiler-options']),
225+
})
209226
} catch (e) {
210227
console.log(e)
211228
return

lib/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
9696
}
9797
var cmd = nodeArgs.concat(wrapper, script, scriptArgs)
9898
var childHookPath = compiler.getChildHookPath()
99-
10099
cmd = (opts.priorNodeArgs || []).concat(['-r', childHookPath]).concat(cmd)
101100
log.debug('Starting child process %s', cmd.join(' '))
102101
child = fork(cmd[0], cmd.slice(1), {
@@ -170,9 +169,9 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
170169
})
171170

172171
// Upon errors, display a notification and tell the child to exit.
173-
ipc.on(child, 'error', function (m) {
172+
ipc.on(child, 'error', function (m) {
174173
log.debug('Child error')
175-
notify(m.error, m.message, 'error')
174+
notify(m.error, m.message, 'error')
176175
stop(m.willTerminate)
177176
})
178177
compiler.writeReadyFile()
@@ -183,19 +182,19 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
183182
if (opts['tree-kill']) {
184183
log.debug('Using tree-kill')
185184
kill(child.pid)
186-
} else {
185+
} else {
187186
child.kill('SIGTERM')
188187
}
189188
}
190189
function stop(willTerminate) {
191190
if (!child || child.stopping) {
192191
return
193-
}
192+
}
194193
child.stopping = true
195194
child.respawn = true
196195
if (child.connected === undefined || child.connected === true) {
197196
log.debug('Disconnecting from child')
198-
child.disconnect()
197+
child.disconnect()
199198
//if (!willTerminate) {
200199
killChild()
201200
//}

0 commit comments

Comments
 (0)