@t0.labs/daxta 0.3.0 → 0.3.2
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 +6 -4
- package/dist/cli/discover-test.d.ts +16 -2
- package/dist/cli/discover-test.js +54 -20
- package/dist/cli/install.js +40 -31
- package/dist/cli/main.js +15 -4
- package/dist/cli/migrate.d.ts +13 -0
- package/dist/cli/migrate.js +242 -0
- package/dist/cli/test.d.ts +2 -1
- package/dist/cli/test.js +70 -93
- package/dist/config.d.ts +5 -1
- package/dist/jest/global-teardown.d.ts +1 -0
- package/dist/jest/global-teardown.js +4 -9
- package/dist/jest/reporter.js +7 -9
- package/package.json +1 -1
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
|
|
38
|
-
daxta test --
|
|
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`
|
|
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
|
|
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
|
-
/**
|
|
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
|
|
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('
|
|
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
|
-
|
|
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('?')}
|
|
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
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
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,
|
|
149
|
-
return
|
|
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
|
}
|
package/dist/cli/install.js
CHANGED
|
@@ -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
|
|
72
|
-
const scripts =
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
'daxta:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
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)('
|
|
191
|
+
await (0, ui_1.step)('Clean package.json scripts', () => {
|
|
203
192
|
const stripped = stripRegisterNodeOptions(pkg);
|
|
204
|
-
const
|
|
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 (
|
|
211
|
-
details.push(
|
|
199
|
+
if (removed.length)
|
|
200
|
+
details.push(`removed aliases: ${removed.join(', ')}`);
|
|
212
201
|
if (!details.length)
|
|
213
|
-
return '
|
|
214
|
-
return { summary: `${details.length}
|
|
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('—
|
|
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)(
|
|
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)('
|
|
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
|
-
{
|
|
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>] [--
|
|
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 =
|
|
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.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Run project tests with recording → build → print docs URL.
|
|
3
|
+
* Quiet: jest output only, then Docs ready + Next.
|
|
3
4
|
*/
|
|
4
5
|
export declare function runDaxtaTest(options?: {
|
|
5
6
|
cwd?: string;
|
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
|
|
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,12 @@ 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
|
-
|
|
121
|
+
standaloneServe = false;
|
|
118
122
|
continue;
|
|
119
123
|
}
|
|
120
124
|
if (token === '--yes' || token === '-y') {
|
|
@@ -123,7 +127,7 @@ function parseTestArgs(argv) {
|
|
|
123
127
|
}
|
|
124
128
|
passthrough.push(token);
|
|
125
129
|
}
|
|
126
|
-
return { configFromFlag, scriptFromFlag, passthrough, port,
|
|
130
|
+
return { configFromFlag, scriptFromFlag, passthrough, port, standaloneServe, yes };
|
|
127
131
|
}
|
|
128
132
|
function loadJestJson(filePath) {
|
|
129
133
|
return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
@@ -157,13 +161,6 @@ function resolveJestBin(cwd) {
|
|
|
157
161
|
function readPkg(cwd) {
|
|
158
162
|
return JSON.parse((0, fs_1.readFileSync)(path.join(cwd, 'package.json'), 'utf8'));
|
|
159
163
|
}
|
|
160
|
-
function detectPackageManager(cwd, pkg) {
|
|
161
|
-
if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
|
|
162
|
-
return 'pnpm';
|
|
163
|
-
if ((0, fs_1.existsSync)(path.join(cwd, 'yarn.lock')))
|
|
164
|
-
return 'yarn';
|
|
165
|
-
return 'npm';
|
|
166
|
-
}
|
|
167
164
|
function resolveBaseConfigPath(cwd, options) {
|
|
168
165
|
if (options.configFromFlag) {
|
|
169
166
|
return path.isAbsolute(options.configFromFlag)
|
|
@@ -186,17 +183,39 @@ function resolveBaseConfigPath(cwd, options) {
|
|
|
186
183
|
}
|
|
187
184
|
return preferred;
|
|
188
185
|
}
|
|
186
|
+
function jestExtrasFromCommand(command) {
|
|
187
|
+
if (!command)
|
|
188
|
+
return [];
|
|
189
|
+
const extra = [];
|
|
190
|
+
const tokens = command.split(/\s+/).filter(Boolean);
|
|
191
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
192
|
+
const t = tokens[i];
|
|
193
|
+
if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
|
|
194
|
+
continue;
|
|
195
|
+
if (t === 'daxta' || t === 'test' || t === '--yes' || t === '-y')
|
|
196
|
+
continue;
|
|
197
|
+
if (t.startsWith('NODE_OPTIONS=') || (t.includes('=') && !t.startsWith('-')))
|
|
198
|
+
continue;
|
|
199
|
+
if (t === '--config' || t === '-c') {
|
|
200
|
+
i += 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (t.startsWith('--config='))
|
|
204
|
+
continue;
|
|
205
|
+
extra.push(t);
|
|
206
|
+
}
|
|
207
|
+
return extra;
|
|
208
|
+
}
|
|
189
209
|
/**
|
|
190
|
-
*
|
|
210
|
+
* Run project tests with recording → build → print docs URL.
|
|
211
|
+
* Quiet: jest output only, then Docs ready + Next.
|
|
191
212
|
*/
|
|
192
213
|
async function runDaxtaTest(options = {}) {
|
|
193
214
|
const cwd = options.cwd ?? process.cwd();
|
|
194
215
|
const parsed = parseTestArgs(options.argv ?? []);
|
|
195
216
|
const pkg = readPkg(cwd);
|
|
196
|
-
const pm = detectPackageManager(cwd, pkg);
|
|
197
217
|
(0, config_1.resetConfig)();
|
|
198
218
|
let config = (0, config_1.getConfig)(true);
|
|
199
|
-
(0, ui_1.banner)('DAxTA test', pkg.name || path.basename(cwd));
|
|
200
219
|
const scriptName = await (0, discover_test_1.resolveTestScript)({
|
|
201
220
|
cwd,
|
|
202
221
|
scripts: pkg.scripts,
|
|
@@ -204,21 +223,21 @@ async function runDaxtaTest(options = {}) {
|
|
|
204
223
|
yes: parsed.yes,
|
|
205
224
|
flag: parsed.scriptFromFlag,
|
|
206
225
|
});
|
|
207
|
-
|
|
208
|
-
|
|
226
|
+
let scriptCommand = config.testCommand ||
|
|
227
|
+
(scriptName && pkg.scripts?.[scriptName] && !(0, discover_test_1.isDaxtaWrappedScript)(pkg.scripts[scriptName])
|
|
228
|
+
? pkg.scripts[scriptName]
|
|
229
|
+
: undefined);
|
|
230
|
+
if (scriptName && (!config.testScript || !config.testCommand) && scriptCommand) {
|
|
231
|
+
(0, discover_test_1.upsertTestWiringInConfig)(cwd, { testScript: scriptName, testCommand: scriptCommand });
|
|
209
232
|
(0, config_1.resetConfig)();
|
|
210
233
|
config = (0, config_1.getConfig)(true);
|
|
211
|
-
|
|
212
|
-
const scriptCommand = scriptName ? pkg.scripts?.[scriptName] : undefined;
|
|
213
|
-
if (scriptName) {
|
|
214
|
-
await (0, ui_1.step)('Test command', () => `${pm} run ${scriptName}`, { paceMs: 600 });
|
|
234
|
+
scriptCommand = config.testCommand || scriptCommand;
|
|
215
235
|
}
|
|
216
236
|
const baseConfigPath = resolveBaseConfigPath(cwd, {
|
|
217
237
|
configFromFlag: parsed.configFromFlag,
|
|
218
238
|
jestConfig: config.jestConfig,
|
|
219
|
-
scriptCommand,
|
|
239
|
+
scriptCommand: scriptCommand || config.testCommand,
|
|
220
240
|
});
|
|
221
|
-
await (0, ui_1.step)('Jest config', () => path.relative(cwd, baseConfigPath), { paceMs: 600 });
|
|
222
241
|
let base;
|
|
223
242
|
try {
|
|
224
243
|
base = loadJestJson(baseConfigPath);
|
|
@@ -230,88 +249,46 @@ async function runDaxtaTest(options = {}) {
|
|
|
230
249
|
const configDir = path.dirname(baseConfigPath);
|
|
231
250
|
const tmpDir = path.join(cwd, 'daxta', 'out');
|
|
232
251
|
(0, fs_1.mkdirSync)(tmpDir, { recursive: true });
|
|
233
|
-
|
|
252
|
+
(0, fs_1.writeFileSync)(path.join(tmpDir, 'jest.daxta.runtime.json'), `${JSON.stringify({ ...merged, _source: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
|
|
234
253
|
const siblingTmp = path.join(configDir, '.jest.daxta.runtime.json');
|
|
235
254
|
(0, fs_1.writeFileSync)(siblingTmp, `${JSON.stringify(merged, null, 2)}\n`);
|
|
236
|
-
(0, fs_1.writeFileSync)(tmpConfig, `${JSON.stringify({ ...merged, _source: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
|
|
237
255
|
(0, recorder_1.clearWorkerHits)();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const t = tokens[i];
|
|
249
|
-
if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
|
|
250
|
-
continue;
|
|
251
|
-
if (t.startsWith('NODE_OPTIONS=') || t.includes('='))
|
|
252
|
-
continue;
|
|
253
|
-
if (t === '--config' || t === '-c') {
|
|
254
|
-
i += 1;
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if (t.startsWith('--config='))
|
|
258
|
-
continue;
|
|
259
|
-
extraFromScript.push(t);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...extraFromScript, ...parsed.passthrough], {
|
|
263
|
-
cwd,
|
|
264
|
-
stdio: 'inherit',
|
|
265
|
-
shell: process.platform === 'win32',
|
|
266
|
-
env: process.env,
|
|
267
|
-
});
|
|
268
|
-
testStatus = result.status ?? 1;
|
|
269
|
-
if (result.error)
|
|
270
|
-
throw result.error;
|
|
271
|
-
return testStatus === 0 ? 'passed' : `exit ${testStatus}`;
|
|
272
|
-
}, { paceMs: 400, spinner: false });
|
|
256
|
+
const jestBin = resolveJestBin(cwd);
|
|
257
|
+
const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...jestExtrasFromCommand(scriptCommand || config.testCommand), ...parsed.passthrough], {
|
|
258
|
+
cwd,
|
|
259
|
+
stdio: 'inherit',
|
|
260
|
+
shell: process.platform === 'win32',
|
|
261
|
+
env: { ...process.env, DAXTA_QUIET: '1' },
|
|
262
|
+
});
|
|
263
|
+
const testStatus = result.status ?? 1;
|
|
264
|
+
if (result.error)
|
|
265
|
+
throw result.error;
|
|
273
266
|
try {
|
|
274
267
|
(0, fs_1.unlinkSync)(siblingTmp);
|
|
275
268
|
}
|
|
276
269
|
catch {
|
|
277
270
|
// ignore
|
|
278
271
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
`${build.hits} recorded hits`,
|
|
292
|
-
`${build.operations} operations`,
|
|
293
|
-
`out · ${path.relative(cwd, config.outDir)}`,
|
|
294
|
-
],
|
|
295
|
-
};
|
|
296
|
-
}, { 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')}`,
|
|
301
|
-
]);
|
|
302
|
-
if (testStatus !== 0)
|
|
303
|
-
process.exit(testStatus);
|
|
272
|
+
const build = (0, build_spec_1.buildDaxtaSpec)({ silent: true, html: true });
|
|
273
|
+
(0, incremental_1.clearPartialMarker)();
|
|
274
|
+
const buildSummary = build.skipped ? 'no hits yet' : `${build.hits} hits · ${build.operations} ops`;
|
|
275
|
+
const docsBase = (0, paths_1.getDocsBasePath)();
|
|
276
|
+
const appDocsUrl = `${config.baseUrl.replace(/\/$/, '')}${docsBase}`;
|
|
277
|
+
if (parsed.standaloneServe) {
|
|
278
|
+
const port = parsed.port ?? config.port;
|
|
279
|
+
(0, ui_1.box)('Docs ready', [
|
|
280
|
+
`${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)} ${ui_1.c.dim(`(${buildSummary})`)}`,
|
|
281
|
+
testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : `${ui_1.c.dim('ctrl+c')} to stop`,
|
|
282
|
+
].filter(Boolean));
|
|
283
|
+
(0, serve_1.serveApiDocs)({ port });
|
|
304
284
|
return;
|
|
305
285
|
}
|
|
306
|
-
const port = parsed.port ?? config.port;
|
|
307
|
-
const docsBase = (0, paths_1.getDocsBasePath)();
|
|
308
286
|
(0, ui_1.box)('Docs ready', [
|
|
309
|
-
`${ui_1.c.green('✔')} ${ui_1.c.
|
|
310
|
-
`${ui_1.c.dim('
|
|
311
|
-
testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}
|
|
312
|
-
]);
|
|
313
|
-
(0, ui_1.nextSteps)([
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
(0, serve_1.serveApiDocs)({ port });
|
|
287
|
+
`${ui_1.c.green('✔')} ${ui_1.c.cyan(appDocsUrl)} ${ui_1.c.dim(`(${buildSummary})`)}`,
|
|
288
|
+
`${ui_1.c.dim('DAXTA_DOCS=true')} required on app start`,
|
|
289
|
+
testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : '',
|
|
290
|
+
].filter(Boolean));
|
|
291
|
+
(0, ui_1.nextSteps)([{ cmd: 'DAXTA_DOCS=true pnpm start:dev', why: `open ${appDocsUrl}` }]);
|
|
292
|
+
if (testStatus !== 0)
|
|
293
|
+
process.exit(testStatus);
|
|
317
294
|
}
|
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
|
|
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;
|
|
@@ -3,18 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = daxtaGlobalTeardown;
|
|
4
4
|
const incremental_1 = require("../build/incremental");
|
|
5
5
|
const build_spec_1 = require("../build/build-spec");
|
|
6
|
+
/** Optional jest globalTeardown — silent; `daxta test` prints the final Docs ready. */
|
|
6
7
|
async function daxtaGlobalTeardown() {
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
-
if (result.changed) {
|
|
10
|
-
console.log(`DAxTA docs updated (${result.hits} hits, ${result.operations} operations — ${result.updated} updated, ${result.unchanged} unchanged)`);
|
|
11
|
-
}
|
|
12
|
-
else if (!result.skipped) {
|
|
13
|
-
console.log(`DAxTA docs ready (${result.hits} hits, ${result.operations} operations)`);
|
|
14
|
-
}
|
|
9
|
+
(0, build_spec_1.buildDaxtaSpec)({ silent: true });
|
|
15
10
|
(0, incremental_1.clearPartialMarker)();
|
|
16
11
|
}
|
|
17
|
-
catch
|
|
18
|
-
|
|
12
|
+
catch {
|
|
13
|
+
// never fail teardown
|
|
19
14
|
}
|
|
20
15
|
}
|
package/dist/jest/reporter.js
CHANGED
|
@@ -5,24 +5,22 @@ class DaxtaJestReporter {
|
|
|
5
5
|
}
|
|
6
6
|
onTestResult() {
|
|
7
7
|
this.suitesDone += 1;
|
|
8
|
-
this.rebuild(
|
|
8
|
+
this.rebuild({ html: this.suitesDone % 5 === 0 });
|
|
9
9
|
}
|
|
10
10
|
onRunComplete() {
|
|
11
|
-
this.rebuild(
|
|
11
|
+
this.rebuild({ html: true });
|
|
12
12
|
}
|
|
13
|
-
rebuild(
|
|
13
|
+
rebuild(options) {
|
|
14
14
|
try {
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
16
|
require('reflect-metadata');
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
18
|
const { rebuildFromDisk } = require('../build/incremental');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.log(`DAxTA ${result.changed ? 'updated' : 'checked'} after ${label}: ${result.hits} hits, ${result.operations} ops${options.html ? '' : ' (json only)'}`);
|
|
22
|
-
}
|
|
19
|
+
rebuildFromDisk({ silent: true, force: true, html: options.html });
|
|
20
|
+
// Keep jest output clean — final summary comes from `daxta test` (Docs ready).
|
|
23
21
|
}
|
|
24
|
-
catch
|
|
25
|
-
|
|
22
|
+
catch {
|
|
23
|
+
// incremental rebuild must never fail the test run
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
}
|