-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
607e105
New: Support `flags.require` config option (closes #108, closes #167)
phated 42b9d8b
Update docs to reflect require against cwd
phated 554c6e1
Add tests for absolute and relative flags.require
phated 860822d
Add test for --require twice
phated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
'use strict'; | ||
|
||
var expect = require('expect'); | ||
|
||
var path = require('path'); | ||
var fixturesDir = path.join(__dirname, 'fixtures/config'); | ||
|
||
var headLines = require('gulp-test-tools').headLines; | ||
phated marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var eraseTime = require('gulp-test-tools').eraseTime; | ||
var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir); | ||
|
||
describe('config: flags.require', function() { | ||
|
||
it('Should configure with an array in a .gulp.* file', function(done) { | ||
runner | ||
.chdir('flags/require/array') | ||
.gulp() | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).toEqual(null); | ||
expect(stderr).toEqual(''); | ||
|
||
var requiring1 = eraseTime(headLines(stdout, 1)); | ||
expect(requiring1).toEqual('Requiring external module ./preload_one'); | ||
var requiring2 = eraseTime(headLines(stdout, 1, 1)); | ||
expect(requiring2).toEqual('Requiring external module ./preload_two'); | ||
var preload1 = eraseTime(headLines(stdout, 1, 4)); | ||
expect(preload1).toEqual('preload one!'); | ||
var preload2 = eraseTime(headLines(stdout, 1, 5)); | ||
expect(preload2).toEqual('preload two!'); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('Should configure with a string in a .gulp.* file', function(done) { | ||
runner | ||
.chdir('flags/require/string') | ||
.gulp() | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).toEqual(null); | ||
expect(stderr).toEqual(''); | ||
var requiring = eraseTime(headLines(stdout, 1)); | ||
expect(requiring).toEqual('Requiring external module ./preload'); | ||
var preload1 = eraseTime(headLines(stdout, 1, 3)); | ||
expect(preload1).toEqual('hello preload!'); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('Combines --require flag with .gulp.* file flags.require', function(done) { | ||
runner | ||
.chdir('flags/require/join-flags') | ||
.gulp('--require ./preload_one') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).toEqual(null); | ||
expect(stderr).toEqual(''); | ||
|
||
var requiring1 = eraseTime(headLines(stdout, 1)); | ||
expect(requiring1).toEqual('Requiring external module ./preload_one'); | ||
var requiring2 = eraseTime(headLines(stdout, 1, 1)); | ||
expect(requiring2).toEqual('Requiring external module ./preload_two'); | ||
var preload1 = eraseTime(headLines(stdout, 1, 4)); | ||
expect(preload1).toEqual('preload one!'); | ||
var preload2 = eraseTime(headLines(stdout, 1, 5)); | ||
expect(preload2).toEqual('preload two!'); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('resolves relative requires against cwd', function(done) { | ||
runner | ||
.gulp('--cwd flags/require/with-cwd') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).toEqual(null); | ||
expect(stderr).toEqual(''); | ||
var requiring = eraseTime(headLines(stdout, 1)); | ||
expect(requiring).toEqual('Requiring external module ../preload'); | ||
var preload1 = eraseTime(headLines(stdout, 1, 4)); | ||
expect(preload1).toEqual('hello preload!'); | ||
done(err); | ||
} | ||
}); | ||
|
||
it('works with absolute paths, ignoring cwd', function(done) { | ||
runner | ||
.gulp('--cwd flags/require/with-absolute') | ||
.run(cb); | ||
|
||
function cb(err, stdout, stderr) { | ||
expect(err).toEqual(null); | ||
expect(stderr).toEqual(''); | ||
|
||
var absolute = path.join(__dirname, './fixtures/config/flags/require/preload'); | ||
var requiring = eraseTime(headLines(stdout, 1)); | ||
expect(requiring).toEqual('Requiring external module ' + absolute); | ||
var preload1 = eraseTime(headLines(stdout, 1, 4)); | ||
expect(preload1).toEqual('hello preload!'); | ||
done(err); | ||
} | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"flags": { | ||
"require": [ | ||
"./preload_one", | ||
"./preload_two" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
|
||
gulp.task('default', function(done) { | ||
console.log(global.preload_one); | ||
console.log(global.preload_two); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload_one = 'preload one!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload_two = 'preload two!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"flags": { | ||
"require": [ | ||
"./preload_two" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
|
||
gulp.task('default', function(done) { | ||
console.log(global.preload_one); | ||
console.log(global.preload_two); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload_one = 'preload one!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload_two = 'preload two!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload = 'hello preload!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"flags": { | ||
"require": "./preload" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
|
||
gulp.task('default', function(done) { | ||
console.log(global.preload); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global.preload = 'hello preload!'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var path = require('path'); | ||
|
||
module.exports = { | ||
flags: { | ||
require: path.join(__dirname, '../preload'), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
|
||
gulp.task('default', function(done) { | ||
console.log(global.preload); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"flags": { | ||
"require": "../preload" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
|
||
gulp.task('default', function(done) { | ||
console.log(global.preload); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
console.log('inside test module 2'); | ||
exports = function() { | ||
console.log('inside test module function 2'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 toenv
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 likeflags.gulpfile
.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 fromcwd
andhome
config files. Everything we've done until now has been thatcwd
configuration overrides any configuration inhome
.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.
There was a problem hiding this comment.
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 tocwd
, 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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above code looks not overriding but appending
require
configuration.With no conversion,If overriding, that concatenation is not needed. (Though normalization ofload-files.js
overrides configurations. So if overriding, only normalizingconfigInfo.value
to array is needed.configInfo.value
to array is needed.)There was a problem hiding this comment.
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 usets-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 } }
?There was a problem hiding this comment.
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...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sttk Joining
flags.require
fromcwd
andhome
will break people that pull the project from GitHub (for example, yourts-node
example would break for me if I pulled that down and didn't have thets-node
in myhome
.gulp.js
file) - we'd want to have all theflags.require
values in thecwd
.gulp.js
file.I think I need to keep this array concat because I want to join the
--require
flags and theflags.require
property. This should be the behavior for anything that takes multiple argument values.I don't want to max the options more complex like you suggested.
I think we should just note that
flags.require
will be resolved tocwd
unless it's a node module or absolute path. I can make that change to the docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly. it might be rare to use
flags.require
in home.I got it. I think this should be so, too.
I got it.
Thanks for writing docs. I checked it.