firebase-tools 14.19.0 → 14.19.1

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.
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.localBuild = void 0;
4
+ const build_1 = require("@apphosting/build");
5
+ async function localBuild(projectRoot, framework) {
6
+ var _a, _b, _c;
7
+ const apphostingBuildOutput = await (0, build_1.localBuild)(projectRoot, framework);
8
+ const annotations = Object.fromEntries(Object.entries(apphostingBuildOutput.metadata).map(([key, value]) => [key, String(value)]));
9
+ const env = (_a = apphostingBuildOutput.runConfig.environmentVariables) === null || _a === void 0 ? void 0 : _a.map(({ variable, value, availability }) => ({
10
+ variable,
11
+ value,
12
+ availability,
13
+ }));
14
+ return {
15
+ outputFiles: (_c = (_b = apphostingBuildOutput.outputFiles) === null || _b === void 0 ? void 0 : _b.serverApp.include) !== null && _c !== void 0 ? _c : [],
16
+ annotations,
17
+ buildConfig: {
18
+ runCommand: apphostingBuildOutput.runConfig.runCommand,
19
+ env: env !== null && env !== void 0 ? env : [],
20
+ },
21
+ };
22
+ }
23
+ exports.localBuild = localBuild;
@@ -18,7 +18,11 @@ async function default_1(context, options) {
18
18
  return;
19
19
  }
20
20
  const bucketsPerLocation = {};
21
- await Promise.all(Object.values(context.backendLocations).map(async (loc) => {
21
+ await Promise.all(Object.entries(context.backendLocations).map(async ([backendId, loc]) => {
22
+ const cfg = context.backendConfigs[backendId];
23
+ if (!cfg) {
24
+ throw new error_1.FirebaseError(`Failed to find config for backend ${backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
25
+ }
22
26
  const baseName = `firebaseapphosting-sources-${options.projectNumber}-${loc.toLowerCase()}`;
23
27
  const resolvedName = await gcs.upsertBucket({
24
28
  product: "apphosting",
@@ -45,19 +49,28 @@ async function default_1(context, options) {
45
49
  bucketsPerLocation[loc] = resolvedName;
46
50
  }));
47
51
  await Promise.all(Object.values(context.backendConfigs).map(async (cfg) => {
48
- const projectSourcePath = options.projectRoot ? options.projectRoot : process.cwd();
49
- const zippedSourcePath = await (0, util_1.createArchive)(cfg, projectSourcePath);
52
+ var _a;
53
+ const rootDir = (_a = options.projectRoot) !== null && _a !== void 0 ? _a : process.cwd();
54
+ let builtAppDir;
55
+ if (cfg.localBuild) {
56
+ builtAppDir = context.backendLocalBuilds[cfg.backendId].buildDir;
57
+ if (!builtAppDir) {
58
+ throw new error_1.FirebaseError(`No local build dir found for ${cfg.backendId}`);
59
+ }
60
+ }
61
+ const zippedSourcePath = await (0, util_1.createArchive)(cfg, rootDir, builtAppDir);
62
+ (0, utils_1.logLabeledBullet)("apphosting", `Zipped ${cfg.localBuild ? "built app" : "source"} for backend ${cfg.backendId}`);
50
63
  const backendLocation = context.backendLocations[cfg.backendId];
51
64
  if (!backendLocation) {
52
65
  throw new error_1.FirebaseError(`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
53
66
  }
54
- (0, utils_1.logLabeledBullet)("apphosting", `Uploading source code at ${projectSourcePath} for backend ${cfg.backendId}...`);
67
+ (0, utils_1.logLabeledBullet)("apphosting", `Uploading ${cfg.localBuild ? "built app" : "source"} for backend ${cfg.backendId}...`);
55
68
  const bucketName = bucketsPerLocation[backendLocation];
56
69
  const { bucket, object } = await gcs.uploadObject({
57
70
  file: zippedSourcePath,
58
71
  stream: fs.createReadStream(zippedSourcePath),
59
72
  }, bucketName);
60
- (0, utils_1.logLabeledBullet)("apphosting", `Source code uploaded at gs://${bucket}/${object}`);
73
+ (0, utils_1.logLabeledBullet)("apphosting", `Uploaded at gs://${bucket}/${object}`);
61
74
  context.backendStorageUris[cfg.backendId] =
62
75
  `gs://${bucketName}/${path.basename(zippedSourcePath)}`;
63
76
  }));
@@ -8,6 +8,8 @@ const devConnect_1 = require("../../gcp/devConnect");
8
8
  const projectUtils_1 = require("../../projectUtils");
9
9
  const prompt_1 = require("../../prompt");
10
10
  const utils_1 = require("../../utils");
11
+ const localbuilds_1 = require("../../apphosting/localbuilds");
12
+ const error_1 = require("../../error");
11
13
  async function default_1(context, options) {
12
14
  var _a;
13
15
  const projectId = (0, projectUtils_1.needProjectId)(options);
@@ -17,6 +19,7 @@ async function default_1(context, options) {
17
19
  context.backendConfigs = {};
18
20
  context.backendLocations = {};
19
21
  context.backendStorageUris = {};
22
+ context.backendLocalBuilds = {};
20
23
  const configs = getBackendConfigs(options);
21
24
  const { backends } = await (0, apphosting_1.listBackends)(projectId, "-");
22
25
  const foundBackends = [];
@@ -105,7 +108,26 @@ async function default_1(context, options) {
105
108
  if (skippedBackends.length > 0) {
106
109
  (0, utils_1.logLabeledWarning)("apphosting", `Skipping deployment of backend(s) ${skippedBackends.map((cfg) => cfg.backendId).join(", ")}.`);
107
110
  }
108
- return;
111
+ for (const cfg of Object.values(context.backendConfigs)) {
112
+ if (!cfg.localBuild) {
113
+ continue;
114
+ }
115
+ (0, utils_1.logLabeledBullet)("apphosting", `Starting local build for backend ${cfg.backendId}`);
116
+ try {
117
+ const { outputFiles, annotations, buildConfig } = await (0, localbuilds_1.localBuild)(options.projectRoot || "./", "nextjs");
118
+ if (outputFiles.length !== 1) {
119
+ throw new error_1.FirebaseError(`Local build for backend ${cfg.backendId} failed: No output files found.`);
120
+ }
121
+ context.backendLocalBuilds[cfg.backendId] = {
122
+ buildDir: outputFiles[0],
123
+ buildConfig,
124
+ annotations,
125
+ };
126
+ }
127
+ catch (e) {
128
+ throw new error_1.FirebaseError(`Local Build for backend ${cfg.backendId} failed: ${e}`);
129
+ }
130
+ }
109
131
  }
110
132
  exports.default = default_1;
111
133
  function getBackendConfigs(options) {
@@ -13,6 +13,11 @@ async function default_1(context, options) {
13
13
  (0, utils_1.logLabeledWarning)("apphosting", `Failed to find metadata for backend(s) ${backendIds.join(", ")}. Please contact support with the contents of your firebase-debug.log to report your issue.`);
14
14
  backendIds = backendIds.filter((id) => !missingBackends.includes(id));
15
15
  }
16
+ const localBuildBackends = backendIds.filter((id) => context.backendLocalBuilds[id]);
17
+ if (localBuildBackends.length > 0) {
18
+ (0, utils_1.logLabeledWarning)("apphosting", `Skipping backend(s) ${localBuildBackends.join(", ")}. Local Builds are not supported yet.`);
19
+ backendIds = backendIds.filter((id) => !localBuildBackends.includes(id));
20
+ }
16
21
  if (backendIds.length === 0) {
17
22
  return;
18
23
  }
@@ -7,20 +7,21 @@ const path = require("path");
7
7
  const tmp = require("tmp");
8
8
  const error_1 = require("../../error");
9
9
  const fsAsync = require("../../fsAsync");
10
- async function createArchive(config, rootDir) {
10
+ async function createArchive(config, rootDir, targetSubDir) {
11
11
  const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
12
12
  const fileStream = fs.createWriteStream(tmpFile, {
13
13
  flags: "w",
14
14
  encoding: "binary",
15
15
  });
16
16
  const archive = archiver("zip");
17
+ const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
17
18
  const ignore = config.ignore || ["node_modules", ".git"];
18
19
  ignore.push("firebase-debug.log", "firebase-debug.*.log");
19
- const gitIgnorePatterns = parseGitIgnorePatterns(rootDir);
20
+ const gitIgnorePatterns = parseGitIgnorePatterns(targetDir);
20
21
  ignore.push(...gitIgnorePatterns);
21
22
  try {
22
23
  const files = await fsAsync.readdirRecursive({
23
- path: rootDir,
24
+ path: targetDir,
24
25
  ignore: ignore,
25
26
  isGitIgnore: true,
26
27
  });
@@ -60,7 +60,7 @@ async function createInstance(args) {
60
60
  await client.post(`projects/${args.projectId}/instances`, {
61
61
  name: args.instanceId,
62
62
  region: args.location,
63
- databaseVersion: "POSTGRES_17",
63
+ databaseVersion: "POSTGRES_15",
64
64
  settings: {
65
65
  tier: "db-f1-micro",
66
66
  edition: "ENTERPRISE",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "14.19.0",
3
+ "version": "14.19.1",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -61,6 +61,8 @@
61
61
  ]
62
62
  },
63
63
  "dependencies": {
64
+ "@apphosting/build": "^0.1.6",
65
+ "@apphosting/common": "^0.0.8",
64
66
  "@electric-sql/pglite": "^0.3.3",
65
67
  "@electric-sql/pglite-tools": "^0.2.8",
66
68
  "@google-cloud/cloud-sql-connector": "^1.3.3",
@@ -1107,6 +1107,9 @@
1107
1107
  },
1108
1108
  "type": "array"
1109
1109
  },
1110
+ "localBuild": {
1111
+ "type": "boolean"
1112
+ },
1110
1113
  "rootDir": {
1111
1114
  "type": "string"
1112
1115
  }
@@ -1134,6 +1137,9 @@
1134
1137
  },
1135
1138
  "type": "array"
1136
1139
  },
1140
+ "localBuild": {
1141
+ "type": "boolean"
1142
+ },
1137
1143
  "rootDir": {
1138
1144
  "type": "string"
1139
1145
  }