From a84b6c88a95fba79f2c0d20ba0134f7888e1448d Mon Sep 17 00:00:00 2001 From: Aleksey V Zapparov Date: Tue, 24 Jul 2012 19:05:21 +0200 Subject: [PATCH] Replace shellwords with 3rd-party module --- bin/mincer.js | 4 ++-- lib/mincer/common.js | 23 -------------------- lib/mincer/processors/directive_processor.js | 6 ++--- package.json | 3 ++- 4 files changed, 7 insertions(+), 29 deletions(-) diff --git a/bin/mincer.js b/bin/mincer.js index 1788ecec..3c94d57c 100755 --- a/bin/mincer.js +++ b/bin/mincer.js @@ -9,12 +9,12 @@ var path = require('path'); // 3rd-party -var ArgumentParser = require('argparse').ArgumentParser; +var ArgumentParser = require('argparse').ArgumentParser; +var shellwords = require('shellwords').split; // internal var Mincer = require('..'); -var shellwords = require('../lib/mincer/common').shellwords; //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/mincer/common.js b/lib/mincer/common.js index 616c1578..8ce044db 100644 --- a/lib/mincer/common.js +++ b/lib/mincer/common.js @@ -46,29 +46,6 @@ module.exports.normalizeExtension = function (extension) { -// parse string in a BASH style -// inspired by Shellwords module of Ruby -var SHELLWORDS_PATTERN = /\s*(?:([^\s\\\'\"]+)|'((?:[^\'\\]|\\.)*)'|"((?:[^\"\\]|\\.)*)")/; -module.exports.shellwords = function (line) { - var words = [], match, field; - - while (line) { - match = SHELLWORDS_PATTERN.exec(line); - - if (!match || !match[0]) { - line = false; - } else { - line = line.substr(match[0].length); - field = (match[1] || match[2] || match[3] || '').replace(/\\(.)/, '$1'); - - words.push(field); - } - } - - return words; -}; - - // Dummy alternative to Ruby's Pathname#is_absolute var ABSOLUTE_PATH_PATTERN = /^\//; module.exports.isAbsolute = function (pathname) { diff --git a/lib/mincer/processors/directive_processor.js b/lib/mincer/processors/directive_processor.js index b9fe4f38..d80c891b 100644 --- a/lib/mincer/processors/directive_processor.js +++ b/lib/mincer/processors/directive_processor.js @@ -31,15 +31,15 @@ var path = require('path'); // 3rd-party -var _ = require('underscore'); -var async = require('async'); +var _ = require('underscore'); +var async = require('async'); +var shellwords = require('shellwords').split; // internal var Template = require('../template'); var prop = require('../common').prop; var getter = require('../common').getter; -var shellwords = require('../common').shellwords; var isAbsolute = require('../common').isAbsolute; var isRelative = require('../common').isRelative; diff --git a/package.json b/package.json index 1f800511..e1473ddb 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "argparse" : "~ 0.1.3", "fs-tools" : "~ 0.2.2", "async" : "~ 0.1.22", - "underscore" : "~ 1.3.3" + "underscore" : "~ 1.3.3", + "shellwords" : "~ 0.1.0" }, "devDependencies" : { "mocha": "~> 1.3.0" }, "engines" : { "node": ">= 0.6.0" }