Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior of changing working directory. #146

Closed
sttk opened this issue Jan 14, 2018 · 5 comments · Fixed by #253
Closed

Strange behavior of changing working directory. #146

sttk opened this issue Jan 14, 2018 · 5 comments · Fixed by #253
Labels
Milestone

Comments

@sttk
Copy link
Contributor

sttk commented Jan 14, 2018

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.

@phated
Copy link
Member

phated commented Jan 16, 2018

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

@sttk
Copy link
Contributor Author

sttk commented Jan 17, 2018

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

@phated
Copy link
Member

phated commented Jan 17, 2018

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
Copy link
Member

phated commented Jan 22, 2018

@sttk still planning to fix this?

@sttk
Copy link
Contributor Author

sttk commented Jan 23, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants