From d36d1551b699c28488d8bdb2d9a5b610bb9aac91 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 08:23:54 +0200 Subject: [PATCH 01/30] added should copy empty sub dir test --- test/copy.spec.js | 22 +++++++++++++++++++++- test/helpers.js | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/test/copy.spec.js b/test/copy.spec.js index 74fcc09..98b787d 100644 --- a/test/copy.spec.js +++ b/test/copy.spec.js @@ -1,5 +1,5 @@ import syncGlob from '../src/index' -import { beforeEachSpec, afterAllSpecs, awaitCount, awaitMatch, compare, compareDir, noop } from './helpers' +import { beforeEachSpec, afterAllSpecs, fs, awaitCount, awaitMatch, compare, compareDir, noop } from './helpers' describe('node-sync-glob copy', () => { beforeEach(beforeEachSpec) @@ -111,4 +111,24 @@ describe('node-sync-glob copy', () => { 'mirror', compareDir(done, 'tmp/mock', 'tmp/copy') )) }) + + it('should copy empty sub directories', (done) => { + fs.ensureDirSync('tmp/mock/bar/empty') + + const close = syncGlob('tmp/mock/**/*', 'tmp/copy', awaitMatch( + 'error', (err) => { + fail(err) + close() + done() + }, + 'mirror', () => { + expect(fs.existsSync('tmp/mock/bar/empty')).toBe(true) + + compareDir(null, 'tmp/mock', 'tmp/copy') + + close() + done() + } + )) + }) }) diff --git a/test/helpers.js b/test/helpers.js index 233f94b..5fdca43 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -10,6 +10,7 @@ export const fs = { appendFileSync: (source, ...args) => fsExtra.appendFileSync(path.normalize(source), ...args), existsSync: source => fsExtra.existsSync(path.normalize(source)), readFileSync: source => fsExtra.readFileSync(path.normalize(source)), + ensureDirSync: source => fsExtra.ensureDirSync(path.normalize(source)), } export const beforeEachSpec = () => { From abdb43aec00ee2039924f688264ba184d1bae5f0 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 08:27:12 +0200 Subject: [PATCH 02/30] added empty sub dir deletion test --- test/sync.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/sync.spec.js b/test/sync.spec.js index f056f4f..7e30d95 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -93,4 +93,26 @@ describe('node-sync-glob watch', () => { } )) }) + + it('should sync empty sub directory deletion', (done) => { + fs.ensureDirSync('tmp/mock/bar/empty') + + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch }, awaitMatch( + 'error', (err) => { + fail(err) + close() + done() + }, + ['mirror', 'watch'], compareDir(() => { + fs.removeSync('tmp/mock/bar/empty') + }, 'tmp/mock', 'tmp/sync'), + 'remove', () => { + expect(fs.existsSync('tmp/sync/foo/b.txt')).toBe(true) + expect(fs.existsSync('tmp/mock/bar/empty')).toBe(false) + + close() + done() + } + )) + }) }) From 3749bdb4d516a306d655c19f818b036a66dbe0fe Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 09:47:11 +0200 Subject: [PATCH 03/30] ooops, fixed wrong path --- test/copy.spec.js | 2 +- test/sync.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/copy.spec.js b/test/copy.spec.js index 98b787d..38097ff 100644 --- a/test/copy.spec.js +++ b/test/copy.spec.js @@ -122,7 +122,7 @@ describe('node-sync-glob copy', () => { done() }, 'mirror', () => { - expect(fs.existsSync('tmp/mock/bar/empty')).toBe(true) + expect(fs.existsSync('tmp/copy/bar/empty')).toBe(true) compareDir(null, 'tmp/mock', 'tmp/copy') diff --git a/test/sync.spec.js b/test/sync.spec.js index 7e30d95..e57eca7 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -108,7 +108,7 @@ describe('node-sync-glob watch', () => { }, 'tmp/mock', 'tmp/sync'), 'remove', () => { expect(fs.existsSync('tmp/sync/foo/b.txt')).toBe(true) - expect(fs.existsSync('tmp/mock/bar/empty')).toBe(false) + expect(fs.existsSync('tmp/sync/bar/empty')).toBe(false) close() done() From 7dccae73cbdcfce8c2dcee22bf9b3dc5609c357f Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 10:05:10 +0200 Subject: [PATCH 04/30] added log of initial mirror --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3013ed0..5e6a133 100644 --- a/src/index.js +++ b/src/index.js @@ -89,7 +89,11 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { const mirrorInit = [ promisify(globAll)(sources.map(source => (isGlob(source) === -1 && fs.statSync(source).isDirectory() ? `${source}/**` : source))) - .then(files => files.map(file => path.normalize(file))), + .then(files => files.map(file => path.normalize(file))) + .then((files) => { + console.log(files) + return files + }), ] if (options.delete) { From f8ec63950827291a4270e05d32c18f46ec8e7309 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 10:29:58 +0200 Subject: [PATCH 05/30] moar log --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5e6a133..d7320e4 100644 --- a/src/index.js +++ b/src/index.js @@ -86,11 +86,15 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { } // Initial mirror + const initSources = sources.map(source => (isGlob(source) === -1 + && fs.statSync(source).isDirectory() ? `${source}/**` : source)) const mirrorInit = [ - promisify(globAll)(sources.map(source => (isGlob(source) === -1 - && fs.statSync(source).isDirectory() ? `${source}/**` : source))) + promisify(globAll)(initSources) .then(files => files.map(file => path.normalize(file))) .then((files) => { + console.log('----------') + console.log(initSources) + console.log('>>>>>>>>>>') console.log(files) return files }), From 05d0d4a4293477d09398f4b141b36b736aa16746 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 10:30:55 +0200 Subject: [PATCH 06/30] fixed missing path normalization --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index d7320e4..7039d1d 100644 --- a/src/index.js +++ b/src/index.js @@ -87,7 +87,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { // Initial mirror const initSources = sources.map(source => (isGlob(source) === -1 - && fs.statSync(source).isDirectory() ? `${source}/**` : source)) + && fs.statSync(path.normalize(source)).isDirectory() ? `${source}/**` : source)) const mirrorInit = [ promisify(globAll)(initSources) .then(files => files.map(file => path.normalize(file))) From 17c3c3d0f82ee5c3289450db7bd470d116a19109 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 10:42:40 +0200 Subject: [PATCH 07/30] fixed double slashh --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7039d1d..d1b1439 100644 --- a/src/index.js +++ b/src/index.js @@ -87,7 +87,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { // Initial mirror const initSources = sources.map(source => (isGlob(source) === -1 - && fs.statSync(path.normalize(source)).isDirectory() ? `${source}/**` : source)) + && fs.statSync(path.normalize(source)).isDirectory() ? `${source}${source.slice(-1) === '/' ? '' : '/'}**` : source)) const mirrorInit = [ promisify(globAll)(initSources) .then(files => files.map(file => path.normalize(file))) From 9b894ed34e45914bc330af32525188a1ff17314a Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 10:49:02 +0200 Subject: [PATCH 08/30] updated fs-extra --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b95109..8bbd185 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "bluebird": "^3.4.7", "chalk": "^1.1.3", "chokidar": "^1.6.1", - "fs-extra": "^1.0.0", + "fs-extra": "^2.1.2", "glob-all": "^3.1.0", "yargs": "^6.3.0" }, From ab4a455c38274da3435533ad4fa52733c5208c0e Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:18:53 +0200 Subject: [PATCH 09/30] normalized target path --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index d1b1439..bba2822 100644 --- a/src/index.js +++ b/src/index.js @@ -41,6 +41,8 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { } // eslint-disable-next-line no-param-reassign sources = sources.map(trimQuotes) + // eslint-disable-next-line no-param-reassign + target = path.normalize(target) if (typeof options === 'function') { // eslint-disable-next-line no-param-reassign From f7be43d85d4e6cdf33e18a150e3889fecdeed702 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:21:09 +0200 Subject: [PATCH 10/30] added conditional raw logging --- src/index.js | 9 ++++++++- test/sync.spec.js | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index bba2822..16c8e27 100644 --- a/src/index.js +++ b/src/index.js @@ -60,7 +60,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { const notifyError = (err) => { notify('error', err) } const bases = sourcesBases(sources) const resolveTargetFromBases = resolveTarget(bases) - const { depth, watch } = options + const { depth, watch, raw } = options let { transform } = options if (typeof depth !== 'number' || isNaN(depth)) { @@ -228,6 +228,13 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { }) .on('error', notifyError) + if (raw) { + watcher.on('raw', (event, rpath, details) => { + console.log(`RAW: ${event} -> ${rpath}`) + console.log(details) + }) + } + process.on('SIGINT', close) process.on('SIGQUIT', close) process.on('SIGTERM', close) diff --git a/test/sync.spec.js b/test/sync.spec.js index e57eca7..c7ff940 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -51,7 +51,7 @@ describe('node-sync-glob watch', () => { }) it('should sync a directory', (done) => { - const close = syncGlob('tmp/mock/foo', 'tmp/sync/', { watch }, awaitMatch( + const close = syncGlob('tmp/mock/foo', 'tmp/sync', { watch, raw: true }, awaitMatch( 'error', (err) => { fail(err) close() @@ -73,7 +73,7 @@ describe('node-sync-glob watch', () => { }) it('should sync globstar', (done) => { - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch }, awaitMatch( + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, raw: true }, awaitMatch( 'error', (err) => { fail(err) close() @@ -97,7 +97,7 @@ describe('node-sync-glob watch', () => { it('should sync empty sub directory deletion', (done) => { fs.ensureDirSync('tmp/mock/bar/empty') - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch }, awaitMatch( + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, raw: true }, awaitMatch( 'error', (err) => { fail(err) close() From 803fa963c81de13d4ea499db8f0eb3f7c157f29c Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:43:03 +0200 Subject: [PATCH 11/30] added dir diff set logging --- test/helpers.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/helpers.js b/test/helpers.js index 5fdca43..f33b9bf 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -107,6 +107,28 @@ export const awaitMatch = (...args) => { } } +const logDirDiffSet = (source, target, res) { + if (!res.same) { + const logs = res.diffSet.map((entry) => { + const state = { + equal: '==', + left: '->', + right: '<-', + distinct: '<>', + }[entry.state] + const name1 = entry.name1 ? entry.name1 : '' + const name2 = entry.name2 ? entry.name2 : '' + const path1 = entry.path1 ? entry.path1 : '' + const path2 = entry.path2 ? entry.path2 : '' + const { type1, type2 } = entry + + return `${path1}/${name1} ${type1} ${state} ${path2}/${name2} ${type2}` + }) + + console.log(`${source} -> ${target}\n\t${logs.join('\n\t')}`) + } +} + export const compare = (done, source, target, options) => (event, data) => { if (event) { if (Array.isArray(data) && data.length === 2 @@ -121,6 +143,8 @@ export const compare = (done, source, target, options) => (event, data) => { compareContent: true, }) + logDirDiffSet(source, target, res) + expect(res.differences).toBe(0) expect(res.differencesFiles).toBe(0) expect(res.distinctFiles).toBe(0) @@ -141,6 +165,8 @@ export const compareDir = (done, source, target, options = {}) => (event) => { compareContent: true, }) + logDirDiffSet(source, target, res) + expect(res.differences).toBe(0) expect(res.differencesFiles).toBe(0) expect(res.distinctFiles).toBe(0) From 056145dc9ae62e9b1db4cba516cd881f6ab7db0d Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:43:45 +0200 Subject: [PATCH 12/30] ooops typo --- test/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers.js b/test/helpers.js index f33b9bf..5b79474 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -107,7 +107,7 @@ export const awaitMatch = (...args) => { } } -const logDirDiffSet = (source, target, res) { +const logDirDiffSet = (source, target, res) => { if (!res.same) { const logs = res.diffSet.map((entry) => { const state = { From a6470288d6bb9a8d42dc23c53146108400c295b2 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:56:22 +0200 Subject: [PATCH 13/30] start adding debug option --- src/bin/sync-glob.js | 5 +++++ src/index.js | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bin/sync-glob.js b/src/bin/sync-glob.js index 8e115bb..1b966bc 100644 --- a/src/bin/sync-glob.js +++ b/src/bin/sync-glob.js @@ -31,6 +31,10 @@ const argv = yargs.usage('Usage: $0 ') .alias('v', 'verbose') .default('verbose', false) .describe('verbose', 'Moar output') + .boolean('debug') + .alias('b', 'debug') + .default('debug', false) + .describe('debug', 'Log essential information for debugging') .version() .help('help') .showHelpOnFail(false, 'Specify --help for available options') @@ -67,6 +71,7 @@ const close = syncGlob(sources, target, { watch: argv.watch, delete: argv.delete, depth: argv.depth || Infinity, + debug: argv.debug, transform: argv.transform, }, (event, data) => { const priority = notifyPriority[event] || 'low' diff --git a/src/index.js b/src/index.js index 16c8e27..7f0e5e2 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ const defaults = { watch: false, delete: true, depth: Infinity, + debug: false, } /** @@ -29,6 +30,7 @@ const defaults = { * @param {bool} [options.watch=false] - Enable or disable watch mode. * @param {bool} [options.delete=true] - Whether to delete the `target`'s content initially. * @param {bool} [options.depth=Infinity] - Chokidars `depth` (If set, limits how many levels of subdirectories will be traversed). + * @param {bool} [options.debug=false] - Log essential information for debugging. * @param {string} [options.transform=false] - A module path resolved by node's `require`. * @param {NotifyCallback} [notify] - An optional notification callback. * @returns {CloseFunc} - Returns a close function which cancels active promises and watch mode. @@ -41,6 +43,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { } // eslint-disable-next-line no-param-reassign sources = sources.map(trimQuotes) + const originalTarget = target // eslint-disable-next-line no-param-reassign target = path.normalize(target) @@ -60,7 +63,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { const notifyError = (err) => { notify('error', err) } const bases = sourcesBases(sources) const resolveTargetFromBases = resolveTarget(bases) - const { depth, watch, raw } = options + const { depth, watch, debug } = options let { transform } = options if (typeof depth !== 'number' || isNaN(depth)) { @@ -94,10 +97,11 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { promisify(globAll)(initSources) .then(files => files.map(file => path.normalize(file))) .then((files) => { - console.log('----------') - console.log(initSources) - console.log('>>>>>>>>>>') - console.log(files) + if (debug) { + console.log(`sources: ${sources} -> ${initSources}`) + console.log(`target: ${originalTarget} -> ${target}`) + console.log(`globed files: ${files}`) + } return files }), ] @@ -228,7 +232,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { }) .on('error', notifyError) - if (raw) { + if (debug) { watcher.on('raw', (event, rpath, details) => { console.log(`RAW: ${event} -> ${rpath}`) console.log(details) From 14f13c84ad8419130d3e7f7290555f9430576b91 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 11:56:32 +0200 Subject: [PATCH 14/30] utilize debug --- test/sync.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sync.spec.js b/test/sync.spec.js index c7ff940..6bfbe58 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -51,7 +51,7 @@ describe('node-sync-glob watch', () => { }) it('should sync a directory', (done) => { - const close = syncGlob('tmp/mock/foo', 'tmp/sync', { watch, raw: true }, awaitMatch( + const close = syncGlob('tmp/mock/foo', 'tmp/sync', { watch, debug: true }, awaitMatch( 'error', (err) => { fail(err) close() @@ -73,7 +73,7 @@ describe('node-sync-glob watch', () => { }) it('should sync globstar', (done) => { - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, raw: true }, awaitMatch( + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( 'error', (err) => { fail(err) close() @@ -97,7 +97,7 @@ describe('node-sync-glob watch', () => { it('should sync empty sub directory deletion', (done) => { fs.ensureDirSync('tmp/mock/bar/empty') - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, raw: true }, awaitMatch( + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( 'error', (err) => { fail(err) close() From a03d5d2a9f16a100878be3a673a9c27a9dbc3f39 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 12:27:04 +0200 Subject: [PATCH 15/30] updated sync empty dir del spec --- test/sync.spec.js | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/test/sync.spec.js b/test/sync.spec.js index 6bfbe58..4ed2f3e 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -95,24 +95,31 @@ describe('node-sync-glob watch', () => { }) it('should sync empty sub directory deletion', (done) => { - fs.ensureDirSync('tmp/mock/bar/empty') + try { + fs.ensureDirSync('tmp/mock/bar/empty') - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( - 'error', (err) => { - fail(err) - close() - done() - }, - ['mirror', 'watch'], compareDir(() => { - fs.removeSync('tmp/mock/bar/empty') - }, 'tmp/mock', 'tmp/sync'), - 'remove', () => { - expect(fs.existsSync('tmp/sync/foo/b.txt')).toBe(true) - expect(fs.existsSync('tmp/sync/bar/empty')).toBe(false) + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( + 'error', (err) => { + fail(err) + close() + done() + }, + ['mirror', 'watch'], compareDir(() => { + fs.removeSync('tmp/mock/bar/empty') + }, 'tmp/mock', 'tmp/sync'), + 'remove', () => { + expect(fs.existsSync('tmp/sync/foo/b.txt')).toBe(true) + expect(fs.existsSync('tmp/sync/bar/empty')).toBe(false) - close() - done() - } - )) + close() + done() + } + )) + } catch (err) { + console.log(err) + + fail(err) + done() + } }) }) From ad2a6ecc215dc6880de9a7e9b719a52ac3c537ef Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 12:30:19 +0200 Subject: [PATCH 16/30] beautified globed files los --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7f0e5e2..fa39bee 100644 --- a/src/index.js +++ b/src/index.js @@ -100,7 +100,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { if (debug) { console.log(`sources: ${sources} -> ${initSources}`) console.log(`target: ${originalTarget} -> ${target}`) - console.log(`globed files: ${files}`) + console.log(`globed files: \n\t${files.join('\n\t')}`) } return files }), From 0d9f4e15a56bc41d00cb8b53651bcd405f0c2842 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 12:34:47 +0200 Subject: [PATCH 17/30] test wheter bar exists --- test/sync.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/sync.spec.js b/test/sync.spec.js index 4ed2f3e..aef2d96 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -96,6 +96,7 @@ describe('node-sync-glob watch', () => { it('should sync empty sub directory deletion', (done) => { try { + console.log(`EXISTS: tmp/mock/bar -> ${fs.existsSync('tmp/mock/bar')}`) fs.ensureDirSync('tmp/mock/bar/empty') const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( From 323bccfd18fdad7b98eaafcede0e48dd1ef8bf9b Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 12:49:00 +0200 Subject: [PATCH 18/30] improve raw log --- src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index fa39bee..1673b8a 100644 --- a/src/index.js +++ b/src/index.js @@ -234,8 +234,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { if (debug) { watcher.on('raw', (event, rpath, details) => { - console.log(`RAW: ${event} -> ${rpath}`) - console.log(details) + console.log(`RAW: ${event} -> ${rpath} \t\n${details}`) }) } From 4dcb624c988b25bf84c7c560ed3f74ebc78e962f Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 12:55:58 +0200 Subject: [PATCH 19/30] added all debug --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1673b8a..25cb8ec 100644 --- a/src/index.js +++ b/src/index.js @@ -181,10 +181,14 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { }) watcher.on('ready', notify.bind(undefined, 'watch', sources)) - .on('all', (event, source) => { + .on('all', (event, source, stats) => { const resolvedTarget = resolveTargetFromBases(source, target) let promise + if (debug) { + console.log(`ALL: ${event} -> ${source} ${stats ? `\t\n${stats}` : ''}`) + } + switch (event) { case 'add': case 'change': From 46b8730c580e5b641e102056dc4abd72694c8d0b Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 13:02:06 +0200 Subject: [PATCH 20/30] utilize inspect --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 25cb8ec..56afe90 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' +import util from 'util' import globAll from 'glob-all' import chokidar from 'chokidar' import Promise, { promisify } from 'bluebird' @@ -186,7 +187,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { let promise if (debug) { - console.log(`ALL: ${event} -> ${source} ${stats ? `\t\n${stats}` : ''}`) + console.log(`ALL: ${event} -> ${source} ${stats ? `\t\n${util.inspect(stats)}` : ''}`) } switch (event) { @@ -238,7 +239,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { if (debug) { watcher.on('raw', (event, rpath, details) => { - console.log(`RAW: ${event} -> ${rpath} \t\n${details}`) + console.log(`RAW: ${event} -> ${rpath} \t\n${util.inspect(details)}`) }) } From 49220eab0d952e36cf7a937b478cd14f5ef200d0 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Tue, 11 Apr 2017 13:07:55 +0200 Subject: [PATCH 21/30] just debug broken test --- test/sync.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sync.spec.js b/test/sync.spec.js index aef2d96..b7e2cbc 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -51,7 +51,7 @@ describe('node-sync-glob watch', () => { }) it('should sync a directory', (done) => { - const close = syncGlob('tmp/mock/foo', 'tmp/sync', { watch, debug: true }, awaitMatch( + const close = syncGlob('tmp/mock/foo', 'tmp/sync', { watch }, awaitMatch( 'error', (err) => { fail(err) close() @@ -73,7 +73,7 @@ describe('node-sync-glob watch', () => { }) it('should sync globstar', (done) => { - const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch }, awaitMatch( 'error', (err) => { fail(err) close() From 79070bbd8edf8d2b9771fd5b3c19ab432223ab63 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 22:29:14 +0200 Subject: [PATCH 22/30] added cwd --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 56afe90..a93c233 100644 --- a/src/index.js +++ b/src/index.js @@ -175,6 +175,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { // Watcher to keep in sync from that if (watch) { watcher = chokidar.watch(sources, { + cwd: process.cwd(), persistent: true, depth, ignoreInitial: true, From 80c9deca5c8bd4e5dba9145f12eead83d7e02655 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 22:32:37 +0200 Subject: [PATCH 23/30] enabled usePolling and useFsEvents --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index a93c233..76880a7 100644 --- a/src/index.js +++ b/src/index.js @@ -180,6 +180,8 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { depth, ignoreInitial: true, awaitWriteFinish: true, + usePolling: true, + useFsEvents: true, }) watcher.on('ready', notify.bind(undefined, 'watch', sources)) From 9be0c790db0c4bf8f7627419331cc118a74a6d18 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 23:25:30 +0200 Subject: [PATCH 24/30] added empty file --- test/mock/emptyFile | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/mock/emptyFile diff --git a/test/mock/emptyFile b/test/mock/emptyFile new file mode 100644 index 0000000..e69de29 From c9ebee34f90a62750f99104a19ea3e84778e8b55 Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 23:28:19 +0200 Subject: [PATCH 25/30] added empty file test --- test/sync.spec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/sync.spec.js b/test/sync.spec.js index b7e2cbc..ec79354 100644 --- a/test/sync.spec.js +++ b/test/sync.spec.js @@ -123,4 +123,24 @@ describe('node-sync-glob watch', () => { done() } }) + + it('should sync empty file deletion', (done) => { + const close = syncGlob('tmp/mock/**/*', 'tmp/sync', { watch, debug: true }, awaitMatch( + 'error', (err) => { + fail(err) + close() + done() + }, + ['mirror', 'watch'], compareDir(() => { + fs.removeSync('tmp/mock/emptyFile') + }, 'tmp/mock', 'tmp/sync'), + 'remove', () => { + expect(fs.existsSync('tmp/sync/foo/b.txt')).toBe(true) + expect(fs.existsSync('tmp/sync/emptyFile')).toBe(false) + + close() + done() + } + )) + }) }) From 4c4f1249b116784bd120250e8b6745d0ea5b7d6b Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 23:29:10 +0200 Subject: [PATCH 26/30] disabled awaitWriteFinish --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 76880a7..588fcc5 100644 --- a/src/index.js +++ b/src/index.js @@ -179,7 +179,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { persistent: true, depth, ignoreInitial: true, - awaitWriteFinish: true, + // awaitWriteFinish: true, usePolling: true, useFsEvents: true, }) From 131dd647185ae0fe833a60dc667fb16d5683a2fb Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Wed, 12 Apr 2017 23:35:24 +0200 Subject: [PATCH 27/30] undo removal of awaitWriteFinish --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 588fcc5..76880a7 100644 --- a/src/index.js +++ b/src/index.js @@ -179,7 +179,7 @@ const syncGlob = (sources, target, options = {}, notify = () => {}) => { persistent: true, depth, ignoreInitial: true, - // awaitWriteFinish: true, + awaitWriteFinish: true, usePolling: true, useFsEvents: true, }) From 2ff0a7cf6aad9e473b6f96e99e89fc3212fbbdaf Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 7 Jul 2017 00:23:52 +0200 Subject: [PATCH 28/30] npm i graceful-fs --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 8bbd185..a799733 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "chokidar": "^1.6.1", "fs-extra": "^2.1.2", "glob-all": "^3.1.0", + "graceful-fs": "^4.1.11", "yargs": "^6.3.0" }, "devDependencies": { From c2ffb1235cfb2f66623fcc484feeb1ca2cbb28fb Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 7 Jul 2017 00:24:09 +0200 Subject: [PATCH 29/30] utilize graceful fs --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index 76880a7..a9c32f8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,8 @@ /* globals process */ import fs from 'fs' +import gracefulFs from 'graceful-fs' +gracefulFs.gracefulify(fs) import path from 'path' import util from 'util' import globAll from 'glob-all' From 1246f80ed7a138f195fd8e684fcf0f467fa2255d Mon Sep 17 00:00:00 2001 From: Andreas Deuschlinger Date: Fri, 7 Jul 2017 00:33:39 +0200 Subject: [PATCH 30/30] disable eslint import rule --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index a9c32f8..a006116 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,9 @@ import fs from 'fs' import gracefulFs from 'graceful-fs' + gracefulFs.gracefulify(fs) +/* eslint-disable import/first */ import path from 'path' import util from 'util' import globAll from 'glob-all'