Skip to content

Commit 69679c9

Browse files
committed
Fix for #321 - don't error if target is named "src"
1 parent fd818ff commit 69679c9

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

tasks/modules/tsconfig.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks/modules/tsconfig.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,19 @@ function warnOnBadConfiguration(options: IGruntTSOptions, projectSpec: ITSConfig
125125

126126
function getGlobs(taskOptions: ITargetOptions, targetOptions: ITargetOptions) {
127127
let globs = null;
128-
if (taskOptions && (<any>taskOptions).src) {
128+
129+
if (taskOptions && isStringOrArray((<any>taskOptions).src)) {
129130
globs = _.map([...(<any>taskOptions).src], item => templateProcessor(item, {}));
130131
}
131-
if (targetOptions && (<any>targetOptions).src) {
132+
if (targetOptions && isStringOrArray((<any>targetOptions).src)) {
132133
globs = _.map([...(<any>targetOptions).src], item => templateProcessor(item, {}));
133134
}
135+
134136
return globs;
137+
138+
function isStringOrArray(thing: any) {
139+
return (_.isArray(thing) || _.isString(thing));
140+
}
135141
}
136142

137143

test/optionsResolverTests.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/optionsResolverTests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ export var tests : nodeunit.ITestGroup = {
220220
test.ok(allWarnings.indexOf(`keyword "watch"`) > -1, "expected warning about keyword watch");
221221
test.done();
222222
}).catch((err) => {test.ifError(err); test.done();});
223+
},
224+
"Works OK when using grunt keyword (src) as target name": (test: nodeunit.Test) => {
225+
test.expect(3);
226+
227+
const cfg = getConfig("minimalist", true);
228+
const tsTaskCfg: any = { "src": cfg };
229+
const files: IGruntTSCompilationInfo[] = [{src: ['test/gruntkeyword.ts']}];
230+
231+
const result = or.resolveAsync(tsTaskCfg, cfg, "src", files).then((result) => {
232+
test.strictEqual(result.warnings.length, 0, "expected zero warnings.");
233+
test.strictEqual(result.errors.length, 0, "expected zero errors.");
234+
test.strictEqual(result.CompilationTasks[0].src.join(""), "test/gruntkeyword.ts", "expected just the test file");
235+
test.done();
236+
}).catch((err) => {test.ifError(err); test.done();});
223237
}
224238
},
225239

0 commit comments

Comments
 (0)