From 1e4e67df5a7822abd55d0b3843380778a3fe2678 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 24 Nov 2015 13:53:10 -0500 Subject: [PATCH] Turn readAndWatchDirectory into a helper method. --- tools/isobuild/package-source.js | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/isobuild/package-source.js b/tools/isobuild/package-source.js index a00d0fb15e..7a5a5c9682 100644 --- a/tools/isobuild/package-source.js +++ b/tools/isobuild/package-source.js @@ -1160,6 +1160,13 @@ _.extend(PackageSource.prototype, { } }, + _readAndWatchDirectory(relDir, watchSet, {include, exclude, names}) { + return watch.readAndWatchDirectory(watchSet, { + absPath: files.pathJoin(this.sourceRoot, relDir), + include, exclude, names + }).map(name => files.pathJoin(relDir, name)); + }, + // Initialize a package from an application directory (has .meteor/packages). initFromAppDir: Profile("initFromAppDir", function (projectContext, ignoreFiles) { var self = this; @@ -1200,23 +1207,19 @@ _.extend(PackageSource.prototype, { getFiles(sourceProcessorSet, watchSet) { const sourceReadOptions = sourceProcessorSet.appReadDirectoryOptions(arch); + + sourceProcessorSet.watchSet = watchSet; + // Ignore files starting with dot (unless they are explicitly in // 'names'). sourceReadOptions.exclude.push(/^\./); // Ignore the usual ignorable files. sourceReadOptions.exclude.push(...ignoreFiles); - // Wrapper around watch.readAndWatchDirectory which takes in and returns - // sourceRoot-relative directories. - var readAndWatchDirectory = (relDir, {include, exclude, names}) => { - var absPath = files.pathJoin(self.sourceRoot, relDir); - var contents = watch.readAndWatchDirectory( - watchSet, {absPath, include, exclude, names}); - return contents.map(x => files.pathJoin(relDir, x)); - }; - // Read top-level source files. - var sources = readAndWatchDirectory('', sourceReadOptions); + var sources = self._readAndWatchDirectory( + '', watchSet, sourceReadOptions + ); // don't include watched but not included control files sources = _.difference(sources, controlFiles); @@ -1249,7 +1252,7 @@ _.extend(PackageSource.prototype, { // Read top-level subdirectories. Ignore subdirectories that have // special handling. - var sourceDirectories = readAndWatchDirectory('', { + var sourceDirectories = self._readAndWatchDirectory('', watchSet, { include: [/\/$/], exclude: [/^packages\/$/, /^tests\/$/, // XXX We no longer actually have special handling @@ -1279,11 +1282,13 @@ _.extend(PackageSource.prototype, { } // Find source files in this directory. - sources.push(...readAndWatchDirectory(dir, sourceReadOptions)); + sources.push(...self._readAndWatchDirectory( + dir, watchSet, sourceReadOptions + )); // Find sub-sourceDirectories. Note that we DON'T need to ignore the // directory names that are only special at the top level. - sourceDirectories.push(...readAndWatchDirectory(dir, { + sourceDirectories.push(...self._readAndWatchDirectory(dir, watchSet, { include: [/\/$/], exclude: [/^tests\/$/, otherUnibuildRegExp].concat( sourceReadOptions.exclude) @@ -1313,7 +1318,9 @@ _.extend(PackageSource.prototype, { // Now look for assets for this unibuild. const assetDir = archinfo.matches(arch, "web") ? "public/" : "private/"; - var assetDirs = readAndWatchDirectory('', {names: [assetDir]}); + var assetDirs = self._readAndWatchDirectory('', watchSet, { + names: [assetDir] + }); const assets = []; @@ -1333,7 +1340,7 @@ _.extend(PackageSource.prototype, { } // Find asset files in this directory. - var assetsAndSubdirs = readAndWatchDirectory(dir, { + var assetsAndSubdirs = self._readAndWatchDirectory(dir, watchSet, { include: [/.?/], // we DO look under dot directories here exclude: ignoreFiles