Skip to content

Commit

Permalink
refactor: rename files to match convention (#693)
Browse files Browse the repository at this point in the history
I found snake-case easier to read, and given that
the project doesn't use OOP a lot, having all PascalCase
names doesn't reflect the paradigm and feels unnatural.
  • Loading branch information
piotr-oles committed Jan 22, 2022
1 parent f7dfdcf commit 39ebae6
Show file tree
Hide file tree
Showing 107 changed files with 499 additions and 412 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[]

| Name | Type | Default value | Description |
| --------- | ------------- | ------------- | ----------- |
| `include` | `IssueFilter` | `undefined` | If `object`, defines issue properties that should be [matched](./src/issue/IssueMatch.ts). If `function`, acts as a predicate where `issue` is an argument. |
| `include` | `IssueFilter` | `undefined` | If `object`, defines issue properties that should be [matched](src/issue/issue-match.ts). If `function`, acts as a predicate where `issue` is an argument. |
| `exclude` | `IssueFilter` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |

<details>
Expand Down
3 changes: 1 addition & 2 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module.exports = {
[
'@semantic-release/exec',
{
prepareCmd:
"sed -i 's/{{VERSION}}/${nextRelease.version}/g' lib/ForkTsCheckerWebpackPlugin.js",
prepareCmd: "sed -i 's/{{VERSION}}/${nextRelease.version}/g' lib/plugin.js",
},
],
],
Expand Down
34 changes: 0 additions & 34 deletions src/ForkTsCheckerWebpackPluginConfiguration.ts

This file was deleted.

44 changes: 28 additions & 16 deletions src/files-change.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type * as webpack from 'webpack';

import subtract from './utils/array/substract';
import unique from './utils/array/unique';

interface FilesChange {
changedFiles?: string[];
deletedFiles?: string[];
Expand All @@ -14,6 +11,12 @@ function getFilesChange(compiler: webpack.Compiler): FilesChange {
return compilerFilesChangeMap.get(compiler) || { changedFiles: [], deletedFiles: [] };
}

function consumeFilesChange(compiler: webpack.Compiler): FilesChange {
const change = getFilesChange(compiler);
clearFilesChange(compiler);
return change;
}

function updateFilesChange(compiler: webpack.Compiler, change: FilesChange): void {
compilerFilesChangeMap.set(compiler, aggregateFilesChanges([getFilesChange(compiler), change]));
}
Expand All @@ -29,22 +32,31 @@ function clearFilesChange(compiler: webpack.Compiler): void {
* @returns Files change that represents all subsequent changes as a one event
*/
function aggregateFilesChanges(changes: FilesChange[]): FilesChange {
let changedFiles: string[] = [];
let deletedFiles: string[] = [];

for (const change of changes) {
changedFiles = unique(
subtract(changedFiles, change.deletedFiles).concat(change.changedFiles || [])
);
deletedFiles = unique(
subtract(deletedFiles, change.changedFiles).concat(change.deletedFiles || [])
);
const changedFilesSet = new Set<string>();
const deletedFilesSet = new Set<string>();

for (const { changedFiles = [], deletedFiles = [] } of changes) {
for (const changedFile of changedFiles) {
changedFilesSet.add(changedFile);
deletedFilesSet.delete(changedFile);
}
for (const deletedFile of deletedFiles) {
changedFilesSet.delete(deletedFile);
deletedFilesSet.add(deletedFile);
}
}

return {
changedFiles,
deletedFiles,
changedFiles: Array.from(changedFilesSet),
deletedFiles: Array.from(deletedFilesSet),
};
}

export { FilesChange, getFilesChange, updateFilesChange, clearFilesChange, aggregateFilesChanges };
export {
FilesChange,
getFilesChange,
consumeFilesChange,
updateFilesChange,
clearFilesChange,
aggregateFilesChanges,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk';

import type { Formatter } from './Formatter';
import type { Formatter } from './formatter';

function createBasicFormatter(): Formatter {
return function basicFormatter(issue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import os from 'os';
import { codeFrameColumns } from '@babel/code-frame';
import fs from 'fs-extra';

import { createBasicFormatter } from './BasicFormatter';
import type { Formatter } from './Formatter';
import { createBasicFormatter } from './basic-formatter';
import type { Formatter } from './formatter';
import { BabelCodeFrameOptions } from './types/babel__code-frame';

function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { createBasicFormatter } from './BasicFormatter';
import { createCodeFrameFormatter } from './CodeFrameFormatter';
import type { Formatter } from './Formatter';
import type { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';
import { createBasicFormatter } from './basic-formatter';
import { createCodeFrameFormatter } from './code-frame-formatter';
import type { Formatter } from './formatter';
import type { CodeframeFormatterOptions, FormatterOptions } from './formatter-options';

type FormatterConfiguration = Formatter;
type FormatterConfig = Formatter;

function createFormatterConfiguration(
options: FormatterOptions | undefined
): FormatterConfiguration {
function createFormatterConfig(options: FormatterOptions | undefined): FormatterConfig {
if (typeof options === 'function') {
return options;
}
Expand All @@ -23,16 +21,16 @@ function createFormatterConfiguration(
}

if (type === 'codeframe') {
const configuration =
const config =
options && typeof options === 'object'
? (options as CodeframeFormatterOptions).options || {}
: {};
return createCodeFrameFormatter(configuration);
return createCodeFrameFormatter(config);
}

throw new Error(
`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`
);
}

export { FormatterConfiguration, createFormatterConfiguration };
export { FormatterConfig, createFormatterConfig };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Formatter } from './Formatter';
import type { Formatter } from './formatter';
import type { BabelCodeFrameOptions } from './types/babel__code-frame';

type FormatterType = 'basic' | 'codeframe';
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/formatter/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './Formatter';
export * from './BasicFormatter';
export * from './CodeFrameFormatter';
export * from './WebpackFormatter';
export * from './FormatterOptions';
export * from './FormatterConfiguration';
export * from './formatter';
export * from './basic-formatter';
export * from './code-frame-formatter';
export * from './webpack-formatter';
export * from './formatter-options';
export * from './formatter-config';
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import os from 'os';
import chalk from 'chalk';

import { formatIssueLocation } from '../issue';
import { relativeToContext } from '../utils/path/relativeToContext';
import { relativeToContext } from '../utils/path/relative-to-context';

import type { Formatter } from './Formatter';
import type { Formatter } from './formatter';

function createWebpackFormatter(formatter: Formatter): Formatter {
// mimics webpack error formatter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getInfrastructureLogger } from '../infrastructure-logger';
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';

function interceptDoneToGetWebpackDevServerTap(
function interceptDoneToGetDevServerTap(
compiler: webpack.Compiler,
configuration: ForkTsCheckerWebpackPluginConfiguration,
config: ForkTsCheckerWebpackPluginConfig,
state: ForkTsCheckerWebpackPluginState
) {
const { debug } = getInfrastructureLogger(compiler);

// inspired by https://github.com/ypresto/fork-ts-checker-async-overlay-webpack-plugin
compiler.hooks.done.intercept({
register: (tap) => {
if (
tap.name === 'webpack-dev-server' &&
tap.type === 'sync' &&
configuration.logger.devServer
) {
if (tap.name === 'webpack-dev-server' && tap.type === 'sync' && config.logger.devServer) {
debug('Intercepting webpack-dev-server tap.');
state.webpackDevServerDoneTap = tap;
}
Expand All @@ -27,4 +23,4 @@ function interceptDoneToGetWebpackDevServerTap(
});
}

export { interceptDoneToGetWebpackDevServerTap };
export { interceptDoneToGetDevServerTap };
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getInfrastructureLogger } from '../infrastructure-logger';
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';

function tapAfterCompileToAddDependencies(
compiler: webpack.Compiler,
configuration: ForkTsCheckerWebpackPluginConfiguration,
config: ForkTsCheckerWebpackPluginConfig,
state: ForkTsCheckerWebpackPluginState
) {
const { debug } = getInfrastructureLogger(compiler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getInfrastructureLogger } from '../infrastructure-logger';
import type { Issue } from '../issue';
import { IssueWebpackError } from '../issue/IssueWebpackError';

import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
import { IssueWebpackError } from '../issue/issue-webpack-error';
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
import { getPluginHooks } from '../plugin-hooks';
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';

function tapAfterCompileToGetIssues(
compiler: webpack.Compiler,
configuration: ForkTsCheckerWebpackPluginConfiguration,
config: ForkTsCheckerWebpackPluginConfig,
state: ForkTsCheckerWebpackPluginState
) {
const hooks = getForkTsCheckerWebpackPluginHooks(compiler);
const hooks = getPluginHooks(compiler);
const { debug } = getInfrastructureLogger(compiler);

compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', async (compilation) => {
Expand All @@ -39,13 +38,13 @@ function tapAfterCompileToGetIssues(
}

// filter list of issues by provided issue predicate
issues = issues.filter(configuration.issue.predicate);
issues = issues.filter(config.issue.predicate);

// modify list of issues in the plugin hooks
issues = hooks.issues.call(issues, compilation);

issues.forEach((issue) => {
const error = new IssueWebpackError(configuration.formatter(issue), issue);
const error = new IssueWebpackError(config.formatter(issue), issue);

if (issue.severity === 'warning') {
compilation.warnings.push(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { getInfrastructureLogger } from '../infrastructure-logger';
import { InclusiveNodeWatchFileSystem } from '../watch/InclusiveNodeWatchFileSystem';
import type { WatchFileSystem } from '../watch/WatchFileSystem';
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
import { InclusiveNodeWatchFileSystem } from '../watch/inclusive-node-watch-file-system';
import type { WatchFileSystem } from '../watch/watch-file-system';

function tapAfterEnvironmentToPatchWatching(
compiler: webpack.Compiler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import chalk from 'chalk';
import type webpack from 'webpack';

import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
import { createWebpackFormatter } from '../formatter/WebpackFormatter';
import { createWebpackFormatter } from '../formatter/webpack-formatter';
import { getInfrastructureLogger } from '../infrastructure-logger';
import type { Issue } from '../issue';
import { IssueWebpackError } from '../issue/IssueWebpackError';
import isPending from '../utils/async/isPending';
import wait from '../utils/async/wait';

import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
import { IssueWebpackError } from '../issue/issue-webpack-error';
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
import { getPluginHooks } from '../plugin-hooks';
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
import { isPending } from '../utils/async/is-pending';
import { wait } from '../utils/async/wait';

function tapDoneToAsyncGetIssues(
compiler: webpack.Compiler,
configuration: ForkTsCheckerWebpackPluginConfiguration,
config: ForkTsCheckerWebpackPluginConfig,
state: ForkTsCheckerWebpackPluginState
) {
const hooks = getForkTsCheckerWebpackPluginHooks(compiler);
const hooks = getPluginHooks(compiler);
const { log, debug } = getInfrastructureLogger(compiler);

compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', async (stats) => {
Expand All @@ -32,7 +31,7 @@ function tapDoneToAsyncGetIssues(
try {
if (await isPending(issuesPromise)) {
hooks.waiting.call(stats.compilation);
configuration.logger.issues.log(chalk.cyan('Issues checking in progress...'));
config.logger.issues.log(chalk.cyan('Issues checking in progress...'));
} else {
// wait 10ms to log issues after webpack stats
await wait(10);
Expand All @@ -51,25 +50,25 @@ function tapDoneToAsyncGetIssues(
}

// filter list of issues by provided issue predicate
issues = issues.filter(configuration.issue.predicate);
issues = issues.filter(config.issue.predicate);

// modify list of issues in the plugin hooks
issues = hooks.issues.call(issues, stats.compilation);

const formatter = createWebpackFormatter(configuration.formatter);
const formatter = createWebpackFormatter(config.formatter);

if (issues.length) {
// follow webpack's approach - one process.write to stderr with all errors and warnings
configuration.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
config.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
} else {
configuration.logger.issues.log(chalk.green('No issues found.'));
config.logger.issues.log(chalk.green('No issues found.'));
}

// report issues to webpack-dev-server, if it's listening
// skip reporting if there are no issues, to avoid an extra hot reload
if (issues.length && state.webpackDevServerDoneTap) {
issues.forEach((issue) => {
const error = new IssueWebpackError(configuration.formatter(issue), issue);
const error = new IssueWebpackError(config.formatter(issue), issue);

if (issue.severity === 'warning') {
stats.compilation.warnings.push(error);
Expand Down
Loading

0 comments on commit 39ebae6

Please sign in to comment.