@t0.labs/daxta 0.2.0 → 0.2.1

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.
@@ -37,27 +37,7 @@ exports.installDaxta = installDaxta;
37
37
  const fs_1 = require("fs");
38
38
  const path = __importStar(require("path"));
39
39
  const child_process_1 = require("child_process");
40
- function walk(dir, match, out = [], depth = 0) {
41
- if (depth > 6 || !(0, fs_1.existsSync)(dir))
42
- return out;
43
- for (const name of (0, fs_1.readdirSync)(dir)) {
44
- if (name === 'node_modules' || name === 'dist' || name === '.git' || name === 'coverage')
45
- continue;
46
- const full = path.join(dir, name);
47
- let st;
48
- try {
49
- st = (0, fs_1.statSync)(full);
50
- }
51
- catch {
52
- continue;
53
- }
54
- if (st.isDirectory())
55
- walk(full, match, out, depth + 1);
56
- else if (match(name))
57
- out.push(full);
58
- }
59
- return out;
60
- }
40
+ const inject_main_1 = require("./inject-main");
61
41
  function readJson(filePath) {
62
42
  return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
63
43
  }
@@ -71,9 +51,17 @@ function detectPackageManager(cwd, pkg) {
71
51
  return 'yarn';
72
52
  return 'npm';
73
53
  }
54
+ function ensureDependency(pkg) {
55
+ const inDeps = Boolean(pkg.dependencies?.['@t0.labs/daxta'] || pkg.devDependencies?.['@t0.labs/daxta']);
56
+ if (inDeps)
57
+ return false;
58
+ pkg.devDependencies = { ...(pkg.devDependencies ?? {}), '@t0.labs/daxta': '^0.2.0' };
59
+ return true;
60
+ }
74
61
  function ensureScripts(pkg) {
75
62
  const scripts = (pkg.scripts ??= {});
76
63
  const wanted = {
64
+ 'daxta:test': 'daxta test',
77
65
  'daxta:build': 'daxta build',
78
66
  'daxta:serve': 'daxta serve',
79
67
  'daxta:fields': 'daxta fields',
@@ -86,41 +74,35 @@ function ensureScripts(pkg) {
86
74
  changed.push(key);
87
75
  }
88
76
  }
89
- return changed;
90
- }
91
- function withNodeRequire(command, moduleId) {
92
- if (command.includes(moduleId))
93
- return command;
94
- if (command.startsWith('NODE_OPTIONS=')) {
95
- return command.replace(/NODE_OPTIONS=(['"]?)([^'"]*)\1/, (_, q, val) => {
96
- const next = val.includes(moduleId) ? val : `${val} --require ${moduleId}`.trim();
97
- return `NODE_OPTIONS=${q}${next}${q}`;
98
- });
77
+ // drop legacy alias that wrapped NODE_OPTIONS
78
+ if (scripts['daxta:start']) {
79
+ delete scripts['daxta:start'];
80
+ changed.push('removed daxta:start');
99
81
  }
100
- return `NODE_OPTIONS='--require ${moduleId}' ${command}`;
82
+ return changed;
101
83
  }
102
- function ensureNestRegister(pkg) {
103
- const scripts = (pkg.scripts ??= {});
84
+ /** Remove NODE_OPTIONS=--require @t0.labs/daxta/register hacks from start scripts. */
85
+ function stripRegisterNodeOptions(pkg) {
86
+ const scripts = pkg.scripts ?? {};
104
87
  const changed = [];
105
- for (const key of ['start', 'start:dev', 'start:debug', 'start:prod']) {
106
- const current = scripts[key];
107
- if (!current)
88
+ const re = /^NODE_OPTIONS=(['"])?(?:[^'"]*\s)?--require\s+@t0\.labs\/daxta\/register\s*([^'"]*)\1\s+/i;
89
+ for (const [key, value] of Object.entries(scripts)) {
90
+ if (!value.includes('@t0.labs/daxta/register'))
108
91
  continue;
109
- const next = withNodeRequire(current, '@t0.labs/daxta/register');
110
- if (next !== current) {
92
+ let next = value.replace(re, '');
93
+ // also strip mid-string require if somehow embedded
94
+ next = next
95
+ .replace(/\s*--require\s+@t0\.labs\/daxta\/register\b/g, '')
96
+ .replace(/NODE_OPTIONS=(['"])\s*\1\s*/g, '')
97
+ .replace(/NODE_OPTIONS=\s+/g, '')
98
+ .trim();
99
+ if (next !== value) {
111
100
  scripts[key] = next;
112
101
  changed.push(key);
113
102
  }
114
103
  }
115
104
  return changed;
116
105
  }
117
- function ensureDependency(pkg) {
118
- const inDeps = Boolean(pkg.dependencies?.['@t0.labs/daxta'] || pkg.devDependencies?.['@t0.labs/daxta']);
119
- if (inDeps)
120
- return false;
121
- pkg.devDependencies = { ...(pkg.devDependencies ?? {}), '@t0.labs/daxta': '^0.1.0' };
122
- return true;
123
- }
124
106
  function writeConfig(cwd, dryRun) {
125
107
  const configPath = path.join(cwd, 'daxta.config.ts');
126
108
  if ((0, fs_1.existsSync)(configPath))
@@ -141,134 +123,23 @@ export default defineConfig({
141
123
  (0, fs_1.writeFileSync)(configPath, body);
142
124
  return `wrote ${configPath}`;
143
125
  }
144
- function patchJestConfig(filePath, dryRun) {
145
- const notes = [];
146
- let data;
147
- try {
148
- data = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
149
- }
150
- catch {
151
- return [`skip non-json jest config ${filePath}`];
152
- }
153
- const setup = Array.isArray(data.setupFilesAfterEnv) ? [...data.setupFilesAfterEnv] : [];
154
- if (!setup.includes('@t0.labs/daxta/setup')) {
155
- setup.unshift('@t0.labs/daxta/setup');
156
- data.setupFilesAfterEnv = setup;
157
- notes.push('setupFilesAfterEnv += @t0.labs/daxta/setup');
158
- }
159
- const reporters = Array.isArray(data.reporters) ? [...data.reporters] : ['default'];
160
- const hasDaxtaReporter = reporters.some((entry) => {
161
- if (entry === '@t0.labs/daxta/jest-reporter')
162
- return true;
163
- if (Array.isArray(entry) && entry[0] === '@t0.labs/daxta/jest-reporter')
164
- return true;
165
- return false;
166
- });
167
- if (!hasDaxtaReporter) {
168
- reporters.push('@t0.labs/daxta/jest-reporter');
169
- data.reporters = reporters;
170
- notes.push('reporters += @t0.labs/daxta/jest-reporter');
171
- }
172
- if (!data.globalSetup) {
173
- data.globalSetup = '@t0.labs/daxta/jest-global-setup';
174
- notes.push('globalSetup = @t0.labs/daxta/jest-global-setup');
175
- }
176
- if (!data.globalTeardown) {
177
- data.globalTeardown = '@t0.labs/daxta/jest-global-teardown';
178
- notes.push('globalTeardown = @t0.labs/daxta/jest-global-teardown');
179
- }
180
- if (!dryRun && notes.length)
181
- writeJson(filePath, data);
182
- return notes.map((n) => `${path.relative(process.cwd(), filePath)}: ${n}`);
183
- }
184
- function resolveRootDirPath(cwd, jestConfigPath, value) {
185
- if (!value.includes('<rootDir>'))
186
- return path.isAbsolute(value) ? value : path.join(cwd, value);
187
- // jest rootDir is often relative to the config file directory
188
- let rootDir = cwd;
189
- try {
190
- const cfg = readJson(jestConfigPath);
191
- if (cfg.rootDir)
192
- rootDir = path.resolve(path.dirname(jestConfigPath), cfg.rootDir);
193
- }
194
- catch {
195
- // ignore
126
+ function ensureGitignore(cwd, dryRun) {
127
+ const gitignorePath = path.join(cwd, '.gitignore');
128
+ const entry = 'daxta/out/';
129
+ if (!(0, fs_1.existsSync)(gitignorePath)) {
130
+ if (!dryRun)
131
+ (0, fs_1.writeFileSync)(gitignorePath, `${entry}\n**/.jest.daxta.runtime.json\n`);
132
+ return `wrote .gitignore (+ ${entry})`;
196
133
  }
197
- return value.replace('<rootDir>', rootDir);
198
- }
199
- function injectIntoTsFile(filePath, dryRun, kind) {
200
- if (!(0, fs_1.existsSync)(filePath))
134
+ const text = (0, fs_1.readFileSync)(gitignorePath, 'utf8');
135
+ const lines = text.split(/\r?\n/).map((l) => l.trim());
136
+ if (lines.includes(entry) || lines.includes('daxta/') || lines.includes('daxta/out')) {
201
137
  return null;
202
- let text = (0, fs_1.readFileSync)(filePath, 'utf8');
203
- const before = text;
204
- if (kind === 'setup') {
205
- if (text.includes('clearWorkerHits') && text.includes('@t0.labs/daxta'))
206
- return null;
207
- if (!text.includes("@t0.labs/daxta")) {
208
- text = `import { clearWorkerHits } from '@t0.labs/daxta';\n${text}`;
209
- }
210
- if (!/clearWorkerHits\s*\(/.test(text)) {
211
- text = text.replace(/(export\s+default\s+async\s+function[^{]*\{)/, '$1\n clearWorkerHits();');
212
- if (!/clearWorkerHits\s*\(/.test(text)) {
213
- text = text.replace(/(export\s+default\s+async\s*\(\s*\)\s*:\s*Promise<void>\s*=>\s*\{)/, '$1\n clearWorkerHits();');
214
- }
215
- }
216
- }
217
- else {
218
- if ((text.includes('buildDaxtaSpec') || text.includes('buildOpenApi')) && text.includes('@t0.labs/daxta'))
219
- return null;
220
- if (!text.includes('@t0.labs/daxta')) {
221
- text = `import { buildDaxtaSpec, clearPartialMarker } from '@t0.labs/daxta';\n${text}`;
222
- }
223
- if (!text.includes('buildDaxtaSpec(') && !text.includes('buildOpenApi(')) {
224
- const hook = `
225
- try {
226
- const result = buildDaxtaSpec({ silent: true });
227
- if (result.changed) {
228
- console.log(\`DAxTA docs updated (\${result.hits} hits, \${result.operations} operations)\`);
229
- }
230
- clearPartialMarker();
231
- } catch (error) {
232
- console.error('DAxTA build failed:', error);
233
- }
234
- `;
235
- text = text.replace(/(export\s+default\s+async\s+function[^{]*\{)/, `$1${hook}`);
236
- if (!text.includes('buildDaxtaSpec({ silent: true })')) {
237
- text = text.replace(/(export\s+default\s+async\s*\(\s*\)\s*:\s*Promise<void>\s*=>\s*\{)/, `$1${hook}`);
238
- }
239
- }
240
138
  }
241
- if (text === before)
242
- return null;
139
+ const extra = `${entry}\n**/.jest.daxta.runtime.json`;
243
140
  if (!dryRun)
244
- (0, fs_1.writeFileSync)(filePath, text);
245
- return `patched ${path.relative(process.cwd(), filePath)}`;
246
- }
247
- function stripManualNestMount(cwd, dryRun) {
248
- const notes = [];
249
- for (const rel of ['src/common/utils/start-daxta-docs.util.ts', 'src/common/utils/start-openapi-docs.util.ts']) {
250
- const file = path.join(cwd, rel);
251
- if (!(0, fs_1.existsSync)(file))
252
- continue;
253
- if (!dryRun)
254
- (0, fs_1.unlinkSync)(file);
255
- notes.push(`removed ${rel} (auto /docs via @t0.labs/daxta/register)`);
256
- }
257
- const configInit = path.join(cwd, 'src/common/utils/config-init.util.ts');
258
- if ((0, fs_1.existsSync)(configInit)) {
259
- let text = (0, fs_1.readFileSync)(configInit, 'utf8');
260
- const before = text;
261
- text = text.replace(/import\s+\{\s*startDaxtaDocs\s*\}\s+from\s+['"]\.\/start-daxta-docs\.util['"];\n?/g, '');
262
- text = text.replace(/import\s+\{\s*startOpenApiDocs\s*\}\s+from\s+['"]\.\/start-openapi-docs\.util['"];\n?/g, '');
263
- text = text.replace(/\n\s*startDaxtaDocs\(app\);\n?/g, '\n');
264
- text = text.replace(/\n\s*startOpenApiDocs\(app\);\n?/g, '\n');
265
- if (text !== before) {
266
- if (!dryRun)
267
- (0, fs_1.writeFileSync)(configInit, text);
268
- notes.push('cleaned Nest mount from src/common/utils/config-init.util.ts');
269
- }
270
- }
271
- return notes;
141
+ (0, fs_1.writeFileSync)(gitignorePath, text.endsWith('\n') ? `${text}${extra}\n` : `${text}\n${extra}\n`);
142
+ return `gitignore += ${entry}, **/.jest.daxta.runtime.json`;
272
143
  }
273
144
  function runPackageInstall(cwd, pm, dryRun) {
274
145
  if (dryRun)
@@ -279,7 +150,11 @@ function runPackageInstall(cwd, pm, dryRun) {
279
150
  throw new Error(`${pm} ${args.join(' ')} failed`);
280
151
  return `installed @t0.labs/daxta via ${pm}`;
281
152
  }
282
- function installDaxta(options = {}) {
153
+ /**
154
+ * Bootstrap: config, outDir, scripts, strip NODE_OPTIONS hacks,
155
+ * prompt to inject `docs(app)` into main.ts.
156
+ */
157
+ async function installDaxta(options = {}) {
283
158
  const cwd = options.cwd ?? process.cwd();
284
159
  const dryRun = Boolean(options.dryRun);
285
160
  const pkgPath = path.join(cwd, 'package.json');
@@ -292,42 +167,44 @@ function installDaxta(options = {}) {
292
167
  const depAdded = ensureDependency(pkg);
293
168
  if (depAdded)
294
169
  log.push('package.json: added @t0.labs/daxta to devDependencies');
170
+ const stripped = stripRegisterNodeOptions(pkg);
171
+ if (stripped.length)
172
+ log.push(`removed NODE_OPTIONS register from: ${stripped.join(', ')}`);
295
173
  const scriptChanges = ensureScripts(pkg);
296
174
  if (scriptChanges.length)
297
175
  log.push(`package.json scripts: ${scriptChanges.join(', ')}`);
298
- const nestScripts = ensureNestRegister(pkg);
299
- if (nestScripts.length)
300
- log.push(`Nest auto /docs via register on: ${nestScripts.join(', ')}`);
301
176
  if (!dryRun)
302
177
  writeJson(pkgPath, pkg);
303
178
  const outDir = path.join(cwd, 'daxta', 'out');
304
179
  if (!dryRun)
305
180
  (0, fs_1.mkdirSync)(outDir, { recursive: true });
306
- log.push(`outDir ready: daxta/out`);
307
- const jestConfigs = walk(cwd, (name) => name.startsWith('jest.') && name.endsWith('.json'));
308
- for (const file of jestConfigs) {
309
- log.push(...patchJestConfig(file, dryRun));
310
- try {
311
- const data = readJson(file);
312
- for (const key of ['globalSetup', 'globalTeardown']) {
313
- const value = data[key];
314
- if (typeof value !== 'string' || value.includes('daxta'))
315
- continue;
316
- const candidate = resolveRootDirPath(cwd, file, value);
317
- const note = injectIntoTsFile(candidate, dryRun, key === 'globalSetup' ? 'setup' : 'teardown');
318
- if (note)
319
- log.push(note);
320
- }
321
- }
322
- catch {
323
- // ignore
324
- }
325
- }
326
- log.push(...stripManualNestMount(cwd, dryRun));
181
+ log.push('outDir ready: daxta/out');
182
+ const gi = ensureGitignore(cwd, dryRun);
183
+ if (gi)
184
+ log.push(gi);
327
185
  if (!options.skipDep && depAdded)
328
186
  log.push(runPackageInstall(cwd, pm, dryRun));
329
187
  else if (!options.skipDep)
330
188
  log.push('@t0.labs/daxta already listed (skip package manager add)');
189
+ if (!options.skipMain) {
190
+ const note = await (0, inject_main_1.promptAndInjectMain)({
191
+ cwd,
192
+ dryRun,
193
+ yes: options.yes,
194
+ mainPath: options.mainPath,
195
+ });
196
+ if (note)
197
+ log.push(note);
198
+ }
331
199
  console.log('DAxTA install complete:\n' + log.map((line) => ` - ${line}`).join('\n'));
332
- console.log('\nNext: run your app / tests, then open http://localhost:<port>/docs');
200
+ console.log(`
201
+ Set in .env (required when docs(app) runs):
202
+ DAXTA_DOCS=true # enable /docs
203
+ DAXTA_DOCS=false # disable (explicit)
204
+
205
+ Then:
206
+ daxta test # record hits from integration tests
207
+ daxta serve # standalone docs viewer
208
+ daxta build # rebuild OpenAPI from hits
209
+ `);
333
210
  }
package/dist/cli/main.js CHANGED
@@ -6,32 +6,41 @@ const config_1 = require("../config");
6
6
  const export_fields_1 = require("../fields/export-fields");
7
7
  const serve_1 = require("../serve");
8
8
  const install_1 = require("./install");
9
+ const test_1 = require("./test");
9
10
  function usage() {
10
11
  console.log(`DAxTA CLI (@t0.labs/daxta)
11
12
 
12
13
  Usage:
13
- daxta install [--dry-run] [--skip-dep]
14
+ daxta install [--dry-run] [--skip-dep] [--skip-main] [--yes] [--main <path>]
14
15
  daxta init (alias of install)
16
+ daxta test [--config <jest.json>] [-- <jest args>]
15
17
  daxta build
16
18
  daxta serve [--port <n>]
17
19
  daxta fields [METHOD] [PATH] [--out <file>]
18
20
  daxta call [METHOD] [PATH] [--fields <file>] [--header k:v ...]
19
21
  daxta call --file <values.json> [--header k:v ...]
22
+
23
+ install:
24
+ writes config, strips NODE_OPTIONS register hacks, asks to inject
25
+ docs(app) into main.ts (requires DAXTA_DOCS env at runtime)
20
26
  `);
21
27
  }
22
28
  function parseArgs(argv) {
23
29
  const args = argv.slice(2);
24
30
  const command = args[0];
31
+ const rest = args.slice(1);
25
32
  const positional = [];
26
33
  const flags = {};
27
34
  const headers = {};
28
- for (let i = 1; i < args.length; i += 1) {
29
- const token = args[i];
30
- if (token === '--port' || token === '--out' || token === '--fields' || token === '--file') {
31
- flags[token.slice(2)] = args[++i];
35
+ for (let i = 0; i < rest.length; i += 1) {
36
+ const token = rest[i];
37
+ if (token === '--')
38
+ break;
39
+ if (token === '--port' || token === '--out' || token === '--fields' || token === '--file' || token === '--main') {
40
+ flags[token.slice(2)] = rest[++i];
32
41
  }
33
42
  else if (token === '--header') {
34
- const raw = args[++i] ?? '';
43
+ const raw = rest[++i] ?? '';
35
44
  const idx = raw.indexOf(':');
36
45
  if (idx === -1)
37
46
  throw new Error(`Invalid --header ${raw}; expected name:value`);
@@ -44,30 +53,38 @@ function parseArgs(argv) {
44
53
  positional.push(token);
45
54
  }
46
55
  }
47
- return { command, positional, flags, headers };
56
+ return { command, rest, positional, flags, headers };
48
57
  }
49
58
  async function main() {
50
59
  (0, config_1.resetConfig)();
51
60
  (0, config_1.getConfig)(true);
52
- const { command, positional, flags, headers } = parseArgs(process.argv);
61
+ const { command, rest, positional, flags, headers } = parseArgs(process.argv);
53
62
  if (!command || command === 'help' || command === '--help' || command === '-h') {
54
63
  usage();
55
64
  return;
56
65
  }
57
66
  if (command === 'install' || command === 'init') {
58
- (0, install_1.installDaxta)({
67
+ await (0, install_1.installDaxta)({
59
68
  dryRun: Boolean(flags['dry-run']),
60
69
  skipDep: Boolean(flags['skip-dep']),
70
+ skipMain: Boolean(flags['skip-main']),
71
+ yes: Boolean(flags.yes),
72
+ mainPath: typeof flags.main === 'string' ? flags.main : undefined,
61
73
  });
62
74
  return;
63
75
  }
76
+ if (command === 'test') {
77
+ const argv = rest[0] === '--' ? rest.slice(1) : rest;
78
+ (0, test_1.runDaxtaTest)({ argv });
79
+ return;
80
+ }
64
81
  if (command === 'build') {
65
82
  (0, build_spec_1.buildDaxtaSpec)({ requireHits: true });
66
83
  return;
67
84
  }
68
85
  if (command === 'serve') {
69
86
  const port = flags.port ? Number(flags.port) : undefined;
70
- (0, serve_1.startDaxtaDocsServer)({ port });
87
+ (0, serve_1.serveDocs)({ port });
71
88
  return;
72
89
  }
73
90
  if (command === 'fields') {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Run the app (or any command) with `@t0.labs/daxta/register` preloaded —
3
+ * Nest `/docs` mounts without editing start scripts.
4
+ *
5
+ * daxta start → pm run start:dev (or start)
6
+ * daxta start -- start:prod
7
+ * daxta start -- nest start
8
+ * daxta start -- node dist/main.js
9
+ */
10
+ export declare function runDaxtaStart(options?: {
11
+ cwd?: string;
12
+ argv?: string[];
13
+ }): void;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.runDaxtaStart = runDaxtaStart;
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ const child_process_1 = require("child_process");
40
+ function readPkg(cwd) {
41
+ return JSON.parse((0, fs_1.readFileSync)(path.join(cwd, 'package.json'), 'utf8'));
42
+ }
43
+ function detectPackageManager(cwd, pkg) {
44
+ if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
45
+ return 'pnpm';
46
+ if ((0, fs_1.existsSync)(path.join(cwd, 'yarn.lock')))
47
+ return 'yarn';
48
+ return 'npm';
49
+ }
50
+ function withRequire(env, moduleId) {
51
+ const flag = `--require ${moduleId}`;
52
+ const current = env.NODE_OPTIONS ?? '';
53
+ if (current.includes(moduleId))
54
+ return { ...env };
55
+ return {
56
+ ...env,
57
+ NODE_OPTIONS: current ? `${current} ${flag}`.trim() : flag,
58
+ };
59
+ }
60
+ /**
61
+ * Run the app (or any command) with `@t0.labs/daxta/register` preloaded —
62
+ * Nest `/docs` mounts without editing start scripts.
63
+ *
64
+ * daxta start → pm run start:dev (or start)
65
+ * daxta start -- start:prod
66
+ * daxta start -- nest start
67
+ * daxta start -- node dist/main.js
68
+ */
69
+ function runDaxtaStart(options = {}) {
70
+ const cwd = options.cwd ?? process.cwd();
71
+ const argv = options.argv ?? [];
72
+ const pkg = readPkg(cwd);
73
+ const pm = detectPackageManager(cwd, pkg);
74
+ const env = withRequire(process.env, '@t0.labs/daxta/register');
75
+ let command;
76
+ let args;
77
+ if (argv.length === 0) {
78
+ const script = pkg.scripts?.['start:dev'] ? 'start:dev' : pkg.scripts?.start ? 'start' : null;
79
+ if (!script)
80
+ throw new Error('No start:dev/start script in package.json; pass a command: daxta start -- <cmd>');
81
+ command = pm;
82
+ args = pm === 'npm' ? ['run', script] : ['run', script];
83
+ }
84
+ else if (argv.length === 1 && pkg.scripts?.[argv[0]]) {
85
+ command = pm;
86
+ args = pm === 'npm' ? ['run', argv[0]] : ['run', argv[0]];
87
+ }
88
+ else {
89
+ command = argv[0];
90
+ args = argv.slice(1);
91
+ }
92
+ console.log(`DAxTA start (register): ${command} ${args.join(' ')}`);
93
+ const result = (0, child_process_1.spawnSync)(command, args, {
94
+ cwd,
95
+ stdio: 'inherit',
96
+ shell: process.platform === 'win32',
97
+ env,
98
+ });
99
+ if (result.status && result.status !== 0)
100
+ process.exit(result.status);
101
+ if (result.error)
102
+ throw result.error;
103
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Run Jest with DAxTA recording injected via a temp config — no project file edits.
3
+ */
4
+ export declare function runDaxtaTest(options?: {
5
+ cwd?: string;
6
+ argv?: string[];
7
+ }): void;