From 6ac5431a6dfa044e60790f576124775e3ef72348 Mon Sep 17 00:00:00 2001 From: Misha Koryak Date: Thu, 11 Jun 2015 09:02:40 -0400 Subject: [PATCH] support for more than 14 entries without overwriting other code. The important change here is ` + chunks[node.range[1] + 1]` which allows code like this to work: ```js foo(require('moment')); ``` without putting that chunk back the code above will be transformed into ```js foo(require('./bower_components/moment/moment.js'); ``` --- index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 4bbd5ce..cad18cd 100644 --- a/index.js +++ b/index.js @@ -130,21 +130,21 @@ module.exports = function (file, options) { var relativeRequiredFilePath = './' + path.relative(path.dirname(file), fullModulePath); relativeRequiredFilePaths.push(JSON.stringify(relativeRequiredFilePath)) }) - + replaceNode(node.arguments[0], relativeRequiredFilePaths); - + }}); function replaceNode(node, paths) { - var s = paths.shift() - chunks[node.range[0]] = s; + chunks[node.range[0]] = paths.shift() || ''; for (var i = node.range[0] + 1; i < node.range[1]; i++) { - chunks[i] = ''; + chunks[i] = ''; + } + if(paths.length) { + chunks[node.range[1] + 1] = paths.map(function (p, i) { + return (i == 0 ? '\n' : '') + 'require(' + p + ')' + }).join(', ') + chunks[node.range[1] + 1]; } - paths.forEach(function (p, i) { - var st = '\nrequire(' + p + ')' - chunks[node.range[1] + (i + 1)] = st - }) } function getModuleName(path) {