Skip to content

Commit 6d1b29c

Browse files
authored
Merge branch 'master' into issue_40_allow_delaying_service_start
2 parents 295ccc3 + fc4d9bd commit 6d1b29c

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
@@ -252,7 +253,8 @@ ForkTsCheckerWebpackPlugin.prototype.spawnService = function () {
252253
TSLINT: this.tslintPath || '',
253254
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
254255
WORK_DIVISION: Math.max(1, this.workersNumber),
255-
MEMORY_LIMIT: this.memoryLimit
256+
MEMORY_LIMIT: this.memoryLimit,
257+
CHECK_SYNTACTIC_ERRORS: this.checkSyntacticErrors
256258
}
257259
),
258260
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
},
@@ -205,4 +206,22 @@ describe('[INTEGRATION] index', function () {
205206

206207
compiler.run(function () {});
207208
});
209+
210+
it('should not find syntactic errors when checkSyntacticErrors is false', function (callback) {
211+
var compiler = createCompiler({}, true);
212+
213+
compiler.run(function(error, stats) {
214+
expect(stats.compilation.errors.length).to.be.equal(1);
215+
callback();
216+
});
217+
});
218+
219+
it('should find syntactic errors when checkSyntacticErrors is true', function (callback) {
220+
var compiler = createCompiler({ checkSyntacticErrors: true }, true);
221+
222+
compiler.run(function(error, stats) {
223+
expect(stats.compilation.errors.length).to.be.equal(2);
224+
callback();
225+
});
226+
});
208227
});
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)