Skip to content

Commit

Permalink
Watch all imported files in linked npm packages on server.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Nov 14, 2016
1 parent e338759 commit e4c7b08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/fs/optimistic.js
Expand Up @@ -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");

Expand Down Expand Up @@ -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") {
Expand Down
17 changes: 13 additions & 4 deletions tools/isobuild/import-scanner.js
Expand Up @@ -28,6 +28,7 @@ import {
optimisticReadFile,
optimisticStatOrNull,
optimisticHashOrNull,
shouldWatch,
} from "../fs/optimistic.js";

import Resolver from "./resolver.js";
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit e4c7b08

Please sign in to comment.