pax_global_header00006660000000000000000000000064132340415450014513gustar00rootroot0000000000000052 comment=5bad47b820e7cabd607f6ceceb1fab1971063536 brfs-1.4.4/000077500000000000000000000000001323404154500124555ustar00rootroot00000000000000brfs-1.4.4/.travis.yml000066400000000000000000000002371323404154500145700ustar00rootroot00000000000000language: node_js node_js: - "9" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: - 'nvm install-latest-npm' sudo: false brfs-1.4.4/LICENSE000066400000000000000000000020611323404154500134610ustar00rootroot00000000000000This 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. brfs-1.4.4/bin/000077500000000000000000000000001323404154500132255ustar00rootroot00000000000000brfs-1.4.4/bin/cmd.js000077500000000000000000000007511323404154500143340ustar00rootroot00000000000000#!/usr/bin/env node var fs = require('fs'); var path = require('path'); var brfs = require('../'); var file = process.argv[2]; if (file === '-h' || file === '--help') { return fs.createReadStream(path.join(__dirname, 'usage.txt')) .pipe(process.stdout) ; } var fromFile = file && file !== '-'; var rs = fromFile ? fs.createReadStream(file) : process.stdin ; var fpath = fromFile ? file : path.join(process.cwd(), '-'); rs.pipe(brfs(fpath)).pipe(process.stdout); brfs-1.4.4/bin/usage.txt000066400000000000000000000003711323404154500150730ustar00rootroot00000000000000usage: brfs file Inline `fs.readFileSync()` calls from `file`, printing the transformed file contents to stdout. brfs brfs - Inline `fs.readFileSync()` calls from stdin, printing the transformed file contents to stdout. brfs-1.4.4/example/000077500000000000000000000000001323404154500141105ustar00rootroot00000000000000brfs-1.4.4/example/async.js000066400000000000000000000001711323404154500155620ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/robot.html', 'utf8', function (err, html) { console.log(html); }); brfs-1.4.4/example/main.js000066400000000000000000000001521323404154500153700ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/example/robot.html000066400000000000000000000000211323404154500161140ustar00rootroot00000000000000beep boop brfs-1.4.4/index.js000066400000000000000000000076741323404154500141400ustar00rootroot00000000000000var staticModule = require('static-module'); var quote = require('quote-stream'); var through = require('through2'); var fs = require('fs'); var path = require('path'); var resolve = require('resolve'); module.exports = function (file, opts) { if (/\.json$/.test(file)) return through(); function resolver (p) { return resolve.sync(p, { basedir: path.dirname(file) }); } var vars = { __filename: file, __dirname: path.dirname(file), require: { resolve: resolver } }; if (!opts) opts = {}; if (opts.vars) Object.keys(opts.vars).forEach(function (key) { vars[key] = opts.vars[key]; }); var sm = staticModule( { fs: { readFileSync: readFileSync, readFile: readFile, readdirSync: readdirSync, readdir: readdir } }, { vars: vars, varModules: { path: path } } ); return sm; function readFile (file, enc, cb) { if (typeof enc === 'function') { cb = enc; enc = null; } if (enc && typeof enc === 'object' && enc.encoding) { enc = enc.encoding; } var isBuffer = false; if (enc === null || enc === undefined) { isBuffer = true; enc = 'base64'; } var stream = through(write, end); stream.push('process.nextTick(function(){(' + cb + ')(null,'); if (isBuffer) stream.push('Buffer('); var s = fs.createReadStream(file, { encoding: enc }); s.on('error', function (err) { sm.emit('error', err) }); return s.pipe(quote()).pipe(stream); function write (buf, enc, next) { this.push(buf); next(); } function end (next) { if (isBuffer) this.push(',"base64")'); this.push(')})'); this.push(null); sm.emit('file', file); next() } } function readFileSync (file, enc) { var isBuffer = false; if (enc === null || enc === undefined) { isBuffer = true; enc = 'base64'; } if (enc && typeof enc === 'object' && enc.encoding) { enc = enc.encoding; } var stream = fs.createReadStream(file, { encoding: enc }) .on('error', function (err) { sm.emit('error', err) }) .pipe(quote()).pipe(through(write, end)) ; if (isBuffer) { stream.push('Buffer('); } return stream; function write (buf, enc, next) { this.push(buf); next(); } function end (next) { if (isBuffer) this.push(',"base64")'); this.push(null); sm.emit('file', file); next(); } } function readdir(path, cb) { var stream = through(write, end); stream.push('process.nextTick(function(){(' + cb + ')(null,'); fs.readdir(path, function (err, src) { if (err) { stream.emit('error', err); return; } stream.push(JSON.stringify(src)); stream.end(')})'); }); return stream; function write (buf, enc, next) { this.push(buf); next(); } function end (next) { this.push(null); next(); } } function readdirSync (path) { var stream = through(write, end); fs.readdir(path, function (err, src) { if (err) { stream.emit('error', err); return; } stream.end(JSON.stringify(src)); }); return stream; function write (buf, enc, next) { this.push(buf); next(); } function end (next) { this.push(null); next(); } } }; brfs-1.4.4/package.json000066400000000000000000000016451323404154500147510ustar00rootroot00000000000000{ "name": "brfs", "version": "1.4.4", "description": "browserify fs.readFileSync() static asset inliner", "main": "index.js", "bin": { "brfs": "bin/cmd.js" }, "dependencies": { "quote-stream": "^1.0.1", "resolve": "^1.1.5", "static-module": "^2.1.1", "through2": "^2.0.0" }, "devDependencies": { "browserify": "^4.2.0", "concat-stream": "^1.6.0", "tap": "~0.4.8", "through": "^2.3.4" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/brfs.git" }, "homepage": "https://github.com/substack/brfs", "keywords": [ "browserify", "browserify-transform", "fs", "readFileSync", "plugin", "static", "asset", "bundle", "base64" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } brfs-1.4.4/readme.markdown000066400000000000000000000102671323404154500154640ustar00rootroot00000000000000# brfs fs.readFileSync() and fs.readFile() static asset browserify transform [![build status](https://secure.travis-ci.org/substack/brfs.png)](http://travis-ci.org/substack/brfs) This module is a plugin for [browserify](http://browserify.org) to parse the AST for `fs.readFileSync()` calls so that you can inline file contents into your bundles. Even though this module is intended for use with browserify, nothing about it is particularly specific to browserify so it should be generally useful in other projects. # example for a main.js: ``` js var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); ``` and a robot.html: ``` html beep boop ``` first `npm install brfs` into your project, then: ## on the command-line ``` $ browserify -t brfs example/main.js > bundle.js ``` now in the bundle output file, ``` js var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); ``` turns into: ``` js var html = "beep boop\n"; ``` ## or with the api ``` js var browserify = require('browserify'); var fs = require('fs'); var b = browserify('example/main.js'); b.transform('brfs'); b.bundle().pipe(fs.createWriteStream('bundle.js')); ``` ## async You can also use `fs.readFile()`: ``` js var fs = require('fs'); fs.readFile(__dirname + '/robot.html', 'utf8', function (err, html) { console.log(html); }); ``` When you run this code through brfs, it turns into: ``` js var fs = require('fs'); process.nextTick(function () {(function (err, html) { console.log(html); })(null,"beep boop\n")}); ``` # methods brfs looks for: * `fs.readFileSync(pathExpr, enc=null)` * `fs.readFile(pathExpr, enc=null, cb)` * `fs.readdirSync(pathExpr)` * `fs.readdir(pathExpr, cb)` Inside of each `pathExpr`, you can use [statically analyzable](http://npmjs.org/package/static-eval) expressions and these variables and functions: * `__dirname` * `__filename` * `path` if you `var path = require('path')` first * `require.resolve()` Just like node, the default encoding is `null` and will give back a `Buffer`. If you want differently-encoded file contents for your inline content you can set `enc` to `'utf8'`, `'base64'`, or `'hex'`. In async mode when a callback `cb` is given, the contents of `pathExpr` are inlined into the source inside of a `process.nextTick()` call. When you use a `'file'`-event aware watcher such as [watchify](https://npmjs.org/package/watchify), the inlined assets will be updated automatically. If you want to use this plugin directly, not through browserify, the api follows. ``` js var brfs = require('brfs') ``` ## var tr = brfs(file, opts) Return a through stream `tr` inlining `fs.readFileSync()` file contents in-place. Optionally, you can set which `opts.vars` will be used in the [static argument evaluation](https://npmjs.org/package/static-eval) in addition to `__dirname` and `__filename`. # events ## tr.on('file', function (file) {}) For every file included with `fs.readFileSync()` or `fs.readFile()`, the `tr` instance emits a `'file'` event with the `file` path. # usage A tiny command-line program ships with this module to make debugging easier. ``` usage: brfs file Inline `fs.readFileSync()` calls from `file`, printing the transformed file contents to stdout. brfs brfs - Inline `fs.readFileSync()` calls from stdin, printing the transformed file contents to stdout. ``` # install With [npm](https://npmjs.org) do: ``` npm install brfs ``` then use `-t brfs` with the browserify command or use `.transform('brfs')` from the browserify api. # gotchas Since `brfs` evaluates your source code *statically*, you can't use dynamic expressions that need to be evaluated at run time. For example: ```js // WILL NOT WORK! var file = window.someFilePath; var str = require('fs').readFileSync(file, 'utf8'); ``` Instead, you must use simpler expressions that can be resolved at build-time: ```js var str = require('fs').readFileSync(__dirname + '/file.txt', 'utf8'); ``` Another gotcha: `brfs` does not yet support ES2015 syntax like destructuring or `import` statements. See [brfs-babel](https://github.com/Jam3/brfs-babel) for an experimental replacement that supports this syntax. # license MIT brfs-1.4.4/test/000077500000000000000000000000001323404154500134345ustar00rootroot00000000000000brfs-1.4.4/test/ag.js000066400000000000000000000010341323404154500143570ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); test('skip parsing json', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/ag.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal('

abcdefg

\n', msg); } }); brfs-1.4.4/test/async.js000066400000000000000000000025171323404154500151140ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); test('async', function (t) { t.plan(1); var b = browserify(__dirname + '/files/async.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { setTimeout: setTimeout, console: { log: log } }); }); function log (msg) { t.equal(msg, 'what\n') } }); test('async encoding', function (t) { t.plan(1); var b = browserify(__dirname + '/files/async_encoding.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { setTimeout: setTimeout, console: { log: log } }); }); function log (msg) { t.equal(msg, '776861740a') } }); test('async string encoding', function (t) { t.plan(1); var b = browserify(__dirname + '/files/async_str_encoding.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { setTimeout: setTimeout, console: { log: log } }); }); function log (msg) { t.equal(msg, '776861740a') } }); brfs-1.4.4/test/buffer.js000066400000000000000000000014341323404154500152450ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var path = require('path'); test('sync string encoding', function (t) { t.plan(2); var b = browserify(__dirname + '/files/buffer.js'); b.require('buffer', { expose: 'buffer' }); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); var context = { setTimeout: setTimeout, console: { log: log } }; var buffers = []; vm.runInNewContext(src, context); t.ok(context.require('buffer').Buffer.isBuffer(buffers[0]), 'isBuffer'); t.equal(buffers[0].toString('utf8'), 'beep boop\n'); function log (msg) { buffers.push(msg) } }); }); brfs-1.4.4/test/bundle.js000066400000000000000000000011201323404154500152350ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('bundle a file', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/main.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/cmd.js000066400000000000000000000011501323404154500145320ustar00rootroot00000000000000var test = require('tap').test; var exec = require('child_process').exec; var vm = require('vm'); var fs = require('fs'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('cmd.js', function (t) { t.plan(1); exec(__dirname + '/../bin/cmd.js ' + __dirname + '/files/main.js', function (error, stdout, stderr) { if (error !== null) { t.fail(); } else { vm.runInNewContext(stdout, { require: function () {}, console: { log: log } }); function log (msg) { t.equal(html, msg); }; }; } ); });brfs-1.4.4/test/dynamic_read_concat.js000066400000000000000000000006531323404154500177440ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var path = require('path'); test('dynamically loaded file gets skipped', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/dynamic_read_concat'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); else t.ok(true, 'build success'); }); }); brfs-1.4.4/test/dynamic_read_no_concat.js000066400000000000000000000006611323404154500204370ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var path = require('path'); test('dynamically loaded file gets skipped', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/dynamic_read_no_concat.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); else t.ok(true, 'build success'); }); }); brfs-1.4.4/test/encoding.js000066400000000000000000000010541323404154500155600ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var path = require('path'); test('sync string encoding', function (t) { t.plan(1); var b = browserify(__dirname + '/files/encoding.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { setTimeout: setTimeout, console: { log: log } }); }); function log (msg) { t.equal(msg, '3c623e6265657020626f6f703c2f623e0a') } }); brfs-1.4.4/test/files/000077500000000000000000000000001323404154500145365ustar00rootroot00000000000000brfs-1.4.4/test/files/ag.js000066400000000000000000000003621323404154500154640ustar00rootroot00000000000000var fs = require('fs'); var pre = fs.readFileSync(__dirname + '/ag_pre.html', 'utf8'); var post = fs.readFileSync(__dirname + '/ag_post.html', 'utf8'); var ag = require('./ag.json'); console.log(pre + Object.keys(ag).sort().join('') + post); brfs-1.4.4/test/files/ag.json000066400000000000000000000000541323404154500160170ustar00rootroot00000000000000{"a":1,"b":2,"c":2,"d":3,"e":4,"f":5,"g":6} brfs-1.4.4/test/files/ag_post.html000066400000000000000000000000061323404154500170540ustar00rootroot00000000000000 brfs-1.4.4/test/files/ag_pre.html000066400000000000000000000000041323404154500166530ustar00rootroot00000000000000

brfs-1.4.4/test/files/async.js000066400000000000000000000001661323404154500162140ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'utf8', function (err, txt) { console.log(txt); }); brfs-1.4.4/test/files/async.txt000066400000000000000000000000051323404154500164070ustar00rootroot00000000000000what brfs-1.4.4/test/files/async_encoding.js000066400000000000000000000002031323404154500200520ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', { encoding: 'hex' }, function (err, txt) { console.log(txt); }); brfs-1.4.4/test/files/async_str_encoding.js000066400000000000000000000001651323404154500207510ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'hex', function (err, txt) { console.log(txt); }); brfs-1.4.4/test/files/buffer.js000066400000000000000000000001401323404154500163400ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html'); console.log(txt); brfs-1.4.4/test/files/dynamic_read_concat.js000066400000000000000000000003201323404154500210350ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(__dirname + dynamicallyCreatedFilename + __dirname, 'utf8'); brfs-1.4.4/test/files/dynamic_read_no_concat.js000066400000000000000000000002701323404154500215350ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(dynamicallyCreatedFilename, 'utf8'); brfs-1.4.4/test/files/encoding.js000066400000000000000000000001651323404154500166640ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' }); console.log(txt);brfs-1.4.4/test/files/hoist.js000066400000000000000000000001521323404154500162200ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/test/files/inline.js000066400000000000000000000001351323404154500163510ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/test/files/main.js000066400000000000000000000001521323404154500160160ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/test/files/multi_var.js000066400000000000000000000001701323404154500170740ustar00rootroot00000000000000var x = 5, y = require('fs'), z = 555; var html = y.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/test/files/non_fs.js000066400000000000000000000001601323404154500163530ustar00rootroot00000000000000var blarg = require('fs'); var html = blarg.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.4.4/test/files/path_join.js000066400000000000000000000002171323404154500170470ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(path.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.4.4/test/files/path_join_other_name.js000066400000000000000000000002151323404154500212460ustar00rootroot00000000000000var fs = require('fs'); var xxx = require('path'); var html = fs.readFileSync(xxx.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.4.4/test/files/path_join_single_var.js000066400000000000000000000002171323404154500212600ustar00rootroot00000000000000var fs = require('fs'); var join = require('path').join; var html = fs.readFileSync(join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.4.4/test/files/readdir-sync.js000066400000000000000000000001011323404154500174500ustar00rootroot00000000000000var fs = require('fs'); console.log(fs.readdirSync(__dirname)); brfs-1.4.4/test/files/readdir.js000066400000000000000000000001721323404154500165060ustar00rootroot00000000000000var fs = require('fs'); fs.readdir(__dirname, function(err, files) { if (err) throw err; console.log(files); }); brfs-1.4.4/test/files/robot.html000066400000000000000000000000211323404154500165420ustar00rootroot00000000000000beep boop brfs-1.4.4/test/files/separators.js000066400000000000000000000001561323404154500172610ustar00rootroot00000000000000var fs = require('fs'); var text = fs.readFileSync(__dirname + '/separators.txt', 'utf8'); console.log(text); brfs-1.4.4/test/files/separators.txt000066400000000000000000000001001323404154500174510ustar00rootroot00000000000000 LINE_SEPARATOR: 
 (U+2028) PARAGRAPH_SEPARATOR: 
 (U+2029) brfs-1.4.4/test/files/tr.beep000066400000000000000000000002011323404154500160110ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/tr.html', 'utf8'); console.log((FN(){ return html.length })()); brfs-1.4.4/test/files/tr.html000066400000000000000000000000151323404154500160450ustar00rootroot00000000000000

abc

brfs-1.4.4/test/files/with_comments.js000066400000000000000000000003701323404154500177540ustar00rootroot00000000000000var /** * Dependencies. */ fs = require('fs'), /** * Local variables. */ style = fs.readFileSync(__dirname + '/robot.html', 'utf8'); module.exports = function () { console.log(style); }; module.exports();brfs-1.4.4/test/hoist.js000066400000000000000000000011321323404154500151150ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('hoisted fs declaration', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/hoist.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/inline.js000066400000000000000000000011221323404154500152440ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('bundle a file', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/inline.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/multi_var.js000066400000000000000000000011401323404154500157700ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('multiple var assignments', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/multi_var.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/non_fs.js000066400000000000000000000011221323404154500152500ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('bundle a file', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/non_fs.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/path_join.js000066400000000000000000000011211323404154500157400ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('path.join', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/path_join.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/path_join_other_name.js000066400000000000000000000011471323404154500201510ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('path.join other name', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/path_join_other_name.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/path_join_single_var.js000066400000000000000000000011471323404154500201610ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('path.join single var', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/path_join_single_var.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } }); brfs-1.4.4/test/readdir.js000066400000000000000000000020421323404154500154020ustar00rootroot00000000000000var browserify = require('browserify'); var test = require('tap').test; var path = require('path'); var vm = require('vm'); var fs = require('fs'); test('readdir', function(t) { t.plan(1); var expected = fs.readdirSync(__dirname + '/files'); var b = browserify(__dirname + '/files/readdir.js'); b.transform(path.dirname(__dirname)); b.bundle(function(err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log }, setTimeout: setTimeout }); }); function log(actual) { t.deepEqual(expected, actual); } }); test('readdirSync', function(t) { t.plan(1); var expected = fs.readdirSync(__dirname + '/files'); var b = browserify(__dirname + '/files/readdir-sync.js'); b.transform(path.dirname(__dirname)); b.bundle(function(err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log(actual) { t.deepEqual(expected, actual); } }); brfs-1.4.4/test/require_resolve.js000066400000000000000000000010101323404154500171750ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); test('require.resolve', function (t) { t.plan(2); var b = browserify(); b.add(__dirname + '/require_resolve/main.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { t.ifError(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(msg, 'amaze\n') } }); brfs-1.4.4/test/require_resolve/000077500000000000000000000000001323404154500166475ustar00rootroot00000000000000brfs-1.4.4/test/require_resolve/main.js000066400000000000000000000002131323404154500201250ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(html); brfs-1.4.4/test/require_resolve/node_modules/000077500000000000000000000000001323404154500213245ustar00rootroot00000000000000brfs-1.4.4/test/require_resolve/node_modules/aaa/000077500000000000000000000000001323404154500220465ustar00rootroot00000000000000brfs-1.4.4/test/require_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061323404154500234170ustar00rootroot00000000000000amaze brfs-1.4.4/test/separators.js000066400000000000000000000021451323404154500161570ustar00rootroot00000000000000var test = require('tap').test; var exec = require('child_process').exec; var browserify = require('browserify'); var path = require('path'); var vm = require('vm'); var fs = require('fs'); var text = fs.readFileSync(__dirname + '/files/separators.txt', 'utf8'); test('run file with special unicode separators', function (t) { t.plan(1); exec(__dirname + '/../bin/cmd.js ' + __dirname + '/files/separators.js', function (error, stdout, stderr) { if (error !== null) { t.fail(); } else { vm.runInNewContext(stdout, { require: function () {}, console: { log: log } }); function log (msg) { t.equal(text, msg); }; }; } ); }); test('bundle file with special unicode separators', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/separators.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(text, msg); } }); brfs-1.4.4/test/tr.js000066400000000000000000000021641323404154500144220ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var through = require('through'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); test('parse non-js, non-json files', function (t) { t.plan(2); var b = browserify(); b.add(__dirname + '/files/tr.beep'); b.transform(function (file) { var buffers = []; if (!/\.beep$/.test(file)) return through(); return through(write, end); function write (buf) { buffers.push(buf) } function end () { var src = Buffer.concat(buffers).toString('utf8'); this.queue(src.replace(/\bFN\b/g, 'function')); this.queue(null); } }); b.transform(path.dirname(__dirname)); var bs = b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); bs.on('transform', function (tr) { tr.on('file', function (file) { t.equal(file, __dirname + '/files/tr.html'); }); }); function log (msg) { t.equal(13, msg); } }); brfs-1.4.4/test/with_comments.js000066400000000000000000000011431323404154500166510ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(__dirname + '/files/robot.html', 'utf8'); test('with comment separators', function (t) { t.plan(1); var b = browserify(); b.add(__dirname + '/files/with_comments.js'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); vm.runInNewContext(src, { console: { log: log } }); }); function log (msg) { t.equal(html, msg); } });