hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
901 stars 57 forks source link

Improve default behavior #10

Open yoshuawuyts opened 10 years ago

yoshuawuyts commented 10 years ago

I ran into https://github.com/hughsk/envify/issues/7 again today, which made me wonder if we might improve the default behavior or envify.

Instead of having to choose between require('envify') and require('envify/custom') this behavior might be more intuitive.

var envify = require('envify');

// detects the process.env.NODE_ENV variable
browserify()
  .transform(envify())

// manually override the environment
browserify()
   .transform(envify({env: 'custom'});

Let me know what you think, if you approve I'll PR the changes.

hughsk commented 10 years ago

So the reason for this API being as it is right now is to cater to transforms specified from either the CLI or within a package.json file: in this case, you're expected to export a function with the transform signature, i.e.:

module.exports = function(file, opts) {
  return new Stream
}

So in the above example you'd actually have the following, where envify is passed in directly:

var envify = require('envify')

browserify().transform(envify)

The only way to get the behaviour you're after is to check the first argument for an Object vs. String, which could be a bit quirky but might work! Would definitely want this to be a major version bump though. If you wanna give it a shot send a PR and we'll see :)