Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: allow id option to be passed through to built-ins, enforce single path rule #53

Merged
merged 2 commits into from
Apr 21, 2015
Merged
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
27 changes: 17 additions & 10 deletions src/nodes/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import watch from './watch';
import { isRegExp } from '../utils/is';
import { ABORTED } from '../utils/signals';

// TODO remove this in a future version
function enforceCorrectArguments ( options ) {
if ( options !== undefined && typeof options !== 'object' ) {
throw new Error( 'As of gobble 0.9.0, you cannot pass multiple strings to .grab() and .moveTo(). Use path.join() instead' );
}
}

export default class Node extends EventEmitter2 {
constructor () {
this._gobble = true; // makes life easier for e.g. gobble-cli
Expand Down Expand Up @@ -109,9 +116,9 @@ export default class Node extends EventEmitter2 {
return watchTask;
}

exclude ( patterns ) {
exclude ( patterns, options ) {
if ( typeof patterns === 'string' ) { patterns = [ patterns ]; }
return new Transformer( this, include, { patterns, exclude: true });
return new Transformer( this, include, { patterns, exclude: true, id: options && options.id });
}

getChanges ( inputdir ) {
Expand Down Expand Up @@ -147,15 +154,15 @@ export default class Node extends EventEmitter2 {
return added.concat( removed ).concat( changed );
}

grab () {
const src = join.apply( null, arguments );
return new Transformer( this, grab, { src });
grab ( src, options ) {
enforceCorrectArguments( options );
return new Transformer( this, grab, { src, id: options && options.id });
}

// Built-in transformers
include ( patterns ) {
include ( patterns, options ) {
if ( typeof patterns === 'string' ) { patterns = [ patterns ]; }
return new Transformer( this, include, { patterns });
return new Transformer( this, include, { patterns, id: options && options.id });
}

inspect ( target, options ) {
Expand All @@ -174,9 +181,9 @@ export default class Node extends EventEmitter2 {
return this.transform( fn, userOptions );
}

moveTo () {
const dest = join.apply( null, arguments );
return new Transformer( this, move, { dest });
moveTo ( dest, options ) {
enforceCorrectArguments( options );
return new Transformer( this, move, { dest, id: options && options.id });
}

observe ( fn, userOptions ) {
Expand Down
16 changes: 16 additions & 0 deletions test/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,22 @@ module.exports = function () {
});
});

it( 'errors on .grab(path1, path2) or .moveTo(path1, path2)', function () {
try {
var source = gobble( 'tmp/foo' ).grab( 'a', 'b' );
assert.ok( false );
} catch ( err ) {
assert.ok( /cannot pass multiple strings/.test( err.message ) );
}

try {
var source = gobble( 'tmp/foo' ).moveTo( 'a', 'b' );
assert.ok( false );
} catch ( err ) {
assert.ok( /cannot pass multiple strings/.test( err.message ) );
}
});

it( 'errors if you try to pass multiple nodes to gobble()', function () {
try {
var source = gobble( 'tmp/foo', 'tmp/bar' );
Expand Down