@boba-cli/machine 0.1.0-alpha.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 +335 -0
- package/dist/browser/index.cjs +696 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +232 -0
- package/dist/browser/index.d.ts +232 -0
- package/dist/browser/index.js +686 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/index.cjs +435 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +329 -0
- package/dist/index.d.ts +329 -0
- package/dist/index.js +364 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.cjs +827 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +235 -0
- package/dist/node/index.d.ts +235 -0
- package/dist/node/index.js +790 -0
- package/dist/node/index.js.map +1 -0
- package/dist/types-FB6TYMn5.d.cts +443 -0
- package/dist/types-FB6TYMn5.d.ts +443 -0
- package/package.json +95 -0
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var module$1 = require('module');
|
|
4
|
+
var process = require('process');
|
|
5
|
+
var promises = require('fs/promises');
|
|
6
|
+
var os = require('os');
|
|
7
|
+
var nodePath = require('path');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
30
|
+
var nodePath__namespace = /*#__PURE__*/_interopNamespace(nodePath);
|
|
31
|
+
|
|
32
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
33
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
34
|
+
}) : x)(function(x) {
|
|
35
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
36
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.55.2_@types+node@24.10.2__jiti@2.6.1_postcss@8.5._cc73ec3ff2d01f4687d3b65cbe1abb84/node_modules/tsup/assets/cjs_shims.js
|
|
40
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
41
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
42
|
+
|
|
43
|
+
// src/style/index.ts
|
|
44
|
+
var ESC = "\x1B[";
|
|
45
|
+
var CODES = {
|
|
46
|
+
// Modifiers (open, close)
|
|
47
|
+
bold: ["1", "22"],
|
|
48
|
+
dim: ["2", "22"],
|
|
49
|
+
italic: ["3", "23"],
|
|
50
|
+
underline: ["4", "24"],
|
|
51
|
+
inverse: ["7", "27"],
|
|
52
|
+
hidden: ["8", "28"],
|
|
53
|
+
strikethrough: ["9", "29"],
|
|
54
|
+
// Basic foreground colors (30-37)
|
|
55
|
+
black: ["30", "39"],
|
|
56
|
+
red: ["31", "39"],
|
|
57
|
+
green: ["32", "39"],
|
|
58
|
+
yellow: ["33", "39"],
|
|
59
|
+
blue: ["34", "39"],
|
|
60
|
+
magenta: ["35", "39"],
|
|
61
|
+
cyan: ["36", "39"],
|
|
62
|
+
white: ["37", "39"],
|
|
63
|
+
// Bright foreground colors (90-97)
|
|
64
|
+
blackBright: ["90", "39"],
|
|
65
|
+
redBright: ["91", "39"],
|
|
66
|
+
greenBright: ["92", "39"],
|
|
67
|
+
yellowBright: ["93", "39"],
|
|
68
|
+
blueBright: ["94", "39"],
|
|
69
|
+
magentaBright: ["95", "39"],
|
|
70
|
+
cyanBright: ["96", "39"],
|
|
71
|
+
whiteBright: ["97", "39"],
|
|
72
|
+
// Basic background colors (40-47)
|
|
73
|
+
bgBlack: ["40", "49"],
|
|
74
|
+
bgRed: ["41", "49"],
|
|
75
|
+
bgGreen: ["42", "49"],
|
|
76
|
+
bgYellow: ["43", "49"],
|
|
77
|
+
bgBlue: ["44", "49"],
|
|
78
|
+
bgMagenta: ["45", "49"],
|
|
79
|
+
bgCyan: ["46", "49"],
|
|
80
|
+
bgWhite: ["47", "49"],
|
|
81
|
+
// Bright background colors (100-107)
|
|
82
|
+
bgBlackBright: ["100", "49"],
|
|
83
|
+
bgRedBright: ["101", "49"],
|
|
84
|
+
bgGreenBright: ["102", "49"],
|
|
85
|
+
bgYellowBright: ["103", "49"],
|
|
86
|
+
bgBlueBright: ["104", "49"],
|
|
87
|
+
bgMagentaBright: ["105", "49"],
|
|
88
|
+
bgCyanBright: ["106", "49"],
|
|
89
|
+
bgWhiteBright: ["107", "49"]
|
|
90
|
+
};
|
|
91
|
+
function applyStyle(text, open, close) {
|
|
92
|
+
const openSeq = `${ESC}${open}m`;
|
|
93
|
+
const closeSeq = `${ESC}${close}m`;
|
|
94
|
+
const replaced = text.replace(
|
|
95
|
+
new RegExp(closeSeq.replace(/[[\](){}|^$+*?.\\]/g, "\\$&"), "g"),
|
|
96
|
+
closeSeq + openSeq
|
|
97
|
+
);
|
|
98
|
+
return openSeq + replaced + closeSeq;
|
|
99
|
+
}
|
|
100
|
+
function hexToRgb(hex) {
|
|
101
|
+
const clean = hex.replace(/^#/, "");
|
|
102
|
+
const num = parseInt(clean, 16);
|
|
103
|
+
if (clean.length === 3) {
|
|
104
|
+
const r2 = (num >> 8 & 15) * 17;
|
|
105
|
+
const g2 = (num >> 4 & 15) * 17;
|
|
106
|
+
const b2 = (num & 15) * 17;
|
|
107
|
+
return [r2, g2, b2];
|
|
108
|
+
}
|
|
109
|
+
const r = num >> 16 & 255;
|
|
110
|
+
const g = num >> 8 & 255;
|
|
111
|
+
const b = num & 255;
|
|
112
|
+
return [r, g, b];
|
|
113
|
+
}
|
|
114
|
+
function createStyle(colorSupport) {
|
|
115
|
+
const enabled = colorSupport.level > 0;
|
|
116
|
+
function build(stack) {
|
|
117
|
+
const fn = (text) => {
|
|
118
|
+
if (!enabled || stack.length === 0) {
|
|
119
|
+
return text;
|
|
120
|
+
}
|
|
121
|
+
let result = text;
|
|
122
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
123
|
+
const [open, close] = stack[i];
|
|
124
|
+
result = applyStyle(result, open, close);
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
const codeNames = Object.keys(CODES);
|
|
129
|
+
for (const name of codeNames) {
|
|
130
|
+
const [open, close] = CODES[name];
|
|
131
|
+
Object.defineProperty(fn, name, {
|
|
132
|
+
get() {
|
|
133
|
+
return build([...stack, [open, close]]);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
Object.defineProperty(fn, "gray", {
|
|
138
|
+
get() {
|
|
139
|
+
const [open, close] = CODES.blackBright;
|
|
140
|
+
return build([...stack, [open, close]]);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(fn, "grey", {
|
|
144
|
+
get() {
|
|
145
|
+
const [open, close] = CODES.blackBright;
|
|
146
|
+
return build([...stack, [open, close]]);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(fn, "hex", {
|
|
150
|
+
value: (color) => {
|
|
151
|
+
if (!enabled || !colorSupport.has16m) {
|
|
152
|
+
return build(stack);
|
|
153
|
+
}
|
|
154
|
+
const [r, g, b] = hexToRgb(color);
|
|
155
|
+
return build([...stack, [`38;2;${r};${g};${b}`, "39"]]);
|
|
156
|
+
},
|
|
157
|
+
writable: true
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(fn, "rgb", {
|
|
160
|
+
value: (r, g, b) => {
|
|
161
|
+
if (!enabled || !colorSupport.has16m) {
|
|
162
|
+
return build(stack);
|
|
163
|
+
}
|
|
164
|
+
return build([...stack, [`38;2;${r};${g};${b}`, "39"]]);
|
|
165
|
+
},
|
|
166
|
+
writable: true
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(fn, "bgHex", {
|
|
169
|
+
value: (color) => {
|
|
170
|
+
if (!enabled || !colorSupport.has16m) {
|
|
171
|
+
return build(stack);
|
|
172
|
+
}
|
|
173
|
+
const [r, g, b] = hexToRgb(color);
|
|
174
|
+
return build([...stack, [`48;2;${r};${g};${b}`, "49"]]);
|
|
175
|
+
},
|
|
176
|
+
writable: true
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(fn, "bgRgb", {
|
|
179
|
+
value: (r, g, b) => {
|
|
180
|
+
if (!enabled || !colorSupport.has16m) {
|
|
181
|
+
return build(stack);
|
|
182
|
+
}
|
|
183
|
+
return build([...stack, [`48;2;${r};${g};${b}`, "49"]]);
|
|
184
|
+
},
|
|
185
|
+
writable: true
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(fn, "ansi256", {
|
|
188
|
+
value: (code) => {
|
|
189
|
+
if (!enabled || !colorSupport.has256) {
|
|
190
|
+
return build(stack);
|
|
191
|
+
}
|
|
192
|
+
return build([...stack, [`38;5;${code}`, "39"]]);
|
|
193
|
+
},
|
|
194
|
+
writable: true
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(fn, "bgAnsi256", {
|
|
197
|
+
value: (code) => {
|
|
198
|
+
if (!enabled || !colorSupport.has256) {
|
|
199
|
+
return build(stack);
|
|
200
|
+
}
|
|
201
|
+
return build([...stack, [`48;5;${code}`, "49"]]);
|
|
202
|
+
},
|
|
203
|
+
writable: true
|
|
204
|
+
});
|
|
205
|
+
return fn;
|
|
206
|
+
}
|
|
207
|
+
return build([]);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// src/node/archive.ts
|
|
211
|
+
var NodeArchiveAdapter = class {
|
|
212
|
+
hasArchiver;
|
|
213
|
+
hasUnzipper;
|
|
214
|
+
/**
|
|
215
|
+
* Create a new Node.js archive adapter.
|
|
216
|
+
* Checks for availability of archiver and unzipper packages.
|
|
217
|
+
*/
|
|
218
|
+
constructor() {
|
|
219
|
+
this.hasArchiver = this.checkPackageAvailability("archiver");
|
|
220
|
+
this.hasUnzipper = this.checkPackageAvailability("unzipper");
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Check if a package is available.
|
|
224
|
+
* @param packageName - Package to check
|
|
225
|
+
* @returns True if package can be imported
|
|
226
|
+
*/
|
|
227
|
+
checkPackageAvailability(packageName) {
|
|
228
|
+
try {
|
|
229
|
+
__require.resolve(packageName);
|
|
230
|
+
return true;
|
|
231
|
+
} catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Check if archive operations are available.
|
|
237
|
+
* @returns True if both archiver and unzipper are available
|
|
238
|
+
*/
|
|
239
|
+
isAvailable() {
|
|
240
|
+
return this.hasArchiver && this.hasUnzipper;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a zip archive from a directory.
|
|
244
|
+
* @param sourceDir - Source directory to archive
|
|
245
|
+
* @param destPath - Destination path for the zip file
|
|
246
|
+
* @throws Error if archiver is not available or archiving fails
|
|
247
|
+
*/
|
|
248
|
+
async zip(sourceDir, destPath) {
|
|
249
|
+
if (!this.hasArchiver) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
"Archive operations not available: archiver package not found. Install with: pnpm add archiver"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
const archiver = await import('archiver');
|
|
255
|
+
const { createWriteStream } = await import('fs');
|
|
256
|
+
const { stat: stat2 } = await import('fs/promises');
|
|
257
|
+
const path = await import('path');
|
|
258
|
+
return new Promise((resolve2, reject) => {
|
|
259
|
+
const outputStream = createWriteStream(destPath);
|
|
260
|
+
const archive = archiver.default("zip", { zlib: { level: 9 } });
|
|
261
|
+
outputStream.on("close", () => {
|
|
262
|
+
resolve2();
|
|
263
|
+
});
|
|
264
|
+
archive.on("error", (err) => {
|
|
265
|
+
reject(err);
|
|
266
|
+
});
|
|
267
|
+
archive.pipe(outputStream);
|
|
268
|
+
stat2(sourceDir).then((stats) => {
|
|
269
|
+
if (stats.isDirectory()) {
|
|
270
|
+
archive.directory(sourceDir, false);
|
|
271
|
+
} else {
|
|
272
|
+
archive.file(sourceDir, { name: path.basename(sourceDir) });
|
|
273
|
+
}
|
|
274
|
+
void archive.finalize();
|
|
275
|
+
}).catch((err) => {
|
|
276
|
+
reject(err);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Extract a zip archive to a directory.
|
|
282
|
+
* @param archivePath - Path to the zip file
|
|
283
|
+
* @param destDir - Destination directory for extraction
|
|
284
|
+
* @throws Error if unzipper is not available or extraction fails
|
|
285
|
+
*/
|
|
286
|
+
async unzip(archivePath, destDir) {
|
|
287
|
+
if (!this.hasUnzipper) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
"Archive operations not available: unzipper package not found. Install with: pnpm add unzipper"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
const unzipper = await import('unzipper');
|
|
293
|
+
const { createReadStream } = await import('fs');
|
|
294
|
+
return new Promise((resolve2, reject) => {
|
|
295
|
+
createReadStream(archivePath).pipe(unzipper.Extract({ path: destDir })).on("close", () => {
|
|
296
|
+
resolve2();
|
|
297
|
+
}).on("error", (err) => {
|
|
298
|
+
reject(err);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
var require2 = module$1.createRequire(importMetaUrl);
|
|
304
|
+
var NodeClipboardAdapter = class {
|
|
305
|
+
clipboard = null;
|
|
306
|
+
available = null;
|
|
307
|
+
/**
|
|
308
|
+
* Create a new Node.js clipboard adapter.
|
|
309
|
+
* Optionally pass a pre-loaded clipboardy module for dependency injection.
|
|
310
|
+
* @param clipboardModule - Optional pre-loaded clipboard module
|
|
311
|
+
*/
|
|
312
|
+
constructor(clipboardModule) {
|
|
313
|
+
if (clipboardModule) {
|
|
314
|
+
this.clipboard = clipboardModule;
|
|
315
|
+
this.available = true;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
async loadClipboard() {
|
|
319
|
+
if (this.available === false) {
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
if (this.clipboard !== null) {
|
|
323
|
+
return this.clipboard;
|
|
324
|
+
}
|
|
325
|
+
try {
|
|
326
|
+
const module = await import('clipboardy');
|
|
327
|
+
this.clipboard = module.default;
|
|
328
|
+
this.available = true;
|
|
329
|
+
return this.clipboard;
|
|
330
|
+
} catch {
|
|
331
|
+
this.available = false;
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async read() {
|
|
336
|
+
const clipboard = await this.loadClipboard();
|
|
337
|
+
if (!clipboard) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
"Clipboard not available. Install clipboardy: npm install clipboardy"
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
return await clipboard.read();
|
|
344
|
+
} catch {
|
|
345
|
+
this.available = false;
|
|
346
|
+
this.clipboard = null;
|
|
347
|
+
throw new Error(
|
|
348
|
+
"Clipboard not available. Install clipboardy: npm install clipboardy"
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
async write(text) {
|
|
353
|
+
const clipboard = await this.loadClipboard();
|
|
354
|
+
if (!clipboard) {
|
|
355
|
+
throw new Error(
|
|
356
|
+
"Clipboard not available. Install clipboardy: npm install clipboardy"
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
await clipboard.write(text);
|
|
361
|
+
} catch {
|
|
362
|
+
this.available = false;
|
|
363
|
+
this.clipboard = null;
|
|
364
|
+
throw new Error(
|
|
365
|
+
"Clipboard not available. Install clipboardy: npm install clipboardy"
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
isAvailable() {
|
|
370
|
+
if (this.available !== null) {
|
|
371
|
+
return this.available;
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
require2.resolve("clipboardy");
|
|
375
|
+
return true;
|
|
376
|
+
} catch {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
var require3 = module$1.createRequire(importMetaUrl);
|
|
382
|
+
var NodeEnvironmentAdapter = class {
|
|
383
|
+
supportsColorModule = null;
|
|
384
|
+
colorSupportCached = null;
|
|
385
|
+
backgroundCached = null;
|
|
386
|
+
/**
|
|
387
|
+
* Create a new Node.js environment adapter.
|
|
388
|
+
* Optionally pass a pre-loaded supports-color module for dependency injection.
|
|
389
|
+
* @param supportsColor - Optional pre-loaded supports-color module
|
|
390
|
+
*/
|
|
391
|
+
constructor(supportsColor) {
|
|
392
|
+
if (supportsColor) {
|
|
393
|
+
this.supportsColorModule = supportsColor;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
get(name) {
|
|
397
|
+
return process__default.default.env[name];
|
|
398
|
+
}
|
|
399
|
+
getColorSupport() {
|
|
400
|
+
if (this.colorSupportCached) {
|
|
401
|
+
return this.colorSupportCached;
|
|
402
|
+
}
|
|
403
|
+
const support = this.detectColorSupport();
|
|
404
|
+
this.colorSupportCached = support;
|
|
405
|
+
return support;
|
|
406
|
+
}
|
|
407
|
+
detectColorSupport() {
|
|
408
|
+
const module = this.loadSupportsColor();
|
|
409
|
+
if (module) {
|
|
410
|
+
const stdout = module.stdout;
|
|
411
|
+
if (stdout && typeof stdout.level === "number") {
|
|
412
|
+
const level = stdout.level;
|
|
413
|
+
return {
|
|
414
|
+
level,
|
|
415
|
+
hasBasic: level >= 1,
|
|
416
|
+
has256: level >= 2,
|
|
417
|
+
has16m: level >= 3
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return this.detectColorSupportFromEnv();
|
|
422
|
+
}
|
|
423
|
+
loadSupportsColor() {
|
|
424
|
+
if (this.supportsColorModule !== null) {
|
|
425
|
+
return this.supportsColorModule;
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const module = require3("supports-color");
|
|
429
|
+
this.supportsColorModule = module;
|
|
430
|
+
return module;
|
|
431
|
+
} catch {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
detectColorSupportFromEnv() {
|
|
436
|
+
const colorTerm = process__default.default.env.COLORTERM?.toLowerCase();
|
|
437
|
+
if (colorTerm === "truecolor" || colorTerm === "24bit") {
|
|
438
|
+
return { level: 3, hasBasic: true, has256: true, has16m: true };
|
|
439
|
+
}
|
|
440
|
+
const term = process__default.default.env.TERM?.toLowerCase() ?? "";
|
|
441
|
+
if (term.includes("256color") || term.includes("256-color")) {
|
|
442
|
+
return { level: 2, hasBasic: true, has256: true, has16m: false };
|
|
443
|
+
}
|
|
444
|
+
if (term.includes("color") || term.includes("ansi") || term.includes("xterm") || term.includes("vt100") || term.includes("screen") || term.includes("linux")) {
|
|
445
|
+
return { level: 1, hasBasic: true, has256: false, has16m: false };
|
|
446
|
+
}
|
|
447
|
+
if (process__default.default.env.CI) {
|
|
448
|
+
return { level: 1, hasBasic: true, has256: false, has16m: false };
|
|
449
|
+
}
|
|
450
|
+
if (process__default.default.stdout?.isTTY) {
|
|
451
|
+
return { level: 1, hasBasic: true, has256: false, has16m: false };
|
|
452
|
+
}
|
|
453
|
+
return { level: 0, hasBasic: false, has256: false, has16m: false };
|
|
454
|
+
}
|
|
455
|
+
getTerminalBackground() {
|
|
456
|
+
if (this.backgroundCached) {
|
|
457
|
+
return this.backgroundCached;
|
|
458
|
+
}
|
|
459
|
+
const background = this.detectTerminalBackground();
|
|
460
|
+
this.backgroundCached = background;
|
|
461
|
+
return background;
|
|
462
|
+
}
|
|
463
|
+
detectTerminalBackground() {
|
|
464
|
+
const colorFgBg = process__default.default.env.COLORFGBG;
|
|
465
|
+
if (colorFgBg) {
|
|
466
|
+
const parts = colorFgBg.split(";");
|
|
467
|
+
const bg = parseInt(parts[parts.length - 1] ?? "", 10);
|
|
468
|
+
if (!isNaN(bg)) {
|
|
469
|
+
return bg < 7 || bg >= 8 && bg < 16 && bg !== 15 ? "dark" : "light";
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const termBackground = process__default.default.env.TERM_BACKGROUND?.toLowerCase();
|
|
473
|
+
if (termBackground === "dark" || termBackground === "light") {
|
|
474
|
+
return termBackground;
|
|
475
|
+
}
|
|
476
|
+
const termProgram = process__default.default.env.TERM_PROGRAM ?? "";
|
|
477
|
+
if (/iTerm/i.test(termProgram)) {
|
|
478
|
+
return "dark";
|
|
479
|
+
}
|
|
480
|
+
if (process__default.default.env.TERM_PROGRAM === "vscode") {
|
|
481
|
+
return "dark";
|
|
482
|
+
}
|
|
483
|
+
return "unknown";
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
var NodeDirectoryEntry = class {
|
|
487
|
+
name;
|
|
488
|
+
_isDirectory;
|
|
489
|
+
_isFile;
|
|
490
|
+
_isSymbolicLink;
|
|
491
|
+
constructor(name, isDirectory, isFile, isSymbolicLink) {
|
|
492
|
+
this.name = name;
|
|
493
|
+
this._isDirectory = isDirectory;
|
|
494
|
+
this._isFile = isFile;
|
|
495
|
+
this._isSymbolicLink = isSymbolicLink;
|
|
496
|
+
}
|
|
497
|
+
isDirectory() {
|
|
498
|
+
return this._isDirectory;
|
|
499
|
+
}
|
|
500
|
+
isFile() {
|
|
501
|
+
return this._isFile;
|
|
502
|
+
}
|
|
503
|
+
isSymbolicLink() {
|
|
504
|
+
return this._isSymbolicLink;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
var NodeFileSystemAdapter = class {
|
|
508
|
+
async readdir(path, options) {
|
|
509
|
+
if (options?.withFileTypes) {
|
|
510
|
+
const entries = await promises.readdir(path, { withFileTypes: true });
|
|
511
|
+
return entries.map(
|
|
512
|
+
(entry) => new NodeDirectoryEntry(
|
|
513
|
+
entry.name,
|
|
514
|
+
entry.isDirectory(),
|
|
515
|
+
entry.isFile(),
|
|
516
|
+
entry.isSymbolicLink()
|
|
517
|
+
)
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
return promises.readdir(path);
|
|
521
|
+
}
|
|
522
|
+
async stat(path) {
|
|
523
|
+
const stats = await promises.stat(path);
|
|
524
|
+
return {
|
|
525
|
+
size: stats.size,
|
|
526
|
+
mode: stats.mode,
|
|
527
|
+
mtime: stats.mtime,
|
|
528
|
+
isDirectory: stats.isDirectory(),
|
|
529
|
+
isFile: stats.isFile(),
|
|
530
|
+
isSymbolicLink: stats.isSymbolicLink()
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
async readFile(path, encoding) {
|
|
534
|
+
return promises.readFile(path, { encoding: encoding ?? "utf-8" });
|
|
535
|
+
}
|
|
536
|
+
async writeFile(path, content) {
|
|
537
|
+
await promises.writeFile(path, content, "utf-8");
|
|
538
|
+
}
|
|
539
|
+
async exists(path) {
|
|
540
|
+
try {
|
|
541
|
+
await promises.stat(path);
|
|
542
|
+
return true;
|
|
543
|
+
} catch {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
async mkdir(path, options) {
|
|
548
|
+
await promises.mkdir(path, { recursive: options?.recursive });
|
|
549
|
+
}
|
|
550
|
+
async unlink(path) {
|
|
551
|
+
await promises.unlink(path);
|
|
552
|
+
}
|
|
553
|
+
async rmdir(path, options) {
|
|
554
|
+
if (options?.recursive || options?.force) {
|
|
555
|
+
await promises.rm(path, { recursive: options.recursive ?? false, force: options.force ?? false });
|
|
556
|
+
} else {
|
|
557
|
+
await promises.rmdir(path);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async rename(src, dst) {
|
|
561
|
+
await promises.rename(src, dst);
|
|
562
|
+
}
|
|
563
|
+
async copyFile(src, dst) {
|
|
564
|
+
await promises.copyFile(src, dst);
|
|
565
|
+
}
|
|
566
|
+
cwd() {
|
|
567
|
+
return process__default.default.cwd();
|
|
568
|
+
}
|
|
569
|
+
homedir() {
|
|
570
|
+
return os.homedir();
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
var NodePathAdapter = class {
|
|
574
|
+
sep = nodePath__namespace.sep;
|
|
575
|
+
join(...segments) {
|
|
576
|
+
return nodePath__namespace.join(...segments);
|
|
577
|
+
}
|
|
578
|
+
dirname(path) {
|
|
579
|
+
return nodePath__namespace.dirname(path);
|
|
580
|
+
}
|
|
581
|
+
basename(path, ext) {
|
|
582
|
+
return nodePath__namespace.basename(path, ext);
|
|
583
|
+
}
|
|
584
|
+
extname(path) {
|
|
585
|
+
return nodePath__namespace.extname(path);
|
|
586
|
+
}
|
|
587
|
+
resolve(...segments) {
|
|
588
|
+
return nodePath__namespace.resolve(...segments);
|
|
589
|
+
}
|
|
590
|
+
isAbsolute(path) {
|
|
591
|
+
return nodePath__namespace.isAbsolute(path);
|
|
592
|
+
}
|
|
593
|
+
normalize(path) {
|
|
594
|
+
return nodePath__namespace.normalize(path);
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var NodeSignalAdapter = class {
|
|
598
|
+
interruptHandlers = /* @__PURE__ */ new Set();
|
|
599
|
+
terminateHandlers = /* @__PURE__ */ new Set();
|
|
600
|
+
disposed = false;
|
|
601
|
+
handleInterrupt = () => {
|
|
602
|
+
for (const handler of this.interruptHandlers) {
|
|
603
|
+
handler();
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
handleTerminate = () => {
|
|
607
|
+
for (const handler of this.terminateHandlers) {
|
|
608
|
+
handler();
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
onInterrupt(handler) {
|
|
612
|
+
if (this.interruptHandlers.size === 0) {
|
|
613
|
+
process__default.default.on("SIGINT", this.handleInterrupt);
|
|
614
|
+
}
|
|
615
|
+
this.interruptHandlers.add(handler);
|
|
616
|
+
return {
|
|
617
|
+
dispose: () => {
|
|
618
|
+
this.interruptHandlers.delete(handler);
|
|
619
|
+
if (this.interruptHandlers.size === 0) {
|
|
620
|
+
process__default.default.off("SIGINT", this.handleInterrupt);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
onTerminate(handler) {
|
|
626
|
+
if (this.terminateHandlers.size === 0) {
|
|
627
|
+
process__default.default.on("SIGTERM", this.handleTerminate);
|
|
628
|
+
}
|
|
629
|
+
this.terminateHandlers.add(handler);
|
|
630
|
+
return {
|
|
631
|
+
dispose: () => {
|
|
632
|
+
this.terminateHandlers.delete(handler);
|
|
633
|
+
if (this.terminateHandlers.size === 0) {
|
|
634
|
+
process__default.default.off("SIGTERM", this.handleTerminate);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
dispose() {
|
|
640
|
+
if (this.disposed) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
this.disposed = true;
|
|
644
|
+
process__default.default.off("SIGINT", this.handleInterrupt);
|
|
645
|
+
process__default.default.off("SIGTERM", this.handleTerminate);
|
|
646
|
+
this.interruptHandlers.clear();
|
|
647
|
+
this.terminateHandlers.clear();
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// src/bytes.ts
|
|
652
|
+
var encoder = new TextEncoder();
|
|
653
|
+
new TextDecoder("utf-8");
|
|
654
|
+
function encodeString(text) {
|
|
655
|
+
return encoder.encode(text);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/node/terminal.ts
|
|
659
|
+
var NodeTerminalAdapter = class {
|
|
660
|
+
constructor(input = process__default.default.stdin, output = process__default.default.stdout) {
|
|
661
|
+
this.input = input;
|
|
662
|
+
this.output = output;
|
|
663
|
+
}
|
|
664
|
+
rawModeEnabled = false;
|
|
665
|
+
inputHandlers = /* @__PURE__ */ new Set();
|
|
666
|
+
resizeHandlers = /* @__PURE__ */ new Set();
|
|
667
|
+
disposed = false;
|
|
668
|
+
handleData = (data) => {
|
|
669
|
+
const bytes = typeof data === "string" ? encodeString(data) : new Uint8Array(data);
|
|
670
|
+
for (const handler of this.inputHandlers) {
|
|
671
|
+
handler(bytes);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
handleResize = () => {
|
|
675
|
+
const size = this.getSize();
|
|
676
|
+
for (const handler of this.resizeHandlers) {
|
|
677
|
+
handler(size);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
onInput(handler) {
|
|
681
|
+
if (this.inputHandlers.size === 0) {
|
|
682
|
+
this.input.on("data", this.handleData);
|
|
683
|
+
this.input.resume();
|
|
684
|
+
}
|
|
685
|
+
this.inputHandlers.add(handler);
|
|
686
|
+
return {
|
|
687
|
+
dispose: () => {
|
|
688
|
+
this.inputHandlers.delete(handler);
|
|
689
|
+
if (this.inputHandlers.size === 0) {
|
|
690
|
+
this.input.off("data", this.handleData);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
onResize(handler) {
|
|
696
|
+
if (this.resizeHandlers.size === 0 && this.isWritableStream(this.output)) {
|
|
697
|
+
this.output.on("resize", this.handleResize);
|
|
698
|
+
}
|
|
699
|
+
this.resizeHandlers.add(handler);
|
|
700
|
+
return {
|
|
701
|
+
dispose: () => {
|
|
702
|
+
this.resizeHandlers.delete(handler);
|
|
703
|
+
if (this.resizeHandlers.size === 0 && this.isWritableStream(this.output)) {
|
|
704
|
+
this.output.off("resize", this.handleResize);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
write(data) {
|
|
710
|
+
if (data.length === 0) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
this.output.write(data);
|
|
714
|
+
}
|
|
715
|
+
getSize() {
|
|
716
|
+
const stream = this.output;
|
|
717
|
+
return {
|
|
718
|
+
columns: stream.columns ?? 80,
|
|
719
|
+
rows: stream.rows ?? 24
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
enableRawMode() {
|
|
723
|
+
const stream = this.input;
|
|
724
|
+
if (this.isTTY() && typeof stream.setRawMode === "function") {
|
|
725
|
+
stream.setRawMode(true);
|
|
726
|
+
stream.resume();
|
|
727
|
+
this.rawModeEnabled = true;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
disableRawMode() {
|
|
731
|
+
const stream = this.input;
|
|
732
|
+
if (this.rawModeEnabled && typeof stream.setRawMode === "function") {
|
|
733
|
+
stream.setRawMode(false);
|
|
734
|
+
stream.pause();
|
|
735
|
+
this.rawModeEnabled = false;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
isTTY() {
|
|
739
|
+
const stream = this.input;
|
|
740
|
+
return typeof stream.isTTY === "boolean" && stream.isTTY;
|
|
741
|
+
}
|
|
742
|
+
dispose() {
|
|
743
|
+
if (this.disposed) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this.disposed = true;
|
|
747
|
+
this.disableRawMode();
|
|
748
|
+
this.input.off("data", this.handleData);
|
|
749
|
+
if (this.isWritableStream(this.output)) {
|
|
750
|
+
this.output.off("resize", this.handleResize);
|
|
751
|
+
}
|
|
752
|
+
this.inputHandlers.clear();
|
|
753
|
+
this.resizeHandlers.clear();
|
|
754
|
+
}
|
|
755
|
+
isWritableStream(stream) {
|
|
756
|
+
return "on" in stream && typeof stream.on === "function";
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// src/node/index.ts
|
|
761
|
+
var NodePlatformAdapter = class {
|
|
762
|
+
terminal;
|
|
763
|
+
signals;
|
|
764
|
+
clipboard;
|
|
765
|
+
environment;
|
|
766
|
+
filesystem;
|
|
767
|
+
path;
|
|
768
|
+
archive;
|
|
769
|
+
style;
|
|
770
|
+
disposed = false;
|
|
771
|
+
disposables = [];
|
|
772
|
+
/**
|
|
773
|
+
* Create a new Node.js platform adapter.
|
|
774
|
+
* @param options - Configuration options
|
|
775
|
+
*/
|
|
776
|
+
constructor(options = {}) {
|
|
777
|
+
const terminalAdapter = new NodeTerminalAdapter(
|
|
778
|
+
options.input,
|
|
779
|
+
options.output
|
|
780
|
+
);
|
|
781
|
+
const signalAdapter = new NodeSignalAdapter();
|
|
782
|
+
const clipboardAdapter = new NodeClipboardAdapter();
|
|
783
|
+
const environmentAdapter = new NodeEnvironmentAdapter();
|
|
784
|
+
const filesystemAdapter = new NodeFileSystemAdapter();
|
|
785
|
+
const pathAdapter = new NodePathAdapter();
|
|
786
|
+
const archiveAdapter = new NodeArchiveAdapter();
|
|
787
|
+
const colorSupport = environmentAdapter.getColorSupport();
|
|
788
|
+
const styleAdapter = {
|
|
789
|
+
style: createStyle(colorSupport),
|
|
790
|
+
enabled: colorSupport.level > 0,
|
|
791
|
+
level: colorSupport.level
|
|
792
|
+
};
|
|
793
|
+
this.terminal = terminalAdapter;
|
|
794
|
+
this.signals = signalAdapter;
|
|
795
|
+
this.clipboard = clipboardAdapter;
|
|
796
|
+
this.environment = environmentAdapter;
|
|
797
|
+
this.filesystem = filesystemAdapter;
|
|
798
|
+
this.path = pathAdapter;
|
|
799
|
+
this.archive = archiveAdapter;
|
|
800
|
+
this.style = styleAdapter;
|
|
801
|
+
this.disposables.push(terminalAdapter, signalAdapter);
|
|
802
|
+
}
|
|
803
|
+
dispose() {
|
|
804
|
+
if (this.disposed) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this.disposed = true;
|
|
808
|
+
for (const disposable of this.disposables) {
|
|
809
|
+
disposable.dispose();
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
function createNodePlatform(options = {}) {
|
|
814
|
+
return new NodePlatformAdapter(options);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
exports.NodeArchiveAdapter = NodeArchiveAdapter;
|
|
818
|
+
exports.NodeClipboardAdapter = NodeClipboardAdapter;
|
|
819
|
+
exports.NodeEnvironmentAdapter = NodeEnvironmentAdapter;
|
|
820
|
+
exports.NodeFileSystemAdapter = NodeFileSystemAdapter;
|
|
821
|
+
exports.NodePathAdapter = NodePathAdapter;
|
|
822
|
+
exports.NodePlatformAdapter = NodePlatformAdapter;
|
|
823
|
+
exports.NodeSignalAdapter = NodeSignalAdapter;
|
|
824
|
+
exports.NodeTerminalAdapter = NodeTerminalAdapter;
|
|
825
|
+
exports.createNodePlatform = createNodePlatform;
|
|
826
|
+
//# sourceMappingURL=index.cjs.map
|
|
827
|
+
//# sourceMappingURL=index.cjs.map
|