main
1"use strict";
2const {
3 __spreadValues,
4 __spreadProps,
5 __export,
6 __toESM,
7 __toCommonJS
8} = require('./esblib.cjs');
9
10
11// src/util.ts
12var util_exports = {};
13__export(util_exports, {
14 bufArrJoin: () => bufArrJoin,
15 bufToString: () => bufToString,
16 getLast: () => getLast,
17 getLines: () => getLines,
18 identity: () => identity,
19 isString: () => isString,
20 isStringLiteral: () => import_vendor_core.isStringLiteral,
21 iteratorToArray: () => iteratorToArray,
22 noop: () => noop,
23 once: () => once,
24 parseBool: () => parseBool,
25 parseDuration: () => parseDuration,
26 preferLocalBin: () => preferLocalBin,
27 proxyOverride: () => proxyOverride,
28 quote: () => quote,
29 quotePowerShell: () => quotePowerShell,
30 randomId: () => randomId,
31 toCamelCase: () => toCamelCase
32});
33module.exports = __toCommonJS(util_exports);
34var import_node_path = __toESM(require("path"), 1);
35var import_node_process = __toESM(require("process"), 1);
36var import_vendor_core = require("./vendor-core.cjs");
37function noop() {
38}
39function identity(v) {
40 return v;
41}
42function randomId() {
43 return Math.random().toString(36).slice(2);
44}
45function isString(obj) {
46 return typeof obj === "string";
47}
48var utf8Decoder = new TextDecoder("utf-8");
49var bufToString = (buf) => isString(buf) ? buf : utf8Decoder.decode(buf);
50var bufArrJoin = (arr) => arr.reduce((acc, buf) => acc + bufToString(buf), "");
51var getLast = (arr) => arr[arr.length - 1];
52function preferLocalBin(env, ...dirs) {
53 const pathKey = import_node_process.default.platform === "win32" ? Object.keys(env).reverse().find((key) => key.toUpperCase() === "PATH") || "Path" : "PATH";
54 const pathValue = dirs.map(
55 (c) => c && [
56 import_node_path.default.resolve(c, "node_modules", ".bin"),
57 import_node_path.default.resolve(c)
58 ]
59 ).flat().concat(env[pathKey]).filter(Boolean).join(import_node_path.default.delimiter);
60 return __spreadProps(__spreadValues({}, env), {
61 [pathKey]: pathValue
62 });
63}
64function quote(arg) {
65 if (arg === "") return `$''`;
66 if (/^[\w/.\-@:=]+$/.test(arg)) return arg;
67 return `$'` + arg.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\f/g, "\\f").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/\v/g, "\\v").replace(/\0/g, "\\0") + `'`;
68}
69function quotePowerShell(arg) {
70 if (arg === "") return `''`;
71 if (/^[\w/.\-]+$/.test(arg)) return arg;
72 return `'` + arg.replace(/'/g, "''") + `'`;
73}
74function parseDuration(d) {
75 if (typeof d === "number") {
76 if (isNaN(d) || d < 0) throw new Error(`Invalid duration: "${d}".`);
77 return d;
78 }
79 const [m, v, u] = d.match(/^(\d+)(m?s?)$/) || [];
80 if (!m) throw new Error(`Unknown duration: "${d}".`);
81 return +v * ({ s: 1e3, ms: 1, m: 6e4 }[u] || 1);
82}
83var once = (fn) => {
84 let called = false;
85 let result;
86 return (...args) => called ? result : (called = true, result = fn(...args));
87};
88var proxyOverride = (origin, ...fallbacks) => new Proxy(origin, {
89 get(target, key) {
90 var _a, _b;
91 return (_b = (_a = fallbacks.find((f) => key in f)) == null ? void 0 : _a[key]) != null ? _b : Reflect.get(target, key);
92 }
93});
94var toCamelCase = (str) => str.toLowerCase().replace(/([a-z])[_-]+([a-z])/g, (_, p1, p2) => p1 + p2.toUpperCase());
95var parseBool = (v) => v === "true" || v !== "false" && v;
96var getLines = (chunk, next, delimiter) => {
97 const lines = ((next.pop() || "") + bufToString(chunk)).split(delimiter);
98 next.push(lines.pop());
99 return lines;
100};
101var iteratorToArray = (it) => {
102 const arr = [];
103 let entry;
104 while (!(entry = it.next()).done) arr.push(entry.value);
105 return arr;
106};
107/* c8 ignore next 100 */
108// Annotate the CommonJS export names for ESM import in node:
1090 && (module.exports = {
110 bufArrJoin,
111 bufToString,
112 getLast,
113 getLines,
114 identity,
115 isString,
116 isStringLiteral,
117 iteratorToArray,
118 noop,
119 once,
120 parseBool,
121 parseDuration,
122 preferLocalBin,
123 proxyOverride,
124 quote,
125 quotePowerShell,
126 randomId,
127 toCamelCase
128});