Skip to content

Commit ff39e48

Browse files
committed
Merge pull request #53 from gobblejs/builtins-options
BREAKING: allow id option to be passed through to built-ins, enforce single path rule
2 parents 16115e1 + 1a8ed95 commit ff39e48

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/nodes/Node.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import watch from './watch';
1717
import { isRegExp } from '../utils/is';
1818
import { ABORTED } from '../utils/signals';
1919

20+
// TODO remove this in a future version
21+
function enforceCorrectArguments ( options ) {
22+
if ( options !== undefined && typeof options !== 'object' ) {
23+
throw new Error( 'As of gobble 0.9.0, you cannot pass multiple strings to .grab() and .moveTo(). Use path.join() instead' );
24+
}
25+
}
26+
2027
export default class Node extends EventEmitter2 {
2128
constructor () {
2229
this._gobble = true; // makes life easier for e.g. gobble-cli
@@ -109,9 +116,9 @@ export default class Node extends EventEmitter2 {
109116
return watchTask;
110117
}
111118

112-
exclude ( patterns ) {
119+
exclude ( patterns, options ) {
113120
if ( typeof patterns === 'string' ) { patterns = [ patterns ]; }
114-
return new Transformer( this, include, { patterns, exclude: true });
121+
return new Transformer( this, include, { patterns, exclude: true, id: options && options.id });
115122
}
116123

117124
getChanges ( inputdir ) {
@@ -147,15 +154,15 @@ export default class Node extends EventEmitter2 {
147154
return added.concat( removed ).concat( changed );
148155
}
149156

150-
grab () {
151-
const src = join.apply( null, arguments );
152-
return new Transformer( this, grab, { src });
157+
grab ( src, options ) {
158+
enforceCorrectArguments( options );
159+
return new Transformer( this, grab, { src, id: options && options.id });
153160
}
154161

155162
// Built-in transformers
156-
include ( patterns ) {
163+
include ( patterns, options ) {
157164
if ( typeof patterns === 'string' ) { patterns = [ patterns ]; }
158-
return new Transformer( this, include, { patterns });
165+
return new Transformer( this, include, { patterns, id: options && options.id });
159166
}
160167

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

177-
moveTo () {
178-
const dest = join.apply( null, arguments );
179-
return new Transformer( this, move, { dest });
184+
moveTo ( dest, options ) {
185+
enforceCorrectArguments( options );
186+
return new Transformer( this, move, { dest, id: options && options.id });
180187
}
181188

182189
observe ( fn, userOptions ) {

test/scenarios.js

+16
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,22 @@ module.exports = function () {
807807
});
808808
});
809809

810+
it( 'errors on .grab(path1, path2) or .moveTo(path1, path2)', function () {
811+
try {
812+
var source = gobble( 'tmp/foo' ).grab( 'a', 'b' );
813+
assert.ok( false );
814+
} catch ( err ) {
815+
assert.ok( /cannot pass multiple strings/.test( err.message ) );
816+
}
817+
818+
try {
819+
var source = gobble( 'tmp/foo' ).moveTo( 'a', 'b' );
820+
assert.ok( false );
821+
} catch ( err ) {
822+
assert.ok( /cannot pass multiple strings/.test( err.message ) );
823+
}
824+
});
825+
810826
it( 'errors if you try to pass multiple nodes to gobble()', function () {
811827
try {
812828
var source = gobble( 'tmp/foo', 'tmp/bar' );

0 commit comments

Comments
 (0)