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

broccoli-funnel

Package Overview
Dependencies
Maintainers
1
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.2 to 0.2.3

63

index.js
'use strict';
var fs = require('fs');
var RSVP = require('rsvp');
var path = require('path');
var rimraf = RSVP.denodeify(require('rimraf'));
var mkdirp = require('mkdirp');

@@ -12,3 +10,3 @@ var walkSync = require('walk-sync');

var symlinkOrCopy = require('symlink-or-copy');
var generateRandomString = require('./lib/generate-random-string');
var readAPICompat = require('broccoli-read-compat');

@@ -25,3 +23,3 @@

function Funnel(inputTree, options) {
if (!(this instanceof Funnel)) { console.error(new Error('You must use \'new Funnel\' to instantiate a broccoli-funnel item.')); }
if (!(this instanceof Funnel)) { return new Funnel(inputTree, options); }

@@ -33,4 +31,2 @@ this.inputTree = inputTree;

this._tmpDir = path.resolve(path.join(this.tmpRoot, 'funnel-dest_' + generateRandomString(6) + '.tmp'));
var keys = Object.keys(options || {});

@@ -42,3 +38,3 @@ for (var i = 0, l = keys.length; i < l; i++) {

this.setupDestPaths();
this.destDir = this.destDir || '/';

@@ -58,24 +54,14 @@ if (this.files && !Array.isArray(this.files)) {

Funnel.prototype.tmpRoot = 'tmp';
Funnel.prototype.setupDestPaths = function() {
this.destDir = this.destDir || '/';
this.destPath = path.join(this._tmpDir, this.destDir);
if (this.destPath[this.destPath.length -1] === '/') {
this.destPath = this.destPath.slice(0, -1);
}
};
Funnel.prototype._setupFilter = function(type) {
var filters = this[type];
if (!filters) {
if (!this[type]) {
return;
}
if (!Array.isArray(filters)) {
throw new Error('Invalid ' + type + ' option, it must be an array. You specified `' + typeof filters + '`.');
if (!Array.isArray(this[type])) {
throw new Error('Invalid ' + type + ' option, it must be an array. You specified `' + typeof this[type] + '`.');
}
// Clone the filter array so we are not mutating an external variable
var filters = this[type] = this[type].slice(0);
for (var i = 0, l = filters.length; i < l; i++) {

@@ -108,17 +94,11 @@ filters[i] = this._processPattern(filters[i]);

Funnel.prototype.read = function(readTree) {
var inputTree = this.inputTree;
Funnel.prototype.rebuild = function() {
this.destPath = path.join(this.outputPath, this.destDir);
if (this.destPath[this.destPath.length -1] === '/') {
this.destPath = this.destPath.slice(0, -1);
}
return RSVP.Promise.resolve()
.then(this.cleanup.bind(this))
.then(function() {
return readTree(inputTree);
})
.then(this.handleReadTree.bind(this));
};
Funnel.prototype.handleReadTree = function(inputTreeRoot) {
var inputPath = inputTreeRoot;
var inputPath = this.inputPath;
if (this.srcDir) {
inputPath = path.join(inputTreeRoot, this.srcDir);
inputPath = path.join(inputPath, this.srcDir);
}

@@ -128,2 +108,3 @@

if (fs.existsSync(inputPath)) {
fs.rmdirSync(this.outputPath);
this._copy(inputPath, this.destPath);

@@ -134,14 +115,6 @@ } else if (this.allowEmpty) {

} else {
mkdirp.sync(this._tmpDir);
this.processFilters(inputPath);
}
return this._tmpDir;
};
Funnel.prototype.cleanup = function() {
return rimraf(this._tmpDir);
};
Funnel.prototype.processFilters = function(inputPath) {

@@ -252,2 +225,4 @@ var files = walkSync(inputPath);

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

@@ -10,3 +10,3 @@ "main": "index.js",

"type": "git",
"url": "https://github.com/rwjblue/broccoli-funnel.git"
"url": "https://github.com/broccolijs/broccoli-funnel.git"
},

@@ -21,7 +21,6 @@ "scripts": {

"dependencies": {
"broccoli-read-compat": "^0.1.2",
"core-object": "0.0.2",
"minimatch": "^2.0.1",
"mkdirp": "^0.5.0",
"rimraf": "^2.2.8",
"rsvp": "^3.0.14",
"symlink-or-copy": "^1.0.0",

@@ -31,3 +30,5 @@ "walk-sync": "^0.1.3"

"devDependencies": {
"broccoli": "^0.13.0",
"broccoli": "^0.15.0",
"rimraf": "^2.3.2",
"rsvp": "^3.0.14",
"expect.js": "^0.3.1",

@@ -34,0 +35,0 @@ "mocha": "~1.18.2",

# Broccoli Funnel
[![Build Status](https://travis-ci.org/rwjblue/broccoli-funnel.svg?branch=master)](https://travis-ci.org/rwjblue/broccoli-funnel)
[![Build Status](https://travis-ci.org/broccolijs/broccoli-funnel.svg?branch=master)](https://travis-ci.org/broccolijs/broccoli-funnel)

@@ -13,3 +13,3 @@ Broccoli Funnel is a plugin that filters a tree and returns a new tree that

### `Funnel(inputTree, options)`
### `funnel(inputTree, options)`

@@ -20,3 +20,3 @@ `inputTree` *{Single tree}*

directory in your project or a tree structure returned from running another
Broccoli filter.
Broccoli plugin.

@@ -43,4 +43,4 @@ If your project has the following file structure:

```javascript
var Funnel = require('broccoli-funnel');
var cssFiles = new Funnel('src/css');
var funnel = require('broccoli-funnel');
var cssFiles = funnel('src/css');

@@ -87,3 +87,3 @@ /*

```javascript
var Funnel = require('broccoli-funnel');
var funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');

@@ -100,3 +100,3 @@

*/
var cssFiles = new Funnel(projectFiles, {
var cssFiles = funnel(projectFiles, {
srcDir: 'css'

@@ -111,3 +111,3 @@ });

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

@@ -148,5 +148,5 @@ });

```javascript
var Funnel = require('broccoli-funnel');
var funnel = require('broccoli-funnel');
var cssFiles = new Funnel('src/css', {
var cssFiles = funnel('src/css', {
destDir: 'build'

@@ -204,7 +204,7 @@ });

```javascript
var Funnel = require('broccoli-funnel');
var funnel = require('broccoli-funnel');
// finds all files that match /todo/ and moves them
// the destDir
var todoRelatedFiles = new Funnel('src', {
var todoRelatedFiles = funnel('src', {
include: [new RegExp(/todo/)]

@@ -258,7 +258,7 @@ });

```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 = new Funnel('src', {
var nobodyLikesTodosAnyway = funnel('src', {
exclude: [new RegExp(/todo/)]

@@ -313,6 +313,6 @@ });

```javascript
var Funnel = require('broccoli-funnel');
var funnel = require('broccoli-funnel');
// finds these specific files and moves them to the destDir
var someFiles = new Funnel('src', {
var someFiles = funnel('src', {
files: ['css/reset.css', 'icons/check-mark.png']

@@ -350,3 +350,3 @@ });

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

@@ -353,0 +353,0 @@

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

[ path.join(fixturePath, 'dir1', 'subdir1/subsubdir2/some.js'),
path.join(outputPath, 'foo/subdir1/subsubdir2/some.js'),
path.join(outputPath, 'foo/subdir1/subsubdir2/some.js'),
'subdir1/subsubdir2/some.js' ]

@@ -162,6 +162,6 @@ ];

.then(function() {
return rimraf(tree._tmpDir);
return rimraf(tree.outputPath);
})
.then(function() {
fs.symlinkSync('foo/bar/baz.js', tree._tmpDir);
fs.symlinkSync('foo/bar/baz.js', tree.outputPath);
})

@@ -317,2 +317,8 @@ .then(function() {

]);
it('is not mutated', function() {
var include = [ '**/*.unknown' ];
testFiltering(include, null, null, []);
expect(include[0]).to.eql('**/*.unknown');
});
});

@@ -349,2 +355,8 @@

]);
it('is not mutated', function() {
var exclude = [ '**/*' ];
testFiltering(null, exclude, null, []);
expect(exclude[0]).to.eql('**/*');
});
});

@@ -351,0 +363,0 @@

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