firebase-tools 12.4.2 → 12.4.3

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.
@@ -144,8 +144,6 @@ function load(client) {
144
144
  client.internaltesting.frameworks.compose = loadCommand("internaltesting-frameworks-compose");
145
145
  client.internaltesting.functions = {};
146
146
  client.internaltesting.functions.discover = loadCommand("internaltesting-functions-discover");
147
- client.internaltesting.frameworks = {};
148
- client.internaltesting.frameworks.init = loadCommand("internaltesting-frameworks-init");
149
147
  }
150
148
  client.login = loadCommand("login");
151
149
  client.login.add = loadCommand("login-add");
@@ -6,15 +6,17 @@ const logger_1 = require("../logger");
6
6
  const driver_1 = require("../frameworks/compose/driver");
7
7
  const compose_1 = require("../frameworks/compose");
8
8
  const error_1 = require("../error");
9
+ const filesystem_1 = require("../frameworks/compose/discover/filesystem");
10
+ const frameworkSpec_1 = require("../frameworks/compose/discover/frameworkSpec");
9
11
  exports.command = new command_1.Command("internaltesting:frameworks:compose")
10
12
  .option("-m, --mode <mode>", "Composer mode (local or docker)", "local")
11
13
  .description("compose framework in current directory")
12
- .action((options) => {
14
+ .action(async (options) => {
13
15
  const mode = options.mode;
14
16
  if (!driver_1.SUPPORTED_MODES.includes(mode)) {
15
17
  throw new error_1.FirebaseError(`Unsupported mode ${mode}. Supported modes are [${driver_1.SUPPORTED_MODES.join(", ")}]`);
16
18
  }
17
- const bundle = (0, compose_1.compose)(mode);
19
+ const bundle = await (0, compose_1.compose)(mode, new filesystem_1.LocalFileSystem("."), frameworkSpec_1.frameworkSpecs);
18
20
  logger_1.logger.info(JSON.stringify(bundle, null, 2));
19
21
  return {};
20
22
  });
@@ -16,7 +16,7 @@ const LINKS = [
16
16
  { name: "Analytics", arg: "analytics", consolePath: "/analytics" },
17
17
  { name: "Authentication: Providers", arg: "auth", consolePath: "/authentication/providers" },
18
18
  { name: "Authentication: Users", arg: "auth:users", consolePath: "/authentication/users" },
19
- { name: "Crash Reporting", arg: "crash", consolePath: "/monitoring" },
19
+ { name: "Crash Reporting", arg: "crash", consolePath: "/crashlytics" },
20
20
  { name: "Database: Data", arg: "database", consolePath: "/database/data" },
21
21
  { name: "Database: Rules", arg: "database:rules", consolePath: "/database/rules" },
22
22
  { name: "Docs", arg: "docs", url: "https://firebase.google.com/docs" },
@@ -38,7 +38,7 @@ const LINKS = [
38
38
  { name: "Functions", arg: "functions", consolePath: "/functions/list" },
39
39
  { name: "Functions Log", arg: "functions:log" },
40
40
  { name: "Hosting: Deployed Site", arg: "hosting:site" },
41
- { name: "Hosting", arg: "hosting", consolePath: "/hosting/main" },
41
+ { name: "Hosting", arg: "hosting", consolePath: "/hosting/sites" },
42
42
  { name: "Notifications", arg: "notifications", consolePath: "/notification" },
43
43
  { name: "Project Dashboard", arg: "dashboard", consolePath: "/overview" },
44
44
  { name: "Project Settings", arg: "settings", consolePath: "/settings/general" },
@@ -35,9 +35,9 @@ const EMULATOR_UPDATE_DETAILS = {
35
35
  ui: experiments.isEnabled("emulatoruisnapshot")
36
36
  ? { version: "SNAPSHOT", expectedSize: -1, expectedChecksum: "" }
37
37
  : {
38
- version: "1.11.6",
39
- expectedSize: 3063444,
40
- expectedChecksum: "14b971f4ed4909f348e647db7114d62b",
38
+ version: "1.11.7",
39
+ expectedSize: 3064105,
40
+ expectedChecksum: "bd2bcc331cbf613a5b3b55a1ce08998b",
41
41
  },
42
42
  pubsub: {
43
43
  version: "0.7.1",
@@ -4,7 +4,7 @@ exports.readOrNull = exports.LocalFileSystem = void 0;
4
4
  const fs_extra_1 = require("fs-extra");
5
5
  const path = require("path");
6
6
  const error_1 = require("../../../error");
7
- const logger_1 = require("../../../../src/logger");
7
+ const logger_1 = require("../../../logger");
8
8
  class LocalFileSystem {
9
9
  constructor(cwd) {
10
10
  this.cwd = cwd;
@@ -1,23 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.discover = void 0;
4
- function discover() {
5
- return {
6
- baseImage: "us-docker.pkg.dev/firestack-build/test/run:latest",
7
- environmentVariables: {
8
- NODE_ENV: "PRODUCTION",
9
- },
10
- installCommand: "npm install",
11
- buildCommand: "npm run build",
12
- startCommand: "npm run start",
13
- afterInstall: (b) => {
14
- console.log("HOOK: AFTER INSTALL");
15
- return Object.assign(Object.assign({}, b), { version: "v1alpha", notes: "afterInstall" });
16
- },
17
- afterBuild(b) {
18
- console.log("HOOK: AFTER BUILD");
19
- return Object.assign(Object.assign({}, b), { version: "v1alpha", notes: "afterBuild" });
20
- },
21
- };
4
+ const node_1 = require("./runtime/node");
5
+ const error_1 = require("../../../error");
6
+ const supportedRuntimes = [new node_1.NodejsRuntime()];
7
+ async function discover(fs, allFrameworkSpecs) {
8
+ try {
9
+ let discoveredRuntime = undefined;
10
+ for (const runtime of supportedRuntimes) {
11
+ if (await runtime.match(fs)) {
12
+ if (!discoveredRuntime) {
13
+ discoveredRuntime = runtime;
14
+ }
15
+ else {
16
+ throw new error_1.FirebaseError(`Conflit occurred as multiple runtimes ${discoveredRuntime.getRuntimeName()}, ${runtime.getRuntimeName()} are discovered in the application.`);
17
+ }
18
+ }
19
+ }
20
+ if (!discoveredRuntime) {
21
+ throw new error_1.FirebaseError(`Unable to determine the specific runtime for the application. The supported runtime options include ${supportedRuntimes
22
+ .map((x) => x.getRuntimeName())
23
+ .join(" , ")}.`);
24
+ }
25
+ const runtimeSpec = await discoveredRuntime.analyseCodebase(fs, allFrameworkSpecs);
26
+ return runtimeSpec;
27
+ }
28
+ catch (error) {
29
+ throw new error_1.FirebaseError(`Failed to identify required specifications to execute the application: ${error}`);
30
+ }
22
31
  }
23
32
  exports.discover = discover;
@@ -4,7 +4,7 @@ exports.NodejsRuntime = void 0;
4
4
  const filesystem_1 = require("../filesystem");
5
5
  const frameworkMatcher_1 = require("../frameworkMatcher");
6
6
  const error_1 = require("../../../../error");
7
- const logger_1 = require("../../../../../src/logger");
7
+ const logger_1 = require("../../../../logger");
8
8
  const utils_1 = require("../../../utils");
9
9
  const supportedNodeVersions = ["18"];
10
10
  const NODE_RUNTIME_ID = "nodejs";
@@ -13,7 +13,6 @@ const YARN_LOCK = "yarn.lock";
13
13
  class NodejsRuntime {
14
14
  constructor() {
15
15
  this.runtimeRequiredFiles = [PACKAGE_JSON];
16
- this.contentCache = {};
17
16
  }
18
17
  async match(fs) {
19
18
  const areAllFilesPresent = await Promise.all(this.runtimeRequiredFiles.map((file) => fs.exists(file)));
@@ -24,13 +23,13 @@ class NodejsRuntime {
24
23
  }
25
24
  getNodeImage(engine) {
26
25
  if (!engine || !engine.node) {
27
- return `node:${supportedNodeVersions[supportedNodeVersions.length - 1]}-slim`;
26
+ return "us-docker.pkg.dev/firestack-build/test/run";
28
27
  }
29
28
  const versionNumber = engine.node;
30
29
  if (!supportedNodeVersions.includes(versionNumber)) {
31
30
  throw new error_1.FirebaseError(`This integration expects Node version ${(0, utils_1.conjoinOptions)(supportedNodeVersions, "or")}. You're running version ${versionNumber}, which is not compatible.`);
32
31
  }
33
- return `node:${versionNumber}-slim`;
32
+ return "us-docker.pkg.dev/firestack-build/test/run";
34
33
  }
35
34
  async getPackageManager(fs) {
36
35
  try {
@@ -89,7 +89,9 @@ class DockerDriver {
89
89
  this.dockerfileBuilder.from(spec.baseImage, "base").user("firebase");
90
90
  }
91
91
  execDockerPush(args) {
92
- console.log(`executing docker build: ${args.join(" ")}`);
92
+ console.debug(JSON.stringify({ message: `executing docker build: ${args.join(" ")}` }));
93
+ console.info(JSON.stringify({ foo: "bar", message: `executing docker build: ${args.join(" ")}` }));
94
+ console.error(JSON.stringify({ message: `executing docker build: ${args.join(" ")}` }));
93
95
  return spawn.sync("docker", ["push", ...args], {
94
96
  stdio: ["pipe", "inherit", "inherit"],
95
97
  });
@@ -126,20 +128,28 @@ class DockerDriver {
126
128
  return JSON.parse(fs.readFileSync("./.firebase/.output/bundle.json", "utf8"));
127
129
  }
128
130
  install() {
129
- this.dockerfileBuilder
130
- .fromLastStage(DOCKER_STAGE_INSTALL)
131
- .workdir("/home/firebase/app")
132
- .envs(this.spec.environmentVariables || {})
133
- .copyForFirebase("package.json", ".")
134
- .run(this.spec.installCommand);
135
- this.buildStage(DOCKER_STAGE_INSTALL, ".");
131
+ if (this.spec.installCommand) {
132
+ this.dockerfileBuilder
133
+ .fromLastStage(DOCKER_STAGE_INSTALL)
134
+ .workdir("/home/firebase/app")
135
+ .envs(this.spec.environmentVariables || {})
136
+ .copyForFirebase("package.json", ".");
137
+ if (this.spec.packageManagerInstallCommand) {
138
+ this.dockerfileBuilder.run(this.spec.packageManagerInstallCommand);
139
+ }
140
+ this.dockerfileBuilder.run(this.spec.installCommand);
141
+ this.buildStage(DOCKER_STAGE_INSTALL, ".");
142
+ }
136
143
  }
137
144
  build() {
138
- this.dockerfileBuilder
139
- .fromLastStage(DOCKER_STAGE_BUILD)
140
- .copyForFirebase(".", ".")
141
- .run(this.spec.buildCommand);
142
- this.buildStage(DOCKER_STAGE_BUILD, ".");
145
+ var _a;
146
+ if ((_a = this.spec.detectedCommands) === null || _a === void 0 ? void 0 : _a.build) {
147
+ this.dockerfileBuilder
148
+ .fromLastStage(DOCKER_STAGE_BUILD)
149
+ .copyForFirebase(".", ".")
150
+ .run(this.spec.detectedCommands.build.cmd);
151
+ this.buildStage(DOCKER_STAGE_BUILD, ".");
152
+ }
143
153
  }
144
154
  export(bundle) {
145
155
  var _a;
@@ -18,12 +18,21 @@ class LocalDriver {
18
18
  }
19
19
  }
20
20
  install() {
21
- const [cmd, ...args] = this.spec.installCommand.split(" ");
22
- this.execCmd(cmd, args);
21
+ if (this.spec.installCommand) {
22
+ if (this.spec.packageManagerInstallCommand) {
23
+ const [cmd, ...args] = this.spec.packageManagerInstallCommand.split(" ");
24
+ this.execCmd(cmd, args);
25
+ }
26
+ const [cmd, ...args] = this.spec.installCommand.split(" ");
27
+ this.execCmd(cmd, args);
28
+ }
23
29
  }
24
30
  build() {
25
- const [cmd, ...args] = this.spec.buildCommand.split(" ");
26
- this.execCmd(cmd, args);
31
+ var _a;
32
+ if ((_a = this.spec.detectedCommands) === null || _a === void 0 ? void 0 : _a.build) {
33
+ const [cmd, ...args] = this.spec.detectedCommands.build.cmd.split(" ");
34
+ this.execCmd(cmd, args);
35
+ }
27
36
  }
28
37
  export(bundle) {
29
38
  }
@@ -3,24 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compose = void 0;
4
4
  const driver_1 = require("./driver");
5
5
  const discover_1 = require("./discover");
6
- function compose(mode) {
6
+ async function compose(mode, fs, allFrameworkSpecs) {
7
+ var _a, _b, _c, _d;
7
8
  let bundle = { version: "v1alpha" };
8
- const spec = (0, discover_1.discover)();
9
+ const spec = await (0, discover_1.discover)(fs, allFrameworkSpecs);
9
10
  const driver = (0, driver_1.getDriver)(mode, spec);
10
- if (spec.startCommand) {
11
+ if ((_a = spec.detectedCommands) === null || _a === void 0 ? void 0 : _a.run) {
11
12
  bundle.server = {
12
13
  start: {
13
- cmd: spec.startCommand.split(" "),
14
+ cmd: spec.detectedCommands.run.cmd.split(" "),
14
15
  },
15
16
  };
16
17
  }
17
18
  driver.install();
18
- if (spec.afterInstall) {
19
- bundle = driver.execHook(bundle, spec.afterInstall);
19
+ if ((_b = spec.frameworkHooks) === null || _b === void 0 ? void 0 : _b.afterInstall) {
20
+ bundle = driver.execHook(bundle, spec.frameworkHooks.afterInstall);
20
21
  }
21
22
  driver.build();
22
- if (spec.afterBuild) {
23
- bundle = driver.execHook(bundle, spec.afterBuild);
23
+ if ((_c = spec.frameworkHooks) === null || _c === void 0 ? void 0 : _c.afterBuild) {
24
+ bundle = driver.execHook(bundle, (_d = spec.frameworkHooks) === null || _d === void 0 ? void 0 : _d.afterBuild);
24
25
  }
25
26
  if (bundle.server) {
26
27
  driver.export(bundle);
@@ -48,16 +48,25 @@ async function discover(dir) {
48
48
  exports.discover = discover;
49
49
  async function build(dir) {
50
50
  var _a, _b;
51
- const { default: nextBuild } = (0, utils_1.relativeRequire)(dir, "next/dist/build");
52
51
  await (0, utils_1.warnIfCustomBuildScript)(dir, exports.name, DEFAULT_BUILD_SCRIPT);
53
52
  const reactVersion = getReactVersion(dir);
54
53
  if (reactVersion && (0, semver_1.gte)(reactVersion, "18.0.0")) {
55
54
  process.env.__NEXT_REACT_ROOT = "true";
56
55
  }
57
- await nextBuild(dir, null, false, false, true).catch((e) => {
58
- console.error(e.message);
59
- throw e;
56
+ const cli = (0, utils_1.getNodeModuleBin)("next", dir);
57
+ const nextBuild = new Promise((resolve, reject) => {
58
+ var _a, _b;
59
+ const buildProcess = (0, cross_spawn_1.spawn)(cli, ["build"], { cwd: dir });
60
+ (_a = buildProcess.stdout) === null || _a === void 0 ? void 0 : _a.on("data", (data) => logger_1.logger.info(data.toString()));
61
+ (_b = buildProcess.stderr) === null || _b === void 0 ? void 0 : _b.on("data", (data) => logger_1.logger.info(data.toString()));
62
+ buildProcess.on("error", (err) => {
63
+ reject(new error_1.FirebaseError(`Unable to build your Next.js app: ${err}`));
64
+ });
65
+ buildProcess.on("exit", (code) => {
66
+ resolve(code);
67
+ });
60
68
  });
69
+ await nextBuild;
61
70
  const reasonsForBackend = new Set();
62
71
  const { distDir, trailingSlash, basePath: baseUrl } = await getConfig(dir);
63
72
  if (await (0, utils_2.isUsingMiddleware)((0, path_1.join)(dir, distDir), false)) {
@@ -3,19 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createBuild = exports.createStack = exports.API_VERSION = void 0;
4
4
  const apiv2_1 = require("../apiv2");
5
5
  const api_1 = require("../api");
6
- exports.API_VERSION = "v1";
6
+ exports.API_VERSION = "v2";
7
7
  const client = new apiv2_1.Client({
8
8
  urlPrefix: api_1.frameworksOrigin,
9
9
  auth: true,
10
10
  apiVersion: exports.API_VERSION,
11
11
  });
12
- async function createStack(projectId, location, stackId, stack) {
13
- const res = await client.post(`projects/${projectId}/locations/${location}/stacks`, stack, { queryParams: { stackId } });
12
+ async function createStack(projectId, location, stackInput) {
13
+ const stackId = stackInput.name;
14
+ const res = await client.post(`projects/${projectId}/locations/${location}/stacks`, stackInput, { queryParams: { stackId } });
14
15
  return res.body;
15
16
  }
16
17
  exports.createStack = createStack;
17
- async function createBuild(projectId, location, stackId, buildId, build) {
18
- const res = await client.post(`projects/${projectId}/locations/${location}/stacks/${stackId}/builds`, build, { queryParams: { buildId } });
18
+ async function createBuild(projectId, location, stackId, buildInput) {
19
+ const buildId = buildInput.name;
20
+ const res = await client.post(`projects/${projectId}/locations/${location}/stacks/${stackId}/builds`, buildInput, { queryParams: { buildId } });
19
21
  return res.body;
20
22
  }
21
23
  exports.createBuild = createBuild;
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doSetup = void 0;
3
+ exports.createStack = exports.doSetup = void 0;
4
4
  const clc = require("colorette");
5
5
  const utils = require("../../../utils");
6
6
  const logger_1 = require("../../../logger");
7
7
  const prompt_1 = require("../../../prompt");
8
8
  const constants_1 = require("./constants");
9
+ const repo_1 = require("./repo");
10
+ const poller = require("../../../operation-poller");
11
+ const api_1 = require("../../../api");
12
+ const gcp = require("../../../gcp/frameworks");
13
+ const frameworks_1 = require("../../../gcp/frameworks");
14
+ const frameworksPollerOptions = {
15
+ apiOrigin: api_1.frameworksOrigin,
16
+ apiVersion: frameworks_1.API_VERSION,
17
+ masterTimeout: 25 * 60 * 1000,
18
+ maxBackoff: 10000,
19
+ };
9
20
  async function doSetup(setup) {
21
+ var _a, _b;
22
+ const projectId = (_b = (_a = setup === null || setup === void 0 ? void 0 : setup.rcfile) === null || _a === void 0 ? void 0 : _a.projects) === null || _b === void 0 ? void 0 : _b.default;
10
23
  setup.frameworks = {};
11
24
  utils.logBullet("First we need a few details to create your service.");
12
25
  await (0, prompt_1.promptOnce)({
@@ -32,5 +45,22 @@ async function doSetup(setup) {
32
45
  message: "How do you want to deploy",
33
46
  choices: constants_1.ALLOWED_DEPLOY_METHODS,
34
47
  }, setup.frameworks);
48
+ if (setup.frameworks.deployMethod === "github") {
49
+ const cloudBuildConnRepo = await (0, repo_1.linkGitHubRepository)(projectId, setup.frameworks.region, setup.frameworks.serviceName);
50
+ toStack(cloudBuildConnRepo, setup.frameworks.serviceName);
51
+ }
35
52
  }
36
53
  exports.doSetup = doSetup;
54
+ function toStack(cloudBuildConnRepo, stackId) {
55
+ return {
56
+ name: stackId,
57
+ codebase: { repository: cloudBuildConnRepo.name, rootDirectory: "/" },
58
+ labels: {},
59
+ };
60
+ }
61
+ async function createStack(projectId, location, stackInput) {
62
+ const op = await gcp.createStack(projectId, location, stackInput);
63
+ const stack = await poller.pollOperation(Object.assign(Object.assign({}, frameworksPollerOptions), { pollerName: `create-${projectId}-${location}-${stackInput.name}`, operationResourceName: op.name }));
64
+ return stack;
65
+ }
66
+ exports.createStack = createStack;
@@ -21,14 +21,11 @@ function extractRepoSlugFromURI(remoteUri) {
21
21
  }
22
22
  return match[1];
23
23
  }
24
- function generateConnectionId(stackId) {
25
- return `composer-${stackId}-conn`;
26
- }
27
24
  function generateRepositoryId() {
28
25
  return `composer-repo`;
29
26
  }
30
27
  async function linkGitHubRepository(projectId, location, stackId) {
31
- const connectionId = generateConnectionId(stackId);
28
+ const connectionId = stackId;
32
29
  await getOrCreateConnection(projectId, location, connectionId);
33
30
  let remoteUri = await promptRepositoryURI(projectId, location, connectionId);
34
31
  while (remoteUri === "") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "12.4.2",
3
+ "version": "12.4.3",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.command = void 0;
4
- const command_1 = require("../command");
5
- const repo_1 = require("../init/features/composer/repo");
6
- const projectUtils_1 = require("../projectUtils");
7
- const requireInteractive_1 = require("../requireInteractive");
8
- exports.command = new command_1.Command("internaltesting:frameworks:init")
9
- .description("connect github repo to cloud build")
10
- .before(requireInteractive_1.default)
11
- .action(async (options) => {
12
- const projectId = (0, projectUtils_1.needProjectId)(options);
13
- await (0, repo_1.linkGitHubRepository)(projectId, "us-central2", "stack0");
14
- });