Skip to content

Commit

Permalink
Merge pull request #698 from KnisterPeter/rebuild-on-depending-dts-ch…
Browse files Browse the repository at this point in the history
…anges

feat: add depending .d.ts files as changed when watch is triggered
  • Loading branch information
johnnyreilly committed Jan 30, 2018
2 parents dd60ed6 + 70dd908 commit b67e587
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const dtsTsTsxRegex = /(\.d)?\.ts(x?)$/i;
export const dtsTsTsxJsJsxRegex = /((\.d)?\.ts(x?)|js(x?))$/i;
export const tsTsxJsJsxRegex = /\.tsx?$|\.jsx?$/i;
export const jsJsx = /\.js(x?)$/i;
export const jsJsxMap = /\.js(x?)\.map$/i;
export const jsJsxMap = /\.js(x?)\.map$/i;
export const nodeModules = /node_modules/i;
35 changes: 24 additions & 11 deletions src/watch-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,31 @@ export function makeWatchRun(
)
.forEach(filePath => {
lastTimes[filePath] = times[filePath];
filePath = path.normalize(filePath);
const file = instance.files[filePath] || instance.otherFiles[filePath];
if (file !== undefined) {
file.text = readFile(filePath) || '';
file.version++;
instance.version!++;
instance.modifiedFiles![filePath] = file;
if (instance.watchHost) {
instance.watchHost.invokeFileWatcher(filePath, instance.compiler.FileWatcherEventKind.Changed);
}
}
updateFile(instance, filePath);
});
// On watch update add all known dts files expect the ones in node_modules
// (skip @types/* and modules with typings)
Object.keys(instance.files)
.filter(filePath =>
filePath.match(constants.dtsDtsxRegex) && !filePath.match(constants.nodeModules)
)
.forEach(filePath => {
updateFile(instance, filePath);
});
cb();
};
}

function updateFile(instance: TSInstance, filePath: string) {
filePath = path.normalize(filePath);
const file = instance.files[filePath] || instance.otherFiles[filePath];
if (file !== undefined) {
file.text = readFile(filePath) || '';
file.version++;
instance.version!++;
instance.modifiedFiles![filePath] = file;
if (instance.watchHost) {
instance.watchHost.invokeFileWatcher(filePath, instance.compiler.FileWatcherEventKind.Changed);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/******/ (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;
var dep = __webpack_require__(1);
console.log(dep);
Thing.doSomething();


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

"use strict";

Thing.doSomething();
module.exports = 'dep';


/***/ })
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Asset Size Chunks Chunk Names
bundle.js 2.75 kB 0 [emitted] main
[0] ./.test/declarationWatch/app.ts 108 bytes {0} [built] [1 error]
[1] ./.test/declarationWatch/dep.ts 59 bytes {0} [built] [1 error]

ERROR in ./.test/declarationWatch/dep.ts
[tsl] ERROR in dep.ts(1,7)
 TS2339: Property 'doSomething' does not exist on type 'typeof Thing'.

ERROR in ./.test/declarationWatch/app.ts
[tsl] ERROR in app.ts(5,7)
 TS2339: Property 'doSomething' does not exist on type 'typeof Thing'.
4 changes: 2 additions & 2 deletions test/comparison-tests/issue441/expectedOutput-2.7/output.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Asset Size Chunks Chunk Names
bundle.js 2.57 kB 0 [emitted] main
[0] ./.test/issue441/app.ts 74 bytes {0} [built]
bundle.js 2.56 kB 0 [emitted] main
[0] ./.test/issue441/app.ts 70 bytes {0} [built]
78 changes: 78 additions & 0 deletions test/comparison-tests/issue441/expectedOutput-2.7/patch0/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/******/ (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;
var foo;
foo.bar = 'foobar';


/***/ })
/******/ ]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Asset Size Chunks Chunk Names
bundle.js 2.56 kB 0 [emitted] main
[0] ./.test/issue441/app.ts 70 bytes {0} [built]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Asset Size Chunks Chunk Names
bundle.js 2.57 kB 0 [emitted] main
[0] ./.test/issue441/app.ts 74 bytes {0} [built]
bundle.js 2.56 kB 0 [emitted] main
[0] ./.test/issue441/app.ts 70 bytes {0} [built]

0 comments on commit b67e587

Please sign in to comment.