Skip to content

Dashes in folder names cause initialization crash #280

@gscottschulz

Description

@gscottschulz

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions