@anvil-works/anvil-cli 0.3.9-canary.0 → 0.3.9

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 (3) hide show
  1. package/dist/cli.js +60 -27
  2. package/dist/index.js +60 -27
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -44512,6 +44512,17 @@ var __webpack_exports__ = {};
44512
44512
  getRepoPath() {
44513
44513
  return this.repoPath;
44514
44514
  }
44515
+ async getGitDir() {
44516
+ try {
44517
+ const gitDir = (await this.git.revparse([
44518
+ "--git-dir"
44519
+ ])).trim();
44520
+ if (!external_path_default().isAbsolute(gitDir)) return external_path_default().resolve(this.repoPath, gitDir);
44521
+ return gitDir;
44522
+ } catch (e) {
44523
+ throw createGitError.commandFailed("rev-parse --git-dir", e.message);
44524
+ }
44525
+ }
44515
44526
  async getCurrentBranch() {
44516
44527
  try {
44517
44528
  const branchRef = await this.git.revparse([
@@ -46198,6 +46209,7 @@ var __webpack_exports__ = {};
46198
46209
  };
46199
46210
  class FileWatcher extends Emitter_Emitter {
46200
46211
  repoPath;
46212
+ gitDir;
46201
46213
  stagedOnly;
46202
46214
  getCurrentBranch;
46203
46215
  headWatcher = null;
@@ -46207,6 +46219,7 @@ var __webpack_exports__ = {};
46207
46219
  constructor(options){
46208
46220
  super();
46209
46221
  this.repoPath = external_path_default().resolve(options.repoPath);
46222
+ this.gitDir = options.gitDir;
46210
46223
  this.stagedOnly = options.stagedOnly ?? false;
46211
46224
  this.getCurrentBranch = options.getCurrentBranch;
46212
46225
  this.sessionId = Math.random().toString(36).substring(2, 10);
@@ -46219,7 +46232,7 @@ var __webpack_exports__ = {};
46219
46232
  else this.startFileWatcher();
46220
46233
  }
46221
46234
  startHeadWatcher() {
46222
- const headPath = external_path_default().join(this.repoPath, ".git", "HEAD");
46235
+ const headPath = external_path_default().join(this.gitDir, "HEAD");
46223
46236
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up HEAD watcher: ${headPath}`);
46224
46237
  this.headWatcher = chokidar_esm.watch(headPath, {
46225
46238
  persistent: true,
@@ -46250,7 +46263,7 @@ var __webpack_exports__ = {};
46250
46263
  });
46251
46264
  }
46252
46265
  startIndexWatcher() {
46253
- const indexPath = external_path_default().join(this.repoPath, ".git", "index");
46266
+ const indexPath = external_path_default().join(this.gitDir, "index");
46254
46267
  logger_logger.verbose(`Setting up watcher for: ${indexPath}`);
46255
46268
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up index watcher (staged-only mode): ${indexPath}`);
46256
46269
  if (!external_fs_.existsSync(indexPath)) return void logger_logger.error(`ERROR: Git index file not found at ${indexPath}`);
@@ -46955,6 +46968,10 @@ var __webpack_exports__ = {};
46955
46968
  metadata: optional(any())
46956
46969
  });
46957
46970
  function validateAnvilYaml(yamlContent) {
46971
+ if (yamlContent.includes("<<<<<<<") || yamlContent.includes(">>>>>>>")) {
46972
+ logger_logger.error("anvil.yaml contains git merge conflict markers. Please resolve conflicts manually.");
46973
+ return false;
46974
+ }
46958
46975
  try {
46959
46976
  const data = js_yaml_load(yamlContent);
46960
46977
  const result = safeParse(AnvilYamlSchema, data);
@@ -48319,47 +48336,61 @@ var __webpack_exports__ = {};
48319
48336
  }
48320
48337
  class SyncManager extends Emitter_Emitter {
48321
48338
  config;
48339
+ syncInProgress = false;
48322
48340
  constructor(config){
48323
48341
  super();
48324
48342
  this.config = config;
48325
48343
  }
48326
48344
  async syncRemoteChanges(knownLocalChanges) {
48327
- const oldCommitId = this.config.getCommitId();
48328
- let locallyChangedFiles;
48329
- if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
48330
- else {
48331
- const status = await this.config.gitService.getStatus();
48332
- locallyChangedFiles = buildLocalChangesSet(status);
48333
- }
48334
- await this.fetchAndResetFromAnvil();
48335
- const newCommitId = await this.config.gitService.getCommitId();
48336
- this.config.setCommitId(newCommitId);
48337
- const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
48338
- const statusAfter = await this.config.gitService.getStatus();
48339
- const newChanges = extractChangesFromStatus(statusAfter);
48340
- if (0 === newChanges.length) {
48341
- logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
48345
+ if (this.syncInProgress) {
48346
+ logger_logger.debug("Sync already in progress, skipping");
48342
48347
  return {
48343
48348
  localOnlyChanges: [],
48344
48349
  conflicts: []
48345
48350
  };
48346
48351
  }
48347
- const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
48348
- await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
48349
- logConflictResolution(result);
48350
- return {
48351
- localOnlyChanges: result.localOnlyChanges,
48352
- conflicts: result.conflicts
48353
- };
48352
+ this.syncInProgress = true;
48353
+ try {
48354
+ const oldCommitId = this.config.getCommitId();
48355
+ let locallyChangedFiles;
48356
+ if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
48357
+ else {
48358
+ const status = await this.config.gitService.getStatus();
48359
+ locallyChangedFiles = buildLocalChangesSet(status);
48360
+ }
48361
+ await this.fetchAndResetFromAnvil();
48362
+ const newCommitId = await this.config.gitService.getCommitId();
48363
+ this.config.setCommitId(newCommitId);
48364
+ const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
48365
+ const statusAfter = await this.config.gitService.getStatus();
48366
+ const newChanges = extractChangesFromStatus(statusAfter);
48367
+ if (0 === newChanges.length) {
48368
+ logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
48369
+ return {
48370
+ localOnlyChanges: [],
48371
+ conflicts: []
48372
+ };
48373
+ }
48374
+ const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
48375
+ await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
48376
+ logConflictResolution(result);
48377
+ return {
48378
+ localOnlyChanges: result.localOnlyChanges,
48379
+ conflicts: result.conflicts
48380
+ };
48381
+ } finally{
48382
+ this.syncInProgress = false;
48383
+ }
48354
48384
  }
48355
48385
  async fetchAndResetFromAnvil() {
48356
48386
  const validToken = await auth_getValidAuthToken(this.config.anvilUrl, this.config.username);
48357
48387
  this.config.setAuthToken(validToken);
48358
48388
  const httpUrl = getGitFetchUrl(this.config.appId, this.config.getAuthToken(), this.config.anvilUrl);
48359
48389
  const currentBranch = this.config.getCurrentBranch();
48360
- await this.config.gitService.fetch(httpUrl, `+${currentBranch}:anvil-sync-temp`);
48361
- await this.config.gitService.reset("anvil-sync-temp", "mixed");
48362
- await this.config.gitService.deleteRef("refs/heads/anvil-sync-temp");
48390
+ const tempRef = `anvil-sync-temp-${Date.now()}`;
48391
+ await this.config.gitService.fetch(httpUrl, `+${currentBranch}:${tempRef}`);
48392
+ await this.config.gitService.reset(tempRef, "mixed");
48393
+ await this.config.gitService.deleteRef(`refs/heads/${tempRef}`);
48363
48394
  await this.config.gitService.checkout([
48364
48395
  ".anvil_editor.yaml",
48365
48396
  "anvil.yaml"
@@ -48619,8 +48650,10 @@ var __webpack_exports__ = {};
48619
48650
  }
48620
48651
  async startWatching() {
48621
48652
  logger_logger.debug(`[Session ${this.sessionId}]`, "Starting watchers...");
48653
+ const gitDir = await this.gitService.getGitDir();
48622
48654
  this.fileWatcher = new FileWatcher({
48623
48655
  repoPath: this.repoPath,
48656
+ gitDir,
48624
48657
  stagedOnly: this.stagedOnly,
48625
48658
  getCurrentBranch: async ()=>this.gitService.getCurrentBranch()
48626
48659
  });
package/dist/index.js CHANGED
@@ -19658,6 +19658,17 @@ var __webpack_exports__ = {};
19658
19658
  getRepoPath() {
19659
19659
  return this.repoPath;
19660
19660
  }
19661
+ async getGitDir() {
19662
+ try {
19663
+ const gitDir = (await this.git.revparse([
19664
+ "--git-dir"
19665
+ ])).trim();
19666
+ if (!external_path_default().isAbsolute(gitDir)) return external_path_default().resolve(this.repoPath, gitDir);
19667
+ return gitDir;
19668
+ } catch (e) {
19669
+ throw createGitError.commandFailed("rev-parse --git-dir", e.message);
19670
+ }
19671
+ }
19661
19672
  async getCurrentBranch() {
19662
19673
  try {
19663
19674
  const branchRef = await this.git.revparse([
@@ -21344,6 +21355,7 @@ var __webpack_exports__ = {};
21344
21355
  };
21345
21356
  class FileWatcher extends Emitter {
21346
21357
  repoPath;
21358
+ gitDir;
21347
21359
  stagedOnly;
21348
21360
  getCurrentBranch;
21349
21361
  headWatcher = null;
@@ -21353,6 +21365,7 @@ var __webpack_exports__ = {};
21353
21365
  constructor(options){
21354
21366
  super();
21355
21367
  this.repoPath = external_path_default().resolve(options.repoPath);
21368
+ this.gitDir = options.gitDir;
21356
21369
  this.stagedOnly = options.stagedOnly ?? false;
21357
21370
  this.getCurrentBranch = options.getCurrentBranch;
21358
21371
  this.sessionId = Math.random().toString(36).substring(2, 10);
@@ -21365,7 +21378,7 @@ var __webpack_exports__ = {};
21365
21378
  else this.startFileWatcher();
21366
21379
  }
21367
21380
  startHeadWatcher() {
21368
- const headPath = external_path_default().join(this.repoPath, ".git", "HEAD");
21381
+ const headPath = external_path_default().join(this.gitDir, "HEAD");
21369
21382
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up HEAD watcher: ${headPath}`);
21370
21383
  this.headWatcher = chokidar_esm.watch(headPath, {
21371
21384
  persistent: true,
@@ -21396,7 +21409,7 @@ var __webpack_exports__ = {};
21396
21409
  });
21397
21410
  }
21398
21411
  startIndexWatcher() {
21399
- const indexPath = external_path_default().join(this.repoPath, ".git", "index");
21412
+ const indexPath = external_path_default().join(this.gitDir, "index");
21400
21413
  logger_logger.verbose(`Setting up watcher for: ${indexPath}`);
21401
21414
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up index watcher (staged-only mode): ${indexPath}`);
21402
21415
  if (!external_fs_.existsSync(indexPath)) return void logger_logger.error(`ERROR: Git index file not found at ${indexPath}`);
@@ -22553,6 +22566,10 @@ var __webpack_exports__ = {};
22553
22566
  metadata: optional(any())
22554
22567
  });
22555
22568
  function validateAnvilYaml(yamlContent) {
22569
+ if (yamlContent.includes("<<<<<<<") || yamlContent.includes(">>>>>>>")) {
22570
+ logger_logger.error("anvil.yaml contains git merge conflict markers. Please resolve conflicts manually.");
22571
+ return false;
22572
+ }
22556
22573
  try {
22557
22574
  const data = load(yamlContent);
22558
22575
  const result = safeParse(AnvilYamlSchema, data);
@@ -23917,47 +23934,61 @@ var __webpack_exports__ = {};
23917
23934
  }
23918
23935
  class SyncManager extends Emitter {
23919
23936
  config;
23937
+ syncInProgress = false;
23920
23938
  constructor(config){
23921
23939
  super();
23922
23940
  this.config = config;
23923
23941
  }
23924
23942
  async syncRemoteChanges(knownLocalChanges) {
23925
- const oldCommitId = this.config.getCommitId();
23926
- let locallyChangedFiles;
23927
- if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
23928
- else {
23929
- const status = await this.config.gitService.getStatus();
23930
- locallyChangedFiles = buildLocalChangesSet(status);
23931
- }
23932
- await this.fetchAndResetFromAnvil();
23933
- const newCommitId = await this.config.gitService.getCommitId();
23934
- this.config.setCommitId(newCommitId);
23935
- const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
23936
- const statusAfter = await this.config.gitService.getStatus();
23937
- const newChanges = extractChangesFromStatus(statusAfter);
23938
- if (0 === newChanges.length) {
23939
- logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
23943
+ if (this.syncInProgress) {
23944
+ logger_logger.debug("Sync already in progress, skipping");
23940
23945
  return {
23941
23946
  localOnlyChanges: [],
23942
23947
  conflicts: []
23943
23948
  };
23944
23949
  }
23945
- const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
23946
- await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
23947
- logConflictResolution(result);
23948
- return {
23949
- localOnlyChanges: result.localOnlyChanges,
23950
- conflicts: result.conflicts
23951
- };
23950
+ this.syncInProgress = true;
23951
+ try {
23952
+ const oldCommitId = this.config.getCommitId();
23953
+ let locallyChangedFiles;
23954
+ if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
23955
+ else {
23956
+ const status = await this.config.gitService.getStatus();
23957
+ locallyChangedFiles = buildLocalChangesSet(status);
23958
+ }
23959
+ await this.fetchAndResetFromAnvil();
23960
+ const newCommitId = await this.config.gitService.getCommitId();
23961
+ this.config.setCommitId(newCommitId);
23962
+ const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
23963
+ const statusAfter = await this.config.gitService.getStatus();
23964
+ const newChanges = extractChangesFromStatus(statusAfter);
23965
+ if (0 === newChanges.length) {
23966
+ logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
23967
+ return {
23968
+ localOnlyChanges: [],
23969
+ conflicts: []
23970
+ };
23971
+ }
23972
+ const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
23973
+ await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
23974
+ logConflictResolution(result);
23975
+ return {
23976
+ localOnlyChanges: result.localOnlyChanges,
23977
+ conflicts: result.conflicts
23978
+ };
23979
+ } finally{
23980
+ this.syncInProgress = false;
23981
+ }
23952
23982
  }
23953
23983
  async fetchAndResetFromAnvil() {
23954
23984
  const validToken = await auth_getValidAuthToken(this.config.anvilUrl, this.config.username);
23955
23985
  this.config.setAuthToken(validToken);
23956
23986
  const httpUrl = getGitFetchUrl(this.config.appId, this.config.getAuthToken(), this.config.anvilUrl);
23957
23987
  const currentBranch = this.config.getCurrentBranch();
23958
- await this.config.gitService.fetch(httpUrl, `+${currentBranch}:anvil-sync-temp`);
23959
- await this.config.gitService.reset("anvil-sync-temp", "mixed");
23960
- await this.config.gitService.deleteRef("refs/heads/anvil-sync-temp");
23988
+ const tempRef = `anvil-sync-temp-${Date.now()}`;
23989
+ await this.config.gitService.fetch(httpUrl, `+${currentBranch}:${tempRef}`);
23990
+ await this.config.gitService.reset(tempRef, "mixed");
23991
+ await this.config.gitService.deleteRef(`refs/heads/${tempRef}`);
23961
23992
  await this.config.gitService.checkout([
23962
23993
  ".anvil_editor.yaml",
23963
23994
  "anvil.yaml"
@@ -24217,8 +24248,10 @@ var __webpack_exports__ = {};
24217
24248
  }
24218
24249
  async startWatching() {
24219
24250
  logger_logger.debug(`[Session ${this.sessionId}]`, "Starting watchers...");
24251
+ const gitDir = await this.gitService.getGitDir();
24220
24252
  this.fileWatcher = new FileWatcher({
24221
24253
  repoPath: this.repoPath,
24254
+ gitDir,
24222
24255
  stagedOnly: this.stagedOnly,
24223
24256
  getCurrentBranch: async ()=>this.gitService.getCurrentBranch()
24224
24257
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvil-works/anvil-cli",
3
- "version": "0.3.9-canary.0",
3
+ "version": "0.3.9",
4
4
  "description": "CLI tool for developing Anvil apps locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",