pax_global_header00006660000000000000000000000064134330235540014514gustar00rootroot0000000000000052 comment=660f6d81cb22eba997503ce17150db2c4aa3f94d brfs-2.0.2/000077500000000000000000000000001343302355400124515ustar00rootroot00000000000000brfs-2.0.2/.travis.yml000066400000000000000000000002501343302355400145570ustar00rootroot00000000000000language: node_js node_js: - "10" - "9" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: - 'nvm install-latest-npm' sudo: false brfs-2.0.2/LICENSE000066400000000000000000000020611343302355400134550ustar00rootroot00000000000000This 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-2.0.2/bin/000077500000000000000000000000001343302355400132215ustar00rootroot00000000000000brfs-2.0.2/bin/cmd.js000077500000000000000000000007511343302355400143300ustar00rootroot00000000000000#!/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-2.0.2/bin/usage.txt000066400000000000000000000003711343302355400150670ustar00rootroot00000000000000usage: 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-2.0.2/example/000077500000000000000000000000001343302355400141045ustar00rootroot00000000000000brfs-2.0.2/example/async.js000066400000000000000000000001711343302355400155560ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/robot.html', 'utf8', function (err, html) { console.log(html); }); brfs-2.0.2/example/main.js000066400000000000000000000001521343302355400153640ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/example/robot.html000066400000000000000000000000211343302355400161100ustar00rootroot00000000000000beep boop brfs-2.0.2/index.js000066400000000000000000000102031343302355400141120ustar00rootroot00000000000000var 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), inputFilename: file } ); 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-2.0.2/package.json000066400000000000000000000016471343302355400147470ustar00rootroot00000000000000{ "name": "brfs", "version": "2.0.2", "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": "^3.0.2", "through2": "^2.0.0" }, "devDependencies": { "browserify": "^16.1.1", "concat-stream": "^1.6.0", "tap": "^10.7.3", "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-2.0.2/readme.markdown000066400000000000000000000104321343302355400154520ustar00rootroot00000000000000# 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-2.0.2/test/000077500000000000000000000000001343302355400134305ustar00rootroot00000000000000brfs-2.0.2/test/ag.js000066400000000000000000000010341343302355400143530ustar00rootroot00000000000000var 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-2.0.2/test/async.js000066400000000000000000000027071343302355400151110ustar00rootroot00000000000000var 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-2.0.2/test/buffer.js000066400000000000000000000017241343302355400152430ustar00rootroot00000000000000var 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-2.0.2/test/bundle.js000066400000000000000000000011201343302355400152310ustar00rootroot00000000000000var 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-2.0.2/test/cmd.js000066400000000000000000000011501343302355400145260ustar00rootroot00000000000000var 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-2.0.2/test/dynamic_read_concat.js000066400000000000000000000006531343302355400177400ustar00rootroot00000000000000var 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-2.0.2/test/dynamic_read_no_concat.js000066400000000000000000000006611343302355400204330ustar00rootroot00000000000000var 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-2.0.2/test/encoding.js000066400000000000000000000010541343302355400155540ustar00rootroot00000000000000var 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-2.0.2/test/files/000077500000000000000000000000001343302355400145325ustar00rootroot00000000000000brfs-2.0.2/test/files/ag.js000066400000000000000000000003621343302355400154600ustar00rootroot00000000000000var 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-2.0.2/test/files/ag.json000066400000000000000000000000541343302355400160130ustar00rootroot00000000000000{"a":1,"b":2,"c":2,"d":3,"e":4,"f":5,"g":6} brfs-2.0.2/test/files/ag_post.html000066400000000000000000000000061343302355400170500ustar00rootroot00000000000000 brfs-2.0.2/test/files/ag_pre.html000066400000000000000000000000041343302355400166470ustar00rootroot00000000000000

brfs-2.0.2/test/files/async.js000066400000000000000000000001661343302355400162100ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'utf8', function (err, txt) { console.log(txt); }); brfs-2.0.2/test/files/async.txt000066400000000000000000000000051343302355400164030ustar00rootroot00000000000000what brfs-2.0.2/test/files/async_encoding.js000066400000000000000000000002031343302355400200460ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', { encoding: 'hex' }, function (err, txt) { console.log(txt); }); brfs-2.0.2/test/files/async_str_encoding.js000066400000000000000000000001651343302355400207450ustar00rootroot00000000000000var fs = require('fs'); fs.readFile(__dirname + '/async.txt', 'hex', function (err, txt) { console.log(txt); }); brfs-2.0.2/test/files/buffer.js000066400000000000000000000001401343302355400163340ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html'); console.log(txt); brfs-2.0.2/test/files/dynamic_read_concat.js000066400000000000000000000003201343302355400210310ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(__dirname + dynamicallyCreatedFilename + __dirname, 'utf8'); brfs-2.0.2/test/files/dynamic_read_no_concat.js000066400000000000000000000002701343302355400215310ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); var stuff = fs.readFileSync(dynamicallyCreatedFilename, 'utf8'); brfs-2.0.2/test/files/encoding.js000066400000000000000000000001651343302355400166600ustar00rootroot00000000000000var fs = require('fs'); var txt = fs.readFileSync(__dirname + '/robot.html', { encoding: 'hex' }); console.log(txt);brfs-2.0.2/test/files/hoist.js000066400000000000000000000001521343302355400162140ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/test/files/inline.js000066400000000000000000000001351343302355400163450ustar00rootroot00000000000000var html = require('fs').readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/test/files/main.js000066400000000000000000000001521343302355400160120ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/test/files/multi_var.js000066400000000000000000000001701343302355400170700ustar00rootroot00000000000000var x = 5, y = require('fs'), z = 555; var html = y.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/test/files/non_fs.js000066400000000000000000000001601343302355400163470ustar00rootroot00000000000000var blarg = require('fs'); var html = blarg.readFileSync(__dirname + '/robot.html', 'utf8'); console.log(html); brfs-2.0.2/test/files/path_join.js000066400000000000000000000002171343302355400170430ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(path.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-2.0.2/test/files/path_join_other_name.js000066400000000000000000000002151343302355400212420ustar00rootroot00000000000000var fs = require('fs'); var xxx = require('path'); var html = fs.readFileSync(xxx.join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-2.0.2/test/files/path_join_single_var.js000066400000000000000000000002171343302355400212540ustar00rootroot00000000000000var fs = require('fs'); var join = require('path').join; var html = fs.readFileSync(join(__dirname, 'robot.html'), 'utf8'); console.log(html); brfs-2.0.2/test/files/readdir-sync.js000066400000000000000000000001011343302355400174440ustar00rootroot00000000000000var fs = require('fs'); console.log(fs.readdirSync(__dirname)); brfs-2.0.2/test/files/readdir.js000066400000000000000000000001721343302355400165020ustar00rootroot00000000000000var fs = require('fs'); fs.readdir(__dirname, function(err, files) { if (err) throw err; console.log(files); }); brfs-2.0.2/test/files/robot.html000066400000000000000000000000211343302355400165360ustar00rootroot00000000000000beep boop brfs-2.0.2/test/files/scope-sentinel000066400000000000000000000000171343302355400174030ustar00rootroot00000000000000SCOPE_SENTINEL brfs-2.0.2/test/files/scope.js000066400000000000000000000005451343302355400162050ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var dynamicallyCreatedFilename = path.join('/files/', 'somefile'); fs.readFileSync(__dirname + dynamicallyCreatedFilename + __dirname, 'utf8'); function x (fs) { fs.readFileSync('doesNotExist') } fs.readFileSync(__dirname + '/scope-sentinel') require('fs').readFileSync(__dirname + '/scope-sentinel') brfs-2.0.2/test/files/separators.js000066400000000000000000000001561343302355400172550ustar00rootroot00000000000000var fs = require('fs'); var text = fs.readFileSync(__dirname + '/separators.txt', 'utf8'); console.log(text); brfs-2.0.2/test/files/separators.txt000066400000000000000000000001001343302355400174450ustar00rootroot00000000000000 LINE_SEPARATOR: 
 (U+2028) PARAGRAPH_SEPARATOR: 
 (U+2029) brfs-2.0.2/test/files/tr.beep000066400000000000000000000002011343302355400160050ustar00rootroot00000000000000var fs = require('fs'); var html = fs.readFileSync(__dirname + '/tr.html', 'utf8'); console.log((FN(){ return html.length })()); brfs-2.0.2/test/files/tr.html000066400000000000000000000000151343302355400160410ustar00rootroot00000000000000

abc

brfs-2.0.2/test/files/with_comments.js000066400000000000000000000003701343302355400177500ustar00rootroot00000000000000var /** * Dependencies. */ fs = require('fs'), /** * Local variables. */ style = fs.readFileSync(__dirname + '/robot.html', 'utf8'); module.exports = function () { console.log(style); }; module.exports();brfs-2.0.2/test/hoist.js000066400000000000000000000011321343302355400151110ustar00rootroot00000000000000var 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-2.0.2/test/inline.js000066400000000000000000000011221343302355400152400ustar00rootroot00000000000000var 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-2.0.2/test/multi_var.js000066400000000000000000000011401343302355400157640ustar00rootroot00000000000000var 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-2.0.2/test/non_fs.js000066400000000000000000000011221343302355400152440ustar00rootroot00000000000000var 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-2.0.2/test/path_join.js000066400000000000000000000011211343302355400157340ustar00rootroot00000000000000var 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-2.0.2/test/path_join_other_name.js000066400000000000000000000011471343302355400201450ustar00rootroot00000000000000var 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-2.0.2/test/path_join_single_var.js000066400000000000000000000011471343302355400201550ustar00rootroot00000000000000var 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-2.0.2/test/readdir.js000066400000000000000000000021121343302355400153740ustar00rootroot00000000000000var 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-2.0.2/test/require_resolve.js000066400000000000000000000010101343302355400171710ustar00rootroot00000000000000var 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-2.0.2/test/require_resolve/000077500000000000000000000000001343302355400166435ustar00rootroot00000000000000brfs-2.0.2/test/require_resolve/main.js000066400000000000000000000002131343302355400201210ustar00rootroot00000000000000var fs = require('fs'); var path = require('path'); var html = fs.readFileSync(require.resolve('aaa/wow.txt'), 'utf8'); console.log(html); brfs-2.0.2/test/require_resolve/node_modules/000077500000000000000000000000001343302355400213205ustar00rootroot00000000000000brfs-2.0.2/test/require_resolve/node_modules/aaa/000077500000000000000000000000001343302355400220425ustar00rootroot00000000000000brfs-2.0.2/test/require_resolve/node_modules/aaa/wow.txt000066400000000000000000000000061343302355400234130ustar00rootroot00000000000000amaze brfs-2.0.2/test/scope.js000066400000000000000000000013671343302355400151060ustar00rootroot00000000000000var test = require('tap').test; var browserify = require('browserify'); var path = require('path'); test('scope', function (t) { t.plan(4); var b = browserify({ node: true }); b.add(__dirname + '/files/scope'); b.transform(path.dirname(__dirname)); b.bundle(function (err, src) { if (err) t.fail(err); t.pass('build success'); src = src.toString(); t.ok(src.indexOf("require('fs')") !== -1, 'kept the require call'); var sentinel = new Buffer('SCOPE_SENTINEL\n', 'utf8').toString('base64') var i = src.indexOf(sentinel); t.ok(i !== -1, 'read the file'); i = src.indexOf(sentinel, i + 10); t.ok(i !== -1, 'did the require("fs").readFileSync'); }); }); brfs-2.0.2/test/separators.js000066400000000000000000000021451343302355400161530ustar00rootroot00000000000000var 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-2.0.2/test/tr.js000066400000000000000000000021631343302355400144150ustar00rootroot00000000000000var 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-2.0.2/test/with_comments.js000066400000000000000000000011431343302355400166450ustar00rootroot00000000000000var 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); } });