Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Reproduce internal error in tsc #7

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/glob-tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ 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);
} else {
process.exit(code);
}
});
});
}

proc.on('exit', onExit);

// terminate children.
process.on('SIGINT', function () {
Expand Down
17 changes: 12 additions & 5 deletions lib/program-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -114,4 +118,7 @@ Helper.getOptions = function () {
return commander;
};

module.exports = Helper;
/**
* @typedef {object} Helper
*/
module.exports = Helper;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down
16 changes: 15 additions & 1 deletion test/cross-spawn.mock.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
var expect = require('chai').expect;

/**
* @constructor
*/
var Process = function () {
/** @type {Record<string, Function>} */
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']);
Expand Down