🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

gulp-clean

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-clean - npm Package Compare versions

Comparing version

to
0.2.0

8

index.js

@@ -6,11 +6,11 @@ 'use strict';

module.exports = function () {
module.exports = function (options) {
return es.map(function (file, cb) {
// Relative paths are already resolved by the gulp
// Paths are resolved by gulp
var filepath = file.path;
var cwd = file.cwd;
var starts = new RegExp('^' + cwd);
var starts = new RegExp('^' + cwd + '/');
// Prevent mistakes with paths
if (starts.test(filepath) && filepath !== cwd) {
if (starts.test(filepath) && filepath !== cwd || (options ? options.force : false)) {
rimraf(filepath, function (error) {

@@ -17,0 +17,0 @@ if (!error) {

{
"name": "gulp-clean",
"version": "0.1.3",
"version": "0.2.0",
"description": "A gulp plugin for removing files and folders.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -20,6 +20,7 @@ # [gulp](https://github.com/wearefractal/gulp)-clean [![Build Status](https://secure.travis-ci.org/peter-vilja/gulp-clean.png?branch=master)](https://travis-ci.org/peter-vilja/gulp-clean) [![NPM version](https://badge.fury.io/js/gulp-clean.png)](http://badge.fury.io/js/gulp-clean)

gulp.task('default', function() {
gulp.src(['app/tmp'])
gulp.src('app/tmp', {read: false})
.pipe(clean());
});
```
Option read false prevents gulp to read the contents of the file and makes this task a lot faster.

@@ -33,4 +34,4 @@ After using gulp-clean the stream still contains the app/tmp and it can be used i.e. for moving the content to different location.

gulp.task('default', function() {
gulp.src(['app/tmp/index.js'])
.pipe(clean());
gulp.src('app/tmp/index.js', {read: false})
.pipe(clean({force: true}));
.pipe(gulp.dest('dist'));

@@ -40,3 +41,3 @@ });

#### For safety only files and folders under the current working directory can be removed.
#### For safety files and folders outside the current working directory can be removed only with option force set to true.

@@ -47,2 +48,5 @@ ## Changelog

* **0.2.0**
* Support for option force, to allow removing files and folders outside the current working directory.
* Fixed a bug, which made it possible to remove files/folders starting with the project's name to be removed outside the current working directory.
* **0.1.3**

@@ -49,0 +53,0 @@ * Improved documentation.

@@ -34,3 +34,3 @@ /*global describe, before, it*/

it('removes file', function (done) {
it('removes a file', function (done) {
var stream = clean();

@@ -57,3 +57,3 @@ var content = 'testing';

it('removes directory', function (done) {
it('removes a directory', function (done) {
fs.mkdir('tmp/test', function () {

@@ -79,3 +79,3 @@ var stream = clean();

it('removes all from tree', function (done) {
it('removes all from the tree', function (done) {
createTree(function () {

@@ -104,3 +104,3 @@ var stream = clean();

it('cannot remove current working directory', function (done) {
it('cannot remove the current working directory', function (done) {
var stream = clean();

@@ -123,3 +123,3 @@

it('cannot delete anything outside working directory', function (done) {
it('cannot delete anything outside the current working directory', function (done) {
var stream = clean();

@@ -143,2 +143,44 @@

});
it('cannot delete a folder outside the current working directory', function (done) {
var stream = clean();
if (!fs.existsSync('../gulp-cleanTemp')) { fs.mkdirSync('../gulp-cleanTemp'); }
stream.on('end', function () {
fs.exists('../gulp-cleanTemp', function (exists) {
expect(exists).to.be.true;
fs.unlink('../gulp-cleanTemp', function () {
done();
});
});
});
stream.write(new gutil.File({
cwd: path.resolve(cwd + '..'),
path: path.resolve(cwd + '/../gulp-cleanTemp/')
}));
stream.end();
});
it('can delete contents outside the current working directory with option force true', function (done) {
var stream = clean({force: true});
if (!fs.existsSync('../gulp-cleanTemp')) { fs.mkdirSync('../gulp-cleanTemp'); }
stream.on('end', function () {
fs.exists('../gulp-cleanTemp', function (exists) {
expect(exists).to.be.false;
done();
});
});
stream.write(new gutil.File({
cwd: path.resolve(cwd + '..'),
path: path.resolve(cwd + '/../gulp-cleanTemp/')
}));
stream.end();
});
});