directory-sync
Advanced tools
Comparing version 2.0.11 to 2.0.12
{ | ||
"name": "directory-sync", | ||
"version": "2.0.11", | ||
"version": "2.0.12", | ||
"description": "Easily synchronize directories between two machines over the internet.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,2 +8,3 @@ import Path from 'path'; | ||
match_extension, | ||
to_path_uri, | ||
to_forward_slashes, | ||
@@ -95,3 +96,4 @@ is_accessible_path, | ||
// Index 0 is "keep" and index 1 is "ignore" | ||
const FILTER_TYPE = index === 0 ? 'keep' : 'ignore'; | ||
// We store the parsed filter functions with "_" prefix to sginify that they are not user-provided | ||
const FILTER_TYPE = index === 0 ? '_keep' : '_ignore'; | ||
if (typeof filter == 'function') { | ||
@@ -107,2 +109,6 @@ // If the filter is a function, use it as is | ||
// Convert files, directories, and extensions to uris | ||
const file_uris = has_files ? files.map((file) => to_path_uri(file)) : []; | ||
const directory_uris = has_directories ? directories.map((directory) => to_path_uri(directory)) : []; | ||
// If the filter has names or extensions, use a function to filter the DirectoryMap | ||
@@ -122,3 +128,3 @@ if (has_files || has_directories || has_extensions) | ||
// If this directory's name matches one of the directory names, return true | ||
if (directories.includes(name)) return true; | ||
if (directory_uris.find((uri) => path.endsWith(uri))) return true; | ||
@@ -130,3 +136,3 @@ // If strict mode is disabled, check for parent directory matches | ||
// If this file's name matches one of the names, return true | ||
if (has_files && files.includes(name)) return true; | ||
if (has_files && file_uris.find((uri) => path.endsWith(uri))) return true; | ||
@@ -240,3 +246,3 @@ // If this is a file and its extension matches one of the extensions, return true | ||
const reference = this; | ||
const { keep, ignore } = this.#options.filters; | ||
const { _keep, _ignore } = this.#options.filters; | ||
watcher.ignored = (path, stats) => { | ||
@@ -254,6 +260,6 @@ // If this execution does not have stats avaialble, ignore it | ||
// The "ignore" filter is applied first as it is more restrictive | ||
if (typeof ignore == 'function' && ignore(relative, stats, true)) return true; | ||
if (typeof _ignore == 'function' && _ignore(relative, stats, true)) return true; | ||
// Assert the "keep" filter as non-strict if one is available | ||
if (typeof keep == 'function' && !keep(relative, stats, false)) return true; | ||
if (typeof _keep == 'function' && !_keep(relative, stats, false)) return true; | ||
@@ -260,0 +266,0 @@ // If this candidate passes above filters, then it is good to be tracked |
@@ -60,2 +60,21 @@ import Crypto from 'crypto'; | ||
/** | ||
* Converts the provided string to a path based uri | ||
* | ||
* @param {String} string | ||
* @returns {String} | ||
*/ | ||
function to_path_uri(string) { | ||
// Add a leading slash if not present | ||
string = string.startsWith('/') ? string : `/${string}`; | ||
// Remove any dual leading slashes | ||
string = string.replace(/\/{2,}/g, '/'); | ||
// Remove any trailing slashes | ||
string = string.replace(/\/$/, ''); | ||
return string; | ||
} | ||
/** | ||
* Converts any backslashes to forward slashes. | ||
@@ -148,2 +167,3 @@ * | ||
match_extension, | ||
to_path_uri, | ||
to_forward_slashes, | ||
@@ -150,0 +170,0 @@ is_accessible_path, |
82591
1800