Giter Site home page Giter Site logo

Delete files in pipechain about del HOT 11 CLOSED

sindresorhus avatar sindresorhus commented on August 12, 2024
Delete files in pipechain

from del.

Comments (11)

adam-lynch avatar adam-lynch commented on August 12, 2024

See gulpjs/gulp#729

from del.

sindresorhus avatar sindresorhus commented on August 12, 2024

What's the use-case?

from del.

adam-lynch avatar adam-lynch commented on August 12, 2024

@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.

sindresorhus avatar sindresorhus commented on August 12, 2024

Why can't you just assign it to a variable and use it in both del and gulp.src?

from del.

adam-lynch avatar adam-lynch commented on August 12, 2024

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.

kevva avatar kevva commented on August 12, 2024

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.

sindresorhus avatar sindresorhus commented on August 12, 2024

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.

adam-lynch avatar adam-lynch commented on August 12, 2024

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.

kevva avatar kevva commented on August 12, 2024

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.

demisx avatar demisx commented on August 12, 2024

@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.

demisx avatar demisx commented on August 12, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.