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

ignoreDiagnostics like ts-loader #150

Merged
merged 5 commits into from
Jun 5, 2016
Merged
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
3 changes: 0 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.tscache
node_modules
dist
!/dist
!/dist.babel
tscommand
Copy link
Contributor Author

@texastoland texastoland Jun 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right I should've left this line so TS output doesn't get published to npm. The next two lines can still be removed though and maybe add dist.babel/test.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ Array of paths to .d.ts files that must be included in program. Useful with `rew

Use this setting to disable type checking.

### ignoreDiagnostics *(number[]) (default=[])*

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.
For example, you can transpile [stage 1 properties](https://github.com/jeffmo/es-class-fields-and-static-properties) from `*.js` using `"ignoreDiagnostics": [8014]`.

### forkChecker *(boolean) (default=false)*

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).
Expand Down Expand Up @@ -169,7 +174,7 @@ Directory when cache is stored.

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

### skipDeclarationFilesCheck *(string) (default=fase)*
### skipDeclarationFilesCheck *(string) (default=false)*

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

Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"description": "Awesome TS loader for webpack",
"main": "dist.babel/entry.js",
"scripts": {
"prepublish": "npm run ts-build && npm run babel-build && grunt",
"ts": "./node_modules/.bin/tsc --project src --watch --pretty --diagnostics",
"ts-build": "./node_modules/.bin/tsc --project src --pretty",
"babel": "babel dist --presets es2015 --out-dir dist.babel --watch",
"babel-build": "babel dist --presets es2015 --out-dir dist.babel",
"prepublish": "npm run test && grunt",
"pretest": "npm run build",
"test": "mocha dist.babel/test",
"build": "npm run grunt && npm run babel-compile",
"lint": "./node_modules/.bin/tslint src/*.ts"
"watch": "npm run watch:ts && npm run watch:babel",
"watch:ts": "npm run build:ts -- --watch --diagnostics",
"watch:babel": "npm run build:babel -- --watch",
"prebuild": "npm run lint",
"build": "npm run build:ts && npm run build:babel",
"build:ts": "tsc -p src --pretty",
"build:babel": "babel dist -d dist.babel",
"lint": "tslint src/*.ts"
},
"author": "Stanislav Panferov <[email protected]> (http://panferov.me/)",
"repository": {
Expand Down Expand Up @@ -59,7 +62,6 @@
"grunt-contrib-copy": "^0.7.0",
"grunt-conventional-changelog": "^1.2.1",
"grunt-shell": "^1.1.2",
"grunt-ts": "^3.0.0",
"load-grunt-tasks": "^0.6.0",
"mkdirp": "^0.5.1",
"mocha": "^2.3.4",
Expand Down
26 changes: 12 additions & 14 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,18 @@ export function codegenErrorReport(errors) {
.join('\n');
}

export function formatErrors(instanceName: string, errors: ts.Diagnostic[]) {
return errors.map(function (diagnostic) {
let lineChar;
if (diagnostic.file) {
lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
}
return (
`[${ instanceName }] ` + (diagnostic.file ? diagnostic.file.fileName : '')
+ (lineChar ? formatLineChar(lineChar) + ' ' : '') + "\n"
+ (typeof diagnostic.messageText == "string" ?
diagnostic.messageText :
formatMessageChain(<ts.DiagnosticMessageChain>diagnostic.messageText))
);
});
export function formatError(diagnostic) {
let lineChar;
if (diagnostic.file) {
lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
}
return (
(diagnostic.file ? diagnostic.file.fileName : '')
+ (lineChar ? formatLineChar(lineChar) + ' ' : '') + "\n"
Copy link
Owner

@s-panferov s-panferov Jun 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceName disappeared. Was it intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted where it moved to. This just unwrapped errors.map(). Most of the diff is indentation.

+ (typeof diagnostic.messageText == "string" ?
diagnostic.messageText :
formatMessageChain(<ts.DiagnosticMessageChain>diagnostic.messageText))
);
}

export function formatMessageChain(chain: ts.DiagnosticMessageChain) {
Expand Down
1 change: 1 addition & 0 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ICompilerOptions extends ts.CompilerOptions {
exclude?: string[];
externals?: any;
doTypeCheck?: boolean;
ignoreDiagnostics?: number[];
forkChecker?: boolean;
forkCheckerSilent?: boolean;
useBabel?: boolean;
Expand Down
15 changes: 9 additions & 6 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as _ from 'lodash';
import * as tsconfig from 'tsconfig';
import { loadLib, formatErrors } from './helpers';
import { loadLib, formatError } from './helpers';
import { ICompilerInfo } from './host';
import { createResolver } from './deps';
import { createChecker } from './checker';
Expand Down Expand Up @@ -358,16 +358,19 @@ function setupAfterCompile(compiler, instanceName, forkChecker = false) {
}

let diagnostics = state.ts.getPreEmitDiagnostics(state.program);
let emitError = (err) => {
let emitError = (msg) => {
if (compilation.bail) {
console.error('Error in bail mode:', err);
console.error('Error in bail mode:', msg);
process.exit(1);
}
compilation.errors.push(new Error(err));
compilation.errors.push(new Error(msg));
};

let errors = formatErrors(instanceName, diagnostics);
errors.forEach(emitError);
let {options: {ignoreDiagnostics}} = instance;
diagnostics
.filter(err => !ignoreDiagnostics || ignoreDiagnostics.indexOf(err.code) == -1)
.map(err => `[${ instanceName }] ` + formatError(err))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instanceName was moved here. It kept me from having to make formatError effectively curried. It also seemed like a preferable separation of concerns since formatError has more to do with the diagnostic than the inner working of atl.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my fault. 👍

.forEach(emitError);

instance.initedPlugins.forEach(plugin => {
plugin.processProgram(state.program);
Expand Down
11 changes: 11 additions & 0 deletions src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ describe('main test', function() {
expect(stats.compilation.errors.length).eq(1);
});

it('should ignore diagnostics', async function() {
let config = {
entry: fixturePath(['errors', 'with-type-errors.ts'])
};

let loaderQuery = { ignoreDiagnostics: [2345] };

let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
expect(stats.compilation.errors.length).eq(0);
});

it('should load tsx files and use tsconfig', async function() {
let tsconfig = fixturePath(['tsx', 'tsconfig.json']);
let config = {
Expand Down
2 changes: 0 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
"compilerOptions": {
"target": "es6",
"outDir": "../dist",
"declaration": false,
"moduleResolution": "node",
"skipDefaultLibCheck": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"preserveConstEnums": true,
"suppressImplicitAnyIndexErrors": true
},
Expand Down