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

Lines changed: 9 additions & 26 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy