Skip to content

Commit

Permalink
fix(default): use eval() in require call for webpack compatibility
Browse files Browse the repository at this point in the history
Also updated the deprecation message. Although this function is depracated, we decided to continue
to support and fix a critical bug in the default export
  • Loading branch information
george43g committed May 5, 2020
1 parent a668570 commit a52dd37
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const funcNameFromRelPath = (relpath: string): string => {
};

/**
* @deprecated as of version 3.1.2 - use exportFunctions() instead
*
* This function will search the given directory using provided glob matching pattern and
* export firebase cloud functions for you automatically, without you having to require
* each file individually. It also applies speed optimisations for cold-start.
Expand All @@ -40,6 +38,9 @@ const funcNameFromRelPath = (relpath: string): string => {
*
* @example import exportCloudFunctions from 'better-firebase-functions'
* exportCloudFunctions(__dirname, __filename, exports, './', GLOB_PATTERN);
*
* @deprecated as of version 3.1.2 - use exportFunctions() named export instead,
* `import { exportFunctions } from 'better-firebase-functions'`
*/
export default function (__dirname: string, __filename: string, exports: any, dir?: string, globPattern?: string) {
// eslint-disable-next-line no-console
Expand All @@ -56,8 +57,8 @@ export default function (__dirname: string, __filename: string, exports: any, di
const funcName = funcNameFromRelPath(relPath); /* ? */
const propPath = funcName.replace(/-/g, '.'); /* ? */
if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === funcName) {
// eslint-disable-next-line import/no-dynamic-require, global-require
const module = require(resolve(__dirname, funcDir, relPath));
// eslint-disable-next-line import/no-dynamic-require, global-require, no-eval
const module = eval('require')(resolve(__dirname, funcDir, relPath));
if (!module.default) continue;
set(exports, propPath, module.default);
}
Expand Down

0 comments on commit a52dd37

Please sign in to comment.