Skip to content

Commit cad78cc

Browse files
committed
optimize virtual globbing from tsconfig.
To resolve #202 (comment)
1 parent eaeb5c5 commit cad78cc

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

tasks/modules/tsconfig.js

Lines changed: 18 additions & 5 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: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,29 @@ function applyCompilerOptions(applyTo: IGruntTSOptions, projectSpec: ITSConfigFi
234234
addUniqueRelativeFilesToSrc(projectSpec.files, src, absolutePathToTSConfig);
235235
} else {
236236
if (!(<any>globExpander).isStub) {
237-
// if files is not specified, default to including *.ts and *.tsx in folder and subfolders.
238-
const virtualGlob = [path.resolve(absolutePathToTSConfig, './**/*.ts'),
239-
path.resolve(absolutePathToTSConfig, './**/*.tsx')];
237+
238+
const virtualGlob: string[] = [];
239+
240240
if (projectSpec.exclude && _.isArray(projectSpec.exclude)) {
241-
projectSpec.exclude.forEach(exc => {
242-
virtualGlob.push('!' + path.resolve(absolutePathToTSConfig, exc, './**/*.ts'));
243-
virtualGlob.push('!' + path.resolve(absolutePathToTSConfig, exc, './**/*.tsx'));
244-
});
241+
virtualGlob.push(path.resolve(absolutePathToTSConfig, './*.ts'));
242+
virtualGlob.push(path.resolve(absolutePathToTSConfig, './*.tsx'));
243+
244+
const tsconfigExcludedDirectories: string[] = [];
245+
projectSpec.exclude.forEach(exc => {
246+
tsconfigExcludedDirectories.push(path.normalize(path.join(absolutePathToTSConfig, exc)));
247+
});
248+
fs.readdirSync(absolutePathToTSConfig).forEach(item => {
249+
const filePath = path.normalize(path.join(absolutePathToTSConfig, item));
250+
if (fs.statSync(filePath).isDirectory()) {
251+
if (tsconfigExcludedDirectories.indexOf(filePath) === -1) {
252+
virtualGlob.push(path.resolve(absolutePathToTSConfig, item, './**/*.ts'));
253+
virtualGlob.push(path.resolve(absolutePathToTSConfig, item, './**/*.tsx'));
254+
}
255+
}
256+
});
257+
} else {
258+
virtualGlob.push(path.resolve(absolutePathToTSConfig, './**/*.ts'));
259+
virtualGlob.push(path.resolve(absolutePathToTSConfig, './**/*.tsx'));
245260
}
246261

247262
const files = globExpander(virtualGlob);

0 commit comments

Comments
 (0)