{"_id":"@beehiveor/better-firebase-functions","_rev":"3-70236c7bbefdec81061d9a9e0ac37473","name":"@beehiveor/better-firebase-functions","dist-tags":{"latest":"3.4.1-1"},"versions":{"3.4.1-1":{"name":"@beehiveor/better-firebase-functions","version":"3.4.1-1","keywords":["firebase","cloud-functions","efficient","deploy"],"author":{"name":"George G"},"license":"MPL-2.0","_id":"@beehiveor/better-firebase-functions@3.4.1-1","maintainers":[{"name":"beehiveor","email":"rndbeehiveor@gmail.com"}],"homepage":"https://github.com/gramstr/better-firebase-functions#readme","bugs":{"url":"https://github.com/gramstr/better-firebase-functions/issues"},"dist":{"shasum":"026af0cf561c50ec4ecd8d26e57ccf5143c651af","tarball":"https://registry.npmjs.org/@beehiveor/better-firebase-functions/-/better-firebase-functions-3.4.1-1.tgz","fileCount":7,"integrity":"sha512-H6Top/w8drw70rk1SgIBgH7frdp8McZi77JgfMHX0ZQsgoyzgoGOrvZLclrz+lnw8p7Ano4URh9+jRHAqnCINQ==","signatures":[{"sig":"MEQCIGBHXjXQJOtiqkzMx2WyW086UVsTAGN9YE0fqZ7H7cc+AiB+ui3H4tHi+waADXBGhOu9y6p2xvoeBBz78WYZKb5wwg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":85962,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhsOu9CRA9TVsSAnZWagAAdZ8P/3Px2WiJ5zPk5gdBGssV\nTBpSVDCvpWszisC9NlaiHP/ydePVetf6+yio60KiahZaOgW/+ARPnu+8ohFN\n948MrF1lL3kD52D/ai+vy8E+FS7ix4ohTljHY6BWweXe6WpSeoHS+DSGDagh\nUnfYOIwDB1J2bWId6gCiF+UBLbFLkiu5uR93PmMHT7NvJxFDz4rLRZ76w+MH\n/hFtg3uVtw9oWLgFfNlPjJ/AkOd/9dSuQGjB6jcXAYOkGYTrBbLTu7ocvkb1\npFKaG2r97MpVztWLgXURB+JDzevFVgvtHx8kUSiZpbYpmxiD6EB640e3PCTg\nBThbVEBDrDdhKhXjhnP7Zh/RQtRHV9SPbCJYExRRRpbe1gG1OE5M2uVl3sYf\nfKBqX2CLbE6aGfIO45UGIdSr/lmfxlOD66w/gXG0joy4b5d6qjqDmJ17AWNn\n5ekB1+M8UWKkox4yDhbzUkh/LXQFOYEdmGVedO07ZA2YZhn/e9wy0hRdowgu\nKk9WgIRzDWKhyxGBw5Xr7Rx5hoPG3W/RiiG8VgV/e3Po5epO5xY3ksqNfQ93\nKBomo8kqYgoawpAkTpxcPF9HNAcOQ6O9sWK1FWliEy9wApT5zKQbGdPyElqU\nva2F7O6/j+9GO3KawYs1AiY+sqRY97bAHxpe+ewxIcSQYgctZ8yxiwyTzhQd\nk9Uv\r\n=cEYU\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"roots":["<rootDir>/src","<rootDir>/__tests__"],"testMatch":["**/__tests__/**/*.+(ts|tsx|js)","**/?(*.)+(spec|test).+(ts|tsx|js)"],"transform":{"^.+\\.(ts|tsx)$":"ts-jest"}},"main":"lib/index.js","husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"types":"lib/types/index.d.ts","config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"4e29ad30d2afdc9649177d409d589c05fa621506","release":{"branch":"master","plugins":["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/changelog",{"changelogFile":"CHANGELOG.md"}],"@semantic-release/npm",["@semantic-release/git",{"assets":["CHANGELOG.md"]}],"@semantic-release/github"]},"scripts":{"lint":"eslint ./src/**/*.ts --fix","test":"jest --verbose","build":"rm -rf ./lib/  && ncc build src/index.ts -o lib/ -m && tsc -d --declarationDir lib/types --emitDeclarationOnly","prepare":"npm run build","release":"npm run semantic-release","prebuild":"npm run lint","test:watch":"jest --verbose --watchAll","semantic-release":"semantic-release"},"_npmUser":{"name":"beehiveor","email":"rndbeehiveor@gmail.com"},"repository":{"url":"git+https://github.com/gramstr/better-firebase-functions.git","type":"git"},"_npmVersion":"8.1.4","description":"This package exposes a function that improves upon the standard way of bundling functions for Firebase Cloud Functions. It includes the ability to glob-match files that contain a cloud function that are then automatically exported. See README.md for more ","directories":{},"_nodeVersion":"16.13.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"tmp":"^0.2.1","glob":"^7.1.6","jest":"^26.0.1","husky":"^4.2.5","eslint":"^7.2.0","rimraf":"^3.0.2","ts-jest":"^26.1.0","ts-node":"^8.10.2","fs-extra":"^9.0.1","@zeit/ncc":"^0.22.3","camelcase":"^6.0.0","@types/tmp":"^0.2.0","commitizen":"^4.1.2","lodash.set":"^4.3.2","typescript":"^3.9.5","@types/glob":"^7.1.2","@types/jest":"^25.2.3","@types/rimraf":"^3.0.0","@commitlint/cli":"^8.3.5","@types/fs-extra":"^9.0.1","semantic-release":"^17.0.8","@types/lodash.set":"^4.3.6","eslint-plugin-jest":"^23.13.2","eslint-plugin-react":"^7.20.0","eslint-config-airbnb":"^18.1.0","eslint-plugin-import":"^2.20.2","@semantic-release/git":"^9.0.0","@commitlint/travis-cli":"^8.3.5","eslint-plugin-jsx-a11y":"^6.2.3","@typescript-eslint/parser":"^3.1.0","cz-conventional-changelog":"^3.2.0","@semantic-release/changelog":"^5.0.1","@commitlint/config-conventional":"^8.3.4","@typescript-eslint/eslint-plugin":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/better-firebase-functions_3.4.1-1_1638984637381_0.14749072255189644","host":"s3://npm-registry-packages"}}},"time":{"created":"2021-12-08T17:30:37.334Z","modified":"2024-08-10T19:44:34.165Z","3.4.1-1":"2021-12-08T17:30:37.620Z"},"bugs":{"url":"https://github.com/gramstr/better-firebase-functions/issues"},"author":{"name":"George G"},"license":"MPL-2.0","homepage":"https://github.com/gramstr/better-firebase-functions#readme","keywords":["firebase","cloud-functions","efficient","deploy"],"repository":{"url":"git+https://github.com/gramstr/better-firebase-functions.git","type":"git"},"description":"This package exposes a function that improves upon the standard way of bundling functions for Firebase Cloud Functions. It includes the ability to glob-match files that contain a cloud function that are then automatically exported. See README.md for more ","maintainers":[{"email":"rostyslav.db@gmail.com","name":"rostyslavb"},{"email":"rndbeehiveor@gmail.com","name":"beehiver"}],"readme":"> NOTE: This package is built from [github:sdemjanenko/better-firebase-functions/fix_deep_directory_function_name](https://github.com/sdemjanenko/better-firebase-functions/tree/fix_deep_directory_function_name). Main project [github:gramstr/better-firebase-functions](https://github.com/gramstr/better-firebase-functions) and package [better-firebase-functions](https://www.npmjs.com/package/better-firebase-functions) seems abandoned.\r\n\r\n# better-firebase-functions\r\n\r\nThe main feature of this package is a function that provides a better way of automatically exporting function triggers\r\nin Firebase Cloud Functions. This method will almost always improve the performance, memory usage and cold-boot time of\r\nyour cloud functions, especially in large projects. It also allows for a more scalable file structure for your source\r\ncode directory.\r\n\r\nThis package is bundled into one module with 0 dependencies, and is designed to be as lightweight, configurable and\r\nreliable/redundant as possible. Suitable for production use in almost any project. Only one feature is available in this\r\npackage to keep the bundle size as small as possible for performance reasons.\r\n\r\n## Installation\r\n\r\nSimply install from NPM:\r\n\r\n```sh\r\nnpm install better-firebase-functions\r\n```\r\n\r\n1. Ensure your main entry point file contains only:\r\n\r\n```typescript\r\n// src/index.ts\r\nimport { exportFunctions } from 'better-firebase-functions';\r\n\r\nexportFunctions({ __filename, exports });\r\n```\r\n\r\n2. Ensure your function triggers are structured like this:\r\n\r\n```typescript\r\n// src/auth/on-create.ts\r\nimport * as functions from 'firebase-functions';\r\n\r\nexport default functions.auth.user().onCreate(/* Function */);\r\n```\r\n\r\n## exportFunctions()\r\n\r\nThis function has two main features:\r\n\r\n1. Automatically export all function triggers from your index file, without having to manually import each module.\r\n\r\n2. Function triggers are exported in a special way that increases performance and reduces cold-boot time of your cloud\r\n   functions.\r\n\r\n_More info:_\r\n\r\n- Functions are automatically named after their path from the root functions directory.\r\n- Rename a function by renaming a file.\r\n- Automatically create function groups based on directory structure, allowing for `--only functions: groupA` deploys.\r\n\r\nFor JS projects that cant use `export default` syntax, just use equivalent `module.exports.default = ...`.\r\n\r\nThis function scans a directory for modules (_.js files), then exports them automatically. It exports each found\r\nmodule's `default` export (`export default _`or`module.exports.default = \\*`). Each file should contain one function\r\ntrigger and export it as the default export. Almost every default behaviour can be customised by the settings object.\r\n\r\n### exportFunctions() Usage\r\n\r\nIn your main entry point file, simply include these two lines of code:\r\n\r\n```typescript\r\n/// entry point, index.js/ts\r\nimport { exportFunctions } from 'better-firebase-functions';\r\nexportFunctions({ __filename, exports });\r\n```\r\n\r\nThe function will export all found triggers from your index file.\r\n\r\nAnd then in your modules, define your function triggers:\r\n\r\n```ts\r\n/// ./http/new-user.func.ts\r\nimport * as functions from 'firebase-functions'\r\nexport default functions.https.onRequest(app)...\r\n```\r\n\r\nThe above function will automatically be exported as `http-newUser`, because it is in a directory called `http` and is\r\nin a file called `new-user.func.ts`. The dash `http-` denotes that the function is in a submodule group called `http`,\r\nmeaning the functions found in the `http` directory can be exported using `firebase deploy --only functions: http`.\r\n\r\n#### How it Works\r\n\r\nexportFunctions() will search the given directory using provided glob matching pattern and export firebase cloud\r\nfunctions for you automatically, without you having to require each file individually. All matching files will then be\r\nchecked for a default export. The filename and path is used to determine the function name. The function triggers are\r\nnested on the exports object to mirror the folder structure, allowing for deployment groups. You can set the glob\r\npattern to only pick up files that end in _.cf.js or _.function.js Be sure to _still_ use `js` as your file extension\r\nwhen matching if you are using Typescript as this code is executed at runtime once the files are compiled.\r\n\r\n### Settings Object\r\n\r\n#### logger : object, enableLogger: boolean\r\n\r\nYou may specify a custom log function, and enable/disable performance logging.\r\n\r\n#### funcNameFromRelPath : method\r\n\r\nYou may provide a custom function for generating function names based on the file path the module was found. The input\r\nis a string that is the relative path to the module, and the expected output is a string with the name of your function.\r\nSubmodules (module groups) are separated by a dash `-` and the names should be in camelCase. The input filenames should\r\nbe in kebab-case.\r\n\r\n#### functionDirectoryPath : string\r\n\r\nProvide a custom subdirectory to search for function triggers.\r\n\r\n#### searchGlob: string\r\n\r\nThis is a glob pattern that allows you to define which files to search for.\r\n\r\n#### extractTrigger: method\r\n\r\nBy passing this method you can customise how `exportFunctions()` gets the function trigger from the module. The default\r\nbehaviour is to look for the `default` export, but you may specify a different way such as a named export. The function\r\nis given the module object and must return the function trigger.\r\n\r\n#### exportPathMode: boolean\r\n\r\nThis flag will result in the export object holding the relative paths to the detected modules as values for the export\r\nkeys rather than the actual module or function trigger. This option is useful when using this package as part of a build\r\nprocess or for debugging.\r\n\r\n### Other Options\r\n\r\nThe provided typings contain jsdoc comments that should provide intellisense about the various configuration options\r\navailable and how to use them.\r\n\r\n#### If my tests are in the same directory\r\n\r\nAs long as your test files do not provide a default export, they won't be included in the export. Otherwise, you can use\r\nglob patterns to only include certain files (`*.func.js`).\r\n\r\nYou can now also control how the function trigger export is \"found\" from each module file. For example, instead of using\r\na default export, you can opt to use a named export called `export const functionTrigger = functions...`.\r\n\r\n### Warnings\r\n\r\nTry to avoid collisions, where two modules are exported to the same path.\r\n\r\nThis module does its best to convert dashes in files to camelCase and multi-extensions on files `user.function.js` to\r\nvalid names, so as to avoid misnaming a function.\r\n\r\nYou can use the glob pattern to specify which files to target, but be careful: `user.test.js & user.function.js`, if\r\nthey are both included accidentally, will collide with each other as they are both called `user` and the extension is\r\nstripped away (provided they both have a default export)\r\n\r\nIf you need both files, then you can optionally change their names to use camelCase or use a dash `-` (which are also\r\nautomatically converted to camelCase) leaving only the dot in .js.\r\n\r\n#### Node 8\r\n\r\nIf you are using Firebase Functions in Node v8, then the master branch will not work with default settings. The\r\nfuncNameFromRelPath method uses a dependency called `camelCase` which crashes in v8. There is a specific branch for Node\r\nv8 called `node8` that can be installed via `npm install git@github.com:gramstr/better-firebase-functions.git#node8`\r\n\r\n## Contribute\r\n\r\nPlease contribute to this project by submitting a pull request. Use Commitizen to generate correct commit messages.\r\n","readmeFilename":"README.md"}