diff --git a/index.ts b/index.ts index a08edc33b..0c8854a08 100644 --- a/index.ts +++ b/index.ts @@ -556,7 +556,10 @@ function loader(contents) { // Make this file dependent on *all* definition files in the program this.clearDependencies(); this.addDependency(filePath); - Object.keys(instance.files).filter(filePath => !!filePath.match(/\.d\.ts$/)).forEach(this.addDependency.bind(this)); + + 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); // Emit Javascript var output = langService.getEmitOutput(filePath); @@ -581,7 +584,7 @@ function loader(contents) { // Make sure webpack is aware that even though the emitted JavaScript may be the same as // a previously cached version the TypeScript may be different and therefore should be // treated as new - this._module.meta['tsLoaderFileVersion'] = file.version; + this._module.meta.tsLoaderFileVersion = file.version; callback(null, outputText, sourceMap) } diff --git a/test/declarationWatch/expectedOutput/patch0/bundle.js b/test/declarationWatch/expectedOutput/patch0/bundle.js new file mode 100644 index 000000000..e22befe59 --- /dev/null +++ b/test/declarationWatch/expectedOutput/patch0/bundle.js @@ -0,0 +1,61 @@ +/******/ (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 4610e5243..ff002e35f 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 main -chunk {0} bundle.js (main) 112 bytes + Asset Size Chunks Chunk Names +bundle.js 1.58 kB 0 [emitted] main +chunk {0} bundle.js (main) 112 bytes [rendered] [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 new file mode 100644 index 000000000..e22befe59 --- /dev/null +++ b/test/declarationWatch/expectedOutput/patch1/bundle.js @@ -0,0 +1,61 @@ +/******/ (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 e9fd3bd07..111f00c5d 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 main -chunk {0} bundle.js (main) 112 bytes + Asset Size Chunks Chunk Names +bundle.js 1.58 kB 0 [emitted] main +chunk {0} bundle.js (main) 112 bytes [rendered] [0] ./.test/declarationWatch/app.ts 67 bytes {0} [built] [1] ./.test/declarationWatch/dep.ts 45 bytes {0} [built] \ No newline at end of file diff --git a/test/issue81/expectedOutput/bundle.js.map b/test/issue81/expectedOutput/bundle.js.map index cc3cb4225..05a1fd6ed 100644 --- a/test/issue81/expectedOutput/bundle.js.map +++ b/test/issue81/expectedOutput/bundle.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 20dda873f690056f1c0c","webpack:///./a.ts"],"names":["bar","Foo"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;ACtCA,KAAI,UAAU,GAAI,aAAQ,UAAK,UAAU,IAAK,UAAU,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE;AACnF,SAAI,CAAC,GAAG,SAAS,CAAC,MAAM;SAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;SAAE,CAAC,CAAC;AAC7H,SAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,KAC1H,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAClJ,YAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;EACjE,CAAC;AAJF,cAAa,MAAW;AACpBA,YAAOA,MAAMA,CAACA;EACjBA;AAED;;EAGCC;AAHD,mBAAC,GAAG,CAQH,EAAE,GAAG,CAAC,C","file":"bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 20dda873f690056f1c0c\n **/","\nfunction bar(target: any) {\n return target;\n}\n\n@bar\nclass Foo {\n \n}\n\n\n/** WEBPACK FOOTER **\n ** ./a.ts\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap [hash]","webpack:///./a.ts"],"names":["bar","Foo"],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;ACtCA,KAAI,UAAU,GAAI,aAAQ,UAAK,UAAU,IAAK,UAAU,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE;AACnF,SAAI,CAAC,GAAG,SAAS,CAAC,MAAM;SAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;SAAE,CAAC,CAAC;AAC7H,SAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,KAC1H,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAClJ,YAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;EACjE,CAAC;AAJF,cAAa,MAAW;AACpBA,YAAOA,MAAMA,CAACA;EACjBA;AAED;;EAGCC;AAHD,mBAAC,GAAG,CAQH,EAAE,GAAG,CAAC,C","file":"bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap [hash]\n **/","\nfunction bar(target: any) {\n return target;\n}\n\n@bar\nclass Foo {\n \n}\n\n\n/** WEBPACK FOOTER **\n ** ./a.ts\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/test/run.js b/test/run.js index 883ccea54..16a740081 100644 --- a/test/run.js +++ b/test/run.js @@ -94,6 +94,7 @@ function createTest(test, testPath, options) { if (options.transpile) config.ts.transpileOnly = true; var iteration = 0; + var lastHash; var watcher = webpack(config).watch({aggregateTimeout: 1500}, function(err, stats) { var patch = ''; if (iteration > 0) { @@ -106,6 +107,16 @@ function createTest(test, testPath, options) { if (saveOutputMode) mkdirp.sync(originalExpectedOutput); } + // replace the hash if found in the output since it can change depending + // on environments and we're not super interested in it + if (stats) { + fs.readdirSync(webpackOutput).forEach(function(file) { + var content = fs.readFileSync(path.join(webpackOutput, file), 'utf-8'); + content = content.split(stats.hash).join('[hash]'); + fs.writeFileSync(path.join(webpackOutput, file), content); + }); + } + // output results if (saveOutputMode) { // loop through webpackOutput and rename to .transpiled if needed @@ -154,7 +165,9 @@ function createTest(test, testPath, options) { } } - if (stats) { + if (stats && stats.hash != lastHash) { + lastHash = stats.hash; + var statsFileName = 'output.txt'; var statsString = stats.toString({timings: false, version: false, hash: false}) diff --git a/test/sourceMaps/expectedOutput/bundle.js.map b/test/sourceMaps/expectedOutput/bundle.js.map index a3883d898..66d9f64e4 100644 --- a/test/sourceMaps/expectedOutput/bundle.js.map +++ b/test/sourceMaps/expectedOutput/bundle.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap 2c777a5d4c08e6b503aa","webpack:///./a.ts"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA,QAAO,CAAC,GAAG,CAAC,aAAa,CAAC","file":"bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 2c777a5d4c08e6b503aa\n **/","console.log('Hello world')\n\n\n/** WEBPACK FOOTER **\n ** ./a.ts\n **/"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap [hash]","webpack:///./a.ts"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA,QAAO,CAAC,GAAG,CAAC,aAAa,CAAC","file":"bundle.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap [hash]\n **/","console.log('Hello world')\n\n\n/** WEBPACK FOOTER **\n ** ./a.ts\n **/"],"sourceRoot":""} \ No newline at end of file