@anvil-works/anvil-cli 0.5.10 → 0.5.11

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 (2) hide show
  1. package/dist/cli.js +67 -26
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -50998,6 +50998,16 @@ var __webpack_exports__ = {};
50998
50998
  const selectedUrl = await logger_logger.select("Multiple logged-in Anvil URLs found. Which one would you like to use?", choices, decision.urls[0]);
50999
50999
  return selectedUrl;
51000
51000
  }
51001
+ const defaultConfigureWatchGitAuthDeps = {
51002
+ configureCredentialHelperForUrl: configureCredentialHelperForUrl,
51003
+ setAppAuthBinding: setAppAuthBinding
51004
+ };
51005
+ const defaultSyncStartDeps = {
51006
+ pushToAnvil,
51007
+ recreateSessionAndValidate,
51008
+ recheckSyncStatus,
51009
+ startWatchingWithEventHandlers
51010
+ };
51001
51011
  function resolveWatchOpenPath(repoPath) {
51002
51012
  return external_path_default().resolve(repoPath);
51003
51013
  }
@@ -51007,6 +51017,17 @@ var __webpack_exports__ = {};
51007
51017
  await openPathInEditorOrDefault(targetPath, preferredEditorCommand, deps);
51008
51018
  logger_logger.info(chalk_source.gray(`Opened ${targetPath}`));
51009
51019
  }
51020
+ async function configureWatchGitAuth(options, deps = defaultConfigureWatchGitAuthDeps) {
51021
+ await deps.configureCredentialHelperForUrl(options.repoPath, options.anvilUrl);
51022
+ await deps.setAppAuthBinding(options.repoPath, options.appId, {
51023
+ url: options.anvilUrl,
51024
+ username: options.username
51025
+ });
51026
+ }
51027
+ function isStaleRemotePushError(message) {
51028
+ const normalized = message.toLowerCase();
51029
+ return normalized.includes("fetch first") || normalized.includes("non-fast-forward") || normalized.includes("failed to push some refs") || normalized.includes("remote contains work that you do") || normalized.includes("[rejected]");
51030
+ }
51010
51031
  async function selectAppId(candidates) {
51011
51032
  if (0 === candidates.length) {
51012
51033
  logger_logger.warn("Could not auto-detect app ID from repository.");
@@ -51093,11 +51114,19 @@ var __webpack_exports__ = {};
51093
51114
  logger_logger.progress("push", "Pushing to Anvil...");
51094
51115
  await git.push(pushUrl, refSpec, options.force ?? false);
51095
51116
  logger_logger.progressEnd("push", "Pushed to Anvil");
51096
- return true;
51117
+ return {
51118
+ success: true,
51119
+ staleRemote: false
51120
+ };
51097
51121
  } catch (e) {
51122
+ const errorMessage = errors_getErrorMessage(e);
51098
51123
  logger_logger.progressEnd("push", "Push failed");
51099
- logger_logger.error(`Failed to push: ${errors_getErrorMessage(e)}`);
51100
- return false;
51124
+ logger_logger.error(`Failed to push: ${errorMessage}`);
51125
+ return {
51126
+ success: false,
51127
+ staleRemote: isStaleRemotePushError(errorMessage),
51128
+ errorMessage
51129
+ };
51101
51130
  }
51102
51131
  }
51103
51132
  async function fetchAndRebaseFromAnvil(options) {
@@ -51223,7 +51252,7 @@ var __webpack_exports__ = {};
51223
51252
  return false;
51224
51253
  }
51225
51254
  }
51226
- async function checkSyncStatusAndStart(session, options) {
51255
+ async function checkSyncStatusAndStart(session, options, deps = defaultSyncStartDeps) {
51227
51256
  const syncStatus = session.syncStatus;
51228
51257
  const branchName = session.getBranchName() || "master";
51229
51258
  const hasUncommitted = session.hasUncommittedChanges;
@@ -51236,8 +51265,8 @@ var __webpack_exports__ = {};
51236
51265
  else {
51237
51266
  shouldPush = await logger_logger.confirm("Would you like to push this branch to Anvil?", true);
51238
51267
  if (shouldPush) {
51239
- const changed = await recheckSyncStatus(stateCategory, branchName, options);
51240
- if (changed) return await checkSyncStatusAndStart(changed, options);
51268
+ const changed = await deps.recheckSyncStatus(stateCategory, branchName, options);
51269
+ if (changed) return await checkSyncStatusAndStart(changed, options, deps);
51241
51270
  }
51242
51271
  }
51243
51272
  if (!shouldPush) {
@@ -51246,15 +51275,21 @@ var __webpack_exports__ = {};
51246
51275
  return false;
51247
51276
  }
51248
51277
  session.cleanup();
51249
- const pushed = await pushToAnvil({
51278
+ const pushed = await deps.pushToAnvil({
51250
51279
  repoPath: options.repoPath,
51251
51280
  appId: options.appId,
51252
51281
  anvilUrl: options.anvilUrl,
51253
51282
  branchName,
51254
51283
  username: options.username
51255
51284
  });
51256
- if (!pushed) return false;
51257
- return await recreateSessionAndValidate(options);
51285
+ if (!pushed.success) {
51286
+ if (pushed.staleRemote) {
51287
+ logger_logger.warn("Branch appeared on Anvil while pushing. Re-checking sync status...");
51288
+ return await deps.recreateSessionAndValidate(options);
51289
+ }
51290
+ return false;
51291
+ }
51292
+ return await deps.recreateSessionAndValidate(options);
51258
51293
  }
51259
51294
  if (syncStatus?.behind || syncStatus?.ahead) if (syncStatus.ahead && !syncStatus.behind) {
51260
51295
  logger_logger.warn(`Your local repository is ${syncStatus.ahead} commit(s) ahead of Anvil.`);
@@ -51274,8 +51309,8 @@ var __webpack_exports__ = {};
51274
51309
  ], "push");
51275
51310
  shouldPush = "push" === action;
51276
51311
  if (shouldPush) {
51277
- const changed = await recheckSyncStatus(stateCategory, branchName, options);
51278
- if (changed) return await checkSyncStatusAndStart(changed, options);
51312
+ const changed = await deps.recheckSyncStatus(stateCategory, branchName, options);
51313
+ if (changed) return await checkSyncStatusAndStart(changed, options, deps);
51279
51314
  }
51280
51315
  }
51281
51316
  if (!shouldPush) {
@@ -51284,15 +51319,15 @@ var __webpack_exports__ = {};
51284
51319
  return false;
51285
51320
  }
51286
51321
  session.cleanup();
51287
- const pushed = await pushToAnvil({
51322
+ const pushed = await deps.pushToAnvil({
51288
51323
  repoPath: options.repoPath,
51289
51324
  appId: options.appId,
51290
51325
  anvilUrl: options.anvilUrl,
51291
51326
  branchName,
51292
51327
  username: options.username
51293
51328
  });
51294
- if (!pushed) return false;
51295
- return await recreateSessionAndValidate(options);
51329
+ if (!pushed.success) return false;
51330
+ return await deps.recreateSessionAndValidate(options);
51296
51331
  } else if (syncStatus.diverged) {
51297
51332
  logger_logger.warn("Your local repository has diverged from Anvil.");
51298
51333
  logger_logger.info(chalk_source.gray(` You are ${syncStatus.ahead} commit(s) ahead and ${syncStatus.behind} commit(s) behind.`));
@@ -51315,7 +51350,7 @@ var __webpack_exports__ = {};
51315
51350
  return false;
51316
51351
  }
51317
51352
  if (!result.success) return false;
51318
- return await recreateSessionAndValidate(options);
51353
+ return await deps.recreateSessionAndValidate(options);
51319
51354
  }
51320
51355
  const action = await logger_logger.select("How would you like to resolve this?", [
51321
51356
  {
@@ -51339,8 +51374,8 @@ var __webpack_exports__ = {};
51339
51374
  logger_logger.warn("Watch cancelled.");
51340
51375
  return false;
51341
51376
  }
51342
- const changed = await recheckSyncStatus(stateCategory, branchName, options);
51343
- if (changed) return await checkSyncStatusAndStart(changed, options);
51377
+ const changed = await deps.recheckSyncStatus(stateCategory, branchName, options);
51378
+ if (changed) return await checkSyncStatusAndStart(changed, options, deps);
51344
51379
  if ("rebase" === action) {
51345
51380
  const result = await fetchAndRebaseFromAnvil({
51346
51381
  repoPath: options.repoPath,
@@ -51357,7 +51392,7 @@ var __webpack_exports__ = {};
51357
51392
  return false;
51358
51393
  }
51359
51394
  if (!result.success) return false;
51360
- return await recreateSessionAndValidate(options);
51395
+ return await deps.recreateSessionAndValidate(options);
51361
51396
  }
51362
51397
  if ("reset" === action) {
51363
51398
  const resetWarning = hasUncommitted ? `This will discard ${syncStatus.ahead} local commit(s) and your uncommitted changes. Are you sure?` : `This will discard ${syncStatus.ahead} local commit(s). Are you sure?`;
@@ -51374,7 +51409,7 @@ var __webpack_exports__ = {};
51374
51409
  username: options.username
51375
51410
  });
51376
51411
  if (!reset) return false;
51377
- return await recreateSessionAndValidate(options);
51412
+ return await deps.recreateSessionAndValidate(options);
51378
51413
  }
51379
51414
  if ("push" === action) {
51380
51415
  const confirmed = await logger_logger.confirm("This will overwrite Anvil's version. Are you sure?", false);
@@ -51382,7 +51417,7 @@ var __webpack_exports__ = {};
51382
51417
  logger_logger.warn("Watch cancelled.");
51383
51418
  return false;
51384
51419
  }
51385
- const pushed = await pushToAnvil({
51420
+ const pushed = await deps.pushToAnvil({
51386
51421
  repoPath: options.repoPath,
51387
51422
  appId: options.appId,
51388
51423
  anvilUrl: options.anvilUrl,
@@ -51390,8 +51425,8 @@ var __webpack_exports__ = {};
51390
51425
  username: options.username,
51391
51426
  force: true
51392
51427
  });
51393
- if (!pushed) return false;
51394
- return await recreateSessionAndValidate(options);
51428
+ if (!pushed.success) return false;
51429
+ return await deps.recreateSessionAndValidate(options);
51395
51430
  }
51396
51431
  } else {
51397
51432
  logger_logger.warn(`Your local repository is ${syncStatus.behind} commit(s) behind Anvil.`);
@@ -51402,8 +51437,8 @@ var __webpack_exports__ = {};
51402
51437
  else {
51403
51438
  shouldSync = await logger_logger.confirm("Would you like to sync to the latest version from Anvil now?", true);
51404
51439
  if (shouldSync) {
51405
- const changed = await recheckSyncStatus(stateCategory, branchName, options);
51406
- if (changed) return await checkSyncStatusAndStart(changed, options);
51440
+ const changed = await deps.recheckSyncStatus(stateCategory, branchName, options);
51441
+ if (changed) return await checkSyncStatusAndStart(changed, options, deps);
51407
51442
  }
51408
51443
  }
51409
51444
  if (!shouldSync) {
@@ -51428,9 +51463,9 @@ var __webpack_exports__ = {};
51428
51463
  logger_logger.error(`Failed to sync: ${errors_getErrorMessage(e)}`);
51429
51464
  process.exit(1);
51430
51465
  }
51431
- return await recreateSessionAndValidate(options);
51466
+ return await deps.recreateSessionAndValidate(options);
51432
51467
  }
51433
- await startWatchingWithEventHandlers(session, options);
51468
+ await deps.startWatchingWithEventHandlers(session, options);
51434
51469
  return true;
51435
51470
  }
51436
51471
  async function startWatchingWithEventHandlers(session, options) {
@@ -51639,6 +51674,12 @@ var __webpack_exports__ = {};
51639
51674
  process.exit(1);
51640
51675
  }
51641
51676
  logger_logger.verbose(chalk_source.green("✓ Authentication tokens found"));
51677
+ await configureWatchGitAuth({
51678
+ repoPath,
51679
+ appId: finalAppId,
51680
+ anvilUrl,
51681
+ username
51682
+ });
51642
51683
  logger_logger.progress("validate", `Validating app ID: ${finalAppId}`);
51643
51684
  const appIdValidation = await validateAppId(finalAppId, anvilUrl, username);
51644
51685
  logger_logger.progressEnd("validate");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvil-works/anvil-cli",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "description": "CLI tool for developing Anvil apps locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",