Skip to content

Commit

Permalink
initial implementation of reportFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
freeman committed Dec 23, 2017
1 parent c633381 commit 2dae882
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 10 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
"chalk": "^2.3.0",
"enhanced-resolve": "^3.0.0",
"loader-utils": "^1.0.2",
"micromatch": "^3.1.4",
"semver": "^5.0.1"
},
"devDependencies": {
"@types/micromatch": "^3.1.0",
"@types/semver": "^5.4.0",
"babel": "^6.0.0",
"babel-core": "^6.0.0",
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function getLoaderOptions(loader: Webpack) {
}

type ValidLoaderOptions = keyof LoaderOptions;
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'contextAsConfigBasePath', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers'];
const validLoaderOptions: ValidLoaderOptions[] = ['silent', 'logLevel', 'logInfoToStdOut', 'instance', 'compiler', 'contextAsConfigBasePath', 'configFile', 'transpileOnly', 'ignoreDiagnostics', 'errorFormatter', 'colors', 'compilerOptions', 'appendTsSuffixTo', 'appendTsxSuffixTo', 'entryFileCannotBeJs' /* DEPRECATED */, 'onlyCompileBundledFiles', 'happyPackMode', 'getCustomTransformers', 'reportFiles'];

/**
* Validate the supplied loader options.
Expand Down Expand Up @@ -148,7 +148,8 @@ function makeLoaderOptions(instanceName: string, configFileOptions: Partial<Load
entryFileCannotBeJs: false,
happyPackMode: false,
colors: true,
onlyCompileBundledFiles: false
onlyCompileBundledFiles: false,
reportFiles: []
} as Partial<LoaderOptions>, configFileOptions, loaderOptions);

options.ignoreDiagnostics = arrify(options.ignoreDiagnostics).map(Number);
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export interface LoaderOptions {
contextAsConfigBasePath: boolean;
transpileOnly: boolean;
ignoreDiagnostics: number[];
reportFiles: string[];
errorFormatter: (message: ErrorInfo, colors: Chalk) => string;
onlyCompileBundledFiles: boolean;
colors: boolean;
Expand Down
12 changes: 11 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as typescript from 'typescript';
import * as path from 'path';
import * as fs from 'fs';
import { Chalk } from 'chalk';
import * as micromatch from 'micromatch';

import constants = require('./constants');
import {
Expand Down Expand Up @@ -49,12 +50,21 @@ export function formatErrors(
loaderOptions: LoaderOptions,
colors: Chalk,
compiler: typeof typescript,
merge?: { file?: string; module?: WebpackModule }
merge: { file?: string; module?: WebpackModule }
): WebpackError[] {

return diagnostics
? diagnostics
.filter(diagnostic => loaderOptions.ignoreDiagnostics.indexOf(diagnostic.code) === -1)
.filter(diagnostic => {
if (loaderOptions.reportFiles.length === 0
|| diagnostic.file === undefined) {
return true;
}
const fileName = diagnostic.file.fileName;
const matchResult = micromatch([fileName], loaderOptions.reportFiles);
return matchResult.length > 0;
})
.map<WebpackError>(diagnostic => {
const file = diagnostic.file;
const position = file === undefined ? undefined : file.getLineAndCharacterOfPosition(diagnostic.start!);
Expand Down
3 changes: 3 additions & 0 deletions test/comparison-tests/reportFiles/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './skip';
export let a: number
a = '10'
88 changes: 88 additions & 0 deletions test/comparison-tests/reportFiles/expectedOutput-2.6/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

exports.__esModule = true;
__webpack_require__(1);
exports.a = '10';


/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

exports.__esModule = true;
exports.a = '10';


/***/ })
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Asset Size Chunks Chunk Names
bundle.js 2.71 kB 0 [emitted] main
[0] ./.test/reportFiles/app.ts 78 bytes {0} [built]
[1] ./.test/reportFiles/skip.ts 59 bytes {0} [built]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Asset Size Chunks Chunk Names
bundle.js 2.71 kB 0 [emitted] main
[0] ./.test/reportFiles/app.ts 78 bytes {0} [built] [1 error]
[1] ./.test/reportFiles/skip.ts 59 bytes {0} [built]

ERROR in ./.test/reportFiles/app.ts
[tsl] ERROR in app.ts(3,1)
 TS2322: Type '"10"' is not assignable to type 'number'.
2 changes: 2 additions & 0 deletions test/comparison-tests/reportFiles/skip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export let a: number
a = '10'
4 changes: 4 additions & 0 deletions test/comparison-tests/reportFiles/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compilerOptions": {
}
}
18 changes: 18 additions & 0 deletions test/comparison-tests/reportFiles/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
entry: './app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['.ts', 'tsx', '.js']
},
module: {
rules: [
{
test: /\.tsx?$/, loader: 'ts-loader', options: {
reportFiles: [ '/**/.test/**/app.ts' ]
}
}
]
}
}
Loading

0 comments on commit 2dae882

Please sign in to comment.