diff --git a/bin/glob-tsc.js b/bin/glob-tsc.js index d8697ff..b37687d 100644 --- a/bin/glob-tsc.js +++ b/bin/glob-tsc.js @@ -6,7 +6,11 @@ var spawn = require('cross-spawn'), commandArgs = options.unknown.concat(helper.resolveTSFiles()), proc = spawn(helper.getTSCCommand(), commandArgs, { stdio: 'inherit' }); -proc.on('exit', function (code, signal) { +/** + * @param {number} code + * @param {number} signal + */ +function onExit (code, signal) { process.on('exit', function(){ if (signal) { process.kill(process.pid, signal); @@ -14,7 +18,9 @@ proc.on('exit', function (code, signal) { process.exit(code); } }); -}); +} + +proc.on('exit', onExit); // terminate children. process.on('SIGINT', function () { diff --git a/lib/program-helper.js b/lib/program-helper.js index f32432e..619ffce 100644 --- a/lib/program-helper.js +++ b/lib/program-helper.js @@ -20,11 +20,13 @@ function error() { /** * Resolve file globs based in command line or tsconfig.json file. - * @returns {Array} + * May throw an error. + * @returns {string[]} */ function resolveGlobs() { var options = Helper.getOptions(), tsConfigFile, + /** @type{string[]} */ tsConfig; if (options['filesGlob'] && options['filesGlob'].length) { @@ -41,14 +43,15 @@ function resolveGlobs() { return tsConfig['filesGlob']; } catch (err) { - error('tsconfig.json file is not accessible.', err); + // explicitly throw here to pass --strictNullChecks + throw error('tsconfig.json file is not accessible.', err); } } } /** * Check if a file exists - * @param cmdPath + * @param {string} cmdPath * @returns {boolean} */ function fileExists(cmdPath) { @@ -80,9 +83,10 @@ Helper.getTSCCommand = function () { /** * Resolve ts file paths * - * @returns {Array} + * @returns {string[]} */ Helper.resolveTSFiles = function () { + /** @type{string[]} */ var files = []; resolveGlobs().forEach(function (pattern) { @@ -114,4 +118,7 @@ Helper.getOptions = function () { return commander; }; -module.exports = Helper; \ No newline at end of file +/** + * @typedef {object} Helper + */ +module.exports = Helper; diff --git a/package.json b/package.json index b923753..617d650 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "glob-tsc": "./bin/glob-tsc.js" }, "scripts": { - "checkjs": "node bin/glob-tsc.js --allowJs --checkJs --noEmit --resolveJsonModule --target es5 -g bin/**/*.js,test/**/*.js", + "checkjs": "node bin/glob-tsc.js --allowJs --checkJs --noEmit --resolveJsonModule --target es5 --strictFunctionTypes --strictBindCallApply --noImplicitThis --strictNullChecks --noImplicitAny -g bin/**/*.js,test/**/*.js", "test": "npm-run-all checkjs test:mocha", "test:mocha": "mocha --timeout 5000", "test:watch": "_mocha --watch" @@ -28,7 +28,11 @@ }, "license": "ISC", "devDependencies": { + "@types/chai": "^4.2.4", + "@types/cross-spawn": "^6.0.1", + "@types/glob": "^7.1.1", "@types/mocha": "^5.2.7", + "@types/mock-require": "^2.0.0", "@types/node": "^12.11.7", "chai": "^4.2.0", "mocha": "^6.2.2", diff --git a/test/cross-spawn.mock.js b/test/cross-spawn.mock.js index c6dc556..147c856 100644 --- a/test/cross-spawn.mock.js +++ b/test/cross-spawn.mock.js @@ -1,14 +1,28 @@ var expect = require('chai').expect; +/** + * @constructor + */ var Process = function () { + /** @type {Record} */ var listeners = {}; - this.on = function (event, cb) { + /** + * @param {string} event + * @param {Function} cb + */ + function onEvent (event, cb) { listeners[event] = cb; }; + + this.on = onEvent; }; module.exports = + /** + * @param {string} cmd + * @param {string[]} args + */ function (cmd, args) { expect(cmd).to.equal('tsc'); expect(args).to.eql(['src/User.ts']);