[Pkg-javascript-commits] [node-browser-pack] 11/141: return undefined when a module name doesn't resolve
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 c5625d79bea3938329fba70821bc62071c9ce4b2
Author: James Halliday <mail at substack.net>
Date: Fri Feb 15 11:14:57 2013 +1000
return undefined when a module name doesn't resolve
---
index.js | 1 +
package.json | 2 +-
readme.markdown | 6 +++++-
test/raw.js | 3 ++-
4 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/index.js b/index.js
index ade9e15..bae4c55 100644
--- a/index.js
+++ b/index.js
@@ -6,6 +6,7 @@ var prelude = [
'(function(p,c,e){',
'function r(n){',
'if(!c[n]){',
+ 'if(!p[n])return;',
'c[n]={exports:{}};',
'p[n][0](function(x){',
'return r(p[n][1][x])',
diff --git a/package.json b/package.json
index 9541f76..9a67292 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "browser-pack",
- "version": "0.1.0",
+ "version": "0.1.1",
"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 84b78ef..c46437e 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -50,7 +50,11 @@ var pack = require('browser-pack');
## pack(opts)
Return a through stream that takes a stream of json input and produces a stream
-of javascript output.
+of javascript output. This module does not export its internal `require()`
+function but you can prepend `'var require='` to the stream contents to get the
+require function. `require()` will return `undefined` when a module hasn't been
+defined to support splitting up modules across several bundles with custom
+fallback logic.
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.
diff --git a/test/raw.js b/test/raw.js
index f3ec488..787edee 100644
--- a/test/raw.js
+++ b/test/raw.js
@@ -2,7 +2,7 @@ var test = require('tape');
var pack = require('../');
test('raw', function (t) {
- t.plan(4);
+ t.plan(5);
var p = pack({ raw: true });
var src = '';
@@ -11,6 +11,7 @@ test('raw', function (t) {
var r = Function(['T'], 'return ' + src)(t);
t.equal(r('xyz')(5), 555);
t.equal(r('xyz')(5), 555);
+ t.equal(r('zzz'), undefined);
});
p.write({
--
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