benbria / browserify-transform-tools

Utilities for writing browserify transforms.
MIT License
65 stars 15 forks source link

Accept transform options provided upstream #7

Closed milotoor closed 9 years ago

milotoor commented 9 years ago

Browserify's API for writing transforms allows transforms to accept two parameters: the file name, which is mandatory if the transform is to do anything meaningful; and trOpts, or transform options, which are optional but can be used by the transform if it so chooses.

Presently, the make*Transform methods all return a function that accepts a file parameter but no trOpts. Consequently it's impossible for any parameters provided to the transform from somewhere upstream (i.e. via Browserify's own b.transform API, or a build tool such as grunt-browserify) to be processed by the created transform.

I propose modifying the function signature of the transform function returned by makeStringTransform (see transformTools.coffee line 53) from

transform = (file) ->

to

transform = (file, opts) ->

and to change the transformOptions from

transformOptions = {
    file: file,
    configData, configData,
    config: configData?.config
}

to

transformOptions = {
    file: file,
    configData, configData,
    config: configData?.config,
    opts: opts
}

Thoughts?

jwalton commented 9 years ago

Yeah, when I wrote browserify-transform-tools, browserify didn't allow that second parameter, and there was much debate about whether it should or not over in the browserify repo. Now that they support it, we probably should, too; I think this is a much better way to pass options.

milotoor commented 9 years ago

Alright, I'm happy to put together a pull request.

jwalton commented 9 years ago

That would be awesome. :)

milotoor commented 9 years ago

See #8. Criticism wholeheartedly welcome!

jwalton commented 9 years ago

Published to npm. Enjoy! :)

milotoor commented 9 years ago

Thank you!