@spica/cli 0.18.40 → 0.18.42

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/index.js +405 -439
  2. package/package.json +1 -37
package/index.js CHANGED
@@ -90,7 +90,7 @@ $\xA0spica context switch <name> to switch context.`
90
90
  return searchResult.config;
91
91
  }
92
92
  config2.get = get;
93
- async function path19() {
93
+ async function path15() {
94
94
  let config3 = await explorer.search(process.cwd());
95
95
  if (!config3) {
96
96
  config3 = await explorer.search(os.homedir());
@@ -100,9 +100,9 @@ $\xA0spica context switch <name> to switch context.`
100
100
  }
101
101
  return void 0;
102
102
  }
103
- config2.path = path19;
103
+ config2.path = path15;
104
104
  async function set(config3) {
105
- let configPath = await path19();
105
+ let configPath = await path15();
106
106
  if (!configPath) {
107
107
  configPath = _path.join(os.homedir(), ".spicarc");
108
108
  }
@@ -3236,8 +3236,8 @@ function isNotFoundException(e) {
3236
3236
  const code = 404;
3237
3237
  return e.status == code || e.statusCode == code || e.data && e.data.statusCode == code;
3238
3238
  }
3239
- async function getFilteredResources(path19, service, ids, paginate) {
3240
- const res = await service.get(path19);
3239
+ async function getFilteredResources(path15, service, ids, paginate) {
3240
+ const res = await service.get(path15);
3241
3241
  const resources = paginate ? res.data : res;
3242
3242
  return ids ? resources.filter((resource) => ids.includes(resource._id)) : resources;
3243
3243
  }
@@ -3429,25 +3429,111 @@ function upgrade_default(program2) {
3429
3429
  }
3430
3430
 
3431
3431
  // apps/cli/src/commands/sync/plan.ts
3432
- import path15 from "path";
3432
+ import path11 from "path";
3433
+
3434
+ // packages/sync/dist/src/types.js
3435
+ var ChangeKind;
3436
+ (function(ChangeKind2) {
3437
+ ChangeKind2["Create"] = "create";
3438
+ ChangeKind2["Update"] = "update";
3439
+ ChangeKind2["Delete"] = "delete";
3440
+ })(ChangeKind || (ChangeKind = {}));
3441
+
3442
+ // packages/sync/dist/src/reporter.js
3443
+ var noopProgress = {
3444
+ update() {
3445
+ },
3446
+ succeed() {
3447
+ },
3448
+ fail() {
3449
+ }
3450
+ };
3451
+ var silentReporter = {
3452
+ task: (_label, op) => op(),
3453
+ progress: () => noopProgress,
3454
+ warn() {
3455
+ }
3456
+ };
3457
+
3458
+ // packages/sync/dist/src/fs-utils.js
3459
+ import fs9 from "fs";
3460
+ import path9 from "path";
3461
+ import yaml from "yaml";
3462
+ function ensureDir(dir) {
3463
+ fs9.mkdirSync(dir, { recursive: true });
3464
+ }
3465
+ function listFolders(dir) {
3466
+ if (!fs9.existsSync(dir))
3467
+ return [];
3468
+ return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
3469
+ }
3470
+ function readYaml(filePath) {
3471
+ if (!fs9.existsSync(filePath))
3472
+ return null;
3473
+ return yaml.parse(fs9.readFileSync(filePath, "utf-8"));
3474
+ }
3475
+ function writeYaml(filePath, data) {
3476
+ ensureDir(path9.dirname(filePath));
3477
+ fs9.writeFileSync(filePath, yaml.stringify(data), "utf-8");
3478
+ }
3479
+ function readText(filePath) {
3480
+ if (!fs9.existsSync(filePath))
3481
+ return null;
3482
+ return fs9.readFileSync(filePath, "utf-8");
3483
+ }
3484
+ function writeText(filePath, content) {
3485
+ ensureDir(path9.dirname(filePath));
3486
+ fs9.writeFileSync(filePath, content, "utf-8");
3487
+ }
3488
+ function removeDir(dir) {
3489
+ if (fs9.existsSync(dir)) {
3490
+ fs9.rmSync(dir, { recursive: true, force: true });
3491
+ }
3492
+ }
3493
+ function omit(obj, fields) {
3494
+ const clone = structuredClone(obj);
3495
+ for (const f of fields)
3496
+ delete clone[f];
3497
+ return clone;
3498
+ }
3499
+ function sanitizeSlug(slug) {
3500
+ return path9.basename(path9.normalize(slug));
3501
+ }
3502
+ function unwrapList(res) {
3503
+ if (Array.isArray(res))
3504
+ return res;
3505
+ return res.data ?? [];
3506
+ }
3507
+ async function readLocalSchemas(rootDir, moduleName) {
3508
+ const dir = path9.join(rootDir, moduleName);
3509
+ const slugs = listFolders(dir);
3510
+ const results = [];
3511
+ for (const slug of slugs) {
3512
+ const data = readYaml(path9.join(dir, slug, "schema.yaml"));
3513
+ if (data)
3514
+ results.push({ slug, data });
3515
+ }
3516
+ return results;
3517
+ }
3518
+ function writeLocalSchema(rootDir, moduleName, remote) {
3519
+ const dir = path9.join(rootDir, moduleName, remote.slug);
3520
+ writeYaml(path9.join(dir, "schema.yaml"), remote.data);
3521
+ }
3522
+ function deleteLocalSchema(rootDir, moduleName, slug) {
3523
+ removeDir(path9.join(rootDir, moduleName, slug));
3524
+ }
3433
3525
 
3434
- // apps/cli/src/commands/sync/planner.ts
3526
+ // packages/sync/dist/src/planner.js
3435
3527
  import { bold as bold4, cyan, green as green4, red as red4, yellow as yellow2 } from "colorette";
3436
3528
  import isEqual2 from "lodash/isEqual.js";
3437
3529
  import { createTwoFilesPatch } from "diff";
3438
- import ora2 from "ora";
3439
- async function buildPlan(modules, http2, rootDir, detailed = false, detectRenames = true) {
3530
+ import yaml2 from "yaml";
3531
+ async function buildPlan(modules, http2, rootDir, detailed = false, detectRenames = true, reporter = silentReporter) {
3440
3532
  const modulePlans = [];
3441
3533
  for (const mod of modules) {
3442
3534
  const [locals, remotes] = await Promise.all([
3443
- spin({
3444
- text: `Reading local ${mod.displayName} files`,
3445
- op: () => mod.readLocal(rootDir)
3446
- }),
3447
- spin({
3448
- text: `Fetching remote ${mod.displayName}`,
3449
- op: () => mod.readRemote(http2)
3450
- })
3535
+ reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
3536
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http2))
3451
3537
  ]);
3452
3538
  const localBySlug = new Map(locals.map((l) => [l.slug, l]));
3453
3539
  const remoteBySlug = new Map(remotes.map((r) => [r.slug, r]));
@@ -3458,7 +3544,7 @@ async function buildPlan(modules, http2, rootDir, detailed = false, detectRename
3458
3544
  const remote = remoteBySlug.get(local.slug);
3459
3545
  if (!remote) {
3460
3546
  creates.push({
3461
- kind: "create" /* Create */,
3547
+ kind: ChangeKind.Create,
3462
3548
  slug: local.slug,
3463
3549
  summary: mod.summaryLine(local),
3464
3550
  changedFields: [],
@@ -3470,7 +3556,7 @@ async function buildPlan(modules, http2, rootDir, detailed = false, detectRename
3470
3556
  const changedFields = mod.diffFields(local.data, remote.data);
3471
3557
  if (changedFields.length > 0) {
3472
3558
  updates.push({
3473
- kind: "update" /* Update */,
3559
+ kind: ChangeKind.Update,
3474
3560
  slug: local.slug,
3475
3561
  summary: mod.summaryLine(local),
3476
3562
  changedFields,
@@ -3484,7 +3570,7 @@ async function buildPlan(modules, http2, rootDir, detailed = false, detectRename
3484
3570
  for (const remote of remotes) {
3485
3571
  if (!localBySlug.has(remote.slug)) {
3486
3572
  deletes.push({
3487
- kind: "delete" /* Delete */,
3573
+ kind: ChangeKind.Delete,
3488
3574
  slug: remote.slug,
3489
3575
  summary: mod.summaryLine(remote),
3490
3576
  changedFields: [],
@@ -3505,7 +3591,7 @@ async function buildPlan(modules, http2, rootDir, detailed = false, detectRename
3505
3591
  promotedRemoteIds.add(matchedDelete.remote.id);
3506
3592
  const changedFields = mod.diffFields(create2.local.data, matchedDelete.remote.data);
3507
3593
  updates.push({
3508
- kind: "update" /* Update */,
3594
+ kind: ChangeKind.Update,
3509
3595
  slug: create2.slug,
3510
3596
  summary: mod.summaryLine(create2.local),
3511
3597
  changedFields,
@@ -3518,11 +3604,7 @@ async function buildPlan(modules, http2, rootDir, detailed = false, detectRename
3518
3604
  }
3519
3605
  }
3520
3606
  creates.splice(0, creates.length, ...remainingCreates);
3521
- deletes.splice(
3522
- 0,
3523
- deletes.length,
3524
- ...deletes.filter((e) => !promotedRemoteIds.has(e.remote.id))
3525
- );
3607
+ deletes.splice(0, deletes.length, ...deletes.filter((e) => !promotedRemoteIds.has(e.remote.id)));
3526
3608
  }
3527
3609
  modulePlans.push({ module: mod, creates, updates, deletes });
3528
3610
  }
@@ -3554,22 +3636,20 @@ function renderPlan(plan2, opts = {}) {
3554
3636
  }
3555
3637
  for (const mp of plan2.modules) {
3556
3638
  const { module: mod, creates, updates, deletes } = mp;
3557
- if (!creates.length && !updates.length && !deletes.length) continue;
3639
+ if (!creates.length && !updates.length && !deletes.length)
3640
+ continue;
3558
3641
  const staleCount = opts.clean ? creates.length : 0;
3559
- console.log(
3560
- `
3561
- ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${summaryBadges(deletes.length, updates.length, staleCount)}`
3562
- );
3642
+ console.log(`
3643
+ ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${summaryBadges(deletes.length, updates.length, staleCount)}`);
3563
3644
  for (const e of deletes) {
3564
3645
  console.log(` ${green4("+")} ${bold4(e.slug)} ${dim(e.summary)}`);
3565
3646
  }
3566
3647
  for (const e of updates) {
3567
- console.log(
3568
- ` ${yellow2("~")} ${bold4(e.slug)} ${dim(e.summary)} ${yellow2(`[${e.changedFields.join(", ")}]`)}`
3569
- );
3648
+ console.log(` ${yellow2("~")} ${bold4(e.slug)} ${dim(e.summary)} ${yellow2(`[${e.changedFields.join(", ")}]`)}`);
3570
3649
  if (opts.detailed) {
3571
3650
  for (const [section, diff] of Object.entries(e.diffs)) {
3572
- if (!diff) continue;
3651
+ if (!diff)
3652
+ continue;
3573
3653
  console.log(` ${bold4(section)}:`);
3574
3654
  renderUnifiedDiff(diff);
3575
3655
  }
@@ -3581,10 +3661,8 @@ ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${
3581
3661
  }
3582
3662
  }
3583
3663
  }
3584
- console.log(
3585
- `
3586
- ${bold4("Plan:")} ${green4(`+${toWrite} to write`)} ${yellow2(`~${toUpdate} to update`)} ${red4(`-${toDelete} to delete`)}`
3587
- );
3664
+ console.log(`
3665
+ ${bold4("Plan:")} ${green4(`+${toWrite} to write`)} ${yellow2(`~${toUpdate} to update`)} ${red4(`-${toDelete} to delete`)}`);
3588
3666
  if (!opts.detailed && toUpdate > 0) {
3589
3667
  console.log(` ${dim("Run with --detailed to see full diffs.")}`);
3590
3668
  }
@@ -3600,21 +3678,19 @@ ${bold4("Plan:")} ${green4(`+${toWrite} to write`)} ${yellow2(`~${toUpdate} t
3600
3678
  }
3601
3679
  for (const mp of plan2.modules) {
3602
3680
  const { module: mod, creates, updates, deletes } = mp;
3603
- if (!creates.length && !updates.length && !deletes.length) continue;
3604
- console.log(
3605
- `
3606
- ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${summaryBadges(creates.length, updates.length, deletes.length)}`
3607
- );
3681
+ if (!creates.length && !updates.length && !deletes.length)
3682
+ continue;
3683
+ console.log(`
3684
+ ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${summaryBadges(creates.length, updates.length, deletes.length)}`);
3608
3685
  for (const e of creates) {
3609
3686
  console.log(` ${green4("+")} ${bold4(e.slug)} ${dim(e.summary)}`);
3610
3687
  }
3611
3688
  for (const e of updates) {
3612
- console.log(
3613
- ` ${yellow2("~")} ${bold4(e.slug)} ${dim(e.summary)} ${yellow2(`[${e.changedFields.join(", ")}]`)}`
3614
- );
3689
+ console.log(` ${yellow2("~")} ${bold4(e.slug)} ${dim(e.summary)} ${yellow2(`[${e.changedFields.join(", ")}]`)}`);
3615
3690
  if (opts.detailed) {
3616
3691
  for (const [section, diff] of Object.entries(e.diffs)) {
3617
- if (!diff) continue;
3692
+ if (!diff)
3693
+ continue;
3618
3694
  console.log(` ${bold4(section)}:`);
3619
3695
  renderUnifiedDiff(diff);
3620
3696
  }
@@ -3624,19 +3700,20 @@ ${bold4(cyan(`\u2500\u2500 ${mod.displayName.toUpperCase()} \u2500\u2500`))} ${
3624
3700
  console.log(` ${red4("-")} ${bold4(e.slug)} ${dim(e.summary)}`);
3625
3701
  }
3626
3702
  }
3627
- console.log(
3628
- `
3629
- ${bold4("Plan:")} ${green4(`+${totalCreates} to create`)} ${yellow2(`~${totalUpdates} to update`)} ${red4(`-${totalDeletes} to delete`)}`
3630
- );
3703
+ console.log(`
3704
+ ${bold4("Plan:")} ${green4(`+${totalCreates} to create`)} ${yellow2(`~${totalUpdates} to update`)} ${red4(`-${totalDeletes} to delete`)}`);
3631
3705
  if (!opts.detailed && totalUpdates > 0) {
3632
3706
  console.log(` ${dim("Run with --detailed to see full diffs.")}`);
3633
3707
  }
3634
3708
  }
3635
3709
  function summaryBadges(c, u, d) {
3636
3710
  const parts = [];
3637
- if (c) parts.push(green4(`+${c}`));
3638
- if (u) parts.push(yellow2(`~${u}`));
3639
- if (d) parts.push(red4(`-${d}`));
3711
+ if (c)
3712
+ parts.push(green4(`+${c}`));
3713
+ if (u)
3714
+ parts.push(yellow2(`~${u}`));
3715
+ if (d)
3716
+ parts.push(red4(`-${d}`));
3640
3717
  return parts.join(" ");
3641
3718
  }
3642
3719
  function dim(s) {
@@ -3655,85 +3732,64 @@ function renderUnifiedDiff(diff) {
3655
3732
  }
3656
3733
  async function applyPlan(plan2, http2, opts = {}) {
3657
3734
  const concurrency = opts.concurrency ?? 10;
3735
+ const reporter = opts.reporter ?? silentReporter;
3658
3736
  const errors = [];
3659
3737
  const handleErr = (label, e) => {
3660
3738
  const msg = formatError(e);
3661
3739
  const full = `${label}: ${msg}`;
3662
- if (opts.abortOnError) throw new Error(full);
3663
- console.warn(bold4(yellow2(` \u26A0 ${full}`)));
3740
+ if (opts.abortOnError)
3741
+ throw new Error(full);
3742
+ reporter.warn(full);
3664
3743
  errors.push(full);
3665
3744
  };
3666
3745
  for (const mp of plan2.modules) {
3667
3746
  const { module: mod, creates, updates, deletes } = mp;
3668
3747
  if (deletes.length) {
3669
- await runConcurrently(
3670
- deletes.map((e) => ({ slug: e.slug, run: () => mod.delete(http2, e.remote.id) })),
3671
- concurrency,
3672
- `Deleting ${mod.displayName}`,
3673
- handleErr
3674
- );
3748
+ await runConcurrently(deletes.map((e) => ({ slug: e.slug, run: () => mod.delete(http2, e.remote.id) })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
3675
3749
  }
3676
3750
  if (updates.length) {
3677
- await runConcurrently(
3678
- updates.map((e) => ({ slug: e.slug, run: () => mod.update(http2, e.local, e.remote.id) })),
3679
- concurrency,
3680
- `Updating ${mod.displayName}`,
3681
- handleErr
3682
- );
3751
+ await runConcurrently(updates.map((e) => ({ slug: e.slug, run: () => mod.update(http2, e.local, e.remote.id) })), concurrency, `Updating ${mod.displayName}`, handleErr, reporter);
3683
3752
  }
3684
3753
  if (creates.length) {
3685
- await runConcurrently(
3686
- creates.map((e) => ({ slug: e.slug, run: () => mod.create(http2, e.local) })),
3687
- concurrency,
3688
- `Creating ${mod.displayName}`,
3689
- handleErr
3690
- );
3754
+ await runConcurrently(creates.map((e) => ({ slug: e.slug, run: () => mod.create(http2, e.local) })), concurrency, `Creating ${mod.displayName}`, handleErr, reporter);
3691
3755
  }
3692
3756
  }
3693
3757
  return { errors };
3694
3758
  }
3695
3759
  async function fetchToDisk(plan2, http2, rootDir, opts = {}) {
3696
3760
  const concurrency = opts.concurrency ?? 10;
3761
+ const reporter = opts.reporter ?? silentReporter;
3697
3762
  const errors = [];
3698
3763
  let written = 0;
3699
3764
  let deleted = 0;
3700
3765
  const handleErr = (label, e) => {
3701
3766
  const msg = formatError(e);
3702
3767
  const full = `${label}: ${msg}`;
3703
- if (opts.abortOnError) throw new Error(full);
3704
- console.warn(bold4(yellow2(` \u26A0 ${full}`)));
3768
+ if (opts.abortOnError)
3769
+ throw new Error(full);
3770
+ reporter.warn(full);
3705
3771
  errors.push(full);
3706
3772
  };
3707
3773
  for (const mp of plan2.modules) {
3708
3774
  const { module: mod, updates, deletes, creates } = mp;
3709
3775
  const toWrite = [...deletes, ...updates];
3710
3776
  if (toWrite.length) {
3711
- await runConcurrently(
3712
- toWrite.map((e) => ({
3713
- slug: e.slug,
3714
- run: async () => {
3715
- await mod.writeLocal(rootDir, e.remote);
3716
- written++;
3717
- }
3718
- })),
3719
- concurrency,
3720
- `Writing ${mod.displayName}`,
3721
- handleErr
3722
- );
3777
+ await runConcurrently(toWrite.map((e) => ({
3778
+ slug: e.slug,
3779
+ run: async () => {
3780
+ await mod.writeLocal(rootDir, e.remote);
3781
+ written++;
3782
+ }
3783
+ })), concurrency, `Writing ${mod.displayName}`, handleErr, reporter);
3723
3784
  }
3724
3785
  if (opts.clean && creates.length) {
3725
- await runConcurrently(
3726
- creates.map((e) => ({
3727
- slug: e.slug,
3728
- run: async () => {
3729
- await mod.deleteLocal(rootDir, e.slug);
3730
- deleted++;
3731
- }
3732
- })),
3733
- concurrency,
3734
- `Deleting ${mod.displayName}`,
3735
- handleErr
3736
- );
3786
+ await runConcurrently(creates.map((e) => ({
3787
+ slug: e.slug,
3788
+ run: async () => {
3789
+ await mod.deleteLocal(rootDir, e.slug);
3790
+ deleted++;
3791
+ }
3792
+ })), concurrency, `Deleting ${mod.displayName}`, handleErr, reporter);
3737
3793
  }
3738
3794
  }
3739
3795
  return { written, deleted, errors };
@@ -3742,41 +3798,47 @@ function diffObjectFields(local, remote, ignoredFields) {
3742
3798
  const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
3743
3799
  const changed = [];
3744
3800
  for (const key of allKeys) {
3745
- if (ignoredFields.includes(key)) continue;
3801
+ if (ignoredFields.includes(key))
3802
+ continue;
3746
3803
  if (!isEqual2(local[key], remote[key])) {
3747
3804
  changed.push(key);
3748
3805
  }
3749
3806
  }
3750
3807
  return changed;
3751
3808
  }
3809
+ function diffSchemaFields(local, remote, ignoredFields) {
3810
+ return diffObjectFields(local, remote, ignoredFields);
3811
+ }
3752
3812
  function buildUnifiedDiff(oldContent, newContent, filename) {
3753
3813
  return createTwoFilesPatch(`remote/${filename}`, `local/${filename}`, oldContent, newContent);
3754
3814
  }
3755
- async function runConcurrently(tasks, concurrency, label, onError) {
3756
- if (!tasks.length) return;
3815
+ function renderSchemaDetail(localData, remoteData, ignoredFields) {
3816
+ const localYaml = yaml2.stringify(omit(localData, ignoredFields));
3817
+ const remoteYaml = yaml2.stringify(omit(remoteData, ignoredFields));
3818
+ return { schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml") };
3819
+ }
3820
+ async function runConcurrently(tasks, concurrency, label, onError, reporter) {
3821
+ if (!tasks.length)
3822
+ return;
3757
3823
  const total = tasks.length;
3758
3824
  let done = 0;
3759
- const spinner = ora2({ text: `${label} (0/${total})`, color: "yellow" }).start();
3825
+ const progress = reporter.progress(label, total);
3760
3826
  try {
3761
3827
  const limit = Math.max(1, Math.min(total, concurrency));
3762
3828
  let batch = [];
3763
3829
  for (let i = 0; i < tasks.length; i++) {
3764
3830
  batch.push(tasks[i]);
3765
3831
  if (batch.length === limit || i === tasks.length - 1) {
3766
- await Promise.all(
3767
- batch.map(
3768
- (task) => task.run().catch((e) => onError(`${label}: ${task.slug}`, e)).finally(() => {
3769
- done++;
3770
- spinner.text = `${label}: ${task.slug} (${done}/${total})`;
3771
- })
3772
- )
3773
- );
3832
+ await Promise.all(batch.map((task) => task.run().catch((e) => onError(`${label}: ${task.slug}`, e)).finally(() => {
3833
+ done++;
3834
+ progress.update(task.slug, done, total);
3835
+ })));
3774
3836
  batch = [];
3775
3837
  }
3776
3838
  }
3777
- spinner.succeed();
3839
+ progress.succeed();
3778
3840
  } catch (e) {
3779
- spinner.fail();
3841
+ progress.fail();
3780
3842
  throw e;
3781
3843
  }
3782
3844
  }
@@ -3788,71 +3850,15 @@ function formatError(e) {
3788
3850
  return String(e);
3789
3851
  }
3790
3852
 
3791
- // apps/cli/src/commands/sync/modules/bucket.ts
3792
- import path10 from "path";
3793
- import yaml2 from "yaml";
3794
-
3795
- // apps/cli/src/commands/sync/fs-utils.ts
3796
- import fs9 from "fs";
3797
- import path9 from "path";
3798
- import yaml from "yaml";
3799
- function ensureDir(dir) {
3800
- fs9.mkdirSync(dir, { recursive: true });
3801
- }
3802
- function listFolders(dir) {
3803
- if (!fs9.existsSync(dir)) return [];
3804
- return fs9.readdirSync(dir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
3805
- }
3806
- function readYaml(filePath) {
3807
- if (!fs9.existsSync(filePath)) return null;
3808
- return yaml.parse(fs9.readFileSync(filePath, "utf-8"));
3809
- }
3810
- function writeYaml(filePath, data) {
3811
- ensureDir(path9.dirname(filePath));
3812
- fs9.writeFileSync(filePath, yaml.stringify(data), "utf-8");
3813
- }
3814
- function readText(filePath) {
3815
- if (!fs9.existsSync(filePath)) return null;
3816
- return fs9.readFileSync(filePath, "utf-8");
3817
- }
3818
- function writeText(filePath, content) {
3819
- ensureDir(path9.dirname(filePath));
3820
- fs9.writeFileSync(filePath, content, "utf-8");
3821
- }
3822
- function removeDir(dir) {
3823
- if (fs9.existsSync(dir)) {
3824
- fs9.rmSync(dir, { recursive: true, force: true });
3825
- }
3826
- }
3827
- function omit(obj, fields) {
3828
- const clone = structuredClone(obj);
3829
- for (const f of fields) delete clone[f];
3830
- return clone;
3831
- }
3832
- function sanitizeSlug(slug) {
3833
- return path9.basename(path9.normalize(slug));
3834
- }
3835
- function unwrapList(res) {
3836
- if (Array.isArray(res)) return res;
3837
- return res.data ?? [];
3838
- }
3839
-
3840
- // apps/cli/src/commands/sync/modules/bucket.ts
3853
+ // packages/sync/dist/src/modules/bucket.js
3841
3854
  var IGNORED_FIELDS = ["_id"];
3842
3855
  var bucketModule = {
3843
3856
  name: "bucket",
3844
3857
  displayName: "Bucket",
3845
3858
  identityField: "title",
3846
3859
  ignoredFields: IGNORED_FIELDS,
3847
- async readLocal(rootDir) {
3848
- const dir = path10.join(rootDir, "bucket");
3849
- const slugs = listFolders(dir);
3850
- const results = [];
3851
- for (const slug of slugs) {
3852
- const data = readYaml(path10.join(dir, slug, "schema.yaml"));
3853
- if (data) results.push({ slug, data });
3854
- }
3855
- return results;
3860
+ readLocal(rootDir) {
3861
+ return readLocalSchemas(rootDir, "bucket");
3856
3862
  },
3857
3863
  async readRemote(http2) {
3858
3864
  const res = await http2.get("bucket");
@@ -3873,25 +3879,16 @@ var bucketModule = {
3873
3879
  await http2.delete(`bucket/${remoteId}`);
3874
3880
  },
3875
3881
  async writeLocal(rootDir, remote) {
3876
- const dir = path10.join(rootDir, "bucket", remote.slug);
3877
- writeYaml(path10.join(dir, "schema.yaml"), remote.data);
3882
+ writeLocalSchema(rootDir, "bucket", remote);
3878
3883
  },
3879
3884
  async deleteLocal(rootDir, slug) {
3880
- removeDir(path10.join(rootDir, "bucket", slug));
3885
+ deleteLocalSchema(rootDir, "bucket", slug);
3881
3886
  },
3882
3887
  diffFields(local, remote) {
3883
- return diffObjectFields(
3884
- local,
3885
- remote,
3886
- IGNORED_FIELDS
3887
- );
3888
+ return diffSchemaFields(local, remote, IGNORED_FIELDS);
3888
3889
  },
3889
3890
  renderDetail(local, remote) {
3890
- const localYaml = yaml2.stringify(omit(local.data, IGNORED_FIELDS));
3891
- const remoteYaml = yaml2.stringify(omit(remote.data, IGNORED_FIELDS));
3892
- return {
3893
- schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml")
3894
- };
3891
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS);
3895
3892
  },
3896
3893
  summaryLine(resource) {
3897
3894
  const propCount = Object.keys(resource.data.properties ?? {}).length;
@@ -3902,24 +3899,15 @@ var bucketModule = {
3902
3899
  }
3903
3900
  };
3904
3901
 
3905
- // apps/cli/src/commands/sync/modules/env-var.ts
3906
- import path11 from "path";
3907
- import yaml3 from "yaml";
3902
+ // packages/sync/dist/src/modules/env-var.js
3908
3903
  var IGNORED_FIELDS2 = ["_id"];
3909
3904
  var envVarModule = {
3910
3905
  name: "env-var",
3911
3906
  displayName: "Environment Variable",
3912
3907
  identityField: "key",
3913
3908
  ignoredFields: IGNORED_FIELDS2,
3914
- async readLocal(rootDir) {
3915
- const dir = path11.join(rootDir, "env-var");
3916
- const slugs = listFolders(dir);
3917
- const results = [];
3918
- for (const slug of slugs) {
3919
- const data = readYaml(path11.join(dir, slug, "schema.yaml"));
3920
- if (data) results.push({ slug, data });
3921
- }
3922
- return results;
3909
+ readLocal(rootDir) {
3910
+ return readLocalSchemas(rootDir, "env-var");
3923
3911
  },
3924
3912
  async readRemote(http2) {
3925
3913
  const res = await http2.get("env-var");
@@ -3940,25 +3928,16 @@ var envVarModule = {
3940
3928
  await http2.delete(`env-var/${remoteId}`);
3941
3929
  },
3942
3930
  async writeLocal(rootDir, remote) {
3943
- const dir = path11.join(rootDir, "env-var", remote.slug);
3944
- writeYaml(path11.join(dir, "schema.yaml"), remote.data);
3931
+ writeLocalSchema(rootDir, "env-var", remote);
3945
3932
  },
3946
3933
  async deleteLocal(rootDir, slug) {
3947
- removeDir(path11.join(rootDir, "env-var", slug));
3934
+ deleteLocalSchema(rootDir, "env-var", slug);
3948
3935
  },
3949
3936
  diffFields(local, remote) {
3950
- return diffObjectFields(
3951
- local,
3952
- remote,
3953
- IGNORED_FIELDS2
3954
- );
3937
+ return diffSchemaFields(local, remote, IGNORED_FIELDS2);
3955
3938
  },
3956
3939
  renderDetail(local, remote) {
3957
- const localYaml = yaml3.stringify(omit(local.data, IGNORED_FIELDS2));
3958
- const remoteYaml = yaml3.stringify(omit(remote.data, IGNORED_FIELDS2));
3959
- return {
3960
- schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml")
3961
- };
3940
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS2);
3962
3941
  },
3963
3942
  summaryLine(resource) {
3964
3943
  return `key: ${resource.data.key}`;
@@ -3968,9 +3947,9 @@ var envVarModule = {
3968
3947
  }
3969
3948
  };
3970
3949
 
3971
- // apps/cli/src/commands/sync/modules/function.ts
3972
- import path12 from "path";
3973
- import yaml4 from "yaml";
3950
+ // packages/sync/dist/src/modules/function.js
3951
+ import path10 from "path";
3952
+ import yaml3 from "yaml";
3974
3953
  import isEqual3 from "lodash/isEqual.js";
3975
3954
  import { bold as bold5, cyan as cyan2, green as green5, yellow as yellow3 } from "colorette";
3976
3955
  var SCHEMA_IGNORED = ["_id", "env_vars", "secrets"];
@@ -3994,7 +3973,8 @@ function normalizeSchema(schema) {
3994
3973
  return normalized;
3995
3974
  }
3996
3975
  function isNotFoundError(error) {
3997
- if (!error || typeof error !== "object") return false;
3976
+ if (!error || typeof error !== "object")
3977
+ return false;
3998
3978
  const c = error;
3999
3979
  return c.status === 404 || c.statusCode === 404 || c.response?.status === 404 || c.response?.statusCode === 404;
4000
3980
  }
@@ -4004,14 +3984,15 @@ var functionModule = {
4004
3984
  identityField: "name",
4005
3985
  ignoredFields: SCHEMA_IGNORED,
4006
3986
  readSchema(rootDir, slug) {
4007
- return readYaml(path12.join(rootDir, "function", slug, "schema.yaml"));
3987
+ return readYaml(path10.join(rootDir, "function", slug, "schema.yaml"));
4008
3988
  },
4009
3989
  readIndex(rootDir, slug, language) {
4010
- return readText(path12.join(rootDir, "function", slug, indexFilename(language))) ?? "";
3990
+ return readText(path10.join(rootDir, "function", slug, indexFilename(language))) ?? "";
4011
3991
  },
4012
3992
  readDependencies(rootDir, slug) {
4013
- const pkgText = readText(path12.join(rootDir, "function", slug, "package.json"));
4014
- if (!pkgText) return {};
3993
+ const pkgText = readText(path10.join(rootDir, "function", slug, "package.json"));
3994
+ if (!pkgText)
3995
+ return {};
4015
3996
  try {
4016
3997
  return JSON.parse(pkgText).dependencies ?? {};
4017
3998
  } catch {
@@ -4019,12 +4000,13 @@ var functionModule = {
4019
4000
  }
4020
4001
  },
4021
4002
  async readLocal(rootDir) {
4022
- const dir = path12.join(rootDir, "function");
4003
+ const dir = path10.join(rootDir, "function");
4023
4004
  const slugs = listFolders(dir);
4024
4005
  const results = [];
4025
4006
  for (const slug of slugs) {
4026
4007
  const schema = this.readSchema(rootDir, slug);
4027
- if (!schema) continue;
4008
+ if (!schema)
4009
+ continue;
4028
4010
  const index = this.readIndex(rootDir, slug, schema.language);
4029
4011
  const dependencies = this.readDependencies(rootDir, slug);
4030
4012
  results.push({ slug, data: { schema, index, dependencies } });
@@ -4033,42 +4015,39 @@ var functionModule = {
4033
4015
  },
4034
4016
  async readRemote(http2) {
4035
4017
  const fns = await http2.get("function");
4036
- return Promise.all(
4037
- fns.map(async (fn) => {
4038
- const id = fn._id;
4039
- const [indexRes, depsRes] = await Promise.all([
4040
- http2.get(`function/${id}/index`).catch(() => ({ index: "" })),
4041
- http2.get(`function/${id}/dependencies`).catch(() => [])
4042
- ]);
4043
- const dependencies = {};
4044
- for (const dep of depsRes) {
4045
- dependencies[dep.name] = dep.version;
4018
+ return Promise.all(fns.map(async (fn) => {
4019
+ const id = fn._id;
4020
+ const [indexRes, depsRes] = await Promise.all([
4021
+ http2.get(`function/${id}/index`).catch(() => ({ index: "" })),
4022
+ http2.get(`function/${id}/dependencies`).catch(() => [])
4023
+ ]);
4024
+ const dependencies = {};
4025
+ for (const dep of depsRes) {
4026
+ dependencies[dep.name] = dep.version;
4027
+ }
4028
+ return {
4029
+ slug: sanitizeSlug(fn.name),
4030
+ id,
4031
+ data: {
4032
+ schema: normalizeSchema(fn),
4033
+ index: indexRes.index ?? "",
4034
+ dependencies
4046
4035
  }
4047
- return {
4048
- slug: sanitizeSlug(fn.name),
4049
- id,
4050
- data: {
4051
- schema: normalizeSchema(fn),
4052
- index: indexRes.index ?? "",
4053
- dependencies
4054
- }
4055
- };
4056
- })
4057
- );
4036
+ };
4037
+ }));
4058
4038
  },
4059
4039
  async create(http2, local) {
4060
4040
  const id = await this.createSchema(http2, local.data.schema);
4061
- if (!id) return;
4041
+ if (!id)
4042
+ return;
4062
4043
  await this.uploadIndex(http2, id, local.data.index);
4063
4044
  await this.uploadDependencies(http2, id, local.data.dependencies);
4064
4045
  },
4065
4046
  async createSchema(http2, schema) {
4066
- const created = await http2.post(
4067
- "function",
4068
- omit(schema, ["env_vars", "secrets"])
4069
- );
4047
+ const created = await http2.post("function", omit(schema, ["env_vars", "secrets"]));
4070
4048
  const id = created._id ?? schema._id;
4071
- if (!id) return void 0;
4049
+ if (!id)
4050
+ return void 0;
4072
4051
  const envVarIds = schema.env_vars ?? [];
4073
4052
  await Promise.all(envVarIds.map((evId) => http2.put(`function/${id}/env-var/${evId}`, {})));
4074
4053
  const secretIds = schema.secrets ?? [];
@@ -4103,14 +4082,11 @@ var functionModule = {
4103
4082
  const currentDeps = await http2.get(`function/${remoteId}/dependencies`).catch(() => []);
4104
4083
  const currentByName = new Map(currentDeps.map((d) => [d.name, d.version]));
4105
4084
  const toDelete = currentDeps.filter((d) => !(d.name in localDeps));
4106
- await Promise.all(
4107
- toDelete.map(
4108
- (d) => http2.delete(`function/${remoteId}/dependencies/${d.name}`).catch((error) => {
4109
- if (isNotFoundError(error)) return;
4110
- throw error;
4111
- })
4112
- )
4113
- );
4085
+ await Promise.all(toDelete.map((d) => http2.delete(`function/${remoteId}/dependencies/${d.name}`).catch((error) => {
4086
+ if (isNotFoundError(error))
4087
+ return;
4088
+ throw error;
4089
+ })));
4114
4090
  const toAdd = Object.entries(localDeps).filter(([n, v]) => {
4115
4091
  const cur = currentByName.get(n);
4116
4092
  return !cur || cur !== v;
@@ -4123,56 +4099,53 @@ var functionModule = {
4123
4099
  await http2.delete(`function/${remoteId}`);
4124
4100
  },
4125
4101
  async writeLocal(rootDir, remote) {
4126
- const fnDir = path12.join(rootDir, "function", remote.slug);
4102
+ const fnDir = path10.join(rootDir, "function", remote.slug);
4127
4103
  ensureDir(fnDir);
4128
- writeYaml(path12.join(fnDir, "schema.yaml"), remote.data.schema);
4104
+ writeYaml(path10.join(fnDir, "schema.yaml"), remote.data.schema);
4129
4105
  const indexFile = indexFilename(remote.data.schema.language);
4130
- writeText(path12.join(fnDir, indexFile), remote.data.index);
4106
+ writeText(path10.join(fnDir, indexFile), remote.data.index);
4131
4107
  const pkg = {
4132
4108
  name: remote.slug,
4133
4109
  version: "0.0.1",
4134
4110
  dependencies: remote.data.dependencies
4135
4111
  };
4136
- writeText(path12.join(fnDir, "package.json"), JSON.stringify(pkg, null, 2));
4112
+ writeText(path10.join(fnDir, "package.json"), JSON.stringify(pkg, null, 2));
4137
4113
  },
4138
4114
  async deleteLocal(rootDir, slug) {
4139
- removeDir(path12.join(rootDir, "function", slug));
4115
+ removeDir(path10.join(rootDir, "function", slug));
4140
4116
  },
4141
4117
  diffFields(local, remote) {
4142
4118
  const changed = [];
4143
- const schemaChanged = diffObjectFields(
4144
- local.schema,
4145
- remote.schema,
4146
- SCHEMA_IGNORED
4147
- );
4148
- if (schemaChanged.length) changed.push("schema");
4149
- if (local.index !== remote.index) changed.push("index");
4150
- if (!isEqual3(local.dependencies, remote.dependencies)) changed.push("dependencies");
4119
+ const schemaChanged = diffObjectFields(local.schema, remote.schema, SCHEMA_IGNORED);
4120
+ if (schemaChanged.length)
4121
+ changed.push("schema");
4122
+ if (local.index !== remote.index)
4123
+ changed.push("index");
4124
+ if (!isEqual3(local.dependencies, remote.dependencies))
4125
+ changed.push("dependencies");
4151
4126
  const localEnvVars = local.schema.env_vars ?? [];
4152
4127
  const remoteEnvVars = remote.schema.env_vars ?? [];
4153
- if (!isEqual3(new Set(localEnvVars), new Set(remoteEnvVars))) changed.push("env_vars");
4128
+ if (!isEqual3(new Set(localEnvVars), new Set(remoteEnvVars)))
4129
+ changed.push("env_vars");
4154
4130
  const localSecrets = local.schema.secrets ?? [];
4155
4131
  const remoteSecrets = remote.schema.secrets ?? [];
4156
- if (!isEqual3(new Set(localSecrets), new Set(remoteSecrets))) changed.push("secrets");
4132
+ if (!isEqual3(new Set(localSecrets), new Set(remoteSecrets)))
4133
+ changed.push("secrets");
4157
4134
  return changed;
4158
4135
  },
4159
4136
  renderDetail(local, remote) {
4160
4137
  const result = {};
4161
- const localSchemaYaml = yaml4.stringify(omit(local.data.schema, SCHEMA_IGNORED));
4162
- const remoteSchemaYaml = yaml4.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
4138
+ const localSchemaYaml = yaml3.stringify(omit(local.data.schema, SCHEMA_IGNORED));
4139
+ const remoteSchemaYaml = yaml3.stringify(omit(remote.data.schema, SCHEMA_IGNORED));
4163
4140
  if (localSchemaYaml !== remoteSchemaYaml) {
4164
4141
  result["schema"] = buildUnifiedDiff(remoteSchemaYaml, localSchemaYaml, "schema.yaml");
4165
4142
  }
4166
4143
  if (local.data.index !== remote.data.index) {
4167
- result["index"] = buildUnifiedDiff(
4168
- remote.data.index,
4169
- local.data.index,
4170
- indexFilename(local.data.schema.language)
4171
- );
4144
+ result["index"] = buildUnifiedDiff(remote.data.index, local.data.index, indexFilename(local.data.schema.language));
4172
4145
  }
4173
4146
  const sortKeys = (obj) => Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
4174
- const localDepsYaml = yaml4.stringify(sortKeys(local.data.dependencies));
4175
- const remoteDepsYaml = yaml4.stringify(sortKeys(remote.data.dependencies));
4147
+ const localDepsYaml = yaml3.stringify(sortKeys(local.data.dependencies));
4148
+ const remoteDepsYaml = yaml3.stringify(sortKeys(remote.data.dependencies));
4176
4149
  if (localDepsYaml !== remoteDepsYaml) {
4177
4150
  result["dependencies"] = buildUnifiedDiff(remoteDepsYaml, localDepsYaml, "package.json");
4178
4151
  }
@@ -4188,39 +4161,28 @@ var functionModule = {
4188
4161
  watchedFiles: ["schema.yaml", "index.ts", "index.mjs", "index.js", "package.json"],
4189
4162
  async devHandleEvent(ctx) {
4190
4163
  const self = this;
4191
- const {
4192
- type,
4193
- slug,
4194
- file,
4195
- http: http2,
4196
- rootDir,
4197
- warn,
4198
- spin: spin2,
4199
- refreshState,
4200
- getRemoteId,
4201
- setRemoteId,
4202
- clearRemoteId,
4203
- schedulePendingDelete,
4204
- consumePendingDeleteByRemoteId
4205
- } = ctx;
4164
+ const { type, slug, file, http: http2, rootDir, warn, spin: spin2, refreshState, getRemoteId, setRemoteId, clearRemoteId, schedulePendingDelete, consumePendingDeleteByRemoteId } = ctx;
4206
4165
  const isIndexFile = (f) => f === "index.ts" || f === "index.mjs" || f === "index.js";
4207
4166
  const isPackageFile = (f) => f === "package.json";
4208
4167
  function fnLabel(symbol, forSlug, sub) {
4209
4168
  const parts = [symbol, bold5(self.displayName), bold5(forSlug)];
4210
- if (sub) parts.push(yellow3(`[${sub}]`));
4169
+ if (sub)
4170
+ parts.push(yellow3(`[${sub}]`));
4211
4171
  return parts.join(" ");
4212
4172
  }
4213
4173
  async function waitForRemoteId() {
4214
4174
  for (let attempt = 0; attempt < 10; attempt++) {
4215
4175
  const id = getRemoteId(slug);
4216
- if (id) return id;
4176
+ if (id)
4177
+ return id;
4217
4178
  await ctx.sleep(200);
4218
4179
  }
4219
4180
  return getRemoteId(slug);
4220
4181
  }
4221
4182
  async function onSchemaAdd() {
4222
4183
  const schema = self.readSchema(rootDir, slug);
4223
- if (!schema) return;
4184
+ if (!schema)
4185
+ return;
4224
4186
  const newLocalId = schema._id;
4225
4187
  if (newLocalId) {
4226
4188
  const pending = consumePendingDeleteByRemoteId(newLocalId);
@@ -4238,7 +4200,8 @@ var functionModule = {
4238
4200
  } else {
4239
4201
  await spin2(fnLabel(green5("+"), slug), "created", async () => {
4240
4202
  const newRemoteId = await self.createSchema(http2, schema);
4241
- if (!newRemoteId) return;
4203
+ if (!newRemoteId)
4204
+ return;
4242
4205
  await refreshState();
4243
4206
  });
4244
4207
  }
@@ -4251,11 +4214,7 @@ var functionModule = {
4251
4214
  if (id) {
4252
4215
  const schema = self.readSchema(rootDir, slug);
4253
4216
  if (schema) {
4254
- await spin2(
4255
- fnLabel(yellow3("~"), slug, "schema"),
4256
- "updated",
4257
- () => self.updateSchema(http2, id, schema)
4258
- );
4217
+ await spin2(fnLabel(yellow3("~"), slug, "schema"), "updated", () => self.updateSchema(http2, id, schema));
4259
4218
  }
4260
4219
  }
4261
4220
  } else if (type !== "unlink" && isIndexFile(file)) {
@@ -4273,30 +4232,22 @@ var functionModule = {
4273
4232
  }
4274
4233
  } else if (type === "unlink" && isSchema) {
4275
4234
  const id = getRemoteId(slug);
4276
- if (id) schedulePendingDelete(slug, id);
4235
+ if (id)
4236
+ schedulePendingDelete(slug, id);
4277
4237
  } else if (type === "unlink" && (isIndexFile(file) || isPackageFile(file))) {
4278
4238
  }
4279
4239
  }
4280
4240
  };
4281
4241
 
4282
- // apps/cli/src/commands/sync/modules/policy.ts
4283
- import path13 from "path";
4284
- import yaml5 from "yaml";
4242
+ // packages/sync/dist/src/modules/policy.js
4285
4243
  var IGNORED_FIELDS3 = ["_id", "system"];
4286
4244
  var policyModule = {
4287
4245
  name: "policy",
4288
4246
  displayName: "Policy",
4289
4247
  identityField: "name",
4290
4248
  ignoredFields: IGNORED_FIELDS3,
4291
- async readLocal(rootDir) {
4292
- const dir = path13.join(rootDir, "policy");
4293
- const slugs = listFolders(dir);
4294
- const results = [];
4295
- for (const slug of slugs) {
4296
- const data = readYaml(path13.join(dir, slug, "schema.yaml"));
4297
- if (data) results.push({ slug, data });
4298
- }
4299
- return results;
4249
+ readLocal(rootDir) {
4250
+ return readLocalSchemas(rootDir, "policy");
4300
4251
  },
4301
4252
  async readRemote(http2) {
4302
4253
  const res = await http2.get("passport/policy");
@@ -4319,25 +4270,16 @@ var policyModule = {
4319
4270
  await http2.delete(`passport/policy/${remoteId}`);
4320
4271
  },
4321
4272
  async writeLocal(rootDir, remote) {
4322
- const dir = path13.join(rootDir, "policy", remote.slug);
4323
- writeYaml(path13.join(dir, "schema.yaml"), remote.data);
4273
+ writeLocalSchema(rootDir, "policy", remote);
4324
4274
  },
4325
4275
  async deleteLocal(rootDir, slug) {
4326
- removeDir(path13.join(rootDir, "policy", slug));
4276
+ deleteLocalSchema(rootDir, "policy", slug);
4327
4277
  },
4328
4278
  diffFields(local, remote) {
4329
- return diffObjectFields(
4330
- local,
4331
- remote,
4332
- IGNORED_FIELDS3
4333
- );
4279
+ return diffSchemaFields(local, remote, IGNORED_FIELDS3);
4334
4280
  },
4335
4281
  renderDetail(local, remote) {
4336
- const localYaml = yaml5.stringify(omit(local.data, IGNORED_FIELDS3));
4337
- const remoteYaml = yaml5.stringify(omit(remote.data, IGNORED_FIELDS3));
4338
- return {
4339
- schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml")
4340
- };
4282
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS3);
4341
4283
  },
4342
4284
  summaryLine(resource) {
4343
4285
  const stmts = resource.data.statement?.length ?? 0;
@@ -4348,24 +4290,15 @@ var policyModule = {
4348
4290
  }
4349
4291
  };
4350
4292
 
4351
- // apps/cli/src/commands/sync/modules/secret.ts
4352
- import path14 from "path";
4353
- import yaml6 from "yaml";
4293
+ // packages/sync/dist/src/modules/secret.js
4354
4294
  var IGNORED_FIELDS4 = ["_id", "value"];
4355
4295
  var secretModule = {
4356
4296
  name: "secret",
4357
4297
  displayName: "Secret",
4358
4298
  identityField: "key",
4359
4299
  ignoredFields: IGNORED_FIELDS4,
4360
- async readLocal(rootDir) {
4361
- const dir = path14.join(rootDir, "secret");
4362
- const slugs = listFolders(dir);
4363
- const results = [];
4364
- for (const slug of slugs) {
4365
- const data = readYaml(path14.join(dir, slug, "schema.yaml"));
4366
- if (data) results.push({ slug, data });
4367
- }
4368
- return results;
4300
+ readLocal(rootDir) {
4301
+ return readLocalSchemas(rootDir, "secret");
4369
4302
  },
4370
4303
  async readRemote(http2) {
4371
4304
  const res = await http2.get("secret");
@@ -4386,25 +4319,16 @@ var secretModule = {
4386
4319
  await http2.delete(`secret/${remoteId}`);
4387
4320
  },
4388
4321
  async writeLocal(rootDir, remote) {
4389
- const dir = path14.join(rootDir, "secret", remote.slug);
4390
- writeYaml(path14.join(dir, "schema.yaml"), remote.data);
4322
+ writeLocalSchema(rootDir, "secret", remote);
4391
4323
  },
4392
4324
  async deleteLocal(rootDir, slug) {
4393
- removeDir(path14.join(rootDir, "secret", slug));
4325
+ deleteLocalSchema(rootDir, "secret", slug);
4394
4326
  },
4395
4327
  diffFields(local, remote) {
4396
- return diffObjectFields(
4397
- local,
4398
- remote,
4399
- IGNORED_FIELDS4
4400
- );
4328
+ return diffSchemaFields(local, remote, IGNORED_FIELDS4);
4401
4329
  },
4402
4330
  renderDetail(local, remote) {
4403
- const localYaml = yaml6.stringify(omit(local.data, IGNORED_FIELDS4));
4404
- const remoteYaml = yaml6.stringify(omit(remote.data, IGNORED_FIELDS4));
4405
- return {
4406
- schema: buildUnifiedDiff(remoteYaml, localYaml, "schema.yaml")
4407
- };
4331
+ return renderSchemaDetail(local.data, remote.data, IGNORED_FIELDS4);
4408
4332
  },
4409
4333
  summaryLine(resource) {
4410
4334
  return `key: ${resource.data.key}`;
@@ -4414,7 +4338,7 @@ var secretModule = {
4414
4338
  }
4415
4339
  };
4416
4340
 
4417
- // apps/cli/src/commands/sync/modules/index.ts
4341
+ // packages/sync/dist/src/modules/index.js
4418
4342
  var ALL_MODULES = [
4419
4343
  policyModule,
4420
4344
  bucketModule,
@@ -4424,24 +4348,44 @@ var ALL_MODULES = [
4424
4348
  ];
4425
4349
  var MODULE_NAMES = ALL_MODULES.map((m) => m.name);
4426
4350
  function resolveModules(names) {
4427
- if (!names || names.length === 0) return ALL_MODULES;
4351
+ if (!names || names.length === 0)
4352
+ return ALL_MODULES;
4428
4353
  return [...new Set(names)].map((name) => {
4429
4354
  const mod = ALL_MODULES.find((m) => m.name === name);
4430
- if (!mod) throw new Error(`Unknown module: "${name}". Available: ${MODULE_NAMES.join(", ")}`);
4355
+ if (!mod)
4356
+ throw new Error(`Unknown module: "${name}". Available: ${MODULE_NAMES.join(", ")}`);
4431
4357
  return mod;
4432
4358
  });
4433
4359
  }
4434
4360
 
4361
+ // apps/cli/src/commands/sync/reporter.ts
4362
+ import ora2 from "ora";
4363
+ import { bold as bold6, yellow as yellow4 } from "colorette";
4364
+ var cliReporter = {
4365
+ task: (label, op) => spin({ text: label, op }),
4366
+ progress: (label, total) => {
4367
+ const spinner = ora2({ text: `${label} (0/${total})`, color: "yellow" }).start();
4368
+ return {
4369
+ update: (slug, done, t) => {
4370
+ spinner.text = `${label}: ${slug} (${done}/${t})`;
4371
+ },
4372
+ succeed: () => spinner.succeed(),
4373
+ fail: () => spinner.fail()
4374
+ };
4375
+ },
4376
+ warn: (message) => console.warn(bold6(yellow4(` \u26A0 ${message}`)))
4377
+ };
4378
+
4435
4379
  // apps/cli/src/commands/sync/plan.ts
4436
4380
  async function plan({ args, options }) {
4437
4381
  try {
4438
- const rootDir = path15.resolve(args.dir ?? process.cwd());
4382
+ const rootDir = path11.resolve(args.dir ?? process.cwd());
4439
4383
  const detailed = !!options.detailed;
4440
4384
  const json = !!options.json;
4441
4385
  const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
4442
4386
  const modules = resolveModules(moduleFilter);
4443
4387
  const http2 = await httpService.createFromCurrentCtx();
4444
- const p = await buildPlan(modules, http2, rootDir, detailed);
4388
+ const p = await buildPlan(modules, http2, rootDir, detailed, true, cliReporter);
4445
4389
  renderPlan(p, { detailed, json });
4446
4390
  process.exitCode = 0;
4447
4391
  } catch (err) {
@@ -4468,9 +4412,9 @@ function plan_default(program2) {
4468
4412
  }
4469
4413
 
4470
4414
  // apps/cli/src/commands/sync/apply.ts
4471
- import path16 from "path";
4415
+ import path12 from "path";
4472
4416
  import caporalCore4 from "@caporal/core";
4473
- import { bold as bold6, green as green6, red as red6, yellow as yellow4 } from "colorette";
4417
+ import { bold as bold7, green as green6, red as red5, yellow as yellow5 } from "colorette";
4474
4418
 
4475
4419
  // apps/cli/src/commands/sync/prompt.ts
4476
4420
  import readline from "readline";
@@ -4487,7 +4431,7 @@ async function confirm(question) {
4487
4431
  // apps/cli/src/commands/sync/apply.ts
4488
4432
  var { CaporalValidator: CaporalValidator4 } = caporalCore4;
4489
4433
  async function apply2({ args, options }) {
4490
- const rootDir = path16.resolve(args.dir ?? process.cwd());
4434
+ const rootDir = path12.resolve(args.dir ?? process.cwd());
4491
4435
  const autoApprove = !!options.autoApprove;
4492
4436
  const concurrency = options.concurrency ?? 10;
4493
4437
  const abortOnError = !!options.abortOnError;
@@ -4495,8 +4439,8 @@ async function apply2({ args, options }) {
4495
4439
  const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
4496
4440
  const modules = resolveModules(moduleFilter);
4497
4441
  const http2 = await httpService.createFromCurrentCtx();
4498
- console.log(bold6("\nBuilding plan\u2026"));
4499
- const p = await buildPlan(modules, http2, rootDir, detailed);
4442
+ console.log(bold7("\nBuilding plan\u2026"));
4443
+ const p = await buildPlan(modules, http2, rootDir, detailed, true, cliReporter);
4500
4444
  const totalChanges = p.modules.reduce(
4501
4445
  (n, m) => n + m.creates.length + m.updates.length + m.deletes.length,
4502
4446
  0
@@ -4509,33 +4453,33 @@ async function apply2({ args, options }) {
4509
4453
  if (!autoApprove) {
4510
4454
  const ok = await confirm("\nApply these changes?");
4511
4455
  if (!ok) {
4512
- console.log(bold6(yellow4("Aborted. No changes were applied.")));
4456
+ console.log(bold7(yellow5("Aborted. No changes were applied.")));
4513
4457
  process.exitCode = 1;
4514
4458
  return;
4515
4459
  }
4516
4460
  }
4517
- console.log(bold6("\nApplying changes\u2026"));
4461
+ console.log(bold7("\nApplying changes\u2026"));
4518
4462
  try {
4519
- const { errors } = await applyPlan(p, http2, { concurrency, abortOnError });
4463
+ const { errors } = await applyPlan(p, http2, { concurrency, abortOnError, reporter: cliReporter });
4520
4464
  if (errors.length) {
4521
- console.log(bold6(yellow4(`
4465
+ console.log(bold7(yellow5(`
4522
4466
  \u26A0 Completed with ${errors.length} error(s):`)));
4523
- for (const e of errors) console.log(` ${red6("\u2717")} ${e}`);
4467
+ for (const e of errors) console.log(` ${red5("\u2717")} ${e}`);
4524
4468
  process.exitCode = 1;
4525
4469
  } else {
4526
4470
  const c = p.modules.reduce((n, m) => n + m.creates.length, 0);
4527
4471
  const u = p.modules.reduce((n, m) => n + m.updates.length, 0);
4528
4472
  const d = p.modules.reduce((n, m) => n + m.deletes.length, 0);
4529
4473
  console.log(
4530
- bold6(green6(`
4531
- \u2713 Apply completed.`)) + ` ${green6(`+${c} created`)} ${yellow4(`~${u} updated`)} ${red6(`-${d} deleted`)}`
4474
+ bold7(green6(`
4475
+ \u2713 Apply completed.`)) + ` ${green6(`+${c} created`)} ${yellow5(`~${u} updated`)} ${red5(`-${d} deleted`)}`
4532
4476
  );
4533
4477
  process.exitCode = 0;
4534
4478
  }
4535
4479
  } catch (err) {
4536
4480
  const msg = err instanceof Error ? err.message : String(err);
4537
4481
  console.log(`
4538
- ${bold6(red6(`\u2717 ${msg}`))}`);
4482
+ ${bold7(red5(`\u2717 ${msg}`))}`);
4539
4483
  process.exitCode = 1;
4540
4484
  }
4541
4485
  }
@@ -4558,12 +4502,12 @@ function apply_default2(program2) {
4558
4502
  }
4559
4503
 
4560
4504
  // apps/cli/src/commands/sync/fetch.ts
4561
- import path17 from "path";
4505
+ import path13 from "path";
4562
4506
  import caporalCore5 from "@caporal/core";
4563
- import { bold as bold7, green as green7, red as red7, yellow as yellow5 } from "colorette";
4507
+ import { bold as bold8, green as green7, red as red6, yellow as yellow6 } from "colorette";
4564
4508
  var { CaporalValidator: CaporalValidator5 } = caporalCore5;
4565
4509
  async function fetch_({ args, options }) {
4566
- const rootDir = path17.resolve(args.dir ?? process.cwd());
4510
+ const rootDir = path13.resolve(args.dir ?? process.cwd());
4567
4511
  const autoApprove = !!options.autoApprove;
4568
4512
  const concurrency = options.concurrency ?? 10;
4569
4513
  const abortOnError = !!options.abortOnError;
@@ -4572,8 +4516,8 @@ async function fetch_({ args, options }) {
4572
4516
  const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
4573
4517
  const modules = resolveModules(moduleFilter);
4574
4518
  const http2 = await httpService.createFromCurrentCtx();
4575
- console.log(bold7("\nBuilding plan\u2026"));
4576
- const p = await buildPlan(modules, http2, rootDir, detailed, false);
4519
+ console.log(bold8("\nBuilding plan\u2026"));
4520
+ const p = await buildPlan(modules, http2, rootDir, detailed, false, cliReporter);
4577
4521
  const toWrite = p.modules.reduce((n, m) => n + m.deletes.length + m.updates.length, 0);
4578
4522
  const toDelete = p.modules.reduce((n, m) => n + m.creates.length, 0);
4579
4523
  const effectiveChanges = toWrite + (clean ? toDelete : 0);
@@ -4585,34 +4529,35 @@ async function fetch_({ args, options }) {
4585
4529
  if (!autoApprove) {
4586
4530
  const ok = await confirm("\nApply these changes?");
4587
4531
  if (!ok) {
4588
- console.log(bold7(yellow5("Aborted. No changes were applied.")));
4532
+ console.log(bold8(yellow6("Aborted. No changes were applied.")));
4589
4533
  process.exitCode = 1;
4590
4534
  return;
4591
4535
  }
4592
4536
  }
4593
- console.log(bold7("\nWriting files\u2026"));
4537
+ console.log(bold8("\nWriting files\u2026"));
4594
4538
  try {
4595
4539
  const { written, deleted, errors } = await fetchToDisk(p, http2, rootDir, {
4596
4540
  concurrency,
4597
4541
  abortOnError,
4598
- clean
4542
+ clean,
4543
+ reporter: cliReporter
4599
4544
  });
4600
4545
  if (errors.length) {
4601
- console.log(bold7(yellow5(`
4546
+ console.log(bold8(yellow6(`
4602
4547
  \u26A0 Completed with ${errors.length} error(s):`)));
4603
- for (const e of errors) console.log(` ${red7("\u2717")} ${e}`);
4548
+ for (const e of errors) console.log(` ${red6("\u2717")} ${e}`);
4604
4549
  process.exitCode = 1;
4605
4550
  } else {
4606
4551
  console.log(
4607
- bold7(green7(`
4608
- \u2713 Fetch complete.`)) + ` ${green7(`+${written} written`)}` + (deleted ? ` ${red7(`-${deleted} deleted`)}` : "")
4552
+ bold8(green7(`
4553
+ \u2713 Fetch complete.`)) + ` ${green7(`+${written} written`)}` + (deleted ? ` ${red6(`-${deleted} deleted`)}` : "")
4609
4554
  );
4610
4555
  process.exitCode = 0;
4611
4556
  }
4612
4557
  } catch (err) {
4613
4558
  const msg = err instanceof Error ? err.message : String(err);
4614
4559
  console.log(`
4615
- ${bold7(red7(`\u2717 ${msg}`))}`);
4560
+ ${bold8(red6(`\u2717 ${msg}`))}`);
4616
4561
  process.exitCode = 1;
4617
4562
  }
4618
4563
  }
@@ -4634,9 +4579,9 @@ function fetch_default(program2) {
4634
4579
  }
4635
4580
 
4636
4581
  // apps/cli/src/commands/sync/dev.ts
4637
- import path18 from "path";
4582
+ import path14 from "path";
4638
4583
  import chokidar from "chokidar";
4639
- import { bold as bold8, cyan as cyan3, green as green8, red as red8, yellow as yellow6 } from "colorette";
4584
+ import { bold as bold9, cyan as cyan3, green as green8, red as red7, yellow as yellow7 } from "colorette";
4640
4585
  import ora3 from "ora";
4641
4586
  function createEmptyState() {
4642
4587
  return { remoteIds: /* @__PURE__ */ new Map() };
@@ -4667,8 +4612,8 @@ function buildWatchIgnored(modules, rootDir) {
4667
4612
  modules.map((m) => [m.name, new Set(m.watchedFiles ?? ["schema.yaml"])])
4668
4613
  );
4669
4614
  return (filePath, stats) => {
4670
- const rel = path18.relative(rootDir, filePath);
4671
- const parts = rel.split(path18.sep);
4615
+ const rel = path14.relative(rootDir, filePath);
4616
+ const parts = rel.split(path14.sep);
4672
4617
  if (stats?.isDirectory()) {
4673
4618
  return parts.length >= 3;
4674
4619
  }
@@ -4681,7 +4626,7 @@ function buildWatchIgnored(modules, rootDir) {
4681
4626
  };
4682
4627
  }
4683
4628
  function readLocalSchema(mod, rootDir, slug) {
4684
- const schemaPath = path18.join(rootDir, mod.name, slug, "schema.yaml");
4629
+ const schemaPath = path14.join(rootDir, mod.name, slug, "schema.yaml");
4685
4630
  const data = readYaml(schemaPath);
4686
4631
  if (!data) return null;
4687
4632
  return { slug, data };
@@ -4694,11 +4639,11 @@ function createDevDispatcher(opts) {
4694
4639
  const pendingDeletes = /* @__PURE__ */ new Map();
4695
4640
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4696
4641
  function parseFilePath(absolutePath) {
4697
- const rel = path18.relative(rootDir, absolutePath);
4698
- const parts = rel.split(path18.sep);
4642
+ const rel = path14.relative(rootDir, absolutePath);
4643
+ const parts = rel.split(path14.sep);
4699
4644
  if (parts.length < 3) return null;
4700
4645
  const [moduleName, slug, ...rest] = parts;
4701
- return { moduleName, slug, file: rest.join(path18.sep) };
4646
+ return { moduleName, slug, file: rest.join(path14.sep) };
4702
4647
  }
4703
4648
  function getRemoteId(moduleName, slug) {
4704
4649
  return state.remoteIds.get(moduleName)?.get(slug);
@@ -4738,20 +4683,24 @@ function createDevDispatcher(opts) {
4738
4683
  pendingDeletes.delete(promotedKey);
4739
4684
  clearRemoteId(mod.name, pending.slug);
4740
4685
  setRemoteId(mod.name, slug, pending.remoteId);
4741
- const renameLabel = `${yellow6("~")} ${bold8(mod.displayName)} ${bold8(pending.slug)} ${cyan3("\u2192")} ${bold8(slug)}`;
4742
- await spinOp(renameLabel, "updated (rename)", () => mod.update(http2, local, pending.remoteId));
4686
+ const renameLabel = `${yellow7("~")} ${bold9(mod.displayName)} ${bold9(pending.slug)} ${cyan3("\u2192")} ${bold9(slug)}`;
4687
+ await spinOp(
4688
+ renameLabel,
4689
+ "updated (rename)",
4690
+ () => mod.update(http2, local, pending.remoteId)
4691
+ );
4743
4692
  return;
4744
4693
  }
4745
4694
  const remoteId = getRemoteId(mod.name, slug);
4746
4695
  if (remoteId) {
4747
4696
  await spinOp(
4748
- `${yellow6("~")} ${bold8(mod.displayName)} ${bold8(slug)}`,
4697
+ `${yellow7("~")} ${bold9(mod.displayName)} ${bold9(slug)}`,
4749
4698
  "updated",
4750
4699
  () => mod.update(http2, local, remoteId)
4751
4700
  );
4752
4701
  } else {
4753
4702
  await spinOp(
4754
- `${green8("+")} ${bold8(mod.displayName)} ${bold8(slug)}`,
4703
+ `${green8("+")} ${bold9(mod.displayName)} ${bold9(slug)}`,
4755
4704
  "created",
4756
4705
  async () => {
4757
4706
  await mod.create(http2, local);
@@ -4766,7 +4715,7 @@ function createDevDispatcher(opts) {
4766
4715
  const remoteId = getRemoteId(mod.name, slug);
4767
4716
  if (!remoteId) return handleSchemaAdd(mod, slug);
4768
4717
  await spinOp(
4769
- `${yellow6("~")} ${bold8(mod.displayName)} ${bold8(slug)}`,
4718
+ `${yellow7("~")} ${bold9(mod.displayName)} ${bold9(slug)}`,
4770
4719
  "updated",
4771
4720
  () => mod.update(http2, local, remoteId)
4772
4721
  );
@@ -4776,14 +4725,16 @@ function createDevDispatcher(opts) {
4776
4725
  if (!remoteId) return;
4777
4726
  const pendingKey = `${mod.name}:${slug}`;
4778
4727
  if (pendingDeletes.has(pendingKey)) return;
4779
- const timer = setTimeout(async () => {
4780
- pendingDeletes.delete(pendingKey);
4781
- clearRemoteId(mod.name, slug);
4782
- await spinOp(
4783
- `${red8("-")} ${bold8(mod.displayName)} ${bold8(slug)}`,
4784
- "deleted",
4785
- () => mod.delete(http2, remoteId)
4786
- );
4728
+ const timer = setTimeout(() => {
4729
+ Promise.resolve().then(async () => {
4730
+ pendingDeletes.delete(pendingKey);
4731
+ clearRemoteId(mod.name, slug);
4732
+ await spinOp(
4733
+ `${red7("-")} ${bold9(mod.displayName)} ${bold9(slug)}`,
4734
+ "deleted",
4735
+ () => mod.delete(http2, remoteId)
4736
+ );
4737
+ }).catch((err) => warn(`Delete failed for ${slug}: ${formatError2(err)}`));
4787
4738
  }, renameWindowMs);
4788
4739
  pendingDeletes.set(pendingKey, { timer, moduleName: mod.name, slug, remoteId });
4789
4740
  }
@@ -4800,14 +4751,16 @@ function createDevDispatcher(opts) {
4800
4751
  schedulePendingDelete(s, remoteId) {
4801
4752
  const pendingKey = `${mod.name}:${s}`;
4802
4753
  if (pendingDeletes.has(pendingKey)) return;
4803
- const timer = setTimeout(async () => {
4804
- pendingDeletes.delete(pendingKey);
4805
- clearRemoteId(mod.name, s);
4806
- await spinOp(
4807
- `${red8("-")} ${bold8(mod.displayName)} ${bold8(s)}`,
4808
- "deleted",
4809
- () => mod.delete(http2, remoteId)
4810
- );
4754
+ const timer = setTimeout(() => {
4755
+ Promise.resolve().then(async () => {
4756
+ pendingDeletes.delete(pendingKey);
4757
+ clearRemoteId(mod.name, s);
4758
+ await spinOp(
4759
+ `${red7("-")} ${bold9(mod.displayName)} ${bold9(s)}`,
4760
+ "deleted",
4761
+ () => mod.delete(http2, remoteId)
4762
+ );
4763
+ }).catch((err) => warn(`Delete failed for ${s}: ${formatError2(err)}`));
4811
4764
  }, renameWindowMs);
4812
4765
  pendingDeletes.set(pendingKey, { timer, moduleName: mod.name, slug: s, remoteId });
4813
4766
  },
@@ -4861,7 +4814,7 @@ function formatError2(e) {
4861
4814
  return String(e);
4862
4815
  }
4863
4816
  async function dev({ args, options }) {
4864
- const rootDir = path18.resolve(args.dir ?? process.cwd());
4817
+ const rootDir = path14.resolve(args.dir ?? process.cwd());
4865
4818
  const moduleFilter = options.module ? (Array.isArray(options.module) ? options.module : [options.module]).map(String) : void 0;
4866
4819
  const modules = resolveModules(moduleFilter);
4867
4820
  let ctx;
@@ -4869,27 +4822,27 @@ async function dev({ args, options }) {
4869
4822
  ctx = await context.getCurrent();
4870
4823
  } catch (err) {
4871
4824
  console.log(`
4872
- ${bold8(red8(`\u2717 ${formatError2(err)}`))}`);
4825
+ ${bold9(red7(`\u2717 ${formatError2(err)}`))}`);
4873
4826
  process.exitCode = 1;
4874
4827
  return;
4875
4828
  }
4876
4829
  if (ctx.url.startsWith("https://")) {
4877
4830
  console.log(
4878
- bold8(yellow6("\n\u26A0 Warning: The current context is using HTTPS.\n")) + ` ${bold8("sync dev")} is designed for development. Using it against a remote instance may have unintended side-effects.
4879
- Tip: Start a local instance with ${bold8("spica project start")} and switch to it with ${bold8("spica context switch <name>")} before running ${bold8("sync dev")}.`
4831
+ bold9(yellow7("\n\u26A0 Warning: The current context is using HTTPS.\n")) + ` ${bold9("sync dev")} is designed for development. Using it against a remote instance may have unintended side-effects.
4832
+ Tip: Start a local instance with ${bold9("spica project start")} and switch to it with ${bold9("spica context switch <name>")} before running ${bold9("sync dev")}.`
4880
4833
  );
4881
4834
  }
4882
4835
  const http2 = httpService.create({
4883
4836
  baseUrl: ctx.url,
4884
4837
  authorization: ctx.authorization
4885
4838
  });
4886
- console.log(bold8("\nBuilding plan\u2026"));
4839
+ console.log(bold9("\nBuilding plan\u2026"));
4887
4840
  let plan2;
4888
4841
  try {
4889
- plan2 = await buildPlan(modules, http2, rootDir, false);
4842
+ plan2 = await buildPlan(modules, http2, rootDir, false, true, cliReporter);
4890
4843
  } catch (err) {
4891
4844
  console.log(`
4892
- ${bold8(red8(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
4845
+ ${bold9(red7(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
4893
4846
  process.exitCode = 1;
4894
4847
  return;
4895
4848
  }
@@ -4901,22 +4854,26 @@ ${bold8(red8(`\u2717 Failed to build plan: ${formatError2(err)}`))}`);
4901
4854
  if (totalChanges > 0) {
4902
4855
  const ok = await confirm("\nApply these changes?");
4903
4856
  if (!ok) {
4904
- console.log(bold8(yellow6("Aborted. No changes were applied.")));
4857
+ console.log(bold9(yellow7("Aborted. No changes were applied.")));
4905
4858
  process.exitCode = 1;
4906
4859
  return;
4907
4860
  }
4908
- console.log(bold8("\nApplying changes\u2026"));
4861
+ console.log(bold9("\nApplying changes\u2026"));
4909
4862
  try {
4910
- const { errors } = await applyPlan(plan2, http2, { concurrency: 5, abortOnError: true });
4863
+ const { errors } = await applyPlan(plan2, http2, {
4864
+ concurrency: 5,
4865
+ abortOnError: true,
4866
+ reporter: cliReporter
4867
+ });
4911
4868
  if (errors.length) {
4912
- console.log(bold8(red8(`
4869
+ console.log(bold9(red7(`
4913
4870
  \u2717 Apply failed with ${errors.length} error(s).`)));
4914
4871
  process.exitCode = 1;
4915
4872
  return;
4916
4873
  }
4917
4874
  } catch (err) {
4918
4875
  console.log(`
4919
- ${bold8(red8(`\u2717 ${formatError2(err)}`))}`);
4876
+ ${bold9(red7(`\u2717 ${formatError2(err)}`))}`);
4920
4877
  process.exitCode = 1;
4921
4878
  return;
4922
4879
  }
@@ -4924,19 +4881,19 @@ ${bold8(red8(`\u2717 ${formatError2(err)}`))}`);
4924
4881
  const u = plan2.modules.reduce((n, m) => n + m.updates.length, 0);
4925
4882
  const d = plan2.modules.reduce((n, m) => n + m.deletes.length, 0);
4926
4883
  console.log(
4927
- bold8(green8(`
4928
- \u2713 Initial sync completed.`)) + ` ${green8(`+${c} created`)} ${yellow6(`~${u} updated`)} ${red8(`-${d} deleted`)}`
4884
+ bold9(green8(`
4885
+ \u2713 Initial sync completed.`)) + ` ${green8(`+${c} created`)} ${yellow7(`~${u} updated`)} ${red7(`-${d} deleted`)}`
4929
4886
  );
4930
4887
  } else {
4931
- console.log(bold8(green8("\n\u2713 Already in sync. Starting watcher\u2026")));
4888
+ console.log(bold9(green8("\n\u2713 Already in sync. Starting watcher\u2026")));
4932
4889
  }
4933
4890
  const state = createEmptyState();
4934
4891
  await Promise.all(modules.map((mod) => refreshStateForModule(mod, http2, state, rootDir)));
4935
- const watchDirs = modules.map((mod) => path18.join(rootDir, mod.name));
4892
+ const watchDirs = modules.map((mod) => path14.join(rootDir, mod.name));
4936
4893
  const dispatcher = createDevDispatcher({ modules, http: http2, rootDir, state });
4937
4894
  console.log(
4938
- bold8(`
4939
- ${cyan3("\u{1F441}")} Watching for changes in ${bold8(rootDir)}\u2026`) + ` ${bold8(yellow6("(Ctrl-C to stop)"))}`
4895
+ bold9(`
4896
+ ${cyan3("\u{1F441}")} Watching for changes in ${bold9(rootDir)}\u2026`) + ` ${bold9(yellow7("(Ctrl-C to stop)"))}`
4940
4897
  );
4941
4898
  const watcher = chokidar.watch(watchDirs, {
4942
4899
  ignoreInitial: true,
@@ -4944,16 +4901,25 @@ ${cyan3("\u{1F441}")} Watching for changes in ${bold8(rootDir)}\u2026`) + ` ${
4944
4901
  ignored: buildWatchIgnored(modules, rootDir),
4945
4902
  awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 }
4946
4903
  });
4947
- watcher.on("add", (p) => dispatcher.handleEvent("add", p));
4948
- watcher.on("change", (p) => dispatcher.handleEvent("change", p));
4949
- watcher.on("unlink", (p) => dispatcher.handleEvent("unlink", p));
4904
+ watcher.on(
4905
+ "add",
4906
+ (p) => dispatcher.handleEvent("add", p).catch((err) => console.warn(`[sync/dev] add: ${formatError2(err)}`))
4907
+ );
4908
+ watcher.on(
4909
+ "change",
4910
+ (p) => dispatcher.handleEvent("change", p).catch((err) => console.warn(`[sync/dev] change: ${formatError2(err)}`))
4911
+ );
4912
+ watcher.on(
4913
+ "unlink",
4914
+ (p) => dispatcher.handleEvent("unlink", p).catch((err) => console.warn(`[sync/dev] unlink: ${formatError2(err)}`))
4915
+ );
4950
4916
  watcher.on(
4951
4917
  "error",
4952
- (err) => console.warn(bold8(yellow6(`
4918
+ (err) => console.warn(bold9(yellow7(`
4953
4919
  \u26A0 Watcher error: ${formatError2(err)}`)))
4954
4920
  );
4955
4921
  const shutdown = () => {
4956
- console.log(bold8("\nStopping watcher\u2026"));
4922
+ console.log(bold9("\nStopping watcher\u2026"));
4957
4923
  dispatcher.dispose();
4958
4924
  watcher.close().then(() => process.exit(0));
4959
4925
  };