Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minifyify

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minifyify - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

.npmignore

9

lib/decouple.js

@@ -11,5 +11,6 @@ var atob = require('atob')

var marker = '//@ sourceMappingURL=data:application/json;base64,'
, offset = src.indexOf(marker)
, offset = src.lastIndexOf(marker)
, defaults = {map: 'scripts.map'}
, map;
, map
, substr;

@@ -23,4 +24,6 @@ opts = opts || {};

map = atob(src.substring(offset + marker.length));
substr = src.substring(offset + marker.length);
map = atob(substr);
return {

@@ -27,0 +30,0 @@ code: src.substring(0, offset)

@@ -5,2 +5,3 @@ var SM = require('source-map')

, validate = require('./validate')
, toAscii = require('./toAscii')
, enhance;

@@ -40,3 +41,4 @@

generator.setSourceContent(source, sourceContent);
// Writing sourcemaps with funky unicode chars breaks stuff..
generator.setSourceContent(source, toAscii(sourceContent));

@@ -43,0 +45,0 @@ return generator.toString();

@@ -10,2 +10,5 @@ var minifyUglify

, fromString: true
, output: {
ascii_only: true
}
});

@@ -12,0 +15,0 @@ }

@@ -25,11 +25,18 @@ var Minifyify

function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
/*
* Helper function, copies a file over to the temporary directory,
* minifying if needed
* minifying and transforming and all that sweet, smooth jazz
*/
copyFile = function (source, destination, opts, next) {
var buff = []
, write = function (d) {
buff.push(d)
, write = function (data) {
buff.push(data)
}

@@ -40,3 +47,2 @@ , end = function () {

, afterMin = function (code, map) {
// Enhance the map

@@ -64,4 +70,11 @@ map = enhanceMap(map, source, buffer);

fs.createReadStream(source)
.pipe( opts.minifier ? minifyingThrough : noopThrough )
var copyStream = fs.createReadStream(source);
// Must pipe through each transform before we minify
// as they might convert non-js files into js
_.each(opts.transforms, function (transform) {
copyStream = copyStream.pipe(transform(source));
});
copyStream.pipe( opts.minifier ? minifyingThrough : noopThrough )
.pipe( fs.createWriteStream(destination).on('finish', next) );

@@ -78,17 +91,8 @@ };

bundleIntoTempDir = function (bundle, opts, cb) {
_.each(opts.transforms, function (transform) {
bundle.transform(transform);
});
var files = [];
bundle
.bundle({debug:true})
.pipe(through(write, end));
var brwsfyBuffer = [];
function write(d) {
brwsfyBuffer.push(d);
};
function end() {
var d = bundle.deps({transform: opts.transforms});
d.pipe(through(function (dep) {
files.push(dep.id);
}, function () {
var self = this

@@ -98,31 +102,19 @@ , tmpdir = path.join(require('osenv').tmpdir(), utils.string.uuid(5))

, chainParams = []
, loadFile
, basedir
, bundleData = brwsfyBuffer.join('')
, filesUnderBaseDir
, files = {};
, packageJsons;
// Pull apart the source map to discover the packages and files used
files = findSources(bundleData);
// Figure out the base directory
// Figure out the base directory so we can use shorter file paths
basedir = findRoot(files);
// Copy over all the package.json files we can find under this directory for browserify
filesUnderBaseDir = _.filter(utils.file.readdirR(basedir), function (p) {
// Copy over all the package.json files we can find under this directory
packageJsons = _.filter(utils.file.readdirR(basedir), function (p) {
return path.basename(p) === 'package.json';
});
files = files.concat(filesUnderBaseDir);
// Add all the package.json files
files = files.concat(packageJsons);
files = _.map(files, function (file) {
return {
key: path.relative(basedir, file)
, file: file
};
});
// Convert to array of AsyncChain params
chainParams = _.map(files, function (f) {
var dest = path.join(tmpdir, f.key)
var dest = path.join(tmpdir, opts.compressPaths(f, basedir))
, dir = path.dirname(dest)

@@ -133,8 +125,10 @@ , modOpts = _.clone(opts);

// Don't minify package.json files
if(path.extname(f.file)==='.json')
// Don't minify .json files, but assume
// that everything else has been transformed
// into js (e.g. hbs templates)
if(path.extname(f)==='.json')
modOpts.minifier = false;
return {
args: [f.file, dest, modOpts]
args: [f, dest, modOpts]
, func: copyFile

@@ -153,3 +147,3 @@ , callback: null

chain.run();
}
}));
};

@@ -173,3 +167,3 @@

* , 'uglify' (default) or 'gcc' (needs Java)
* @param [opts.compressPaths] {Function} - Transform source paths in the map
* @param [opts.compressPaths] {Function} - Transform source paths in the map, function(path, base)
* @param cb {Function} - Callback with signature function(code, map)

@@ -184,9 +178,6 @@ */

, transforms: []
, compressPaths: function (p) {
return path.relative(process.cwd(), p);
, compressPaths: function (fullPath, baseDir) {
return path.relative(baseDir, fullPath);
}
}
, hint = function (f) {
console.log(' > ' + f);
};
};

@@ -214,3 +205,3 @@ opts = opts || {}

transform(opts, decoupled.code, decoupled.map, cb);
transform(_.extend(opts,{basedir:basedir}), decoupled.code, decoupled.map, cb);
});

@@ -217,0 +208,0 @@ });

@@ -10,3 +10,3 @@ var transform

* Transforms source code and a map
* opts [Object] - {file: string, map: string, compressPaths: function}
* opts [Object] - {file: string, map: string, compressPaths: function, basedir: string}
* code [String] - The code to transform

@@ -26,16 +26,17 @@ * map [String] - The map to tranform

var newMapping = {
generated: {
line: mapping.generatedLine
, column: mapping.generatedColumn
}
, original: {
line: mapping.originalLine
, column: mapping.originalColumn
}
, source: opts.compressPaths(mapping.source)
, name: mapping.name
};
var compressedSource = opts.compressPaths(mapping.source, opts.basedir)
, newMapping = {
generated: {
line: mapping.generatedLine
, column: mapping.generatedColumn
}
, original: {
line: mapping.originalLine
, column: mapping.originalColumn
}
, source: compressedSource
, name: mapping.name
};
sources[opts.compressPaths(mapping.source)] = mapping.source;
sources[compressedSource] = mapping.source;
generator.addMapping(newMapping);

@@ -42,0 +43,0 @@ }

@@ -14,3 +14,3 @@ {

],
"version": "0.3.1",
"version": "0.3.2",
"repository": {

@@ -38,3 +38,5 @@ "type": "git",

"jake": "latest",
"backbone": "1.0.x"
"backbone": "1.0.x",
"hbsfy": "0.1.x",
"handlebars-runtime": "1.0.x"
},

@@ -41,0 +43,0 @@ "optionalDependencies": {},

Minifyify
---------
=========
#### Tiny, Debuggable Browserify Bundles

@@ -11,2 +11,6 @@

## Known Issues
There is an issue in `browserify` that results in broken sourcemaps. [Use my patched fork](https://github.com/ben-ng/node-browserify) until the PR gets merged.
## Usage

@@ -13,0 +17,0 @@

@@ -45,10 +45,3 @@ var _ = require('lodash')

, map: path.relative(encAppDir, fixtures.bundledMap(encAppname))
, compressPaths: function (p) {
try {
return path.relative( path.join(fixtures.dir, appname), p );
}
catch (e) {
throw new Error('Invalid path: ' + e);
}
}
, transforms: [require('hbsfy')]
};

@@ -85,2 +78,6 @@

tests['transformed app'] = function (next) {
testApp('transformed app', next);
};
tests['simple file'] = function (next) {

@@ -87,0 +84,0 @@ testApp('simple file', next);

@@ -6,4 +6,2 @@ var Backbone = require('backbone')

Backbone.$ = $;
View = Backbone.View.extend({

@@ -10,0 +8,0 @@ template: _.template('<%= message %>')

var submodule = require('./submodule')
, myString;
, myString
, actual
, expected;

@@ -12,2 +14,9 @@ myString = submodule.createString(function () {

console.log(myString);
actual = document.createElement('pre');
expected = document.createElement('pre');
actual.innerHTML = 'Actual: ' + myString;
expected.innerHTML = 'Expected: Wed Dec 31 1969 22:30:23 GMT-0800 (PST) friedpotato #26740bakedpotato #26740sliced potato #26740';
document.body.appendChild(actual);
document.body.appendChild(expected)
var submodule = require('./submodule')
, path = require('path')
, myString;
, assert = require('assert')
, myString
, expectedString = 'highway/to/hell,highway/to/hell,highway/to/hell/stairway/to/heaven'
, actual = document.createElement('pre')
, expected = document.createElement('pre')
, result = document.createElement('pre');

@@ -11,2 +16,16 @@ myString = submodule.createString(function () {

console.log(myString);
actual.innerHTML = 'Actual: ' + myString;
expected.innerHTML = 'Expected: ' + expectedString;
document.body.appendChild(actual);
document.body.appendChild(expected);
try {
assert.strictEqual(myString, expectedString);
result.innerHTML = 'Assertion Suceeded';
}
catch(e) {
result.innerHTML = 'Assertion FAILED';
}
document.body.appendChild(result);

@@ -1,3 +0,12 @@

var myString = Array.join(['stairway', 'to', 'heaven']);
var myString = ['Open','Your','Dev','Tools!']
, anotherString
, header = document.createElement('h1')
, msg = document.createElement('p');
console.log(myString);
anotherString = myString.join(' ');
header.innerHTML = myString;
document.body.appendChild(header);
msg.innerHTML = 'Do you see this? Great! Too bad this isn\'t actually the test.<br /><br />Open your dev tools and see if an "entry.js" file is there. If so, the actual test suceeded.<br /><br /><em>Remember to turn on source maps in your options!</em>';
document.body.appendChild(msg);

@@ -10,2 +10,5 @@ var _ = require('lodash')

, enhanceMap = require('../lib/enhance')
, atob = require('atob')
, btoa = require('btoa')
, osenv = require('osenv')

@@ -58,11 +61,2 @@ // Constants.. I want destructuring..

, map: filename + '.' + compiler + '.map.json'
, compressPaths: function (p) {
try {
return path.relative( path.join(fixtures.dir, 'libraries'), p );
}
catch (e) {
console.error(p);
throw new Error('Invalid path');
}
}
}

@@ -113,14 +107,38 @@ , data = fs.readFileSync(file).toString();

compileLib(filename, function (srcs) {
assert.doesNotThrow(function () {
_.each(srcs, function (src) {
var srcObj = {}
srcObj[filename+'.js'] = src.src;
validate.validate(srcObj, src.min, src.map, src.compiler);
, encoded
, roundtripped
, parsed
, tmpfile = path.join(osenv.tmpdir(), utils.string.uuid(5) + '-roundtrip.tmp');
assert.doesNotThrow(function () {
srcObj[filename+'.js'] = src.src;
validate.validate(srcObj, src.min, src.map, src.compiler);
}, 'map did not validate');
// Test roundtripping
encoded = btoa(src.map);
fs.writeFileSync(tmpfile, encoded);
roundtripped = fs.readFileSync(tmpfile);
assert.doesNotThrow(function () {
parsed = JSON.parse(atob(roundtripped.toString()));
}, 'map did not survive encoding/decoding roundtrip');
});
});
cb();
cb();
});
};
tests['Handlebars Runtime'] = function (next) {
testLib('HandlebarsRuntime', next);
};
tests['lo-dash'] = function (next) {
testLib('Lodash', next);
};
tests['Backbone.js'] = function (next) {

@@ -134,6 +152,2 @@ testLib('Backbone', next);

tests['lo-dash'] = function (next) {
testLib('Lodash', next);
};
tests['Underscore.js'] = function (next) {

@@ -140,0 +154,0 @@ testLib('Underscore', next);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc