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

API Transforms w/ Options #62

Closed
joshlasdin opened this issue Dec 8, 2014 · 6 comments
Closed

API Transforms w/ Options #62

joshlasdin opened this issue Dec 8, 2014 · 6 comments

Comments

@joshlasdin
Copy link

How do I specify options for transforms (using more than 1) using the API syntax? Saw this thread: #39 but I can't find a way to pass options to the transform.

Thanks!

@joshlasdin
Copy link
Author

Maybe I'm misunderstanding this block, but according to node-browserify b.transform() accepts two properties in the order of name, options. Other projects like grunt-browserify allow an array of transforms which can each have settings defined (in [name, options]) format. Wondering if that same mentality could be applied here, changing:

if (opts.transform) {
    [].concat(opts.transform).forEach(function (t) {
        if (typeof t === 'string') {
            b.transform({}, t);
        } else {
            b.transform(t, t._.shift());
        }
    });
}

to:

if (opts.transform) {
    [].concat(opts.transform).forEach(function (t) {
        if (typeof t === 'string') {
            b.transform(t, {});
        } else {
            b.transform(t[0], t[1]);
        }
    });
}

(example options definition):

{
    transform: [
        ['hbsfy', { global: true }],
        ['debowerify', { global: true }]
    ]
}

Of course, I may just be totally misunderstanding this block, but this change appears to work in the way I thought the API option would be used.

@mantoni
Copy link
Owner

mantoni commented Dec 9, 2014

You can specify multiple transforms by using --transform multiple times. To pass arguments to the transforms, you have to use the subarg notation:

$ mochify --transform [ mything -x -y -z ]

Does that answer your question?

@joshlasdin
Copy link
Author

@mantoni Actually I was referring to using the module API, the example given in the README was:

var mochify = require('mochify');

mochify('./test/*.js', {
    reporter : 'tap',
    cover    : true
}).bundle();

Thanks!

@mantoni
Copy link
Owner

mantoni commented Dec 9, 2014

Ah, I see. Well, then you will have to look into the browserify API documentation. Mochify returns a Browserify instance. So this is what the API is like:

b.transform(tr, opts={})

@mantoni mantoni closed this as completed Dec 9, 2014
@joshlasdin
Copy link
Author

Ah, I didn't realize that it returned a browserify instance, moved my transforms to just use the browserify api directly and that works great. Thanks!

@leslc
Copy link

leslc commented Dec 2, 2015

I've been looking for an example of passing arguments to "hbsfy" transform via subarg syntax. Finally got it working and posting for others in case they're searching.

I want to pass in these arguments:

hbsfy --compiler 'require("handlebars")'

(Reason for this is that I can't use the hbsfy/runtime because I need to dynamically register partials).

The subarg syntax to do this is:

    b = mochify(config.tests.testFiles, {
      transform: { _: [ 'hbsfy' ], compiler: 'require("handlebars")' },
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants