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

Commit 2f60591

Browse files
committed
Check if functions directory exists. Fixes #182
1 parent 0ebd840 commit 2f60591

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/utils/serve-functions.js

+23-21
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,29 @@ function buildClientContext(headers) {
5656

5757
function createHandler(dir) {
5858
const functions = {};
59-
fs.readdirSync(dir).forEach(file => {
60-
if (dir === "node_modules") {
61-
return;
62-
}
63-
const functionPath = path.resolve(path.join(dir, file));
64-
const handlerPath = findHandler(functionPath);
65-
if (!handlerPath) {
66-
return;
67-
}
68-
if (path.extname(functionPath) === ".js") {
69-
functions[file.replace(/\.js$/, "")] = {
70-
functionPath,
71-
moduleDir: findModuleDir(functionPath)
72-
};
73-
} else if (fs.lstatSync(functionPath).isDirectory()) {
74-
functions[file] = {
75-
functionPath: handlerPath,
76-
moduleDir: findModuleDir(functionPath)
77-
};
78-
}
79-
});
59+
if (fs.existsSync(dir)) {
60+
fs.readdirSync(dir).forEach(file => {
61+
if (dir === "node_modules") {
62+
return;
63+
}
64+
const functionPath = path.resolve(path.join(dir, file));
65+
const handlerPath = findHandler(functionPath);
66+
if (!handlerPath) {
67+
return;
68+
}
69+
if (path.extname(functionPath) === ".js") {
70+
functions[file.replace(/\.js$/, "")] = {
71+
functionPath,
72+
moduleDir: findModuleDir(functionPath)
73+
};
74+
} else if (fs.lstatSync(functionPath).isDirectory()) {
75+
functions[file] = {
76+
functionPath: handlerPath,
77+
moduleDir: findModuleDir(functionPath)
78+
};
79+
}
80+
});
81+
}
8082

8183
const clearCache = action => path => {
8284
console.log(`${NETLIFYDEVLOG} ${path} ${action}, reloading...`); // eslint-disable-line no-console

0 commit comments

Comments
 (0)