@donotdev/cli 0.0.34 → 0.0.35

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.
@@ -8052,7 +8052,7 @@ var init_cli_input = __esm({
8052
8052
  });
8053
8053
 
8054
8054
  // packages/tooling/src/utils/cli-tools.ts
8055
- import { spawnSync as spawnSync2 } from "node:child_process";
8055
+ import { spawnSync } from "node:child_process";
8056
8056
  function checkCLI(command, args = ["--version"], useCache = true) {
8057
8057
  const cacheKey = `${command}:${args.join(",")}`;
8058
8058
  if (useCache && cliCache.has(cacheKey)) {
@@ -8076,7 +8076,7 @@ function checkCLI(command, args = ["--version"], useCache = true) {
8076
8076
  ].filter(Boolean);
8077
8077
  for (const fullPath of commonPaths) {
8078
8078
  try {
8079
- const testResult = spawnSync2(
8079
+ const testResult = spawnSync(
8080
8080
  "powershell.exe",
8081
8081
  [
8082
8082
  "-NoProfile",
@@ -8098,7 +8098,7 @@ function checkCLI(command, args = ["--version"], useCache = true) {
8098
8098
  continue;
8099
8099
  }
8100
8100
  }
8101
- result = spawnSync2(
8101
+ result = spawnSync(
8102
8102
  "powershell.exe",
8103
8103
  [
8104
8104
  "-NoProfile",
@@ -8113,7 +8113,7 @@ function checkCLI(command, args = ["--version"], useCache = true) {
8113
8113
  }
8114
8114
  );
8115
8115
  } else {
8116
- result = spawnSync2(`${command} ${args.join(" ")}`, {
8116
+ result = spawnSync(`${command} ${args.join(" ")}`, {
8117
8117
  stdio: "pipe",
8118
8118
  shell: true
8119
8119
  });
@@ -8341,6 +8341,29 @@ var init_cli_tools = __esm({
8341
8341
  }
8342
8342
  });
8343
8343
 
8344
+ // packages/tooling/src/utils/error-handling.ts
8345
+ function isError(error2) {
8346
+ return error2 instanceof Error;
8347
+ }
8348
+ function getErrorMessage(error2) {
8349
+ if (isError(error2)) {
8350
+ return error2.message;
8351
+ }
8352
+ if (typeof error2 === "string") {
8353
+ return error2;
8354
+ }
8355
+ if (error2 && typeof error2 === "object" && "message" in error2) {
8356
+ return String(error2.message);
8357
+ }
8358
+ return String(error2);
8359
+ }
8360
+ var init_error_handling = __esm({
8361
+ "packages/tooling/src/utils/error-handling.ts"() {
8362
+ "use strict";
8363
+ init_utils();
8364
+ }
8365
+ });
8366
+
8344
8367
  // node_modules/.bun/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js
8345
8368
  var require_identity = __commonJS({
8346
8369
  "node_modules/.bun/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js"(exports) {
@@ -15702,29 +15725,6 @@ var require_dist = __commonJS({
15702
15725
  }
15703
15726
  });
15704
15727
 
15705
- // packages/tooling/src/utils/error-handling.ts
15706
- function isError(error2) {
15707
- return error2 instanceof Error;
15708
- }
15709
- function getErrorMessage(error2) {
15710
- if (isError(error2)) {
15711
- return error2.message;
15712
- }
15713
- if (typeof error2 === "string") {
15714
- return error2;
15715
- }
15716
- if (error2 && typeof error2 === "object" && "message" in error2) {
15717
- return String(error2.message);
15718
- }
15719
- return String(error2);
15720
- }
15721
- var init_error_handling = __esm({
15722
- "packages/tooling/src/utils/error-handling.ts"() {
15723
- "use strict";
15724
- init_utils();
15725
- }
15726
- });
15727
-
15728
15728
  // packages/tooling/src/apps/vercel-api.ts
15729
15729
  function formatVercelError(status, body, context) {
15730
15730
  let vercelCode;
@@ -16631,6 +16631,10 @@ init_utils();
16631
16631
  // packages/tooling/src/cli/index.ts
16632
16632
  init_utils();
16633
16633
 
16634
+ // packages/tooling/src/apps/deploy-utils.ts
16635
+ init_utils();
16636
+ import { spawnSync as spawnSync3 } from "node:child_process";
16637
+
16634
16638
  // packages/tooling/src/utils/spawn-utils.ts
16635
16639
  init_utils();
16636
16640
  init_cli_output();
@@ -16638,7 +16642,7 @@ init_errors();
16638
16642
  init_pathResolver();
16639
16643
  import {
16640
16644
  spawn,
16641
- spawnSync,
16645
+ spawnSync as spawnSync2,
16642
16646
  execSync
16643
16647
  } from "node:child_process";
16644
16648
  import { platform } from "node:os";
@@ -16664,7 +16668,7 @@ function executeFirebaseCommand(args, options) {
16664
16668
  env: deployEnv
16665
16669
  };
16666
16670
  let result;
16667
- result = spawnSync(`firebase ${args.join(" ")}`, {
16671
+ result = spawnSync2(`firebase ${args.join(" ")}`, {
16668
16672
  ...spawnOptions,
16669
16673
  shell: true
16670
16674
  });
@@ -16758,103 +16762,357 @@ function safeRemove(path, options = {}) {
16758
16762
  }
16759
16763
  }
16760
16764
 
16761
- // packages/tooling/src/apps/deploy.ts
16762
- init_utils();
16763
- import { execSync as execSync3 } from "node:child_process";
16764
-
16765
- // packages/tooling/src/apps/deploy-frontend.ts
16766
- init_utils();
16767
- async function deployFrontend(appDir, serviceAccountPath, projectId, config) {
16768
- const s = Y2();
16769
- s.start("Deploying frontend to Firebase Hosting...");
16770
- const args = buildFirebaseDeployArgs(
16771
- "hosting",
16772
- projectId,
16773
- config.debug,
16774
- config.force ?? true
16775
- );
16776
- const result = executeFirebaseCommand(args, {
16777
- cwd: appDir,
16778
- serviceAccountPath,
16779
- projectId,
16780
- debug: config.debug
16781
- });
16782
- if (result.error) {
16783
- s.stop("Deployment failed");
16784
- throw result.error;
16765
+ // packages/tooling/src/apps/deploy-utils.ts
16766
+ init_error_handling();
16767
+ init_pathResolver();
16768
+ init_typed_file_operations();
16769
+ function detectAvailableApps() {
16770
+ const currentDir = process.cwd();
16771
+ const appsDir = joinPath(currentDir, "apps");
16772
+ if (!pathExists(appsDir)) {
16773
+ return [];
16785
16774
  }
16786
- if (!result.success) {
16787
- s.stop("Deployment failed");
16788
- handleDeploymentFailure(
16789
- result,
16790
- `firebase ${args.join(" ")}`,
16791
- serviceAccountPath
16775
+ return readdirSync2(appsDir).filter((item) => {
16776
+ const itemPath = joinPath(appsDir, item);
16777
+ const stat2 = statSync2(itemPath);
16778
+ return stat2?.isDirectory() === true;
16779
+ }).filter((app) => {
16780
+ const appDir = joinPath(appsDir, app);
16781
+ const firebaseJsonPath = joinPath(appDir, "firebase.json");
16782
+ const supabaseDir = joinPath(appDir, "supabase");
16783
+ const vercelJsonPath = joinPath(appDir, "vercel.json");
16784
+ return pathExists(firebaseJsonPath) || pathExists(supabaseDir) || pathExists(vercelJsonPath);
16785
+ }).sort();
16786
+ }
16787
+ function detectAppDir(appName) {
16788
+ const currentDir = process.cwd();
16789
+ const appDir = joinPath(currentDir, "apps", appName);
16790
+ if (!pathExists(appDir)) {
16791
+ throw new DoNotDevError(
16792
+ `App directory not found: ${appDir}`,
16793
+ "file-not-found",
16794
+ { context: { appName, expectedPath: appDir } }
16792
16795
  );
16793
16796
  }
16794
- s.stop("Frontend deployed successfully");
16797
+ return appDir;
16795
16798
  }
16796
-
16797
- // packages/tooling/src/apps/deploy-functions.ts
16798
- init_utils();
16799
- var import_yaml = __toESM(require_dist(), 1);
16800
- import { execSync as execSync2, spawnSync as spawnSync3 } from "node:child_process";
16801
- init_cli_tools();
16802
- init_pathResolver();
16803
- init_typed_file_operations();
16804
- function backupFiles(functionsDir) {
16805
- const backupDir = joinPath(functionsDir, ".deploy-backup");
16806
- const packageJsonPath = joinPath(functionsDir, "package.json");
16807
- const packageLockJsonPath = joinPath(functionsDir, "package-lock.json");
16799
+ function validateServiceAccount(appDir, options) {
16800
+ const keyFileName = options?.staging ? "service-account-key.staging.json" : "service-account-key.json";
16801
+ const rootKeyPath = joinPath(appDir, keyFileName);
16802
+ const functionsDir = joinPath(appDir, "functions");
16803
+ const functionsKeyPath = joinPath(functionsDir, keyFileName);
16804
+ const keyPath = pathExists(rootKeyPath) ? rootKeyPath : functionsKeyPath;
16805
+ const errors = [];
16806
+ if (!pathExists(keyPath)) {
16807
+ return {
16808
+ valid: false,
16809
+ info: {
16810
+ path: keyPath,
16811
+ projectId: "",
16812
+ clientEmail: "",
16813
+ valid: false,
16814
+ errors: [
16815
+ `Service account key file not found. Checked:`,
16816
+ ` - ${rootKeyPath}`,
16817
+ ` - ${functionsKeyPath}`
16818
+ ]
16819
+ }
16820
+ };
16821
+ }
16808
16822
  try {
16809
- ensureDirSync(backupDir);
16810
- const backupPackageJson = joinPath(backupDir, "package.json");
16811
- const backupPackageLockJson = joinPath(backupDir, "package-lock.json");
16812
- if (pathExists(packageJsonPath)) {
16813
- const contentRaw = readSync(packageJsonPath, { format: "text" });
16814
- const content = typeof contentRaw === "string" ? contentRaw : null;
16815
- if (!content) {
16816
- throw new Error(`Failed to read package.json: ${packageJsonPath}`);
16823
+ const keyData = readServiceAccountKey(keyPath);
16824
+ return {
16825
+ valid: true,
16826
+ info: {
16827
+ path: keyPath,
16828
+ projectId: keyData.project_id,
16829
+ clientEmail: keyData.client_email,
16830
+ valid: true,
16831
+ errors: []
16817
16832
  }
16818
- writeSync(backupPackageJson, content, { overwrite: true });
16819
- }
16820
- if (pathExists(packageLockJsonPath)) {
16821
- const contentRaw = readSync(packageLockJsonPath, { format: "text" });
16822
- const content = typeof contentRaw === "string" ? contentRaw : null;
16823
- if (!content) {
16824
- throw new Error(
16825
- `Failed to read package-lock.json: ${packageLockJsonPath}`
16826
- );
16833
+ };
16834
+ } catch (error2) {
16835
+ return {
16836
+ valid: false,
16837
+ info: {
16838
+ path: keyPath,
16839
+ projectId: "",
16840
+ clientEmail: "",
16841
+ valid: false,
16842
+ errors: [`Invalid service account key: ${getErrorMessage(error2)}`]
16827
16843
  }
16828
- writeSync(backupPackageLockJson, content, { overwrite: true });
16829
- }
16844
+ };
16845
+ }
16846
+ }
16847
+ function validateFirebaseJson(appDir) {
16848
+ const firebaseJsonPath = joinPath(appDir, "firebase.json");
16849
+ if (!pathExists(firebaseJsonPath)) {
16830
16850
  return {
16831
- packageJson: backupPackageJson,
16832
- packageLockJson: backupPackageLockJson
16851
+ valid: false,
16852
+ hasHosting: false,
16853
+ hasFunctions: false,
16854
+ hasFirestoreRules: false,
16855
+ hasFirestoreIndexes: false,
16856
+ hasStorageRules: false,
16857
+ errors: [`firebase.json not found at: ${firebaseJsonPath}`]
16858
+ };
16859
+ }
16860
+ try {
16861
+ const config = readFirebaseJson(firebaseJsonPath);
16862
+ const hasHosting = !!config.hosting;
16863
+ const hasFunctions = !!config.functions && Array.isArray(config.functions);
16864
+ const hasFirestoreRules = !!config.firestore?.rules && pathExists(joinPath(appDir, config.firestore.rules));
16865
+ const hasFirestoreIndexes = !!config.firestore?.indexes && pathExists(joinPath(appDir, config.firestore.indexes));
16866
+ const hasStorageRules = !!config.storage?.rules && pathExists(joinPath(appDir, config.storage.rules));
16867
+ return {
16868
+ valid: true,
16869
+ projectId: config.projectId,
16870
+ hasHosting,
16871
+ hasFunctions,
16872
+ hasFirestoreRules,
16873
+ hasFirestoreIndexes,
16874
+ hasStorageRules,
16875
+ errors: []
16833
16876
  };
16834
16877
  } catch (error2) {
16835
- log.warn(
16836
- `Failed to backup files: ${error2 instanceof Error ? error2.message : String(error2)}`
16837
- );
16838
- return null;
16878
+ return {
16879
+ valid: false,
16880
+ hasHosting: false,
16881
+ hasFunctions: false,
16882
+ hasFirestoreRules: false,
16883
+ hasFirestoreIndexes: false,
16884
+ hasStorageRules: false,
16885
+ errors: [`Invalid firebase.json: ${getErrorMessage(error2)}`]
16886
+ };
16839
16887
  }
16840
16888
  }
16841
- function generateCleanPackageJson(functionsDir) {
16842
- const packageJsonPath = joinPath(functionsDir, "package.json");
16843
- if (!pathExists(packageJsonPath)) {
16844
- throw new DoNotDevError(
16845
- `package.json not found: ${packageJsonPath}`,
16846
- "file-not-found"
16847
- );
16889
+ function validateBuild(appDir) {
16890
+ const distPath = joinPath(appDir, "dist");
16891
+ if (!pathExists(distPath)) {
16892
+ return { exists: false, isEmpty: true, path: distPath };
16848
16893
  }
16849
- const packageJson = readPackageJson(packageJsonPath);
16850
- if (!packageJson.name) {
16851
- throw new Error(
16852
- `package.json is empty or invalid JSON at ${packageJsonPath}`
16853
- );
16894
+ try {
16895
+ const files = readdirSync2(distPath);
16896
+ return {
16897
+ exists: true,
16898
+ isEmpty: files.length === 0,
16899
+ path: distPath
16900
+ };
16901
+ } catch {
16902
+ return { exists: true, isEmpty: true, path: distPath };
16854
16903
  }
16855
- const cleanPackageJson = { ...packageJson };
16856
- if (cleanPackageJson.dependencies) {
16857
- const removedDeps = Object.entries(cleanPackageJson.dependencies).filter(
16904
+ }
16905
+ function readStagingProject(startDir) {
16906
+ let current = startDir;
16907
+ for (let i = 0; i < 10; i++) {
16908
+ const firebasercPath = joinPath(current, ".firebaserc");
16909
+ if (pathExists(firebasercPath)) {
16910
+ try {
16911
+ const firebaserc = readFirebaserc(firebasercPath);
16912
+ if (firebaserc?.projects?.staging) {
16913
+ return firebaserc.projects.staging;
16914
+ }
16915
+ } catch (error2) {
16916
+ }
16917
+ }
16918
+ const parent = joinPath(current, "..");
16919
+ if (parent === current) break;
16920
+ current = parent;
16921
+ }
16922
+ return null;
16923
+ }
16924
+ function checkConfigPlaceholders(appDir) {
16925
+ const CONFIG_FILES = ["vercel.json", "firebase.json", ".firebaserc"];
16926
+ const bad = [];
16927
+ for (const file of CONFIG_FILES) {
16928
+ const filePath = joinPath(appDir, file);
16929
+ if (!pathExists(filePath)) continue;
16930
+ const content = readSync(filePath, { format: "text" });
16931
+ if (typeof content === "string" && (content.includes("{{") || content.includes("}}"))) {
16932
+ bad.push(file);
16933
+ }
16934
+ }
16935
+ if (bad.length > 0) {
16936
+ log.warn(`Unreplaced template placeholders found in: ${bad.join(", ")}`);
16937
+ log.warn(` Fix manually or re-run "dndev init" to regenerate.
16938
+ `);
16939
+ }
16940
+ return bad.length > 0;
16941
+ }
16942
+ async function showServiceAccountError(info2, projectId) {
16943
+ const consoleUrl = projectId ? `https://console.firebase.google.com/project/${projectId}/settings/serviceaccounts/adminsdk` : "https://console.firebase.google.com/project/YOUR_PROJECT/settings/serviceaccounts/adminsdk";
16944
+ const errorList = info2.errors.map((e2) => `\u2022 ${e2}`).join("\n");
16945
+ Me(
16946
+ `${errorList}
16947
+
16948
+ Why it matters:
16949
+ Firebase CLI needs service account credentials to deploy.
16950
+ Without valid credentials, deployment will fail.
16951
+
16952
+ How to fix:
16953
+ 1. Go to Firebase Console:
16954
+ ${consoleUrl}
16955
+ 2. Click "Generate New Private Key"
16956
+ 3. Save the JSON file as: ${info2.path}
16957
+ 4. Required IAM roles:
16958
+ \u2022 Firebase Hosting Admin (for frontend)
16959
+ \u2022 Cloud Functions Admin (for functions)
16960
+ \u2022 Or Firebase Admin (covers both)`,
16961
+ "Service Account Error"
16962
+ );
16963
+ if (projectId) {
16964
+ const shouldOpen = await askForConfirmation(
16965
+ "Open Firebase Console now?",
16966
+ true
16967
+ );
16968
+ if (shouldOpen) {
16969
+ try {
16970
+ const openCommand = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
16971
+ spawnSync3(`${openCommand} ${consoleUrl}`, { shell: true });
16972
+ log.success("Opening Firebase Console...");
16973
+ } catch {
16974
+ log.warn("Could not open browser. Please open the URL manually.");
16975
+ }
16976
+ }
16977
+ }
16978
+ }
16979
+ function showFirebaseJsonError(errors, appDir, deploymentType) {
16980
+ const errorList = errors.map((e2) => `\u2022 ${e2}`).join("\n");
16981
+ const firebaseJsonPath = joinPath(appDir, "firebase.json");
16982
+ let configExample = "";
16983
+ if (deploymentType === "frontend" || deploymentType === "both") {
16984
+ configExample += `
16985
+ Hosting config:
16986
+ { "hosting": { "public": "dist", ... } }`;
16987
+ }
16988
+ if (deploymentType === "functions" || deploymentType === "both") {
16989
+ configExample += `
16990
+ Functions config:
16991
+ { "functions": [{ "source": "functions", ... }] }`;
16992
+ }
16993
+ Me(
16994
+ `${errorList}
16995
+
16996
+ Why it matters:
16997
+ firebase.json defines your deployment configuration.
16998
+ Without it, Firebase CLI doesn't know what to deploy.
16999
+
17000
+ How to fix:
17001
+ 1. Ensure firebase.json exists at: ${firebaseJsonPath}
17002
+ 2. Add required configuration:${configExample}`,
17003
+ "Firebase Configuration Error"
17004
+ );
17005
+ }
17006
+ function clearFirebaseCache(appDir) {
17007
+ const firebaseCacheDir = joinPath(appDir, ".firebase");
17008
+ if (pathExists(firebaseCacheDir)) {
17009
+ log.info("Clearing Firebase cache...");
17010
+ const removed = safeRemove(firebaseCacheDir, { silent: true });
17011
+ if (removed) {
17012
+ log.success("Firebase cache cleared");
17013
+ } else {
17014
+ log.warn("Could not clear Firebase cache (non-critical)");
17015
+ }
17016
+ }
17017
+ }
17018
+
17019
+ // packages/tooling/src/apps/deploy.ts
17020
+ init_utils();
17021
+ import { execSync as execSync3 } from "node:child_process";
17022
+
17023
+ // packages/tooling/src/apps/deploy-frontend.ts
17024
+ init_utils();
17025
+ async function deployFrontend(appDir, serviceAccountPath, projectId, config) {
17026
+ const s = Y2();
17027
+ s.start("Deploying frontend to Firebase Hosting...");
17028
+ const args = buildFirebaseDeployArgs(
17029
+ "hosting",
17030
+ projectId,
17031
+ config.debug,
17032
+ config.force ?? true
17033
+ );
17034
+ const result = executeFirebaseCommand(args, {
17035
+ cwd: appDir,
17036
+ serviceAccountPath,
17037
+ projectId,
17038
+ debug: config.debug
17039
+ });
17040
+ if (result.error) {
17041
+ s.stop("Deployment failed");
17042
+ throw result.error;
17043
+ }
17044
+ if (!result.success) {
17045
+ s.stop("Deployment failed");
17046
+ handleDeploymentFailure(
17047
+ result,
17048
+ `firebase ${args.join(" ")}`,
17049
+ serviceAccountPath
17050
+ );
17051
+ }
17052
+ s.stop("Frontend deployed successfully");
17053
+ }
17054
+
17055
+ // packages/tooling/src/apps/deploy-functions.ts
17056
+ init_utils();
17057
+ var import_yaml = __toESM(require_dist(), 1);
17058
+ import { execSync as execSync2, spawnSync as spawnSync4 } from "node:child_process";
17059
+ init_cli_tools();
17060
+ init_pathResolver();
17061
+ init_typed_file_operations();
17062
+ function backupFiles(functionsDir) {
17063
+ const backupDir = joinPath(functionsDir, ".deploy-backup");
17064
+ const packageJsonPath = joinPath(functionsDir, "package.json");
17065
+ const packageLockJsonPath = joinPath(functionsDir, "package-lock.json");
17066
+ try {
17067
+ ensureDirSync(backupDir);
17068
+ const backupPackageJson = joinPath(backupDir, "package.json");
17069
+ const backupPackageLockJson = joinPath(backupDir, "package-lock.json");
17070
+ if (pathExists(packageJsonPath)) {
17071
+ const contentRaw = readSync(packageJsonPath, { format: "text" });
17072
+ const content = typeof contentRaw === "string" ? contentRaw : null;
17073
+ if (!content) {
17074
+ throw new Error(`Failed to read package.json: ${packageJsonPath}`);
17075
+ }
17076
+ writeSync(backupPackageJson, content, { overwrite: true });
17077
+ }
17078
+ if (pathExists(packageLockJsonPath)) {
17079
+ const contentRaw = readSync(packageLockJsonPath, { format: "text" });
17080
+ const content = typeof contentRaw === "string" ? contentRaw : null;
17081
+ if (!content) {
17082
+ throw new Error(
17083
+ `Failed to read package-lock.json: ${packageLockJsonPath}`
17084
+ );
17085
+ }
17086
+ writeSync(backupPackageLockJson, content, { overwrite: true });
17087
+ }
17088
+ return {
17089
+ packageJson: backupPackageJson,
17090
+ packageLockJson: backupPackageLockJson
17091
+ };
17092
+ } catch (error2) {
17093
+ log.warn(
17094
+ `Failed to backup files: ${error2 instanceof Error ? error2.message : String(error2)}`
17095
+ );
17096
+ return null;
17097
+ }
17098
+ }
17099
+ function generateCleanPackageJson(functionsDir) {
17100
+ const packageJsonPath = joinPath(functionsDir, "package.json");
17101
+ if (!pathExists(packageJsonPath)) {
17102
+ throw new DoNotDevError(
17103
+ `package.json not found: ${packageJsonPath}`,
17104
+ "file-not-found"
17105
+ );
17106
+ }
17107
+ const packageJson = readPackageJson(packageJsonPath);
17108
+ if (!packageJson.name) {
17109
+ throw new Error(
17110
+ `package.json is empty or invalid JSON at ${packageJsonPath}`
17111
+ );
17112
+ }
17113
+ const cleanPackageJson = { ...packageJson };
17114
+ if (cleanPackageJson.dependencies) {
17115
+ const removedDeps = Object.entries(cleanPackageJson.dependencies).filter(
16858
17116
  ([, version]) => String(version).startsWith("file:") || String(version).startsWith("workspace:")
16859
17117
  );
16860
17118
  if (removedDeps.length > 0) {
@@ -16984,7 +17242,7 @@ function updateCloudRunIAM(functionNames, projectId, region, serviceAccountPath,
16984
17242
  let failCount = 0;
16985
17243
  for (const funcName of functionNames) {
16986
17244
  try {
16987
- const result = spawnSync3(
17245
+ const result = spawnSync4(
16988
17246
  "gcloud",
16989
17247
  [
16990
17248
  "run",
@@ -17102,7 +17360,7 @@ async function autoSyncSecrets(functionsDir, projectId, config) {
17102
17360
  let failCount = 0;
17103
17361
  for (const { key, value } of secrets) {
17104
17362
  try {
17105
- const result = spawnSync3(
17363
+ const result = spawnSync4(
17106
17364
  firebaseCmd,
17107
17365
  ["functions:secrets:set", key, "--project", projectId],
17108
17366
  {
@@ -17287,244 +17545,6 @@ async function deployRules(appDir, serviceAccountPath, projectId, config, option
17287
17545
  s.stop(`${targetNames} deployed successfully`);
17288
17546
  }
17289
17547
 
17290
- // packages/tooling/src/apps/deploy-utils.ts
17291
- init_utils();
17292
- import { spawnSync as spawnSync4 } from "node:child_process";
17293
- init_error_handling();
17294
- init_pathResolver();
17295
- init_typed_file_operations();
17296
- function detectAvailableApps() {
17297
- const currentDir = process.cwd();
17298
- const appsDir = joinPath(currentDir, "apps");
17299
- if (!pathExists(appsDir)) {
17300
- return [];
17301
- }
17302
- return readdirSync2(appsDir).filter((item) => {
17303
- const itemPath = joinPath(appsDir, item);
17304
- const stat2 = statSync2(itemPath);
17305
- return stat2?.isDirectory() === true;
17306
- }).filter((app) => {
17307
- const appDir = joinPath(appsDir, app);
17308
- const firebaseJsonPath = joinPath(appDir, "firebase.json");
17309
- const supabaseDir = joinPath(appDir, "supabase");
17310
- const vercelJsonPath = joinPath(appDir, "vercel.json");
17311
- return pathExists(firebaseJsonPath) || pathExists(supabaseDir) || pathExists(vercelJsonPath);
17312
- }).sort();
17313
- }
17314
- function detectAppDir(appName) {
17315
- const currentDir = process.cwd();
17316
- const appDir = joinPath(currentDir, "apps", appName);
17317
- if (!pathExists(appDir)) {
17318
- throw new DoNotDevError(
17319
- `App directory not found: ${appDir}`,
17320
- "file-not-found",
17321
- { context: { appName, expectedPath: appDir } }
17322
- );
17323
- }
17324
- return appDir;
17325
- }
17326
- function validateServiceAccount(appDir, options) {
17327
- const keyFileName = options?.staging ? "service-account-key.staging.json" : "service-account-key.json";
17328
- const rootKeyPath = joinPath(appDir, keyFileName);
17329
- const functionsDir = joinPath(appDir, "functions");
17330
- const functionsKeyPath = joinPath(functionsDir, keyFileName);
17331
- const keyPath = pathExists(rootKeyPath) ? rootKeyPath : functionsKeyPath;
17332
- const errors = [];
17333
- if (!pathExists(keyPath)) {
17334
- return {
17335
- valid: false,
17336
- info: {
17337
- path: keyPath,
17338
- projectId: "",
17339
- clientEmail: "",
17340
- valid: false,
17341
- errors: [
17342
- `Service account key file not found. Checked:`,
17343
- ` - ${rootKeyPath}`,
17344
- ` - ${functionsKeyPath}`
17345
- ]
17346
- }
17347
- };
17348
- }
17349
- try {
17350
- const keyData = readServiceAccountKey(keyPath);
17351
- return {
17352
- valid: true,
17353
- info: {
17354
- path: keyPath,
17355
- projectId: keyData.project_id,
17356
- clientEmail: keyData.client_email,
17357
- valid: true,
17358
- errors: []
17359
- }
17360
- };
17361
- } catch (error2) {
17362
- return {
17363
- valid: false,
17364
- info: {
17365
- path: keyPath,
17366
- projectId: "",
17367
- clientEmail: "",
17368
- valid: false,
17369
- errors: [`Invalid service account key: ${getErrorMessage(error2)}`]
17370
- }
17371
- };
17372
- }
17373
- }
17374
- function validateFirebaseJson(appDir) {
17375
- const firebaseJsonPath = joinPath(appDir, "firebase.json");
17376
- if (!pathExists(firebaseJsonPath)) {
17377
- return {
17378
- valid: false,
17379
- hasHosting: false,
17380
- hasFunctions: false,
17381
- hasFirestoreRules: false,
17382
- hasFirestoreIndexes: false,
17383
- hasStorageRules: false,
17384
- errors: [`firebase.json not found at: ${firebaseJsonPath}`]
17385
- };
17386
- }
17387
- try {
17388
- const config = readFirebaseJson(firebaseJsonPath);
17389
- const hasHosting = !!config.hosting;
17390
- const hasFunctions = !!config.functions && Array.isArray(config.functions);
17391
- const hasFirestoreRules = !!config.firestore?.rules && pathExists(joinPath(appDir, config.firestore.rules));
17392
- const hasFirestoreIndexes = !!config.firestore?.indexes && pathExists(joinPath(appDir, config.firestore.indexes));
17393
- const hasStorageRules = !!config.storage?.rules && pathExists(joinPath(appDir, config.storage.rules));
17394
- return {
17395
- valid: true,
17396
- projectId: config.projectId,
17397
- hasHosting,
17398
- hasFunctions,
17399
- hasFirestoreRules,
17400
- hasFirestoreIndexes,
17401
- hasStorageRules,
17402
- errors: []
17403
- };
17404
- } catch (error2) {
17405
- return {
17406
- valid: false,
17407
- hasHosting: false,
17408
- hasFunctions: false,
17409
- hasFirestoreRules: false,
17410
- hasFirestoreIndexes: false,
17411
- hasStorageRules: false,
17412
- errors: [`Invalid firebase.json: ${getErrorMessage(error2)}`]
17413
- };
17414
- }
17415
- }
17416
- function validateBuild(appDir) {
17417
- const distPath = joinPath(appDir, "dist");
17418
- if (!pathExists(distPath)) {
17419
- return { exists: false, isEmpty: true, path: distPath };
17420
- }
17421
- try {
17422
- const files = readdirSync2(distPath);
17423
- return {
17424
- exists: true,
17425
- isEmpty: files.length === 0,
17426
- path: distPath
17427
- };
17428
- } catch {
17429
- return { exists: true, isEmpty: true, path: distPath };
17430
- }
17431
- }
17432
- function readStagingProject(startDir) {
17433
- let current = startDir;
17434
- for (let i = 0; i < 10; i++) {
17435
- const firebasercPath = joinPath(current, ".firebaserc");
17436
- if (pathExists(firebasercPath)) {
17437
- try {
17438
- const firebaserc = readFirebaserc(firebasercPath);
17439
- if (firebaserc?.projects?.staging) {
17440
- return firebaserc.projects.staging;
17441
- }
17442
- } catch (error2) {
17443
- }
17444
- }
17445
- const parent = joinPath(current, "..");
17446
- if (parent === current) break;
17447
- current = parent;
17448
- }
17449
- return null;
17450
- }
17451
- async function showServiceAccountError(info2, projectId) {
17452
- const consoleUrl = projectId ? `https://console.firebase.google.com/project/${projectId}/settings/serviceaccounts/adminsdk` : "https://console.firebase.google.com/project/YOUR_PROJECT/settings/serviceaccounts/adminsdk";
17453
- const errorList = info2.errors.map((e2) => `\u2022 ${e2}`).join("\n");
17454
- Me(
17455
- `${errorList}
17456
-
17457
- Why it matters:
17458
- Firebase CLI needs service account credentials to deploy.
17459
- Without valid credentials, deployment will fail.
17460
-
17461
- How to fix:
17462
- 1. Go to Firebase Console:
17463
- ${consoleUrl}
17464
- 2. Click "Generate New Private Key"
17465
- 3. Save the JSON file as: ${info2.path}
17466
- 4. Required IAM roles:
17467
- \u2022 Firebase Hosting Admin (for frontend)
17468
- \u2022 Cloud Functions Admin (for functions)
17469
- \u2022 Or Firebase Admin (covers both)`,
17470
- "Service Account Error"
17471
- );
17472
- if (projectId) {
17473
- const shouldOpen = await askForConfirmation(
17474
- "Open Firebase Console now?",
17475
- true
17476
- );
17477
- if (shouldOpen) {
17478
- try {
17479
- const openCommand = process.platform === "win32" ? "start" : process.platform === "darwin" ? "open" : "xdg-open";
17480
- spawnSync4(`${openCommand} ${consoleUrl}`, { shell: true });
17481
- log.success("Opening Firebase Console...");
17482
- } catch {
17483
- log.warn("Could not open browser. Please open the URL manually.");
17484
- }
17485
- }
17486
- }
17487
- }
17488
- function showFirebaseJsonError(errors, appDir, deploymentType) {
17489
- const errorList = errors.map((e2) => `\u2022 ${e2}`).join("\n");
17490
- const firebaseJsonPath = joinPath(appDir, "firebase.json");
17491
- let configExample = "";
17492
- if (deploymentType === "frontend" || deploymentType === "both") {
17493
- configExample += `
17494
- Hosting config:
17495
- { "hosting": { "public": "dist", ... } }`;
17496
- }
17497
- if (deploymentType === "functions" || deploymentType === "both") {
17498
- configExample += `
17499
- Functions config:
17500
- { "functions": [{ "source": "functions", ... }] }`;
17501
- }
17502
- Me(
17503
- `${errorList}
17504
-
17505
- Why it matters:
17506
- firebase.json defines your deployment configuration.
17507
- Without it, Firebase CLI doesn't know what to deploy.
17508
-
17509
- How to fix:
17510
- 1. Ensure firebase.json exists at: ${firebaseJsonPath}
17511
- 2. Add required configuration:${configExample}`,
17512
- "Firebase Configuration Error"
17513
- );
17514
- }
17515
- function clearFirebaseCache(appDir) {
17516
- const firebaseCacheDir = joinPath(appDir, ".firebase");
17517
- if (pathExists(firebaseCacheDir)) {
17518
- log.info("Clearing Firebase cache...");
17519
- const removed = safeRemove(firebaseCacheDir, { silent: true });
17520
- if (removed) {
17521
- log.success("Firebase cache cleared");
17522
- } else {
17523
- log.warn("Could not clear Firebase cache (non-critical)");
17524
- }
17525
- }
17526
- }
17527
-
17528
17548
  // packages/tooling/src/apps/deploy-vercel-frontend.ts
17529
17549
  init_utils();
17530
17550
  init_vercel_api();
@@ -17596,8 +17616,26 @@ async function uploadFiles(files, token, orgId) {
17596
17616
  );
17597
17617
  }
17598
17618
  }
17599
- async function createDeployment(files, token, orgId, projectId, projectName) {
17619
+ function loadVercelConfig(appDir) {
17620
+ const configPath = joinPath(appDir, "vercel.json");
17621
+ if (!pathExists(configPath)) return {};
17622
+ try {
17623
+ const raw = readSync(configPath);
17624
+ const config = JSON.parse(raw);
17625
+ const result = {};
17626
+ if (config.rewrites) result.rewrites = config.rewrites;
17627
+ if (config.redirects) result.redirects = config.redirects;
17628
+ if (config.headers) result.headers = config.headers;
17629
+ if (config.cleanUrls != null) result.cleanUrls = config.cleanUrls;
17630
+ if (config.trailingSlash != null) result.trailingSlash = config.trailingSlash;
17631
+ return result;
17632
+ } catch {
17633
+ return {};
17634
+ }
17635
+ }
17636
+ async function createDeployment(files, token, orgId, projectId, projectName, appDir) {
17600
17637
  const q2 = teamQuery(orgId);
17638
+ const vercelConfig = loadVercelConfig(appDir);
17601
17639
  const body = {
17602
17640
  name: projectName,
17603
17641
  project: projectId,
@@ -17611,7 +17649,8 @@ async function createDeployment(files, token, orgId, projectId, projectName) {
17611
17649
  buildCommand: "",
17612
17650
  installCommand: "",
17613
17651
  outputDirectory: "."
17614
- }
17652
+ },
17653
+ ...vercelConfig
17615
17654
  };
17616
17655
  const res = await fetch(`${VERCEL_API2}/v13/deployments${q2}`, {
17617
17656
  method: "POST",
@@ -17695,7 +17734,8 @@ async function deployVercelFrontend(appDir, _config) {
17695
17734
  token,
17696
17735
  orgId,
17697
17736
  projectId,
17698
- project.projectName
17737
+ project.projectName,
17738
+ appDir
17699
17739
  );
17700
17740
  log.info(`Deployment ${deployment.id} created, waiting...`);
17701
17741
  const ready = await waitForReady(deployment.id, token, orgId);
@@ -17863,6 +17903,12 @@ async function main2(options = {}) {
17863
17903
  process.exit(1);
17864
17904
  }
17865
17905
  const appDir = appName ? detectAppDir(appName) : projectRoot;
17906
+ if (checkConfigPlaceholders(appDir)) {
17907
+ throw new DoNotDevError(
17908
+ "Config files contain unreplaced template placeholders. Fix before deploying.",
17909
+ "configuration-error"
17910
+ );
17911
+ }
17866
17912
  const appProviderInfo = detectProvider(appDir);
17867
17913
  const hasVercelConfig = pathExists(joinPath(appDir, "vercel.json"));
17868
17914
  let deploymentType = config.deploymentType;