@venizia/vulcan 0.4.10-13 → 0.4.10-14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/vulcan",
3
- "version": "0.4.10-13",
3
+ "version": "0.4.10-14",
4
4
  "description": "VULCAN - one setup, one workflow for every project: init, sync, doctor, upgrade, and `vulcan x` for the shipped tools. Bun-only.",
5
5
  "homepage": "https://github.com/VENIZIA-AI/vulcan/tree/main/packages/cli",
6
6
  "bugs": {
@@ -45,8 +45,8 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@clack/prompts": "1.8.1",
48
- "@venizia/vulcan-atlas": "0.4.10-13",
49
- "@venizia/vulcan-okf": "0.4.10-13",
48
+ "@venizia/vulcan-atlas": "0.4.10-14",
49
+ "@venizia/vulcan-okf": "0.4.10-14",
50
50
  "zod": "^4.6.7"
51
51
  },
52
52
  "devDependencies": {
@@ -1,9 +1,53 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
1
3
  import { ExitCodes } from '../common/index.ts';
2
4
  import type { ICommandContext } from '../common/index.ts';
5
+ import { ConfigLoader } from '../config/index.ts';
3
6
  import { runXCommand } from './x.command.ts';
4
7
 
5
8
  const SUBCOMMANDS = new Set(['plan', 'apply']);
6
9
 
10
+ /**
11
+ * The project a folder belongs to: the nearest folder at or above `cwd` that has a VULCAN config, never
12
+ * above the git work tree root (a config of an unrelated parent is not this project's). `undefined` when
13
+ * there is none, so the folder is served as it is and atlas says there is nothing to serve.
14
+ */
15
+ const enclosingProjectOf = (opts: { cwd: string }): string | undefined => {
16
+ let directory = opts.cwd;
17
+
18
+ for (;;) {
19
+ if (ConfigLoader.findFile({ root: directory }) !== undefined) {
20
+ return directory;
21
+ }
22
+
23
+ const parent = dirname(directory);
24
+
25
+ if (existsSync(join(directory, '.git')) || parent === directory) {
26
+ return undefined;
27
+ }
28
+
29
+ directory = parent;
30
+ }
31
+ };
32
+
33
+ /** `--app` made absolute against the folder the command was run in, and added (as that folder) when absent. */
34
+ const withApp = (opts: { args: string[]; cwd: string }): string[] => {
35
+ const args = [...opts.args];
36
+ const at = args.findIndex((arg) => arg === '--app' || arg.startsWith('--app='));
37
+
38
+ if (at === -1) {
39
+ return [...args, '--app', opts.cwd];
40
+ }
41
+
42
+ if (args[at] === '--app') {
43
+ args[at + 1] = resolve(opts.cwd, args[at + 1] ?? '');
44
+ } else {
45
+ args[at] = `--app=${resolve(opts.cwd, args[at].slice('--app='.length))}`;
46
+ }
47
+
48
+ return args;
49
+ };
50
+
7
51
  /** `vulcan migrate plan|apply`: atlas's `migrate` run at the pinned version, over the sources this project serves. */
8
52
  export const runMigrateCommand = (opts: ICommandContext): Promise<number> => {
9
53
  if (!SUBCOMMANDS.has(opts.args[0] ?? '')) {
@@ -14,5 +58,14 @@ export const runMigrateCommand = (opts: ICommandContext): Promise<number> => {
14
58
  return Promise.resolve(ExitCodes.USAGE);
15
59
  }
16
60
 
17
- return runXCommand({ ...opts, args: ['atlas', 'migrate', ...opts.args] });
61
+ const project = enclosingProjectOf({ cwd: opts.cwd });
62
+
63
+ // Run in the project that has the config; the app is the folder the command was run in unless `--app` says otherwise.
64
+ return project === undefined || project === opts.cwd
65
+ ? runXCommand({ ...opts, args: ['atlas', 'migrate', ...opts.args] })
66
+ : runXCommand({
67
+ ...opts,
68
+ cwd: project,
69
+ args: ['atlas', 'migrate', ...withApp({ args: opts.args, cwd: opts.cwd })],
70
+ });
18
71
  };