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

asset-smasher

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-smasher - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

6

CHANGELOG.md
# Asset Smasher Changelog
## 0.2.3 (March 14, 2013)
- Use the `send` module rather than the internals of connect's static middleware. (Fixes #6)
- Minify all CSS (not just CSS generated from LESS/stylus) using the `ycssmin` module. (Fixes #4)
- Update to latest versions of dependencies.
## 0.2.2 (November 7, 2012)

@@ -4,0 +10,0 @@

14

lib/asset-smasher.js

@@ -12,2 +12,3 @@ var async = require('async');

var JsMinifier = require('./compilation/minifier').JsMinifier;
var CSSMinifier = require('./compilation/minifier').CSSMinifier;
var AssetHasher = require('./compilation/hasher').AssetHasher;

@@ -21,3 +22,3 @@ var OutputAsset = require('./output/save').OutputAsset;

function executePhase(phase, target, cb) {
async.forEachSeries(phase, function (operation, cb) {
async.eachSeries(phase, function (operation, cb) {
operation(target, cb);

@@ -132,2 +133,3 @@ }, function (e) {

phases.postCompilation.push(new JsMinifier().asOperation());
phases.postCompilation.push(new CSSMinifier().asOperation());
}

@@ -170,3 +172,3 @@

});
async.forEachSeries(orderedAssets, function (asset, eachCb) {
async.eachSeries(orderedAssets, function (asset, eachCb) {
executePhase(self.phases.compilation, asset, eachCb);

@@ -179,7 +181,7 @@ }, wfCb);

}, function (wfCb) {
async.forEach(bundle.getAllAssets(), function (asset, eachCb) {
async.each(bundle.getAllAssets(), function (asset, eachCb) {
executePhase(self.phases.postCompilation, asset, eachCb);
}, wfCb);
}, function (wfCb) {
async.forEach(bundle.getAllAssets(), function (asset, eachCb) {
async.each(bundle.getAllAssets(), function (asset, eachCb) {
executePhase(self.phases.output, asset, eachCb);

@@ -225,3 +227,3 @@ }, wfCb);

dependencies.push(asset); // Add the final asset we're making to the end
async.forEachSeries(dependencies, function (dep, eachCb) {
async.eachSeries(dependencies, function (dep, eachCb) {
dep.reset(); // Ensure the file gets compiled even if it's already been compiled before

@@ -256,3 +258,3 @@ executePhase(self.phases.compilation, dep, eachCb);

function (b, wfCb) {
async.forEach(bundle.getAllAssets(), function (asset, eachCb) {
async.each(bundle.getAllAssets(), function (asset, eachCb) {
executePhase(self.phases.nameTransformation, asset, eachCb);

@@ -259,0 +261,0 @@ }, wfCb);

/**
*
* This operation minifies JavaScript using uglify-js
* Minify JavaScript using uglify-js
* Minify CSS using ycssmin
*
*/
var path = require('path');
var uglify;
var uglify = require('uglify-js');
var cssmin = require('ycssmin').cssmin;

@@ -17,9 +19,28 @@ var JsMinifier = exports.JsMinifier = function JsMinifier() {

if (path.extname(asset.logicalPath) === '.js') {
if (!uglify) {
try {
uglify = require('uglify-js');
} catch (e) {
cb(new Error('uglify-js could not be loaded'));
try {
var contents = asset.contents;
if (Buffer.isBuffer(contents)) {
contents = contents.toString('utf-8');
}
asset.contents = uglify.minify(contents, {
fromString: true
}).code;
cb(null, asset);
} catch (e) {
cb(e);
}
} else {
cb(null, asset);
}
}
};
var CSSMinifier = exports.CSSMinifier = function CSSMinifier() {
};
CSSMinifier.prototype = {
asOperation:function () {
return this.execute.bind(this);
},
execute:function (asset, cb) {
if (path.extname(asset.logicalPath) === '.css') {
try {

@@ -30,3 +51,3 @@ var contents = asset.contents;

}
asset.contents = uglify(contents);
asset.contents = cssmin(contents, 32000); // Max line length of 32000
cb(null, asset);

@@ -33,0 +54,0 @@ } catch (e) {

@@ -97,3 +97,3 @@ /**

// Do any post-transform processing that needs to be done
async.forEachSeries(postTransforms, function (postTransform, eachCb) {
async.eachSeries(postTransforms, function (postTransform, eachCb) {
postTransform(asset, eachCb);

@@ -108,3 +108,3 @@ }, wfCb);

var self = this;
async.forEach(assetBundle.getAllAssets(), function(asset, eachCb) {
async.each(assetBundle.getAllAssets(), function(asset, eachCb) {
self.executeDry(asset, eachCb);

@@ -111,0 +111,0 @@ }, function (e) {

@@ -34,3 +34,3 @@ /**

dust = require('dust');
} catch (e) {
} catch (e2) {
cb(new Error('dust could not be found'));

@@ -37,0 +37,0 @@ }

@@ -5,5 +5,2 @@ /**

*
* It takes a "compress" option which indicates whether minified CSS should
* be output.
*
* Any @imports in the files are relative to the path that the file is in.

@@ -58,6 +55,6 @@ *

try {
asset.contents = tree.toCSS({compress:self.options.compress});
asset.contents = tree.toCSS();
cb();
} catch (e) {
cb(e);
} catch (e2) {
cb(e2);
}

@@ -64,0 +61,0 @@ }

@@ -5,5 +5,2 @@ /**

*
* It takes a "compress" option which indicates whether minified CSS should
* be output.
*
* Any @imports in the files are relative to the path that the file is in.

@@ -49,3 +46,2 @@ *

set('filename', assetFilePath).
set('compress', this.options.compress).
set('paths', [importDir]).

@@ -52,0 +48,0 @@ render(function(e, out) {

@@ -31,3 +31,3 @@ /**

var self = this;
async.forEach(this.paths, function (p, eachCb) {
async.each(this.paths, function (p, eachCb) {
glob(self.matchPattern, { cwd:p }, function (e, matches) {

@@ -71,3 +71,3 @@ if (e) {

if (this.lookFor.length > 0) {
async.forEach(assetBundle.getAllAssets(), function(asset, eachCb) {
async.each(assetBundle.getAllAssets(), function(asset, eachCb) {
self.executeSingle(asset, assetBundle, eachCb);

@@ -74,0 +74,0 @@ }, function (e) {

@@ -52,3 +52,3 @@ /**

var self = this;
async.forEachSeries(assetBundle.getAllAssets(), function (asset, eachCb) {
async.eachSeries(assetBundle.getAllAssets(), function (asset, eachCb) {
if (path.extname(asset.assetFilePath) === '.mf') {

@@ -73,3 +73,3 @@ self.walkManifest(asset, assetBundle, eachCb);

function (contents, wfCb) {
async.forEachSeries(contents.split('\n'), function (line, eachCb) {
async.eachSeries(contents.split('\n'), function (line, eachCb) {
if (line && line.indexOf('#') !== 0) {

@@ -113,3 +113,3 @@ var directive = line.match(DIRECTIVE_REGEX);

} else {
async.forEachSeries(this.paths, function (p, eachCb) {
async.eachSeries(this.paths, function (p, eachCb) {
self.resolveFile(file, p, function (e, f) {

@@ -145,3 +145,3 @@ if (e) {

function (files, wfCb) {
async.forEachSeries(files, function (f, eachCb) {
async.eachSeries(files, function (f, eachCb) {
var filePath = path.join(dirPath, f);

@@ -169,3 +169,3 @@ var extn = path.extname(f);

function (files, wfCb) {
async.forEachSeries(files, function (f, eachCb) {
async.eachSeries(files, function (f, eachCb) {
var extn = path.extname(f);

@@ -216,3 +216,3 @@ if (f !== manifestFilePath && _.contains(self.extensions, extn)) {

function (files, wfCb) {
async.forEachSeries(files, function (f, eachCb) {
async.eachSeries(files, function (f, eachCb) {
var lookupBase = path.basename(filePath);

@@ -219,0 +219,0 @@ var fBase = path.basename(f);

@@ -5,3 +5,3 @@ var path = require('path');

var Smasher = require('./asset-smasher').Smasher;
var staticMiddleware;
var send = require('send');

@@ -75,5 +75,12 @@ function Middleware(options) {

serveAsset:function (req, res, next, asset) {
staticMiddleware.send(req, res, next, {
path:asset.compiledAssetFilePath
});
function error(err) {
if (err.status === 404) {
next();
} else {
next(err);
}
}
send(req, asset.compiledAssetFilePath)
.on('error', error)
.pipe(res);
},

@@ -156,11 +163,4 @@ loadAssetMap:function () {

module.exports = function (options) {
if (!staticMiddleware) {
try {
staticMiddleware = require('express')['static'];
} catch (e) {
throw new Error('Express is not available.');
}
}
var middleware = new Middleware(options);
return middleware.execute.bind(middleware);
};
{
"name": "asset-smasher",
"description": "Asset pre-processor, merger, and compressor.",
"version": "0.2.2",
"version": "0.2.3",
"author": "Jim Riecken <jriecken@gmail.com>",

@@ -28,9 +28,11 @@ "keywords": [

"dependencies": {
"async": "0.1.22",
"commander": "0.6.1",
"glob": "3.1.10",
"mkdirp": "0.3.3",
"minimatch": "0.2.5",
"uglify-js": "1.3.2",
"underscore": "1.3.3"
"async": "0.2.6",
"commander": "1.1.1",
"glob": "3.1.21",
"mkdirp": "0.3.5",
"minimatch": "0.2.11",
"send":"0.1.0",
"uglify-js": "2.2.5",
"underscore": "1.4.4",
"ycssmin":"1.0.1"
},

@@ -37,0 +39,0 @@ "optionalDependencies": {},

@@ -36,3 +36,3 @@ # Asset Smasher

- Compress JavaScript files with `uglify-js`
- Compress LESS during LESS preprocessing
- Compress CSS files with `ycssmin`
- Generate Gzipped versions of files

@@ -390,3 +390,2 @@ - Include a MD5 hash of the file's contents in the file name. `myAsset.js` -> `myAsset-c89cba7b7df028e65cb01d86f4d27077.js`

- When the `compress` option is true, the compression is done directly via the `less/stylus` compilers
- Any `@include/@import` paths are *relative to the path that the file is in*.

@@ -393,0 +392,0 @@ - Any `@include/@import`ed files will *not* be processed individually by Asset Smasher (i.e. you can't `@include` a LESS file that is preprocessed by ejs)

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