Skip to content

Replacing an invalid return statement with a valid exit code and allowing gulp to be run anywhere within a project. - #23

Closed
jsdevel wants to merge 2 commits into
gulpjs:masterfrom
jsdevel:master
Closed

jsdevel wants to merge 2 commits into
gulpjs:masterfrom
jsdevel:master

Conversation

@jsdevel

@jsdevel jsdevel commented Nov 13, 2013

Copy link
Copy Markdown

No description provided.

@yocontra

Copy link
Copy Markdown
Member

Couple of comments

  1. Not a fan of doing the chdir within getGulpfile - getGulpfile should have no side effects that way it can be tested easily
  2. What change was introduced to getGulpfile other than adding the chdir? The whole function was completely rewritten and I'm not sure why - I prefer the functional style it used before

+1 on the return statement fix

@jsdevel

jsdevel commented Nov 13, 2013

Copy link
Copy Markdown
Author
  1. With the change, I can gulp in any directory within my project, not just the directory where my gulpfile.js resides.
  2. A side effect of the previous item is: relative paths within my project that depended on CWD are now broken.
  3. The chdir considers the previous two points and prevents me from having to specify absolute paths everywhere within my code.
  4. Testing shouldn't be effected at all, in fact it should be enhanced as the CWD of gulpfile.js is always going to be the project root.
  5. require.extensions has been deprecated http://nodejs.org/api/globals.html#globals_require_extensions

@yocontra

Copy link
Copy Markdown
Member

gulpfile locating: I would prefer if we used a 3rd party module for walking up to find the gulpfile (grunt uses findup-sync for this)

Testing/chdir: Don't do a chdir in the function - do it before the gulpfile is loaded. I want the getGulpFile function to have no side effects.

As for require.extensions being deprecated:

Since the Module system is locked, this feature will probably never go away. However, it may have subtle bugs and complexities that are best left untouched.

If they ever remove it or an alternative arises I will revisit changing it. The changes you put in break support for coffee-script (which I personally use).

yocontra pushed a commit that referenced this pull request Nov 13, 2013
@yocontra yocontra closed this in 920a54a Nov 13, 2013
@jsdevel

jsdevel commented Nov 13, 2013

Copy link
Copy Markdown
Author

+1 for findup-sync

You're still doing a chdir within a function though 👯

@yocontra

Copy link
Copy Markdown
Member

@jsdevel the function name is what determines if it should have side effects. get(something) should not set something externally as well. set(something) or load(something) is perfectly fine to have some side effects in

@jsdevel

jsdevel commented Nov 13, 2013

Copy link
Copy Markdown
Author

@contra I disagree about set and load in relation to external side effects. setProperties() would be strange if it did a chdir.

I think a better option would be to scope chdir within the program instead of within a function, similar to the following:

if (!gulpFile) {
  cliGulp.log(chalk.red('No Gulpfile found'));
  process.exit(1);
} else {
  process.chdir(path.dirname(gulpFile));
}

I'm happy with your solution though. Now I can gulp away 👍

@yocontra

Copy link
Copy Markdown
Member

2.4 is published let me know if your problem is still unsolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants