Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 9e76272

Browse files
authored
update serve-functions to watch all files in functions folder, fixes #167 (#171)
update serve-functions to watch all files in functions folder, fixes #167
2 parents 008575b + a706084 commit 9e76272

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

src/utils/serve-functions.js

+9-26
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,16 @@ function createHandler(dir) {
7878
}
7979
});
8080

81-
Object.keys(functions).forEach(name => {
82-
const fn = functions[name];
83-
const clearCache = action => () => {
84-
if (action !== "added") {
85-
console.log(
86-
`${NETLIFYDEVLOG} function ${chalk.yellow(
87-
name
88-
)} ${action}, reloading...`
89-
); // eslint-disable-line no-console
90-
}
91-
const before = module.paths;
92-
module.paths = [fn.moduleDir];
93-
delete require.cache[require.resolve(fn.functionPath)];
94-
module.paths = before;
95-
};
96-
const pathsToWatch = [fn.functionPath];
97-
if (fn.moduleDir) {
98-
pathsToWatch.push(path.join(fn.moduleDir, "package.json"));
99-
}
100-
fn.watcher = chokidar.watch(pathsToWatch, {
101-
ignored: /node_modules/
81+
const clearCache = action => path => {
82+
console.log(`${NETLIFYDEVLOG} ${path} ${action}, reloading...`); // eslint-disable-line no-console
83+
Object.keys(require.cache).forEach(k => {
84+
delete require.cache[k];
10285
});
103-
fn.watcher
104-
.on("add", clearCache("added"))
105-
.on("change", clearCache("modified"))
106-
.on("unlink", clearCache("deleted"));
107-
});
86+
};
87+
const watcher = chokidar.watch(dir, { ignored: /node_modules/ });
88+
watcher
89+
.on("change", clearCache("modified"))
90+
.on("unlink", clearCache("deleted"));
10891

10992
return function(request, response) {
11093
// handle proxies without path re-writes (http-servr)

0 commit comments

Comments
 (0)