Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' :
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -465,7 +476,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): {
pushArray(compilation.errors, formatErrors(errors, instance, {file: filePath}));
}
});

callback();
});

Expand Down Expand Up @@ -526,13 +537,13 @@ function loader(contents) {
if (!file) {
file = instance.files[filePath] = <TSFile>{ version: 0 };
}

if (file.text !== contents) {
file.version++;
file.text = contents;
instance.version++;
}

var outputText: string, sourceMapText: string, diagnostics: typescript.Diagnostic[] = [];

if (options.transpileOnly) {
Expand All @@ -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);
Expand All @@ -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); }
}
Expand Down
Empty file added test/tsconfigInvalidFile/app.ts
Empty file.
50 changes: 50 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.6/bundle.transpiled.js
Original file line number Diff line number Diff line change
@@ -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) {



/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 3 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.6/output.txt
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.7/bundle.transpiled.js
Original file line number Diff line number Diff line change
@@ -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) {



/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 3 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.7/output.txt
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.8/bundle.transpiled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/******/ (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) {

"use strict";


/***/ }
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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]
3 changes: 3 additions & 0 deletions test/tsconfigInvalidFile/expectedOutput-1.8/output.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/tsconfigInvalidFile/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"sourceMap": true
},
"files": [
"i-am-a-file-what-does-not-exist.ts",
"app.ts"
]
}
17 changes: 17 additions & 0 deletions test/tsconfigInvalidFile/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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") } }