Skip to content

Commit

Permalink
fix: remove references to external typings (#422)
Browse files Browse the repository at this point in the history
Fixes E2E test to ensure that the package typings can be consumed without need to install external packages except `@types/webpack`.

✅ Solves: #339
  • Loading branch information
piotr-oles committed May 26, 2020
1 parent cfcc0fe commit f277444
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 62 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -349,6 +349,20 @@ hooks.waiting.tap('yourListenerName', () => {
});
```

## Typings

To use the plugin typings, you have to install `@types/webpack`. It's not included by default to not collide with your
existing typings (`@types/webpack` imports `@types/node`). [It's an old TypeScript issue](https://github.com/microsoft/TypeScript/issues/18588),
the alternative is to set `skipLibCheck: true` in the `compilerOptions` 😉
```sh
# with npm
npm install --save-dev @types/webpack

# with yarn
yarn add --dev @types/webpack
```


## Related projects

* [`ts-loader`](https://github.com/TypeStrong/ts-loader) - TypeScript loader for webpack.
Expand Down
@@ -1,13 +1,14 @@
import os from 'os';
import fs from 'fs-extra';
import { codeFrameColumns, BabelCodeFrameOptions } from '@babel/code-frame';
import { codeFrameColumns } from '@babel/code-frame';
import { Formatter } from './Formatter';
import { createBasicFormatter } from './BasicFormatter';
import { BabelCodeFrameOptions } from './types/babel__code-frame';

function createCodeframeFormatter(options?: BabelCodeFrameOptions): Formatter {
function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter {
const basicFormatter = createBasicFormatter();

return function codeframeFormatter(issue) {
return function codeFrameFormatter(issue) {
const source = issue.file && fs.existsSync(issue.file) && fs.readFileSync(issue.file, 'utf-8');

let frame = '';
Expand All @@ -30,4 +31,4 @@ function createCodeframeFormatter(options?: BabelCodeFrameOptions): Formatter {
};
}

export { createCodeframeFormatter, BabelCodeFrameOptions };
export { createCodeFrameFormatter, BabelCodeFrameOptions };
4 changes: 2 additions & 2 deletions src/formatter/FormatterFactory.ts
@@ -1,5 +1,5 @@
import { Formatter } from './Formatter';
import { BabelCodeFrameOptions, createCodeframeFormatter } from './CodeframeFormatter';
import { BabelCodeFrameOptions, createCodeFrameFormatter } from './CodeFrameFormatter';
import { createBasicFormatter } from './BasicFormatter';

type NotConfigurableFormatterType = undefined | 'basic';
Expand Down Expand Up @@ -31,7 +31,7 @@ function createFormatter(type?: FormatterType, options?: object): Formatter {
return createBasicFormatter();

case 'codeframe':
return createCodeframeFormatter(options);
return createCodeFrameFormatter(options);

default:
throw new Error(`Unknown "${type}" formatter. Available types are: basic, codeframe.`);
Expand Down
2 changes: 1 addition & 1 deletion src/formatter/index.ts
@@ -1,6 +1,6 @@
export * from './Formatter';
export * from './BasicFormatter';
export * from './CodeframeFormatter';
export * from './CodeFrameFormatter';
export * from './WebpackFormatter';
export * from './FormatterFactory';
export * from './FormatterOptions';
Expand Down
27 changes: 27 additions & 0 deletions src/formatter/types/babel__code-frame.ts
@@ -0,0 +1,27 @@
// Base on the type definitions for @babel/code-frame 7.0
// Project: https://github.com/babel/babel/tree/master/packages/babel-code-frame, https://babeljs.io
// Definitions by: Mohsen Azimi <https://github.com/mohsen1>
// Forbes Lindesay <https://github.com/ForbesLindesay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export interface BabelCodeFrameOptions {
/** Syntax highlight the code as JavaScript for terminals. default: false */
highlightCode?: boolean;
/** The number of lines to show above the error. default: 2 */
linesAbove?: number;
/** The number of lines to show below the error. default: 3 */
linesBelow?: number;
/**
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
* overrides highlightCode.
* default: false
*/
forceColor?: boolean;
/**
* Pass in a string to be displayed inline (if possible) next to the
* highlighted location in the code. If it can't be positioned inline,
* it will be placed above the code frame.
* default: nothing
*/
message?: string;
}
47 changes: 0 additions & 47 deletions src/types/eslint.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/typescript-reporter/reporter/PassiveFileSystem.ts
@@ -1,6 +1,8 @@
import { dirname, basename, join, normalize } from 'path';
import fs, { Stats, Dirent } from 'fs-extra';
import fs from 'fs-extra';
import { fs as mem } from 'memfs';
// eslint-disable-next-line node/no-unsupported-features/node-builtins
import { Stats, Dirent } from 'fs';

interface PassiveFileSystem {
// read
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/fixtures/type-definitions.fixture
Expand Up @@ -8,6 +8,7 @@
"tsc": "tsc"
},
"devDependencies": {
"@types/webpack": "^4.0.0",
"fork-ts-checker-webpack-plugin": ${FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION},
"typescript": "~3.8.0"
}
Expand All @@ -21,8 +22,8 @@
"lib": ["ES6", "DOM"],
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"skipLibCheck": false,
"skipDefaultLibCheck": false,
"strict": true,
"baseUrl": "./"
},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/eslint-reporter/issue/EsLintIssueFactory.spec.ts
@@ -1,4 +1,4 @@
import { LintMessage, LintResult } from '../../../../lib/types/eslint';
import { LintMessage, LintResult } from '../../../../lib/eslint-reporter/types/eslint';
import { createIssuesFromEsLintResults } from '../../../../lib/eslint-reporter/issue/EsLintIssueFactory';

describe('eslint-reporter/issue/EsLintIssueFactory', () => {
Expand Down
@@ -1,9 +1,9 @@
import * as os from 'os';
import mockFs from 'mock-fs';
import { Issue } from 'lib/issue';
import { createCodeframeFormatter } from 'lib/formatter';
import { createCodeFrameFormatter } from 'lib/formatter';

describe('formatter/CodeframeFormatter', () => {
describe('formatter/CodeFrameFormatter', () => {
beforeEach(() => {
mockFs({
src: {
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('formatter/CodeframeFormatter', () => {
],
])('formats issue message "%p" to "%p"', (...args) => {
const [issue, expectedFormatted] = args as [Issue, string];
const formatter = createCodeframeFormatter({
const formatter = createCodeFrameFormatter({
linesAbove: 1,
linesBelow: 1,
});
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -11,7 +11,8 @@
"strict": true,
"declaration": true,
"baseUrl": "./src",
"outDir": "./lib"
"outDir": "./lib",
"forceConsistentCasingInFileNames": true
},
"include": ["./src"],
"exclude": ["node_modules", "test", "lib"]
Expand Down

0 comments on commit f277444

Please sign in to comment.