Open LeadDreamer opened 4 years ago
Runs successfully in emulation; have yet to deploy properly. Mis-read logs ealier.
Deploy successful. Issue was unrelated (exact format of firebase-admin initializeApp - I use a centralized wrapper module for all firebase operations). Pull request valid.
This is the only PR which I havent been able to merge yet. Please check if this change still applies to the latest version.
So: I ended up converting to JS, since this was the only TS portion of my codebase. BUT I also both simplified it, and detected if the actual filename was "index.{wev}" - tossing that part if it was. I also did NOT reassemble with {sep} only to split it and rejoin it again later. If you never use "index.js" under a named directory, then my addition is not relevant. So I ended up:
function funcNameFromRelPathDefault(relPath) {
if (!relPath) return ""; //short circuit
let relPathArray = relPath.split(sep); /* ? */
//check the last element for "index", and remove it if it is
let filename = relPathArray.pop().toLowerCase().split(".").shift();
if (filename === "index") {
filename = relPathArray.pop().toLowerCase().split(".").shift();
}
relPathArray.push(filename);
//camelcase all the elements, and join with "-"
const funcName = relPathArray.map((element) => camelCase(element)).join("-");
return funcName;
}
This still appears to be an issue for me using the latest release. Here's what I need to do in order to get it working:
const { exportFunctions } = require('better-firebase-functions')
const camelCase = require('camelcase')
const { sep } = require('path')
exportFunctions({
__filename,
exports,
funcNameFromRelPath: relPath => {
const relPathArray = relPath.split(sep)
const fileName = relPathArray.pop()
const relDirPathFunctionNameChunk = relPathArray
.map(pathFragment => camelCase(pathFragment))
.join(sep)
const fileNameFunctionNameChunk = camelCase((fileName || '').split('.')[0])
const funcName = relDirPathFunctionNameChunk
? `${relDirPathFunctionNameChunk}${sep}${fileNameFunctionNameChunk}`
: fileNameFunctionNameChunk
return funcName.split(sep).join('-')
}
})
Without that, I receive the following error:
... function name(s) can only contain letters, numbers, hyphens, and not exceed 62 characters in length
One issue, one style; both resolved by simplifying code: Issue: the last replace, because it was a value not a regex, only replaced the first instance
Style: the string was already split; why .join(sep) only to .replace(`/${sep}/g, "-") later?
SO: split, then join("-"), then no need to replace.
Ran what tests I could (apparently don't have the full sample/test environment), but also tested "in the field" (emulator and deploy).