Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add depending .d.ts files as changed when watch is triggered #698

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/constants.ts
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
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);
}
}
}
@@ -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';


/***/ })
/******/ ]);
@@ -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
@@ -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
@@ -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';


/***/ })
/******/ ]);
@@ -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]
@@ -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]