Skip to content

Commit

Permalink
replace underscore with lodash
Browse files Browse the repository at this point in the history
Using Lo-Dash for usability improvements, extra functionality, and performance gains.
  • Loading branch information
peterkc committed Aug 22, 2015
1 parent 03e3252 commit a05b0ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var _ = require( 'underscore' );
var _ = require( 'lodash' );
var fs = require( 'fs' );
var url = require( 'url' );
var path = require( 'path' );
Expand Down Expand Up @@ -52,7 +52,7 @@ function Cartero( entryPoints, outputDirPath, options ) {

assetTypes : [ 'style', 'image' ],
assetTypesToConcatenate : [ 'style' ],

appTransforms : [],
appTransformDirs : _.isString( entryPoints ) && fs.existsSync( entryPoints ) && fs.lstatSync( entryPoints ).isDirectory() ? [ entryPoints ] : [],

Expand Down Expand Up @@ -296,7 +296,7 @@ Cartero.prototype.processMains = function( callback ) {
var tempJavascriptBundleEmitter = new EventEmitter();

tempJavascriptBundleEmitter.setMaxListeners( 0 ); // don't warn if we got lots of listeners, as we need 1 per entry point

function createTempJsBundleStreamsByEntryPoint() {
tempJsBundlesByEntryPoint = _.map( _this.mainPaths, function( thisEntryPoint ) {
var thisJsBundlePath = _this.getTempBundlePath( 'js' );
Expand Down Expand Up @@ -549,7 +549,7 @@ Cartero.prototype.copyTempBundleToParcelDiretory = function( tempBundlePath, ass

if( this.watching ) {
// if there is an old bundle that already exists for this asset type, delete it. this
// happens in watch mode when a new bundle is generated. (note the old bundle
// happens in watch mode when a new bundle is generated. (note the old bundle
// likely does not have the same path as the new bundle due to sha1)
if( oldBundlePath ) {
fs.unlinkSync( oldBundlePath );
Expand Down Expand Up @@ -577,7 +577,7 @@ Cartero.prototype.writeCommonJavascriptBundle = function( buf, callback ) {

if( this.watching && oldBundlePath ) {
// if there is an old bundle that already exists, delete it. this
// happens in watch mode when a new bundle is generated. (note the old bundle
// happens in watch mode when a new bundle is generated. (note the old bundle
// likely does not have the same path as the new bundle due to sha1)
fs.unlinkSync( oldBundlePath );
}
Expand Down Expand Up @@ -699,7 +699,7 @@ Cartero.prototype.writeIndividualAssetsToDisk = function( thePackage, assetTypes
if( err ) return nextAsset( err );

_this.emit( 'fileWritten', thisAssetDstPath, thisAssetType, false, _this.watching );

// why were we doing this? metaData does not contain references to individual assets
// if( _this.watching ) _this.writeMetaDataFile( function() {} );

Expand Down Expand Up @@ -735,7 +735,7 @@ Cartero.prototype.writeMetaDataFile = function( callback ) {
var _this = this;

var metaDataFilePath = path.join( _this.outputDirPath, kMetaDataFileName );

var packageMap = _.reduce( _this.packagePathsToIds, function( memo, thisPackageId, thisPackagePath ) {
var thisPackageKey = _this.getPackageMapKeyFromPath( thisPackagePath );

Expand All @@ -744,7 +744,7 @@ Cartero.prototype.writeMetaDataFile = function( callback ) {
// // note that if we had a situation where there was more than one incarnation as a parcel, we
// // might run into problems. can cross that bridge when we get to it...
// if( _this.parcelMap[ thisPackageKey ] ) thisPackageId = _this.parcelMap[ thisPackageKey ];

memo[ thisPackageKey ] = thisPackageId;
return memo;
}, {} );
Expand Down Expand Up @@ -777,4 +777,4 @@ Cartero.prototype.getPackageMapKeyFromPath = function( thePath ) {

function renameFileExtension( file, toExt ) {
return file.replace( new RegExp( path.extname( file ) + "$" ), toExt );
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"glob": "^3.2.8",
"globwatcher": "^1.3.0",
"inherits": "^2.0.1",
"lodash": "^3.10.1",
"minimist": "0.0.8",
"mkdirp": "^0.3.5",
"npmlog": "0.0.6",
Expand All @@ -54,7 +55,6 @@
"stream-combiner": "^0.0.4",
"through": "^2.3.4",
"through2": "^0.4.1",
"underscore": "^1.4.4",
"watchify": "^3.2.3"
}
}
10 changes: 4 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require( 'path' );
var test = require( 'tape' );
var fs = require( 'fs' );
var crypto = require( 'crypto' );
var _ = require( 'underscore' );
var _ = require( 'lodash' );

var outputDirFiles = [ 'metaData.json' ];

Expand Down Expand Up @@ -32,7 +32,7 @@ test( 'example1', function( t ) {
);

t.deepEqual( JSON.parse( fs.readFileSync( path.join( outputDirPath, 'metaData.json' ), 'utf8' ) ).packageMap, packageMap );

t.deepEqual(
fs.readdirSync( path.join( outputDirPath, packageId ) ).sort(),
[ 'assets.json', 'page1_bundle_9238125c90e5cfc790e8a5ac8926185dfb162b8c.css', 'page1_bundle_08786d2274344b392803ce9659e6d469ede96834.js' ].sort()
Expand Down Expand Up @@ -140,7 +140,7 @@ test( 'example3', function( t ) {
);

t.deepEqual( JSON.parse( fs.readFileSync( path.join( outputDirPath, 'metaData.json' ), 'utf8' ) ).packageMap, packageMap );

var page1PackageFiles = fs.readdirSync( path.join( outputDirPath, parcelIdsByPath[ 'page1' ] ) ).sort();
var page2PackageFiles = fs.readdirSync( path.join( outputDirPath, parcelIdsByPath[ 'page2' ] ) ).sort();

Expand All @@ -149,7 +149,7 @@ test( 'example3', function( t ) {

var page1JsContents = fs.readFileSync( page1JsBundle, 'utf8' );
t.ok( page1JsContents.indexOf( '/' + commonJsPackageId + '/robot.png' ) !== -1, '##asset_url resolved' );

var page1CssBundle = _.find( page1PackageFiles, function( thisFile ) { return path.extname( thisFile ) === '.css'; } );
page1CssBundle = path.join( outputDirPath, parcelIdsByPath[ 'page1' ], page1CssBundle );

Expand All @@ -169,5 +169,3 @@ test( 'example3', function( t ) {
), 'robot.png in common package' );
} );
} );


0 comments on commit a05b0ad

Please sign in to comment.