From e4c7b0890cdfaaa5d92db1cbcde39c62ccb5e12f Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 14 Nov 2016 14:17:20 -0500 Subject: [PATCH] Watch all imported files in linked npm packages on server. --- tools/fs/optimistic.js | 4 ++-- tools/isobuild/import-scanner.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/fs/optimistic.js b/tools/fs/optimistic.js index 74290628a2..902030d11f 100644 --- a/tools/fs/optimistic.js +++ b/tools/fs/optimistic.js @@ -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") { diff --git a/tools/isobuild/import-scanner.js b/tools/isobuild/import-scanner.js index 351dd345db..23c8127930 100644 --- a/tools/isobuild/import-scanner.js +++ b/tools/isobuild/import-scanner.js @@ -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; }