From 6af81a196a74cecd31bca05188d2033a2d22156b Mon Sep 17 00:00:00 2001 From: John Reilly Date: Sun, 24 Jan 2016 20:28:03 +0000 Subject: [PATCH 1/3] Make invalid files in tsconfig.json super obvious when ts-loader errors --- index.ts | 41 +++++++++------ test/tsconfigInvalidFile/app.ts | 0 .../expectedOutput-1.6/output.txt | 3 ++ .../expectedOutput-1.7/bundle.transpiled.js | 50 +++++++++++++++++++ .../expectedOutput-1.7/output.transpiled.txt | 4 ++ .../expectedOutput-1.7/output.txt | 3 ++ .../expectedOutput-1.8/output.txt | 3 ++ test/tsconfigInvalidFile/tsconfig.json | 9 ++++ test/tsconfigInvalidFile/webpack.config.js | 17 +++++++ 9 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 test/tsconfigInvalidFile/app.ts create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.6/output.txt create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.7/bundle.transpiled.js create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.7/output.transpiled.txt create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.7/output.txt create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.8/output.txt create mode 100644 test/tsconfigInvalidFile/tsconfig.json create mode 100644 test/tsconfigInvalidFile/webpack.config.js diff --git a/index.ts b/index.ts index d4bb38fc1..be2b7630f 100644 --- a/index.ts +++ b/index.ts @@ -297,13 +297,24 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { } // Load initial files (core lib files, any files specified in tsconfig.json) - filesToLoad.forEach(filePath => { - filePath = path.normalize(filePath); - files[filePath] = { - text: fs.readFileSync(filePath, 'utf-8'), - version: 0 - } - }); + let filePath: string; + try { + filesToLoad.forEach(fp => { + filePath = path.normalize(fp); + files[filePath] = { + text: fs.readFileSync(filePath, 'utf-8'), + version: 0 + }; + }); + } + catch (exc) { + let filePathError = `A file specified in tsconfig.json could not be found: ${ filePath }`; + return { error: { + message: filePathError.red, + rawMessage: filePathError, + loaderSource: 'ts-loader' + }}; + } let newLine = compilerOptions.newLine === 0 /* CarriageReturnLineFeed */ ? '\r\n' : @@ -341,11 +352,11 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { // We either load from memory or from disk fileName = path.normalize(fileName); var file = files[fileName]; - + if (!file) { let text = readFile(fileName); if (text == null) return; - + file = files[fileName] = { version: 0, text } } @@ -465,7 +476,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { pushArray(compilation.errors, formatErrors(errors, instance, {file: filePath})); } }); - + callback(); }); @@ -526,13 +537,13 @@ function loader(contents) { if (!file) { file = instance.files[filePath] = { version: 0 }; } - + if (file.text !== contents) { file.version++; file.text = contents; instance.version++; } - + var outputText: string, sourceMapText: string, diagnostics: typescript.Diagnostic[] = []; if (options.transpileOnly) { @@ -549,11 +560,11 @@ function loader(contents) { } else { let langService = instance.languageService; - + // Make this file dependent on *all* definition files in the program this.clearDependencies(); this.addDependency(filePath); - + let allDefinitionFiles = Object.keys(instance.files).filter(filePath => /\.d\.ts$/.test(filePath)); allDefinitionFiles.forEach(this.addDependency.bind(this)); this._module.meta.tsLoaderDefinitionFileVersions = allDefinitionFiles.map(filePath => filePath+'@'+instance.files[filePath].version); @@ -566,7 +577,7 @@ function loader(contents) { var sourceMapFile = output.outputFiles.filter(file => !!file.name.match(/\.js(x?)\.map$/)).pop(); if (sourceMapFile) { sourceMapText = sourceMapFile.text } - + var declarationFile = output.outputFiles.filter(file => !!file.name.match(/\.d.ts$/)).pop(); if (declarationFile) { this.emitFile(path.relative(this.options.context, declarationFile.name), declarationFile.text); } } diff --git a/test/tsconfigInvalidFile/app.ts b/test/tsconfigInvalidFile/app.ts new file mode 100644 index 000000000..e69de29bb diff --git a/test/tsconfigInvalidFile/expectedOutput-1.6/output.txt b/test/tsconfigInvalidFile/expectedOutput-1.6/output.txt new file mode 100644 index 000000000..32c729263 --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.6/output.txt @@ -0,0 +1,3 @@ + +ERROR in ./.test/tsconfigInvalidFile/app.ts +Module build failed: A file specified in tsconfig.json could not be found: i-am-a-file-what-does-not-exist.ts \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.7/bundle.transpiled.js b/test/tsconfigInvalidFile/expectedOutput-1.7/bundle.transpiled.js new file mode 100644 index 000000000..53daa020b --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.7/bundle.transpiled.js @@ -0,0 +1,50 @@ +/******/ (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] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = 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; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports) { + + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.7/output.transpiled.txt b/test/tsconfigInvalidFile/expectedOutput-1.7/output.transpiled.txt new file mode 100644 index 000000000..d47d7531c --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.7/output.transpiled.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 1.39 kB 0 [emitted] main +chunk {0} bundle.js (main) 0 bytes [rendered] + [0] ./.test/tsconfigInvalidFile/app.ts 0 bytes {0} [built] \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.7/output.txt b/test/tsconfigInvalidFile/expectedOutput-1.7/output.txt new file mode 100644 index 000000000..32c729263 --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.7/output.txt @@ -0,0 +1,3 @@ + +ERROR in ./.test/tsconfigInvalidFile/app.ts +Module build failed: A file specified in tsconfig.json could not be found: i-am-a-file-what-does-not-exist.ts \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.8/output.txt b/test/tsconfigInvalidFile/expectedOutput-1.8/output.txt new file mode 100644 index 000000000..32c729263 --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.8/output.txt @@ -0,0 +1,3 @@ + +ERROR in ./.test/tsconfigInvalidFile/app.ts +Module build failed: A file specified in tsconfig.json could not be found: i-am-a-file-what-does-not-exist.ts \ No newline at end of file diff --git a/test/tsconfigInvalidFile/tsconfig.json b/test/tsconfigInvalidFile/tsconfig.json new file mode 100644 index 000000000..835172124 --- /dev/null +++ b/test/tsconfigInvalidFile/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "sourceMap": true + }, + "files": [ + "i-am-a-file-what-does-not-exist.ts", + "app.ts" + ] +} diff --git a/test/tsconfigInvalidFile/webpack.config.js b/test/tsconfigInvalidFile/webpack.config.js new file mode 100644 index 000000000..aae026d84 --- /dev/null +++ b/test/tsconfigInvalidFile/webpack.config.js @@ -0,0 +1,17 @@ +module.exports = { + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['', '.ts', '.js'] + }, + module: { + loaders: [ + { test: /\.ts$/, loader: 'ts-loader' } + ] + } +} + +// for test harness purposes only, you would not need this in a normal project +module.exports.resolveLoader = { alias: { 'ts-loader': require('path').join(__dirname, "../../index.js") } } \ No newline at end of file From d4b85fcbbd4b10ada4bdd4559e87c66799f3d8ec Mon Sep 17 00:00:00 2001 From: John Reilly Date: Sun, 24 Jan 2016 20:49:28 +0000 Subject: [PATCH 2/3] Added test results for ts 1.6 & 1.8 --- .../expectedOutput-1.6/bundle.transpiled.js | 50 +++++++++++++++++++ .../expectedOutput-1.6/output.transpiled.txt | 4 ++ .../expectedOutput-1.8/bundle.transpiled.js | 50 +++++++++++++++++++ .../expectedOutput-1.8/output.transpiled.txt | 4 ++ 4 files changed, 108 insertions(+) create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.6/bundle.transpiled.js create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.6/output.transpiled.txt create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js create mode 100644 test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt diff --git a/test/tsconfigInvalidFile/expectedOutput-1.6/bundle.transpiled.js b/test/tsconfigInvalidFile/expectedOutput-1.6/bundle.transpiled.js new file mode 100644 index 000000000..53daa020b --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.6/bundle.transpiled.js @@ -0,0 +1,50 @@ +/******/ (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] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = 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; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports) { + + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.6/output.transpiled.txt b/test/tsconfigInvalidFile/expectedOutput-1.6/output.transpiled.txt new file mode 100644 index 000000000..d47d7531c --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.6/output.transpiled.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 1.39 kB 0 [emitted] main +chunk {0} bundle.js (main) 0 bytes [rendered] + [0] ./.test/tsconfigInvalidFile/app.ts 0 bytes {0} [built] \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js b/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js new file mode 100644 index 000000000..53daa020b --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js @@ -0,0 +1,50 @@ +/******/ (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] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = 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; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports) { + + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt b/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt new file mode 100644 index 000000000..d47d7531c --- /dev/null +++ b/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt @@ -0,0 +1,4 @@ + Asset Size Chunks Chunk Names +bundle.js 1.39 kB 0 [emitted] main +chunk {0} bundle.js (main) 0 bytes [rendered] + [0] ./.test/tsconfigInvalidFile/app.ts 0 bytes {0} [built] \ No newline at end of file From 3361f8d1d993191356d332f72705bb81e152c006 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Mon, 25 Jan 2016 20:47:19 +0000 Subject: [PATCH 3/3] "use strict" your way to glory --- .../expectedOutput-1.8/bundle.transpiled.js | 3 ++- .../expectedOutput-1.8/output.transpiled.txt | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js b/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js index 53daa020b..5650b52eb 100644 --- a/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js +++ b/test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js @@ -44,7 +44,8 @@ /* 0 */ /***/ function(module, exports) { - + "use strict"; + /***/ } /******/ ]); \ No newline at end of file diff --git a/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt b/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt index d47d7531c..04ed019a5 100644 --- a/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt +++ b/test/tsconfigInvalidFile/expectedOutput-1.8/output.transpiled.txt @@ -1,4 +1,4 @@ - Asset Size Chunks Chunk Names -bundle.js 1.39 kB 0 [emitted] main -chunk {0} bundle.js (main) 0 bytes [rendered] - [0] ./.test/tsconfigInvalidFile/app.ts 0 bytes {0} [built] \ No newline at end of file + Asset Size Chunks Chunk Names +bundle.js 1.4 kB 0 [emitted] main +chunk {0} bundle.js (main) 14 bytes [rendered] + [0] ./.test/tsconfigInvalidFile/app.ts 14 bytes {0} [built] \ No newline at end of file