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

New: Support flags.require config option (closes #108, closes #167) #183

Merged
merged 4 commits into from
Mar 21, 2019

Conversation

phated
Copy link
Member

@phated phated commented Mar 13, 2019

@sttk please review

@phated phated requested a review from sttk March 13, 2019 20:11
Copy link
Contributor

@sttk sttk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phated This is great! It slips my mind to need to concat flags.require in multiple .gulp.*.

Please change for my two comments.

@@ -16,6 +17,9 @@ function convert(configInfo, envInfo) {
if (envInfo.keyChain === 'configBase') {
return path.dirname(configInfo.value);
}
if (envInfo.keyChain === 'require') {
return [].concat(envInfo.value, configInfo.value);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be moved to load-files.js, which is executed by each config file.
env-flags.js is executed only once for copying configs to env after merging config files.

Take notice that if a value of flags.require is relative path, it is treated as relative to cwd when requiring. So this value needs to be converted to an absolute path when loading like flags.gulpfile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I knew I was probably doing something wrong. I'll add a test for that too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk I am looking at this now and I don't think this belongs in load-files.js because that would combine the config from cwd and home config files. Everything we've done until now has been that cwd configuration overrides any configuration in home.

I think we should continue that for this configuration, because it would be hard to track where the require was coming from. Also, it'd be the only option that combines a field from both locations and I'd like to keep everything consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk currently, when using --cwd and --require on the command-line, you have to be aware that your file will be required relative to cwd, is that not the behavior we want to reflect when using the .gulp.json file? Or do we need to fix the --require flag as well?

I'm not sure what behavior I would expect from this combination, so I don't know how we should change (if at all).

Copy link
Contributor

@sttk sttk Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cwd configuration overrides any configuration in home.

The above code looks not overriding but appending require configuration. With no conversion, load-files.js overrides configurations. So if overriding, only normalizing configInfo.value to array is needed. If overriding, that concatenation is not needed. (Though normalization of configInfo.value to array is needed.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think both two cases (overriding and appending) can be requested. For example, a TS user uses ts-node ususally so writes requiring it in ~/.gulp.json, and writes more loaders in (project-dir)/.gulp.json by project, but he don't want to use ts-node in only one project.

What do you think about adding one more format to choice overriding or appending like { "flags.require": { "path": "module-name", "append": true } } ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About a relative path, I think better that a relative path written in ~/.gulp.* is relative to home dir because it is looked and can be used by all project, and directory structures of projects are different.

But I notice that what I'm saying can be solved by specifying an absolute path. And certainly, what I'm saying ignores --cwd/gulpfile options. Umm...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttk Joining flags.require from cwd and home will break people that pull the project from GitHub (for example, your ts-node example would break for me if I pulled that down and didn't have the ts-node in my home .gulp.js file) - we'd want to have all the flags.require values in the cwd .gulp.js file.

I think I need to keep this array concat because I want to join the --require flags and the flags.require property. This should be the behavior for anything that takes multiple argument values.

What do you think about adding one more format to choice overriding or appending like { "flags.require": { "path": "module-name", "append": true } } ?

I don't want to max the options more complex like you suggested.

About a relative path, I think better that a relative path written in ~/.gulp.* is relative to home dir because it is looked and can be used by all project, and directory structures of projects are different.
But I notice that what I'm saying can be solved by specifying an absolute path. And certainly, what I'm saying ignores --cwd/gulpfile options. Umm...

I think we should just note that flags.require will be resolved to cwd unless it's a node module or absolute path. I can make that change to the docs.

Copy link
Contributor

@sttk sttk Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joining flags.require from cwd and home will break people that pull the project from GitHub

Certainly. it might be rare to use flags.require in home.

I think I need to keep this array concat because I want to join the --require flags and the flags.require property.

I got it. I think this should be so, too.

I don't want to max the options more complex like you suggested.

I got it.

I think we should just note that flags.require will be resolved to cwd unless it's a node module or absolute path. I can make that change to the docs.

Thanks for writing docs. I checked it.

test/config-flags-require.js Show resolved Hide resolved
@phated
Copy link
Member Author

phated commented Mar 19, 2019

@sttk I added docs and tests based on our discussions. Please review again and hopefully we can merge this.

@phated phated requested a review from sttk March 19, 2019 03:44
@phated
Copy link
Member Author

phated commented Mar 20, 2019

@sttk you are probably busy, but could you review this so we can land it?

@sttk
Copy link
Contributor

sttk commented Mar 20, 2019

@phated Sorry for the delay. I'll review this today. (It's a public holiday in japan today)

@phated
Copy link
Member Author

phated commented Mar 20, 2019

Thanks! Sorry to interrupt your holiday 😭

Copy link
Contributor

@sttk sttk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phated Don't worry. What I wanted to say is I have time to review today.

I think all is good and no problem. I approve this.

@@ -16,6 +17,9 @@ function convert(configInfo, envInfo) {
if (envInfo.keyChain === 'configBase') {
return path.dirname(configInfo.value);
}
if (envInfo.keyChain === 'require') {
return [].concat(envInfo.value, configInfo.value);
}
Copy link
Contributor

@sttk sttk Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joining flags.require from cwd and home will break people that pull the project from GitHub

Certainly. it might be rare to use flags.require in home.

I think I need to keep this array concat because I want to join the --require flags and the flags.require property.

I got it. I think this should be so, too.

I don't want to max the options more complex like you suggested.

I got it.

I think we should just note that flags.require will be resolved to cwd unless it's a node module or absolute path. I can make that change to the docs.

Thanks for writing docs. I checked it.

@phated phated merged commit 33e14d7 into master Mar 21, 2019
@phated
Copy link
Member Author

phated commented Mar 21, 2019

@sttk thanks for reviewing!

@phated phated deleted the flags-require branch March 21, 2019 22:24
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.

None yet

3 participants