No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

triggerParser.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var url = require("url");
  3. var extractTriggers = require("./extractTriggers");
  4. var EXIT = function () {
  5. process.exit(0);
  6. };
  7. const dynamicImport = new Function("modulePath", "return import(modulePath)");
  8. async function loadModule(packageDir) {
  9. try {
  10. return require(packageDir);
  11. }
  12. catch (e) {
  13. if (e.code === "ERR_REQUIRE_ESM") {
  14. const modulePath = require.resolve(packageDir);
  15. const moduleURL = url.pathToFileURL(modulePath).href;
  16. return await dynamicImport(moduleURL);
  17. }
  18. throw e;
  19. }
  20. }
  21. (async function () {
  22. if (!process.send) {
  23. console.warn("Could not parse function triggers (process.send === undefined).");
  24. process.exit(1);
  25. }
  26. var packageDir = process.argv[2];
  27. if (!packageDir) {
  28. process.send({ error: "Must supply package directory for functions trigger parsing." }, EXIT);
  29. return;
  30. }
  31. var mod;
  32. var triggers = [];
  33. try {
  34. mod = await loadModule(packageDir);
  35. }
  36. catch (e) {
  37. if (e.code === "MODULE_NOT_FOUND") {
  38. process.send({
  39. error: "Error parsing triggers: " +
  40. e.message +
  41. '\n\nTry running "npm install" in your functions directory before deploying.',
  42. }, EXIT);
  43. return;
  44. }
  45. if (/Firebase config variables are not available/.test(e.message)) {
  46. process.send({
  47. error: "Error occurred while parsing your function triggers. " +
  48. 'Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.\n\n' +
  49. e.stack,
  50. }, EXIT);
  51. return;
  52. }
  53. process.send({
  54. error: "Error occurred while parsing your function triggers.\n\n" + e.stack,
  55. }, EXIT);
  56. return;
  57. }
  58. try {
  59. extractTriggers(mod, triggers);
  60. }
  61. catch (err) {
  62. if (/Maximum call stack size exceeded/.test(err.message)) {
  63. process.send({
  64. error: "Error occurred while parsing your function triggers. Please ensure that index.js only " +
  65. "exports cloud functions.\n\n",
  66. }, EXIT);
  67. return;
  68. }
  69. process.send({ error: err.message }, EXIT);
  70. }
  71. process.send({ triggers: triggers }, EXIT);
  72. })();