gulp-cli icon indicating copy to clipboard operation
gulp-cli copied to clipboard

Strange behavior of changing working directory.

Open sttk opened this issue 7 years ago • 5 comments

I found a strange behavior about changing working directory. This is related to the comment in #109.

Assuming directory structure:

project/
  ├── gulpfile.js
  └── currentdir/
        ├── .gulp.js
        └── gulpfile-2.js

and the contents of each files:

$ cat currentdir/.gulp.js 
module.exports = {
  flags: {
    gulpfile: './gulpfile-2.js'
  }
}

$ cat currentdir/gulpfile-2.js 
var gulp = require('gulp');
gulp.task('default', function() {
  console.log(__filename);
});

$ cat gulpfile.js 
var gulp = require('gulp');
gulp.task('default', function() {
  console.log(__filename);
});

In this condition, the following execution uses project/gulpfile.js against my intention.

$ cd currentdir/
$ gulp
[15:36:42] Working directory changed to ~/project
[15:36:42] Using gulpfile ~/project/gulpfile.js
[15:36:42] Starting 'default'...
/Users/sttk/project/gulpfile.js
[15:36:42] Finished 'default' after 141 μs

When project/gulpfile.js is removed or renamed, project/currentdir/gulpfile-2.js is used along my intention.

$ mv ../gulpfile.js ../gulpfile.js.x
$ gulp 
[15:41:05] Using gulpfile ~/project/currentdir/gulpfile-2.js
[15:41:05] Starting 'default'...
/Users/sttk/project/currentdir/gulpfile-2.js
[15:41:05] Finished 'default' after 95 μs

This cause is that gulp found up project/gulpfile.js and ~~changed cwd to project/ before finding and applying config files.~~ changed cwd for finding a config file to project/ in liftoff.

~~I think when a gulpfile is specified in a config file, cwd should be set back to INIT_CWD or set to parent directory of the gulpfile.~~ I think that process.INIT_CWD should be added to the directories for finding config files.


EDIT: I modified the last two sentences.

sttk avatar Jan 14 '18 07:01 sttk

@sttk that is strange, indeed. Do you think we need to make a change in liftoff?

phated avatar Jan 16 '18 20:01 phated

@phated I think this find-up behavior is helpful when a user works in a directory which is a sub directory but not a sub project of a project, so I think we need not change liftoff.

It would be enough to add the real current directory (= env.INIT_CWD) to config file entries. The current cwd entry indicates a (parent) project directory, actually.

I think it's good that the entry order of this directory is the last because a config file in this diretory should be given the most priority.

sttk avatar Jan 17 '18 14:01 sttk

It would be enough to add the real current directory (= env.INIT_CWD) to config file entries. The current cwd entry indicates a (parent) project directory, actually.

I think it's good that the entry order of this directory is the last because a config file in this diretory should be given the most priority.

I'm good with this solution.

phated avatar Jan 17 '18 21:01 phated

@sttk still planning to fix this?

phated avatar Jan 22 '18 21:01 phated

@phated I've just merged v2.0.1 to my repository, and I'm going to address this issue from now.

sttk avatar Jan 23 '18 13:01 sttk