gulpjs / glob-stream

Readable streamx interface over anymatch.
MIT License
178 stars 53 forks source link

Only some files are being copied, if run inside a series #139

Open ghnp5 opened 1 month ago

ghnp5 commented 1 month ago

What were you expecting to happen?

All 840 files should be copied, recursively.

What actually happened?

Only the first few files (sorted alphabetically) of each folder are being copied, instead of all files.

This used to work, but seems broken since v5.

This is happening as the last step of a gulp.series, consistently. But if I run npx gulp copy-changed, it copies all the files, always.

Please give us a sample of your gulpfile

import { spawnSync } from 'child_process';
import glob from 'glob';
import path from 'path';
import fs from 'fs';
import mergeStream from 'ordered-read-streams';
import PluginError from 'plugin-error';
import gulp from 'gulp';
import htmlmin from 'gulp-htmlmin';
import clean from 'gulp-clean';
import newer from 'gulp-newer';
import changed from 'gulp-changed';
import rename from 'gulp-rename';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('__filename:', __filename);
console.log('__dirname:', __dirname);

(...)

// npx gulp copy-changed
gulp.task('copy-changed', () => {
    return gulp.src([path.join(__dirname, 'build\\_delta\\**\\*')], { dot: true })
        .pipe(gulp.dest(path.join(__dirname, 'build\\')));
});

gulp.task('build-debug', gulp.series(
    ...,
    ...,
    ...,
    'copy-changed'
));

Terminal output / screenshots

[01:29:42] Using gulpfile F:...\gulpfile.mjs [01:29:42] Starting 'build-debug'... [01:29:42] Starting '...'... [01:29:42] Finished '...' after 209 ms [01:29:42] Starting '...'... [01:29:42] Finished '...' after 107 ms [01:29:42] Starting '...'... (node:20356) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated. (Use node --trace-deprecation ... to show where the warning was created) [01:29:42] Finished '...' after 82 ms [01:29:42] Starting 'copy-changed'... [01:29:43] Finished 'copy-changed' after 1.1 s [01:29:43] Finished 'build-debug' after 1.54 s

Please provide the following information:

ghnp5 commented 1 week ago

The previous task copies stuff to that "_delta" folder, inside a mergeStream (which used to be on merge-stream, but when I was trying to fix this issue, I had upgraded to ordered-read-streams, but the same happens).

Seems that what's happening is that at the time "copy-changed" runs, the files aren't ready yet or so.

If I put a "sleep" of 3 seconds, it seems to work now.

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

gulp.task('copy-changed', () => {
    return sleep(3000).then(() => {
        return gulp.src([path.join(__dirname, 'build\\_delta\\**\\*')], { dot: true })
        .pipe(gulp.dest(path.join(__dirname, 'build\\')));
    });
});

This used to work before, so I'm not sure why it needs a sleep now.