pax_global_header00006660000000000000000000000064131371615350014517gustar00rootroot0000000000000052 comment=e34bda135c85b7b4b73a246a0ad472e890cf1b41 static-module-1.5.0/000077500000000000000000000000001313716153500142745ustar00rootroot00000000000000static-module-1.5.0/.travis.yml000066400000000000000000000000601313716153500164010ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" static-module-1.5.0/LICENSE000066400000000000000000000020611313716153500153000ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. static-module-1.5.0/example/000077500000000000000000000000001313716153500157275ustar00rootroot00000000000000static-module-1.5.0/example/brfs.js000066400000000000000000000005261313716153500172240ustar00rootroot00000000000000var staticModule = require('../'); var quote = require('quote-stream'); var fs = require('fs'); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: __dirname + '/brfs' } }); process.stdin.pipe(sm).pipe(process.stdout); static-module-1.5.0/example/brfs/000077500000000000000000000000001313716153500166635ustar00rootroot00000000000000static-module-1.5.0/example/brfs/source.js000066400000000000000000000001331313716153500205160ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt'); console.log(src); static-module-1.5.0/example/brfs/x.txt000066400000000000000000000000121313716153500176640ustar00rootroot00000000000000beep boop static-module-1.5.0/example/fs.js000066400000000000000000000014161313716153500166770ustar00rootroot00000000000000var staticModule = require('../'); var quote = require('quote-stream'); var through = require('through2'); var fs = require('fs'); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); }, readFile: function (file, cb) { var stream = through(write, end); stream.push('process.nextTick(function(){(' + cb + ')(null,'); return fs.createReadStream(file).pipe(quote()).pipe(stream); function write (buf, enc, next) { this.push(buf); next() } function end (next) { this.push(')})'); this.push(null); next() } } } }, { vars: { __dirname: __dirname + '/fs' } }); process.stdin.pipe(sm).pipe(process.stdout); static-module-1.5.0/example/fs/000077500000000000000000000000001313716153500163375ustar00rootroot00000000000000static-module-1.5.0/example/fs/source.js000066400000000000000000000001511313716153500201720ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-1.5.0/example/fs/x.txt000066400000000000000000000000121313716153500173400ustar00rootroot00000000000000beep boop static-module-1.5.0/index.js000066400000000000000000000302041313716153500157400ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var through = require('through2'); var Readable = require('readable-stream').Readable; var concat = require('concat-stream'); var duplexer = require('duplexer2'); var falafel = require('falafel'); var unparse = require('escodegen').generate; var inspect = require('object-inspect'); var evaluate = require('static-eval'); var copy = require('shallow-copy'); var has = require('has'); module.exports = function parse (modules, opts) { if (!opts) opts = {}; var vars = opts.vars || {}; var varNames = opts.varNames || {}; var varModules = opts.varModules || {}; var skip = opts.skip || {}; var skipOffset = opts.skipOffset || 0; var updates = []; var output = through(); var body; return duplexer(concat(function (buf) { try { body = buf.toString('utf8').replace(/^#!/, '//#!'); falafel(body, { ecmaVersion: 8 }, walk); } catch (err) { return error(err) } finish(body); }), output); function finish (src) { var pos = 0; src = String(src); (function next () { if (updates.length === 0) return done(); var s = updates.shift(); output.push(src.slice(pos, s.start)); pos = s.start + s.offset; s.stream.pipe(output, { end: false }); s.stream.on('end', next); })(); function done () { output.push(src.slice(pos)); output.push(null); } } function error (msg) { var err = typeof msg === 'string' ? new Error(msg) : msg; output.emit('error', err); } function walk (node) { var isreq = isRequire(node); var isreqm = false, isreqv = false, reqid; if (isreq) { reqid = node.arguments[0].value; isreqm = has(modules, reqid); isreqv = has(varModules, reqid); } if (isreqv && node.parent.type === 'VariableDeclarator' && node.parent.id.type === 'Identifier') { vars[node.parent.id.name] = varModules[reqid]; } else if (isreqv && node.parent.type === 'AssignmentExpression' && node.parent.left.type === 'Identifier') { vars[node.parent.left.name] = varModules[reqid]; } else if (isreqv && node.parent.type === 'MemberExpression' && isStaticProperty(node.parent.property) && node.parent.parent.type === 'VariableDeclarator' && node.parent.parent.id.type === 'Identifier') { var v = varModules[reqid][resolveProperty(node.parent.property)]; vars[node.parent.parent.id.name] = v; } else if (isreqv && node.parent.type === 'MemberExpression' && node.parent.property.type === 'Identifier') { //vars[node.parent.parent.id.name] = varModules[reqid]; } else if (isreqv && node.parent.type === 'CallExpression') { // } if (isreqm && node.parent.type === 'VariableDeclarator' && node.parent.id.type === 'Identifier') { varNames[node.parent.id.name] = reqid; var decs = node.parent.parent.declarations; var ix = decs.indexOf(node.parent); var dec; if (ix >= 0) { dec = decs[ix]; decs.splice(ix, 1); } if (decs.length) { var src = unparse(node.parent.parent); updates.push({ start: node.parent.parent.start, offset: node.parent.parent.end - node.parent.parent.start, stream: st('var ') }); decs.forEach(function (d, i) { var key = (d.start + skipOffset) + ',' + (d.end + skipOffset) ; skip[key] = true; var s = parse(modules, { skip: skip, skipOffset: skipOffset + (d.init ? d.init.start : 0), vars: vars, varNames: varNames }); var up = { start: node.parent.parent.end, offset: 0, stream: s }; updates.push(up); if (i < decs.length - 1) { var comma; if (i === ix - 1) { comma = body.slice(d.end, dec.start); } else comma = body.slice(d.end, decs[i+1].start); updates.push({ start: node.parent.parent.end, offset: 0, stream: st(comma) }); } else { updates.push({ start: node.parent.parent.end, offset: 0, stream: st(';') }); } s.end(unparse(d)); }); } else { updates.push({ start: node.parent.parent.start, offset: node.parent.parent.end - node.parent.parent.start, stream: st() }); } } else if (isreqm && node.parent.type === 'AssignmentExpression' && node.parent.left.type === 'Identifier') { varNames[node.parent.left.name] = reqid; var cur = node.parent.parent; if (cur.type === 'SequenceExpression') { var ex = cur.expressions; var ix = ex.indexOf(node.parent); if (ix >= 0) ex.splice(ix, 1); updates.push({ start: node.parent.parent.start, offset: node.parent.parent.end - node.parent.parent.start, stream: st(unparse(node.parent.parent)) }); } else { updates.push({ start: node.parent.parent.start, offset: node.parent.parent.end - node.parent.parent.start, stream: st() }); } } else if (isreqm && node.parent.type === 'MemberExpression' && isStaticProperty(node.parent.property) && node.parent.parent.type === 'VariableDeclarator' && node.parent.parent.id.type === 'Identifier') { varNames[node.parent.parent.id.name] = [ reqid, resolveProperty(node.parent.property) ]; var decNode = node.parent.parent.parent; var decs = decNode.declarations; var ix = decs.indexOf(node.parent.parent); if (ix >= 0) decs.splice(ix, 1); updates.push({ start: decNode.start, offset: decNode.end - decNode.start, stream: decs.length ? st(unparse(decNode)) : st() }); } else if (isreqm && node.parent.type === 'MemberExpression' && isStaticProperty(node.parent.property)) { var name = resolveProperty(node.parent.property); var cur = copy(node.parent.parent); cur.callee = copy(node.parent.property); cur.callee.parent = cur; traverse(cur.callee, modules[reqid][name]); } else if (isreqm && node.parent.type === 'CallExpression') { var cur = copy(node.parent); var iname = Math.pow(16,8) * Math.random(); cur.callee = { type: 'Identifier', name: '_' + Math.floor(iname).toString(16), parent: cur }; traverse(cur.callee, modules[reqid]); } if (node.type === 'Identifier' && has(varNames, node.name)) { var vn = varNames[node.name]; if (Array.isArray(vn)) { traverse(node, modules[vn[0]][vn[1]]); } else traverse(node, modules[vn]); } } function traverse (node, val) { for (var p = node; p; p = p.parent) { if (p.start === undefined || p.end === undefined) continue; var key = (p.start + skipOffset) + ',' + (p.end + skipOffset) ; if (skip[key]) { skip[key] = false; return; } } if (skip[key]) { skip[key] = false; return; } if (node.parent.type === 'CallExpression') { if (typeof val !== 'function') { return error( 'tried to statically call ' + inspect(val) + ' as a function' ); } var xvars = copy(vars); xvars[node.name] = val; var res = evaluate(node.parent, xvars); if (res !== undefined) { updates.push({ start: node.parent.start, offset: node.parent.end - node.parent.start, stream: isStream(res) ? wrapStream(res) : st(String(res)) }); } } else if (node.parent.type === 'MemberExpression') { if (!isStaticProperty(node.parent.property)) { return error( 'dynamic property in member expression: ' + node.parent.source() ); } var cur = node.parent.parent; if (cur.type === 'MemberExpression') { cur = cur.parent; if (cur.type !== 'CallExpression' && cur.parent.type === 'CallExpression') { cur = cur.parent; } } if (node.parent.type === 'MemberExpression' && (cur.type !== 'CallExpression' && cur.type !== 'MemberExpression')) { cur = node.parent; } var xvars = copy(vars); xvars[node.name] = val; var res = evaluate(cur, xvars); if (res !== undefined) { updates.push({ start: cur.start, offset: cur.end - cur.start, stream: isStream(res) ? wrapStream(res) : st(String(res)) }); } } else if (node.parent.type === 'UnaryExpression') { var xvars = copy(vars); xvars[node.name] = val; var res = evaluate(node.parent, xvars); if (res !== undefined) { updates.push({ start: node.parent.start, offset: node.parent.end - node.parent.start, stream: isStream(res) ? wrapStream(res) : st(String(res)) }); } else { output.emit('error', new Error( 'unsupported unary operator: ' + node.parent.operator )); } } else { output.emit('error', new Error( 'unsupported type for static module: ' + node.parent.type + '\nat expression:\n\n ' + unparse(node.parent) + '\n' )); } } } function isRequire (node) { var c = node.callee; return c && node.type === 'CallExpression' && c.type === 'Identifier' && c.name === 'require' ; } function isStream (s) { return s && typeof s === 'object' && typeof s.pipe === 'function'; } function wrapStream (s) { if (typeof s.read === 'function') return s else return (new Readable).wrap(s) } function isStaticProperty(node) { return node.type === 'Identifier' || node.type === 'Literal'; } function resolveProperty(node) { return node.type === 'Identifier' ? node.name : node.value; } function st (msg) { var r = new Readable; r._read = function () {}; if (msg != null) r.push(msg); r.push(null); return r; } static-module-1.5.0/package.json000066400000000000000000000017421313716153500165660ustar00rootroot00000000000000{ "name": "static-module", "version": "1.5.0", "description": "convert module usage to inline expressions", "main": "index.js", "dependencies": { "concat-stream": "~1.6.0", "duplexer2": "~0.0.2", "escodegen": "~1.3.2", "falafel": "^2.1.0", "has": "^1.0.0", "object-inspect": "~0.4.0", "quote-stream": "~0.0.0", "readable-stream": "~1.0.27-1", "shallow-copy": "~0.0.1", "static-eval": "~0.2.0", "through2": "~0.4.1" }, "devDependencies": { "resolve": "^1.1.5", "tape": "^3.4.0" }, "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/static-module.git" }, "homepage": "https://github.com/substack/static-module", "keywords": [ "ast", "static", "analysis", "esprima", "syntax", "tree" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } static-module-1.5.0/readme.markdown000066400000000000000000000047351313716153500173060ustar00rootroot00000000000000# static-module convert module usage to inline expressions # example Here's a simplified version of the [brfs](https://npmjs.org/package/brfs) module using static-module. brfs converts `fs.readFileSync(file)` calls to inline strings with the contents of `file` included in-place. ``` js var staticModule = require('static-module'); var quote = require('quote-stream'); var fs = require('fs'); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: __dirname + '/brfs' } }); process.stdin.pipe(sm).pipe(process.stdout); ``` input: ``` $ cat brfs/source.js var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt'); console.log(src); ``` output: ``` $ node brfs.js < brfs/source.js var src = "beep boop\n"; console.log(src); ``` # methods ``` js var staticModule = require('static-module') ``` ## var sm = staticModule(modules, opts={}) Return a transform stream `sm` that transforms javascript source input to javascript source output with each property in the `modules` object expanded in inline form. Properties in the `modules` object can be ordinary values that will be included directly or functions that will be executed with the [statically evaluated](https://npmjs.org/package/static-eval) arguments from the source under an optional set of `opts.vars` variables. Property functions can return streams, in which case their contents will be piped directly into the source output. Otherwise, the return values of functions will be inlined into the source in place as strings. Use `opts.varModules` to map whitelisted module names to definitions that can be declared in client code with `var` and will appear in static expressions like `opts.vars`. For example, to make this code with `path.join()` work: ``` js var fs = require('fs'); var path = require('path'); var src = fs.readFileSync(path.join(__dirname, 'x.txt'), 'utf8'); console.log(src); ``` you can do: ``` js var staticModule = require('static-module'); var quote = require('quote-stream'); var fs = require('fs'); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } }, varMods: { path: require('path') } }, { vars: { __dirname: __dirname + '/brfs' } }); process.stdin.pipe(sm).pipe(process.stdout); ``` # install With [npm](https://npmjs.org) do: ``` npm install static-module ``` # license MIT static-module-1.5.0/test/000077500000000000000000000000001313716153500152535ustar00rootroot00000000000000static-module-1.5.0/test/assign.js000066400000000000000000000023701313716153500170770ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('assign', function (t) { t.plan(3); var expected = [ 12, 555 ]; var sm = staticModule({ beep: { x: 4, f: function (n) { return n * 111 } } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), '\nconsole.log(4 * 3);' + '\nconsole.log(555);\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('assign comma', function (t) { t.plan(3); var expected = [ 12, 555 ]; var sm = staticModule({ beep: { x: 4, f: function (n) { return n * 111 } } }); readStream('comma.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'x = 5;\n' + 'console.log(4 * 3);\n' + 'console.log(555);\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'assign', file)); } static-module-1.5.0/test/assign/000077500000000000000000000000001313716153500165375ustar00rootroot00000000000000static-module-1.5.0/test/assign/comma.js000066400000000000000000000001071313716153500201670ustar00rootroot00000000000000x = 5, b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-1.5.0/test/assign/source.js000066400000000000000000000001001313716153500203640ustar00rootroot00000000000000b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-1.5.0/test/brfs.js000066400000000000000000000136021313716153500165470ustar00rootroot00000000000000var staticModule = require('../'); var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var fs = require('fs'); var path = require('path'); var vm = require('vm'); test('readFileSync', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('attribute.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute with multiple vars', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('attribute_vars.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'var x = 5, y = 2;' + '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute with multiple require vars', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('multi_require.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'var x = 5;' + '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute with multiple require vars including an uninitalized var', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('multi_require_with_uninitialized.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'var x;' + '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute with multiple require vars x5', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('x5.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8').replace(/;/g,''), 'var a = 1, b = 2, c = 3, d = 4, ' + 'src = "beep boop\\n",\n' + ' e = 5\n' + 'console.log(src)\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync with bracket notation', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('brackets.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('readFileSync attribute bracket notation', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('attribute_brackets.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), '\nvar src = "beep boop\\n";' + '\nconsole.log(src);\n' ); vm.runInNewContext(body.toString('utf8'), { console: { log: log } }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'brfs', file)); } static-module-1.5.0/test/brfs/000077500000000000000000000000001313716153500162075ustar00rootroot00000000000000static-module-1.5.0/test/brfs/attribute.js000066400000000000000000000001411313716153500205440ustar00rootroot00000000000000var f = require('fs').readFileSync; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/attribute_brackets.js000066400000000000000000000001441313716153500224250ustar00rootroot00000000000000var f = require('fs')["readFileSync"]; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/attribute_vars.js000066400000000000000000000001571313716153500216060ustar00rootroot00000000000000var x = 5, f = require('fs').readFileSync, y = 2; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/brackets.js000066400000000000000000000001461313716153500203440ustar00rootroot00000000000000var fs = require('fs'); var src = fs["readFileSync"](__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/multi_require.js000066400000000000000000000001521313716153500214310ustar00rootroot00000000000000var fs = require('fs'), x = 5; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/multi_require_with_uninitialized.js000066400000000000000000000001461313716153500254170ustar00rootroot00000000000000var fs = require('fs'), x; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/source.js000066400000000000000000000001431313716153500200430ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-1.5.0/test/brfs/x.txt000066400000000000000000000000121313716153500172100ustar00rootroot00000000000000beep boop static-module-1.5.0/test/brfs/x5.js000066400000000000000000000002071313716153500171000ustar00rootroot00000000000000var a = 1, b = 2, fs = require('fs'), c = 3, d = 4, src = fs.readFileSync(__dirname + '/x.txt', 'utf8'), e = 5 ; console.log(src); static-module-1.5.0/test/fn.js000066400000000000000000000010521313716153500162120ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('function', function (t) { t.plan(1); var sm = staticModule({ beep: function (n) { return n * 111 } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 555) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'fn', file)); } static-module-1.5.0/test/fn/000077500000000000000000000000001313716153500156565ustar00rootroot00000000000000static-module-1.5.0/test/fn/source.js000066400000000000000000000000541313716153500175130ustar00rootroot00000000000000var b = require('beep'); console.log(b(5)); static-module-1.5.0/test/fs.js000066400000000000000000000034541313716153500162270ustar00rootroot00000000000000var staticModule = require('../'); var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var through = require('through2'); var fs = require('fs'); var path = require('path'); test('fs.readFile', function (t) { t.plan(2); var sm = staticModule({ fs: { readFile: readFile } }, { vars: { __dirname: __dirname + '/fs' } }); readStream('readfile.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8').replace(/;/g,'').trim(), 'process.nextTick(function(){(function (err, src) {\n' + ' console.log(src)\n' + '})(null,"beep boop\\n")})' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 'beep boop\n') } })); }); test('fs.readFileSync', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: readFileSync } }, { vars: { __dirname: __dirname + '/fs' } }); readStream('html.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'var html = "EXTERMINATE\\n";\n' + 'console.log(html);\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 'EXTERMINATE\n') } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'fs', file)); } function readFile (file, cb) { var stream = through(write, end); stream.push('process.nextTick(function(){(' + cb + ')(null,'); return fs.createReadStream(file).pipe(quote()).pipe(stream); function write (buf, enc, next) { this.push(buf); next() } function end (next) { this.push(')})'); this.push(null); next() } } function readFileSync (file, opts) { return fs.createReadStream(file).pipe(quote()); } static-module-1.5.0/test/fs/000077500000000000000000000000001313716153500156635ustar00rootroot00000000000000static-module-1.5.0/test/fs/html.js000066400000000000000000000001351313716153500171640ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); static-module-1.5.0/test/fs/readfile.js000066400000000000000000000001511313716153500177710ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-1.5.0/test/fs/robot.html000066400000000000000000000000141313716153500176710ustar00rootroot00000000000000EXTERMINATE static-module-1.5.0/test/fs/x.txt000066400000000000000000000000121313716153500166640ustar00rootroot00000000000000beep boop static-module-1.5.0/test/fs_twice.js000066400000000000000000000055741313716153500174270ustar00rootroot00000000000000var staticModule = require('../'); var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var through = require('through2'); var fs = require('fs'); var path = require('path'); test('fs.readFileSync twice', function (t) { var expected = [ 'EXTERMINATE\n', 'beep boop\n' ]; t.plan(expected.length + 1); var sm = staticModule({ fs: { readFileSync: readFileSync } }, { vars: { __dirname: __dirname + '/fs_twice' } }); readStream('html.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'var a = "EXTERMINATE\\n";\n' + 'var b = "beep boop\\n";\n' + 'console.log(a);\n' + 'console.log(b);\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('fs.readFileSync twice in vars', function (t) { var expected = [ 'EXTERMINATE\n', 'beep boop\n' ]; t.plan(expected.length + 1); var sm = staticModule({ fs: { readFileSync: readFileSync } }, { vars: { __dirname: __dirname + '/fs_twice' } }); readStream('vars.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8').trim(), 'var a = "EXTERMINATE\\n",\n' + ' b = "beep boop\\n";\n' + 'console.log(a);\n' + 'console.log(b);' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('fs.readFileSync 4x', function (t) { var expected = [ 'EXTERMINATE\n', 'beep boop\n', 'EXTERMINATE\n', 'beep boop\n' ]; t.plan(expected.length + 1); var sm = staticModule({ fs: { readFileSync: readFileSync } }, { vars: { __dirname: __dirname + '/fs_twice' } }); readStream('4x.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8').trim(), 'var a = "EXTERMINATE\\n";\n' + 'var b = "beep boop\\n";\n' + 'var c = "EXTERMINATE\\n";\n' + 'var d = "beep boop\\n";\n' + 'console.log(a);\n' + 'console.log(b);\n' + 'console.log(c);\n' + 'console.log(d);' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'fs_twice', file)); } function readFile (file, cb) { var stream = through(write, end); stream.push('process.nextTick(function(){(' + cb + ')(null,'); return fs.createReadStream(file).pipe(quote()).pipe(stream); function write (buf, enc, next) { this.push(buf); next() } function end (next) { this.push(')})'); this.push(null); next() } } function readFileSync (file, opts) { return fs.createReadStream(file).pipe(quote()); } static-module-1.5.0/test/fs_twice/000077500000000000000000000000001313716153500170565ustar00rootroot00000000000000static-module-1.5.0/test/fs_twice/4x.js000066400000000000000000000004761313716153500177560ustar00rootroot00000000000000var fs = require('fs'); var a = fs.readFileSync(__dirname + '/robot.html', 'utf8'); var b = fs.readFileSync(__dirname + '/x.txt', 'utf8'); var c = fs.readFileSync(__dirname + '/robot.html', 'utf8'); var d = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(a); console.log(b); console.log(c); console.log(d); static-module-1.5.0/test/fs_twice/html.js000066400000000000000000000002511313716153500203560ustar00rootroot00000000000000var a = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); var b = require('fs').readFileSync(__dirname + '/x.txt', 'utf8'); console.log(a); console.log(b); static-module-1.5.0/test/fs_twice/readfile.js000066400000000000000000000001511313716153500211640ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-1.5.0/test/fs_twice/robot.html000066400000000000000000000000141313716153500210640ustar00rootroot00000000000000EXTERMINATE static-module-1.5.0/test/fs_twice/vars.js000066400000000000000000000002531313716153500203670ustar00rootroot00000000000000var fs = require('fs'); var a = fs.readFileSync(__dirname + '/robot.html', 'utf8'), b = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(a); console.log(b); static-module-1.5.0/test/fs_twice/x.txt000066400000000000000000000000121313716153500200570ustar00rootroot00000000000000beep boop static-module-1.5.0/test/inline.js000066400000000000000000000042301313716153500170660ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('inline object', function (t) { t.plan(1); var sm = staticModule({ beep: { f: function (n) { return n * 111 } } }); readStream('obj.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 555) } })); }); test('inline object call', function (t) { t.plan(1); var sm = staticModule({ beep: { f: function (n) { return n * 111 } } }); readStream('obj_call.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 555) } })); }); test('inline object expression', function (t) { t.plan(1); var sm = staticModule({ beep: { f: function (n) { return n * 111 } } }); readStream('obj_expr.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 1110) } })); }); test('inline function', function (t) { t.plan(1); var sm = staticModule({ beep: function (n) { return n * 111 } }); readStream('fn.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 555) } })); }); test('inline function call', function (t) { t.plan(1); var sm = staticModule({ beep: function (n) { return n * 111 } }); readStream('fn_call.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 555) } })); }); test('inline function expression', function (t) { t.plan(1); var sm = staticModule({ beep: function (n) { return n * 111 } }); readStream('fn_expr.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 1665) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'inline', file)); } static-module-1.5.0/test/inline/000077500000000000000000000000001313716153500165315ustar00rootroot00000000000000static-module-1.5.0/test/inline/fn.js000066400000000000000000000000541313716153500174710ustar00rootroot00000000000000var x = require('beep')(5); console.log(x); static-module-1.5.0/test/inline/fn_call.js000066400000000000000000000000411313716153500204600ustar00rootroot00000000000000console.log(require('beep')(5)); static-module-1.5.0/test/inline/fn_expr.js000066400000000000000000000000451313716153500205270ustar00rootroot00000000000000console.log(require('beep')(5) * 3); static-module-1.5.0/test/inline/obj.js000066400000000000000000000000561313716153500176420ustar00rootroot00000000000000var x = require('beep').f(5); console.log(x); static-module-1.5.0/test/inline/obj_call.js000066400000000000000000000000431313716153500206310ustar00rootroot00000000000000console.log(require('beep').f(5)); static-module-1.5.0/test/inline/obj_expr.js000066400000000000000000000000471313716153500207000ustar00rootroot00000000000000console.log(require('beep').f(5) * 2); static-module-1.5.0/test/log.js000066400000000000000000000026101313716153500163710ustar00rootroot00000000000000var staticModule = require('../'); var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var fs = require('fs'); var path = require('path'); test('stream into a console.log', function (t) { t.plan(1); var sm = staticModule({ beep: function () { var q = quote(); q.end('eek'); return q; } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'console.log("eek");\n'); })); }); test('trickle stream into a console.log', function (t) { t.plan(1); var sm = staticModule({ beep: function () { var q = quote(); var chunks = [ 'beep', ' boop', ' robots' ]; var iv = setInterval(function () { if (chunks.length === 0) { clearInterval(iv); q.end(); } else q.write(chunks.shift()); }, 10); return q; } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), 'console.log("beep boop robots");\n'); })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'log', file)); } static-module-1.5.0/test/log/000077500000000000000000000000001313716153500160345ustar00rootroot00000000000000static-module-1.5.0/test/log/source.js000066400000000000000000000000401313716153500176640ustar00rootroot00000000000000console.log(require('beep')()); static-module-1.5.0/test/many.js000066400000000000000000000044321313716153500165600ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('many instances', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'many') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8'), '\nvar a = "A!\\n";\n' + 'var b = "B!\\n";\n' + 'var c = "C!\\n";\n' + 'console.log(a + b + c);\n' ); function log (msg) { t.equal(msg, 'A!\nB!\nC!\n') } })); }); test('expansions inline', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'many') } }); readStream('inline.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8'), '\nvar a = "A!\\n",\n' + ' b = "B!\\n",\n' + ' c = "C!\\n"\n' + ';\n' + 'console.log(a + b + c);\n' ); function log (msg) { t.equal(msg, 'A!\nB!\nC!\n') } })); }); test('all inline', function (t) { t.plan(2); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'many') } }); readStream('all_inline.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8').replace(/;/g,''), 'var a = "A!\\n",\n' + ' b = "B!\\n",\n' + ' c = "C!\\n"\n' + 'console.log(a + b + c)\n' ); function log (msg) { t.equal(msg, 'A!\nB!\nC!\n') } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'many', file)); } static-module-1.5.0/test/many/000077500000000000000000000000001313716153500162175ustar00rootroot00000000000000static-module-1.5.0/test/many/a.txt000066400000000000000000000000031313716153500171710ustar00rootroot00000000000000A! static-module-1.5.0/test/many/all_inline.js000066400000000000000000000003261313716153500206640ustar00rootroot00000000000000var fs = require('fs'), a = fs.readFileSync(__dirname + '/a.txt', 'utf8'), b = fs.readFileSync(__dirname + '/b.txt', 'utf8'), c = fs.readFileSync(__dirname + '/c.txt', 'utf8') ; console.log(a + b + c); static-module-1.5.0/test/many/b.txt000066400000000000000000000000031313716153500171720ustar00rootroot00000000000000B! static-module-1.5.0/test/many/c.txt000066400000000000000000000000031313716153500171730ustar00rootroot00000000000000C! static-module-1.5.0/test/many/inline.js000066400000000000000000000003261313716153500200340ustar00rootroot00000000000000var fs = require('fs'); var a = fs.readFileSync(__dirname + '/a.txt', 'utf8'), b = fs.readFileSync(__dirname + '/b.txt', 'utf8'), c = fs.readFileSync(__dirname + '/c.txt', 'utf8') ; console.log(a + b + c); static-module-1.5.0/test/many/source.js000066400000000000000000000003251313716153500200550ustar00rootroot00000000000000var fs = require('fs'); var a = fs.readFileSync(__dirname + '/a.txt', 'utf8'); var b = fs.readFileSync(__dirname + '/b.txt', 'utf8'); var c = fs.readFileSync(__dirname + '/c.txt', 'utf8'); console.log(a + b + c); static-module-1.5.0/test/mixed.js000066400000000000000000000036421313716153500167240ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('mixed nested objects and streams', function (t) { t.plan(4); var expected = [ 12, 'oh hello\n', 555 ]; var sm = staticModule({ beep: { x: { y: { z: 4 } }, quote: { read: function (file) { return fs.createReadStream(file).pipe(quote()); } }, f: { g: { h: function (n) { return n * 111 } } } } }, { vars: { __dirname: path.join(__dirname, 'mixed') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8'), '\nconsole.log(4 * 3);' + '\nconsole.log("oh hello\\n");' + '\nconsole.log(555);\n' ); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('mixed objects and streams', function (t) { t.plan(4); var expected = [ 12, 'oh hello\n', 555 ]; var sm = staticModule({ beep: { x: 4, quote: function (file) { return fs.createReadStream(file).pipe(quote()); }, f: function (n) { return n * 111 } } }, { vars: { __dirname: path.join(__dirname, 'mixed') } }); readStream('unmixed.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8'), '\nconsole.log(4 * 3);' + '\nconsole.log("oh hello\\n");' + '\nconsole.log(555);\n' ); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'mixed', file)); } static-module-1.5.0/test/mixed/000077500000000000000000000000001313716153500163615ustar00rootroot00000000000000static-module-1.5.0/test/mixed/source.js000066400000000000000000000001771313716153500202240ustar00rootroot00000000000000var b = require('beep'); console.log(b.x.y.z * 3); console.log(b.quote.read(__dirname + '/xyz.txt')); console.log(b.f.g.h(5)); static-module-1.5.0/test/mixed/unmixed.js000066400000000000000000000001621313716153500203670ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.quote(__dirname + '/xyz.txt')); console.log(b.f(5)); static-module-1.5.0/test/mixed/xyz.txt000066400000000000000000000000111313716153500177440ustar00rootroot00000000000000oh hello static-module-1.5.0/test/nested.js000066400000000000000000000014551313716153500171000ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('nested object', function (t) { t.plan(3); var expected = [ 12, 555 ]; var sm = staticModule({ beep: { x: { y: { z: 4 } }, f: { g: { h: function (n) { return n * 111 } } } } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); t.equal( body.toString('utf8'), '\nconsole.log(4 * 3);\nconsole.log(555);\n' ); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'nested', file)); } static-module-1.5.0/test/nested/000077500000000000000000000000001313716153500165355ustar00rootroot00000000000000static-module-1.5.0/test/nested/source.js000066400000000000000000000001141313716153500203670ustar00rootroot00000000000000var b = require('beep'); console.log(b.x.y.z * 3); console.log(b.f.g.h(5)); static-module-1.5.0/test/obj.js000066400000000000000000000011571313716153500163670ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('object', function (t) { t.plan(2); var expected = [ 12, 555 ]; var sm = staticModule({ beep: { x: 4, f: function (n) { return n * 111 } } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'obj', file)); } static-module-1.5.0/test/obj/000077500000000000000000000000001313716153500160255ustar00rootroot00000000000000static-module-1.5.0/test/obj/source.js000066400000000000000000000001041313716153500176560ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-1.5.0/test/prop.js000066400000000000000000000011261313716153500165710ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('property', function (t) { t.plan(1); var sm = staticModule({ fff: function (n) { return '[' + (n * 111) + ']' } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.deepEqual(msg, '[object Array]') } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'prop', file)); } static-module-1.5.0/test/prop/000077500000000000000000000000001313716153500162335ustar00rootroot00000000000000static-module-1.5.0/test/prop/source.js000066400000000000000000000001441313716153500200700ustar00rootroot00000000000000var f = require('fff'); var toString = Object.prototype.toString; console.log(toString.call(f(5))); static-module-1.5.0/test/readfile_resolve.js000066400000000000000000000017711313716153500211310ustar00rootroot00000000000000var staticModule = require('../'); var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var through = require('through2'); var fs = require('fs'); var path = require('path'); var resolve = require('resolve'); test('readFileSync of require.resolve()', function (t) { t.plan(1); var dir = __dirname + '/readfile_resolve'; function rres (p) { return resolve.sync(p, { basedir: dir }) } var vars = { __dirname: dir, require: { resolve: rres } }; var sm = staticModule({ fs: { readFileSync: readFileSync } }, { vars: vars }); readStream('main.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, 'amaze\n') } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'readfile_resolve', file)); } function readFileSync (file, opts) { return fs.createReadStream(file).pipe(quote()); } static-module-1.5.0/test/readfile_resolve/000077500000000000000000000000001313716153500205655ustar00rootroot00000000000000static-module-1.5.0/test/readfile_resolve/main.js000066400000000000000000000001541313716153500220470ustar00rootroot00000000000000var fs = require('fs') var src = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(src); static-module-1.5.0/test/readfile_resolve/node_modules/000077500000000000000000000000001313716153500232425ustar00rootroot00000000000000static-module-1.5.0/test/readfile_resolve/node_modules/aaa/000077500000000000000000000000001313716153500237645ustar00rootroot00000000000000static-module-1.5.0/test/readfile_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061313716153500253350ustar00rootroot00000000000000amaze static-module-1.5.0/test/shebang.js000066400000000000000000000011641313716153500172220ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('shebang', function (t) { t.plan(2); var expected = [ 12, 555 ]; var sm = staticModule({ beep: { x: 4, f: function (n) { return n * 111 } } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'shebang', file)); } static-module-1.5.0/test/shebang/000077500000000000000000000000001313716153500166625ustar00rootroot00000000000000static-module-1.5.0/test/shebang/source.js000066400000000000000000000001301313716153500205120ustar00rootroot00000000000000#!/usr/bin/env node var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-1.5.0/test/unary.js000066400000000000000000000015631313716153500167540ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('supported unary operator', function (t) { t.plan(1); var expected = [ false ]; var sm = staticModule({ beep: { x: 42 } }); readStream('supported.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('unsupported unary operator', function (t) { t.plan(1) var sm = staticModule({ beep: { x: 42 } }); readStream('unsupported.js').pipe(sm).on('error', function (error) { t.equal(error.message, 'unsupported unary operator: typeof') }) }) function readStream (file) { return fs.createReadStream(path.join(__dirname, 'unary', file)); } static-module-1.5.0/test/unary/000077500000000000000000000000001313716153500164115ustar00rootroot00000000000000static-module-1.5.0/test/unary/supported.js000066400000000000000000000000561313716153500207750ustar00rootroot00000000000000var beep = require('beep') console.log(!beep) static-module-1.5.0/test/unary/unsupported.js000066400000000000000000000000641313716153500213370ustar00rootroot00000000000000var beep = require('beep') console.log(typeof beep) static-module-1.5.0/test/varmod.js000066400000000000000000000021351313716153500171020ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('variable modules', function (t) { t.plan(2); var expected = [ 'beep boop!' ]; var sm = staticModule({ fs: { readFileSync: function (file, enc) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'vars') }, varModules: { path: require('path') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal( body.toString('utf8'), '\nvar path = require(\'path\');' + '\nvar html = "beep boop";\nvar x = \'!\';' + '\nconsole.log(html + x);\n' ); Function(['console','require'],body)({ log: log },require); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'varmod', file)); } static-module-1.5.0/test/varmod/000077500000000000000000000000001313716153500165435ustar00rootroot00000000000000static-module-1.5.0/test/varmod/source.js000066400000000000000000000002371313716153500204030ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(path.join(__dirname, 'vars.html'), 'utf8'); var x = '!'; console.log(html + x); static-module-1.5.0/test/varmod/vars.html000066400000000000000000000000111313716153500203740ustar00rootroot00000000000000beep boopstatic-module-1.5.0/test/vars.js000066400000000000000000000053051313716153500165670ustar00rootroot00000000000000var test = require('tape'); var concat = require('concat-stream'); var quote = require('quote-stream'); var staticModule = require('../'); var fs = require('fs'); var path = require('path'); test('multi-vars', function (t) { t.plan(2); var expected = [ 'beep boop!' ]; var sm = staticModule({ fs: { readFileSync: function (file, enc) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'vars') } }); readStream('source.js').pipe(sm).pipe(concat(function (body) { t.equal( body.toString('utf8').replace(/;/g,''), 'var html = "beep boop",\n x = \'!\'\nconsole.log(html + x)\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('2-var', function (t) { t.plan(2); var expected = [ 'beep boop' ]; var sm = staticModule({ fs: { readFileSync: function (file, enc) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'vars') } }); readStream('one.js').pipe(sm).pipe(concat(function (body) { t.equal( body.toString('utf8').replace(/;/g,''), 'var html = "beep boop"\nconsole.log(html)\n' ); Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('5-var', function (t) { t.plan(1); var expected = [ 'beep boop123' ]; var sm = staticModule({ fs: { readFileSync: function (file, enc) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'vars') } }); readStream('five.js').pipe(sm).pipe(concat(function (body) { Function(['console'],body)({ log: log }); function log (msg) { t.equal(msg, expected.shift()) } })); }); test('multi consecutive require vars', function (t) { t.plan(1); var expected = [ 'beep boop' ]; var sm = staticModule({ fs: { readFileSync: function (file, enc) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'vars') } }); readStream('multi-require.js').pipe(sm).pipe(concat(function (body) { Function(['console','require'],body)({ log: log }, function() { return {} }); function log (msg) { t.equal(msg, expected.shift()) } })); }); function readStream (file) { return fs.createReadStream(path.join(__dirname, 'vars', file)); } static-module-1.5.0/test/vars/000077500000000000000000000000001313716153500162265ustar00rootroot00000000000000static-module-1.5.0/test/vars/five.js000066400000000000000000000002151313716153500175130ustar00rootroot00000000000000var a = 1, fs = require('fs'), b = 2, html = fs.readFileSync(__dirname + '/vars.html', 'utf8'), c = 3 ; console.log(html + a + b + c); static-module-1.5.0/test/vars/multi-require.js000066400000000000000000000005751313716153500213770ustar00rootroot00000000000000var fs = require('fs'), tls = require('tls'), zlib = require('zlib'), Socket = require('net').Socket, EventEmitter = require('events').EventEmitter, inherits = require('util').inherits, inspect = require('util').inspect; var foo = require('foo'); var bar = require('bar'); var html = fs.readFileSync(__dirname + '/vars.html', 'utf8'); console.log(html); static-module-1.5.0/test/vars/one.js000066400000000000000000000001501313716153500173410ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8') ; console.log(html); static-module-1.5.0/test/vars/source.js000066400000000000000000000001671313716153500200700ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8'), x = '!' ; console.log(html + x); static-module-1.5.0/test/vars/vars.html000066400000000000000000000000111313716153500200570ustar00rootroot00000000000000beep boop