Skip to content

Commit fc4d9bd

Browse files
authored
Merge pull request #43 from johnnyreilly/master
Speculative fix for #39
2 parents 256eb96 + b4c349d commit fc4d9bd

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Options passed to formatters (currently only `codeframe` - see [available option
9292
* **silent** `boolean`:
9393
If `true`, logger will not be used. Default: `false`.
9494

95+
* **checkSyntacticErrors** `boolean`:
96+
This option is useful if you're using ts-loader in `happyPackMode` with [HappyPack](https://github.com/amireh/happypack) or [thread-loader](https://github.com/webpack-contrib/thread-loader) to parallelise your builds. It will ensure that the plugin checks for both syntactic errors (eg `const array = [{} {}];`) and semantic errors (eg `const x: number = '1';`). By default the plugin only checks for semantic errors. This is because when ts-loader is used in `transpileOnly` mode, ts-loader will still report syntactic errors. When used in `happyPackMode` it does not. Default: `false`.
97+
9598
* **memoryLimit** `number`:
9699
Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: `2048`.
97100

lib/IncrementalChecker.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ var FilesWatcher = require('./FilesWatcher');
77
var WorkSet = require('./WorkSet');
88
var NormalizedMessage = require('./NormalizedMessage');
99

10-
function IncrementalChecker (programConfigFile, linterConfigFile, watchPaths, workNumber, workDivision) {
10+
function IncrementalChecker (programConfigFile, linterConfigFile, watchPaths, workNumber, workDivision, checkSyntacticErrors) {
1111
this.programConfigFile = programConfigFile;
1212
this.linterConfigFile = linterConfigFile;
1313
this.watchPaths = watchPaths;
1414
this.workNumber = workNumber || 0;
1515
this.workDivision = workDivision || 1;
16+
this.checkSyntacticErrors = checkSyntacticErrors || false;
1617

1718
// it's shared between compilations
1819
this.files = new FilesRegister(function() {
@@ -125,7 +126,13 @@ IncrementalChecker.prototype.getDiagnostics = function (cancellationToken) {
125126
cancellationToken.throwIfCancellationRequested();
126127
}
127128

128-
diagnostics.push.apply(diagnostics, this.program.getSemanticDiagnostics(sourceFile, cancellationToken));
129+
var diagnosticsToRegister = this.checkSyntacticErrors
130+
? []
131+
.concat(this.program.getSemanticDiagnostics(sourceFile, cancellationToken))
132+
.concat(this.program.getSyntacticDiagnostics(sourceFile, cancellationToken))
133+
: this.program.getSemanticDiagnostics(sourceFile, cancellationToken);
134+
135+
diagnostics.push.apply(diagnostics, diagnosticsToRegister);
129136
}.bind(this));
130137

131138
// normalize and deduplicate diagnostics

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function ForkTsCheckerWebpackPlugin (options) {
3131
this.logger = options.logger || console;
3232
this.silent = options.silent === true; // default false
3333
this.async = options.async !== false; // default true
34+
this.checkSyntacticErrors = options.checkSyntacticErrors === true; // default false
3435
this.workersNumber = options.workers || ForkTsCheckerWebpackPlugin.ONE_CPU;
3536
this.memoryLimit = options.memoryLimit || ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT;
3637
this.useColors = options.colors !== false; // default true
@@ -250,7 +251,8 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
250251
TSLINT: this.tslintPath || '',
251252
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
252253
WORK_DIVISION: Math.max(1, this.workersNumber),
253-
MEMORY_LIMIT: this.memoryLimit
254+
MEMORY_LIMIT: this.memoryLimit,
255+
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors
254256
}
255257
),
256258
stdio: ['inherit', 'inherit', 'inherit', 'ipc']

lib/service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var checker = new IncrementalChecker(
88
process.env.TSLINT === '' ? false : process.env.TSLINT,
99
process.env.WATCH === '' ? [] : process.env.WATCH.split('|'),
1010
parseInt(process.env.WORK_NUMBER, 10),
11-
parseInt(process.env.WORK_DIVISION, 10)
11+
parseInt(process.env.WORK_DIVISION, 10),
12+
process.env.CHECK_SYNTACTIC_ERRORS === 'true'
1213
);
1314

1415
function run (cancellationToken) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test:integration": "mocha -R spec ./test/integration && rimraf tmp",
1212
"test": "npm run test:unit && npm run test:integration",
1313
"test:watch": "mocha -R spec --watch ./test/unit",
14-
"test:coverage": "rimraf coverage && istanbul cover -root lib --include-all-sources node_modules/.bin/_mocha -- -R spec ./test/unit ./test/integration",
14+
"test:coverage": "rimraf coverage && istanbul cover -root lib --include-all-sources mocha -- -R spec ./test/unit ./test/integration",
1515
"lint": "eslint ./lib ./test",
1616
"lint:fix": "eslint ./lib ./test --fix"
1717
},

test/integration/index.spec.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ describe('[INTEGRATION] index', function () {
1010
this.timeout(30000);
1111
var plugin;
1212

13-
function createCompiler(options) {
13+
function createCompiler(options, happyPackMode) {
1414
plugin = new ForkTsCheckerWebpackPlugin(Object.assign({}, options, { silent: true }));
1515

16+
var tsLoaderOptions = happyPackMode
17+
? { happyPackMode: true, silent: true }
18+
: { transpileOnly: true, silent: true };
19+
1620
return webpack({
1721
context: path.resolve(__dirname, './project'),
1822
entry: './src/index.ts',
@@ -24,10 +28,7 @@ describe('[INTEGRATION] index', function () {
2428
{
2529
test: /\.tsx?$/,
2630
loader: 'ts-loader',
27-
options: {
28-
transpileOnly: true,
29-
silent: true
30-
}
31+
options: tsLoaderOptions
3132
}
3233
]
3334
},
@@ -185,4 +186,22 @@ describe('[INTEGRATION] index', function () {
185186
createCompiler({ tslint: true });
186187
}).to.not.throw.error;
187188
});
189+
190+
it('should not find syntactic errors when checkSyntacticErrors is false', function (callback) {
191+
var compiler = createCompiler({}, true);
192+
193+
compiler.run(function(error, stats) {
194+
expect(stats.compilation.errors.length).to.be.equal(1);
195+
callback();
196+
});
197+
});
198+
199+
it('should find syntactic errors when checkSyntacticErrors is true', function (callback) {
200+
var compiler = createCompiler({ checkSyntacticErrors: true }, true);
201+
202+
compiler.run(function(error, stats) {
203+
expect(stats.compilation.errors.length).to.be.equal(2);
204+
callback();
205+
});
206+
});
188207
});
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
1+
// Semantic error
22
const x: number = '1';
3-
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Syntactic error
2+
const array = [{} {}];

0 commit comments

Comments
 (0)