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.

index.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getRuntimeDelegate = exports.getHumanFriendlyRuntimeName = exports.isValidRuntime = exports.isDeprecatedRuntime = void 0;
  4. const node = require("./node");
  5. const validate = require("../validate");
  6. const error_1 = require("../../../error");
  7. const RUNTIMES = ["nodejs10", "nodejs12", "nodejs14", "nodejs16", "nodejs18"];
  8. const EXPERIMENTAL_RUNTIMES = ["go113"];
  9. const DEPRECATED_RUNTIMES = ["nodejs6", "nodejs8"];
  10. function isDeprecatedRuntime(runtime) {
  11. return DEPRECATED_RUNTIMES.includes(runtime);
  12. }
  13. exports.isDeprecatedRuntime = isDeprecatedRuntime;
  14. function isValidRuntime(runtime) {
  15. return RUNTIMES.includes(runtime) || EXPERIMENTAL_RUNTIMES.includes(runtime);
  16. }
  17. exports.isValidRuntime = isValidRuntime;
  18. const MESSAGE_FRIENDLY_RUNTIMES = {
  19. nodejs6: "Node.js 6 (Deprecated)",
  20. nodejs8: "Node.js 8 (Deprecated)",
  21. nodejs10: "Node.js 10",
  22. nodejs12: "Node.js 12",
  23. nodejs14: "Node.js 14",
  24. nodejs16: "Node.js 16",
  25. nodejs18: "Node.js 18",
  26. go113: "Go 1.13",
  27. };
  28. function getHumanFriendlyRuntimeName(runtime) {
  29. return MESSAGE_FRIENDLY_RUNTIMES[runtime] || runtime;
  30. }
  31. exports.getHumanFriendlyRuntimeName = getHumanFriendlyRuntimeName;
  32. const factories = [node.tryCreateDelegate];
  33. async function getRuntimeDelegate(context) {
  34. const { projectDir, sourceDir, runtime } = context;
  35. validate.functionsDirectoryExists(sourceDir, projectDir);
  36. if (runtime && !isValidRuntime(runtime)) {
  37. throw new error_1.FirebaseError(`Cannot deploy function with runtime ${runtime}`);
  38. }
  39. for (const factory of factories) {
  40. const delegate = await factory(context);
  41. if (delegate) {
  42. return delegate;
  43. }
  44. }
  45. throw new error_1.FirebaseError(`Could not detect language for functions at ${sourceDir}`);
  46. }
  47. exports.getRuntimeDelegate = getRuntimeDelegate;