Skip to content

Commit fb078f0

Browse files
committed
refactor: wip
1 parent 655c9c2 commit fb078f0

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Helper script for testing coreConfigMiddleware with tsconfig path resolution.
5+
* This script is executed in a subprocess to test the middleware in isolation.
6+
*
7+
* Usage: tsx core-config-middleware.int-helper.ts <configPath> [tsconfigPath]
8+
*
9+
* Note: Logger output is redirected to stderr to avoid interfering with JSON output on stdout.
10+
*/
11+
import { coreConfigMiddleware } from '../src/lib/implementation/core-config.middleware.js';
12+
13+
// Redirect console.log and process.stdout.write to stderr to prevent logger output
14+
// from interfering with JSON output
15+
const originalLog = console.log;
16+
const originalWrite = process.stdout.write.bind(process.stdout);
17+
18+
console.log = (...args: unknown[]) => {
19+
process.stderr.write(args.join(' ') + '\n');
20+
};
21+
22+
process.stdout.write = ((chunk: any, ...args: any[]): boolean => {
23+
return process.stderr.write(chunk, ...args);
24+
}) as typeof process.stdout.write;
25+
26+
const [configPath, tsconfigPath] = process.argv.slice(2);
27+
28+
if (!configPath) {
29+
console.error('Error: configPath is required');
30+
process.exit(1);
31+
}
32+
33+
try {
34+
const result = await coreConfigMiddleware({
35+
config: configPath,
36+
...(tsconfigPath && { tsconfig: tsconfigPath }),
37+
plugins: [],
38+
onlyPlugins: [],
39+
skipPlugins: [],
40+
});
41+
42+
// Restore original stdout.write before outputting JSON
43+
process.stdout.write = originalWrite;
44+
45+
// Use originalLog to write JSON to stdout
46+
originalLog(
47+
JSON.stringify({
48+
success: true,
49+
config: result.config,
50+
}),
51+
);
52+
process.exit(0);
53+
} catch (error) {
54+
console.error(error);
55+
process.exit(1);
56+
}

packages/cli/src/lib/implementation/core-config.middleware.int.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const runMiddlewareInCwd = async (configPath: string, tsconfigPath?: string) =>
3333
...(tsconfigPath ? [tsconfigPath] : []),
3434
],
3535
cwd: configDirPath,
36+
env: {
37+
...process.env,
38+
// Disable all logger output to avoid interfering with JSON output
39+
CP_VERBOSE: 'false',
40+
CI: 'false',
41+
},
3642
});
3743
describe('coreConfigMiddleware', () => {
3844
const CLI_DEFAULTS = {

0 commit comments

Comments
 (0)