diff --git a/appveyor.yml b/appveyor.yml index c774a77..aef7b0a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,6 +6,8 @@ environment: - nodejs_version: "5" - nodejs_version: "6" - nodejs_version: "7" + - nodejs_version: "8" + - nodejs_version: "9" install: - ps: Install-Product node $env:nodejs_version diff --git a/lib/tmp.js b/lib/tmp.js index 1175a4f..4652200 100644 --- a/lib/tmp.js +++ b/lib/tmp.js @@ -547,6 +547,24 @@ function _safely_install_listener() { } } + // windows does not support signals + // it'd never had won if it wasn't a major PITA + // with node v8.x and win 10 this is no longer an issue + if (process.platform == 'win32') { + var rl = require('readline').createInterface({ + input: process.stdin, + output: process.stdout + }); + + rl.on('SIGINT', function () { + process.emit('SIGINT'); + }); + } + + process.on('SIGINT', function () { + process.exit(0); + }); + process.addListener(EVENT, function _tmp$safe_listener(data) { if (existingListeners.length) { for (var i = 0, length = existingListeners.length; i < length; i++) { @@ -559,7 +577,6 @@ function _safely_install_listener() { _safely_install_listener(); - /** * Configuration options. * diff --git a/package-lock.json b/package-lock.json index 136640c..8ec7480 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tmp", - "version": "0.0.33", + "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/child-process.js b/test/child-process.js index 20c6c02..5a72365 100644 --- a/test/child-process.js +++ b/test/child-process.js @@ -19,7 +19,7 @@ module.exports.genericChildProcess = function spawnGenericChildProcess(configFil _do_spawn(command_args, cb); }; -module.exports.childProcess = function spawnChildProcess(configFile, cb) { +module.exports.childProcess = function spawnChildProcess(configFile, cb, detach) { var configFilePath = path.join(__dirname, 'outband', configFile), command_args = [path.join(__dirname, 'spawn-custom.js'), configFilePath]; @@ -28,10 +28,16 @@ module.exports.childProcess = function spawnChildProcess(configFile, cb) { if (!existsSync(configFilePath)) return cb(new Error('ENOENT: configFile ' + configFilePath + ' does not exist')); - _do_spawn(command_args, cb); + if (arguments.length > 2) { + for (var i=2; i < arguments.length; i++) { + command_args.push(arguments[i]); + } + } + + _do_spawn(command_args, cb, detach); } -function _do_spawn(command_args, cb) { +function _do_spawn(command_args, cb, detach) { var node_path = process.argv[0], stdoutBufs = [], @@ -43,7 +49,7 @@ function _do_spawn(command_args, cb) { // spawn doesn’t have the quoting problems that exec does, // especially when going for Windows portability. - child = spawn(node_path, command_args); + child = spawn(node_path, command_args, detach ? { detached:true } : undefined); child.stdin.end(); // TODO:we no longer support node 0.6 // Cannot use 'close' event because not on node-0.6. diff --git a/test/issue121-test.js b/test/issue121-test.js new file mode 100644 index 0000000..50f2dde --- /dev/null +++ b/test/issue121-test.js @@ -0,0 +1,27 @@ +/* eslint-disable no-octal */ +// vim: expandtab:ts=2:sw=2 + +const + assert = require('assert'), + assertions = require('./assertions'), + childProcess = require('./child-process').childProcess, + signals = ['SIGINT', 'SIGTERM']; + +describe('tmp', function () { + describe('issue121 - clean up on terminating signals', function () { + for (var i=0; i