[Pkg-javascript-commits] [node-browser-pack] 10/141: opts.raw

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:23:20 UTC 2017


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

rouca pushed a commit to branch master
in repository node-browser-pack.

commit 8016435233be5703cb02eefc1b89381de819a356
Author: James Halliday <mail at substack.net>
Date:   Tue Feb 12 05:44:23 2013 -0800

    opts.raw
---
 index.js        |  5 +++--
 package.json    |  2 +-
 readme.markdown |  5 ++++-
 test/raw.js     | 29 +++++++++++++++++++++++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/index.js b/index.js
index 6667595..ade9e15 100644
--- a/index.js
+++ b/index.js
@@ -18,8 +18,9 @@ var prelude = [
     '})({'
 ].join('');
 
-module.exports = function () {
-    var parser = JSONStream.parse([ true ]);
+module.exports = function (opts) {
+    if (!opts) opts = {};
+    var parser = opts.raw ? through() : JSONStream.parse([ true ]);
     var output = through(write, end);
     parser.pipe(output);
     
diff --git a/package.json b/package.json
index 8c648a7..9541f76 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "browser-pack",
-    "version": "0.0.0",
+    "version": "0.1.0",
     "description": "pack node-style source files from a json stream into a browser bundle",
     "main": "index.js",
     "bin": {
diff --git a/readme.markdown b/readme.markdown
index 482292e..84b78ef 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -47,11 +47,14 @@ $ browser-pack < input.json
 var pack = require('browser-pack');
 ```
 
-## pack()
+## pack(opts)
 
 Return a through stream that takes a stream of json input and produces a stream
 of javascript output.
 
+If `opts.raw` is given, the writable end of the stream will expect objects to be
+written to it instead of expecting a stream of json text it will need to parse.
+
 # install
 
 With [npm](https://npmjs.org), to get the library do:
diff --git a/test/raw.js b/test/raw.js
new file mode 100644
index 0000000..f3ec488
--- /dev/null
+++ b/test/raw.js
@@ -0,0 +1,29 @@
+var test = require('tape');
+var pack = require('../');
+
+test('raw', function (t) {
+    t.plan(4);
+    
+    var p = pack({ raw: true });
+    var src = '';
+    p.on('data', function (buf) { src += buf });
+    p.on('end', function () {
+        var r = Function(['T'], 'return ' + src)(t);
+        t.equal(r('xyz')(5), 555);
+        t.equal(r('xyz')(5), 555);
+    });
+    
+    p.write({
+        id: 'abc',
+        source: 'T.equal(require("./xyz")(3), 333)',
+        entry: true,
+        deps: { './xyz': 'xyz' }
+    });
+    
+    p.write({
+        id: 'xyz',
+        source: 'T.ok(true); module.exports=function(n){return n*111}'
+    });
+    
+    p.end();
+});

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



More information about the Pkg-javascript-commits mailing list