pax_global_header00006660000000000000000000000064132745262250014522gustar00rootroot0000000000000052 comment=932fc54cbbb68549b4ee0a8f3a06c9ffd6377824 static-module-2.2.5/000077500000000000000000000000001327452622500143025ustar00rootroot00000000000000static-module-2.2.5/.npmrc000066400000000000000000000000231327452622500154150ustar00rootroot00000000000000package-lock=false static-module-2.2.5/.travis.yml000066400000000000000000000000771327452622500164170ustar00rootroot00000000000000language: node_js node_js: - 9 - 8 - 6 - 4 - "0.10" static-module-2.2.5/LICENSE000066400000000000000000000020611327452622500153060ustar00rootroot00000000000000This 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.2.5/example/000077500000000000000000000000001327452622500157355ustar00rootroot00000000000000static-module-2.2.5/example/brfs.js000066400000000000000000000005261327452622500172320ustar00rootroot00000000000000var 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.2.5/example/brfs/000077500000000000000000000000001327452622500166715ustar00rootroot00000000000000static-module-2.2.5/example/brfs/source.js000066400000000000000000000001331327452622500205240ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt'); console.log(src); static-module-2.2.5/example/brfs/x.txt000066400000000000000000000000121327452622500176720ustar00rootroot00000000000000beep boop static-module-2.2.5/example/fs.js000066400000000000000000000014161327452622500167050ustar00rootroot00000000000000var 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.2.5/example/fs/000077500000000000000000000000001327452622500163455ustar00rootroot00000000000000static-module-2.2.5/example/fs/source.js000066400000000000000000000001511327452622500202000ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.2.5/example/fs/x.txt000066400000000000000000000000121327452622500173460ustar00rootroot00000000000000beep boop static-module-2.2.5/index.js000066400000000000000000000365721327452622500157640ustar00rootroot00000000000000var 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'); var MagicString = require('magic-string'); var convertSourceMap = require('convert-source-map'); var mergeSourceMap = require('merge-source-map'); 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 sourcemapper; var inputMap; var output = through(); var body; return duplexer(concat({ encoding: 'buffer' }, function (buf) { try { body = buf.toString('utf8').replace(/^#!/, '//#!'); var matches = false; for (var key in modules) { if (body.indexOf(key) !== -1) { matches = true; break; } } if (!matches) { // just pass it through output.end(buf); return; } if (opts.sourceMap) { inputMap = convertSourceMap.fromSource(body); if (inputMap) inputMap = inputMap.toObject(); body = convertSourceMap.removeComments(body); sourcemapper = new MagicString(body); } 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.write(src.slice(pos, s.start)); pos = s.start + s.offset; s.stream.pipe(output, { end: false }); if (opts.sourceMap) { s.stream.pipe(concat({ encoding: 'string' }, function (chunk) { // We have to give magic-string the replacement string, // so it can calculate the amount of lines and columns. if (s.offset === 0) { sourcemapper.appendRight(s.start, chunk); } else { sourcemapper.overwrite(s.start, s.start + s.offset, chunk); } })).on('finish', next); } else { s.stream.on('end', next); } })(); function done () { output.write(src.slice(pos)); if (opts.sourceMap) { var map = sourcemapper.generateMap({ source: opts.inputFilename || 'input.js', includeContent: true }); if (inputMap) { var merged = mergeSourceMap(inputMap, map); output.write('\n' + convertSourceMap.fromObject(merged).toComment() + '\n'); } else { output.write('\n//# sourceMappingURL=' + map.toUrl() + '\n'); } } output.end(); } } function error (msg) { var err = typeof msg === 'string' ? new Error(msg) : msg; output.emit('error', err); } function walk (node) { if (opts.sourceMap) { sourcemapper.addSourcemapLocation(node.start); sourcemapper.addSourcemapLocation(node.end); } 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.2.5/package.json000066400000000000000000000022301327452622500165650ustar00rootroot00000000000000{ "name": "static-module", "version": "2.2.5", "description": "convert module usage to inline expressions", "main": "index.js", "dependencies": { "concat-stream": "~1.6.0", "convert-source-map": "^1.5.1", "duplexer2": "~0.1.4", "escodegen": "~1.9.0", "falafel": "^2.1.0", "has": "^1.0.1", "magic-string": "^0.22.4", "merge-source-map": "1.0.4", "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": { "from2-string": "^1.1.0", "resolve": "^1.5.0", "source-map": "^0.6.1", "tape": "^4.8.0", "uglify-js": "3.3.12" }, "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.2.5/readme.markdown000066400000000000000000000054161327452622500173110ustar00rootroot00000000000000# 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. Set `opts.sourceMap` to `true` to generate a source map and add it as an inline comment. You can add `opts.inputFilename` to configure the original file name that will be listed in the source map. # install With [npm](https://npmjs.org) do: ``` npm install static-module ``` # license MIT static-module-2.2.5/test/000077500000000000000000000000001327452622500152615ustar00rootroot00000000000000static-module-2.2.5/test/assign.js000066400000000000000000000023701327452622500171050ustar00rootroot00000000000000var 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.2.5/test/assign/000077500000000000000000000000001327452622500165455ustar00rootroot00000000000000static-module-2.2.5/test/assign/comma.js000066400000000000000000000001071327452622500201750ustar00rootroot00000000000000x = 5, b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.2.5/test/assign/source.js000066400000000000000000000001001327452622500203720ustar00rootroot00000000000000b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.2.5/test/brfs.js000066400000000000000000000144441327452622500165620ustar00rootroot00000000000000var 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 empty', function (t) { t.plan(1); var sm = staticModule({ fs: { readFileSync: function (file) { return fs.createReadStream(file).pipe(quote()); } } }, { vars: { __dirname: path.join(__dirname, 'brfs') } }); readStream('empty.js').pipe(sm).pipe(concat(function (body) { t.equal(body.toString('utf8'), ''); })); }); 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.2.5/test/brfs/000077500000000000000000000000001327452622500162155ustar00rootroot00000000000000static-module-2.2.5/test/brfs/attribute.js000066400000000000000000000001411327452622500205520ustar00rootroot00000000000000var f = require('fs').readFileSync; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/attribute_brackets.js000066400000000000000000000001441327452622500224330ustar00rootroot00000000000000var f = require('fs')["readFileSync"]; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/attribute_vars.js000066400000000000000000000001571327452622500216140ustar00rootroot00000000000000var x = 5, f = require('fs').readFileSync, y = 2; var src = f(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/brackets.js000066400000000000000000000001461327452622500203520ustar00rootroot00000000000000var fs = require('fs'); var src = fs["readFileSync"](__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/empty.js000066400000000000000000000000001327452622500176770ustar00rootroot00000000000000static-module-2.2.5/test/brfs/multi_require.js000066400000000000000000000001521327452622500214370ustar00rootroot00000000000000var fs = require('fs'), x = 5; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/multi_require_with_uninitialized.js000066400000000000000000000001461327452622500254250ustar00rootroot00000000000000var fs = require('fs'), x; var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/source.js000066400000000000000000000001431327452622500200510ustar00rootroot00000000000000var fs = require('fs'); var src = fs.readFileSync(__dirname + '/x.txt', 'utf8'); console.log(src); static-module-2.2.5/test/brfs/x.txt000066400000000000000000000000121327452622500172160ustar00rootroot00000000000000beep boop static-module-2.2.5/test/brfs/x5.js000066400000000000000000000002071327452622500171060ustar00rootroot00000000000000var 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.2.5/test/fn.js000066400000000000000000000010521327452622500162200ustar00rootroot00000000000000var 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.2.5/test/fn/000077500000000000000000000000001327452622500156645ustar00rootroot00000000000000static-module-2.2.5/test/fn/source.js000066400000000000000000000000541327452622500175210ustar00rootroot00000000000000var b = require('beep'); console.log(b(5)); static-module-2.2.5/test/fs.js000066400000000000000000000034541327452622500162350ustar00rootroot00000000000000var 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.2.5/test/fs/000077500000000000000000000000001327452622500156715ustar00rootroot00000000000000static-module-2.2.5/test/fs/html.js000066400000000000000000000001351327452622500171720ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); static-module-2.2.5/test/fs/readfile.js000066400000000000000000000001511327452622500177770ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.2.5/test/fs/robot.html000066400000000000000000000000141327452622500176770ustar00rootroot00000000000000EXTERMINATE static-module-2.2.5/test/fs/x.txt000066400000000000000000000000121327452622500166720ustar00rootroot00000000000000beep boop static-module-2.2.5/test/fs_twice.js000066400000000000000000000055741327452622500174350ustar00rootroot00000000000000var 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.2.5/test/fs_twice/000077500000000000000000000000001327452622500170645ustar00rootroot00000000000000static-module-2.2.5/test/fs_twice/4x.js000066400000000000000000000004761327452622500177640ustar00rootroot00000000000000var 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.2.5/test/fs_twice/html.js000066400000000000000000000002511327452622500203640ustar00rootroot00000000000000var 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.2.5/test/fs_twice/readfile.js000066400000000000000000000001511327452622500211720ustar00rootroot00000000000000var fs = require('fs') fs.readFile(__dirname + '/x.txt', function (err, src) { console.log(src); }); static-module-2.2.5/test/fs_twice/robot.html000066400000000000000000000000141327452622500210720ustar00rootroot00000000000000EXTERMINATE static-module-2.2.5/test/fs_twice/vars.js000066400000000000000000000002531327452622500203750ustar00rootroot00000000000000var 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.2.5/test/fs_twice/x.txt000066400000000000000000000000121327452622500200650ustar00rootroot00000000000000beep boop static-module-2.2.5/test/inline.js000066400000000000000000000042301327452622500170740ustar00rootroot00000000000000var 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.2.5/test/inline/000077500000000000000000000000001327452622500165375ustar00rootroot00000000000000static-module-2.2.5/test/inline/fn.js000066400000000000000000000000541327452622500174770ustar00rootroot00000000000000var x = require('beep')(5); console.log(x); static-module-2.2.5/test/inline/fn_call.js000066400000000000000000000000411327452622500204660ustar00rootroot00000000000000console.log(require('beep')(5)); static-module-2.2.5/test/inline/fn_expr.js000066400000000000000000000000451327452622500205350ustar00rootroot00000000000000console.log(require('beep')(5) * 3); static-module-2.2.5/test/inline/obj.js000066400000000000000000000000561327452622500176500ustar00rootroot00000000000000var x = require('beep').f(5); console.log(x); static-module-2.2.5/test/inline/obj_call.js000066400000000000000000000000431327452622500206370ustar00rootroot00000000000000console.log(require('beep').f(5)); static-module-2.2.5/test/inline/obj_expr.js000066400000000000000000000000471327452622500207060ustar00rootroot00000000000000console.log(require('beep').f(5) * 2); static-module-2.2.5/test/limit-parsing.js000066400000000000000000000012141327452622500203740ustar00rootroot00000000000000var concat = require('concat-stream'); var from = require('from2-string'); var staticModule = require('../'); var test = require('tape'); test('limit parsing to files including a target module', function (t) { var passInput = 'THIS WILL NOT PARSE'; var failInput = passInput + '; require("fs")'; t.plan(2); from(passInput) .pipe(staticModule({ fs: require('fs') })) .pipe(concat(function (passOutput) { t.equal(passInput, String(passOutput), 'does not parse'); })); from(failInput) .pipe(staticModule({ fs: require('fs') })) .once('error', function () { t.pass('parses if module is included'); }); }); static-module-2.2.5/test/log.js000066400000000000000000000026101327452622500163770ustar00rootroot00000000000000var 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.2.5/test/log/000077500000000000000000000000001327452622500160425ustar00rootroot00000000000000static-module-2.2.5/test/log/source.js000066400000000000000000000000401327452622500176720ustar00rootroot00000000000000console.log(require('beep')()); static-module-2.2.5/test/many.js000066400000000000000000000044321327452622500165660ustar00rootroot00000000000000var 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.2.5/test/many/000077500000000000000000000000001327452622500162255ustar00rootroot00000000000000static-module-2.2.5/test/many/a.txt000066400000000000000000000000031327452622500171770ustar00rootroot00000000000000A! static-module-2.2.5/test/many/all_inline.js000066400000000000000000000003261327452622500206720ustar00rootroot00000000000000var 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.2.5/test/many/b.txt000066400000000000000000000000031327452622500172000ustar00rootroot00000000000000B! static-module-2.2.5/test/many/c.txt000066400000000000000000000000031327452622500172010ustar00rootroot00000000000000C! static-module-2.2.5/test/many/inline.js000066400000000000000000000003261327452622500200420ustar00rootroot00000000000000var 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.2.5/test/many/source.js000066400000000000000000000003251327452622500200630ustar00rootroot00000000000000var 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.2.5/test/mixed.js000066400000000000000000000036421327452622500167320ustar00rootroot00000000000000var 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.2.5/test/mixed/000077500000000000000000000000001327452622500163675ustar00rootroot00000000000000static-module-2.2.5/test/mixed/source.js000066400000000000000000000001771327452622500202320ustar00rootroot00000000000000var 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.2.5/test/mixed/unmixed.js000066400000000000000000000001621327452622500203750ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.quote(__dirname + '/xyz.txt')); console.log(b.f(5)); static-module-2.2.5/test/mixed/xyz.txt000066400000000000000000000000111327452622500177520ustar00rootroot00000000000000oh hello static-module-2.2.5/test/nested.js000066400000000000000000000014551327452622500171060ustar00rootroot00000000000000var 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.2.5/test/nested/000077500000000000000000000000001327452622500165435ustar00rootroot00000000000000static-module-2.2.5/test/nested/source.js000066400000000000000000000001141327452622500203750ustar00rootroot00000000000000var b = require('beep'); console.log(b.x.y.z * 3); console.log(b.f.g.h(5)); static-module-2.2.5/test/obj.js000066400000000000000000000011571327452622500163750ustar00rootroot00000000000000var 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.2.5/test/obj/000077500000000000000000000000001327452622500160335ustar00rootroot00000000000000static-module-2.2.5/test/obj/source.js000066400000000000000000000001041327452622500176640ustar00rootroot00000000000000var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.2.5/test/prop.js000066400000000000000000000011261327452622500165770ustar00rootroot00000000000000var 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.2.5/test/prop/000077500000000000000000000000001327452622500162415ustar00rootroot00000000000000static-module-2.2.5/test/prop/source.js000066400000000000000000000001441327452622500200760ustar00rootroot00000000000000var f = require('fff'); var toString = Object.prototype.toString; console.log(toString.call(f(5))); static-module-2.2.5/test/readfile_resolve.js000066400000000000000000000017711327452622500211370ustar00rootroot00000000000000var 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.2.5/test/readfile_resolve/000077500000000000000000000000001327452622500205735ustar00rootroot00000000000000static-module-2.2.5/test/readfile_resolve/main.js000066400000000000000000000001541327452622500220550ustar00rootroot00000000000000var fs = require('fs') var src = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(src); static-module-2.2.5/test/readfile_resolve/node_modules/000077500000000000000000000000001327452622500232505ustar00rootroot00000000000000static-module-2.2.5/test/readfile_resolve/node_modules/aaa/000077500000000000000000000000001327452622500237725ustar00rootroot00000000000000static-module-2.2.5/test/readfile_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061327452622500253430ustar00rootroot00000000000000amaze static-module-2.2.5/test/shebang.js000066400000000000000000000011641327452622500172300ustar00rootroot00000000000000var 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.2.5/test/shebang/000077500000000000000000000000001327452622500166705ustar00rootroot00000000000000static-module-2.2.5/test/shebang/source.js000066400000000000000000000001301327452622500205200ustar00rootroot00000000000000#!/usr/bin/env node var b = require('beep'); console.log(b.x * 3); console.log(b.f(5)); static-module-2.2.5/test/sourcemap.js000066400000000000000000000071411327452622500176200ustar00rootroot00000000000000var test = require('tape'); var fs = require('fs'); var concat = require('concat-stream'); var PassThrough = require('stream').PassThrough; var convertSourceMap = require('convert-source-map'); var SourceMapConsumer = require('source-map').SourceMapConsumer; var uglify = require('uglify-js'); var staticModule = require('../'); test('source maps', function (t) { t.plan(6); var transform = staticModule({ sheetify: function (filename) { var stream = PassThrough(); stream.write('`.css{\n'); stream.write(' color: red;\n'); stream.end('}`'); return stream; } }, { sourceMap: true, inputFilename: 'main.js' }); fs.createReadStream(__dirname + '/sourcemap/main.js').pipe(transform).pipe(concat({ encoding: 'string' }, function (res) { var consumer = new SourceMapConsumer(convertSourceMap.fromSource(res).toObject()); var mapped = consumer.originalPositionFor({ line: 8, column: 0 }); t.equal(mapped.line, 8); t.equal(mapped.column, 0); mapped = consumer.originalPositionFor({ line: 10, column: 2 }); t.equal(mapped.line, 8); t.equal(mapped.column, 19); mapped = consumer.originalPositionFor({ line: 12, column: 0 }); t.equal(mapped.line, 10); t.equal(mapped.column, 0); })); }); test('input source map', function (t) { t.plan(4); var content = fs.readFileSync(__dirname + '/sourcemap/main.js', 'utf8'); var minified = uglify.minify({ 'main.js': content }, { output: { beautify: true }, sourceMap: { url: 'inline', includeSources: true } }); var transform = staticModule({ sheetify: function (filename) { var stream = PassThrough(); stream.end('`.css{\n color: orange;\n}`'); return stream; } }, { sourceMap: true, inputFilename: 'main.js' }); transform.pipe(concat({ encoding: 'string' }, function (res) { var consumer = new SourceMapConsumer(convertSourceMap.fromSource(res).toObject()); var mapped = consumer.originalPositionFor({ line: 7, column: 0 }); t.equal(mapped.line, 8); t.equal(mapped.column, 0); mapped = consumer.originalPositionFor({ line: 9, column: 4 }); t.equal(mapped.line, 10); t.equal(mapped.column, 0); })); transform.end(minified.code); }); test('retain input source map when file has no static-module use', function (t) { t.plan(4); var content = fs.readFileSync(__dirname + '/sourcemap/main.js', 'utf8'); var minified = uglify.minify({ 'main.js': content }, { output: { beautify: true }, sourceMap: { url: 'inline', includeSources: true } }); var transform = staticModule({ not_sheetify: function () { return 'whatever'; } }, { sourceMap: true, inputFilename: 'main.js' }); transform.pipe(concat({ encoding: 'string' }, function (res) { var consumer = new SourceMapConsumer(convertSourceMap.fromSource(res).toObject()); var mapped = consumer.originalPositionFor({ line: 7, column: 0 }); t.equal(mapped.line, 8); t.equal(mapped.column, 0); mapped = consumer.originalPositionFor({ line: 7, column: 21 }); t.equal(mapped.line, 10); t.equal(mapped.column, 0); })); transform.end(minified.code); }); static-module-2.2.5/test/sourcemap/000077500000000000000000000000001327452622500172575ustar00rootroot00000000000000static-module-2.2.5/test/sourcemap/main.js000066400000000000000000000003041327452622500205360ustar00rootroot00000000000000var css = require('sheetify'); function doSomeStuff () { // doing some stuff before inlining a static module call return yadda(yadda) } css('filename.css'); exports.blah = whatever.xyz static-module-2.2.5/test/unary.js000066400000000000000000000015631327452622500167620ustar00rootroot00000000000000var 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.2.5/test/unary/000077500000000000000000000000001327452622500164175ustar00rootroot00000000000000static-module-2.2.5/test/unary/supported.js000066400000000000000000000000561327452622500210030ustar00rootroot00000000000000var beep = require('beep') console.log(!beep) static-module-2.2.5/test/unary/unsupported.js000066400000000000000000000000641327452622500213450ustar00rootroot00000000000000var beep = require('beep') console.log(typeof beep) static-module-2.2.5/test/varmod.js000066400000000000000000000021351327452622500171100ustar00rootroot00000000000000var 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.2.5/test/varmod/000077500000000000000000000000001327452622500165515ustar00rootroot00000000000000static-module-2.2.5/test/varmod/source.js000066400000000000000000000002371327452622500204110ustar00rootroot00000000000000var 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.2.5/test/varmod/vars.html000066400000000000000000000000111327452622500204020ustar00rootroot00000000000000beep boopstatic-module-2.2.5/test/vars.js000066400000000000000000000054501327452622500165760ustar00rootroot00000000000000var 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') }, sourceMap: true // Make sure source maps work when replacing 0 length ranges. }); 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.2.5/test/vars/000077500000000000000000000000001327452622500162345ustar00rootroot00000000000000static-module-2.2.5/test/vars/five.js000066400000000000000000000002151327452622500175210ustar00rootroot00000000000000var 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.2.5/test/vars/multi-require.js000066400000000000000000000005751327452622500214050ustar00rootroot00000000000000var 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.2.5/test/vars/one.js000066400000000000000000000001501327452622500173470ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8') ; console.log(html); static-module-2.2.5/test/vars/source.js000066400000000000000000000001671327452622500200760ustar00rootroot00000000000000var fs = require('fs'), html = fs.readFileSync(__dirname + '/vars.html', 'utf8'), x = '!' ; console.log(html + x); static-module-2.2.5/test/vars/vars.html000066400000000000000000000000111327452622500200650ustar00rootroot00000000000000beep boop