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

Commit a15de0a

Browse files
authored
feat: case errors, silent, diagnostics, paths-plugin fixes (#446)
* feat: case errors, silent, diagnostics, paths-plugin fixes * chore: fix tests on linux * chore: fix test * chore: fix tests * feat: trying to track removals * fix: syntax error * fix: tests * fix: insensitive * fix: tests
1 parent c05e296 commit a15de0a

20 files changed

+810
-279
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ before_script:
88
- yarn run build
99
node_js:
1010
- "7"
11-
- "6"
12-
- "4"

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ Use pre-compiled files if any. Files must be named as `{filename}.js` and `{file
163163

164164
Directory when cache is stored.
165165

166+
### reportFiles *(string[])*
167+
168+
Specify [globs](https://github.com/isaacs/minimatch) to report file diagnistics. ALL OTHER ERRORS WILL NOT BE REPORTED. Example:
169+
170+
```
171+
reportFiles: [
172+
"src/**/*.{ts,tsx}"
173+
]
174+
```
175+
166176
## Compiler options
167177

168178
You can pass compiler options inside loader query string or in tsconfig file.

appveyor.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
environment:
22
nodejs_version: "6"
33
matrix:
4-
- TYPESCRIPT: [email protected]
4+
- TYPESCRIPT: [email protected]
5+
- TYPESCRIPT: [email protected]
56
cache:
67
- "%LOCALAPPDATA%\\Yarn"
78
install:

package.json

+15-13
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,33 @@
3636
"enhanced-resolve": "^3.1.0",
3737
"loader-utils": "^1.1.0",
3838
"lodash": "^4.17.4",
39+
"minimatch": "^3.0.4",
3940
"mkdirp": "^0.5.1",
4041
"object-assign": "^4.1.1",
4142
"source-map-support": "^0.4.15"
4243
},
4344
"devDependencies": {
44-
"@types/chai": "^3.5.2",
45+
"@types/chai": "^4.0.0",
4546
"@types/colors": "^1.1.3",
46-
"@types/lodash": "^4.14.63",
47+
"@types/lodash": "^4.14.66",
48+
"@types/minimatch": "^2.0.29",
4749
"@types/mocha": "^2.2.41",
48-
"@types/node": "^7.0.14",
49-
"@types/shelljs": "^0.7.1",
50-
"@types/sinon": "^2.1.3",
50+
"@types/node": "^7.0.31",
51+
"@types/shelljs": "^0.7.2",
52+
"@types/sinon": "^2.3.1",
5153
"@types/webpack": "^2.2.15",
5254
"bluebird": "^3.5.0",
53-
"chai": "^3.5.0",
55+
"chai": "^4.0.2",
5456
"empty-module": "0.0.2",
55-
"fs-extra": "^3.0.0",
56-
"mocha": "^3.3.0",
57+
"fs-extra": "^3.0.1",
58+
"mocha": "^3.4.2",
5759
"ps-node": "^0.1.6",
5860
"rimraf": "^2.6.1",
59-
"shelljs": "^0.7.7",
60-
"standard-version": "^4.0.0",
61+
"shelljs": "^0.7.8",
62+
"standard-version": "^4.2.0",
6163
"temp": "^0.8.3",
62-
"tslint": "^5.1.0",
63-
"typescript": "^2.3.0",
64-
"webpack": "^2.4.1"
64+
"tslint": "^5.4.3",
65+
"typescript": "^2.3.4",
66+
"webpack": "^2.6.1"
6567
}
6668
}

src/__test__/angular-webpack-starter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
2-
exec as run, spec, expect, stdout
2+
exec as run, xspec, expect, stdout
33
} from './utils';
44

55
import { exec, ln } from 'shelljs';
66

7-
spec(__filename, async function(_env, done) {
7+
xspec(__filename, async function(_env, done) {
88
this.timeout(5 * 60 * 1000);
99

1010
exec('rimraf package.json');

src/__test__/compile-output.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
src, tsconfig, stdout, stderr,
2+
src, tsconfig, stdout,
33
spec, file, execWebpack
44
} from './utils';
55

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

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

src/__test__/remove.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
src, webpackConfig, tsconfig,
3-
watch, expectErrors, xspec
3+
watch, expectErrors, spec
44
} from './utils';
55

6-
xspec(__filename, async function() {
6+
spec(__filename, async function() {
77
const index = src('index.ts', `
88
import sum from './sum'
99
import mul from './mul'
@@ -34,13 +34,12 @@ xspec(__filename, async function() {
3434
`Cannot find name 'c'`
3535
]);
3636

37+
mul.remove();
3738
index.update(() => `
3839
import sum from './sum'
3940
sum(1, 1)
4041
`);
4142

42-
mul.remove();
43-
4443
stats = await watcher.wait();
4544
expectErrors(stats, 0);
4645
});

src/__test__/rename-case.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
src, webpackConfig, tsconfig, watch,
3+
expectErrors, spec
4+
} from './utils';
5+
6+
spec(__filename, async function() {
7+
const index = src('index.ts', `
8+
import { a } from './MyFIle'
9+
`);
10+
11+
const file = src('MyFIle.ts', `
12+
export let a: number = '10'
13+
`);
14+
15+
tsconfig();
16+
17+
const watcher = watch(webpackConfig());
18+
19+
{
20+
let stats = await watcher.wait();
21+
expectErrors(stats, 1, [
22+
`Type '"10"' is not assignable to type 'number'`
23+
]);
24+
}
25+
26+
index.update(text => {
27+
return `
28+
import { a } from './MyFile'
29+
`;
30+
});
31+
32+
file.move('src/MyFile.ts');
33+
file.update(text => {
34+
return `
35+
export let a: number = 10
36+
`;
37+
});
38+
39+
{
40+
let stats = await watcher.wait();
41+
expectErrors(stats, 0);
42+
}
43+
});

src/__test__/report-files.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {
2+
src, webpackConfig, tsconfig, compile,
3+
expectErrors, spec, query, file, include
4+
} from './utils';
5+
6+
spec(__filename, async function() {
7+
src('index.ts', `
8+
import 'project/index'
9+
export let a: number
10+
a = '10'
11+
`);
12+
13+
file('node_modules/project/package.json', `
14+
{
15+
"name": "project",
16+
"version": "0.0.0",
17+
"main": "index.ts"
18+
}
19+
`);
20+
21+
file('node_modules/project/index.ts', `
22+
export let a: number
23+
a = '10'
24+
`);
25+
26+
src('skip.ts', `
27+
export let a: number
28+
a = '10'
29+
`);
30+
31+
tsconfig();
32+
33+
{
34+
let stats = await compile(webpackConfig(
35+
query({
36+
reportFiles: [
37+
'src/**/*.{ts,tsx}',
38+
'!src/skip.ts'
39+
]
40+
}),
41+
include("node_modules")
42+
));
43+
44+
expectErrors(stats, 1, [
45+
'./src/index.ts',
46+
`Type '"10"' is not assignable to type 'number'`
47+
]);
48+
}
49+
50+
{
51+
let stats = await compile(webpackConfig(
52+
include("node_modules")
53+
));
54+
55+
expectErrors(stats, 3, [
56+
'./src/index.ts',
57+
`Type '"10"' is not assignable to type 'number'`,
58+
'./src/skip.ts',
59+
`Type '"10"' is not assignable to type 'number'`,
60+
'./node_modules/project/index.ts',
61+
`Type '"10"' is not assignable to type 'number'`,
62+
]);
63+
}
64+
});

src/__test__/utils.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,22 @@ export function entry(file: string) {
5050
export function query(q: any) {
5151
return config => {
5252
_.merge(
53-
config.module.loaders.find(loader =>
54-
loader.loader === LOADER).query,
53+
config.module.loaders.find(loader => loader.loader === LOADER).query,
5554
q
5655
);
5756
};
5857
}
5958

59+
export function include(...folders: string[]) {
60+
return config => {
61+
config.module.loaders.find(loader => loader.loader === LOADER).include.push(
62+
...folders.map(f => {
63+
return path.join(process.cwd(), f);
64+
})
65+
);
66+
};
67+
}
68+
6069
export function webpackConfig(...enchance: any[]): webpack.Configuration {
6170
const config = {
6271
entry: { index: path.join(process.cwd(), SRC_DIR, 'index.ts') },
@@ -288,6 +297,10 @@ export function touchFile(fileName: string): Promise<any> {
288297
.then(source => writeFile(fileName, source));
289298
}
290299

300+
export function moveFile(from: string, to: string) {
301+
fs.renameSync(from, to);
302+
}
303+
291304
export function compile(config): Promise<any> {
292305
return new Promise((resolve, reject) => {
293306
const compiler = webpack(config);
@@ -436,6 +449,12 @@ export class Fixture {
436449
touchFile(this.fileName);
437450
}
438451

452+
move(to: string) {
453+
mkdirp.sync(path.dirname(to));
454+
moveFile(this.fileName, to);
455+
this.fileName = to;
456+
}
457+
439458
update(updater: (text: string) => string) {
440459
let newText = updater(this.text);
441460
this.text = newText;

src/__test__/watch-output.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
src, tsconfig, stdout, stderr,
2+
src, tsconfig, stdout,
33
spec, execWebpack
44
} from './utils';
55

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

2323
await webpack.wait(
2424
stdout('Webpack is watching the files…'),
25-
stderr('Checking finished with 1 errors'),
2625
stdout([
2726
'ERROR in [at-loader] ./src/index.ts',
2827
`TS2345: Argument of type '"1"' is not assignable to parameter of type 'number'`

src/checker/fs.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
export interface MapLike<T> {
3+
get(key: string): T | undefined;
4+
has(key: string): boolean;
5+
set(key: string, file: T);
6+
delete(key: string);
7+
forEach<R>(cb: (v: T, key: string) => R);
8+
map<R>(cb: (v: T, key: string) => R): R[];
9+
}
10+
11+
export class CaseSensitiveMap<T> implements MapLike<T> {
12+
private store = new Map<string, T>();
13+
get(key: string) {
14+
return this.store.get(key);
15+
}
16+
delete(key: string) {
17+
return this.store.delete(key);
18+
}
19+
has(key: string) {
20+
return this.store.has(key);
21+
}
22+
set(key: string, file: T) {
23+
return this.store.set(key, file);
24+
}
25+
forEach<R>(cb: (v: T, key: string) => R) {
26+
this.store.forEach(cb);
27+
}
28+
map<R>(cb: (v: T, key: string) => R): R[] {
29+
const res = [] as R[];
30+
this.forEach((v, key) => {
31+
res.push(cb(v, key));
32+
});
33+
34+
return res;
35+
}
36+
}
37+
38+
export class CaseInsensitiveMap<T> implements MapLike<T> {
39+
private store = new Map<string, T>();
40+
get(key: string) {
41+
return this.store.get(key.toLowerCase());
42+
}
43+
delete(key: string) {
44+
return this.store.delete(key.toLowerCase());
45+
}
46+
has(key: string) {
47+
return this.store.has(key.toLowerCase());
48+
}
49+
set(key: string, file: T) {
50+
return this.store.set(key.toLowerCase(), file);
51+
}
52+
forEach<R>(cb: (v: T, key: string) => R) {
53+
this.store.forEach(cb);
54+
}
55+
map<R>(cb: (v: T, key: string) => R): R[] {
56+
const res = [] as R[];
57+
this.forEach((v, key) => {
58+
res.push(cb(v, key));
59+
});
60+
61+
return res;
62+
}
63+
}

src/checker/protocol.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type Req =
2222
UpdateFile.Request |
2323
Diagnostics.Request |
2424
RemoveFile.Request |
25-
Files.Request
25+
Files.Request;
2626

2727
export interface Res {
2828
seq?: number;

0 commit comments

Comments
 (0)