Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit be62881

Browse files
authored
Merge pull request #12647 from adobe/shell-node6
Make file watching compatible with node version 6.x (runs on 0.10 too)
2 parents 4be34b6 + 4e17c98 commit be62881

43 files changed

Lines changed: 836 additions & 2050 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ module.exports = function (grunt) {
347347
/*'cssmin',*/
348348
/*'uglify',*/
349349
'copy',
350+
'npm-install',
350351
'cleanempty',
351352
'usemin',
352353
'build-config'

npm-shrinkwrap.json

Lines changed: 281 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"branch": "",
1313
"SHA": ""
1414
},
15+
"dependencies": {
16+
"anymatch": "1.3.0",
17+
"chokidar": "1.6.0"
18+
},
1519
"devDependencies": {
1620
"grunt": "0.4.5",
1721
"jasmine-node": "1.11.0",

src/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"branch": "",
3636
"SHA": ""
3737
},
38+
"dependencies": {
39+
"anymatch": "1.3.0",
40+
"chokidar": "1.6.0"
41+
},
3842
"devDependencies": {
3943
"grunt": "0.4.5",
4044
"jasmine-node": "1.11.0",

src/filesystem/FileSystem.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ define(function (require, exports, module) {
261261
FileSystem.prototype._watchOrUnwatchEntry = function (entry, watchedRoot, callback, shouldWatch) {
262262
var impl = this._impl,
263263
recursiveWatch = impl.recursiveWatch,
264-
commandName = shouldWatch ? "watchPath" : "unwatchPath";
264+
commandName = shouldWatch ? "watchPath" : "unwatchPath",
265+
filterGlobs = watchedRoot.filterGlobs;
265266

266267
if (recursiveWatch) {
267268
// The impl can watch the entire subtree with one call on the root (we also fall into this case for
@@ -273,7 +274,7 @@ define(function (require, exports, module) {
273274
} else {
274275
// The impl will handle finding all subdirectories to watch.
275276
this._enqueueWatchRequest(function (requestCb) {
276-
impl[commandName].call(impl, entry.fullPath, requestCb);
277+
impl[commandName].call(impl, entry.fullPath, filterGlobs, requestCb);
277278
}.bind(this), callback);
278279
}
279280
} else if (shouldWatch) {
@@ -314,7 +315,7 @@ define(function (require, exports, module) {
314315
};
315316

316317
entriesToWatch.forEach(function (entry) {
317-
impl.watchPath(entry.fullPath, watchCallback);
318+
impl.watchPath(entry.fullPath, filterGlobs, watchCallback);
318319
});
319320
});
320321
}, callback);
@@ -851,11 +852,19 @@ define(function (require, exports, module) {
851852
* @param {function(string): boolean} filter - Returns true if a particular item should
852853
* be watched, given its name (not full path). Items that are ignored are also
853854
* filtered from Directory.getContents() results within this subtree.
855+
* @param {Array<string>} filterGlobs - glob compatible string definitions for
856+
* filtering out events on the node side.
854857
* @param {function(?string)=} callback - A function that is called when the watch has
855858
* completed. If the watch fails, the function will have a non-null FileSystemError
856859
* string parametr.
857860
*/
858-
FileSystem.prototype.watch = function (entry, filter, callback) {
861+
FileSystem.prototype.watch = function (entry, filter, filterGlobs, callback) {
862+
// make filterGlobs an optional argument to stay backwards compatible
863+
if (typeof callback === "undefined" && typeof filterGlobs === "function") {
864+
callback = filterGlobs;
865+
filterGlobs = null;
866+
}
867+
859868
var fullPath = entry.fullPath;
860869

861870
callback = callback || function () {};
@@ -882,7 +891,7 @@ define(function (require, exports, module) {
882891
return;
883892
}
884893

885-
var watchedRoot = new WatchedRoot(entry, filter);
894+
var watchedRoot = new WatchedRoot(entry, filter, filterGlobs);
886895

887896
this._watchedRoots[fullPath] = watchedRoot;
888897

src/filesystem/FileSystemStats.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ define(function (require, exports, module) {
3636

3737
this._isFile = isFile;
3838
this._isDirectory = !isFile;
39-
this._mtime = options.mtime;
39+
// in case of stats transferred over a node-domain,
40+
// mtime will have JSON-ified value which needs to be restored
41+
this._mtime = options.mtime instanceof Date ? options.mtime : new Date(options.mtime);
4042
this._size = options.size;
41-
this._hash = options.hash;
43+
// hash is a property introduced by brackets and it's calculated
44+
// as a valueOf modification time -> calculate here if it's not present
45+
this._hash = options.hash || this._mtime.valueOf();
4246

4347
var realPath = options.realPath;
4448
if (realPath) {

0 commit comments

Comments
 (0)