Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit 8892545

Browse files
committed
Merge pull request #150 from AppShipIt/148-ignore-diagnostics
ignoreDiagnostics like ts-loader
2 parents 3783b6c + 24eddaa commit 8892545

File tree

8 files changed

+49
-34
lines changed

8 files changed

+49
-34
lines changed

.npmignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
.tscache
22
node_modules
3-
dist
4-
!/dist
5-
!/dist.babel
63
tscommand

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ Array of paths to .d.ts files that must be included in program. Useful with `rew
125125

126126
Use this setting to disable type checking.
127127

128+
### ignoreDiagnostics *(number[]) (default=[])*
129+
130+
You can squelch certain TypeScript errors by specifying an array of [diagnostic codes](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json) to ignore.
131+
For example, you can transpile [stage 1 properties](https://github.com/jeffmo/es-class-fields-and-static-properties) from `*.js` using `"ignoreDiagnostics": [8014]`.
132+
128133
### forkChecker *(boolean) (default=false)*
129134

130135
Do type checking in a separate process, so webpack doesn't need to wait. **Significantly** improves development workflow with tools like [react-hot-loader](https://github.com/gaearon/react-hot-loader).
@@ -169,7 +174,7 @@ Directory when cache is stored.
169174

170175
Invoke glob resolver using 'filesGlob' and 'exclude' sections of `tsconfig`.
171176

172-
### skipDeclarationFilesCheck *(string) (default=fase)*
177+
### skipDeclarationFilesCheck *(string) (default=false)*
173178

174179
Skip declaration files typechecking. Use this only if you understand consequences.
175180

package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"description": "Awesome TS loader for webpack",
55
"main": "dist.babel/entry.js",
66
"scripts": {
7-
"prepublish": "npm run ts-build && npm run babel-build && grunt",
8-
"ts": "./node_modules/.bin/tsc --project src --watch --pretty --diagnostics",
9-
"ts-build": "./node_modules/.bin/tsc --project src --pretty",
10-
"babel": "babel dist --presets es2015 --out-dir dist.babel --watch",
11-
"babel-build": "babel dist --presets es2015 --out-dir dist.babel",
7+
"prepublish": "npm run test && grunt",
8+
"pretest": "npm run build",
129
"test": "mocha dist.babel/test",
13-
"build": "npm run grunt && npm run babel-compile",
14-
"lint": "./node_modules/.bin/tslint src/*.ts"
10+
"watch": "npm run watch:ts && npm run watch:babel",
11+
"watch:ts": "npm run build:ts -- --watch --diagnostics",
12+
"watch:babel": "npm run build:babel -- --watch",
13+
"prebuild": "npm run lint",
14+
"build": "npm run build:ts && npm run build:babel",
15+
"build:ts": "tsc -p src --pretty",
16+
"build:babel": "babel dist -d dist.babel",
17+
"lint": "tslint src/*.ts"
1518
},
1619
"author": "Stanislav Panferov <[email protected]> (http://panferov.me/)",
1720
"repository": {
@@ -59,7 +62,6 @@
5962
"grunt-contrib-copy": "^0.7.0",
6063
"grunt-conventional-changelog": "^1.2.1",
6164
"grunt-shell": "^1.1.2",
62-
"grunt-ts": "^3.0.0",
6365
"load-grunt-tasks": "^0.6.0",
6466
"mkdirp": "^0.5.1",
6567
"mocha": "^2.3.4",

src/helpers.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,18 @@ export function codegenErrorReport(errors) {
5858
.join('\n');
5959
}
6060

61-
export function formatErrors(instanceName: string, errors: ts.Diagnostic[]) {
62-
return errors.map(function (diagnostic) {
63-
let lineChar;
64-
if (diagnostic.file) {
65-
lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
66-
}
67-
return (
68-
`[${ instanceName }] ` + (diagnostic.file ? diagnostic.file.fileName : '')
69-
+ (lineChar ? formatLineChar(lineChar) + ' ' : '') + "\n"
70-
+ (typeof diagnostic.messageText == "string" ?
71-
diagnostic.messageText :
72-
formatMessageChain(<ts.DiagnosticMessageChain>diagnostic.messageText))
73-
);
74-
});
61+
export function formatError(diagnostic) {
62+
let lineChar;
63+
if (diagnostic.file) {
64+
lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
65+
}
66+
return (
67+
(diagnostic.file ? diagnostic.file.fileName : '')
68+
+ (lineChar ? formatLineChar(lineChar) + ' ' : '') + "\n"
69+
+ (typeof diagnostic.messageText == "string" ?
70+
diagnostic.messageText :
71+
formatMessageChain(<ts.DiagnosticMessageChain>diagnostic.messageText))
72+
);
7573
}
7674

7775
export function formatMessageChain(chain: ts.DiagnosticMessageChain) {

src/host.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface ICompilerOptions extends ts.CompilerOptions {
4141
exclude?: string[];
4242
externals?: any;
4343
doTypeCheck?: boolean;
44+
ignoreDiagnostics?: number[];
4445
forkChecker?: boolean;
4546
forkCheckerSilent?: boolean;
4647
useBabel?: boolean;

src/instance.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'fs';
33
import * as path from 'path';
44
import * as _ from 'lodash';
55
import * as tsconfig from 'tsconfig';
6-
import { loadLib, formatErrors } from './helpers';
6+
import { loadLib, formatError } from './helpers';
77
import { ICompilerInfo } from './host';
88
import { createResolver } from './deps';
99
import { createChecker } from './checker';
@@ -358,16 +358,19 @@ function setupAfterCompile(compiler, instanceName, forkChecker = false) {
358358
}
359359

360360
let diagnostics = state.ts.getPreEmitDiagnostics(state.program);
361-
let emitError = (err) => {
361+
let emitError = (msg) => {
362362
if (compilation.bail) {
363-
console.error('Error in bail mode:', err);
363+
console.error('Error in bail mode:', msg);
364364
process.exit(1);
365365
}
366-
compilation.errors.push(new Error(err));
366+
compilation.errors.push(new Error(msg));
367367
};
368368

369-
let errors = formatErrors(instanceName, diagnostics);
370-
errors.forEach(emitError);
369+
let {options: {ignoreDiagnostics}} = instance;
370+
diagnostics
371+
.filter(err => !ignoreDiagnostics || ignoreDiagnostics.indexOf(err.code) == -1)
372+
.map(err => `[${ instanceName }] ` + formatError(err))
373+
.forEach(emitError);
371374

372375
instance.initedPlugins.forEach(plugin => {
373376
plugin.processProgram(state.program);

src/test/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ describe('main test', function() {
2828
expect(stats.compilation.errors.length).eq(1);
2929
});
3030

31+
it('should ignore diagnostics', async function() {
32+
let config = {
33+
entry: fixturePath(['errors', 'with-type-errors.ts'])
34+
};
35+
36+
let loaderQuery = { ignoreDiagnostics: [2345] };
37+
38+
let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
39+
expect(stats.compilation.errors.length).eq(0);
40+
});
41+
3142
it('should load tsx files and use tsconfig', async function() {
3243
let tsconfig = fixturePath(['tsx', 'tsconfig.json']);
3344
let config = {

src/tsconfig.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
"compilerOptions": {
33
"target": "es6",
44
"outDir": "../dist",
5-
"declaration": false,
65
"moduleResolution": "node",
76
"skipDefaultLibCheck": true,
87
"allowSyntheticDefaultImports": true,
98
"noImplicitAny": false,
109
"removeComments": true,
11-
"noLib": false,
1210
"preserveConstEnums": true,
1311
"suppressImplicitAnyIndexErrors": true
1412
},

0 commit comments

Comments
 (0)