firebase-backend icon indicating copy to clipboard operation
firebase-backend copied to clipboard

Dashes in folder names cause initialization crash

Open gscottschulz opened this issue 2 years ago • 1 comments

Describe the bug If you name a folder with dashes in it, the dash is converted to a dot (.) by the FunctionParser class. This was while testing a reactive function not a restful endpoint.

To Reproduce Bad structure: Screenshot 2023-04-13 at 1 37 50 PM

Good Structure: Screenshot 2023-04-13 at 1 36 09 PM

In order to see the difference in the generated exports, I modified my index.ts file. If you run the firebase emulator and do something to invoke a reactive function, you'll see the difference. Make one function's folder have a dash in the name and another without to compare logs.

// index.ts

import * as admin from 'firebase-admin';
import { FunctionParser } from 'firebase-backend';

admin.initializeApp();

const exportsTmp = new FunctionParser({
  rootPath: __dirname,
  exports: exports,
  verbose: true,
}).exports;

console.log('exportsTmp', exportsTmp);

exports = exportsTmp;

const backendVersion = 'v1';
const separator = '_';

for (const key in exports) {
  if (Object.prototype.hasOwnProperty.call(exports, key)) {
    const newKey = `${backendVersion}${separator}${key}`;
    console.log('key', key);
    console.log('newKey', newKey);
    exports[newKey] = exports[key];
    delete exports[key];
  }
}

Expected behavior Dashes should be converted to camel-case.

Screenshots See above.

Additional context Keep it up @FilledStacks!

gscottschulz avatar Apr 13 '23 17:04 gscottschulz

Thanks for filing the issue.

I don't know if we should support a structure we don't want to promote. Js uses camel case so I don't think it's important to supply conversions from kebab case. If you want to do it you can submit a PR, I'll happily include it. But it's not something that I'll be adding.

FilledStacks avatar Apr 17 '23 12:04 FilledStacks