Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/builtins/include.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ module.exports = function include ( inputdir, outputdir, options, callback ) {
sander.mkdirSync( path.dirname( destpath ) );

try {
symlinkOrCopy( filepath, destpath );
if ( !sander.existsSync( destpath ) ) {
symlinkOrCopy( filepath, destpath );
}
check();
} catch ( e ) {
cb( e );
Expand Down
10 changes: 9 additions & 1 deletion lib/builtins/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ module.exports = function map ( inputdir, outputdir, options ) {
// If this mapper only accepts certain extensions, and this isn't
// one of them, just copy the file
if ( options.accept && !~options.accept.indexOf( ext ) ) {
return sander.link( srcpath ).to( destpath );
if ( !sander.existsSync( destpath ) ) {
return sander.link( srcpath ).to( destpath );
} else {
return Promise.resolve( true );
}
}

return sander.stat( srcpath ).then( function ( stats ) {
Expand All @@ -57,6 +61,10 @@ module.exports = function map ( inputdir, outputdir, options ) {
previous = options.cache[ filename ];

if ( previous && compareBuffers( crc, previous.crc ) ) {
if ( sander.existsSync( destpath ) ) {
return Promise.resolve( true );
}

promises = [ sander.link( previous.codepath ).to( destpath ) ];

if ( previous.mappath ) {
Expand Down
4 changes: 3 additions & 1 deletion lib/file/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = function () {
var dest = resolve.apply( null, arguments );

return sander.mkdir( path.dirname( dest ) ).then( function () {
symlinkOrCopy( src, dest );
if ( !sander.existsSync( dest ) ) {
symlinkOrCopy( src, dest );
}
});
}
};
Expand Down
140 changes: 74 additions & 66 deletions lib/nodes/Transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,76 +54,84 @@ module.exports = Node.extend({
};

outputdir = path.resolve( session.config.gobbledir, node.id, '' + node.counter++ );
node._ready = sander.mkdir( outputdir ).then( function () {
return node.input.ready().then( function ( inputdir ) {
return queue.add( function ( fulfil, reject ) {
var promise, called, callback, start;

node.emit( 'info', {
code: 'TRANSFORM_START',
progressIndicator: true,
id: node.id
});

start = Date.now();

callback = function ( err ) {
var gobbleError, stack, loc;

if ( called ) {
return;
}

called = true;

if ( err ) {
stack = err.stack || new Error().stack;

loc = extractLocationInfo( err );

gobbleError = new GobbleError({
message: 'transformation failed',
id: node.id,
code: 'TRANSFORMATION_FAILED',
original: err,
stack: stack,
file: loc.file,
line: loc.line,
column: loc.column
});

reject( gobbleError );
}

else {
node.emit( 'info', {
code: 'TRANSFORM_COMPLETE',
id: node.id,
duration: Date.now() - start
});

node._cleanup( outputdir );
fulfil( outputdir );
node._ready = sander.readFile( transformation.cachedir, '.cacheMap' ).then( function ( cache ) {
node.options.cache = JSON.parse( cache.toString() );
}, function() { return true; } ).then( function () {
return sander.mkdir( outputdir ).then( function () {
return node.input.ready().then( function ( inputdir ) {
return queue.add( function ( fulfil, reject ) {
var promise, called, callback, start;

node.emit( 'info', {
code: 'TRANSFORM_START',
progressIndicator: true,
id: node.id
});

start = Date.now();

callback = function ( err ) {
var gobbleError, stack, loc;

if ( called ) {
return;
}

called = true;

if ( err ) {
stack = err.stack || new Error().stack;

loc = extractLocationInfo( err );

gobbleError = new GobbleError({
message: 'transformation failed',
id: node.id,
code: 'TRANSFORMATION_FAILED',
original: err,
stack: stack,
file: loc.file,
line: loc.line,
column: loc.column
});

reject( gobbleError );
}

else {
node.emit( 'info', {
code: 'TRANSFORM_COMPLETE',
id: node.id,
duration: Date.now() - start
});

// stash the cache for future
sander.writeFileSync( transformation.cachedir, '.cacheMap', JSON.stringify( node.options.cache || {} ) );

node._cleanup( outputdir );
fulfil( outputdir );
}
};

try {
promise = node.transformer.call( transformation, inputdir, outputdir, assign({}, node.options ), callback );

if ( promise && typeof promise.then === 'function' ) {
promise.then( function () {
callback(); // ensure no argument is passed
}).catch( callback );
}
} catch ( err ) {
callback( err );
}
};

try {
promise = node.transformer.call( transformation, inputdir, outputdir, assign({}, node.options ), callback );
});
}).catch( function ( err ) {
node._abort();
queue.abort();

if ( promise && typeof promise.then === 'function' ) {
promise.then( function () {
callback(); // ensure no argument is passed
}).catch( callback );
}
} catch ( err ) {
callback( err );
}
throw err;
});
}).catch( function ( err ) {
node._abort();
queue.abort();

throw err;
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var sander = require( 'sander' ),
module.exports = function cleanup ( dir ) {
return sander.mkdir( dir ).then( function () {
return sander.readdir( dir ).then( function ( files ) {
var promises = files.map( function ( filename ) {
var promises = files.filter( function ( filename ) { return filename.indexOf( '.cache' ) !== -1; }).map( function ( filename ) {
return sander.rimraf( dir, filename );
});

Expand Down
1 change: 1 addition & 0 deletions test/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = function () {
files = files.filter( function ( file ) { return /-foo$/.test( file ); });

sander.readdir( '.gobble', files[0] ).then( function ( files ) {
files = files.filter( function ( file ) { return file.indexOf( '.cache' ) === -1; });
assert.deepEqual( files, [ '2' ] );
done();
});
Expand Down