Sha256: dc3f98b0083b59bfdb0a66d65bcce2d76bb0994975ef83f70fa127bbe0187ccc

Contents?: true

Size: 1.65 KB

Versions: 19

Compression:

Stored size: 1.65 KB

Contents

'use strict'

var fs = require('fs')
var PassThrough = require('stream').PassThrough
var Transform = require('stream').Transform

if (typeof Transform === 'undefined') {
  throw new Error('UglifyJS only supports browserify when using node >= 0.10.x')
}

var cache = {}
module.exports = transform
function transform(file) {
  if (!/tools\/node\.js$/.test(file.replace(/\\/g,'/'))) return new PassThrough();
  if (cache[file]) return makeStream(cache[file])
  var uglify = require(file)
  var src = 'var sys = require("util");\nvar MOZ_SourceMap = require("source-map");\nvar UglifyJS = exports;\n' + uglify.FILES.map(function (path) { return fs.readFileSync(path, 'utf8') }).join('\n')

  var ast = uglify.parse(src)
  ast.figure_out_scope()

  var variables = ast.variables
    .map(function (node, name) {
      return name
    })

  src += '\n\n' + variables.map(function (v) { return 'exports.' + v + ' = ' + v + ';' }).join('\n') + '\n\n'

  src += 'exports.AST_Node.warn_function = function (txt) { if (typeof console != "undefined" && typeof console.warn === "function") console.warn(txt) }\n\n'

  src += 'exports.minify = ' + uglify.minify.toString() + ';\n\n'
  src += 'exports.describe_ast = ' + uglify.describe_ast.toString() + ';'

  // TODO: remove once https://github.com/substack/node-browserify/issues/631 is resolved
  src = src.replace(/"for"/g, '"fo" + "r"')

  cache[file] = src
  return makeStream(src);
}

function makeStream(src) {
  var res = new Transform();
  res._transform = function (chunk, encoding, callback) { callback() }
  res._flush = function (callback) {
    res.push(src)
    callback()
  }
  return res;
}

Version data entries

19 entries across 17 versions & 9 rubygems

Version Path
epuber-stylus-source-0.56.0 vendor/node_modules/uglify-to-browserify/index.js
epuber-stylus-source-0.54.8 vendor/node_modules/uglify-to-browserify/index.js
ilog-0.4.1 node_modules/uglify-to-browserify/index.js
ilog-0.4.0 node_modules/uglify-to-browserify/index.js
ilog-0.3.3 node_modules/uglify-to-browserify/index.js
optimacms-0.4.3 spec/dummy/node_modules/uglify-to-browserify/index.js
optimacms-0.4.2 spec/dummy/node_modules/uglify-to-browserify/index.js
locomotivecms-3.4.0 app/javascript/node_modules/uglify-to-browserify/index.js
cortex-0.1.3 spec/dummy/node_modules/uglify-to-browserify/index.js
lanes-0.8.0 node_modules/uglify-to-browserify/index.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/handlebars/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/handlebars/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
gulp_assets-1.0.0.pre.5 template/node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
gulp_assets-1.0.0.pre.4 template/node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
gulp_assets-1.0.0.pre.3 template/node_modules/webpack/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
trans-0.5.10 template/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
trans-0.5.10 template/node_modules/grunt-contrib-uglify/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
trans-0.5.9 template/node_modules/gulp-uglify/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js
trans-0.5.9 template/node_modules/grunt-contrib-uglify/node_modules/uglify-js/node_modules/uglify-to-browserify/index.js