@mettlecast/domain-cli 0.2.85 → 0.2.86

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.
@@ -120,9 +120,8 @@ export async function runBuildCatalog(registryDir) {
120
120
  });
121
121
  }
122
122
  }
123
- const mcDir = join(process.cwd(), '.mc');
124
- await mkdir(mcDir, { recursive: true });
125
- const outPath = join(mcDir, 'domain-registry.json');
123
+ const outPath = join(dir, 'domain-registry.json');
124
+ await mkdir(dir, { recursive: true });
126
125
  await writeFile(outPath, JSON.stringify(catalog), 'utf8');
127
126
  cliLogger.info({ outPath, domains: catalog.domains.length, actions: catalog.actions.length, events: catalog.events.length, jobs: catalog.jobs.length, schedules: catalog.schedules.length, integrations: catalog.integrations.length }, 'Domain catalog written');
128
127
  return catalog;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mettlecast/domain-cli",
3
- "version": "0.2.85",
3
+ "version": "0.2.86",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",
@@ -0,0 +1,89 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { writeFile, readFile, mkdir } from 'node:fs/promises';
3
+ import { createHash } from 'node:crypto';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { join, resolve } from 'node:path';
6
+ import { tmpdir } from 'node:os';
7
+ import { rmSync } from 'node:fs';
8
+ import { runBuildCatalog } from '../../commands/build-catalog.js';
9
+
10
+ describe('build-catalog', () => {
11
+ let tempDir: string;
12
+
13
+ beforeEach(async () => {
14
+ tempDir = join(tmpdir(), `tib-build-catalog-${Math.random().toString(36).slice(2)}`);
15
+ await mkdir(tempDir, { recursive: true });
16
+ });
17
+
18
+ afterEach(() => {
19
+ rmSync(tempDir, { recursive: true, force: true });
20
+ });
21
+
22
+ /**
23
+ * Regression test for #5087.
24
+ * When registryDir is explicitly given, the catalog output must be written
25
+ * to that directory (resolved) — NOT to process.cwd()/.mc.
26
+ * This ensures --mc-dir controls both read and write locations.
27
+ */
28
+ it('writes catalog to the resolved registryDir, not to cwd/.mc (#5087)', async () => {
29
+ // Arrange: seed a temp .mc directory with one per-domain registry file.
30
+ const mcDir = join(tempDir, '.mc');
31
+ await mkdir(mcDir, { recursive: true });
32
+
33
+ await writeFile(
34
+ join(mcDir, 'test-domain-registry.json'),
35
+ JSON.stringify({
36
+ domain: { id: 'test-domain', name: 'Test Domain', tenancy: 'required' },
37
+ actions: [],
38
+ events: [],
39
+ subscribers: [],
40
+ jobs: [],
41
+ schedules: [],
42
+ integrations: [],
43
+ })
44
+ );
45
+
46
+ // Capture hash of the project's existing domain-registry.json (if any)
47
+ // so we can assert the test did NOT overwrite it.
48
+ const projectCatalogPath = join(process.cwd(), '.mc', 'domain-registry.json');
49
+ const beforeHash = existsSync(projectCatalogPath)
50
+ ? createHash('sha256').update(readFileSync(projectCatalogPath)).digest('hex')
51
+ : null;
52
+
53
+ // Act: pass explicit registryDir (the temp .mc dir)
54
+ const catalog = await runBuildCatalog(mcDir);
55
+
56
+ // Assert — output landed inside the resolved registryDir
57
+ const outPath = join(mcDir, 'domain-registry.json');
58
+ expect(existsSync(outPath)).toBe(true);
59
+
60
+ const onDisk = JSON.parse(await readFile(outPath, 'utf8'));
61
+ expect(onDisk.version).toBe(2);
62
+ expect(onDisk.generatedAt).toBeDefined();
63
+ expect(onDisk.domains).toHaveLength(1);
64
+ expect(onDisk.domains[0]?.id).toBe('test-domain');
65
+
66
+ // Returned catalog matches what was written
67
+ expect(catalog.domains[0]?.id).toBe('test-domain');
68
+
69
+ // Assert — project .mc/domain-registry.json must NOT have been touched
70
+ const afterHash = existsSync(projectCatalogPath)
71
+ ? createHash('sha256').update(readFileSync(projectCatalogPath)).digest('hex')
72
+ : null;
73
+ expect(afterHash).toBe(beforeHash);
74
+ });
75
+
76
+ it('preserves default behavior when registryDir is omitted', async () => {
77
+ // Seed cwd/.mc with a temp registry file. We can't actually create
78
+ // files in cwd, but we CAN verify the default directory resolution
79
+ // produces the expected path relative to cwd.
80
+ // Instead, create a temp dir and pass no argument, then verify
81
+ // the function resolves dir to process.cwd() + '/.mc'.
82
+ // Since the project's .mc may have real registries, just verify
83
+ // no error is thrown and a valid catalog is returned.
84
+ const catalog = await runBuildCatalog();
85
+ expect(catalog.version).toBe(2);
86
+ expect(Array.isArray(catalog.domains)).toBe(true);
87
+ expect(Array.isArray(catalog.actions)).toBe(true);
88
+ });
89
+ });
@@ -213,9 +213,8 @@ export async function runBuildCatalog(registryDir?: string): Promise<DomainCatal
213
213
  }
214
214
  }
215
215
 
216
- const mcDir = join(process.cwd(), '.mc');
217
- await mkdir(mcDir, { recursive: true });
218
- const outPath = join(mcDir, 'domain-registry.json');
216
+ const outPath = join(dir, 'domain-registry.json');
217
+ await mkdir(dir, { recursive: true });
219
218
  await writeFile(outPath, JSON.stringify(catalog), 'utf8');
220
219
 
221
220
  cliLogger.info(