gulpjs / glob-stream

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

Gulp v5.0.0. Problem via `src` usage with external `gulpfile.js` #130

Closed Dmitriy-Frostoff closed 7 months ago

Dmitriy-Frostoff commented 7 months ago

What were you expecting to happen?

Expected npx gulp --gulpfile ./configs/gulp/gulpfile.js html to bundle html file via gulp-file-include plugin and a few more ones (check the gulpfile.js for details). P.S. via gulp@4.0.2 and gulp-cli@3.0.0 everything works fine.

What actually happened?

Got the exception with the globs argument according to Gulp official docs.

Please give us a sample of your gulpfile

Link to my bolerplate

gulpfile.js is at configs/gulp/gulpfile.js

Terminal output / screenshots

$ npx gulp --gulpfile ./configs/gulp/gulpfile.js html
[23:08:48] Working directory changed to E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\configs\gulp
[23:08:48] Using gulpfile E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\configs\gulp\gulpfile.js
[23:08:48] Starting 'html'...
[23:08:48] 'html' errored after 24 ms
[23:08:48] Error: File not found with singular glob: E:/Code learning/boilerplate-webpack-gulp-html-scss-js-components/projectName/src/pages/index
_gulp_include.html (if this was purposeful, use `allowEmpty` option)
    at E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\glob-stream\index.js:305:19
    at Array.forEach (<anonymous>)
    at EventEmitter.onEnd (E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\glob-stream\index.js:302:11)
    at Object.onceWrapper (node:events:633:28)
    at EventEmitter.emit (node:events:519:28)
    at EventEmitter.emit (node:domain:551:15)
    at queue.drain (E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\glob-stream\index.js:36:8)
    at Task.release (E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\fastq\queue.js:179:12)
    at worked (E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\fastq\queue.js:223:10)
    at E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\node_modules\glob-stream\index.js:82:9

Please provide the following information:

Steps to reproduce:

npm run html

works fine;

npm un gulp
npm i -D gulp
npx gulp --gulpfile ./configs/gulp/gulpfile.js html

Additional information

The problem occurs only when gulpfile.js placed not in a root of a project (in a root folder it works fine with the relevant src paths). Via gulp@4.0.2 and gulp-cli@3.0.0 everything works fine. No globally installed packages were used. The boilerplate is set to use modules (type: module in package.json is set). Check the description for more.

P.S. Thank you the Gulpjs Team for Hard work and Tools!!! gulpjs.com/docs is Awesome resource for learning the tool! I really enjoyed the way you've done it - imho, one of the best ever! Great job done, Team!)))

phated commented 7 months ago

Thanks for the report. I haven't debugged anything here, but I think the issue is that glob-stream always starts at the cwd and your cwd is being changed to the location of the gulpfile.

Can you try adding an explicit cwd to your src? Something like { cwd: "../.." } as the second argument

phated commented 7 months ago

If the above proves to solve the issue, we may need to resolve the "most common directory" of all globs to start the walkdir πŸ€”

Dmitriy-Frostoff commented 7 months ago

Blaine, thanks for your help!!! πŸ™ πŸ™ πŸ™ πŸ™
Your tip cured the situation! πŸ‘ πŸ‘ πŸ‘ πŸ‘

I've followed your tip and done this steps:

Current gulpfile.js config

import gulp from 'gulp';
const { src, dest, series } = gulp;
import include from 'gulp-file-include';
import replace from 'gulp-replace';
import rename from 'gulp-rename';

export function html() {
  return src('projectName/src/pages/index_gulp_include.html', {
    cwd: '../../',
  })
    .pipe(
      include({
        prefix: '@@',
        indent: true,
      }),
    )
    .pipe(replace(/="(\.\.\/){2,}/gi, '="../'))
    .pipe(rename('index.html'))
    .pipe(dest('../../projectName/src/pages/'));
}

The bash log

$ npx gulp --gulpfile ./configs/gulp/gulpfile.js html
[11:30:15] Working directory changed to E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\configs\gulp
[11:30:15] Using gulpfile E:\Code learning\boilerplate-webpack-gulp-html-scss-js-components\configs\gulp\gulpfile.js
[11:30:15] Starting 'html'...
[11:30:15] Finished 'html' after 351 ms

P.S. and especially thanks for clearing up how to use optional cwd, root parameters. My knowledge of gulp has been strengthened now πŸ‘πŸ‘πŸ‘πŸ‘

Dmitriy-Frostoff commented 7 months ago

As notice if you won't mind:
interesting thing but dest is set to be relative to the current place of the gulpfile.js and it works as expected (places bundled html file to the projectName/src/pages/index.html relative to the root). πŸ€”

jcvignoli commented 7 months ago

I think it may be related to this bug: multilevel reinclusion don't work. With Gulp 4 I could properly chain an exclusion followed by a reinclusion, Gulp 5 doesn't reinclude the files that are an exception to an exclusion. files: { src: [ './src/**/*.*', '!./src/vendor/**/*.*', './src/vendor/composer/**/*.*', './src/vendor/autoload.*', } };

Patta commented 7 months ago

I can confirm, that src can no longer handle ../ at the beginning. This is the case when gulpfile is in a subdirectory like Build and Resources is outside of Build.

src('../Resources/Private/Sass/*') no longer works src('Resources/Private/Sass/*') works

PS: dest works sometimes with ../ at the beginning, but not in all cases.