diff --git a/index.js b/index.js index ad654c1..b6ead31 100644 --- a/index.js +++ b/index.js @@ -54,11 +54,9 @@ class PackDir { escapeArg(arg) { if (isWindows) { - return '"' - + arg + return arg .trim() - .replace(/(["])/g, '\\$1') - + '"'; + .replace(' ' , '\ '); } return arg @@ -119,7 +117,7 @@ class PackDir { } } catch (e) { - console.error(`Error while packaging "${path}": ${e.message}.`); + console.error(`Error while packaging "${path}":\n${e.message.trim()}`); } return false; @@ -193,14 +191,14 @@ class PackDir { let fileName = path + this.ZIP, pathInfo = Path.parse(path), pathStat = FS.statSync(path), - pathWithMask = this.escapeArg( + pathWithMask = ( pathStat.isDirectory() - ? pathInfo.base + Path.sep + '*' - : pathInfo.base + ? (pathInfo.base + Path.sep + '*') + : pathInfo.base ), - pathToZipFile = this.escapeArg(pathInfo.base + '.zip'), + pathToZipFile = pathInfo.base + '.zip', params = {}; - + if (pathInfo.dir) { params.cwd = pathInfo.dir; } @@ -209,8 +207,8 @@ class PackDir { let args = [ '-r', - pathToZipFile, - pathWithMask + this.escapeArg(pathToZipFile), + this.escapeArg(pathWithMask) ]; if (isWindows) { diff --git a/tests/index.test.js b/tests/index.test.js index 35ba1a0..8f03835 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -50,7 +50,7 @@ describe('Pack Dir', () => { }); it('executed sync/async', () => { - let cmd = 'echo test'; + let cmd = 'node -v'; Pack.param('isSync', true); expect(Pack.exec(cmd) instanceof Buffer).toBe(true); @@ -60,13 +60,14 @@ describe('Pack Dir', () => { }); it('executed file sync/async', () => { - let cmd = 'echo'; + let cmd = 'node', + args = ['-v']; Pack.param('isSync', true); expect(Pack.execFile(cmd) instanceof Buffer).toBe(true); Pack.param('isSync', false); - expect(Pack.execFile(cmd) instanceof require('events')).toBe(true); + expect(Pack.execFile(cmd, args) instanceof require('events')).toBe(true); }); it('logs are silent when off', () => { @@ -117,7 +118,7 @@ describe('Pack Dir', () => { it('escapes args/paths', () => { if (isWindows) { - expect(Pack.escapeArg(TEST_PATH)).toEqual('"' + TEST_PATH.replace('"', '\\"') + '"'); + expect(Pack.escapeArg(TEST_PATH)).toEqual(TEST_PATH.replace(' ' , '\ ')); } else { expect(Pack.escapeArg(TEST_PATH)).toEqual(TEST_PATH.replace(' ', '\\ ')); }