From 7417548afd552eeca424712d9e883b41bd93c73d Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 10 Oct 2014 13:26:45 +0300 Subject: [PATCH] Added support for external modules in command line parameter. Fixes #5. --- README.md | 1 + bin/pure-cjs.js | 11 +++++++++++ lib/replacerMap.js | 2 +- package.json | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cc2a367..f0c1af4 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Command-line options: -e, --exports top module exports destination (optional) -x, --extension default extension for requires (defaults to "js") -d, --module-dir modules directory name to look in (defaults to "node_modules") +-s, --external [hash] external modules (names or JSON hashes) ``` ## Usage from Node.js diff --git a/bin/pure-cjs.js b/bin/pure-cjs.js index 7104ca6..951ff4d 100755 --- a/bin/pure-cjs.js +++ b/bin/pure-cjs.js @@ -11,6 +11,17 @@ program .option('-m, --map [file]', 'file to store source map to (optional)') .option('-c, --comments', 'preserve comments in output') .option('-e, --exports ', 'top module exports destination (optional)') + .option('-s, --external [hash]', 'external modules (names or JSON hashes)', function (value, obj) { + try { + var add = JSON.parse(value); + for (var name in add) { + obj[name] = add[name]; + } + } catch (e) { + obj[value] = true; + } + return obj; + }, {}) .parse(process.argv); if (!program.input) { diff --git a/lib/replacerMap.js b/lib/replacerMap.js index 5ddffa0..fe2dc3c 100644 --- a/lib/replacerMap.js +++ b/lib/replacerMap.js @@ -10,7 +10,7 @@ function ReplacerMap(options) { this.defaultExt = options.defaultExt; this.moduleDir = options.moduleDir; this.depsMap = options.deps.reduce(function (obj, dep) { - obj[pathUtils.getNodePath('.', dep.name, this)] = dep; + obj[pathUtils.getNodePath('_', dep.name, this)] = dep; return obj; }.bind(this), {}); } diff --git a/package.json b/package.json index bcfdb56..e4a8a32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pure-cjs", - "version": "1.12.0", + "version": "1.12.1", "description": "Pure minimalistic CommonJS builder", "bin": "./bin/pure-cjs.js", "main": "./lib/index.js",