[
  {
    "path": ".gitignore",
    "content": "node_modules/\n"
  },
  {
    "path": "LICENSE.md",
    "content": "This software is released under the MIT license:\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# uglifyify\n\nA [Browserify](http://browserify.org) v2 transform which minifies your code\nusing [terser](https://github.com/fabiosantoscode/terser) (a maintained fork of uglify-es).\n\n## Installation\n\n``` bash\nnpm install uglifyify\n```\n\n## Motivation/Usage\n\nOrdinarily you'd be fine doing this:\n\n``` bash\nbrowserify index.js | uglifyjs -c > bundle.js\n```\n\nBut uglifyify is able to yield smaller output by processing files individually\ninstead of just the entire bundle. When using uglifyify you should generally\n**also** use Uglify, to achieve the smallest output. Uglifyify provides an\nadditional optimization when used with Uglify, but does not provide all of the\noptimization that using Uglify on its own does, so it's not a replacement.\n\nUglifyify gives you the benefit of applying Uglify's \"squeeze\" transform on each\nfile *before* it's included in the bundle, meaning you can remove dead code\npaths for conditional requires. Here's a contrived example:\n\n``` javascript\nif (true) {\n  module.exports = require('./browser')\n} else {\n  module.exports = require('./node')\n}\n```\n\n`module.exports = require('./node')` will be excluded by Uglify, meaning that\nonly `./browser` will be bundled and required.\n\nIf you combine uglifyify with [envify](http://github.com/hughsk/envify), you\ncan make this a little more accessible. Take this code:\n\n``` javascript\nif (process.env.NODE_ENV === 'development') {\n  module.exports = require('./development')\n} else {\n  module.exports = require('./production')\n}\n```\n\nAnd use this to compile:\n\n``` bash\nNODE_ENV=development browserify -t envify -t uglifyify index.js -o dev.js &&\nNODE_ENV=production browserify -t envify -t uglifyify index.js -o prod.js\n```\n\nIt should go without saying that you should be hesitant using environment\nvariables in a Browserify module - this is best suited to your own\napplications or modules built with Browserify's `--standalone` tag.\n\n## File Extensions\n\nSometimes, you don't want uglifyify to minify all of your files – for example,\nif you're using a transform to `require` CSS or HTML, you might get an error\nas uglify expects JavaScript and will throw if it can't parse what it's given.\n\nThis is done using the `-x` or `--exts` transform options, e.g. from the\ncommand-line:\n\n``` bash\nbrowserify     \\\n  -t coffeeify \\\n  -t [ uglifyify -x .js -x .coffee ]\n```\n\nThe above example will only minify `.js` and `.coffee` files, ignoring the rest.\n\n## Global Transforms\n\nYou might also want to take advantage of uglifyify's pre-bundle minification\nto produce slightly leaner files across your entire browserify bundle. By\ndefault, transforms only alter your application code, but you can use global\ntransforms to minify module code too. From your terminal:\n\n``` bash\nbrowserify -g uglifyify ./index.js > bundle.js\n```\n\nOr programatically:\n\n``` javascript\nvar browserify = require('browserify')\nvar fs = require('fs')\n\nvar bundler = browserify(__dirname + '/index.js')\n\nbundler.transform('uglifyify', { global: true  })\n\nbundler.bundle()\n  .pipe(fs.createWriteStream(__dirname + '/bundle.js'))\n```\n\nNote that this is fine for uglifyify as it shouldn't modify the behavior of\nyour code unexpectedly, but transforms such as envify should almost always\nstay local – otherwise you'll run into unexpected side-effects within modules\nthat weren't expecting to be modified as such.\n\n## Ignoring Files\n\nSometimes uglifyjs will break specific files under specific settings – it's\nrare, but does happen – and to work around that, you can use the `ignore`\noption. Given one or more glob patterns, you can filter out specific files\nthis way:\n\n``` bash\nbrowserify -g [ uglifyify --ignore '**/node_modules/weakmap/*' ] ./index.js\n```\n\n``` javascript\nvar bundler = browserify('index.js')\n\nbundler.transform('uglifyify', {\n  global: true,\n  ignore: [\n      '**/node_modules/weakmap/*'\n    , '**/node_modules/async/*'\n  ]\n})\n\nbundler.bundle().pipe(process.stdout)\n```\n\n## Source Maps\n\nUglifyify supports source maps, so you can minify your code and still see the\noriginal source – this works especially well with a tool such as\n[exorcist](https://github.com/thlorenz/exorcist) when creating production\nbuilds.\n\nSource maps are enabled when:\n\n* You're using another transform, such as\n  [coffeeify](https://github.com/jnordberg/coffeeify), that inlines source maps.\n* You've passed the `--debug` flag (or `debug` option) to your browserify\n  bundle.\n\nEnabling `--debug` with browserify is easy:\n\n``` bash\nbrowserify -t uglifyify --debug index.js\n```\n``` javascript\nvar bundler = browserify({ debug: true })\n\nbundler\n  .add('index.js')\n  .transform('uglifyify')\n  .bundle()\n  .pipe(process.stdout)\n```\n\nIf you'd prefer them not to be included regardless, you can opt out\nusing the `sourcemap` option:\n\n``` bash\nbrowserify -t [ uglifyify --no-sourcemap ] app.js\n```\n``` javascript\nvar bundler = browserify('index.js')\n\nbundler.transform('uglifyify', { sourceMap: false })\n  .bundle()\n  .pipe(process.stdout)\n```\n"
  },
  {
    "path": "index.js",
    "content": "var minimatch = require('minimatch').Minimatch\n  , convert = require('convert-source-map')\n  , through = require('through')\n  , path = require('path')\n  , ujs = require('terser')\n  , xtend = require('xtend')\n\nmodule.exports = uglifyify\n\nfunction uglifyify(file, opts) {\n  opts = xtend(opts || {})\n\n  var debug = opts._flags && opts._flags.debug\n\n  if (ignore(file, opts.ignore)) {\n    return through()\n  }\n\n  var buffer = ''\n  var exts = []\n    .concat(opts.exts || [])\n    .concat(opts.x || [])\n    .map(function(d) {\n      if (d.charAt(0) === '.') return d\n      return '.' + d\n    })\n\n  if (\n    /\\.json$/.test(file) ||\n    exts.length &&\n    exts.indexOf(path.extname(file)) === -1\n  ) {\n    return through()\n  }\n\n  // remove exts before passing opts to uglify\n  delete opts.global\n  delete opts.exts\n  delete opts.x\n\n  return through(function write(chunk) {\n    buffer += chunk\n  }, capture(function ready() {\n    debug = opts.sourceMap !== false && debug\n    opts  = xtend({\n      compress: true,\n      mangle: true,\n      sourceMap: {\n        filename: file\n      }\n    }, opts)\n\n    // map out command line options to uglify compatible ones\n    mapArgv(opts)\n\n    if (typeof opts.compress === 'object') {\n      delete opts.compress._\n    }\n\n    if (debug) opts.sourceMap.url = 'out.js.map'\n\n    // Check if incoming source code already has source map comment.\n    // If so, send it in to ujs.minify as the inSourceMap parameter\n    if (debug) {\n      opts.sourceMap.content = 'inline'\n    }\n\n    var min = ujs.minify(buffer, opts)\n    // we should catcch the min error if it comes back and end the stream\n    if (min.error) return this.emit('error', min.error)\n\n    // Uglify leaves a source map comment pointing back to \"out.js.map\",\n    // which we want to get rid of because it confuses browserify.\n    min.code = min.code.replace(/\\/\\/[#@] ?sourceMappingURL=out.js.map$/, '')\n    this.queue(min.code)\n\n    if (min.map && min.map !== 'null') {\n      var map = convert.fromJSON(min.map)\n\n      map.setProperty('sources', [path.basename(file)])\n\n      this.queue('\\n')\n      this.queue(map.toComment())\n    }\n\n    this.queue(null)\n  }))\n\n  function capture(fn) {\n    return function() {\n      try {\n        fn.apply(this, arguments)\n      } catch(err) {\n        return this.emit('error', err)\n      }\n    }\n  }\n}\n\nfunction ignore(file, list) {\n  if (!list) return\n\n  list = Array.isArray(list) ? list : [list]\n\n  return list.some(function(pattern) {\n    var match = minimatch(pattern)\n    return match.match(file)\n  })\n}\n\n// uglify-es doesn't allow for command line options in javascript api, this\n// remaps it\nfunction mapArgv (opts) {\n  if (opts._flags) {\n    delete opts._flags\n  }\n  if (opts.c) {\n    opts.compress = opts.c\n    delete opts.c\n  }\n  if (opts.m) {\n    opts.mangle = opts.m\n    delete opts.m\n  }\n  if (opts.p) {\n    opts.parse = opts.p\n    delete opts.p\n  }\n  if (opts.b) {\n    opts.beautify = opts.b\n    delete opts.b\n  }\n  if (opts.o) {\n    opts.output = opts.o\n    delete opts.o\n  }\n  if (opts.d) {\n    opts.define = opts.d\n    delete opts.d\n  }\n  delete opts._\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"uglifyify\",\n  \"version\": \"5.0.2\",\n  \"description\": \"A browserify transform which minifies your code using UglifyJS2\",\n  \"main\": \"index.js\",\n  \"dependencies\": {\n    \"convert-source-map\": \"~1.1.0\",\n    \"minimatch\": \"^3.0.2\",\n    \"terser\": \"^3.7.5\",\n    \"through\": \"~2.3.4\",\n    \"xtend\": \"^4.0.1\"\n  },\n  \"devDependencies\": {\n    \"bl\": \"^0.9.3\",\n    \"browserify\": \"^8.1.1\",\n    \"from2\": \"^1.3.0\",\n    \"tap-spec\": \"^2.1.2\",\n    \"tape\": \"^3.2.0\",\n    \"wrap-stream\": \"^2.0.0\"\n  },\n  \"scripts\": {\n    \"test\": \"node test | tap-spec\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/hughsk/uglifyify.git\"\n  },\n  \"keywords\": [\n    \"uglify\",\n    \"minify\",\n    \"compress\",\n    \"compile\",\n    \"browserify\",\n    \"transform\",\n    \"stream\"\n  ],\n  \"author\": \"Hugh Kennedy <hughskennedy@gmail.com> (http://hughskennedy.com/)\",\n  \"license\": \"MIT\",\n  \"readmeFilename\": \"README.md\"\n}\n"
  },
  {
    "path": "test/fixture.js",
    "content": "var hello = 'world'\nif (hello !== 'world') {\n  throw new Error\n}\n"
  },
  {
    "path": "test/index.js",
    "content": "const convert    = require('convert-source-map')\nconst wrap       = require('wrap-stream')\nconst browserify = require('browserify')\nconst uglify     = require('terser')\nconst from2      = require('from2')\nconst test       = require('tape')\nconst path       = require('path')\nconst uglifyify  = require('../')\nconst fs         = require('fs')\nconst bl         = require('bl')\n\ntest('uglifyify: sanity check', function(t) {\n  var src  = path.join(__dirname, 'fixture.js')\n  var orig = fs.readFileSync(src, 'utf8')\n\n  fs.createReadStream(src)\n    .pipe(uglifyify(src))\n    .pipe(bl(function(err, data) {\n      if (err) return t.ifError(err)\n      data = String(data)\n      t.notEqual(data.indexOf('var hello'), -1, 'var hello')\n      t.notEqual(data.indexOf('\"world\"'), -1, '\"world\"')\n      t.notEqual(data, orig, 'should be minified')\n      t.end()\n    }))\n})\n\ntest('uglifyify: ignores json', function(t) {\n  var src  = path.join(__dirname, 'fixture.js')\n  var json = path.join(__dirname, 'fixture.json')\n  var orig = fs.readFileSync(src, 'utf8')\n\n  fs.createReadStream(src)\n    .pipe(uglifyify(json))\n    .pipe(bl(buffered))\n\n  function buffered(err, data) {\n    if (err) return t.ifError(err)\n    data = String(data)\n    t.equal(data, orig, 'should not be minified')\n    t.end()\n  }\n})\n\ntest('uglifyify: -t [ uglifyify --exts ]', function(t) {\n  var src  = path.join(__dirname, 'fixture.js')\n  var orig = fs.readFileSync(src, 'utf8')\n\n  t.plan(5)\n\n  check(path.join(__dirname, 'fixture.json'), true)\n  check(path.join(__dirname, 'fixture.obj2'), false)\n  check(path.join(__dirname, 'fixture.mkdn'), false)\n  check(path.join(__dirname, 'fixture.fbla'), true)\n  check(src, true)\n\n  function check(name, ignored) {\n    fs.createReadStream(src)\n      .pipe(uglifyify(name, { exts: ['mkdn' ], x: ['.obj2'] }))\n      .pipe(bl(buffered))\n\n    function buffered(err, data) {\n      if (err) return t.ifError(err)\n      data = String(data)\n      t.ok(ignored\n        ? data === orig\n        : data !== orig\n      , path.extname(name) + ' handled as expected')\n    }\n  }\n})\n\ntest('uglifyify: passes options to uglify', function(t) {\n  var src  = path.join(__dirname, 'fixture.js')\n  var orig = fs.readFileSync(src, 'utf8')\n  var buf1 = null\n\n  fs.createReadStream(src)\n    .pipe(closure())\n    .pipe(uglifyify(src, { compress: { conditionals: false } }))\n    .pipe(bl(buffered1))\n\n  function buffered1(err, _buf1) {\n    if (err) return t.ifError(err)\n    buf1 = String(_buf1)\n    t.notEqual(buf1, orig, 'should be minified')\n\n    fs.createReadStream(src)\n      .pipe(closure())\n      .pipe(uglifyify(src))\n      .pipe(bl(buffered2))\n  }\n\n  function buffered2(err, buf2) {\n    if (err) return\n    buf2 = String(buf2)\n    t.notEqual(buf2, orig, 'should be minified')\n    t.notEqual(buf1, buf2, 'options altered output')\n    t.end()\n  }\n})\n\n\n\nfunction closure() {\n  return wrap('(function(){', '})()')\n}\n\ntest('uglifyify: sourcemaps', function(t) {\n  t.plan(10)\n\n  var src  = path.join(__dirname, 'fixture.js')\n  var json = path.join(__dirname, 'fixture.json')\n  var orig = fs.readFileSync(src, 'utf8')\n  var min  = uglify.minify(orig, {\n    sourceMap: {\n      url: 'out.js.map'\n    }\n  })\n\n  var map = convert.fromJSON(min.map)\n  map.setProperty('sources', [src])\n  map.setProperty('sourcesContent', [orig])\n\n  var mapped = [orig, map.toComment()].join('\\n')\n\n  from2([mapped])\n    .pipe(uglifyify(json))\n    .pipe(bl(doneWithMap))\n\n  from2([orig])\n    .pipe(uglifyify(json))\n    .pipe(bl(doneWithoutMap))\n\n  browserify({ entries: [src], debug: true })\n    .transform(uglifyify)\n    .bundle()\n    .pipe(bl(doneWithMap))\n\n  browserify({ entries: [src], debug: false })\n    .transform(uglifyify)\n    .bundle()\n    .pipe(bl(doneWithoutDebug))\n\n  from2([mapped])\n    .pipe(uglifyify(json, { _flags: { debug: false }}))\n    .pipe(bl(doneWithMapAndNoDebug))\n\n  function doneWithMap(err, data) {\n    if (err) return t.ifError(err)\n    data = String(data)\n    t.notEqual(data, orig, 'should have changed')\n    t.equal(data.match(/\\/\\/[@#]/g).length, 1, 'should have sourcemap')\n  }\n\n  function doneWithoutMap(err, data) {\n    if (err) return t.ifError(err)\n    data = String(data)\n    t.equal(data, orig, 'should not have changed')\n    t.equal(data.indexOf(/\\/\\/[@#]/g), -1, 'should not have sourcemap')\n  }\n\n  function doneWithoutDebug(err, data) {\n    if (err) return t.ifError(err)\n    data = String(data)\n    t.notEqual(data, orig, 'should have changed')\n    t.equal(data.indexOf(/\\/\\/[@#]/g), -1, 'should not have sourcemap')\n  }\n\n  function doneWithMapAndNoDebug(err, data) {\n    if (err) return t.ifError(err)\n    data = String(data)\n    t.notEqual(data, orig, 'should have changed')\n    t.equal(data.match(/\\/\\/[@#]/g).length, 1, 'should have sourcemap')\n  }\n})\n\ntest('uglifyify: transform is stable', function(t) {\n  t.plan(1)\n\n  var src  = path.join(__dirname, 'fixture.js')\n  var opts = {\n    _flags: {\n      debug: false\n    }\n  }\n\n  var tr1 = fs.createReadStream(src).pipe(uglifyify(src, opts))\n  var tr2 = fs.createReadStream(src).pipe(uglifyify(src, opts))\n\n  tr1.pipe(bl(function(err, data) {\n    if (err) return t.ifError(err)\n    var data1 = String(data)\n\n    tr2.pipe(bl(function(err, data) {\n      if (err) return t.ifError(err)\n      var data2 = String(data)\n\n      t.equal(data2, data1, 'repeated runs should be the same')\n      t.end()\n    }))\n  }))\n})\n"
  }
]