diff --git a/index.ts b/index.ts index c185b01a7..e90326379 100644 --- a/index.ts +++ b/index.ts @@ -47,6 +47,7 @@ interface TSInstance { loaderOptions: LoaderOptions; files: TSFiles; languageService?: typescript.LanguageService; + version?: number; } interface TSInstances { @@ -188,7 +189,8 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { compilerOptions: null, loaderOptions, files, - languageService: null + languageService: null, + version: 0 }; var compilerOptions: typescript.CompilerOptions = { @@ -323,6 +325,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { // Create the TypeScript language service var servicesHost = { + getProjectVersion: () => instance.version+'', getScriptFileNames: () => Object.keys(files).filter(filePath => scriptRegex.test(filePath)), getScriptVersion: fileName => { fileName = path.normalize(fileName); @@ -387,7 +390,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { var languageService = instance.languageService = compiler.createLanguageService(servicesHost, compiler.createDocumentRegistry()); - var compilerOptionDiagnostics = languageService.getCompilerOptionsDiagnostics(); + var getCompilerOptionDiagnostics = true; loader._compiler.plugin("after-compile", (compilation, callback) => { let stats = compilation.stats; @@ -411,10 +414,12 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { removeTSLoaderErrors(compilation.errors); // handle compiler option errors after the first compile - pushArray( - compilation.errors, - formatErrors(compilerOptionDiagnostics, instance, {file: configFilePath || 'tsconfig.json'})); - compilerOptionDiagnostics = []; + if (getCompilerOptionDiagnostics) { + getCompilerOptionDiagnostics = false; + pushArray( + compilation.errors, + formatErrors(languageService.getCompilerOptionsDiagnostics(), instance, {file: configFilePath || 'tsconfig.json'})); + } // build map of all modules based on normalized filename // this is used for quick-lookup when trying to find modules @@ -460,7 +465,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { pushArray(compilation.errors, formatErrors(errors, instance, {file: filePath})); } }); - + callback(); }); @@ -475,6 +480,7 @@ function ensureTypeScriptInstance(loaderOptions: LoaderOptions, loader: any): { if (file) { file.text = fs.readFileSync(filePath, {encoding: 'utf8'}); file.version++; + instance.version++; } }); cb() @@ -515,13 +521,18 @@ function loader(contents) { return; } - // Update file version + // Update file contents var file = instance.files[filePath] if (!file) { file = instance.files[filePath] = { version: 0 }; } - file.version++; - + + if (file.text !== contents) { + file.version++; + file.text = contents; + instance.version++; + } + var outputText: string, sourceMapText: string, diagnostics: typescript.Diagnostic[] = []; if (options.transpileOnly) { @@ -538,10 +549,7 @@ function loader(contents) { } else { let langService = instance.languageService; - - // Update file contents - file.text = contents; - + // Make this file dependent on *all* definition files in the program this.clearDependencies(); this.addDependency(filePath); diff --git a/test/declarationWatch/expectedOutput/patch0/bundle.js b/test/declarationWatch/expectedOutput/patch0/bundle.js deleted file mode 100644 index e22befe59..000000000 --- a/test/declarationWatch/expectedOutput/patch0/bundle.js +++ /dev/null @@ -1,61 +0,0 @@ -/******/ (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, __webpack_require__) { - - var dep = __webpack_require__(1); - console.log(dep); - Thing.doSomething(); - - -/***/ }, -/* 1 */ -/***/ function(module, exports) { - - Thing.doSomething(); - module.exports = 'dep'; - - -/***/ } -/******/ ]); \ No newline at end of file diff --git a/test/declarationWatch/expectedOutput/patch0/output.txt b/test/declarationWatch/expectedOutput/patch0/output.txt index ff002e35f..4610e5243 100644 --- a/test/declarationWatch/expectedOutput/patch0/output.txt +++ b/test/declarationWatch/expectedOutput/patch0/output.txt @@ -1,6 +1,6 @@ - Asset Size Chunks Chunk Names -bundle.js 1.58 kB 0 [emitted] main -chunk {0} bundle.js (main) 112 bytes [rendered] + Asset Size Chunks Chunk Names +bundle.js 1.58 kB 0 main +chunk {0} bundle.js (main) 112 bytes [0] ./.test/declarationWatch/app.ts 67 bytes {0} [built] [1 error] [1] ./.test/declarationWatch/dep.ts 45 bytes {0} [built] [1 error] diff --git a/test/declarationWatch/expectedOutput/patch1/bundle.js b/test/declarationWatch/expectedOutput/patch1/bundle.js deleted file mode 100644 index e22befe59..000000000 --- a/test/declarationWatch/expectedOutput/patch1/bundle.js +++ /dev/null @@ -1,61 +0,0 @@ -/******/ (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, __webpack_require__) { - - var dep = __webpack_require__(1); - console.log(dep); - Thing.doSomething(); - - -/***/ }, -/* 1 */ -/***/ function(module, exports) { - - Thing.doSomething(); - module.exports = 'dep'; - - -/***/ } -/******/ ]); \ No newline at end of file diff --git a/test/declarationWatch/expectedOutput/patch1/output.txt b/test/declarationWatch/expectedOutput/patch1/output.txt index 111f00c5d..e9fd3bd07 100644 --- a/test/declarationWatch/expectedOutput/patch1/output.txt +++ b/test/declarationWatch/expectedOutput/patch1/output.txt @@ -1,5 +1,5 @@ - Asset Size Chunks Chunk Names -bundle.js 1.58 kB 0 [emitted] main -chunk {0} bundle.js (main) 112 bytes [rendered] + Asset Size Chunks Chunk Names +bundle.js 1.58 kB 0 main +chunk {0} bundle.js (main) 112 bytes [0] ./.test/declarationWatch/app.ts 67 bytes {0} [built] [1] ./.test/declarationWatch/dep.ts 45 bytes {0} [built] \ No newline at end of file