Skip to content

Commit

Permalink
Merge pull request #256 from HubSpot/fix/nested-functions
Browse files Browse the repository at this point in the history
Allow user to functions in the same directory
  • Loading branch information
anthmatic authored Jul 15, 2020
2 parents 8b84df9 + 0b9ab4a commit f32da53
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/cms-lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const findup = require('findup-sync');
const { logger } = require('./logger');
const { logFileSystemErrorInstance } = require('./errorHandlers');
const isObject = require('./lib/isObject');
const { getCwd } = require('./path');

const functionBody = `
exports.main = ({ accountId, body, params }, sendResponse) => {
Expand Down Expand Up @@ -98,11 +99,16 @@ function createFunction(
{ functionsFolder, filename, endpointPath, endpointMethod },
dest
) {
const ancestorFunctionsDir = findup('*.functions');
const ancestorFunctionsConfig = findup('serverless.json', {
cwd: getCwd(),
nocase: true,
});

if (ancestorFunctionsDir) {
if (ancestorFunctionsConfig) {
logger.error(
`Cannot create a functions directory inside "${ancestorFunctionsDir}"`
`Cannot create a functions directory inside "${path.dirname(
ancestorFunctionsConfig
)}"`
);
return;
}
Expand Down

0 comments on commit f32da53

Please sign in to comment.