thomas-darling / gulp-dependents

Gulp plugin that tracks dependencies between files and adds any files that depend on the files currently in the stream, thus enabling incremental build.
14 stars 5 forks source link

[BUG] running multiple time on saving multi file at a time #12

Open danny007in opened 3 years ago

danny007in commented 3 years ago

For example if save 4 multiple file on a time in folder it compile 4 times, but it has should compile only once

const scss = () => {
  return src(paths.src.scss + '/**/*.scss', {
    since: lastRun(scss),
    sourcemaps: true
  })
    .pipe(dependents())
    .pipe(sass(sassOptions).on('error', sass.logError))
    .pipe(postcss(postcssOptions))
    .pipe(dest(paths.temp.css, { sourcemaps: '.' }))
    .pipe(browserSync.stream())
}

const serve = () => {
  browserSync.init({
    server: paths.temp.base
  })

  watch([paths.src.scss], { delay: 500 }, series(scss))
}
[10:58:14] Starting 'scss'...
[Browsersync] 4 files changed (adminlte.css, adminlte.css, adminlte.css, adminlte.css)
[10:58:22] Finished 'scss' after 7.31 s

this is a wonderful devDep, plz solve this fast

danny007in commented 3 years ago

Just make an filter to remove duplicate path, before sending to src

danny007in commented 3 years ago

Any solution

danny007in commented 3 years ago

Can i expect this issue will be solved,

danny007in commented 3 years ago

I made a solution for this

gulp.task("build", function ()
{
    let chunksPath = [];
    let orgFilesPath = []

    return gulp

        // Get all source files.
        .src("source/**/*.scss", { since: gulp.lastRun('build') })

        // Add any dependent files to the stream.
        .pipe(dependents(config, { logDependents: true, logDependencyMap: false }))
        .pipe(through2.obj(function (chunk, enc, callback) {
            let filePath = path.normalize(chunk.path);

            if (!orgFilesPath.includes(filePath)) {
                console.log("🚀 ~ file: gulpfile.js ~ line 95 ~ filePath", filePath)
                this.push(chunk);
            }

            chunksPath.push(chunk)

            for (const allChun of chunksPath) {
                orgFilesPath.push(path.normalize(allChun.path))
            }

            callback()
        }))

        // For debugging, just output the name of each file we're about to build.
        .pipe(debug({ title: "[build]" }));
});
danny007in commented 3 years ago

main parts is

    let chunksPath = [];
    let orgFilesPath = []

        .pipe(through2.obj(function (chunk, enc, callback) {
            let filePath = path.normalize(chunk.path);

            if (!orgFilesPath.includes(filePath)) {
                console.log("🚀 ~ file: gulpfile.js ~ line 95 ~ filePath", filePath)
                this.push(chunk);
            }

            chunksPath.push(chunk)

            for (const allChun of chunksPath) {
                orgFilesPath.push(path.normalize(allChun.path))
            }

implement in main code