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

broccoli-funnel

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-funnel - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

5

CHANGELOG.md
# master
* Do not use `CoreObject`
* Derive from broccoli-plugin base class
# 0.2.3
* Make `new` operator optional

@@ -4,0 +9,0 @@ * Use [new `.rebuild` API](https://github.com/broccolijs/broccoli/blob/master/docs/new-rebuild-api.md)

51

index.js

@@ -6,9 +6,8 @@ 'use strict';

var mkdirp = require('mkdirp');
var walkSync = require('walk-sync');
var walkSync = require('walk-sync-matcher');
var Minimatch = require('minimatch').Minimatch;
var CoreObject = require('core-object');
var Plugin = require('broccoli-plugin');
var symlinkOrCopy = require('symlink-or-copy');
var readAPICompat = require('broccoli-read-compat');
var debug = require('debug');
function makeDictionary() {

@@ -22,6 +21,8 @@ var cache = Object.create(null);

function Funnel(inputTree, options) {
if (!(this instanceof Funnel)) { return new Funnel(inputTree, options); }
Funnel.prototype = Object.create(Plugin.prototype);
Funnel.prototype.constructor = Funnel;
function Funnel(inputNode, options) {
if (!(this instanceof Funnel)) { return new Funnel(inputNode, options); }
this.inputTree = inputTree;
Plugin.call(this, [inputNode]);

@@ -46,7 +47,12 @@ this._includeFileCache = makeDictionary();

this._matchedWalk = this.include && this.include.filter(function(a) {
return a instanceof Minimatch;
}).length > 0;
this._instantiatedStack = (new Error()).stack;
}
Funnel.__proto__ = CoreObject;
Funnel.prototype.constructor = Funnel;
Funnel.prototype._debug = function(message) {
debug('broccoli-funnel:' + (this.description || this.name || this.constructor.name)).apply(null, arguments);
};

@@ -92,3 +98,3 @@ Funnel.prototype._setupFilter = function(type) {

Funnel.prototype.rebuild = function() {
Funnel.prototype.build = function() {
this.destPath = path.join(this.outputPath, this.destDir);

@@ -99,3 +105,3 @@ if (this.destPath[this.destPath.length -1] === '/') {

var inputPath = this.inputPath;
var inputPath = this.inputPaths[0];
if (this.srcDir) {

@@ -118,5 +124,17 @@ inputPath = path.join(inputPath, this.srcDir);

Funnel.prototype.processFilters = function(inputPath) {
var files = walkSync(inputPath);
var files;
if (this.files && !this.exclude && !this.include) {
files = this.files.slice(0); //clone to be compatible with walkSync
} else {
if (this._matchedWalk) {
files = walkSync(inputPath, undefined, this.include);
} else {
files = walkSync(inputPath);
}
}
var relativePath, destRelativePath, fullInputPath, fullOutputPath;
var count = 0;
for (var i = 0, l = files.length; i < l; i++) {

@@ -126,2 +144,3 @@ relativePath = files[i];

if (this.includeFile(relativePath)) {
count++;
fullInputPath = path.join(inputPath, relativePath);

@@ -134,2 +153,8 @@ destRelativePath = this.lookupDestinationPath(relativePath);

}
this._debug('processFilters %o', {
filesFound: files.length,
filesProcessed: count,
inputPath: inputPath
});
};

@@ -225,4 +250,2 @@

readAPICompat.wrapFactory(Funnel);
module.exports = Funnel;
{
"name": "broccoli-funnel",
"version": "0.2.3",
"description": "Broccoli plugin that allows you to filter files selected from an input tree down based on regular expressions.",
"version": "0.2.4",
"description": "Broccoli plugin that allows you to filter files selected from an input node down based on regular expressions.",
"main": "index.js",

@@ -20,8 +20,8 @@ "author": "Robert Jackson",

"dependencies": {
"broccoli-read-compat": "^0.1.2",
"core-object": "0.0.2",
"broccoli-plugin": "^1.0.0",
"debug": "^2.2.0",
"minimatch": "^2.0.1",
"mkdirp": "^0.5.0",
"symlink-or-copy": "^1.0.0",
"walk-sync": "^0.1.3"
"walk-sync-matcher": "^0.2.0"
},

@@ -28,0 +28,0 @@ "devDependencies": {

@@ -5,17 +5,16 @@ # Broccoli Funnel

Broccoli Funnel is a plugin that filters a tree and returns a new tree that
represents a subset of the files in the original tree. The filters are
expressed as regular expressions.
Given an input node, the Broccoli Funnel plugin returns a new node with only a
subset of the files from the input node. The files can be moved to different
paths. You can use regular expressions to select which files to include or
exclude.
Inspired by [broccoli-static-compiler](https://github.com/joliss/broccoli-static-compiler).
## Documentation
### `funnel(inputTree, options)`
### `new Funnel(inputNode, options)`
`inputTree` *{Single tree}*
`inputNode` *{Single node}*
A Broccoli tree. A tree in Broccoli can be either a string that references a
directory in your project or a tree structure returned from running another
Broccoli plugin.
A Broccoli node (formerly: "tree"). A node in Broccoli can be either a string
that references a directory in your project or a node object returned from
running another Broccoli plugin.

@@ -42,7 +41,7 @@ If your project has the following file structure:

```javascript
var funnel = require('broccoli-funnel');
var cssFiles = funnel('src/css');
var Funnel = require('broccoli-funnel');
var cssFiles = new Funnel('src/css');
/*
cssFiles is now equivalent to this tree:
cssFiles contains the following files:

@@ -53,3 +52,3 @@ ├── reset.css

// export a tree for Broccoli to begin processing
// export the node for Broccoli to begin processing
module.exports = cssFiles;

@@ -62,6 +61,6 @@ ```

A string representing the portion of the input tree to start the funneling
A string representing the portion of the input node to start the funneling
from. This will be the base path for any `include`/`exclude` regexps.
Default: `'.'`, the root path of input tree.
Default: `'.'`, the root path of the input node.

@@ -85,7 +84,7 @@ If your project has the following file structure:

You can select a subsection of the tree via Funnel:
You can select a subsection of the node via Funnel:
```javascript
var funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
var MergeTrees = require('broccoli-merge-trees');

@@ -95,4 +94,4 @@ // root of our source files

/* get a new tree of only files in the 'src/css' directory
cssFiles is equivalent to the tree:
/* get a new node of only files in the 'src/css' directory
cssFiles contains the following files:

@@ -102,8 +101,8 @@ ├── reset.css

*/
var cssFiles = funnel(projectFiles, {
var cssFiles = new Funnel(projectFiles, {
srcDir: 'css'
});
/* get a new tree of only files in the 'src/icons' directory
imageFiles is equivalent to the tree:
/* get a new node of only files in the 'src/icons' directory
imageFiles contains the following files:

@@ -113,3 +112,3 @@ ├── check-mark.png

*/
var imageFiles = funnel(projectFiles, {
var imageFiles = new Funnel(projectFiles, {
srcDir: 'icons'

@@ -119,3 +118,3 @@ });

module.exports = mergeTrees([cssFiles, imageFiles]);
module.exports = new MergeTrees([cssFiles, imageFiles]);
```

@@ -129,3 +128,3 @@

Default: `'.'`, the root path of input tree.
Default: `'.'`, the root path of input node.

@@ -149,8 +148,8 @@ If your project has the following file structure:

You can select a subsection of the tree via Funnel and copy it to a new location:
You can select a subsection of the directory structure via Funnel and copy it to a new location:
```javascript
var funnel = require('broccoli-funnel');
var Funnel = require('broccoli-funnel');
var cssFiles = funnel('src/css', {
var cssFiles = new Funnel('src/css', {
destDir: 'build'

@@ -160,3 +159,3 @@ });

/*
cssFiles is equivalent to the tree:
cssFiles contains the following files:

@@ -182,3 +181,3 @@ build/

One or more matcher expression (regular expression, glob string, or function). Files within the tree whose names match this
One or more matcher expression (regular expression, glob string, or function). Files within the node whose names match this
expression will be copied (with the location inside their parent directories

@@ -206,11 +205,11 @@ preserved) to the `destDir`.

You can select files that match a regular expression copy those subtrees to a
You can select files that match a regular expression copy those subdirectories to a
new location, preserving their location within parent directories:
```javascript
var funnel = require('broccoli-funnel');
var Funnel = require('broccoli-funnel');
// finds all files that match /todo/ and moves them
// the destDir
var todoRelatedFiles = funnel('src', {
var todoRelatedFiles = new Funnel('src', {
include: [new RegExp(/todo/)]

@@ -220,3 +219,3 @@ });

/*
todoRelatedFiles is equivalent to the tree:
todoRelatedFiles contains the following files:
.

@@ -236,3 +235,3 @@ ├── css

One or more matcher expression (regular expression, glob string, or function). Files within the tree whose names match this
One or more matcher expression (regular expression, glob string, or function). Files within the node whose names match this
expression will _not_ be copied to the `destDir` if they otherwise would have

@@ -266,7 +265,7 @@ been.

```javascript
var funnel = require('broccoli-funnel');
var Funnel = require('broccoli-funnel');
// finds all files in 'src' EXCEPT those that match /todo/
// and adds them to a tree.
var nobodyLikesTodosAnyway = funnel('src', {
// and adds them to a node.
var nobodyLikesTodosAnyway = new Funnel('src', {
exclude: [new RegExp(/todo/)]

@@ -276,3 +275,3 @@ });

/*
nobodyLikesTodosAnyway is equivalent to the tree:
nobodyLikesTodosAnyway contains the following files:
.

@@ -295,3 +294,3 @@ ├── css

One or more relative file paths. Files within the tree whose relative paths match
One or more relative file paths. Files within the node whose relative paths match
will be copied (with the location inside their parent directories

@@ -319,10 +318,10 @@ preserved) to the `destDir`.

You can select a specific list of files copy those subtrees to a
You can select a specific list of files copy those subdirectories to a
new location, preserving their location within parent directories:
```javascript
var funnel = require('broccoli-funnel');
var Funnel = require('broccoli-funnel');
// finds these specific files and moves them to the destDir
var someFiles = funnel('src', {
var someFiles = new Funnel('src', {
files: ['css/reset.css', 'icons/check-mark.png']

@@ -332,3 +331,3 @@ });

/*
someFiles is equivalent to the tree:
someFiles contains the following files:
.

@@ -350,3 +349,3 @@ ├── css

`relativePath` as its first argument. The value returned from
`getDestinationPath` will be used as the destination for the new tree. This is
`getDestinationPath` will be used as the destination for the new node. This is
a very simple way to move files from one path to another (replacing the need

@@ -362,3 +361,3 @@ for `broccoli-file-mover` for example).

```javascript
var tree = funnel('packages/ember-metal/lib', {
var node = new Funnel('packages/ember-metal/lib', {
destDir: 'ember-metal',

@@ -365,0 +364,0 @@

@@ -7,3 +7,3 @@ 'use strict';

var expect = require('expect.js');
var walkSync = require('walk-sync');
var walkSync = require('walk-sync-matcher');
var broccoli = require('broccoli');

@@ -29,3 +29,3 @@ var rimraf = RSVP.denodeify(require('rimraf'));

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
processFile: function() {

@@ -36,3 +36,3 @@ throw new Error('should never be called');

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -50,3 +50,3 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
include: [ /.png$/, /.js$/ ],

@@ -56,16 +56,17 @@ destDir: 'foo',

processFile: function(sourcePath, destPath, relativePath) {
processFileArguments.push([sourcePath, destPath, relativePath]);
var relSourcePath = sourcePath.replace(this.inputPaths[0], '__input_path__');
var relDestPath = destPath.replace(this.outputPath, '__output_path__');
processFileArguments.push([relSourcePath, relDestPath, relativePath]);
}
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()
.then(function(results) {
var outputPath = results.directory;
var expected = [
[ path.join(fixturePath, 'dir1', 'subdir1/subsubdir1/foo.png'),
path.join(outputPath, 'foo/subdir1/subsubdir1/foo.png'),
[ path.join('__input_path__', 'subdir1/subsubdir1/foo.png'),
path.join('__output_path__', 'foo/subdir1/subsubdir1/foo.png'),
'subdir1/subsubdir1/foo.png' ],
[ path.join(fixturePath, 'dir1', 'subdir1/subsubdir2/some.js'),
path.join(outputPath, 'foo/subdir1/subsubdir2/some.js'),
[ path.join('__input_path__', 'subdir1/subsubdir2/some.js'),
path.join('__output_path__', 'foo/subdir1/subsubdir2/some.js'),
'subdir1/subsubdir2/some.js' ]

@@ -80,3 +81,3 @@ ];

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
include: [ /.png$/, /.js$/ ],

@@ -90,3 +91,3 @@ destDir: 'foo',

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -105,5 +106,5 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath);
var node = new Funnel(inputPath);
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -124,7 +125,7 @@ .then(function(results) {

it('simply returns a copy of the input tree', function() {
it('simply returns a copy of the input node', function() {
var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath);
var node = new Funnel(inputPath);
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -138,9 +139,9 @@ .then(function(results) {

it('simply returns a copy of the input tree at a nested destination', function() {
it('simply returns a copy of the input node at a nested destination', function() {
var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
destDir: 'some-random'
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -164,13 +165,13 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
srcDir: 'subdir1'
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()
.then(function() {
return rimraf(tree.outputPath);
return rimraf(node.outputPath);
})
.then(function() {
fs.symlinkSync('foo/bar/baz.js', tree.outputPath);
fs.symlinkSync('foo/bar/baz.js', node.outputPath);
})

@@ -188,9 +189,9 @@ .then(function() {

it('simply returns a copy of the input tree at a nested source', function() {
it('simply returns a copy of the input node at a nested source', function() {
var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
srcDir: 'subdir1'
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -214,5 +215,5 @@ .then(function(results) {

it('does not error with input tree at a missing nested source', function() {
it('does not error with input node at a missing nested source', function() {
var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
srcDir: 'subdir3',

@@ -224,3 +225,3 @@ allowEmpty: true

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -246,3 +247,3 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
include: includes,

@@ -253,3 +254,3 @@ exclude: excludes,

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -278,3 +279,3 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
files: [

@@ -286,3 +287,3 @@ 'subdir1/subsubdir1/foo.png',

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -380,3 +381,3 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
exclude: [ /.png$/, /.js$/ ],

@@ -386,3 +387,3 @@ include: [ /.txt$/ ]

builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -402,7 +403,7 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath, {
var node = new Funnel(inputPath, {
exclude: [ /.*/ ]
});
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -420,9 +421,9 @@ .then(function(results) {

var inputPath = path.join(fixturePath, 'dir1');
var tree = new Funnel(inputPath);
var node = new Funnel(inputPath);
tree.getDestinationPath = function(relativePath) {
node.getDestinationPath = function(relativePath) {
return path.join('foo', relativePath);
};
builder = new broccoli.Builder(tree);
builder = new broccoli.Builder(node);
return builder.build()

@@ -438,3 +439,3 @@ .then(function(results) {

describe('includeFile', function() {
var tree;
var node;

@@ -444,38 +445,38 @@ beforeEach(function() {

tree = new Funnel(inputPath);
node = new Funnel(inputPath);
});
it('returns false if the path is included in an exclude filter', function() {
tree.exclude = [ /.foo$/, /.bar$/ ];
node.exclude = [ /.foo$/, /.bar$/ ];
expect(tree.includeFile('blah/blah/blah.foo')).to.not.be.ok();
expect(tree.includeFile('blah/blah/blah.bar')).to.not.be.ok();
expect(tree.includeFile('blah/blah/blah.baz')).to.be.ok();
expect(node.includeFile('blah/blah/blah.foo')).to.not.be.ok();
expect(node.includeFile('blah/blah/blah.bar')).to.not.be.ok();
expect(node.includeFile('blah/blah/blah.baz')).to.be.ok();
});
it('returns true if the path is included in an include filter', function() {
tree.include = [ /.foo$/, /.bar$/ ];
node.include = [ /.foo$/, /.bar$/ ];
expect(tree.includeFile('blah/blah/blah.foo')).to.be.ok();
expect(tree.includeFile('blah/blah/blah.bar')).to.be.ok();
expect(node.includeFile('blah/blah/blah.foo')).to.be.ok();
expect(node.includeFile('blah/blah/blah.bar')).to.be.ok();
});
it('returns false if the path is not included in an include filter', function() {
tree.include = [ /.foo$/, /.bar$/ ];
node.include = [ /.foo$/, /.bar$/ ];
expect(tree.includeFile('blah/blah/blah.baz')).to.not.be.ok();
expect(node.includeFile('blah/blah/blah.baz')).to.not.be.ok();
});
it('returns true if no patterns were used', function() {
expect(tree.includeFile('blah/blah/blah.baz')).to.be.ok();
expect(node.includeFile('blah/blah/blah.baz')).to.be.ok();
});
it('uses a cache to ensure we do not recalculate the filtering on subsequent attempts', function() {
expect(tree.includeFile('blah/blah/blah.baz')).to.be.ok();
expect(node.includeFile('blah/blah/blah.baz')).to.be.ok();
// changing the filter mid-run should have no result on
// previously calculated paths
tree.include = [ /.foo$/, /.bar$/ ];
node.include = [ /.foo$/, /.bar$/ ];
expect(tree.includeFile('blah/blah/blah.baz')).to.be.ok();
expect(node.includeFile('blah/blah/blah.baz')).to.be.ok();
});

@@ -485,3 +486,3 @@ });

describe('lookupDestinationPath', function() {
var tree;
var node;

@@ -491,3 +492,3 @@ beforeEach(function() {

tree = new Funnel(inputPath);
node = new Funnel(inputPath);
});

@@ -498,3 +499,3 @@

expect(tree.lookupDestinationPath(relativePath)).to.be.equal(relativePath);
expect(node.lookupDestinationPath(relativePath)).to.be.equal(relativePath);
});

@@ -506,7 +507,7 @@

tree.getDestinationPath = function() {
node.getDestinationPath = function() {
return expected;
};
expect(tree.lookupDestinationPath(relativePath)).to.be.equal(expected);
expect(node.lookupDestinationPath(relativePath)).to.be.equal(expected);
});

@@ -520,3 +521,3 @@

tree.getDestinationPath = function() {
node.getDestinationPath = function() {
getDestPathCalled++;

@@ -527,3 +528,3 @@

expect(tree.lookupDestinationPath(relativePath)).to.be.equal(expected);
expect(node.lookupDestinationPath(relativePath)).to.be.equal(expected);
expect(getDestPathCalled).to.be.equal(1);

@@ -533,3 +534,3 @@

expect(tree.lookupDestinationPath(relativePath)).to.be.equal(expected);
expect(node.lookupDestinationPath(relativePath)).to.be.equal(expected);
expect(getDestPathCalled).to.be.equal(1);

@@ -536,0 +537,0 @@ });

Sorry, the diff of this file is not supported yet

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