printable-shell-command 0.3.2 → 1.0.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.
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { ChildProcess as NodeChildProcess, SpawnOptions as NodeSpawnOptions, SpawnOptionsWithStdioTuple as NodeSpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio as NodeSpawnOptionsWithoutStdio, StdioNull as NodeStdioNull, StdioPipe as NodeStdioPipe } from "node:child_process";
|
|
2
|
+
import type { SpawnOptions as BunSpawnOptions, Subprocess as BunSubprocess } from "bun";
|
|
3
|
+
type SingleArgument = string;
|
|
4
|
+
type FlagArgumentPair = [string, string];
|
|
5
|
+
type ArgsEntry = SingleArgument | FlagArgumentPair;
|
|
6
|
+
type Args = ArgsEntry[];
|
|
7
|
+
export interface PrintOptions {
|
|
8
|
+
mainIndentation?: string;
|
|
9
|
+
argIndentation?: string;
|
|
10
|
+
quoting?: "auto" | "extra-safe";
|
|
11
|
+
argumentLineWrapping?: "by-entry" | "nested-by-entry" | "by-argument" | "inline";
|
|
12
|
+
}
|
|
13
|
+
export declare class PrintableShellCommand {
|
|
14
|
+
#private;
|
|
15
|
+
private args;
|
|
16
|
+
constructor(commandName: string, args?: Args);
|
|
17
|
+
get commandName(): string;
|
|
18
|
+
toFlatCommand(): string[];
|
|
19
|
+
forBun(): string[];
|
|
20
|
+
toCommandWithFlatArgs(): [string, string[]];
|
|
21
|
+
forNode(): [string, string[]];
|
|
22
|
+
getPrintableCommand(options?: PrintOptions): string;
|
|
23
|
+
print(options?: PrintOptions): PrintableShellCommand;
|
|
24
|
+
/**
|
|
25
|
+
* The returned child process includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313
|
|
26
|
+
*/
|
|
27
|
+
spawnNode<Stdin extends NodeStdioNull | NodeStdioPipe, Stdout extends NodeStdioNull | NodeStdioPipe, Stderr extends NodeStdioNull | NodeStdioPipe>(options?: NodeSpawnOptions | NodeSpawnOptionsWithoutStdio | NodeSpawnOptionsWithStdioTuple<Stdin, Stdout, Stderr>): // TODO: figure out how to return `ChildProcessByStdio<…>` without duplicating fragile boilerplate.
|
|
28
|
+
NodeChildProcess & {
|
|
29
|
+
success: Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
/** A wrapper for `.spawnNode(…)` that sets stdio to `"inherit"` (common for
|
|
32
|
+
* invoking commands from scripts whose output and interaction should be
|
|
33
|
+
* surfaced to the user). */
|
|
34
|
+
spawnNodeInherit(options?: Omit<NodeSpawnOptions, "stdio">): NodeChildProcess & {
|
|
35
|
+
success: Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
/** Equivalent to:
|
|
38
|
+
*
|
|
39
|
+
* ```
|
|
40
|
+
* await this.print().spawnNodeInherit().success;
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
shellOutNode(options?: Omit<NodeSpawnOptions, "stdio">): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* The returned subprocess includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313
|
|
46
|
+
*/
|
|
47
|
+
spawnBun<const In extends BunSpawnOptions.Writable = "ignore", const Out extends BunSpawnOptions.Readable = "pipe", const Err extends BunSpawnOptions.Readable = "inherit">(options?: Omit<BunSpawnOptions.OptionsObject<In, Out, Err>, "cmd">): BunSubprocess<In, Out, Err> & {
|
|
48
|
+
success: Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* A wrapper for `.spawnBunInherit(…)` that sets stdio to `"inherit"` (common
|
|
52
|
+
* for invoking commands from scripts whose output and interaction should be
|
|
53
|
+
* surfaced to the user).
|
|
54
|
+
*/
|
|
55
|
+
spawnBunInherit(options?: Omit<Omit<BunSpawnOptions.OptionsObject<"inherit", "inherit", "inherit">, "cmd">, "stdio">): BunSubprocess<"inherit", "inherit", "inherit"> & {
|
|
56
|
+
success: Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
/** Equivalent to:
|
|
59
|
+
*
|
|
60
|
+
* ```
|
|
61
|
+
* new Response(this.spawnBun(options).stdout);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
spawnBunStdout(options?: Omit<Omit<BunSpawnOptions.OptionsObject<"inherit", "inherit", "inherit">, "cmd">, "stdio">): Response;
|
|
65
|
+
/** Equivalent to:
|
|
66
|
+
*
|
|
67
|
+
* ```
|
|
68
|
+
* await this.print().spawnBunInherit().success;
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
shellOutBun(options?: Omit<Omit<BunSpawnOptions.OptionsObject<"inherit", "inherit", "inherit">, "cmd">, "stdio">): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var DEFAULT_MAIN_INDENTATION = "";
|
|
3
|
+
var DEFAULT_ARG_INDENTATION = " ";
|
|
4
|
+
var DEFAULT_ARGUMENT_LINE_WRAPPING = "by-entry";
|
|
5
|
+
var INLINE_SEPARATOR = " ";
|
|
6
|
+
var LINE_WRAP_LINE_END = " \\\n";
|
|
7
|
+
function isString(s) {
|
|
8
|
+
return typeof s === "string";
|
|
9
|
+
}
|
|
10
|
+
var SPECIAL_SHELL_CHARACTERS = /* @__PURE__ */ new Set([
|
|
11
|
+
" ",
|
|
12
|
+
'"',
|
|
13
|
+
"'",
|
|
14
|
+
"`",
|
|
15
|
+
"|",
|
|
16
|
+
"$",
|
|
17
|
+
"*",
|
|
18
|
+
"?",
|
|
19
|
+
">",
|
|
20
|
+
"<",
|
|
21
|
+
"(",
|
|
22
|
+
")",
|
|
23
|
+
"[",
|
|
24
|
+
"]",
|
|
25
|
+
"{",
|
|
26
|
+
"}",
|
|
27
|
+
"&",
|
|
28
|
+
"\\",
|
|
29
|
+
";"
|
|
30
|
+
]);
|
|
31
|
+
var SPECIAL_SHELL_CHARACTERS_FOR_MAIN_COMMAND = (
|
|
32
|
+
// biome-ignore lint/suspicious/noExplicitAny: Workaround to make this package easier to use in a project that otherwise only uses ES2022.)
|
|
33
|
+
SPECIAL_SHELL_CHARACTERS.union(/* @__PURE__ */ new Set(["="]))
|
|
34
|
+
);
|
|
35
|
+
var PrintableShellCommand = class {
|
|
36
|
+
constructor(commandName, args = []) {
|
|
37
|
+
this.args = args;
|
|
38
|
+
if (!isString(commandName)) {
|
|
39
|
+
throw new Error("Command name is not a string:", commandName);
|
|
40
|
+
}
|
|
41
|
+
this.#commandName = commandName;
|
|
42
|
+
if (typeof args === "undefined") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!Array.isArray(args)) {
|
|
46
|
+
throw new Error("Command arguments are not an array");
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < args.length; i++) {
|
|
49
|
+
const argEntry = args[i];
|
|
50
|
+
if (typeof argEntry === "string") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(argEntry) && argEntry.length === 2 && isString(argEntry[0]) && isString(argEntry[1])) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Invalid arg entry at index: ${i}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
#commandName;
|
|
60
|
+
get commandName() {
|
|
61
|
+
return this.#commandName;
|
|
62
|
+
}
|
|
63
|
+
// For use with `bun`.
|
|
64
|
+
//
|
|
65
|
+
// Usage example:
|
|
66
|
+
//
|
|
67
|
+
// import { PrintableShellCommand } from "printable-shell-command";
|
|
68
|
+
// import { spawn } from "bun";
|
|
69
|
+
//
|
|
70
|
+
// const command = new PrintableShellCommand(/* … */);
|
|
71
|
+
// await spawn(command.toFlatCommand()).exited;
|
|
72
|
+
//
|
|
73
|
+
toFlatCommand() {
|
|
74
|
+
return [this.commandName, ...this.args.flat()];
|
|
75
|
+
}
|
|
76
|
+
// Convenient alias for `toFlatCommand()`.
|
|
77
|
+
//
|
|
78
|
+
// Usage example:
|
|
79
|
+
//
|
|
80
|
+
// import { PrintableShellCommand } from "printable-shell-command";
|
|
81
|
+
// import { spawn } from "bun";
|
|
82
|
+
//
|
|
83
|
+
// const command = new PrintableShellCommand(/* … */);
|
|
84
|
+
// await spawn(command.forBun()).exited;
|
|
85
|
+
//
|
|
86
|
+
forBun() {
|
|
87
|
+
return this.toFlatCommand();
|
|
88
|
+
}
|
|
89
|
+
// For use with `node:child_process`
|
|
90
|
+
//
|
|
91
|
+
// Usage example:
|
|
92
|
+
//
|
|
93
|
+
// import { PrintableShellCommand } from "printable-shell-command";
|
|
94
|
+
// import { spawn } from "node:child_process";
|
|
95
|
+
//
|
|
96
|
+
// const command = new PrintableShellCommand(/* … */);
|
|
97
|
+
// const child_process = spawn(...command.toCommandWithFlatArgs()); // Note the `...`
|
|
98
|
+
//
|
|
99
|
+
toCommandWithFlatArgs() {
|
|
100
|
+
return [this.commandName, this.args.flat()];
|
|
101
|
+
}
|
|
102
|
+
// For use with `node:child_process`
|
|
103
|
+
//
|
|
104
|
+
// Usage example:
|
|
105
|
+
//
|
|
106
|
+
// import { PrintableShellCommand } from "printable-shell-command";
|
|
107
|
+
// import { spawn } from "node:child_process";
|
|
108
|
+
//
|
|
109
|
+
// const command = new PrintableShellCommand(/* … */);
|
|
110
|
+
// const child_process = spawn(...command.forNode()); // Note the `...`
|
|
111
|
+
//
|
|
112
|
+
// Convenient alias for `toCommandWithFlatArgs()`.
|
|
113
|
+
forNode() {
|
|
114
|
+
return this.toCommandWithFlatArgs();
|
|
115
|
+
}
|
|
116
|
+
#escapeArg(arg, isMainCommand, options) {
|
|
117
|
+
const argCharacters = new Set(arg);
|
|
118
|
+
const specialShellCharacters = isMainCommand ? SPECIAL_SHELL_CHARACTERS_FOR_MAIN_COMMAND : SPECIAL_SHELL_CHARACTERS;
|
|
119
|
+
if (options?.quoting === "extra-safe" || // biome-ignore lint/suspicious/noExplicitAny: Workaround to make this package easier to use in a project that otherwise only uses ES2022.)
|
|
120
|
+
argCharacters.intersection(specialShellCharacters).size > 0) {
|
|
121
|
+
const escaped = arg.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
122
|
+
return `'${escaped}'`;
|
|
123
|
+
}
|
|
124
|
+
return arg;
|
|
125
|
+
}
|
|
126
|
+
#mainIndentation(options) {
|
|
127
|
+
return options?.mainIndentation ?? DEFAULT_MAIN_INDENTATION;
|
|
128
|
+
}
|
|
129
|
+
#argIndentation(options) {
|
|
130
|
+
return this.#mainIndentation(options) + (options?.argIndentation ?? DEFAULT_ARG_INDENTATION);
|
|
131
|
+
}
|
|
132
|
+
#lineWrapSeparator(options) {
|
|
133
|
+
return LINE_WRAP_LINE_END + this.#argIndentation(options);
|
|
134
|
+
}
|
|
135
|
+
#argPairSeparator(options) {
|
|
136
|
+
switch (options?.argumentLineWrapping ?? DEFAULT_ARGUMENT_LINE_WRAPPING) {
|
|
137
|
+
case "by-entry": {
|
|
138
|
+
return INLINE_SEPARATOR;
|
|
139
|
+
}
|
|
140
|
+
case "nested-by-entry": {
|
|
141
|
+
return this.#lineWrapSeparator(options) + this.#argIndentation(options);
|
|
142
|
+
}
|
|
143
|
+
case "by-argument": {
|
|
144
|
+
return this.#lineWrapSeparator(options);
|
|
145
|
+
}
|
|
146
|
+
case "inline": {
|
|
147
|
+
return INLINE_SEPARATOR;
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
throw new Error("Invalid argument line wrapping argument.");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
#entrySeparator(options) {
|
|
154
|
+
switch (options?.argumentLineWrapping ?? DEFAULT_ARGUMENT_LINE_WRAPPING) {
|
|
155
|
+
case "by-entry": {
|
|
156
|
+
return LINE_WRAP_LINE_END + this.#argIndentation(options);
|
|
157
|
+
}
|
|
158
|
+
case "nested-by-entry": {
|
|
159
|
+
return LINE_WRAP_LINE_END + this.#argIndentation(options);
|
|
160
|
+
}
|
|
161
|
+
case "by-argument": {
|
|
162
|
+
return LINE_WRAP_LINE_END + this.#argIndentation(options);
|
|
163
|
+
}
|
|
164
|
+
case "inline": {
|
|
165
|
+
return INLINE_SEPARATOR;
|
|
166
|
+
}
|
|
167
|
+
default:
|
|
168
|
+
throw new Error("Invalid argument line wrapping argument.");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
getPrintableCommand(options) {
|
|
172
|
+
options ??= {};
|
|
173
|
+
const serializedEntries = [];
|
|
174
|
+
serializedEntries.push(
|
|
175
|
+
this.#mainIndentation(options) + this.#escapeArg(this.commandName, true, options)
|
|
176
|
+
);
|
|
177
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
178
|
+
const argsEntry = this.args[i];
|
|
179
|
+
if (isString(argsEntry)) {
|
|
180
|
+
serializedEntries.push(this.#escapeArg(argsEntry, false, options));
|
|
181
|
+
} else {
|
|
182
|
+
const [part1, part2] = argsEntry;
|
|
183
|
+
serializedEntries.push(
|
|
184
|
+
this.#escapeArg(part1, false, options) + this.#argPairSeparator(options) + this.#escapeArg(part2, false, options)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return serializedEntries.join(this.#entrySeparator(options));
|
|
189
|
+
}
|
|
190
|
+
print(options) {
|
|
191
|
+
console.log(this.getPrintableCommand(options));
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The returned child process includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313
|
|
196
|
+
*/
|
|
197
|
+
spawnNode(options) {
|
|
198
|
+
const { spawn } = process.getBuiltinModule("node:child_process");
|
|
199
|
+
const subprocess = spawn(...this.forNode(), options);
|
|
200
|
+
Object.defineProperty(subprocess, "success", {
|
|
201
|
+
get() {
|
|
202
|
+
return new Promise(
|
|
203
|
+
(resolve, reject) => this.addListener(
|
|
204
|
+
"exit",
|
|
205
|
+
(exitCode) => {
|
|
206
|
+
if (exitCode === 0) {
|
|
207
|
+
resolve();
|
|
208
|
+
} else {
|
|
209
|
+
reject(`Command failed with non-zero exit code: ${exitCode}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
},
|
|
215
|
+
enumerable: false
|
|
216
|
+
});
|
|
217
|
+
return subprocess;
|
|
218
|
+
}
|
|
219
|
+
/** A wrapper for `.spawnNode(…)` that sets stdio to `"inherit"` (common for
|
|
220
|
+
* invoking commands from scripts whose output and interaction should be
|
|
221
|
+
* surfaced to the user). */
|
|
222
|
+
spawnNodeInherit(options) {
|
|
223
|
+
if (options && "stdio" in options) {
|
|
224
|
+
throw new Error("Unexpected `stdio` field.");
|
|
225
|
+
}
|
|
226
|
+
return this.spawnNode({ ...options, stdio: "inherit" });
|
|
227
|
+
}
|
|
228
|
+
/** Equivalent to:
|
|
229
|
+
*
|
|
230
|
+
* ```
|
|
231
|
+
* await this.print().spawnNodeInherit().success;
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async shellOutNode(options) {
|
|
235
|
+
await this.print().spawnNodeInherit(options).success;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* The returned subprocess includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313
|
|
239
|
+
*/
|
|
240
|
+
spawnBun(options) {
|
|
241
|
+
if (options && "cmd" in options) {
|
|
242
|
+
throw new Error("Unexpected `cmd` field.");
|
|
243
|
+
}
|
|
244
|
+
const { spawn } = process.getBuiltinModule("bun");
|
|
245
|
+
const subprocess = spawn({
|
|
246
|
+
...options,
|
|
247
|
+
cmd: this.forBun()
|
|
248
|
+
});
|
|
249
|
+
Object.defineProperty(subprocess, "success", {
|
|
250
|
+
get() {
|
|
251
|
+
return new Promise(
|
|
252
|
+
(resolve, reject) => this.exited.then((exitCode) => {
|
|
253
|
+
if (exitCode === 0) {
|
|
254
|
+
resolve();
|
|
255
|
+
} else {
|
|
256
|
+
reject(
|
|
257
|
+
new Error(
|
|
258
|
+
`Command failed with non-zero exit code: ${exitCode}`
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}).catch(reject)
|
|
263
|
+
);
|
|
264
|
+
},
|
|
265
|
+
enumerable: false
|
|
266
|
+
});
|
|
267
|
+
return subprocess;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* A wrapper for `.spawnBunInherit(…)` that sets stdio to `"inherit"` (common
|
|
271
|
+
* for invoking commands from scripts whose output and interaction should be
|
|
272
|
+
* surfaced to the user).
|
|
273
|
+
*/
|
|
274
|
+
spawnBunInherit(options) {
|
|
275
|
+
if (options && "stdio" in options) {
|
|
276
|
+
throw new Error("Unexpected `stdio` field.");
|
|
277
|
+
}
|
|
278
|
+
return this.spawnBun({
|
|
279
|
+
...options,
|
|
280
|
+
stdio: ["inherit", "inherit", "inherit"]
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/** Equivalent to:
|
|
284
|
+
*
|
|
285
|
+
* ```
|
|
286
|
+
* new Response(this.spawnBun(options).stdout);
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
spawnBunStdout(options) {
|
|
290
|
+
return new Response(this.spawnBun(options).stdout);
|
|
291
|
+
}
|
|
292
|
+
/** Equivalent to:
|
|
293
|
+
*
|
|
294
|
+
* ```
|
|
295
|
+
* await this.print().spawnBunInherit().success;
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
async shellOutBun(options) {
|
|
299
|
+
await this.print().spawnBunInherit(options).success;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
export {
|
|
303
|
+
PrintableShellCommand
|
|
304
|
+
};
|
|
305
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n\tChildProcess as NodeChildProcess,\n\tSpawnOptions as NodeSpawnOptions,\n\tSpawnOptionsWithStdioTuple as NodeSpawnOptionsWithStdioTuple,\n\tSpawnOptionsWithoutStdio as NodeSpawnOptionsWithoutStdio,\n\tStdioNull as NodeStdioNull,\n\tStdioPipe as NodeStdioPipe,\n} from \"node:child_process\";\nimport type {\n\tSpawnOptions as BunSpawnOptions,\n\tSubprocess as BunSubprocess,\n} from \"bun\";\n\nconst DEFAULT_MAIN_INDENTATION = \"\";\nconst DEFAULT_ARG_INDENTATION = \" \";\nconst DEFAULT_ARGUMENT_LINE_WRAPPING = \"by-entry\";\n\nconst INLINE_SEPARATOR = \" \";\nconst LINE_WRAP_LINE_END = \" \\\\\\n\";\n\n// biome-ignore lint/suspicious/noExplicitAny: This is the correct type nere.\nfunction isString(s: any): s is string {\n\treturn typeof s === \"string\";\n}\n\n// TODO: allow `.toString()`ables?\ntype SingleArgument = string;\ntype FlagArgumentPair = [string, string];\ntype ArgsEntry = SingleArgument | FlagArgumentPair;\ntype Args = ArgsEntry[];\n\nexport interface PrintOptions {\n\tmainIndentation?: string; // Defaults to \"\"\n\targIndentation?: string; // Defaults to \" \"\n\t// - \"auto\": Quote only arguments that need it for safety. This tries to be\n\t// portable and safe across shells, but true safety and portability is hard\n\t// to guarantee.\n\t// - \"extra-safe\": Quote all arguments, even ones that don't need it. This is\n\t// more likely to be safe under all circumstances.\n\tquoting?: \"auto\" | \"extra-safe\";\n\t// Line wrapping to use between arguments. Defaults to `\"by-entry\"`.\n\targumentLineWrapping?:\n\t\t| \"by-entry\"\n\t\t| \"nested-by-entry\"\n\t\t| \"by-argument\"\n\t\t| \"inline\";\n}\n\n// https://mywiki.wooledge.org/BashGuide/SpecialCharacters\nconst SPECIAL_SHELL_CHARACTERS = new Set([\n\t\" \",\n\t'\"',\n\t\"'\",\n\t\"`\",\n\t\"|\",\n\t\"$\",\n\t\"*\",\n\t\"?\",\n\t\">\",\n\t\"<\",\n\t\"(\",\n\t\")\",\n\t\"[\",\n\t\"]\",\n\t\"{\",\n\t\"}\",\n\t\"&\",\n\t\"\\\\\",\n\t\";\",\n]);\n\n// https://mywiki.wooledge.org/BashGuide/SpecialCharacters\nconst SPECIAL_SHELL_CHARACTERS_FOR_MAIN_COMMAND =\n\t// biome-ignore lint/suspicious/noExplicitAny: Workaround to make this package easier to use in a project that otherwise only uses ES2022.)\n\t(SPECIAL_SHELL_CHARACTERS as unknown as any).union(new Set([\"=\"]));\n\nexport class PrintableShellCommand {\n\t#commandName: string;\n\tconstructor(\n\t\tcommandName: string,\n\t\tprivate args: Args = [],\n\t) {\n\t\tif (!isString(commandName)) {\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: We want to print this, no matter what it is.\n\t\t\tthrow new Error(\"Command name is not a string:\", commandName as any);\n\t\t}\n\t\tthis.#commandName = commandName;\n\t\tif (typeof args === \"undefined\") {\n\t\t\treturn;\n\t\t}\n\t\tif (!Array.isArray(args)) {\n\t\t\tthrow new Error(\"Command arguments are not an array\");\n\t\t}\n\t\tfor (let i = 0; i < args.length; i++) {\n\t\t\tconst argEntry = args[i];\n\t\t\tif (typeof argEntry === \"string\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tArray.isArray(argEntry) &&\n\t\t\t\targEntry.length === 2 &&\n\t\t\t\tisString(argEntry[0]) &&\n\t\t\t\tisString(argEntry[1])\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow new Error(`Invalid arg entry at index: ${i}`);\n\t\t}\n\t}\n\n\tget commandName(): string {\n\t\treturn this.#commandName;\n\t}\n\n\t// For use with `bun`.\n\t//\n\t// Usage example:\n\t//\n\t// import { PrintableShellCommand } from \"printable-shell-command\";\n\t// import { spawn } from \"bun\";\n\t//\n\t// const command = new PrintableShellCommand(/* \u2026 */);\n\t// await spawn(command.toFlatCommand()).exited;\n\t//\n\tpublic toFlatCommand(): string[] {\n\t\treturn [this.commandName, ...this.args.flat()];\n\t}\n\n\t// Convenient alias for `toFlatCommand()`.\n\t//\n\t// Usage example:\n\t//\n\t// import { PrintableShellCommand } from \"printable-shell-command\";\n\t// import { spawn } from \"bun\";\n\t//\n\t// const command = new PrintableShellCommand(/* \u2026 */);\n\t// await spawn(command.forBun()).exited;\n\t//\n\tpublic forBun(): string[] {\n\t\treturn this.toFlatCommand();\n\t}\n\n\t// For use with `node:child_process`\n\t//\n\t// Usage example:\n\t//\n\t// import { PrintableShellCommand } from \"printable-shell-command\";\n\t// import { spawn } from \"node:child_process\";\n\t//\n\t// const command = new PrintableShellCommand(/* \u2026 */);\n\t// const child_process = spawn(...command.toCommandWithFlatArgs()); // Note the `...`\n\t//\n\tpublic toCommandWithFlatArgs(): [string, string[]] {\n\t\treturn [this.commandName, this.args.flat()];\n\t}\n\n\t// For use with `node:child_process`\n\t//\n\t// Usage example:\n\t//\n\t// import { PrintableShellCommand } from \"printable-shell-command\";\n\t// import { spawn } from \"node:child_process\";\n\t//\n\t// const command = new PrintableShellCommand(/* \u2026 */);\n\t// const child_process = spawn(...command.forNode()); // Note the `...`\n\t//\n\t// Convenient alias for `toCommandWithFlatArgs()`.\n\tpublic forNode(): [string, string[]] {\n\t\treturn this.toCommandWithFlatArgs();\n\t}\n\n\t#escapeArg(\n\t\targ: string,\n\t\tisMainCommand: boolean,\n\t\toptions: PrintOptions,\n\t): string {\n\t\tconst argCharacters = new Set(arg);\n\t\tconst specialShellCharacters = isMainCommand\n\t\t\t? SPECIAL_SHELL_CHARACTERS_FOR_MAIN_COMMAND\n\t\t\t: SPECIAL_SHELL_CHARACTERS;\n\t\tif (\n\t\t\toptions?.quoting === \"extra-safe\" ||\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Workaround to make this package easier to use in a project that otherwise only uses ES2022.)\n\t\t\t(argCharacters as unknown as any).intersection(specialShellCharacters)\n\t\t\t\t.size > 0\n\t\t) {\n\t\t\t// Use single quote to reduce the need to escape (and therefore reduce the chance for bugs/security issues).\n\t\t\tconst escaped = arg.replaceAll(\"\\\\\", \"\\\\\\\\\").replaceAll(\"'\", \"\\\\'\");\n\t\t\treturn `'${escaped}'`;\n\t\t}\n\t\treturn arg;\n\t}\n\n\t#mainIndentation(options: PrintOptions): string {\n\t\treturn options?.mainIndentation ?? DEFAULT_MAIN_INDENTATION;\n\t}\n\n\t#argIndentation(options: PrintOptions): string {\n\t\treturn (\n\t\t\tthis.#mainIndentation(options) +\n\t\t\t(options?.argIndentation ?? DEFAULT_ARG_INDENTATION)\n\t\t);\n\t}\n\n\t#lineWrapSeparator(options: PrintOptions): string {\n\t\treturn LINE_WRAP_LINE_END + this.#argIndentation(options);\n\t}\n\n\t#argPairSeparator(options: PrintOptions): string {\n\t\tswitch (options?.argumentLineWrapping ?? DEFAULT_ARGUMENT_LINE_WRAPPING) {\n\t\t\tcase \"by-entry\": {\n\t\t\t\treturn INLINE_SEPARATOR;\n\t\t\t}\n\t\t\tcase \"nested-by-entry\": {\n\t\t\t\treturn this.#lineWrapSeparator(options) + this.#argIndentation(options);\n\t\t\t}\n\t\t\tcase \"by-argument\": {\n\t\t\t\treturn this.#lineWrapSeparator(options);\n\t\t\t}\n\t\t\tcase \"inline\": {\n\t\t\t\treturn INLINE_SEPARATOR;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Invalid argument line wrapping argument.\");\n\t\t}\n\t}\n\n\t#entrySeparator(options: PrintOptions): string {\n\t\tswitch (options?.argumentLineWrapping ?? DEFAULT_ARGUMENT_LINE_WRAPPING) {\n\t\t\tcase \"by-entry\": {\n\t\t\t\treturn LINE_WRAP_LINE_END + this.#argIndentation(options);\n\t\t\t}\n\t\t\tcase \"nested-by-entry\": {\n\t\t\t\treturn LINE_WRAP_LINE_END + this.#argIndentation(options);\n\t\t\t}\n\t\t\tcase \"by-argument\": {\n\t\t\t\treturn LINE_WRAP_LINE_END + this.#argIndentation(options);\n\t\t\t}\n\t\t\tcase \"inline\": {\n\t\t\t\treturn INLINE_SEPARATOR;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Invalid argument line wrapping argument.\");\n\t\t}\n\t}\n\n\tpublic getPrintableCommand(options?: PrintOptions): string {\n\t\t// TODO: Why in the world does TypeScript not give the `options` arg the type of `PrintOptions | undefined`???\n\t\t// biome-ignore lint/style/noParameterAssign: We want a default assignment without affecting the signature.\n\t\toptions ??= {};\n\t\tconst serializedEntries: string[] = [];\n\n\t\tserializedEntries.push(\n\t\t\tthis.#mainIndentation(options) +\n\t\t\t\tthis.#escapeArg(this.commandName, true, options),\n\t\t);\n\n\t\tfor (let i = 0; i < this.args.length; i++) {\n\t\t\tconst argsEntry = this.args[i];\n\n\t\t\tif (isString(argsEntry)) {\n\t\t\t\tserializedEntries.push(this.#escapeArg(argsEntry, false, options));\n\t\t\t} else {\n\t\t\t\tconst [part1, part2] = argsEntry;\n\t\t\t\tserializedEntries.push(\n\t\t\t\t\tthis.#escapeArg(part1, false, options) +\n\t\t\t\t\t\tthis.#argPairSeparator(options) +\n\t\t\t\t\t\tthis.#escapeArg(part2, false, options),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn serializedEntries.join(this.#entrySeparator(options));\n\t}\n\n\tpublic print(options?: PrintOptions): PrintableShellCommand {\n\t\tconsole.log(this.getPrintableCommand(options));\n\t\treturn this;\n\t}\n\n\t/**\n\t * The returned child process includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313\n\t */\n\tpublic spawnNode<\n\t\tStdin extends NodeStdioNull | NodeStdioPipe,\n\t\tStdout extends NodeStdioNull | NodeStdioPipe,\n\t\tStderr extends NodeStdioNull | NodeStdioPipe,\n\t>(\n\t\toptions?:\n\t\t\t| NodeSpawnOptions\n\t\t\t| NodeSpawnOptionsWithoutStdio\n\t\t\t| NodeSpawnOptionsWithStdioTuple<Stdin, Stdout, Stderr>,\n\t): // TODO: figure out how to return `ChildProcessByStdio<\u2026>` without duplicating fragile boilerplate.\n\tNodeChildProcess & { success: Promise<void> } {\n\t\tconst { spawn } = process.getBuiltinModule(\"node:child_process\");\n\t\t// @ts-ignore: The TypeScript checker has trouble reconciling the optional (i.e. potentially `undefined`) `options` with the third argument.\n\t\tconst subprocess = spawn(...this.forNode(), options) as NodeChildProcess & {\n\t\t\tsuccess: Promise<void>;\n\t\t};\n\t\tObject.defineProperty(subprocess, \"success\", {\n\t\t\tget() {\n\t\t\t\treturn new Promise<void>((resolve, reject) =>\n\t\t\t\t\tthis.addListener(\n\t\t\t\t\t\t\"exit\",\n\t\t\t\t\t\t(exitCode: number /* we only use the first arg */) => {\n\t\t\t\t\t\t\tif (exitCode === 0) {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treject(`Command failed with non-zero exit code: ${exitCode}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t});\n\t\treturn subprocess;\n\t}\n\n\t/** A wrapper for `.spawnNode(\u2026)` that sets stdio to `\"inherit\"` (common for\n\t * invoking commands from scripts whose output and interaction should be\n\t * surfaced to the user). */\n\tpublic spawnNodeInherit(\n\t\toptions?: Omit<NodeSpawnOptions, \"stdio\">,\n\t): NodeChildProcess & { success: Promise<void> } {\n\t\tif (options && \"stdio\" in options) {\n\t\t\tthrow new Error(\"Unexpected `stdio` field.\");\n\t\t}\n\t\treturn this.spawnNode({ ...options, stdio: \"inherit\" });\n\t}\n\n\t/** Equivalent to:\n\t *\n\t * ```\n\t * await this.print().spawnNodeInherit().success;\n\t * ```\n\t */\n\tpublic async shellOutNode(\n\t\toptions?: Omit<NodeSpawnOptions, \"stdio\">,\n\t): Promise<void> {\n\t\tawait this.print().spawnNodeInherit(options).success;\n\t}\n\n\t/**\n\t * The returned subprocess includes a `.success` `Promise` field, per https://github.com/oven-sh/bun/issues/8313\n\t */\n\tpublic spawnBun<\n\t\tconst In extends BunSpawnOptions.Writable = \"ignore\",\n\t\tconst Out extends BunSpawnOptions.Readable = \"pipe\",\n\t\tconst Err extends BunSpawnOptions.Readable = \"inherit\",\n\t>(\n\t\toptions?: Omit<BunSpawnOptions.OptionsObject<In, Out, Err>, \"cmd\">,\n\t): BunSubprocess<In, Out, Err> & { success: Promise<void> } {\n\t\tif (options && \"cmd\" in options) {\n\t\t\tthrow new Error(\"Unexpected `cmd` field.\");\n\t\t}\n\t\tconst { spawn } = process.getBuiltinModule(\"bun\") as typeof import(\"bun\");\n\t\tconst subprocess = spawn({\n\t\t\t...options,\n\t\t\tcmd: this.forBun(),\n\t\t}) as BunSubprocess<In, Out, Err> & { success: Promise<void> };\n\t\tObject.defineProperty(subprocess, \"success\", {\n\t\t\tget() {\n\t\t\t\treturn new Promise<void>((resolve, reject) =>\n\t\t\t\t\tthis.exited\n\t\t\t\t\t\t.then((exitCode: number) => {\n\t\t\t\t\t\t\tif (exitCode === 0) {\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\treject(\n\t\t\t\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t\t\t\t`Command failed with non-zero exit code: ${exitCode}`,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch(reject),\n\t\t\t\t);\n\t\t\t},\n\t\t\tenumerable: false,\n\t\t});\n\t\treturn subprocess;\n\t}\n\n\t/**\n\t * A wrapper for `.spawnBunInherit(\u2026)` that sets stdio to `\"inherit\"` (common\n\t * for invoking commands from scripts whose output and interaction should be\n\t * surfaced to the user).\n\t */\n\tpublic spawnBunInherit(\n\t\toptions?: Omit<\n\t\t\tOmit<\n\t\t\t\tBunSpawnOptions.OptionsObject<\"inherit\", \"inherit\", \"inherit\">,\n\t\t\t\t\"cmd\"\n\t\t\t>,\n\t\t\t\"stdio\"\n\t\t>,\n\t): BunSubprocess<\"inherit\", \"inherit\", \"inherit\"> & {\n\t\tsuccess: Promise<void>;\n\t} {\n\t\tif (options && \"stdio\" in options) {\n\t\t\tthrow new Error(\"Unexpected `stdio` field.\");\n\t\t}\n\t\treturn this.spawnBun({\n\t\t\t...options,\n\t\t\tstdio: [\"inherit\", \"inherit\", \"inherit\"],\n\t\t});\n\t}\n\n\t/** Equivalent to:\n\t *\n\t * ```\n\t * new Response(this.spawnBun(options).stdout);\n\t * ```\n\t */\n\tpublic spawnBunStdout(\n\t\toptions?: Omit<\n\t\t\tOmit<\n\t\t\t\tBunSpawnOptions.OptionsObject<\"inherit\", \"inherit\", \"inherit\">,\n\t\t\t\t\"cmd\"\n\t\t\t>,\n\t\t\t\"stdio\"\n\t\t>,\n\t): Response {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: Avoid breaking the lib check when used without `@types/bun`.\n\t\treturn new Response((this.spawnBun(options) as any).stdout);\n\t}\n\n\t/** Equivalent to:\n\t *\n\t * ```\n\t * await this.print().spawnBunInherit().success;\n\t * ```\n\t */\n\tpublic async shellOutBun(\n\t\toptions?: Omit<\n\t\t\tOmit<\n\t\t\t\tBunSpawnOptions.OptionsObject<\"inherit\", \"inherit\", \"inherit\">,\n\t\t\t\t\"cmd\"\n\t\t\t>,\n\t\t\t\"stdio\"\n\t\t>,\n\t): Promise<void> {\n\t\tawait this.print().spawnBunInherit(options).success;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";AAaA,IAAM,2BAA2B;AACjC,IAAM,0BAA0B;AAChC,IAAM,iCAAiC;AAEvC,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAG3B,SAAS,SAAS,GAAqB;AACtC,SAAO,OAAO,MAAM;AACrB;AA0BA,IAAM,2BAA2B,oBAAI,IAAI;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAGD,IAAM;AAAA;AAAA,EAEJ,yBAA4C,MAAM,oBAA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,WAAO,KAAK,SAAS;AAAA,MACpB,GAAG;AAAA,MACH,OAAO,CAAC,WAAW,WAAW,SAAS;AAAA,IACxC,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,eACN,SAOW;AAEX,WAAO,IAAI,SAAU,KAAK,SAAS,OAAO,EAAU,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAa,YACZ,SAOgB;AAChB,UAAM,KAAK,MAAM,EAAE,gBAAgB,OAAO,EAAE;AAAA,EAC7C;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "printable-shell-command",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"main": "./src/index.ts",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"types": "./src/index.ts",
|
|
9
|
-
"import": "./src/index.ts"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
5
|
"devDependencies": {
|
|
13
6
|
"@biomejs/biome": "^1.9.4",
|
|
7
|
+
"@cubing/dev-config": "^0.1.2",
|
|
14
8
|
"@types/bun": "^1.2.11",
|
|
15
|
-
"@types/node": "^22.15.3"
|
|
9
|
+
"@types/node": "^22.15.3",
|
|
10
|
+
"esbuild": "^0.25.3"
|
|
16
11
|
},
|
|
17
12
|
"optionalDependencies": {
|
|
18
13
|
"@types/bun": "^1.2.11",
|
|
19
14
|
"@types/node": "^22.15.3"
|
|
20
15
|
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/lib/printable-shell-command/index.d.ts",
|
|
19
|
+
"import": "./dist/lib/printable-shell-command/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
21
22
|
"files": [
|
|
22
|
-
"
|
|
23
|
-
"src"
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"./dist/",
|
|
24
|
+
"./src/"
|
|
25
|
+
],
|
|
26
|
+
"type": "module"
|
|
26
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -422,7 +422,8 @@ export class PrintableShellCommand {
|
|
|
422
422
|
"stdio"
|
|
423
423
|
>,
|
|
424
424
|
): Response {
|
|
425
|
-
|
|
425
|
+
// biome-ignore lint/suspicious/noExplicitAny: Avoid breaking the lib check when used without `@types/bun`.
|
|
426
|
+
return new Response((this.spawnBun(options) as any).stdout);
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
/** Equivalent to:
|