@andrei.fyi/picocli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +357 -0
- package/dist/create-eQnnIhZu.d.cts +87 -0
- package/dist/create-eQnnIhZu.d.ts +87 -0
- package/dist/index.cjs +1175 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1166 -0
- package/dist/mcp/index.cjs +507 -0
- package/dist/mcp/index.d.cts +30 -0
- package/dist/mcp/index.d.ts +30 -0
- package/dist/mcp/index.js +502 -0
- package/dist/testing/testkit.cjs +115 -0
- package/dist/testing/testkit.d.cts +23 -0
- package/dist/testing/testkit.d.ts +23 -0
- package/dist/testing/testkit.js +112 -0
- package/package.json +94 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
|
|
4
|
+
// src/testing/testkit.ts
|
|
5
|
+
var METHODS = ["log", "info", "debug", "warn", "error"];
|
|
6
|
+
var consoleCaptureStorage = new AsyncLocalStorage();
|
|
7
|
+
var depth = 0;
|
|
8
|
+
var original;
|
|
9
|
+
var createConsoleRouter = (method) => (...args) => {
|
|
10
|
+
const capture = consoleCaptureStorage.getStore();
|
|
11
|
+
const handler = capture?.[method];
|
|
12
|
+
if (handler) handler(args);
|
|
13
|
+
else original?.[method](...args);
|
|
14
|
+
};
|
|
15
|
+
var installConsoleCapture = () => {
|
|
16
|
+
if (depth++ > 0) return;
|
|
17
|
+
original = Object.fromEntries(METHODS.map((method) => [method, console[method].bind(console)]));
|
|
18
|
+
for (const method of METHODS) {
|
|
19
|
+
console[method] = createConsoleRouter(method);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var uninstallConsoleCapture = () => {
|
|
23
|
+
depth--;
|
|
24
|
+
if (depth > 0 || !original) return;
|
|
25
|
+
for (const method of METHODS) console[method] = original[method];
|
|
26
|
+
original = void 0;
|
|
27
|
+
};
|
|
28
|
+
var withConsoleCapture = async (capture, runCaptured) => {
|
|
29
|
+
installConsoleCapture();
|
|
30
|
+
try {
|
|
31
|
+
return await consoleCaptureStorage.run(capture, runCaptured);
|
|
32
|
+
} finally {
|
|
33
|
+
uninstallConsoleCapture();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
Object.fromEntries(
|
|
37
|
+
METHODS.map((method) => [method, () => {
|
|
38
|
+
}])
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// src/testing/testkit.ts
|
|
42
|
+
var formatConsoleArgs = (args) => `${format(...args)}
|
|
43
|
+
`;
|
|
44
|
+
var createConsoleCapture = (output) => ({
|
|
45
|
+
log: (args) => void output.stdout.push(formatConsoleArgs(args)),
|
|
46
|
+
info: (args) => void output.stdout.push(formatConsoleArgs(args)),
|
|
47
|
+
debug: (args) => void output.stdout.push(formatConsoleArgs(args)),
|
|
48
|
+
error: (args) => void output.stderr.push(formatConsoleArgs(args)),
|
|
49
|
+
warn: (args) => void output.stderr.push(formatConsoleArgs(args))
|
|
50
|
+
});
|
|
51
|
+
var parseJsonResult = (stdout) => {
|
|
52
|
+
try {
|
|
53
|
+
const json = JSON.parse(stdout);
|
|
54
|
+
return { stdout: `${JSON.stringify(json)}
|
|
55
|
+
`, json, hasJson: true };
|
|
56
|
+
} catch {
|
|
57
|
+
return { stdout, json: void 0, hasJson: false };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var runCliWithOutputFormat = async (app, argv, opts, outputFormat) => {
|
|
61
|
+
const output = {
|
|
62
|
+
stdout: [],
|
|
63
|
+
stderr: [],
|
|
64
|
+
exitCode: 0,
|
|
65
|
+
wroteFrameworkStdout: false
|
|
66
|
+
};
|
|
67
|
+
const stdin = opts.stdin;
|
|
68
|
+
const readStdin = stdin === void 0 ? void 0 : async () => stdin;
|
|
69
|
+
await withConsoleCapture(createConsoleCapture(output), async () => {
|
|
70
|
+
await app.serve(argv, {
|
|
71
|
+
stdout: (s) => {
|
|
72
|
+
output.wroteFrameworkStdout = true;
|
|
73
|
+
output.stdout.push(s);
|
|
74
|
+
},
|
|
75
|
+
stderr: (s) => {
|
|
76
|
+
output.stderr.push(s);
|
|
77
|
+
},
|
|
78
|
+
exit: (code) => {
|
|
79
|
+
output.exitCode = code;
|
|
80
|
+
},
|
|
81
|
+
env: opts.env ?? {},
|
|
82
|
+
isTTY: opts.isTTY ?? false,
|
|
83
|
+
stdin: readStdin,
|
|
84
|
+
format: outputFormat
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const stdout = output.stdout.join("");
|
|
88
|
+
const stderr = output.stderr.join("");
|
|
89
|
+
if (outputFormat !== "json" && !output.wroteFrameworkStdout) {
|
|
90
|
+
return { stdout, stderr, exitCode: output.exitCode, json: void 0, hasJson: false };
|
|
91
|
+
}
|
|
92
|
+
const parsed = parseJsonResult(stdout);
|
|
93
|
+
return {
|
|
94
|
+
stdout: parsed.stdout,
|
|
95
|
+
stderr,
|
|
96
|
+
exitCode: output.exitCode,
|
|
97
|
+
json: parsed.json,
|
|
98
|
+
hasJson: parsed.hasJson
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
var runCli = async (app, argv, opts = {}) => {
|
|
102
|
+
const { hasJson: _, ...result } = await runCliWithOutputFormat(app, argv, opts, void 0);
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
var runJson = async (app, argv, opts = {}) => {
|
|
106
|
+
const result = await runCliWithOutputFormat(app, argv, opts, "json");
|
|
107
|
+
if (!result.hasJson) throw new Error("runJson expected JSON output");
|
|
108
|
+
const { hasJson: _, ...publicResult } = result;
|
|
109
|
+
return publicResult;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export { runCli, runJson };
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andrei.fyi/picocli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tiny CLI framework for Node and Bun.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22",
|
|
19
|
+
"bun": ">=1.1.0"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"default": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./mcp": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/mcp/index.d.ts",
|
|
35
|
+
"default": "./dist/mcp/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/mcp/index.d.cts",
|
|
39
|
+
"default": "./dist/mcp/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./testing": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/testing/testkit.d.ts",
|
|
45
|
+
"default": "./dist/testing/testkit.js"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/testing/testkit.d.cts",
|
|
49
|
+
"default": "./dist/testing/testkit.cjs"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
54
|
+
"typesVersions": {
|
|
55
|
+
"*": {
|
|
56
|
+
"mcp": [
|
|
57
|
+
"./dist/mcp/index.d.cts"
|
|
58
|
+
],
|
|
59
|
+
"testing": [
|
|
60
|
+
"./dist/testing/testkit.d.cts"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"test": "bun test",
|
|
66
|
+
"typecheck": "tsc --noEmit",
|
|
67
|
+
"build": "tsup",
|
|
68
|
+
"examples:typecheck": "tsc --noEmit --module Preserve --moduleResolution bundler --target ESNext --lib ESNext --types node,bun --strict --skipLibCheck examples/**/*.ts",
|
|
69
|
+
"examples:check": "bun run scripts/check-examples.mjs",
|
|
70
|
+
"smoke:node": "node ./scripts/smoke-dist.mjs",
|
|
71
|
+
"smoke:bun": "bun run ./scripts/smoke-dist.mjs",
|
|
72
|
+
"publint": "bunx publint --level=warning",
|
|
73
|
+
"attw": "bunx -p @arethetypeswrong/cli attw --pack .",
|
|
74
|
+
"prepack": "bun run build",
|
|
75
|
+
"verify": "tsc --noEmit && bun test && tsup && node ./scripts/smoke-dist.mjs && bun run ./scripts/smoke-dist.mjs && bun run examples:typecheck && bun run examples:check && bunx publint --level=warning && bun run attw"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
79
|
+
"zod": "^4"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@modelcontextprotocol/sdk": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
88
|
+
"@types/bun": "^1.2.21",
|
|
89
|
+
"@types/node": "^24.5.2",
|
|
90
|
+
"tsup": "^8.5.0",
|
|
91
|
+
"typescript": "^5.9.2",
|
|
92
|
+
"zod": "^4.3.6"
|
|
93
|
+
}
|
|
94
|
+
}
|