@t0.labs/daxta 0.3.0 → 0.3.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.
package/README.md CHANGED
@@ -34,16 +34,18 @@ DAXTA_DOCS=false # disable (must be set explicitly)
34
34
  ## Runtime CLI
35
35
 
36
36
  ```bash
37
- daxta test # run project tests → build → serve docs
38
- daxta test --no-serve # build only, don't open server
37
+ daxta test # run tests → build (docs on app /docs)
38
+ daxta test --serve # also open standalone viewer
39
39
  daxta test --script test:integration
40
- daxta serve
40
+ daxta serve # standalone only
41
41
  daxta build
42
42
  daxta fields
43
43
  daxta call
44
44
  ```
45
45
 
46
- `daxta test` uses `testScript` from `daxta.config.ts` (set during install). It injects recording into Jest, builds OpenAPI/HTML, then serves the viewer.
46
+ `daxta test` uses your wired script (`testScript` / `testCommand` in config). Recording is injected at runtime — no extra `daxta:*` scripts.
47
+
48
+ On package upgrade, the next `daxta` command auto-migrates old config/scripts (`daxtaVersion` in `daxta.config.ts`).
47
49
 
48
50
  ## API
49
51
 
@@ -2,12 +2,13 @@ export type TestScriptChoice = {
2
2
  name: string;
3
3
  command: string;
4
4
  };
5
+ export declare function isDaxtaWrappedScript(command: string | undefined): boolean;
5
6
  /** package.json scripts that look like runnable test entrypoints */
6
7
  export declare function listTestScripts(scripts: Record<string, string> | undefined): TestScriptChoice[];
7
8
  /** Extract `--config` / `-c` path from a script command string */
8
9
  export declare function extractJestConfigFromCommand(command: string): string | null;
9
10
  /**
10
- * Ask which package.json script to use for `daxta test`.
11
+ * Ask which package.json script to wire.
11
12
  * Returns script name (e.g. test:integration) or null to skip.
12
13
  */
13
14
  export declare function resolveTestScript(options: {
@@ -17,5 +18,18 @@ export declare function resolveTestScript(options: {
17
18
  yes?: boolean;
18
19
  flag?: string;
19
20
  }): Promise<string | null>;
20
- /** Insert or update `testScript` in daxta.config.ts */
21
+ /** Persist which script is wired + the original jest command (before wrap). */
22
+ export declare function upsertTestWiringInConfig(cwd: string, wiring: {
23
+ testScript: string;
24
+ testCommand: string;
25
+ }, dryRun?: boolean): string;
26
+ /** @deprecated use upsertTestWiringInConfig */
21
27
  export declare function upsertTestScriptInConfig(cwd: string, testScript: string, dryRun?: boolean): string;
28
+ /**
29
+ * Point the user's script at `daxta test --yes` without adding new script keys.
30
+ * Returns the original command that must be stored in config as `testCommand`.
31
+ */
32
+ export declare function wrapUserTestScript(scripts: Record<string, string>, scriptName: string): {
33
+ original: string;
34
+ changed: boolean;
35
+ };
@@ -33,10 +33,13 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.isDaxtaWrappedScript = isDaxtaWrappedScript;
36
37
  exports.listTestScripts = listTestScripts;
37
38
  exports.extractJestConfigFromCommand = extractJestConfigFromCommand;
38
39
  exports.resolveTestScript = resolveTestScript;
40
+ exports.upsertTestWiringInConfig = upsertTestWiringInConfig;
39
41
  exports.upsertTestScriptInConfig = upsertTestScriptInConfig;
42
+ exports.wrapUserTestScript = wrapUserTestScript;
40
43
  const readline_1 = require("readline");
41
44
  const fs_1 = require("fs");
42
45
  const path = __importStar(require("path"));
@@ -64,12 +67,17 @@ function scoreScript(name, command) {
64
67
  score += 10;
65
68
  if (cmd.includes('jest'))
66
69
  score += 30;
70
+ if (cmd.includes('daxta test'))
71
+ score += 25; // already wired
67
72
  if (cmd.includes('integration'))
68
73
  score += 20;
69
74
  if (n.includes('unit') || n.includes('watch') || n.includes('cov'))
70
75
  score -= 50;
71
76
  return score;
72
77
  }
78
+ function isDaxtaWrappedScript(command) {
79
+ return Boolean(command && /\bdaxta\s+test\b/.test(command));
80
+ }
73
81
  /** package.json scripts that look like runnable test entrypoints */
74
82
  function listTestScripts(scripts) {
75
83
  if (!scripts)
@@ -92,7 +100,7 @@ function extractJestConfigFromCommand(command) {
92
100
  return m?.[2] ?? null;
93
101
  }
94
102
  /**
95
- * Ask which package.json script to use for `daxta test`.
103
+ * Ask which package.json script to wire.
96
104
  * Returns script name (e.g. test:integration) or null to skip.
97
105
  */
98
106
  async function resolveTestScript(options) {
@@ -112,13 +120,14 @@ async function resolveTestScript(options) {
112
120
  const def = choices[0];
113
121
  if (options.yes || !process.stdin.isTTY)
114
122
  return def.name;
115
- console.log(` ${ui_1.c.dim('test scripts')}`);
123
+ console.log(` ${ui_1.c.dim('your scripts')}`);
116
124
  choices.slice(0, 8).forEach((choice, i) => {
117
125
  const mark = i === 0 ? ui_1.c.cyan('●') : ui_1.c.dim('○');
118
126
  const label = i === 0 ? ui_1.c.bold(choice.name) : ui_1.c.dim(choice.name);
119
- console.log(` ${mark} ${label} ${ui_1.c.dim(choice.command.slice(0, 60))}`);
127
+ const cmd = isDaxtaWrappedScript(choice.command) ? '(already wired → daxta test)' : choice.command.slice(0, 56);
128
+ console.log(` ${mark} ${label} ${ui_1.c.dim(cmd)}`);
120
129
  });
121
- const answer = await prompt(` ${ui_1.c.yellow('?')} Use ${ui_1.c.cyan(def.name)} for ${ui_1.c.bold('daxta test')}?\n` +
130
+ const answer = await prompt(` ${ui_1.c.yellow('?')} Wire ${ui_1.c.cyan(def.name)} with DAxTA recording?\n` +
122
131
  ` ${ui_1.c.dim('Y')} yes · ${ui_1.c.dim('n')} skip · or type another script name\n ${ui_1.c.cyan('›')} `);
123
132
  if (!answer || /^y(es)?$/i.test(answer))
124
133
  return def.name;
@@ -126,25 +135,50 @@ async function resolveTestScript(options) {
126
135
  return null;
127
136
  return answer;
128
137
  }
129
- /** Insert or update `testScript` in daxta.config.ts */
130
- function upsertTestScriptInConfig(cwd, testScript, dryRun = false) {
138
+ function upsertConfigFields(cwd, fields, dryRun = false) {
131
139
  const configPath = path.join(cwd, 'daxta.config.ts');
132
- if (!(0, fs_1.existsSync)(configPath)) {
140
+ if (!(0, fs_1.existsSync)(configPath))
133
141
  return 'no daxta.config.ts to update';
134
- }
135
142
  let text = (0, fs_1.readFileSync)(configPath, 'utf8');
136
- if (/testScript\s*:/.test(text)) {
137
- const next = text.replace(/testScript\s*:\s*['`][^'"`]*['`]/, `testScript: '${testScript}'`);
138
- if (next === text)
139
- return `testScript already '${testScript}'`;
140
- if (!dryRun)
141
- (0, fs_1.writeFileSync)(configPath, next);
142
- return `updated testScript → '${testScript}'`;
143
+ const notes = [];
144
+ for (const [key, value] of Object.entries(fields)) {
145
+ const literal = JSON.stringify(value);
146
+ const re = new RegExp(`${key}\\s*:\\s*['\`][^'\`"]*['\`]|${key}\\s*:\\s*"[^"]*"`);
147
+ if (re.test(text)) {
148
+ text = text.replace(re, `${key}: ${literal}`);
149
+ notes.push(`updated ${key}`);
150
+ }
151
+ else {
152
+ const next = text.replace(/defineConfig\(\s*\{/, `defineConfig({\n ${key}: ${literal},`);
153
+ if (next === text)
154
+ throw new Error(`Could not insert ${key} into daxta.config.ts`);
155
+ text = next;
156
+ notes.push(`set ${key}`);
157
+ }
143
158
  }
144
- const next = text.replace(/defineConfig\(\s*\{/, `defineConfig({\n testScript: '${testScript}',`);
145
- if (next === text)
146
- throw new Error('Could not insert testScript into daxta.config.ts');
147
159
  if (!dryRun)
148
- (0, fs_1.writeFileSync)(configPath, next);
149
- return `set testScript: '${testScript}'`;
160
+ (0, fs_1.writeFileSync)(configPath, text);
161
+ return notes.join(', ');
162
+ }
163
+ /** Persist which script is wired + the original jest command (before wrap). */
164
+ function upsertTestWiringInConfig(cwd, wiring, dryRun = false) {
165
+ return upsertConfigFields(cwd, wiring, dryRun);
166
+ }
167
+ /** @deprecated use upsertTestWiringInConfig */
168
+ function upsertTestScriptInConfig(cwd, testScript, dryRun = false) {
169
+ return upsertConfigFields(cwd, { testScript }, dryRun);
170
+ }
171
+ /**
172
+ * Point the user's script at `daxta test --yes` without adding new script keys.
173
+ * Returns the original command that must be stored in config as `testCommand`.
174
+ */
175
+ function wrapUserTestScript(scripts, scriptName) {
176
+ const current = scripts[scriptName];
177
+ if (!current)
178
+ throw new Error(`Script not found: ${scriptName}`);
179
+ if (isDaxtaWrappedScript(current)) {
180
+ return { original: current, changed: false };
181
+ }
182
+ scripts[scriptName] = 'daxta test --yes';
183
+ return { original: current, changed: true };
150
184
  }
@@ -68,27 +68,16 @@ function isDaxtaListed(pkg) {
68
68
  function isDaxtaInstalled(cwd) {
69
69
  return (0, fs_1.existsSync)(path.join(cwd, 'node_modules', '@t0.labs', 'daxta', 'package.json'));
70
70
  }
71
- function ensureScripts(pkg) {
72
- const scripts = (pkg.scripts ??= {});
73
- const wanted = {
74
- 'daxta:test': 'daxta test',
75
- 'daxta:build': 'daxta build',
76
- 'daxta:serve': 'daxta serve',
77
- 'daxta:fields': 'daxta fields',
78
- 'daxta:call': 'daxta call',
79
- };
80
- const changed = [];
81
- for (const [key, value] of Object.entries(wanted)) {
82
- if (scripts[key] !== value) {
83
- scripts[key] = value;
84
- changed.push(key);
85
- }
86
- }
87
- if (scripts['daxta:start']) {
88
- delete scripts['daxta:start'];
89
- changed.push('removed daxta:start');
71
+ function removeDaxtaAliasScripts(pkg) {
72
+ const scripts = pkg.scripts ?? {};
73
+ const removed = [];
74
+ for (const key of Object.keys(scripts)) {
75
+ if (!key.startsWith('daxta:'))
76
+ continue;
77
+ delete scripts[key];
78
+ removed.push(key);
90
79
  }
91
- return changed;
80
+ return removed;
92
81
  }
93
82
  function stripRegisterNodeOptions(pkg) {
94
83
  const scripts = pkg.scripts ?? {};
@@ -199,19 +188,19 @@ async function installDaxta(options = {}) {
199
188
  const { created, rel } = writeConfig(cwd, dryRun);
200
189
  return created ? `created ${rel}` : `exists · ${rel}`;
201
190
  }, { paceMs });
202
- await (0, ui_1.step)('Patch package.json scripts', () => {
191
+ await (0, ui_1.step)('Clean package.json scripts', () => {
203
192
  const stripped = stripRegisterNodeOptions(pkg);
204
- const scriptChanges = ensureScripts(pkg);
193
+ const removed = removeDaxtaAliasScripts(pkg);
205
194
  if (!dryRun)
206
195
  writeJson(pkgPath, pkg);
207
196
  const details = [];
208
197
  if (stripped.length)
209
198
  details.push(`removed NODE_OPTIONS register: ${stripped.join(', ')}`);
210
- if (scriptChanges.length)
211
- details.push(`+ ${scriptChanges.join(', ')}`);
199
+ if (removed.length)
200
+ details.push(`removed aliases: ${removed.join(', ')}`);
212
201
  if (!details.length)
213
- return 'unchanged';
214
- return { summary: `${details.length} change(s)`, details };
202
+ return 'no daxta:* aliases';
203
+ return { summary: `${details.length} cleanup(s)`, details };
215
204
  }, { paceMs });
216
205
  await (0, ui_1.step)('Prepare output dir', () => {
217
206
  if (!dryRun)
@@ -250,24 +239,44 @@ async function installDaxta(options = {}) {
250
239
  }
251
240
  }
252
241
  console.log('');
253
- console.log(` ${ui_1.c.yellow(ui_1.c.bold('?'))} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— used by daxta test')}`);
242
+ console.log(` ${ui_1.c.yellow(ui_1.c.bold('?'))} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— wire your existing script')}`);
254
243
  const testScript = await (0, discover_test_1.resolveTestScript)({
255
244
  cwd,
256
245
  scripts: pkg.scripts,
257
246
  yes: options.yes,
258
247
  });
259
- if (testScript) {
260
- await (0, ui_1.step)('Save test script', () => (0, discover_test_1.upsertTestScriptInConfig)(cwd, testScript, dryRun), { paceMs });
248
+ if (testScript && pkg.scripts?.[testScript]) {
249
+ await (0, ui_1.step)(`Wire ${testScript}`, () => {
250
+ const current = pkg.scripts[testScript];
251
+ if ((0, discover_test_1.isDaxtaWrappedScript)(current)) {
252
+ return {
253
+ summary: 'already wired',
254
+ details: [`${testScript} → daxta test --yes`],
255
+ };
256
+ }
257
+ const { original } = (0, discover_test_1.wrapUserTestScript)(pkg.scripts, testScript);
258
+ if (!dryRun)
259
+ writeJson(pkgPath, pkg);
260
+ const note = (0, discover_test_1.upsertTestWiringInConfig)(cwd, { testScript, testCommand: original }, dryRun);
261
+ return {
262
+ summary: `${testScript} → daxta test --yes`,
263
+ details: [`kept original as testCommand`, note],
264
+ };
265
+ }, { paceMs });
261
266
  }
262
267
  else {
263
- await (0, ui_1.step)('Save test script', () => 'skipped — daxta test will ask later', { paceMs });
268
+ await (0, ui_1.step)('Wire test script', () => 'skipped — run daxta test later to choose', { paceMs });
264
269
  }
265
270
  (0, ui_1.box)('Done', [
266
271
  `${ui_1.c.green('✔')} DAxTA wired for ${ui_1.c.bold(project)}`,
267
272
  `${ui_1.c.dim('env')} ${ui_1.c.cyan('DAXTA_DOCS=true')} or ${ui_1.c.cyan('false')} ${ui_1.c.dim('(required — app throws if missing)')}`,
268
273
  ]);
274
+ const wired = testScript && pkg.scripts?.[testScript] ? testScript : null;
269
275
  (0, ui_1.nextSteps)([
270
276
  { cmd: 'echo "DAXTA_DOCS=true" >> .env', why: 'enable /docs on the app port' },
271
- { cmd: 'daxta test', why: 'run tests → build OpenAPI → serve docs' },
277
+ {
278
+ cmd: wired ? `${pm} run ${wired}` : 'daxta test',
279
+ why: wired ? 'your script → record hits → build docs' : 'pick a test script and run',
280
+ },
272
281
  ]);
273
282
  }
package/dist/cli/main.js CHANGED
@@ -6,6 +6,7 @@ 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 migrate_1 = require("./migrate");
9
10
  const test_1 = require("./test");
10
11
  function usage() {
11
12
  console.log(`DAxTA CLI (@t0.labs/daxta)
@@ -13,7 +14,7 @@ function usage() {
13
14
  Usage:
14
15
  daxta install [--dry-run] [--skip-dep] [--skip-main] [--yes] [--main <path>] [--fast]
15
16
  daxta init (alias of install)
16
- daxta test [--script <name>] [--config <jest.json>] [--port <n>] [--no-serve] [--yes]
17
+ daxta test [--script <name>] [--config <jest.json>] [--serve] [--port <n>] [--yes]
17
18
  daxta build
18
19
  daxta serve [--port <n>]
19
20
  daxta fields [METHOD] [PATH] [--out <file>]
@@ -24,7 +25,10 @@ One-shot setup:
24
25
  pnpm dlx @t0.labs/daxta install
25
26
  npx @t0.labs/daxta install
26
27
 
27
- daxta test = learn/run project tests → build → serve docs
28
+ daxta test = run tests → build docs (served on app via apiDocs(app) /docs)
29
+ --serve = optional standalone viewer (no app)
30
+
31
+ On upgrade, CLI auto-migrates old daxta.config / scripts / apiDocs wiring.
28
32
  `);
29
33
  }
30
34
  function parseArgs(argv) {
@@ -58,14 +62,19 @@ function parseArgs(argv) {
58
62
  return { command, rest, positional, flags, headers };
59
63
  }
60
64
  async function main() {
61
- (0, config_1.resetConfig)();
62
- (0, config_1.getConfig)(true);
63
65
  const { command, rest, positional, flags, headers } = parseArgs(process.argv);
64
66
  if (!command || command === 'help' || command === '--help' || command === '-h') {
65
67
  usage();
66
68
  return;
67
69
  }
70
+ // Auto-upgrade project wiring when package version changes
71
+ if (command !== 'install' && command !== 'init') {
72
+ (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)());
73
+ }
74
+ (0, config_1.resetConfig)();
75
+ (0, config_1.getConfig)(true);
68
76
  if (command === 'install' || command === 'init') {
77
+ (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)());
69
78
  await (0, install_1.installDaxta)({
70
79
  dryRun: Boolean(flags['dry-run']),
71
80
  skipDep: Boolean(flags['skip-dep']),
@@ -74,6 +83,8 @@ async function main() {
74
83
  fast: Boolean(flags.fast),
75
84
  mainPath: typeof flags.main === 'string' ? flags.main : undefined,
76
85
  });
86
+ // stamp version after install
87
+ (0, migrate_1.reportMigration)((0, migrate_1.migrateProject)());
77
88
  return;
78
89
  }
79
90
  if (command === 'test') {
@@ -0,0 +1,13 @@
1
+ export declare function packageVersion(): string;
2
+ export type MigrateResult = {
3
+ changed: boolean;
4
+ fromVersion: string | null;
5
+ toVersion: string;
6
+ notes: string[];
7
+ };
8
+ /**
9
+ * Idempotent project migration when `@t0.labs/daxta` is upgraded.
10
+ * Safe to run on every CLI invocation.
11
+ */
12
+ export declare function migrateProject(cwd?: string): MigrateResult;
13
+ export declare function reportMigration(result: MigrateResult): void;
@@ -0,0 +1,242 @@
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.packageVersion = packageVersion;
37
+ exports.migrateProject = migrateProject;
38
+ exports.reportMigration = reportMigration;
39
+ const fs_1 = require("fs");
40
+ const path = __importStar(require("path"));
41
+ const inject_main_1 = require("./inject-main");
42
+ const discover_test_1 = require("./discover-test");
43
+ const ui_1 = require("./ui");
44
+ const CONFIG_NAMES = ['daxta.config.ts', 'daxta.config.js', 'daxta.config.mjs', 'daxta.config.cjs'];
45
+ function readJson(filePath) {
46
+ return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
47
+ }
48
+ function writeJson(filePath, value) {
49
+ (0, fs_1.writeFileSync)(filePath, `${JSON.stringify(value, null, 2)}\n`);
50
+ }
51
+ function packageVersion() {
52
+ try {
53
+ return readJson(path.join(__dirname, '..', '..', 'package.json')).version || '0.0.0';
54
+ }
55
+ catch {
56
+ return '0.0.0';
57
+ }
58
+ }
59
+ function findConfigPath(cwd) {
60
+ for (const name of CONFIG_NAMES) {
61
+ const full = path.join(cwd, name);
62
+ if ((0, fs_1.existsSync)(full))
63
+ return full;
64
+ }
65
+ return null;
66
+ }
67
+ function readConfigVersion(configText) {
68
+ const m = configText.match(/daxtaVersion\s*:\s*['"`]([^'"`]+)['"`]/);
69
+ return m?.[1] ?? null;
70
+ }
71
+ function upsertConfigField(configPath, key, value) {
72
+ let text = (0, fs_1.readFileSync)(configPath, 'utf8');
73
+ const literal = JSON.stringify(value);
74
+ const re = new RegExp(`${key}\\s*:\\s*['\`][^'\`"]*['\`]|${key}\\s*:\\s*"[^"]*"`);
75
+ if (re.test(text)) {
76
+ const next = text.replace(re, `${key}: ${literal}`);
77
+ if (next === text)
78
+ return false;
79
+ (0, fs_1.writeFileSync)(configPath, next);
80
+ return true;
81
+ }
82
+ const next = text.replace(/defineConfig\(\s*\{/, `defineConfig({\n ${key}: ${literal},`);
83
+ if (next === text)
84
+ return false;
85
+ (0, fs_1.writeFileSync)(configPath, next);
86
+ return true;
87
+ }
88
+ function readStringField(configText, key) {
89
+ const m = configText.match(new RegExp(`${key}\\s*:\\s*['\`"]([^'\`"]+)['\`"]`));
90
+ return m?.[1] ?? null;
91
+ }
92
+ function stripRegisterNodeOptions(scripts) {
93
+ const changed = [];
94
+ const re = /^NODE_OPTIONS=(['"])?(?:[^'"]*\s)?--require\s+@t0\.labs\/daxta\/register\s*([^'"]*)\1\s+/i;
95
+ for (const [key, value] of Object.entries(scripts)) {
96
+ if (!value.includes('@t0.labs/daxta/register'))
97
+ continue;
98
+ let next = value
99
+ .replace(re, '')
100
+ .replace(/\s*--require\s+@t0\.labs\/daxta\/register\b/g, '')
101
+ .replace(/NODE_OPTIONS=(['"])\s*\1\s*/g, '')
102
+ .replace(/NODE_OPTIONS=\s+/g, '')
103
+ .trim();
104
+ if (next !== value) {
105
+ scripts[key] = next;
106
+ changed.push(key);
107
+ }
108
+ }
109
+ return changed;
110
+ }
111
+ function removeDaxtaAliases(scripts) {
112
+ const removed = [];
113
+ for (const key of Object.keys(scripts)) {
114
+ if (!key.startsWith('daxta:'))
115
+ continue;
116
+ delete scripts[key];
117
+ removed.push(key);
118
+ }
119
+ return removed;
120
+ }
121
+ function migrateTestWiring(cwd, configPath, configText, pkg) {
122
+ const notes = [];
123
+ const scripts = pkg.scripts ?? {};
124
+ const testScript = readStringField(configText, 'testScript');
125
+ const testCommand = readStringField(configText, 'testCommand');
126
+ if (!testScript || !scripts[testScript])
127
+ return notes;
128
+ const current = scripts[testScript];
129
+ if (!(0, discover_test_1.isDaxtaWrappedScript)(current)) {
130
+ const { original } = (0, discover_test_1.wrapUserTestScript)(scripts, testScript);
131
+ upsertConfigField(configPath, 'testScript', testScript);
132
+ upsertConfigField(configPath, 'testCommand', original);
133
+ notes.push(`${testScript} → daxta test --yes`);
134
+ notes.push(`testCommand ← ${original}`);
135
+ return notes;
136
+ }
137
+ if (!testCommand) {
138
+ notes.push(`missing testCommand for ${testScript} — re-run daxta install to capture original jest cmd`);
139
+ }
140
+ return notes;
141
+ }
142
+ function migrateMainApiDocs(cwd) {
143
+ const notes = [];
144
+ for (const file of (0, inject_main_1.findMainCandidates)(cwd).slice(0, 5)) {
145
+ let before;
146
+ try {
147
+ before = (0, fs_1.readFileSync)(file, 'utf8');
148
+ }
149
+ catch {
150
+ continue;
151
+ }
152
+ if (!before.includes('mountDaxtaDocs') && !(/(?<![\w.])docs\s*\(/.test(before) && before.includes('@t0.labs/daxta'))) {
153
+ continue;
154
+ }
155
+ if (before.includes('apiDocs(') && /import\s*\{[^}]*\bapiDocs\b/.test(before) && !before.includes('mountDaxtaDocs')) {
156
+ continue;
157
+ }
158
+ try {
159
+ const note = (0, inject_main_1.injectApiDocs)(file, false);
160
+ if (!note.startsWith('already'))
161
+ notes.push(note);
162
+ }
163
+ catch {
164
+ // ignore
165
+ }
166
+ }
167
+ return notes;
168
+ }
169
+ function migrateConfigDefaults(configPath, configText) {
170
+ const notes = [];
171
+ const fields = readStringField(configText, 'fieldsFile');
172
+ const outDir = readStringField(configText, 'outDir') || 'daxta/out';
173
+ if (fields === 'daxta.fields.json' || fields === './daxta.fields.json') {
174
+ const next = `${outDir.replace(/\\/g, '/').replace(/\/$/, '')}/daxta.fields.json`;
175
+ if (upsertConfigField(configPath, 'fieldsFile', next)) {
176
+ notes.push(`fieldsFile → ${next}`);
177
+ }
178
+ }
179
+ return notes;
180
+ }
181
+ /**
182
+ * Idempotent project migration when `@t0.labs/daxta` is upgraded.
183
+ * Safe to run on every CLI invocation.
184
+ */
185
+ function migrateProject(cwd = process.cwd()) {
186
+ const toVersion = packageVersion();
187
+ const notes = [];
188
+ const configPath = findConfigPath(cwd);
189
+ if (!configPath) {
190
+ return { changed: false, fromVersion: null, toVersion, notes: [] };
191
+ }
192
+ let configText = (0, fs_1.readFileSync)(configPath, 'utf8');
193
+ const fromVersion = readConfigVersion(configText);
194
+ const versionBump = fromVersion !== toVersion;
195
+ const pkgPath = path.join(cwd, 'package.json');
196
+ let pkgDirty = false;
197
+ if ((0, fs_1.existsSync)(pkgPath)) {
198
+ const pkg = readJson(pkgPath);
199
+ pkg.scripts ??= {};
200
+ const stripped = stripRegisterNodeOptions(pkg.scripts);
201
+ const removed = removeDaxtaAliases(pkg.scripts);
202
+ if (stripped.length) {
203
+ notes.push(`stripped register from: ${stripped.join(', ')}`);
204
+ pkgDirty = true;
205
+ }
206
+ if (removed.length) {
207
+ notes.push(`removed aliases: ${removed.join(', ')}`);
208
+ pkgDirty = true;
209
+ }
210
+ if (versionBump) {
211
+ const beforeScripts = JSON.stringify(pkg.scripts);
212
+ const wiringNotes = migrateTestWiring(cwd, configPath, configText, pkg);
213
+ notes.push(...wiringNotes);
214
+ if (JSON.stringify(pkg.scripts) !== beforeScripts)
215
+ pkgDirty = true;
216
+ }
217
+ if (pkgDirty)
218
+ writeJson(pkgPath, pkg);
219
+ }
220
+ if (versionBump) {
221
+ configText = (0, fs_1.readFileSync)(configPath, 'utf8');
222
+ notes.push(...migrateConfigDefaults(configPath, configText));
223
+ notes.push(...migrateMainApiDocs(cwd));
224
+ }
225
+ if (upsertConfigField(configPath, 'daxtaVersion', toVersion)) {
226
+ if (fromVersion && fromVersion !== toVersion)
227
+ notes.push(`daxtaVersion ${fromVersion} → ${toVersion}`);
228
+ else if (!fromVersion)
229
+ notes.push(`daxtaVersion set to ${toVersion}`);
230
+ }
231
+ return { changed: notes.length > 0, fromVersion, toVersion, notes };
232
+ }
233
+ function reportMigration(result) {
234
+ if (!result.changed)
235
+ return;
236
+ console.log('');
237
+ console.log(` ${ui_1.c.magenta('↻')} ${ui_1.c.bold('DAxTA migrate')} ${ui_1.c.dim(result.fromVersion ? `${result.fromVersion} → ${result.toVersion}` : `→ ${result.toVersion}`)}`);
238
+ for (const note of result.notes) {
239
+ console.log(` ${ui_1.c.dim('→')} ${note}`);
240
+ }
241
+ console.log('');
242
+ }
package/dist/cli/test.js CHANGED
@@ -85,7 +85,7 @@ function parseTestArgs(argv) {
85
85
  let configFromFlag;
86
86
  let scriptFromFlag;
87
87
  let port;
88
- let noServe = false;
88
+ let standaloneServe = false;
89
89
  let yes = false;
90
90
  for (let i = 0; i < argv.length; i += 1) {
91
91
  const token = argv[i];
@@ -113,8 +113,13 @@ function parseTestArgs(argv) {
113
113
  port = Number(argv[++i]);
114
114
  continue;
115
115
  }
116
+ if (token === '--serve') {
117
+ standaloneServe = true;
118
+ continue;
119
+ }
116
120
  if (token === '--no-serve') {
117
- noServe = true;
121
+ // legacy alias — default is already no standalone serve
122
+ standaloneServe = false;
118
123
  continue;
119
124
  }
120
125
  if (token === '--yes' || token === '-y') {
@@ -123,7 +128,7 @@ function parseTestArgs(argv) {
123
128
  }
124
129
  passthrough.push(token);
125
130
  }
126
- return { configFromFlag, scriptFromFlag, passthrough, port, noServe, yes };
131
+ return { configFromFlag, scriptFromFlag, passthrough, port, standaloneServe, yes };
127
132
  }
128
133
  function loadJestJson(filePath) {
129
134
  return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
@@ -204,19 +209,24 @@ async function runDaxtaTest(options = {}) {
204
209
  yes: parsed.yes,
205
210
  flag: parsed.scriptFromFlag,
206
211
  });
207
- if (scriptName && scriptName !== config.testScript) {
208
- await (0, ui_1.step)('Remember test script', () => (0, discover_test_1.upsertTestScriptInConfig)(cwd, scriptName), { paceMs: 800 });
212
+ // Prefer saved original command — package.json may already be wrapped as `daxta test --yes`
213
+ let scriptCommand = config.testCommand ||
214
+ (scriptName && pkg.scripts?.[scriptName] && !(0, discover_test_1.isDaxtaWrappedScript)(pkg.scripts[scriptName])
215
+ ? pkg.scripts[scriptName]
216
+ : undefined);
217
+ if (scriptName && (!config.testScript || !config.testCommand) && scriptCommand) {
218
+ await (0, ui_1.step)('Remember test wiring', () => (0, discover_test_1.upsertTestWiringInConfig)(cwd, { testScript: scriptName, testCommand: scriptCommand }), { paceMs: 600 });
209
219
  (0, config_1.resetConfig)();
210
220
  config = (0, config_1.getConfig)(true);
221
+ scriptCommand = config.testCommand || scriptCommand;
211
222
  }
212
- const scriptCommand = scriptName ? pkg.scripts?.[scriptName] : undefined;
213
223
  if (scriptName) {
214
- await (0, ui_1.step)('Test command', () => `${pm} run ${scriptName}`, { paceMs: 600 });
224
+ await (0, ui_1.step)('Test entry', () => (config.testCommand ? `${scriptName} · ${config.testCommand}` : `${pm} / ${scriptName}`), { paceMs: 600 });
215
225
  }
216
226
  const baseConfigPath = resolveBaseConfigPath(cwd, {
217
227
  configFromFlag: parsed.configFromFlag,
218
228
  jestConfig: config.jestConfig,
219
- scriptCommand,
229
+ scriptCommand: scriptCommand || config.testCommand,
220
230
  });
221
231
  await (0, ui_1.step)('Jest config', () => path.relative(cwd, baseConfigPath), { paceMs: 600 });
222
232
  let base;
@@ -241,14 +251,16 @@ async function runDaxtaTest(options = {}) {
241
251
  // Prefer running via package script env when possible, but always inject our config:
242
252
  // jest --config <merged> + any extra args from the user / script beyond config.
243
253
  const extraFromScript = [];
244
- if (scriptCommand) {
245
- // strip jest binary and --config pair from script; keep other flags
246
- const tokens = scriptCommand.split(/\s+/).filter(Boolean);
254
+ const commandForExtras = scriptCommand || config.testCommand;
255
+ if (commandForExtras) {
256
+ const tokens = commandForExtras.split(/\s+/).filter(Boolean);
247
257
  for (let i = 0; i < tokens.length; i += 1) {
248
258
  const t = tokens[i];
249
259
  if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
250
260
  continue;
251
- if (t.startsWith('NODE_OPTIONS=') || t.includes('='))
261
+ if (t === 'daxta' || t === 'test' || t === '--yes' || t === '-y')
262
+ continue;
263
+ if (t.startsWith('NODE_OPTIONS=') || (t.includes('=') && !t.startsWith('-')))
252
264
  continue;
253
265
  if (t === '--config' || t === '-c') {
254
266
  i += 1;
@@ -294,24 +306,30 @@ async function runDaxtaTest(options = {}) {
294
306
  ],
295
307
  };
296
308
  }, { paceMs: 800 });
297
- if (parsed.noServe) {
298
- (0, ui_1.box)('Done', [
299
- `${ui_1.c.green('✔')} docs built (${buildSummary})`,
300
- `${ui_1.c.dim('serve later')} ${ui_1.c.cyan('daxta serve')}`,
309
+ const docsBase = (0, paths_1.getDocsBasePath)();
310
+ const appDocsUrl = `${config.baseUrl.replace(/\/$/, '')}${docsBase}`;
311
+ // Primary path: apiDocs(app) exposes /docs on the Nest app port.
312
+ // Optional --serve spins a standalone viewer (no app required).
313
+ if (parsed.standaloneServe) {
314
+ const port = parsed.port ?? config.port;
315
+ (0, ui_1.box)('Standalone docs', [
316
+ `${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)}`,
317
+ `${ui_1.c.dim('openapi')} http://127.0.0.1:${port}${docsBase}/openapi.json`,
318
+ testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : `${ui_1.c.dim('ctrl+c')} to stop`,
301
319
  ]);
302
- if (testStatus !== 0)
303
- process.exit(testStatus);
320
+ (0, serve_1.serveApiDocs)({ port });
304
321
  return;
305
322
  }
306
- const port = parsed.port ?? config.port;
307
- const docsBase = (0, paths_1.getDocsBasePath)();
308
323
  (0, ui_1.box)('Docs ready', [
309
- `${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)}`,
310
- `${ui_1.c.dim('openapi')} http://127.0.0.1:${port}${docsBase}/openapi.json`,
311
- testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus} — docs still served` : `${ui_1.c.dim('ctrl+c')} to stop`,
312
- ]);
324
+ `${ui_1.c.green('✔')} built (${buildSummary})`,
325
+ `${ui_1.c.bold('App route')} ${ui_1.c.cyan(appDocsUrl)}`,
326
+ `${ui_1.c.dim('via')} apiDocs(app) · set ${ui_1.c.cyan('DAXTA_DOCS=true')}`,
327
+ testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : '',
328
+ ].filter(Boolean));
313
329
  (0, ui_1.nextSteps)([
314
- { cmd: `open http://127.0.0.1:${port}${docsBase}`, why: 'viewer' },
330
+ { cmd: 'DAXTA_DOCS=true pnpm start:dev', why: `open ${appDocsUrl}` },
331
+ { cmd: 'daxta test --serve', why: 'standalone viewer without starting the app' },
315
332
  ]);
316
- (0, serve_1.serveApiDocs)({ port });
333
+ if (testStatus !== 0)
334
+ process.exit(testStatus);
317
335
  }
package/dist/config.d.ts CHANGED
@@ -14,8 +14,12 @@ export type DaxtaConfig = {
14
14
  port?: number;
15
15
  fieldsFile?: string;
16
16
  docsPath?: string;
17
- /** package.json script name used by `daxta test` (e.g. test:integration) */
17
+ /** package.json script name wired to DAxTA (e.g. test:integration) */
18
18
  testScript?: string;
19
+ /** Original test command before wrap (e.g. jest --config …) */
20
+ testCommand?: string;
21
+ /** Last auto-migrated @t0.labs/daxta version */
22
+ daxtaVersion?: string;
19
23
  /** Optional explicit Jest JSON config path */
20
24
  jestConfig?: string;
21
25
  templatize?: (pathname: string, test?: string) => string | null | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",