@roarkanalytics/cli 0.51.2 → 0.53.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.53.0](https://github.com/roarkhq/cli-roark-analytics/compare/v0.52.0...v0.53.0) (2026-10-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * **cli:** send X-Roark-Client on every API request ([#137](https://github.com/roarkhq/cli-roark-analytics/issues/137)) ([8efb7e8](https://github.com/roarkhq/cli-roark-analytics/commit/8efb7e8d78775f6e8185c9fe85764ed69c49be10))
9
+
10
+ ## [0.52.0](https://github.com/roarkhq/cli-roark-analytics/compare/v0.51.2...v0.52.0) (2026-10-25)
11
+
12
+
13
+ ### Features
14
+
15
+ * **config:** evaluate a TypeScript config file, not just a YAML directory ([#135](https://github.com/roarkhq/cli-roark-analytics/issues/135)) ([85779d1](https://github.com/roarkhq/cli-roark-analytics/commit/85779d1f8b0b3d8660e08a463159fe57458b16ea))
16
+
3
17
  ## [0.51.2](https://github.com/roarkhq/cli-roark-analytics/compare/v0.51.1...v0.51.2) (2026-10-23)
4
18
 
5
19
 
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@roarkanalytics/cli",
3
- "version": "0.51.2",
3
+ "version": "0.53.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@roarkanalytics/cli",
9
- "version": "0.51.2",
9
+ "version": "0.53.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@roarkanalytics/sdk": "^5.12.0",
13
13
  "commander": "^14.0.3",
14
+ "jiti": "^2.4.2",
14
15
  "yaml": "^2.9.0"
15
16
  },
16
17
  "bin": {
@@ -21,9 +22,9 @@
21
22
  }
22
23
  },
23
24
  "node_modules/@roarkanalytics/sdk": {
24
- "version": "5.12.0",
25
- "resolved": "https://registry.npmjs.org/@roarkanalytics/sdk/-/sdk-5.12.0.tgz",
26
- "integrity": "sha512-s+DRYkWPWvFha9Ri51sah7Nkm5t9RdTFX5bwfLpX5q87B/6VZiWD6Dwp2gkQwdErNyK8+P2X3mpwSUvFp1o85g==",
25
+ "version": "5.14.0",
26
+ "resolved": "https://registry.npmjs.org/@roarkanalytics/sdk/-/sdk-5.14.0.tgz",
27
+ "integrity": "sha512-DOQBoDCs4C2cDISP6LHR/DZ6uIaD05zfT+BjwH3H0ftnIpXKh5Cxnv+ibC49McGK0t4WeRmC96u4SBWDR/iXNw==",
27
28
  "license": "Apache-2.0"
28
29
  },
29
30
  "node_modules/commander": {
@@ -35,6 +36,15 @@
35
36
  "node": ">=20"
36
37
  }
37
38
  },
39
+ "node_modules/jiti": {
40
+ "version": "2.7.0",
41
+ "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz",
42
+ "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==",
43
+ "license": "MIT",
44
+ "bin": {
45
+ "jiti": "lib/jiti-cli.mjs"
46
+ }
47
+ },
38
48
  "node_modules/yaml": {
39
49
  "version": "2.9.1",
40
50
  "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roarkanalytics/cli",
3
- "version": "0.51.2",
3
+ "version": "0.53.0",
4
4
  "description": "The official command line interface for the Roark API",
5
5
  "author": "Roark <james@roark.ai>",
6
6
  "type": "commonjs",
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "@roarkanalytics/sdk": "^5.12.0",
33
33
  "commander": "^14.0.3",
34
+ "jiti": "^2.4.2",
34
35
  "yaml": "^2.9.0"
35
36
  },
36
37
  "man": [
@@ -2,9 +2,11 @@
2
2
  * `roark config diff [dir]` and `roark config apply [dir]` - config as code.
3
3
  *
4
4
  * These wrap the generated `config.diff` / `config.apply` SDK methods with the one client-side
5
- * step they need to be useful: building the bundle from a directory of YAML files. Point either
6
- * at a config directory and it reads `*.yaml`, inlines `file://` references, and submits the
7
- * `{ resources, prune }` bundle. `--data`/stdin still take a pre-built bundle for scripting.
5
+ * step they need to be useful: building the `{ resources, prune }` bundle. Point either at a
6
+ * directory of YAML (`*.yaml`, with `file://` references inlined) or at a TypeScript config file
7
+ * (`roark.config.ts`, whose `defineConfig(...)` default export is evaluated with jiti); with no
8
+ * argument it auto-detects `roark.config.ts` in the cwd. `--data`/stdin still take a pre-built
9
+ * bundle for scripting.
8
10
  *
9
11
  * `apply` previews the diff and asks to confirm before writing (config-managed resources absent
10
12
  * from the bundle are deleted unless `--no-prune`), so a destructive apply is never a surprise.
@@ -3,9 +3,11 @@
3
3
  * `roark config diff [dir]` and `roark config apply [dir]` - config as code.
4
4
  *
5
5
  * These wrap the generated `config.diff` / `config.apply` SDK methods with the one client-side
6
- * step they need to be useful: building the bundle from a directory of YAML files. Point either
7
- * at a config directory and it reads `*.yaml`, inlines `file://` references, and submits the
8
- * `{ resources, prune }` bundle. `--data`/stdin still take a pre-built bundle for scripting.
6
+ * step they need to be useful: building the `{ resources, prune }` bundle. Point either at a
7
+ * directory of YAML (`*.yaml`, with `file://` references inlined) or at a TypeScript config file
8
+ * (`roark.config.ts`, whose `defineConfig(...)` default export is evaluated with jiti); with no
9
+ * argument it auto-detects `roark.config.ts` in the cwd. `--data`/stdin still take a pre-built
10
+ * bundle for scripting.
9
11
  *
10
12
  * `apply` previews the diff and asks to confirm before writing (config-managed resources absent
11
13
  * from the bundle are deleted unless `--no-prune`), so a destructive apply is never a surprise.
@@ -14,12 +16,14 @@
14
16
  */
15
17
  Object.defineProperty(exports, "__esModule", { value: true });
16
18
  exports.registerConfigAsCodeCommands = void 0;
19
+ const promises_1 = require("node:fs/promises");
17
20
  const commander_1 = require("commander");
18
21
  const confirm_1 = require("../confirm");
19
22
  const errors_1 = require("../errors");
20
23
  const input_1 = require("../input");
21
24
  const output_1 = require("../output");
22
25
  const config_bundle_1 = require("../config-bundle");
26
+ const config_module_1 = require("../config-module");
23
27
  const OP_MARK = { create: '+', update: '~', delete: '-', noop: ' ' };
24
28
  /** One-line-per-change summary for a terminal; `apply` results also carry a status. */
25
29
  const formatChanges = (data) => {
@@ -39,11 +43,25 @@ const formatChanges = (data) => {
39
43
  return [...lines, '', tally].join('\n');
40
44
  };
41
45
  const changeCount = (summary) => (summary['create'] ?? 0) + (summary['update'] ?? 0) + (summary['delete'] ?? 0);
42
- /** Resolve the bundle: a directory (build it) or a pre-built bundle via --data / piped stdin. */
43
- const resolveBundle = async (dir, options) => {
46
+ /**
47
+ * Resolve the bundle from a `path`, `--data`/stdin, or an auto-detected config file:
48
+ * - a directory → build it from YAML
49
+ * - a `.ts`/`.js` file → evaluate it (the `defineConfig(...)` default export)
50
+ * - `--data`/piped stdin → a pre-built JSON bundle
51
+ * - nothing → auto-detect `roark.config.ts` in the cwd (like `sst.config.ts`)
52
+ */
53
+ const resolveBundle = async (path, options) => {
44
54
  const prune = options['prune'] === false ? false : undefined;
45
- if (dir !== undefined) {
46
- return (0, config_bundle_1.buildBundle)(dir, { ...(prune === undefined ? {} : { prune }) });
55
+ const pruneOpt = prune === undefined ? {} : { prune };
56
+ if (path !== undefined) {
57
+ const info = await (0, promises_1.stat)(path).catch(() => null);
58
+ if (info?.isDirectory())
59
+ return (0, config_bundle_1.buildBundle)(path, pruneOpt);
60
+ if (info?.isFile() && (0, config_module_1.isConfigModulePath)(path))
61
+ return (0, config_module_1.loadConfigModule)(path, pruneOpt);
62
+ if (!info)
63
+ throw new errors_1.UsageError(`path not found: ${path}`);
64
+ throw new errors_1.UsageError(`${path} is not a config directory or a .ts/.js config file`);
47
65
  }
48
66
  const explicit = options['data'] === undefined ? undefined : (0, input_1.readData)(options['data']);
49
67
  const piped = explicit === undefined && (0, input_1.stdinIsPiped)() ?
@@ -53,11 +71,17 @@ const resolveBundle = async (dir, options) => {
53
71
  })()
54
72
  : undefined;
55
73
  const body = explicit ?? piped;
56
- if (body === undefined || typeof body !== 'object') {
57
- throw new errors_1.UsageError('provide a config directory (e.g. `./roark`), or a bundle via --data / stdin');
74
+ if (body !== undefined) {
75
+ if (typeof body !== 'object')
76
+ throw new errors_1.UsageError('--data / stdin must be a JSON bundle object');
77
+ const bundle = body;
78
+ return prune === undefined ? bundle : { ...bundle, prune };
58
79
  }
59
- const bundle = body;
60
- return prune === undefined ? bundle : { ...bundle, prune };
80
+ // Nothing given: fall back to a config file in the working directory.
81
+ const auto = (0, config_module_1.findDefaultConfigModule)(process.cwd());
82
+ if (auto)
83
+ return (0, config_module_1.loadConfigModule)(auto, pruneOpt);
84
+ throw new errors_1.UsageError('provide a config directory (e.g. `./roark`), a .ts config file, or a bundle via --data / stdin');
61
85
  };
62
86
  const configGroup = (root) => {
63
87
  const existing = root.commands.find((child) => child.name() === 'config');
@@ -81,11 +105,16 @@ const withCommonOptions = (command) => command
81
105
  .showHelpAfterError();
82
106
  const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput) => {
83
107
  const config = configGroup(root);
84
- withCommonOptions(config.command('diff [dir]'))
85
- .description('Preview the changes a config directory (or bundle) would make. No writes.')
86
- .addHelpText('after', ['', 'Examples:', ` ${binaryName} config diff ./roark`].join('\n'))
87
- .action(async (dir, options) => {
88
- const bundle = await resolveBundle(dir, options);
108
+ withCommonOptions(config.command('diff [path]'))
109
+ .description('Preview the changes a config directory, .ts config file, or bundle would make. No writes.')
110
+ .addHelpText('after', [
111
+ '',
112
+ 'Examples:',
113
+ ` ${binaryName} config diff ./roark`,
114
+ ` ${binaryName} config diff roark.config.ts`,
115
+ ].join('\n'))
116
+ .action(async (path, options) => {
117
+ const bundle = await resolveBundle(path, options);
89
118
  const client = clientFor(options);
90
119
  const result = await client.config.diff(bundle);
91
120
  const output = resolveOutput(options);
@@ -93,13 +122,18 @@ const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput
93
122
  (0, output_1.render)(result.data, output)
94
123
  : formatChanges(result.data));
95
124
  });
96
- withCommonOptions(config.command('apply [dir]'))
97
- .description('Reconcile the project to a config directory (or bundle). Previews and confirms first.')
125
+ withCommonOptions(config.command('apply [path]'))
126
+ .description('Reconcile the project to a config directory, .ts config file, or bundle. Previews and confirms first.')
98
127
  .option('-y, --yes', 'skip the confirmation prompt')
99
128
  .option('--no-input', 'never prompt; fail instead')
100
- .addHelpText('after', ['', 'Examples:', ` ${binaryName} config apply ./roark`].join('\n'))
101
- .action(async (dir, options) => {
102
- const bundle = await resolveBundle(dir, options);
129
+ .addHelpText('after', [
130
+ '',
131
+ 'Examples:',
132
+ ` ${binaryName} config apply ./roark`,
133
+ ` ${binaryName} config apply roark.config.ts`,
134
+ ].join('\n'))
135
+ .action(async (path, options) => {
136
+ const bundle = await resolveBundle(path, options);
103
137
  const client = clientFor(options);
104
138
  const output = resolveOutput(options);
105
139
  const json = output.format === 'json' || options['json'] === true;
@@ -123,9 +157,10 @@ const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput
123
157
  });
124
158
  config.addHelpText('after', [
125
159
  '',
126
- 'Config as code: keep your Roark resources as YAML in git and sync them.',
127
- ` ${binaryName} config diff ./roark # preview`,
128
- ` ${binaryName} config apply ./roark # reconcile (asks to confirm)`,
160
+ 'Config as code: keep your Roark resources in git (YAML or TypeScript) and sync them.',
161
+ ` ${binaryName} config apply ./roark # a directory of YAML`,
162
+ ` ${binaryName} config apply roark.config.ts # a TypeScript config (defineConfig)`,
163
+ ` ${binaryName} config apply # auto-detects roark.config.ts in the cwd`,
129
164
  ].join('\n'));
130
165
  };
131
166
  exports.registerConfigAsCodeCommands = registerConfigAsCodeCommands;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Load a config-as-code bundle from a TypeScript (or JS) config file.
3
+ *
4
+ * The code-first counterpart to `config-bundle.ts` (which walks a YAML directory). Point the CLI
5
+ * at a `roark.config.ts` and it evaluates the module with jiti — the same zero-build TS loader
6
+ * tools like SST and Vitest use for their `*.config.ts` — and reads its default export: the
7
+ * `{ resources, prune }` bundle a `defineConfig(...)` returns (or a bare array of resources, or a
8
+ * function returning either). The result is the exact same bundle the YAML path produces, so it
9
+ * flows through the identical `config diff` / `config apply` without any new API surface.
10
+ *
11
+ * jiti resolves the config file's own imports (e.g. `@roarkanalytics/sdk/lib/config`) relative to
12
+ * the file, so they come from the user's project, not the CLI's bundled dependencies.
13
+ */
14
+ import type { ConfigBundle } from './config-bundle';
15
+ /** Whether a path looks like a TypeScript/JS config entrypoint (vs. a YAML directory). */
16
+ export declare const isConfigModulePath: (path: string) => boolean;
17
+ /** The first `roark.config.*` present in `cwd`, or undefined — like `sst` finding `sst.config.ts`. */
18
+ export declare const findDefaultConfigModule: (cwd: string) => string | undefined;
19
+ /**
20
+ * Evaluate a config module and normalize its export to a bundle. A `--no-prune` flag
21
+ * (`options.prune === false`) overrides whatever the module set; otherwise the module's own
22
+ * `prune` (from `defineConfig`) is kept.
23
+ */
24
+ export declare const loadConfigModule: (file: string, options?: {
25
+ prune?: boolean;
26
+ }) => Promise<ConfigBundle>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * Load a config-as-code bundle from a TypeScript (or JS) config file.
4
+ *
5
+ * The code-first counterpart to `config-bundle.ts` (which walks a YAML directory). Point the CLI
6
+ * at a `roark.config.ts` and it evaluates the module with jiti — the same zero-build TS loader
7
+ * tools like SST and Vitest use for their `*.config.ts` — and reads its default export: the
8
+ * `{ resources, prune }` bundle a `defineConfig(...)` returns (or a bare array of resources, or a
9
+ * function returning either). The result is the exact same bundle the YAML path produces, so it
10
+ * flows through the identical `config diff` / `config apply` without any new API surface.
11
+ *
12
+ * jiti resolves the config file's own imports (e.g. `@roarkanalytics/sdk/lib/config`) relative to
13
+ * the file, so they come from the user's project, not the CLI's bundled dependencies.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.loadConfigModule = exports.findDefaultConfigModule = exports.isConfigModulePath = void 0;
17
+ const node_fs_1 = require("node:fs");
18
+ const node_path_1 = require("node:path");
19
+ const node_url_1 = require("node:url");
20
+ const jiti_1 = require("jiti");
21
+ const errors_1 = require("./errors");
22
+ const MODULE_EXTENSIONS = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'];
23
+ /** Whether a path looks like a TypeScript/JS config entrypoint (vs. a YAML directory). */
24
+ const isConfigModulePath = (path) => MODULE_EXTENSIONS.some((ext) => path.endsWith(ext));
25
+ exports.isConfigModulePath = isConfigModulePath;
26
+ /** The default config entrypoints to auto-detect in the working directory, in order. */
27
+ const DEFAULT_CONFIG_FILES = ['roark.config.ts', 'roark.config.mts', 'roark.config.js', 'roark.config.mjs'];
28
+ /** The first `roark.config.*` present in `cwd`, or undefined — like `sst` finding `sst.config.ts`. */
29
+ const findDefaultConfigModule = (cwd) => {
30
+ for (const name of DEFAULT_CONFIG_FILES) {
31
+ const candidate = (0, node_path_1.resolve)(cwd, name);
32
+ if ((0, node_fs_1.existsSync)(candidate))
33
+ return candidate;
34
+ }
35
+ return undefined;
36
+ };
37
+ exports.findDefaultConfigModule = findDefaultConfigModule;
38
+ /**
39
+ * Evaluate a config module and normalize its export to a bundle. A `--no-prune` flag
40
+ * (`options.prune === false`) overrides whatever the module set; otherwise the module's own
41
+ * `prune` (from `defineConfig`) is kept.
42
+ */
43
+ const loadConfigModule = async (file, options = {}) => {
44
+ const abs = (0, node_path_1.resolve)(file);
45
+ const jiti = (0, jiti_1.createJiti)((0, node_url_1.pathToFileURL)(abs).href);
46
+ let mod;
47
+ try {
48
+ mod = await jiti.import(abs);
49
+ }
50
+ catch (error) {
51
+ throw new errors_1.UsageError(`failed to load config file ${file}: ${error.message}`);
52
+ }
53
+ // Prefer the default export; accept a bundle object, a bare resources array, or a
54
+ // (possibly async) function returning either.
55
+ const record = mod && typeof mod === 'object' ? mod : {};
56
+ let exported = 'default' in record ? record['default'] : mod;
57
+ if (typeof exported === 'function')
58
+ exported = await exported();
59
+ exported = await exported;
60
+ const bundle = Array.isArray(exported) ? { resources: exported } : exported;
61
+ if (!bundle || typeof bundle !== 'object' || !Array.isArray(bundle.resources)) {
62
+ throw new errors_1.UsageError(`config file ${file} must export (as default) a bundle from defineConfig(...), or an array of resources`);
63
+ }
64
+ const typed = bundle;
65
+ const prune = options.prune === false ? false : typed.prune;
66
+ return { resources: typed.resources, ...(prune === undefined ? {} : { prune }) };
67
+ };
68
+ exports.loadConfigModule = loadConfigModule;
@@ -22,6 +22,7 @@ const config_2 = require("./config");
22
22
  const errors_1 = require("./errors");
23
23
  const input_1 = require("./input");
24
24
  const output_1 = require("./output");
25
+ const version_1 = require("../version");
25
26
  /** Verbs whose effect a user cannot undo, so they get a confirmation prompt. */
26
27
  const DESTRUCTIVE_VERBS = new Set(['delete']);
27
28
  const isDestructive = (command) => DESTRUCTIVE_VERBS.has(command.commandPath.at(-1) ?? '');
@@ -142,6 +143,10 @@ const clientFor = (options, requiresAuth = true) => {
142
143
  ...(config.baseURL === undefined ? {} : { baseURL: config.baseURL }),
143
144
  ...(config.timeout === undefined ? {} : { timeout: config.timeout }),
144
145
  ...(config.maxRetries === undefined ? {} : { maxRetries: config.maxRetries }),
146
+ // Tells the API this request came from the CLI. The SDK's own user agent is
147
+ // the same for every program built on it, so without this a CLI command is
148
+ // counted as plain SDK usage.
149
+ defaultHeaders: { 'X-Roark-Client': `cli/${version_1.version}` },
145
150
  });
146
151
  };
147
152
  const resolveOutput = (options) => ({
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.51.2";
1
+ export declare const version = "0.53.0";
package/version.js CHANGED
@@ -10,4 +10,4 @@ exports.version = void 0;
10
10
  //
11
11
  // Do not edit: an edit here is overwritten, and the published number is whatever
12
12
  // package.json says.
13
- exports.version = '0.51.2'; // x-release-please-version
13
+ exports.version = '0.53.0'; // x-release-please-version