Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for subarg to allow passing file extension #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ function compileFile(file, src) {
function es6ify(filePattern) {
filePattern = filePattern || /\.js$/;

return function (file) {
return function (file, opts) {
if (opts && opts.extension) {
filePattern = new RegExp(opts.extension);
}

// Don't es6ify the traceur runtime
if (file === runtime) return through();
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
var log = (function(msg) {
return console.log(msg);
});
module.exports = log;
3 changes: 3 additions & 0 deletions test/fixtures/log.js.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var log = msg => console.log(msg);

module.exports = log;
25 changes: 25 additions & 0 deletions test/subarg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var es6ify = require('..')
, test = require('tap').test
, fs = require('fs')
, path = require('path')
, through = require('through');

test('accepts optional argument for file pattern', function(t) {

t.plan(1);
var data = '';
var file = path.join(__dirname, 'fixtures/log.js.es6');

fs.createReadStream(file)
.pipe(es6ify(file, {extension: '.js.es6'}))
.on('error', console.error)
.pipe(through(write, end));

function write (buf) { data += buf; }

function end () {
var expectedOutput = fs.readFileSync(path.join(__dirname, 'fixtures/log.js'));

t.equal(data.indexOf(expectedOutput), 0);
}
});