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

feat: case errors, silent, diagnostics, paths-plugin fixes #446

Merged
merged 9 commits into from
Jun 16, 2017
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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ before_script:
- yarn run build
node_js:
- "7"
- "6"
- "4"
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ Use pre-compiled files if any. Files must be named as `{filename}.js` and `{file

Directory when cache is stored.

### reportFiles *(string[])*

Specify [globs](https://github.com/isaacs/minimatch) to report file diagnistics. ALL OTHER ERRORS WILL NOT BE REPORTED. Example:

```
reportFiles: [
"src/**/*.{ts,tsx}"
]
```

## Compiler options

You can pass compiler options inside loader query string or in tsconfig file.
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
environment:
nodejs_version: "6"
matrix:
- TYPESCRIPT: [email protected]
- TYPESCRIPT: [email protected]
- TYPESCRIPT: [email protected]
cache:
- "%LOCALAPPDATA%\\Yarn"
install:
Expand Down
28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,33 @@
"enhanced-resolve": "^3.1.0",
"loader-utils": "^1.1.0",
"lodash": "^4.17.4",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"object-assign": "^4.1.1",
"source-map-support": "^0.4.15"
},
"devDependencies": {
"@types/chai": "^3.5.2",
"@types/chai": "^4.0.0",
"@types/colors": "^1.1.3",
"@types/lodash": "^4.14.63",
"@types/lodash": "^4.14.66",
"@types/minimatch": "^2.0.29",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.14",
"@types/shelljs": "^0.7.1",
"@types/sinon": "^2.1.3",
"@types/node": "^7.0.31",
"@types/shelljs": "^0.7.2",
"@types/sinon": "^2.3.1",
"@types/webpack": "^2.2.15",
"bluebird": "^3.5.0",
"chai": "^3.5.0",
"chai": "^4.0.2",
"empty-module": "0.0.2",
"fs-extra": "^3.0.0",
"mocha": "^3.3.0",
"fs-extra": "^3.0.1",
"mocha": "^3.4.2",
"ps-node": "^0.1.6",
"rimraf": "^2.6.1",
"shelljs": "^0.7.7",
"standard-version": "^4.0.0",
"shelljs": "^0.7.8",
"standard-version": "^4.2.0",
"temp": "^0.8.3",
"tslint": "^5.1.0",
"typescript": "^2.3.0",
"webpack": "^2.4.1"
"tslint": "^5.4.3",
"typescript": "^2.3.4",
"webpack": "^2.6.1"
}
}
4 changes: 2 additions & 2 deletions src/__test__/angular-webpack-starter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
exec as run, spec, expect, stdout
exec as run, xspec, expect, stdout
} from './utils';

import { exec, ln } from 'shelljs';

spec(__filename, async function(_env, done) {
xspec(__filename, async function(_env, done) {
this.timeout(5 * 60 * 1000);

exec('rimraf package.json');
Expand Down
4 changes: 1 addition & 3 deletions src/__test__/compile-output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
src, tsconfig, stdout, stderr,
src, tsconfig, stdout,
spec, file, execWebpack
} from './utils';

Expand Down Expand Up @@ -47,7 +47,6 @@ spec(__filename, async function(env, done) {
webpack.strictOutput();

await webpack.wait(
stderr('Checking finished with 1 errors'),
stdout([
'ERROR in [at-loader]',
`Argument of type '"1"' is not assignable to parameter of type 'number'`
Expand All @@ -57,4 +56,3 @@ spec(__filename, async function(env, done) {
webpack.close();
done();
});

7 changes: 3 additions & 4 deletions src/__test__/remove.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
src, webpackConfig, tsconfig,
watch, expectErrors, xspec
watch, expectErrors, spec
} from './utils';

xspec(__filename, async function() {
spec(__filename, async function() {
const index = src('index.ts', `
import sum from './sum'
import mul from './mul'
Expand Down Expand Up @@ -34,13 +34,12 @@ xspec(__filename, async function() {
`Cannot find name 'c'`
]);

mul.remove();
index.update(() => `
import sum from './sum'
sum(1, 1)
`);

mul.remove();

stats = await watcher.wait();
expectErrors(stats, 0);
});
43 changes: 43 additions & 0 deletions src/__test__/rename-case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
src, webpackConfig, tsconfig, watch,
expectErrors, spec
} from './utils';

spec(__filename, async function() {
const index = src('index.ts', `
import { a } from './MyFIle'
`);

const file = src('MyFIle.ts', `
export let a: number = '10'
`);

tsconfig();

const watcher = watch(webpackConfig());

{
let stats = await watcher.wait();
expectErrors(stats, 1, [
`Type '"10"' is not assignable to type 'number'`
]);
}

index.update(text => {
return `
import { a } from './MyFile'
`;
});

file.move('src/MyFile.ts');
file.update(text => {
return `
export let a: number = 10
`;
});

{
let stats = await watcher.wait();
expectErrors(stats, 0);
}
});
64 changes: 64 additions & 0 deletions src/__test__/report-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
src, webpackConfig, tsconfig, compile,
expectErrors, spec, query, file, include
} from './utils';

spec(__filename, async function() {
src('index.ts', `
import 'project/index'
export let a: number
a = '10'
`);

file('node_modules/project/package.json', `
{
"name": "project",
"version": "0.0.0",
"main": "index.ts"
}
`);

file('node_modules/project/index.ts', `
export let a: number
a = '10'
`);

src('skip.ts', `
export let a: number
a = '10'
`);

tsconfig();

{
let stats = await compile(webpackConfig(
query({
reportFiles: [
'src/**/*.{ts,tsx}',
'!src/skip.ts'
]
}),
include("node_modules")
));

expectErrors(stats, 1, [
'./src/index.ts',
`Type '"10"' is not assignable to type 'number'`
]);
}

{
let stats = await compile(webpackConfig(
include("node_modules")
));

expectErrors(stats, 3, [
'./src/index.ts',
`Type '"10"' is not assignable to type 'number'`,
'./src/skip.ts',
`Type '"10"' is not assignable to type 'number'`,
'./node_modules/project/index.ts',
`Type '"10"' is not assignable to type 'number'`,
]);
}
});
23 changes: 21 additions & 2 deletions src/__test__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ export function entry(file: string) {
export function query(q: any) {
return config => {
_.merge(
config.module.loaders.find(loader =>
loader.loader === LOADER).query,
config.module.loaders.find(loader => loader.loader === LOADER).query,
q
);
};
}

export function include(...folders: string[]) {
return config => {
config.module.loaders.find(loader => loader.loader === LOADER).include.push(
...folders.map(f => {
return path.join(process.cwd(), f);
})
);
};
}

export function webpackConfig(...enchance: any[]): webpack.Configuration {
const config = {
entry: { index: path.join(process.cwd(), SRC_DIR, 'index.ts') },
Expand Down Expand Up @@ -288,6 +297,10 @@ export function touchFile(fileName: string): Promise<any> {
.then(source => writeFile(fileName, source));
}

export function moveFile(from: string, to: string) {
fs.renameSync(from, to);
}

export function compile(config): Promise<any> {
return new Promise((resolve, reject) => {
const compiler = webpack(config);
Expand Down Expand Up @@ -436,6 +449,12 @@ export class Fixture {
touchFile(this.fileName);
}

move(to: string) {
mkdirp.sync(path.dirname(to));
moveFile(this.fileName, to);
this.fileName = to;
}

update(updater: (text: string) => string) {
let newText = updater(this.text);
this.text = newText;
Expand Down
3 changes: 1 addition & 2 deletions src/__test__/watch-output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
src, tsconfig, stdout, stderr,
src, tsconfig, stdout,
spec, execWebpack
} from './utils';

Expand All @@ -22,7 +22,6 @@ spec(__filename, async function(env, done) {

await webpack.wait(
stdout('Webpack is watching the files…'),
stderr('Checking finished with 1 errors'),
stdout([
'ERROR in [at-loader] ./src/index.ts',
`TS2345: Argument of type '"1"' is not assignable to parameter of type 'number'`
Expand Down
63 changes: 63 additions & 0 deletions src/checker/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

export interface MapLike<T> {
get(key: string): T | undefined;
has(key: string): boolean;
set(key: string, file: T);
delete(key: string);
forEach<R>(cb: (v: T, key: string) => R);
map<R>(cb: (v: T, key: string) => R): R[];
}

export class CaseSensitiveMap<T> implements MapLike<T> {
private store = new Map<string, T>();
get(key: string) {
return this.store.get(key);
}
delete(key: string) {
return this.store.delete(key);
}
has(key: string) {
return this.store.has(key);
}
set(key: string, file: T) {
return this.store.set(key, file);
}
forEach<R>(cb: (v: T, key: string) => R) {
this.store.forEach(cb);
}
map<R>(cb: (v: T, key: string) => R): R[] {
const res = [] as R[];
this.forEach((v, key) => {
res.push(cb(v, key));
});

return res;
}
}

export class CaseInsensitiveMap<T> implements MapLike<T> {
private store = new Map<string, T>();
get(key: string) {
return this.store.get(key.toLowerCase());
}
delete(key: string) {
return this.store.delete(key.toLowerCase());
}
has(key: string) {
return this.store.has(key.toLowerCase());
}
set(key: string, file: T) {
return this.store.set(key.toLowerCase(), file);
}
forEach<R>(cb: (v: T, key: string) => R) {
this.store.forEach(cb);
}
map<R>(cb: (v: T, key: string) => R): R[] {
const res = [] as R[];
this.forEach((v, key) => {
res.push(cb(v, key));
});

return res;
}
}
2 changes: 1 addition & 1 deletion src/checker/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type Req =
UpdateFile.Request |
Diagnostics.Request |
RemoveFile.Request |
Files.Request
Files.Request;

export interface Res {
seq?: number;
Expand Down
Loading