Skip to content

Commit 19f86d1

Browse files
committed
Structure where to put upcoming module addition
1 parent 8e15dc2 commit 19f86d1

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

packages/react-dev-utils/WatchTestFilesPlugin.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,40 @@ function computeGlob(pattern, options) {
1212
});
1313
}
1414

15+
function getGlobs(patterns, cwd) {
16+
return Promise.all(patterns.map(globPattern =>
17+
computeGlob(globPattern, {
18+
cwd: cwd,
19+
ignore: 'node_modules/**',
20+
})
21+
))
22+
.then(globLists => [].concat.apply([], globLists))
23+
}
24+
1525
function WatchTestFilesPlugin(testGlobs) {
1626
this.testGlobs = testGlobs || [];
1727
}
1828

1929
WatchTestFilesPlugin.prototype.apply = function(compiler) {
20-
compiler.plugin('emit', (compilation, callback) => {
21-
console.log()
22-
Promise.all(this.testGlobs.map(globPattern =>
23-
computeGlob(globPattern, {
24-
cwd: compiler.options.context,
25-
ignore: 'node_modules/**',
26-
})
27-
))
28-
.then(globLists => [].concat.apply([], globLists))
29-
.then(testFiles => {
30-
testFiles.forEach(testFile => {
31-
compilation.fileDependencies.push(path.join(compiler.options.context, testFile));
32-
});
30+
var testFiles = [];
31+
compiler.plugin('make', (compilation, callback) => {
32+
getGlobs(this.testGlobs, compiler.options.context)
33+
.then(foundFiles => {
34+
testFiles = foundFiles;
35+
return Promise.all(
36+
testFiles.map(filename => new Promise((resolve, reject) => {
37+
// TODO: add to modules
38+
resolve(filename);
39+
}))
40+
)
3341
})
34-
.then(callback)
35-
.catch(console.error);
42+
.then(callback);
43+
});
44+
compiler.plugin('emit', (compilation, callback) => {
45+
testFiles.forEach(testFile => {
46+
compilation.fileDependencies.push(path.join(compiler.options.context, testFile));
47+
});
48+
callback();
3649
});
3750
};
3851

0 commit comments

Comments
 (0)