Skip to content

Commit 35e01d6

Browse files
committed
fixes #15, #16
1 parent 8475122 commit 35e01d6

File tree

8 files changed

+51
-23
lines changed

8 files changed

+51
-23
lines changed

lib/compiler.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var compiler = {
3232
getCompilerReadyFilePath: function () {
3333
return path.join(os.tmpdir(), 'ts-node-dev-ready-' + comilationInstanceStampt)
3434
.replace(/\\/g, '/')
35-
},
35+
},
3636
getChildHookPath: function () {
3737
return path.join(os.tmpdir(), 'ts-node-dev-hook-' + comilationInstanceStampt + '.js')
3838
.replace(/\\/g, '/')
@@ -86,7 +86,7 @@ var compiler = {
8686
console.log(e)
8787
}
8888
}
89-
89+
9090
var tsNodeOptions = {
9191
fast: options['fast'],
9292
cache: options['cache'] || !options['no-cache'],
@@ -102,7 +102,7 @@ var compiler = {
102102
ignoreDiagnostics: options['ignoreDiagnostics'],
103103
disableWarnings: options['disableWarnings'],
104104
compilerOptions: compilerOptions
105-
}
105+
}
106106
try {
107107
register(tsNodeOptions)
108108
} catch (e) {
@@ -140,7 +140,7 @@ var compiler = {
140140
compile: function (params) {
141141
var fileName = params.compile
142142
var code = fs.readFileSync(fileName, 'utf-8')
143-
var compiledPath = params.compiledPath
143+
var compiledPath = params.compiledPath
144144
function writeCompiled(code, filename) {
145145
fs.writeFileSync(compiledPath, code)
146146
fs.writeFileSync(compiledPath + '.done', '')
@@ -151,13 +151,19 @@ var compiler = {
151151
var m = {
152152
_compile: writeCompiled
153153
}
154-
tsHandler(m, fileName)
154+
tsHandler(m, fileName)
155155
try {
156156
m._compile(code, fileName)
157157
} catch (e) {
158-
console.error('Compilation error:', e)
159-
code = 'throw new Error("Unable to compile TypeScript");'
160-
writeCompiled(code)
158+
var splits = e.message.split('\n')
159+
var title = splits.shift()
160+
var message = splits.join('\n')
161+
compiler.notify(title, message, 'error')
162+
setTimeout(function () {
163+
compiler.stop()
164+
})
165+
//code = 'throw ' + 'new Error(' + JSON.stringify(e.message) + ')' + ';'
166+
//writeCompiled(code)
161167
}
162168
}
163169
}

lib/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
2626
var main = resolveMain(script);
2727
var cfg = require('./cfg')(main, opts);
2828
var log = require('./log')(cfg);
29-
var notify = require('./notify')(cfg, log);
30-
29+
var notify = require('./notify')(cfg, log);
30+
compiler.notify = notify
31+
compiler.stop = stop
3132
// Run ./dedupe.js as preload script
3233
if (cfg.dedupe) process.env.NODE_DEV_PRELOAD = __dirname + '/dedupe';
3334

@@ -42,9 +43,9 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
4243
if (cfg.clear) process.stdout.write('\033[2J\033[H');
4344
notify('Restarting', file + ' has been modified');
4445
compiler.compileChanged(file)
45-
watcher.removeAll();
46+
//watcher.removeAll();
4647
if (child) {
47-
// Child is still running, restart upon exit
48+
// Child is still running, restart upon exit
4849
child.on('exit', start);
4950
stop();
5051
} else {
@@ -63,7 +64,7 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
6364
/**
6465
* Run the wrapped script.
6566
*/
66-
function start() {
67+
function start() {
6768
var cmd = nodeArgs.concat(wrapper, script, scriptArgs);
6869
var childHookPath = compiler.getChildHookPath();
6970
cmd = ['-r', childHookPath].concat(cmd);
@@ -99,7 +100,6 @@ module.exports = function (script, scriptArgs, nodeArgs, opts) {
99100
child.on('message', function (message) {
100101
if (currentCompilePath == message.compiledPath) return
101102
currentCompilePath = message.compiledPath
102-
// console.log('message comile', message.compile);
103103
compiler.compile(message)
104104
});
105105

lib/wrap.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ if (cfg.fork) {
3737
}
3838

3939
// Error handler that displays a notification and logs the stack to stderr:
40+
var caught = false;
4041
process.on('uncaughtException', function (err) {
41-
console.error(err.stack || err);
42+
// Handle exepection only once
43+
if (caught) return;
44+
caught = true;
4245
// If there's a custom uncaughtException handler expect it to terminate
4346
// the process.
4447
var hasCustomHandler = process.listeners('uncaughtException').length > 1;
48+
if (!hasCustomHandler) {
49+
console.error(err.stack || err);
50+
}
4551
ipc.send({
4652
error: err.name || 'Error',
4753
message: err.message,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
"node": ">=0.8.0"
3333
},
3434
"scripts": {
35+
"ts-node-dev": "node ./bin/ts-node-dev",
3536
"test-node-dev": "tap test/*.js",
36-
"test": "node ./bin/ts-node-dev -r tsconfig-paths/register -r ./test/ts/add-require.js -r ./test/ts/add-require-2.js -O \"{\\\"module\\\": \\\"commonjs\\\"}\" --respawn --ignore-watch 'lib' --ignore-watch bin --prefer-ts --cache-directory .ts-node test/ts/test-script test-arg --fd",
37+
"test": "node ./bin/ts-node-dev -r tsconfig-paths/register -r ./test/ts/add-require.js -r ./test/ts/add-require-2.js -O \"{\\\"module\\\": \\\"commonjs\\\"}\" --respawn --ignore-watch 'lib' --ignore-watch bin --prefer-ts --cache-directory .ts-node test/ts/test-script test-arg --fd",
3738
"test-docker": "docker run --rm -v ${PWD}:/app mhart/alpine-node:8.7.0 sh -c 'cd app && node ./bin/ts-node-dev --cache-directory .ts-node test/ts/big'"
3839
},
3940
"dependencies": {

test.ts

Whitespace-only changes.

test/ts/dep.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2-
export const fn = () => {
2+
export const fn = (x: number) => {
33
console.log('function from dep module here')
4-
}
4+
}
5+

test/ts/test-script.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import {fn} from './dep'
22

33
const str: string = process.argv[2]
44
console.log('test', str)
5-
fn()
5+
6+
fn()

yarn.lock

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ deeper@^2.1.0:
511511
version "2.1.0"
512512
resolved "https://registry.yarnpkg.com/deeper/-/deeper-2.1.0.tgz#bc564e5f73174fdf201e08b00030e8a14da74368"
513513

514+
deepmerge@^2.0.1:
515+
version "2.1.0"
516+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.1.0.tgz#511a54fff405fc346f0240bb270a3e9533a31102"
517+
514518
default-require-extensions@^1.0.0:
515519
version "1.0.0"
516520
resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-1.0.0.tgz#f37ea15d3e13ffd9b437d33e1a75b5fb97874cb8"
@@ -2290,7 +2294,7 @@ strip-indent@^1.0.1:
22902294
dependencies:
22912295
get-stdin "^4.0.1"
22922296

2293-
strip-json-comments@^2.0.0:
2297+
strip-json-comments@^2.0.0, strip-json-comments@^2.0.1:
22942298
version "2.0.1"
22952299
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
22962300

@@ -2433,9 +2437,9 @@ tryit@^1.0.1:
24332437
version "1.0.3"
24342438
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"
24352439

2436-
ts-node@*:
2437-
version "5.0.0"
2438-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-5.0.0.tgz#9aa573889ad7949411f972981c209e064705e36f"
2440+
ts-node@^6.0.3:
2441+
version "6.0.3"
2442+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-6.0.3.tgz#28bf74bcad134fad17f7469dad04638ece03f0f4"
24392443
dependencies:
24402444
arrify "^1.0.0"
24412445
chalk "^2.3.0"
@@ -2446,6 +2450,15 @@ ts-node@*:
24462450
source-map-support "^0.5.3"
24472451
yn "^2.0.0"
24482452

2453+
tsconfig-paths@^3.3.1:
2454+
version "3.3.1"
2455+
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.3.1.tgz#e2f4f46ea23a245fc07ba2f84be5f3fab17ee2d5"
2456+
dependencies:
2457+
deepmerge "^2.0.1"
2458+
minimist "^1.2.0"
2459+
strip-bom "^3.0.0"
2460+
strip-json-comments "^2.0.1"
2461+
24492462
tsconfig@^7.0.0:
24502463
version "7.0.0"
24512464
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-7.0.0.tgz#84538875a4dc216e5c4a5432b3a4dec3d54e91b7"

0 commit comments

Comments
 (0)