Watch all imported files in linked npm packages on server.

This commit is contained in:
Ben Newman
2016-11-14 14:17:20 -05:00
parent e3387599a2
commit e4c7b0890c
2 changed files with 15 additions and 6 deletions

View File

@@ -74,7 +74,7 @@ function makeOptimistic(name, fn) {
return Profile("optimistic " + name, wrapper);
}
function shouldWatch(path) {
export const shouldWatch = wrap(path => {
const parts = path.split(pathSep);
const nmi = parts.indexOf("node_modules");
@@ -113,7 +113,7 @@ function shouldWatch(path) {
// instead we rely on dependOnNodeModules to tell us when files in
// node_modules directories might have changed.
return false;
}
});
function maybeDependOnNodeModules(path) {
if (typeof path !== "string") {

View File

@@ -28,6 +28,7 @@ import {
optimisticReadFile,
optimisticStatOrNull,
optimisticHashOrNull,
shouldWatch,
} from "../fs/optimistic.js";
import Resolver from "./resolver.js";
@@ -557,11 +558,19 @@ export default class ImportScanner {
// Append this file to the output array and record its index.
this._addFile(absImportedPath, depFile);
// On the server, modules in node_modules directories will be
// handled natively by Node, so we don't need to build a
// meteorInstall-style bundle beyond the entry-point module.
if (! this.isWeb() &&
depFile.installPath.startsWith("node_modules/")) {
// On the server, modules in node_modules directories will be
// handled natively by Node, so we don't need to build a
// meteorInstall-style bundle beyond the entry-point module.
depFile.installPath.startsWith("node_modules/") &&
// If optimistic functions care about this file, e.g. because it
// resides in a linked npm package, then we should allow it to
// be watched by including it in the server bundle by not
// returning here. Note that inclusion in the server bundle is
// an unnecessary consequence of this logic, since Node will
// still evaluate this module natively on the server. What we
// really care about is watching the file for changes.
! shouldWatch(absImportedPath)) {
return;
}