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

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 +35 -64
  2. package/dist/index.js +35 -64
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -44512,17 +44512,6 @@ 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
- }
44526
44515
  async getCurrentBranch() {
44527
44516
  try {
44528
44517
  const branchRef = await this.git.revparse([
@@ -44744,6 +44733,9 @@ var __webpack_exports__ = {};
44744
44733
  throw createGitError.commandFailed("status", e.message);
44745
44734
  }
44746
44735
  }
44736
+ function normalizeLineEndings(content) {
44737
+ return content.replace(/\r\n/g, "\n");
44738
+ }
44747
44739
  function pythonifyName(name) {
44748
44740
  return name.replace(/[^A-z0-9]/g, "_").replace(/^[0-9]/, "_$&");
44749
44741
  }
@@ -46206,7 +46198,6 @@ var __webpack_exports__ = {};
46206
46198
  };
46207
46199
  class FileWatcher extends Emitter_Emitter {
46208
46200
  repoPath;
46209
- gitDir;
46210
46201
  stagedOnly;
46211
46202
  getCurrentBranch;
46212
46203
  headWatcher = null;
@@ -46216,7 +46207,6 @@ var __webpack_exports__ = {};
46216
46207
  constructor(options){
46217
46208
  super();
46218
46209
  this.repoPath = external_path_default().resolve(options.repoPath);
46219
- this.gitDir = options.gitDir;
46220
46210
  this.stagedOnly = options.stagedOnly ?? false;
46221
46211
  this.getCurrentBranch = options.getCurrentBranch;
46222
46212
  this.sessionId = Math.random().toString(36).substring(2, 10);
@@ -46229,7 +46219,7 @@ var __webpack_exports__ = {};
46229
46219
  else this.startFileWatcher();
46230
46220
  }
46231
46221
  startHeadWatcher() {
46232
- const headPath = external_path_default().join(this.gitDir, "HEAD");
46222
+ const headPath = external_path_default().join(this.repoPath, ".git", "HEAD");
46233
46223
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up HEAD watcher: ${headPath}`);
46234
46224
  this.headWatcher = chokidar_esm.watch(headPath, {
46235
46225
  persistent: true,
@@ -46260,7 +46250,7 @@ var __webpack_exports__ = {};
46260
46250
  });
46261
46251
  }
46262
46252
  startIndexWatcher() {
46263
- const indexPath = external_path_default().join(this.gitDir, "index");
46253
+ const indexPath = external_path_default().join(this.repoPath, ".git", "index");
46264
46254
  logger_logger.verbose(`Setting up watcher for: ${indexPath}`);
46265
46255
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up index watcher (staged-only mode): ${indexPath}`);
46266
46256
  if (!external_fs_.existsSync(indexPath)) return void logger_logger.error(`ERROR: Git index file not found at ${indexPath}`);
@@ -46965,10 +46955,6 @@ var __webpack_exports__ = {};
46965
46955
  metadata: optional(any())
46966
46956
  });
46967
46957
  function validateAnvilYaml(yamlContent) {
46968
- if (yamlContent.includes("<<<<<<<") || yamlContent.includes(">>>>>>>")) {
46969
- logger_logger.error("anvil.yaml contains git merge conflict markers. Please resolve conflicts manually.");
46970
- return false;
46971
- }
46972
46958
  try {
46973
46959
  const data = js_yaml_load(yamlContent);
46974
46960
  const result = safeParse(AnvilYamlSchema, data);
@@ -47107,13 +47093,14 @@ var __webpack_exports__ = {};
47107
47093
  };
47108
47094
  }
47109
47095
  async function readFileContent(repoPath, relativePath, stagedOnly) {
47110
- if (!stagedOnly) return await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath), "utf8");
47111
- {
47096
+ let content;
47097
+ if (stagedOnly) {
47112
47098
  const git = esm_default(repoPath);
47113
- return await git.show([
47099
+ content = await git.show([
47114
47100
  `:${relativePath}`
47115
47101
  ]);
47116
- }
47102
+ } else content = await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath), "utf8");
47103
+ return normalizeLineEndings(content);
47117
47104
  }
47118
47105
  async function readBinaryFileContent(repoPath, relativePath, stagedOnly) {
47119
47106
  if (!stagedOnly) return await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath));
@@ -48332,61 +48319,47 @@ var __webpack_exports__ = {};
48332
48319
  }
48333
48320
  class SyncManager extends Emitter_Emitter {
48334
48321
  config;
48335
- syncInProgress = false;
48336
48322
  constructor(config){
48337
48323
  super();
48338
48324
  this.config = config;
48339
48325
  }
48340
48326
  async syncRemoteChanges(knownLocalChanges) {
48341
- if (this.syncInProgress) {
48342
- logger_logger.debug("Sync already in progress, skipping");
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"));
48343
48342
  return {
48344
48343
  localOnlyChanges: [],
48345
48344
  conflicts: []
48346
48345
  };
48347
48346
  }
48348
- this.syncInProgress = true;
48349
- try {
48350
- const oldCommitId = this.config.getCommitId();
48351
- let locallyChangedFiles;
48352
- if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
48353
- else {
48354
- const status = await this.config.gitService.getStatus();
48355
- locallyChangedFiles = buildLocalChangesSet(status);
48356
- }
48357
- await this.fetchAndResetFromAnvil();
48358
- const newCommitId = await this.config.gitService.getCommitId();
48359
- this.config.setCommitId(newCommitId);
48360
- const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
48361
- const statusAfter = await this.config.gitService.getStatus();
48362
- const newChanges = extractChangesFromStatus(statusAfter);
48363
- if (0 === newChanges.length) {
48364
- logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
48365
- return {
48366
- localOnlyChanges: [],
48367
- conflicts: []
48368
- };
48369
- }
48370
- const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
48371
- await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
48372
- logConflictResolution(result);
48373
- return {
48374
- localOnlyChanges: result.localOnlyChanges,
48375
- conflicts: result.conflicts
48376
- };
48377
- } finally{
48378
- this.syncInProgress = false;
48379
- }
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
+ };
48380
48354
  }
48381
48355
  async fetchAndResetFromAnvil() {
48382
48356
  const validToken = await auth_getValidAuthToken(this.config.anvilUrl, this.config.username);
48383
48357
  this.config.setAuthToken(validToken);
48384
48358
  const httpUrl = getGitFetchUrl(this.config.appId, this.config.getAuthToken(), this.config.anvilUrl);
48385
48359
  const currentBranch = this.config.getCurrentBranch();
48386
- const tempRef = `anvil-sync-temp-${Date.now()}`;
48387
- await this.config.gitService.fetch(httpUrl, `+${currentBranch}:${tempRef}`);
48388
- await this.config.gitService.reset(tempRef, "mixed");
48389
- await this.config.gitService.deleteRef(`refs/heads/${tempRef}`);
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
48363
  await this.config.gitService.checkout([
48391
48364
  ".anvil_editor.yaml",
48392
48365
  "anvil.yaml"
@@ -48646,10 +48619,8 @@ var __webpack_exports__ = {};
48646
48619
  }
48647
48620
  async startWatching() {
48648
48621
  logger_logger.debug(`[Session ${this.sessionId}]`, "Starting watchers...");
48649
- const gitDir = await this.gitService.getGitDir();
48650
48622
  this.fileWatcher = new FileWatcher({
48651
48623
  repoPath: this.repoPath,
48652
- gitDir,
48653
48624
  stagedOnly: this.stagedOnly,
48654
48625
  getCurrentBranch: async ()=>this.gitService.getCurrentBranch()
48655
48626
  });
package/dist/index.js CHANGED
@@ -19658,17 +19658,6 @@ 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
- }
19672
19661
  async getCurrentBranch() {
19673
19662
  try {
19674
19663
  const branchRef = await this.git.revparse([
@@ -19890,6 +19879,9 @@ var __webpack_exports__ = {};
19890
19879
  throw createGitError.commandFailed("status", e.message);
19891
19880
  }
19892
19881
  }
19882
+ function normalizeLineEndings(content) {
19883
+ return content.replace(/\r\n/g, "\n");
19884
+ }
19893
19885
  function pythonifyName(name) {
19894
19886
  return name.replace(/[^A-z0-9]/g, "_").replace(/^[0-9]/, "_$&");
19895
19887
  }
@@ -21352,7 +21344,6 @@ var __webpack_exports__ = {};
21352
21344
  };
21353
21345
  class FileWatcher extends Emitter {
21354
21346
  repoPath;
21355
- gitDir;
21356
21347
  stagedOnly;
21357
21348
  getCurrentBranch;
21358
21349
  headWatcher = null;
@@ -21362,7 +21353,6 @@ var __webpack_exports__ = {};
21362
21353
  constructor(options){
21363
21354
  super();
21364
21355
  this.repoPath = external_path_default().resolve(options.repoPath);
21365
- this.gitDir = options.gitDir;
21366
21356
  this.stagedOnly = options.stagedOnly ?? false;
21367
21357
  this.getCurrentBranch = options.getCurrentBranch;
21368
21358
  this.sessionId = Math.random().toString(36).substring(2, 10);
@@ -21375,7 +21365,7 @@ var __webpack_exports__ = {};
21375
21365
  else this.startFileWatcher();
21376
21366
  }
21377
21367
  startHeadWatcher() {
21378
- const headPath = external_path_default().join(this.gitDir, "HEAD");
21368
+ const headPath = external_path_default().join(this.repoPath, ".git", "HEAD");
21379
21369
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up HEAD watcher: ${headPath}`);
21380
21370
  this.headWatcher = chokidar_esm.watch(headPath, {
21381
21371
  persistent: true,
@@ -21406,7 +21396,7 @@ var __webpack_exports__ = {};
21406
21396
  });
21407
21397
  }
21408
21398
  startIndexWatcher() {
21409
- const indexPath = external_path_default().join(this.gitDir, "index");
21399
+ const indexPath = external_path_default().join(this.repoPath, ".git", "index");
21410
21400
  logger_logger.verbose(`Setting up watcher for: ${indexPath}`);
21411
21401
  logger_logger.debug(`[FileWatcher ${this.sessionId}]`, `Setting up index watcher (staged-only mode): ${indexPath}`);
21412
21402
  if (!external_fs_.existsSync(indexPath)) return void logger_logger.error(`ERROR: Git index file not found at ${indexPath}`);
@@ -22563,10 +22553,6 @@ var __webpack_exports__ = {};
22563
22553
  metadata: optional(any())
22564
22554
  });
22565
22555
  function validateAnvilYaml(yamlContent) {
22566
- if (yamlContent.includes("<<<<<<<") || yamlContent.includes(">>>>>>>")) {
22567
- logger_logger.error("anvil.yaml contains git merge conflict markers. Please resolve conflicts manually.");
22568
- return false;
22569
- }
22570
22556
  try {
22571
22557
  const data = load(yamlContent);
22572
22558
  const result = safeParse(AnvilYamlSchema, data);
@@ -22705,13 +22691,14 @@ var __webpack_exports__ = {};
22705
22691
  };
22706
22692
  }
22707
22693
  async function readFileContent(repoPath, relativePath, stagedOnly) {
22708
- if (!stagedOnly) return await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath), "utf8");
22709
- {
22694
+ let content;
22695
+ if (stagedOnly) {
22710
22696
  const git = esm_default(repoPath);
22711
- return await git.show([
22697
+ content = await git.show([
22712
22698
  `:${relativePath}`
22713
22699
  ]);
22714
- }
22700
+ } else content = await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath), "utf8");
22701
+ return normalizeLineEndings(content);
22715
22702
  }
22716
22703
  async function readBinaryFileContent(repoPath, relativePath, stagedOnly) {
22717
22704
  if (!stagedOnly) return await external_fs_.promises.readFile(external_path_default().join(repoPath, relativePath));
@@ -23930,61 +23917,47 @@ var __webpack_exports__ = {};
23930
23917
  }
23931
23918
  class SyncManager extends Emitter {
23932
23919
  config;
23933
- syncInProgress = false;
23934
23920
  constructor(config){
23935
23921
  super();
23936
23922
  this.config = config;
23937
23923
  }
23938
23924
  async syncRemoteChanges(knownLocalChanges) {
23939
- if (this.syncInProgress) {
23940
- logger_logger.debug("Sync already in progress, skipping");
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"));
23941
23940
  return {
23942
23941
  localOnlyChanges: [],
23943
23942
  conflicts: []
23944
23943
  };
23945
23944
  }
23946
- this.syncInProgress = true;
23947
- try {
23948
- const oldCommitId = this.config.getCommitId();
23949
- let locallyChangedFiles;
23950
- if (knownLocalChanges) locallyChangedFiles = knownLocalChanges;
23951
- else {
23952
- const status = await this.config.gitService.getStatus();
23953
- locallyChangedFiles = buildLocalChangesSet(status);
23954
- }
23955
- await this.fetchAndResetFromAnvil();
23956
- const newCommitId = await this.config.gitService.getCommitId();
23957
- this.config.setCommitId(newCommitId);
23958
- const remoteChangedFiles = await detectRemoteChanges(this.config.gitService, oldCommitId, newCommitId);
23959
- const statusAfter = await this.config.gitService.getStatus();
23960
- const newChanges = extractChangesFromStatus(statusAfter);
23961
- if (0 === newChanges.length) {
23962
- logger_logger.verbose(chalk_source.gray(" No local changes - working directory is clean"));
23963
- return {
23964
- localOnlyChanges: [],
23965
- conflicts: []
23966
- };
23967
- }
23968
- const result = categorizeChanges(newChanges, locallyChangedFiles, remoteChangedFiles);
23969
- await acceptRemoteChanges(this.config.gitService, result.remoteOnlyChanges);
23970
- logConflictResolution(result);
23971
- return {
23972
- localOnlyChanges: result.localOnlyChanges,
23973
- conflicts: result.conflicts
23974
- };
23975
- } finally{
23976
- this.syncInProgress = false;
23977
- }
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
+ };
23978
23952
  }
23979
23953
  async fetchAndResetFromAnvil() {
23980
23954
  const validToken = await auth_getValidAuthToken(this.config.anvilUrl, this.config.username);
23981
23955
  this.config.setAuthToken(validToken);
23982
23956
  const httpUrl = getGitFetchUrl(this.config.appId, this.config.getAuthToken(), this.config.anvilUrl);
23983
23957
  const currentBranch = this.config.getCurrentBranch();
23984
- const tempRef = `anvil-sync-temp-${Date.now()}`;
23985
- await this.config.gitService.fetch(httpUrl, `+${currentBranch}:${tempRef}`);
23986
- await this.config.gitService.reset(tempRef, "mixed");
23987
- await this.config.gitService.deleteRef(`refs/heads/${tempRef}`);
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
23961
  await this.config.gitService.checkout([
23989
23962
  ".anvil_editor.yaml",
23990
23963
  "anvil.yaml"
@@ -24244,10 +24217,8 @@ var __webpack_exports__ = {};
24244
24217
  }
24245
24218
  async startWatching() {
24246
24219
  logger_logger.debug(`[Session ${this.sessionId}]`, "Starting watchers...");
24247
- const gitDir = await this.gitService.getGitDir();
24248
24220
  this.fileWatcher = new FileWatcher({
24249
24221
  repoPath: this.repoPath,
24250
- gitDir,
24251
24222
  stagedOnly: this.stagedOnly,
24252
24223
  getCurrentBranch: async ()=>this.gitService.getCurrentBranch()
24253
24224
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvil-works/anvil-cli",
3
- "version": "0.3.8",
3
+ "version": "0.3.9-canary.0",
4
4
  "description": "CLI tool for developing Anvil apps locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",