Sin descripción
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.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 = [];
  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. };
  27. function getHumanFriendlyRuntimeName(runtime) {
  28. return MESSAGE_FRIENDLY_RUNTIMES[runtime] || runtime;
  29. }
  30. exports.getHumanFriendlyRuntimeName = getHumanFriendlyRuntimeName;
  31. const factories = [node.tryCreateDelegate];
  32. async function getRuntimeDelegate(context) {
  33. const { projectDir, sourceDir, runtime } = context;
  34. validate.functionsDirectoryExists(sourceDir, projectDir);
  35. if (runtime && !isValidRuntime(runtime)) {
  36. throw new error_1.FirebaseError(`Cannot deploy function with runtime ${runtime}`);
  37. }
  38. for (const factory of factories) {
  39. const delegate = await factory(context);
  40. if (delegate) {
  41. return delegate;
  42. }
  43. }
  44. throw new error_1.FirebaseError(`Could not detect language for functions at ${sourceDir}`);
  45. }
  46. exports.getRuntimeDelegate = getRuntimeDelegate;