[Pkg-javascript-commits] [node-umd] 09/10: Remove streaming support

Bastien Roucariès rouca at moszumanska.debian.org
Mon Apr 17 07:38:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to annotated tag 3.0.0
in repository node-umd.

commit 11c4644d052114132a47add8eca1a71204b1c2ce
Author: Forbes Lindesay <forbes at lindesay.co.uk>
Date:   Wed Feb 4 14:32:16 2015 +0000

    Remove streaming support
    
    The cli still streams from stdin to stdout, so as to remain efficient,
    and it is still easy to do your own streaming via `umd.prelude` and
    `um.postlude` but by removing it from the core mud module, we can make
    this module much simpler and remove the dependency on `through`.
---
 README.md    | 13 ++++++++-----
 bin/cli.js   | 10 +++++++---
 package.json |  4 +---
 source.js    | 22 +++-------------------
 4 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/README.md b/README.md
index 4b3a1e9..af4544e 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,6 @@
 Universal Module Definition for use in automated build systems
 
  - simple synchronous wrapping of a string
- - optional wrapping of a "stream" with genuine streaming
  - `return` style module support
  - CommonJS support
  - prevents internal UMDs from conflicting
@@ -35,13 +34,11 @@ options:
 
  - `commonJS` (default: `false`) - If commonJS is `true` then it will accept CommonJS source instead of source code which `return`s the module.
 
-### umd(name, [source], [options])
+### umd(name, source, [options])
 
   The `name` should the the name of the module.  Use a string like name, all lower case with hyphens instead of spaces.
 
-  If `source` is provided and is a string, then it is wrapped in umd and returned as a string.  If it is not provided, a duplex stream is returned which wraps the modules (see examples/build.js).
-
-  Both commonJS and source are optional and can be provided in either order.
+  If `source` should be a string, that is wrapped in umd and returned as a string.
 
 ### umd.prelude(module, [options])
 
@@ -64,6 +61,12 @@ Options:
  -c --commonJS Use CommonJS module format
  ```
 
+ You can easilly pipe unix commands together like:
+
+ ```js
+ cat my-module.js | umd my-module | uglify-js > my-module.umd.min.js
+ ```
+
 ## License
 
   MIT
diff --git a/bin/cli.js b/bin/cli.js
index 58ad1f1..3a2287a 100644
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -34,6 +34,10 @@ if (help || !args[0]) {
 } else {
   var source = args[1] ? read(args[1]) : process.stdin
   var dest = args[2] ? write(args[2]) : process.stdout
-
-  source.pipe(umd(args[0], commonJS)).pipe(dest)
-}
\ No newline at end of file
+  var prelude = umd.prelude(args[0], {commonJS: commonJS})
+  var postlude = umd.postlude(args[0], {commonJS: commonJS})
+  dest.write(prelude)
+  source.on('end', function () {
+    dest.write(postlude + '\n')
+  }).pipe(dest, {end: false})
+}
diff --git a/package.json b/package.json
index 854c9ab..eb46188 100644
--- a/package.json
+++ b/package.json
@@ -3,9 +3,7 @@
   "version": "2.1.0",
   "description": "Universal Module Definition for use in automated build systems",
   "bin": "./bin/cli.js",
-  "dependencies": {
-    "through": "~2.3.4"
-  },
+  "dependencies": {},
   "devDependencies": {
     "brfs": "^1.3.0",
     "linify": "~1.0.1",
diff --git a/source.js b/source.js
index 28784e4..cc22308 100644
--- a/source.js
+++ b/source.js
@@ -1,7 +1,6 @@
 'use strict';
 
 var fs = require('fs');
-var through = require('through');
 var templateSTR = fs.readFileSync(__dirname + '/template.min.js', 'utf8');
 
 function template(moduleName, options) {
@@ -22,28 +21,13 @@ function template(moduleName, options) {
   return str;
 }
 
-exports = module.exports = function (name, options, src) {
-  if (typeof options === 'string') {
+exports = module.exports = function (name, src, options) {
+  if (typeof options === 'string' && typeof src === 'object') {
     var tmp = options;
     options = src;
     src = tmp;
   }
-  if (src) {
-    return exports.prelude(name, options) + src + exports.postlude(name, options);
-  }
-  var strm = through(write, end);
-  var first = true;
-  function write(chunk) {
-    if (first) strm.queue(exports.prelude(name, options));
-    first = false;
-    strm.queue(chunk);
-  }
-  function end() {
-    if (first) strm.queue(exports.prelude(name, options));
-    strm.queue(exports.postlude(name, options));
-    strm.queue(null);
-  }
-  return strm;
+  return exports.prelude(name, options) + src + exports.postlude(name, options);
 };
 
 exports.prelude = function (moduleName, options) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-umd.git



More information about the Pkg-javascript-commits mailing list