Comments (11)
See gulpjs/gulp#729
from del.
What's the use-case?
from del.
@sindresorhus I've a use case where I get files from a sitemap.xml
(with gulp-sitemap-files) and delete them with del
.
from del.
Why can't you just assign it to a variable and use it in both del
and gulp.src
?
from del.
I'm not sure what you mean. See gulpjs/gulp#729, how would you "assign it to a variable and use it in both del
and gulp.src
" there?
from del.
Yeah, that's not possible. I wouldn't make this module a gulp-plugin though. What is wrong with doing it your way?
from del.
Off topic, but looking at your plugin it shouldn't be a gulp plugin, but rather a vinyl source plugin like vinyl-fs. Working on only one file in gulp.src is usually a sign you're doing something wrong.
As for this issue, what's wrong with doing like you're doing in your linked example? Except for wrong usage of map ofc. Use through2
instead.
from del.
Working on only one file in gulp.src is usually a sign you're doing something wrong
Maybe I'd have multiple sitemaps though? Also, I don't know but there might be a use case where it needs to follow a pipe instead of just being a source (probably unlikely though).
Use
through2
instead.
Cool
from del.
The problem @sindresorhus is describing with your plugin is that it shouldn't take a source. The basics of transform streams/write streams is that you should be able to pipe in whatever stuff you got.
By wrapping del
inside through.obj
you're essentially creating a transform stream (or "follow a pipe" as you describe it) so it's no difference from using any other gulp plugin. Make sure you include this.push(file)
if you want to pipe the files to another plugin. E.g:
.pipe(through.obj(function (file, enc, cb) {
this.push(file);
del(file.path, cb);
}))
.pipe(somePlugin());
from del.
@sindresorhus My use case is being able to delete corresponding files from a build
directory when a watched file was deleted in the app
directory. For example, when a .coffee
file is deleted, I capture deleted
event in the stream and I need to delete corresponding .js
and .js.map
files in the build directory.
from del.
@kevva Thank you for sharing an approach. Though, it didn't work for me as is when I plugged it into the middle of my existing pipe chain. I had to reverse the order and push the file after calling del()
, otherwise my next pipe would change the file object and del would try to operate on the wrong path. Not sure why yet, but this is what worked:
.pipe(through.obj(function(file, enc, cb) {
del(file.path);
this.push(file);
cb();
}));
Perhaps this is more compliant with the gulp plugin guidelines:
Do not pass the
file
object downstream until you are done with it
from del.
Related Issues (20)
- Cannot delete dirs containing files with invalid UTF8 sequences in their name HOT 7
- The example of doc don't work HOT 2
- Very confused at glob behavior in 5.x vs 4.x HOT 4
- gulp DeprecationWarning in node 14.5? HOT 1
- Typescript 2x Error HOT 1
- Delete all content except the folder HOT 3
- Plugin is not working with Electron App HOT 1
- Add `progress` event
- Filenames with parentheses not deleted
- why 'del' restores the files I have deleted using 'rimraf'
- 5. X and 6 X performs wildcard recursive directory deletion, which is invalid
- Weird problem in the npm page HOT 1
- Upgrade: v7 convert to ESM lets Disscuse the API HOT 6
- Error: Cannot delete files/directories outside the current working directory HOT 1
- Release Notes for version 7 are incorrect HOT 1
- Build fail when using Babel HOT 3
- Couldn't delete dot files in del7.0.0 HOT 1
- [v8] Make the `dot` option true by default?
- Cannot find module 'del' HOT 1
- TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from del.