firebase-tools 11.21.0 → 11.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/lib/commands/ext-configure.js +3 -3
  2. package/lib/commands/ext-dev-init.js +16 -4
  3. package/lib/commands/ext-dev-publish.js +3 -3
  4. package/lib/commands/ext-dev-register.js +2 -2
  5. package/lib/commands/ext-info.js +3 -3
  6. package/lib/commands/ext-install.js +2 -2
  7. package/lib/commands/ext-uninstall.js +2 -2
  8. package/lib/commands/ext-update.js +2 -2
  9. package/lib/commands/hosting-channel-create.js +2 -2
  10. package/lib/commands/hosting-channel-delete.js +2 -2
  11. package/lib/commands/hosting-channel-deploy.js +2 -2
  12. package/lib/commands/hosting-clone.js +2 -2
  13. package/lib/deploy/functions/release/fabricator.js +3 -0
  14. package/lib/deploy/functions/runtimes/discovery/index.js +1 -1
  15. package/lib/deploy/functions/runtimes/index.js +5 -2
  16. package/lib/deploy/functions/runtimes/node/index.js +70 -27
  17. package/lib/deploy/functions/runtimes/node/versioning.js +4 -2
  18. package/lib/deploy/functions/runtimes/python/index.js +132 -0
  19. package/lib/deploy/hosting/convertConfig.js +2 -1
  20. package/lib/emulator/auth/apiSpec.js +21 -1
  21. package/lib/emulator/controller.js +5 -5
  22. package/lib/emulator/downloadableEmulators.js +6 -6
  23. package/lib/emulator/extensionsEmulator.js +3 -2
  24. package/lib/emulator/functionsEmulator.js +119 -87
  25. package/lib/emulator/functionsEmulatorRuntime.js +26 -42
  26. package/lib/emulator/functionsRuntimeWorker.js +51 -35
  27. package/lib/emulator/hub.js +6 -6
  28. package/lib/emulator/pubsubEmulator.js +12 -9
  29. package/lib/emulator/storage/apis/shared.js +2 -1
  30. package/lib/emulator/storage/cloudFunctions.js +1 -1
  31. package/lib/emulator/storage/files.js +18 -11
  32. package/lib/emulator/types.js +9 -9
  33. package/lib/extensions/askUserForConsent.js +4 -4
  34. package/lib/extensions/askUserForEventsConfig.js +2 -2
  35. package/lib/extensions/askUserForParam.js +34 -3
  36. package/lib/extensions/billingMigrationHelper.js +4 -4
  37. package/lib/extensions/change-log.js +4 -4
  38. package/lib/extensions/displayExtensionInfo.js +4 -4
  39. package/lib/extensions/emulator/optionsHelper.js +3 -3
  40. package/lib/extensions/emulator/specHelper.js +17 -16
  41. package/lib/extensions/extensionsApi.js +2 -2
  42. package/lib/extensions/extensionsHelper.js +6 -6
  43. package/lib/extensions/provisioningHelper.js +2 -2
  44. package/lib/extensions/updateHelper.js +2 -2
  45. package/lib/extensions/warnings.js +5 -5
  46. package/lib/firestore/checkDatabaseType.js +3 -3
  47. package/lib/frameworks/angular/index.js +6 -4
  48. package/lib/frameworks/index.js +47 -11
  49. package/lib/frameworks/lit/index.js +5 -1
  50. package/lib/frameworks/next/index.js +48 -20
  51. package/lib/frameworks/next/utils.js +1 -1
  52. package/lib/frameworks/nuxt/index.js +18 -26
  53. package/lib/frameworks/nuxt/interfaces.js +2 -0
  54. package/lib/frameworks/nuxt/utils.js +13 -0
  55. package/lib/frameworks/nuxt2/index.js +91 -0
  56. package/lib/frameworks/preact/index.js +5 -1
  57. package/lib/frameworks/react/index.js +5 -1
  58. package/lib/frameworks/svelte/index.js +5 -1
  59. package/lib/frameworks/vite/index.js +6 -4
  60. package/lib/functions/python.js +16 -0
  61. package/lib/gcp/cloudfunctionsv2.js +8 -0
  62. package/lib/getDefaultHostingSite.js +3 -1
  63. package/lib/init/features/firestore/index.js +1 -3
  64. package/lib/init/features/functions/index.js +10 -0
  65. package/lib/init/features/functions/python.js +48 -0
  66. package/lib/init/features/hosting/index.js +3 -2
  67. package/lib/projectUtils.js +2 -2
  68. package/lib/rc.js +4 -4
  69. package/lib/serve/functions.js +1 -3
  70. package/npm-shrinkwrap.json +1295 -276
  71. package/package.json +2 -2
  72. package/templates/extensions/extension.yaml +1 -1
  73. package/templates/extensions/integration-test.env +2 -0
  74. package/templates/extensions/integration-test.json +14 -0
  75. package/templates/extensions/javascript/WELCOME.md +14 -5
  76. package/templates/extensions/javascript/index.js +10 -10
  77. package/templates/extensions/javascript/integration-test.js +13 -0
  78. package/templates/extensions/javascript/package.lint.json +12 -4
  79. package/templates/extensions/javascript/package.nolint.json +11 -2
  80. package/templates/extensions/typescript/WELCOME.md +18 -5
  81. package/templates/extensions/typescript/_mocharc +10 -0
  82. package/templates/extensions/typescript/index.ts +16 -15
  83. package/templates/extensions/typescript/integration-test.ts +13 -0
  84. package/templates/extensions/typescript/package.lint.json +16 -4
  85. package/templates/extensions/typescript/package.nolint.json +12 -4
  86. package/templates/init/functions/javascript/_eslintrc +16 -2
  87. package/templates/init/functions/javascript/package.lint.json +4 -4
  88. package/templates/init/functions/javascript/package.nolint.json +3 -3
  89. package/templates/init/functions/python/_gitignore +0 -0
  90. package/templates/init/functions/python/main.py +13 -0
  91. package/templates/init/functions/python/requirements.txt +1 -0
  92. package/templates/init/functions/typescript/_eslintrc +1 -0
  93. package/templates/init/functions/typescript/package.lint.json +4 -4
  94. package/templates/init/functions/typescript/package.nolint.json +4 -3
@@ -10,30 +10,34 @@ const utils_1 = require("../utils");
10
10
  exports.name = "Nuxt";
11
11
  exports.support = "experimental";
12
12
  exports.type = 4;
13
+ const utils_2 = require("./utils");
13
14
  const DEFAULT_BUILD_SCRIPT = ["nuxt build"];
14
15
  async function discover(dir) {
15
16
  if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
16
17
  return;
17
- const nuxtDependency = (0, __1.findDependency)("nuxt", { cwd: dir, depth: 0, omitDev: false });
18
- const configFilesExist = await Promise.all([
19
- (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.js")),
20
- (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.ts")),
21
- ]);
22
- const anyConfigFileExists = configFilesExist.some((it) => it);
18
+ const nuxtDependency = (0, __1.findDependency)("nuxt", {
19
+ cwd: dir,
20
+ depth: 0,
21
+ omitDev: false,
22
+ });
23
+ const version = nuxtDependency === null || nuxtDependency === void 0 ? void 0 : nuxtDependency.version;
24
+ const anyConfigFileExists = await (0, utils_2.nuxtConfigFilesExist)(dir);
23
25
  if (!anyConfigFileExists && !nuxtDependency)
24
26
  return;
25
- return { mayWantBackend: true };
27
+ if (version && (0, semver_1.gte)(version, "3.0.0-0"))
28
+ return { mayWantBackend: true };
29
+ return;
26
30
  }
27
31
  exports.discover = discover;
28
32
  async function build(root) {
29
33
  const { buildNuxt } = await (0, __1.relativeRequire)(root, "@nuxt/kit");
30
- const nuxtApp = await getNuxtApp(root);
34
+ const nuxtApp = await getNuxt3App(root);
31
35
  await (0, utils_1.warnIfCustomBuildScript)(root, exports.name, DEFAULT_BUILD_SCRIPT);
32
36
  await buildNuxt(nuxtApp);
33
37
  return { wantsBackend: true };
34
38
  }
35
39
  exports.build = build;
36
- async function getNuxtApp(cwd) {
40
+ async function getNuxt3App(cwd) {
37
41
  const { loadNuxt } = await (0, __1.relativeRequire)(cwd, "@nuxt/kit");
38
42
  return await loadNuxt({
39
43
  cwd,
@@ -42,29 +46,17 @@ async function getNuxtApp(cwd) {
42
46
  },
43
47
  });
44
48
  }
45
- function isNuxt3(cwd) {
46
- const { version } = (0, __1.findDependency)("nuxt", { cwd, depth: 0, omitDev: false });
47
- return (0, semver_1.gte)(version, "3.0.0-0");
48
- }
49
49
  async function ɵcodegenPublicDirectory(root, dest) {
50
- const app = await getNuxtApp(root);
51
- const distPath = isNuxt3(root) ? (0, path_1.join)(root, ".output", "public") : app.options.generate.dir;
50
+ const distPath = (0, path_1.join)(root, ".output", "public");
52
51
  await (0, fs_extra_1.copy)(distPath, dest);
53
52
  }
54
53
  exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
55
54
  async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
56
55
  const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
57
56
  const packageJson = JSON.parse(packageJsonBuffer.toString());
58
- if (isNuxt3(sourceDir)) {
59
- const outputPackageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, ".output", "server", "package.json"));
60
- const outputPackageJson = JSON.parse(outputPackageJsonBuffer.toString());
61
- await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".output", "server"), destDir);
62
- return { packageJson: Object.assign(Object.assign({}, packageJson), outputPackageJson), frameworksEntry: "nuxt3" };
63
- }
64
- else {
65
- const { options: { buildDir }, } = await getNuxtApp(sourceDir);
66
- await (0, fs_extra_1.copy)(buildDir, (0, path_1.join)(destDir, (0, path_1.basename)(buildDir)));
67
- return { packageJson };
68
- }
57
+ const outputPackageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, ".output", "server", "package.json"));
58
+ const outputPackageJson = JSON.parse(outputPackageJsonBuffer.toString());
59
+ await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".output", "server"), destDir);
60
+ return { packageJson: Object.assign(Object.assign({}, packageJson), outputPackageJson), frameworksEntry: "nuxt3" };
69
61
  }
70
62
  exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nuxtConfigFilesExist = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const path_1 = require("path");
6
+ async function nuxtConfigFilesExist(dir) {
7
+ const configFilesExist = await Promise.all([
8
+ (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.js")),
9
+ (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "nuxt.config.ts")),
10
+ ]);
11
+ return configFilesExist.some((it) => it);
12
+ }
13
+ exports.nuxtConfigFilesExist = nuxtConfigFilesExist;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ɵcodegenFunctionsDirectory = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.type = exports.support = exports.name = void 0;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const promises_1 = require("fs/promises");
6
+ const path_1 = require("path");
7
+ const semver_1 = require("semver");
8
+ const __1 = require("..");
9
+ const utils_1 = require("../nuxt/utils");
10
+ exports.name = "Nuxt";
11
+ exports.support = "experimental";
12
+ exports.type = 2;
13
+ async function discover(dir) {
14
+ if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "package.json"))))
15
+ return;
16
+ const nuxtDependency = (0, __1.findDependency)("nuxt", {
17
+ cwd: dir,
18
+ depth: 0,
19
+ omitDev: false,
20
+ });
21
+ const version = nuxtDependency === null || nuxtDependency === void 0 ? void 0 : nuxtDependency.version;
22
+ const anyConfigFileExists = await (0, utils_1.nuxtConfigFilesExist)(dir);
23
+ if (!anyConfigFileExists && !nuxtDependency)
24
+ return;
25
+ if (version && (0, semver_1.lt)(version, "3.0.0-0"))
26
+ return { mayWantBackend: true };
27
+ return;
28
+ }
29
+ exports.discover = discover;
30
+ async function getNuxtApp(cwd) {
31
+ return await (0, __1.relativeRequire)(cwd, "nuxt/dist/nuxt.js");
32
+ }
33
+ async function build(root) {
34
+ const nuxt = await getNuxtApp(root);
35
+ const nuxtApp = await nuxt.loadNuxt({
36
+ for: "build",
37
+ rootDir: root,
38
+ });
39
+ const { options: { ssr, target }, } = await nuxt.build(nuxtApp);
40
+ if (ssr === true && target === "server") {
41
+ return { wantsBackend: true };
42
+ }
43
+ else {
44
+ if (ssr === false && target === "static") {
45
+ console.log("Firebase: Nuxt 2: Static target is not supported with `ssr: false`. Please use `target: 'server'` in your `nuxt.config.js` file.");
46
+ console.log("Firebase: Nuxt 2: Bundling only for client side.\n");
47
+ }
48
+ await buildAndGenerate(nuxt, root);
49
+ return { wantsBackend: false };
50
+ }
51
+ }
52
+ exports.build = build;
53
+ async function buildAndGenerate(nuxt, root) {
54
+ const nuxtApp = await nuxt.loadNuxt({
55
+ for: "start",
56
+ rootDir: root,
57
+ });
58
+ const builder = await nuxt.getBuilder(nuxtApp);
59
+ const generator = new nuxt.Generator(nuxtApp, builder);
60
+ await generator.generate({ build: false, init: true });
61
+ }
62
+ async function ɵcodegenPublicDirectory(root, dest) {
63
+ var _a, _b;
64
+ const nuxt = await getNuxtApp(root);
65
+ const nuxtConfig = await nuxt.loadNuxtConfig();
66
+ const { ssr, target } = nuxtConfig;
67
+ if (!(ssr === true && target === "server")) {
68
+ const source = ((_a = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _a === void 0 ? void 0 : _a.dir) !== undefined
69
+ ? (0, path_1.join)(root, (_b = nuxtConfig === null || nuxtConfig === void 0 ? void 0 : nuxtConfig.generate) === null || _b === void 0 ? void 0 : _b.dir)
70
+ : (0, path_1.join)(root, "dist");
71
+ await (0, fs_extra_1.copy)(source, dest);
72
+ }
73
+ const staticPath = (0, path_1.join)(root, "static");
74
+ if (await (0, fs_extra_1.pathExists)(staticPath)) {
75
+ await (0, fs_extra_1.copy)(staticPath, dest);
76
+ }
77
+ }
78
+ exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
79
+ async function ɵcodegenFunctionsDirectory(sourceDir, destDir) {
80
+ const packageJsonBuffer = await (0, promises_1.readFile)((0, path_1.join)(sourceDir, "package.json"));
81
+ const packageJson = JSON.parse(packageJsonBuffer.toString());
82
+ const nuxt = await getNuxtApp(sourceDir);
83
+ const nuxtConfig = await nuxt.loadNuxtConfig();
84
+ await (0, fs_extra_1.copy)((0, path_1.join)(sourceDir, ".nuxt"), (0, path_1.join)(destDir, ".nuxt"));
85
+ if (!nuxtConfig.ssr) {
86
+ const nuxtConfigFile = nuxtConfig._nuxtConfigFile.split("/").pop();
87
+ await (0, fs_extra_1.copy)(nuxtConfig._nuxtConfigFile, (0, path_1.join)(destDir, nuxtConfigFile));
88
+ }
89
+ return { packageJson: Object.assign({}, packageJson), frameworksEntry: "nuxt" };
90
+ }
91
+ exports.ɵcodegenFunctionsDirectory = ɵcodegenFunctionsDirectory;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDevModeHandle = exports.ɵcodegenPublicDirectory = exports.build = exports.discover = exports.vitePluginDiscover = exports.viteDiscoverWithNpmDependency = exports.init = exports.initViteTemplate = exports.DEFAULT_BUILD_SCRIPT = exports.type = exports.support = exports.name = void 0;
4
4
  const child_process_1 = require("child_process");
5
+ const cross_spawn_1 = require("cross-spawn");
5
6
  const fs_1 = require("fs");
6
7
  const fs_extra_1 = require("fs-extra");
7
8
  const path_1 = require("path");
@@ -14,9 +15,9 @@ exports.support = "experimental";
14
15
  exports.type = 4;
15
16
  const CLI_COMMAND = (0, path_1.join)("node_modules", ".bin", process.platform === "win32" ? "vite.cmd" : "vite");
16
17
  exports.DEFAULT_BUILD_SCRIPT = ["vite build", "tsc && vite build"];
17
- const initViteTemplate = (template) => async (setup) => await init(setup, template);
18
+ const initViteTemplate = (template) => async (setup, config) => await init(setup, config, template);
18
19
  exports.initViteTemplate = initViteTemplate;
19
- async function init(setup, baseTemplate = "vanilla") {
20
+ async function init(setup, config, baseTemplate = "vanilla") {
20
21
  const template = await (0, prompt_1.promptOnce)({
21
22
  type: "list",
22
23
  default: "JavaScript",
@@ -28,8 +29,9 @@ async function init(setup, baseTemplate = "vanilla") {
28
29
  });
29
30
  (0, child_process_1.execSync)(`npm create vite@latest ${setup.hosting.source} --yes -- --template ${template}`, {
30
31
  stdio: "inherit",
32
+ cwd: config.projectDir,
31
33
  });
32
- (0, child_process_1.execSync)(`npm install`, { stdio: "inherit", cwd: setup.hosting.source });
34
+ (0, child_process_1.execSync)(`npm install`, { stdio: "inherit", cwd: (0, path_1.join)(config.projectDir, setup.hosting.source) });
33
35
  }
34
36
  exports.init = init;
35
37
  const viteDiscoverWithNpmDependency = (dep) => async (dir) => await discover(dir, undefined, dep);
@@ -70,7 +72,7 @@ async function ɵcodegenPublicDirectory(root, dest) {
70
72
  exports.ɵcodegenPublicDirectory = ɵcodegenPublicDirectory;
71
73
  async function getDevModeHandle(dir) {
72
74
  const host = new Promise((resolve) => {
73
- const serve = (0, child_process_1.spawn)(CLI_COMMAND, [], { cwd: dir });
75
+ const serve = (0, cross_spawn_1.spawn)(CLI_COMMAND, [], { cwd: dir });
74
76
  serve.stdout.on("data", (data) => {
75
77
  process.stdout.write(data);
76
78
  const match = data.toString().match(/(http:\/\/.+:\d+)/);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWithVirtualEnv = void 0;
4
+ const path = require("path");
5
+ const spawn = require("cross-spawn");
6
+ const logger_1 = require("../logger");
7
+ const DEFAULT_VENV_DIR = "venv";
8
+ function runWithVirtualEnv(commandAndArgs, cwd, envs, spawnOpts = {}, venvDir = DEFAULT_VENV_DIR) {
9
+ const activateScriptPath = process.platform === "win32" ? ["Scripts", "activate.bat"] : ["bin", "activate"];
10
+ const venvActivate = path.join(cwd, venvDir, ...activateScriptPath);
11
+ const command = process.platform === "win32" ? venvActivate : "source";
12
+ const args = [process.platform === "win32" ? "" : venvActivate, "&&", ...commandAndArgs];
13
+ logger_1.logger.debug(`Running command with virtualenv: command=${command}, args=${JSON.stringify(args)}`);
14
+ return spawn(command, args, Object.assign(Object.assign({ shell: true, cwd, stdio: ["pipe", "pipe", "pipe", "pipe"] }, spawnOpts), { env: envs }));
15
+ }
16
+ exports.runWithVirtualEnv = runWithVirtualEnv;
@@ -342,6 +342,14 @@ function endpointFromFunction(gcfFunction) {
342
342
  if ((_f = gcfFunction.labels) === null || _f === void 0 ? void 0 : _f[constants_1.HASH_LABEL]) {
343
343
  endpoint.hash = gcfFunction.labels[constants_1.HASH_LABEL];
344
344
  }
345
+ const serviceName = gcfFunction.serviceConfig.service;
346
+ if (!serviceName) {
347
+ logger_1.logger.debug("Got a v2 function without a service name." +
348
+ "Maybe we've migrated to using the v2 API everywhere and missed this code");
349
+ }
350
+ else {
351
+ endpoint.runServiceId = utils.last(serviceName.split("/"));
352
+ }
345
353
  return endpoint;
346
354
  }
347
355
  exports.endpointFromFunction = endpointFromFunction;
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDefaultHostingSite = void 0;
4
4
  const logger_1 = require("./logger");
5
5
  const projects_1 = require("./management/projects");
6
+ const projectUtils_1 = require("./projectUtils");
6
7
  async function getDefaultHostingSite(options) {
7
8
  var _a;
8
- const project = await (0, projects_1.getFirebaseProject)(options.project);
9
+ const projectId = (0, projectUtils_1.needProjectId)(options);
10
+ const project = await (0, projects_1.getFirebaseProject)(projectId);
9
11
  const site = (_a = project.resources) === null || _a === void 0 ? void 0 : _a.hostingSite;
10
12
  if (!site) {
11
13
  logger_1.logger.debug(`No default hosting site found for project: ${options.project}. Using projectId as hosting site name.`);
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.doSetup = void 0;
4
4
  const logger_1 = require("../../../logger");
5
5
  const apiEnabled = require("../../../ensureApiEnabled");
6
- const ensureCloudResourceLocation_1 = require("../../../ensureCloudResourceLocation");
7
6
  const requirePermissions_1 = require("../../../requirePermissions");
8
7
  const checkDatabaseType_1 = require("../../../firestore/checkDatabaseType");
9
8
  const rules = require("./rules");
@@ -21,10 +20,9 @@ async function checkProjectSetup(setup, config, options) {
21
20
  if (!dbType) {
22
21
  throw firestoreUnusedError;
23
22
  }
24
- else if (dbType !== "CLOUD_FIRESTORE") {
23
+ else if (dbType !== "FIRESTORE_NATIVE") {
25
24
  throw new error_1.FirebaseError(`It looks like this project is using Cloud Datastore or Cloud Firestore in Datastore mode. The Firebase CLI can only manage projects using Cloud Firestore in Native mode. For more information, visit https://cloud.google.com/datastore/docs/firestore-or-datastore`, { exit: 1 });
26
25
  }
27
- (0, ensureCloudResourceLocation_1.ensureLocationSet)(setup.projectLocation, "Cloud Firestore");
28
26
  await (0, requirePermissions_1.requirePermissions)(Object.assign(Object.assign({}, options), { project: setup.projectId }));
29
27
  }
30
28
  async function doSetup(setup, config, options) {
@@ -8,6 +8,7 @@ const requirePermissions_1 = require("../../../requirePermissions");
8
8
  const ensureApiEnabled_1 = require("../../../ensureApiEnabled");
9
9
  const projectConfig_1 = require("../../../functions/projectConfig");
10
10
  const error_1 = require("../../../error");
11
+ const experiments_1 = require("../../../experiments");
11
12
  const MAX_ATTEMPTS = 5;
12
13
  async function doSetup(setup, config, options) {
13
14
  var _a, _b;
@@ -139,6 +140,12 @@ async function languageSetup(setup, config) {
139
140
  value: "typescript",
140
141
  },
141
142
  ];
143
+ if ((0, experiments_1.isEnabled)("pythonfunctions")) {
144
+ choices.push({
145
+ name: "Python",
146
+ value: "python",
147
+ });
148
+ }
142
149
  const language = await (0, prompt_1.promptOnce)({
143
150
  type: "list",
144
151
  message: "What language would you like to use to write Cloud Functions?",
@@ -153,6 +160,9 @@ async function languageSetup(setup, config) {
153
160
  case "typescript":
154
161
  cbconfig.ignore = ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log"];
155
162
  break;
163
+ case "python":
164
+ cbconfig.ignore = ["venv", ".git", "firebase-debug.log", "firebase-debug.*.log"];
165
+ break;
156
166
  }
157
167
  return require("./" + language).setup(setup, config);
158
168
  }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setup = void 0;
4
+ const fs = require("fs");
5
+ const spawn = require("cross-spawn");
6
+ const path = require("path");
7
+ const python_1 = require("../../../deploy/functions/runtimes/python");
8
+ const python_2 = require("../../../functions/python");
9
+ const prompt_1 = require("../../../prompt");
10
+ const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/python");
11
+ const MAIN_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "main.py"), "utf8");
12
+ const REQUIREMENTS_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "requirements.txt"), "utf8");
13
+ const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
14
+ async function setup(setup, config) {
15
+ await config.askWriteProjectFile(`${setup.functions.source}/requirements.txt`, REQUIREMENTS_TEMPLATE);
16
+ await config.askWriteProjectFile(`${setup.functions.source}/.gitignore`, GITIGNORE_TEMPLATE);
17
+ await config.askWriteProjectFile(`${setup.functions.source}/main.py`, MAIN_TEMPLATE);
18
+ config.set("functions.runtime", python_1.LATEST_VERSION);
19
+ config.set("functions.ignore", ["venv", "__pycache__"]);
20
+ const venvProcess = spawn((0, python_1.getPythonBinary)(python_1.LATEST_VERSION), ["-m", "venv", "venv"], {
21
+ shell: true,
22
+ cwd: config.path(setup.functions.source),
23
+ stdio: ["pipe", "pipe", "pipe", "pipe"],
24
+ });
25
+ await new Promise((resolve, reject) => {
26
+ venvProcess.on("exit", resolve);
27
+ venvProcess.on("error", reject);
28
+ });
29
+ const install = await (0, prompt_1.promptOnce)({
30
+ name: "install",
31
+ type: "confirm",
32
+ message: "Do you want to install dependencies now?",
33
+ default: true,
34
+ });
35
+ if (install) {
36
+ const upgradeProcess = (0, python_2.runWithVirtualEnv)(["pip3", "install", "--upgrade", "pip"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
37
+ await new Promise((resolve, reject) => {
38
+ upgradeProcess.on("exit", resolve);
39
+ upgradeProcess.on("error", reject);
40
+ });
41
+ const installProcess = (0, python_2.runWithVirtualEnv)([(0, python_1.getPythonBinary)(python_1.LATEST_VERSION), "-m", "pip", "install", "-r", "requirements.txt"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
42
+ await new Promise((resolve, reject) => {
43
+ installProcess.on("exit", resolve);
44
+ installProcess.on("error", reject);
45
+ });
46
+ }
47
+ }
48
+ exports.setup = setup;
@@ -10,6 +10,7 @@ const prompt_1 = require("../../../prompt");
10
10
  const logger_1 = require("../../../logger");
11
11
  const frameworks_1 = require("../../../frameworks");
12
12
  const experiments = require("../../../experiments");
13
+ const path_1 = require("path");
13
14
  const INDEX_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/index.html", "utf8");
14
15
  const MISSING_TEMPLATE = fs.readFileSync(__dirname + "/../../../../templates/init/hosting/404.html", "utf8");
15
16
  const DEFAULT_IGNORES = ["firebase.json", "**/.*", "**/node_modules/**"];
@@ -51,7 +52,7 @@ async function doSetup(setup, config) {
51
52
  }, setup.hosting);
52
53
  if (setup.hosting.source !== ".")
53
54
  delete setup.hosting.useDiscoveredFramework;
54
- discoveredFramework = await (0, frameworks_1.discover)(setup.hosting.source);
55
+ discoveredFramework = await (0, frameworks_1.discover)((0, path_1.join)(config.projectDir, setup.hosting.source));
55
56
  if (discoveredFramework) {
56
57
  const name = frameworks_1.WebFrameworks[discoveredFramework.framework].name;
57
58
  await (0, prompt_1.promptOnce)({
@@ -83,7 +84,7 @@ async function doSetup(setup, config) {
83
84
  }, setup.hosting);
84
85
  if (discoveredFramework)
85
86
  (0, rimraf_1.sync)(setup.hosting.source);
86
- await frameworks_1.WebFrameworks[setup.hosting.whichFramework].init(setup);
87
+ await frameworks_1.WebFrameworks[setup.hosting.whichFramework].init(setup, config);
87
88
  }
88
89
  setup.config.hosting = {
89
90
  source: setup.hosting.source,
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliases = exports.needProjectNumber = exports.needProjectId = exports.getProjectId = void 0;
4
4
  const projects_1 = require("./management/projects");
5
5
  const clc = require("colorette");
6
- const { marked } = require("marked");
6
+ const marked_1 = require("marked");
7
7
  const { FirebaseError } = require("./error");
8
8
  function getProjectId({ projectId, project, }) {
9
9
  return projectId || project;
@@ -27,7 +27,7 @@ function needProjectId({ projectId, project, rc, }) {
27
27
  "To list all the Firebase projects to which you have access, run " +
28
28
  clc.bold("firebase projects:list") +
29
29
  ".\n" +
30
- marked("To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases"));
30
+ (0, marked_1.marked)("To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases"));
31
31
  }
32
32
  const aliasList = Object.entries(aliases)
33
33
  .map(([aname, projectId]) => ` ${aname} (${projectId})`)
package/lib/rc.js CHANGED
@@ -23,10 +23,6 @@ function loadRC(options) {
23
23
  }
24
24
  exports.loadRC = loadRC;
25
25
  class RC {
26
- constructor(rcpath, data) {
27
- this.path = rcpath;
28
- this.data = Object.assign({ projects: {}, targets: {}, etags: {} }, data);
29
- }
30
26
  static loadFile(rcpath) {
31
27
  let data = {};
32
28
  if (fsutils.fileExistsSync(rcpath)) {
@@ -39,6 +35,10 @@ class RC {
39
35
  }
40
36
  return new RC(rcpath, data);
41
37
  }
38
+ constructor(rcpath, data) {
39
+ this.path = rcpath;
40
+ this.data = Object.assign({ projects: {}, targets: {}, etags: {} }, data);
41
+ }
42
42
  set(key, value) {
43
43
  _.set(this.data, key, value);
44
44
  return;
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FunctionsServer = void 0;
4
4
  const path = require("path");
5
5
  const functionsEmulator_1 = require("../emulator/functionsEmulator");
6
- const functionsEmulatorUtils_1 = require("../emulator/functionsEmulatorUtils");
7
6
  const projectUtils_1 = require("../projectUtils");
8
7
  const auth_1 = require("../auth");
9
8
  const projectConfig = require("../functions/projectConfig");
@@ -22,11 +21,10 @@ class FunctionsServer {
22
21
  const backends = [];
23
22
  for (const cfg of config) {
24
23
  const functionsDir = path.join(options.config.projectDir, cfg.source);
25
- const nodeMajorVersion = (0, functionsEmulatorUtils_1.parseRuntimeVersion)(cfg.runtime);
26
24
  backends.push({
27
25
  functionsDir,
28
26
  codebase: cfg.codebase,
29
- nodeMajorVersion,
27
+ runtime: cfg.runtime,
30
28
  env: {},
31
29
  secretEnv: [],
32
30
  });