pax_global_header00006660000000000000000000000064132633402220014507gustar00rootroot0000000000000052 comment=548b566818953d558d4acd804d39c30540101a68 brfs-1.6.1/000077500000000000000000000000001326334022200124505ustar00rootroot00000000000000brfs-1.6.1/.travis.yml000066400000000000000000000002371326334022200145630ustar00rootroot00000000000000language: 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.6.1/LICENSE000066400000000000000000000020611326334022200134540ustar00rootroot00000000000000This 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.6.1/bin/000077500000000000000000000000001326334022200132205ustar00rootroot00000000000000brfs-1.6.1/bin/cmd.js000077500000000000000000000007511326334022200143270ustar00rootroot00000000000000#!/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.6.1/bin/usage.txt000066400000000000000000000003711326334022200150660ustar00rootroot00000000000000usage: 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.6.1/example/000077500000000000000000000000001326334022200141035ustar00rootroot00000000000000brfs-1.6.1/example/async.js000066400000000000000000000001711326334022200155550ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/robot.html', 'utf8', function (err, html) { console.log(html); }); brfs-1.6.1/example/main.js000066400000000000000000000001521326334022200153630ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/example/robot.html000066400000000000000000000000211326334022200161070ustar00rootroot00000000000000beep boop brfs-1.6.1/index.js000066400000000000000000000101421326334022200141130ustar00rootroot00000000000000var 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 }, parserOpts: opts && opts.parserOpts, sourceMap: opts && (opts.sourceMap || opts._flags && opts._flags.debug) } ); 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.6.1/package.json000066400000000000000000000016461326334022200147450ustar00rootroot00000000000000{ "name": "brfs", "version": "1.6.1", "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.2.0", "through2": "^2.0.0" }, "devDependencies": { "browserify": "^16.1.1", "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.6.1/readme.markdown000066400000000000000000000104321326334022200154510ustar00rootroot00000000000000# brfs fs.readFileSync() and fs.readFile() static asset browserify transform [![build status](https://secure.travis-ci.org/browserify/brfs.png)](http://travis-ci.org/browserify/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`. `opts.parserOpts` can be used to configure the parser brfs uses, [acorn](https://github.com/acornjs/acorn#main-parser). # 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 ES module `import` statements. See [brfs-babel](https://github.com/Jam3/brfs-babel) for an experimental replacement that supports this syntax. # license MIT brfs-1.6.1/test/000077500000000000000000000000001326334022200134275ustar00rootroot00000000000000brfs-1.6.1/test/ag.js000066400000000000000000000010341326334022200143520ustar00rootroot00000000000000var 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.6.1/test/async.js000066400000000000000000000027071326334022200151100ustar00rootroot00000000000000var 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, clearTimeout: clearTimeout, 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, clearTimeout: clearTimeout, 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, clearTimeout: clearTimeout, console: { log: log } }); }); function log (msg) { t.equal(msg, '776861740a') } }); brfs-1.6.1/test/buffer.js000066400000000000000000000017241326334022200152420ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var vm = require('vm'); var path = require('path'); if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; }; 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 }, ArrayBuffer: ArrayBuffer, Uint8Array: Uint8Array, DataView: DataView }; 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.6.1/test/bundle.js000066400000000000000000000011201326334022200152300ustar00rootroot00000000000000var 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.6.1/test/cmd.js000066400000000000000000000011501326334022200145250ustar00rootroot00000000000000var 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.6.1/test/dynamic_read_concat.js000066400000000000000000000006531326334022200177370ustar00rootroot00000000000000var 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.6.1/test/dynamic_read_no_concat.js000066400000000000000000000006611326334022200204320ustar00rootroot00000000000000var 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.6.1/test/encoding.js000066400000000000000000000010541326334022200155530ustar00rootroot00000000000000var 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.6.1/test/files/000077500000000000000000000000001326334022200145315ustar00rootroot00000000000000brfs-1.6.1/test/files/ag.js000066400000000000000000000003621326334022200154570ustar00rootroot00000000000000var 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.6.1/test/files/ag.json000066400000000000000000000000541326334022200160120ustar00rootroot00000000000000{"a":1,"b":2,"c":2,"d":3,"e":4,"f":5,"g":6} brfs-1.6.1/test/files/ag_post.html000066400000000000000000000000061326334022200170470ustar00rootroot00000000000000 brfs-1.6.1/test/files/ag_pre.html000066400000000000000000000000041326334022200166460ustar00rootroot00000000000000

brfs-1.6.1/test/files/async.js000066400000000000000000000001661326334022200162070ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'utf8', function (err, txt) { console.log(txt); }); brfs-1.6.1/test/files/async.txt000066400000000000000000000000051326334022200164020ustar00rootroot00000000000000what brfs-1.6.1/test/files/async_encoding.js000066400000000000000000000002031326334022200200450ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', { encoding: 'hex' }, function (err, txt) { console.log(txt); }); brfs-1.6.1/test/files/async_str_encoding.js000066400000000000000000000001651326334022200207440ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'hex', function (err, txt) { console.log(txt); }); brfs-1.6.1/test/files/buffer.js000066400000000000000000000001401326334022200163330ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html'); console.log(txt); brfs-1.6.1/test/files/dynamic_read_concat.js000066400000000000000000000003201326334022200210300ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(__dirname + dynamicallyCreatedFilename + __dirname, 'utf8'); brfs-1.6.1/test/files/dynamic_read_no_concat.js000066400000000000000000000002701326334022200215300ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(dynamicallyCreatedFilename, 'utf8'); brfs-1.6.1/test/files/encoding.js000066400000000000000000000001651326334022200166570ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' }); console.log(txt);brfs-1.6.1/test/files/hoist.js000066400000000000000000000001521326334022200162130ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/test/files/inline.js000066400000000000000000000001351326334022200163440ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/test/files/main.js000066400000000000000000000001521326334022200160110ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/test/files/multi_var.js000066400000000000000000000001701326334022200170670ustar00rootroot00000000000000var x = 5, y = require('fs'), z = 555; var html = y.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/test/files/non_fs.js000066400000000000000000000001601326334022200163460ustar00rootroot00000000000000var blarg = require('fs'); var html = blarg.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-1.6.1/test/files/path_join.js000066400000000000000000000002171326334022200170420ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(path.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.6.1/test/files/path_join_other_name.js000066400000000000000000000002151326334022200212410ustar00rootroot00000000000000var fs = require('fs'); var xxx = require('path'); var html = fs.readFileSync(xxx.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.6.1/test/files/path_join_single_var.js000066400000000000000000000002171326334022200212530ustar00rootroot00000000000000var fs = require('fs'); var join = require('path').join; var html = fs.readFileSync(join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-1.6.1/test/files/readdir-sync.js000066400000000000000000000001011326334022200174430ustar00rootroot00000000000000var fs = require('fs'); console.log(fs.readdirSync(__dirname)); brfs-1.6.1/test/files/readdir.js000066400000000000000000000001721326334022200165010ustar00rootroot00000000000000var fs = require('fs'); fs.readdir(__dirname, function(err, files) { if (err) throw err; console.log(files); }); brfs-1.6.1/test/files/robot.html000066400000000000000000000000211326334022200165350ustar00rootroot00000000000000beep boop brfs-1.6.1/test/files/separators.js000066400000000000000000000001561326334022200172540ustar00rootroot00000000000000var fs = require('fs'); var text = fs.readFileSync(__dirname + '/separators.txt', 'utf8'); console.log(text); brfs-1.6.1/test/files/separators.txt000066400000000000000000000001001326334022200174440ustar00rootroot00000000000000 LINE_SEPARATOR: 
 (U+2028) PARAGRAPH_SEPARATOR: 
 (U+2029) brfs-1.6.1/test/files/tr.beep000066400000000000000000000002011326334022200160040ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/tr.html', 'utf8'); console.log((FN(){ return html.length })()); brfs-1.6.1/test/files/tr.html000066400000000000000000000000151326334022200160400ustar00rootroot00000000000000

abc

brfs-1.6.1/test/files/with_comments.js000066400000000000000000000003701326334022200177470ustar00rootroot00000000000000var /** * Dependencies. */ fs = require('fs'), /** * Local variables. */ style = fs.readFileSync(__dirname + '/robot.html', 'utf8'); module.exports = function () { console.log(style); }; module.exports();brfs-1.6.1/test/hoist.js000066400000000000000000000011321326334022200151100ustar00rootroot00000000000000var 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.6.1/test/inline.js000066400000000000000000000011221326334022200152370ustar00rootroot00000000000000var 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.6.1/test/multi_var.js000066400000000000000000000011401326334022200157630ustar00rootroot00000000000000var 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.6.1/test/non_fs.js000066400000000000000000000011221326334022200152430ustar00rootroot00000000000000var 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.6.1/test/path_join.js000066400000000000000000000011211326334022200157330ustar00rootroot00000000000000var 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.6.1/test/path_join_other_name.js000066400000000000000000000011471326334022200201440ustar00rootroot00000000000000var 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.6.1/test/path_join_single_var.js000066400000000000000000000011471326334022200201540ustar00rootroot00000000000000var 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.6.1/test/readdir.js000066400000000000000000000021121326334022200153730ustar00rootroot00000000000000var 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, clearTimeout: clearTimeout }); }); 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.6.1/test/require_resolve.js000066400000000000000000000010101326334022200171700ustar00rootroot00000000000000var 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.6.1/test/require_resolve/000077500000000000000000000000001326334022200166425ustar00rootroot00000000000000brfs-1.6.1/test/require_resolve/main.js000066400000000000000000000002131326334022200201200ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(html); brfs-1.6.1/test/require_resolve/node_modules/000077500000000000000000000000001326334022200213175ustar00rootroot00000000000000brfs-1.6.1/test/require_resolve/node_modules/aaa/000077500000000000000000000000001326334022200220415ustar00rootroot00000000000000brfs-1.6.1/test/require_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061326334022200234120ustar00rootroot00000000000000amaze brfs-1.6.1/test/separators.js000066400000000000000000000021451326334022200161520ustar00rootroot00000000000000var 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.6.1/test/tr.js000066400000000000000000000021631326334022200144140ustar00rootroot00000000000000var 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 } }); }); b.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.6.1/test/with_comments.js000066400000000000000000000011431326334022200166440ustar00rootroot00000000000000var 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); } });