pax_global_header00006660000000000000000000000064132340401230014502gustar00rootroot0000000000000052 comment=74dcb7e772d242af8f0731b7e21a38393d71386d static-module-2.1.1/000077500000000000000000000000001323404012300142555ustar00rootroot00000000000000static-module-2.1.1/.travis.yml000066400000000000000000000000771323404012300163720ustar00rootroot00000000000000language: node_js node_js: - 9 - 8 - 6 - 4 - "0.10" static-module-2.1.1/LICENSE000066400000000000000000000020611323404012300152610ustar00rootroot00000000000000This 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-2.1.1/example/000077500000000000000000000000001323404012300157105ustar00rootroot00000000000000static-module-2.1.1/example/brfs.js000066400000000000000000000005261323404012300172050ustar00rootroot00000000000000var 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-2.1.1/example/brfs/000077500000000000000000000000001323404012300166445ustar00rootroot00000000000000static-module-2.1.1/example/brfs/source.js000066400000000000000000000001331323404012300204770ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt'); console.log(src); static-module-2.1.1/example/brfs/x.txt000066400000000000000000000000121323404012300176450ustar00rootroot00000000000000beep boop static-module-2.1.1/example/fs.js000066400000000000000000000014161323404012300166600ustar00rootroot00000000000000var 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-2.1.1/example/fs/000077500000000000000000000000001323404012300163205ustar00rootroot00000000000000static-module-2.1.1/example/fs/source.js000066400000000000000000000001511323404012300201530ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.1.1/example/fs/x.txt000066400000000000000000000000121323404012300173210ustar00rootroot00000000000000beep boop static-module-2.1.1/index.js000066400000000000000000000326721323404012300157340ustar00rootroot00000000000000var 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 parserOpts = opts.parserOpts || { ecmaVersion: 8 }; var updates = []; var output = through(); var body; return duplexer(concat(function (buf) { try { body = buf.toString('utf8').replace(/^#!/, '//#!'); falafel(body, parserOpts, 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 && cur.type === 'CallExpression') { // static-eval can't safely evaluate code with callbacks, so do it manually in a safe way var callee = evaluate(cur.callee, xvars); var args = cur.arguments.map(function (arg) { // Return a function stub for callbacks so that `static-module` users // can do `callback.toString()` and get the original source if (arg.type === 'FunctionExpression' || arg.type === 'ArrowFunctionExpression') { var fn = function () { throw new Error('static-module: cannot call callbacks defined inside source code'); }; fn.toString = function () { return body.slice(arg.start, arg.end); }; return fn; } return evaluate(arg, xvars); }); if (callee !== undefined) { try { res = callee.apply(null, args); } catch (err) { // Evaluate to undefined } } } 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-2.1.1/package.json000066400000000000000000000017371323404012300165530ustar00rootroot00000000000000{ "name": "static-module", "version": "2.1.1", "description": "convert module usage to inline expressions", "main": "index.js", "dependencies": { "concat-stream": "~1.6.0", "duplexer2": "~0.1.4", "escodegen": "~1.9.0", "falafel": "^2.1.0", "has": "^1.0.1", "object-inspect": "~1.4.0", "quote-stream": "~1.0.2", "readable-stream": "~2.3.3", "shallow-copy": "~0.0.1", "static-eval": "^2.0.0", "through2": "~2.0.3" }, "devDependencies": { "resolve": "^1.5.0", "tape": "^4.8.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-2.1.1/readme.markdown000066400000000000000000000051101323404012300172530ustar00rootroot00000000000000# 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); ``` Use `opts.parserOpts` to set additional options for the [acorn](https://github.com/acornjs/acorn) parser. # install With [npm](https://npmjs.org) do: ``` npm install static-module ``` # license MIT static-module-2.1.1/test/000077500000000000000000000000001323404012300152345ustar00rootroot00000000000000static-module-2.1.1/test/assign.js000066400000000000000000000023701323404012300170600ustar00rootroot00000000000000var 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-2.1.1/test/assign/000077500000000000000000000000001323404012300165205ustar00rootroot00000000000000static-module-2.1.1/test/assign/comma.js000066400000000000000000000001071323404012300201500ustar00rootroot00000000000000x = 5, b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.1.1/test/assign/source.js000066400000000000000000000001001323404012300203450ustar00rootroot00000000000000b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.1.1/test/brfs.js000066400000000000000000000136021323404012300165300ustar00rootroot00000000000000var 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-2.1.1/test/brfs/000077500000000000000000000000001323404012300161705ustar00rootroot00000000000000static-module-2.1.1/test/brfs/attribute.js000066400000000000000000000001411323404012300205250ustar00rootroot00000000000000var f = require('fs').readFileSync; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/attribute_brackets.js000066400000000000000000000001441323404012300224060ustar00rootroot00000000000000var f = require('fs')["readFileSync"]; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/attribute_vars.js000066400000000000000000000001571323404012300215670ustar00rootroot00000000000000var x = 5, f = require('fs').readFileSync, y = 2; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/brackets.js000066400000000000000000000001461323404012300203250ustar00rootroot00000000000000var fs = require('fs'); var src = fs["readFileSync"](__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/multi_require.js000066400000000000000000000001521323404012300214120ustar00rootroot00000000000000var fs = require('fs'), x = 5; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/multi_require_with_uninitialized.js000066400000000000000000000001461323404012300254000ustar00rootroot00000000000000var fs = require('fs'), x; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/source.js000066400000000000000000000001431323404012300200240ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.1.1/test/brfs/x.txt000066400000000000000000000000121323404012300171710ustar00rootroot00000000000000beep boop static-module-2.1.1/test/brfs/x5.js000066400000000000000000000002071323404012300170610ustar00rootroot00000000000000var 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-2.1.1/test/fn.js000066400000000000000000000010521323404012300161730ustar00rootroot00000000000000var 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-2.1.1/test/fn/000077500000000000000000000000001323404012300156375ustar00rootroot00000000000000static-module-2.1.1/test/fn/source.js000066400000000000000000000000541323404012300174740ustar00rootroot00000000000000var b = require('beep'); console.log(b(5)); static-module-2.1.1/test/fs.js000066400000000000000000000034541323404012300162100ustar00rootroot00000000000000var 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-2.1.1/test/fs/000077500000000000000000000000001323404012300156445ustar00rootroot00000000000000static-module-2.1.1/test/fs/html.js000066400000000000000000000001351323404012300171450ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); static-module-2.1.1/test/fs/readfile.js000066400000000000000000000001511323404012300177520ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.1.1/test/fs/robot.html000066400000000000000000000000141323404012300176520ustar00rootroot00000000000000EXTERMINATE static-module-2.1.1/test/fs/x.txt000066400000000000000000000000121323404012300166450ustar00rootroot00000000000000beep boop static-module-2.1.1/test/fs_twice.js000066400000000000000000000055741323404012300174100ustar00rootroot00000000000000var 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-2.1.1/test/fs_twice/000077500000000000000000000000001323404012300170375ustar00rootroot00000000000000static-module-2.1.1/test/fs_twice/4x.js000066400000000000000000000004761323404012300177370ustar00rootroot00000000000000var 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-2.1.1/test/fs_twice/html.js000066400000000000000000000002511323404012300203370ustar00rootroot00000000000000var 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-2.1.1/test/fs_twice/readfile.js000066400000000000000000000001511323404012300211450ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.1.1/test/fs_twice/robot.html000066400000000000000000000000141323404012300210450ustar00rootroot00000000000000EXTERMINATE static-module-2.1.1/test/fs_twice/vars.js000066400000000000000000000002531323404012300203500ustar00rootroot00000000000000var 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-2.1.1/test/fs_twice/x.txt000066400000000000000000000000121323404012300200400ustar00rootroot00000000000000beep boop static-module-2.1.1/test/inline.js000066400000000000000000000042301323404012300170470ustar00rootroot00000000000000var 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-2.1.1/test/inline/000077500000000000000000000000001323404012300165125ustar00rootroot00000000000000static-module-2.1.1/test/inline/fn.js000066400000000000000000000000541323404012300174520ustar00rootroot00000000000000var x = require('beep')(5); console.log(x); static-module-2.1.1/test/inline/fn_call.js000066400000000000000000000000411323404012300204410ustar00rootroot00000000000000console.log(require('beep')(5)); static-module-2.1.1/test/inline/fn_expr.js000066400000000000000000000000451323404012300205100ustar00rootroot00000000000000console.log(require('beep')(5) * 3); static-module-2.1.1/test/inline/obj.js000066400000000000000000000000561323404012300176230ustar00rootroot00000000000000var x = require('beep').f(5); console.log(x); static-module-2.1.1/test/inline/obj_call.js000066400000000000000000000000431323404012300206120ustar00rootroot00000000000000console.log(require('beep').f(5)); static-module-2.1.1/test/inline/obj_expr.js000066400000000000000000000000471323404012300206610ustar00rootroot00000000000000console.log(require('beep').f(5) * 2); static-module-2.1.1/test/log.js000066400000000000000000000026101323404012300163520ustar00rootroot00000000000000var 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-2.1.1/test/log/000077500000000000000000000000001323404012300160155ustar00rootroot00000000000000static-module-2.1.1/test/log/source.js000066400000000000000000000000401323404012300176450ustar00rootroot00000000000000console.log(require('beep')()); static-module-2.1.1/test/many.js000066400000000000000000000044321323404012300165410ustar00rootroot00000000000000var 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-2.1.1/test/many/000077500000000000000000000000001323404012300162005ustar00rootroot00000000000000static-module-2.1.1/test/many/a.txt000066400000000000000000000000031323404012300171520ustar00rootroot00000000000000A! static-module-2.1.1/test/many/all_inline.js000066400000000000000000000003261323404012300206450ustar00rootroot00000000000000var 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-2.1.1/test/many/b.txt000066400000000000000000000000031323404012300171530ustar00rootroot00000000000000B! static-module-2.1.1/test/many/c.txt000066400000000000000000000000031323404012300171540ustar00rootroot00000000000000C! static-module-2.1.1/test/many/inline.js000066400000000000000000000003261323404012300200150ustar00rootroot00000000000000var 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-2.1.1/test/many/source.js000066400000000000000000000003251323404012300200360ustar00rootroot00000000000000var 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-2.1.1/test/mixed.js000066400000000000000000000036421323404012300167050ustar00rootroot00000000000000var 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-2.1.1/test/mixed/000077500000000000000000000000001323404012300163425ustar00rootroot00000000000000static-module-2.1.1/test/mixed/source.js000066400000000000000000000001771323404012300202050ustar00rootroot00000000000000var 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-2.1.1/test/mixed/unmixed.js000066400000000000000000000001621323404012300203500ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.quote(__dirname + '/xyz.txt')); console.log(b.f(5)); static-module-2.1.1/test/mixed/xyz.txt000066400000000000000000000000111323404012300177250ustar00rootroot00000000000000oh hello static-module-2.1.1/test/nested.js000066400000000000000000000014551323404012300170610ustar00rootroot00000000000000var 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-2.1.1/test/nested/000077500000000000000000000000001323404012300165165ustar00rootroot00000000000000static-module-2.1.1/test/nested/source.js000066400000000000000000000001141323404012300203500ustar00rootroot00000000000000var b = require('beep'); console.log(b.x.y.z * 3); console.log(b.f.g.h(5)); static-module-2.1.1/test/obj.js000066400000000000000000000011571323404012300163500ustar00rootroot00000000000000var 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-2.1.1/test/obj/000077500000000000000000000000001323404012300160065ustar00rootroot00000000000000static-module-2.1.1/test/obj/source.js000066400000000000000000000001041323404012300176370ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.1.1/test/prop.js000066400000000000000000000011261323404012300165520ustar00rootroot00000000000000var 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-2.1.1/test/prop/000077500000000000000000000000001323404012300162145ustar00rootroot00000000000000static-module-2.1.1/test/prop/source.js000066400000000000000000000001441323404012300200510ustar00rootroot00000000000000var f = require('fff'); var toString = Object.prototype.toString; console.log(toString.call(f(5))); static-module-2.1.1/test/readfile_resolve.js000066400000000000000000000017711323404012300211120ustar00rootroot00000000000000var 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-2.1.1/test/readfile_resolve/000077500000000000000000000000001323404012300205465ustar00rootroot00000000000000static-module-2.1.1/test/readfile_resolve/main.js000066400000000000000000000001541323404012300220300ustar00rootroot00000000000000var fs = require('fs') var src = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(src); static-module-2.1.1/test/readfile_resolve/node_modules/000077500000000000000000000000001323404012300232235ustar00rootroot00000000000000static-module-2.1.1/test/readfile_resolve/node_modules/aaa/000077500000000000000000000000001323404012300237455ustar00rootroot00000000000000static-module-2.1.1/test/readfile_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061323404012300253160ustar00rootroot00000000000000amaze static-module-2.1.1/test/shebang.js000066400000000000000000000011641323404012300172030ustar00rootroot00000000000000var 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-2.1.1/test/shebang/000077500000000000000000000000001323404012300166435ustar00rootroot00000000000000static-module-2.1.1/test/shebang/source.js000066400000000000000000000001301323404012300204730ustar00rootroot00000000000000#!/usr/bin/env node var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.1.1/test/unary.js000066400000000000000000000015631323404012300167350ustar00rootroot00000000000000var 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-2.1.1/test/unary/000077500000000000000000000000001323404012300163725ustar00rootroot00000000000000static-module-2.1.1/test/unary/supported.js000066400000000000000000000000561323404012300207560ustar00rootroot00000000000000var beep = require('beep') console.log(!beep) static-module-2.1.1/test/unary/unsupported.js000066400000000000000000000000641323404012300213200ustar00rootroot00000000000000var beep = require('beep') console.log(typeof beep) static-module-2.1.1/test/varmod.js000066400000000000000000000021351323404012300170630ustar00rootroot00000000000000var 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-2.1.1/test/varmod/000077500000000000000000000000001323404012300165245ustar00rootroot00000000000000static-module-2.1.1/test/varmod/source.js000066400000000000000000000002371323404012300203640ustar00rootroot00000000000000var 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-2.1.1/test/varmod/vars.html000066400000000000000000000000111323404012300203550ustar00rootroot00000000000000beep boopstatic-module-2.1.1/test/vars.js000066400000000000000000000053051323404012300165500ustar00rootroot00000000000000var 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-2.1.1/test/vars/000077500000000000000000000000001323404012300162075ustar00rootroot00000000000000static-module-2.1.1/test/vars/five.js000066400000000000000000000002151323404012300174740ustar00rootroot00000000000000var a = 1, fs = require('fs'), b = 2, html = fs.readFileSync(__dirname + '/vars.html', 'utf8'), c = 3 ; console.log(html + a + b + c); static-module-2.1.1/test/vars/multi-require.js000066400000000000000000000005751323404012300213600ustar00rootroot00000000000000var 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-2.1.1/test/vars/one.js000066400000000000000000000001501323404012300173220ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8') ; console.log(html); static-module-2.1.1/test/vars/source.js000066400000000000000000000001671323404012300200510ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8'), x = '!' ; console.log(html + x); static-module-2.1.1/test/vars/vars.html000066400000000000000000000000111323404012300200400ustar00rootroot00000000000000beep boop