[react-packager] Pick up package changes while running

This commit is contained in:
Amjad Masad 2015-03-23 11:36:20 -07:00
parent ac8cd5a5d0
commit a6b154332b
4 changed files with 57 additions and 32 deletions

View File

@ -8,7 +8,6 @@
var sharedBlacklist = [
__dirname,
'website',
'node_modules/parse/node_modules/xmlhttprequest/lib/XMLHttpRequest.js',
'node_modules/react-tools/src/utils/ImmutableObject.js',
'node_modules/react-tools/src/core/ReactInstanceHandles.js',
'node_modules/react-tools/src/event/EventPropagators.js'

View File

@ -296,6 +296,15 @@ DependecyGraph.prototype._findAndProcessPackage = function(files, root) {
}
if (packagePath != null) {
return this._processPackage(packagePath);
} else {
return q();
}
};
DependecyGraph.prototype._processPackage = function(packagePath) {
var packageRoot = path.dirname(packagePath);
var self = this;
return readFile(packagePath, 'utf8')
.then(function(content) {
var packageJson;
@ -314,15 +323,21 @@ DependecyGraph.prototype._findAndProcessPackage = function(files, root) {
return q();
}
packageJson._root = root;
self._packageByRoot[root] = packageJson;
self._packagesById[packageJson.name] = packageJson;
packageJson._root = packageRoot;
self._addPackageToIndices(packageJson);
return packageJson;
});
} else {
return q();
}
};
DependecyGraph.prototype._addPackageToIndices = function(packageJson) {
this._packageByRoot[packageJson._root] = packageJson;
this._packagesById[packageJson.name] = packageJson;
};
DependecyGraph.prototype._removePackageFromIndices = function(packageJson) {
delete this._packageByRoot[packageJson._root];
delete this._packagesById[packageJson.name];
};
/**
@ -436,16 +451,27 @@ DependecyGraph.prototype._processFileChange = function(eventType, filePath, root
this._debugUpdateEvents.push({event: eventType, path: filePath});
var isPackage = path.basename(filePath) === 'package.json';
if (eventType === 'delete') {
if (isPackage) {
var packageJson = this._packageByRoot[path.dirname(absPath)];
if (packageJson) {
this._removePackageFromIndices(packageJson);
}
} else {
var module = this._graph[absPath];
if (module == null) {
return;
}
this._deleteModule(module);
}
} else if (!(stat && stat.isDirectory())) {
var self = this;
this._loading = this._loading.then(function() {
if (isPackage) {
return self._processPackage(absPath);
}
return self._processModule(absPath);
});
}

View File

@ -56,7 +56,7 @@ function createWatcher(root) {
}
return detectingWatcherClass.then(function(Watcher) {
var watcher = new Watcher(root, {glob: '**/*.js'});
var watcher = new Watcher(root, {glob: ['**/*.js', '**/package.json']});
return new Promise(function(resolve, reject) {
var rejectTimeout = setTimeout(function() {

View File

@ -67,7 +67,7 @@ function Server(options) {
this._debouncedFileChangeHandler = _.debounce(function(filePath) {
self._rebuildPackages(filePath);
self._informChangeWatchers();
}, 50, true);
}, 50);
}
Server.prototype._onFileChange = function(type, filepath, root) {