Skip to content

Commit 060fb67

Browse files
committed
Merge branch 'master' of github.com:TypeStrong/fork-ts-checker-webpack-plugin into alpha
2 parents e90c7e4 + cadede8 commit 060fb67

9 files changed

+592
-505
lines changed

src/formatter/WebpackFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { Formatter } from './Formatter';
55
import { formatIssueLocation } from '../issue';
66
import forwardSlash from '../utils/path/forwardSlash';
77

8-
function createWebpackFormatter(formatter: Formatter, context: string): Formatter {
8+
function createWebpackFormatter(formatter: Formatter): Formatter {
99
// mimics webpack error formatter
1010
return function webpackFormatter(issue) {
1111
const color = issue.severity === 'warning' ? chalk.yellow.bold : chalk.red.bold;
1212

1313
const severity = issue.severity.toUpperCase();
1414

1515
if (issue.file) {
16-
let location = forwardSlash(path.relative(context, issue.file));
16+
let location = forwardSlash(path.relative(process.cwd(), issue.file));
1717
if (issue.location) {
1818
location += `:${formatIssueLocation(issue.location)}`;
1919
}

src/hooks/tapDoneToAsyncGetIssues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function tapDoneToAsyncGetIssues(
5858
// modify list of issues in the plugin hooks
5959
issues = hooks.issues.call(issues, stats.compilation);
6060

61-
const formatter = createWebpackFormatter(configuration.formatter, compiler.context);
61+
const formatter = createWebpackFormatter(configuration.formatter);
6262

6363
if (issues.length) {
6464
// follow webpack's approach - one process.write to stderr with all errors and warnings

test/e2e/TypeScriptContextOption.spec.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFixture } from './sandbox/Fixture';
22
import { join } from 'path';
3+
import os from 'os';
34
import { createSandbox, Sandbox } from './sandbox/Sandbox';
45
import {
56
createWebpackDevServerDriver,
@@ -28,7 +29,7 @@ describe('TypeScript Context Option', () => {
2829
{ async: false, typescript: '~3.0.0' },
2930
{ async: true, typescript: '~3.6.0' },
3031
{ async: false, typescript: '~3.8.0' },
31-
])('uses context to resolve project files for %p', async ({ async, typescript }) => {
32+
])('uses context and cwd to resolve project files for %p', async ({ async, typescript }) => {
3233
await sandbox.load([
3334
await readFixture(join(__dirname, 'fixtures/environment/typescript-basic.fixture'), {
3435
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION: JSON.stringify(
@@ -65,13 +66,18 @@ describe('TypeScript Context Option', () => {
6566
exclude: ['node_modules'],
6667
})
6768
);
69+
await sandbox.patch(
70+
'webpack.config.js',
71+
"entry: './src/index.ts',",
72+
"entry: path.resolve(__dirname, './src/index.ts'),"
73+
);
6874
await sandbox.patch(
6975
'webpack.config.js',
7076
' logger: {',
7177
[
7278
' typescript: {',
7379
' enabled: true,',
74-
' configFile: "build/tsconfig.json",',
80+
' configFile: path.resolve(__dirname, "build/tsconfig.json"),',
7581
' context: __dirname,',
7682
' },',
7783
' logger: {',
@@ -82,12 +88,21 @@ describe('TypeScript Context Option', () => {
8288
' transpileOnly: true',
8389
[
8490
' transpileOnly: true,',
85-
' configFile: "build/tsconfig.json",',
91+
' configFile: path.resolve(__dirname, "build/tsconfig.json"),',
8692
' context: __dirname,',
8793
].join('\n')
8894
);
95+
// create additional directory for cwd test
96+
await sandbox.write('foo/.gitignore', '');
8997

90-
const driver = createWebpackDevServerDriver(sandbox.spawn('npm run webpack-dev-server'), async);
98+
const driver = createWebpackDevServerDriver(
99+
sandbox.spawn(
100+
`../node_modules/.bin/webpack-dev-server${os.platform() === 'win32' ? '.cmd' : ''}`,
101+
{},
102+
join(sandbox.context, 'foo')
103+
),
104+
async
105+
);
91106

92107
// first compilation is successful
93108
await driver.waitForNoErrors();
@@ -103,7 +118,7 @@ describe('TypeScript Context Option', () => {
103118
const errors = await driver.waitForErrors();
104119
expect(errors).toEqual([
105120
[
106-
'ERROR in src/model/User.ts:11:16',
121+
'ERROR in ../src/model/User.ts:11:16',
107122
"TS2339: Property 'firstName' does not exist on type 'User'.",
108123
' 9 | ',
109124
' 10 | function getUserName(user: User): string {',
@@ -114,7 +129,7 @@ describe('TypeScript Context Option', () => {
114129
' 14 | }',
115130
].join('\n'),
116131
[
117-
'ERROR in src/model/User.ts:11:32',
132+
'ERROR in ../src/model/User.ts:11:32',
118133
"TS2339: Property 'lastName' does not exist on type 'User'.",
119134
' 9 | ',
120135
' 10 | function getUserName(user: User): string {',

0 commit comments

Comments
 (0)