@vlandoss/clibuddy 0.0.6 → 0.0.7-git-bbfb0f7.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/package.json +5 -13
- package/dist/index.cjs +0 -241
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -60
- package/dist/index.d.ts +0 -60
- package/dist/index.js +0 -194
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vlandoss/clibuddy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-git-bbfb0f7.0",
|
|
4
4
|
"description": "A helper library to create CLIs in Variable Land",
|
|
5
5
|
"homepage": "https://github.com/variableland/dx/tree/main/packages/clibuddy#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -14,26 +14,18 @@
|
|
|
14
14
|
"author": "rcrd <rcrd@variable.land>",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
"bun": "./src/index.ts",
|
|
19
|
-
"import": "./dist/index.js",
|
|
20
|
-
"require": "./dist/index.cjs",
|
|
21
|
-
"default": "./dist/index.js"
|
|
22
|
-
},
|
|
17
|
+
".": "./src/index.ts",
|
|
23
18
|
"./test-helpers": {
|
|
24
19
|
"bun": "./test-helpers/index.ts"
|
|
25
20
|
}
|
|
26
21
|
},
|
|
27
|
-
"main": "./dist/index.cjs",
|
|
28
|
-
"module": "./dist/index.js",
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
22
|
"files": [
|
|
31
23
|
"dist",
|
|
32
24
|
"src"
|
|
33
25
|
],
|
|
34
26
|
"dependencies": {
|
|
35
|
-
"@pnpm/workspace.find-packages": "^1000.0.
|
|
36
|
-
"@pnpm/workspace.read-manifest": "^1000.
|
|
27
|
+
"@pnpm/workspace.find-packages": "^1000.0.62",
|
|
28
|
+
"@pnpm/workspace.read-manifest": "^1000.2.10",
|
|
37
29
|
"chalk": "5.4.1",
|
|
38
30
|
"read-package-up": "11.0.0",
|
|
39
31
|
"supports-color": "10.0.0",
|
|
@@ -46,6 +38,6 @@
|
|
|
46
38
|
"bun": ">=1.0.0"
|
|
47
39
|
},
|
|
48
40
|
"scripts": {
|
|
49
|
-
"
|
|
41
|
+
"test:types": "rr tsc"
|
|
50
42
|
}
|
|
51
43
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
PkgService: () => PkgService,
|
|
34
|
-
ShellService: () => ShellService,
|
|
35
|
-
colors: () => colors,
|
|
36
|
-
createPkgService: () => createPkgService,
|
|
37
|
-
createShellService: () => createShellService,
|
|
38
|
-
cwd: () => cwd,
|
|
39
|
-
getPreferLocal: () => getPreferLocal,
|
|
40
|
-
getVersion: () => getVersion,
|
|
41
|
-
isProcessOutput: () => isProcessOutput,
|
|
42
|
-
isRaw: () => isRaw,
|
|
43
|
-
quote: () => quote
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
|
|
47
|
-
// src/colors.ts
|
|
48
|
-
var import_chalk = __toESM(require("chalk"), 1);
|
|
49
|
-
var import_supports_color = __toESM(require("supports-color"), 1);
|
|
50
|
-
var colorIsSupported = () => import_supports_color.default.stdout && !process.env.NO_COLOR;
|
|
51
|
-
var identity = (x) => x;
|
|
52
|
-
var safe = (style) => colorIsSupported() ? style : identity;
|
|
53
|
-
var colors = {
|
|
54
|
-
blueBright: safe(import_chalk.default.blueBright),
|
|
55
|
-
redBright: safe(import_chalk.default.redBright),
|
|
56
|
-
greenBright: safe(import_chalk.default.greenBright),
|
|
57
|
-
bold: safe(import_chalk.default.bold),
|
|
58
|
-
muted: safe(import_chalk.default.dim),
|
|
59
|
-
link: safe(import_chalk.default.underline)
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/services/pkg.ts
|
|
63
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
64
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
65
|
-
var import_workspace = require("@pnpm/workspace.find-packages");
|
|
66
|
-
var import_workspace2 = require("@pnpm/workspace.read-manifest");
|
|
67
|
-
var import_read_package_up = require("read-package-up");
|
|
68
|
-
var PkgService = class {
|
|
69
|
-
#packageJson;
|
|
70
|
-
#dirPath;
|
|
71
|
-
get dirPath() {
|
|
72
|
-
return this.#dirPath;
|
|
73
|
-
}
|
|
74
|
-
get packageJson() {
|
|
75
|
-
return this.#packageJson;
|
|
76
|
-
}
|
|
77
|
-
constructor(packageJson, pkgPath) {
|
|
78
|
-
this.#packageJson = packageJson;
|
|
79
|
-
this.#dirPath = import_node_path.default.dirname(pkgPath);
|
|
80
|
-
}
|
|
81
|
-
info() {
|
|
82
|
-
return {
|
|
83
|
-
packageJson: this.#packageJson,
|
|
84
|
-
dirPath: this.#dirPath
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
hasFile(name, dir) {
|
|
88
|
-
const filepath = dir ? import_node_path.default.join(dir, name) : this.#fromApp(name);
|
|
89
|
-
return import_node_fs.default.existsSync(filepath);
|
|
90
|
-
}
|
|
91
|
-
isMonorepo() {
|
|
92
|
-
return this.#packageJson.workspaces !== void 0 || this.#hasPnpmWorkspace();
|
|
93
|
-
}
|
|
94
|
-
async getWorkspaceProjects() {
|
|
95
|
-
let patterns;
|
|
96
|
-
if (this.#hasPnpmWorkspace()) {
|
|
97
|
-
const manifest = await (0, import_workspace2.readWorkspaceManifest)(this.#dirPath);
|
|
98
|
-
if (!manifest) {
|
|
99
|
-
throw new Error("Can't read pnpm workspace manifest");
|
|
100
|
-
}
|
|
101
|
-
patterns = manifest.packages;
|
|
102
|
-
} else {
|
|
103
|
-
patterns = Array.isArray(this.#packageJson.workspaces) ? this.#packageJson.workspaces : this.#packageJson.workspaces?.packages ?? [];
|
|
104
|
-
}
|
|
105
|
-
if (!Array.isArray(patterns) || patterns.some((p) => typeof p !== "string")) {
|
|
106
|
-
throw new Error("Invalid workspace patterns");
|
|
107
|
-
}
|
|
108
|
-
const projects = await (0, import_workspace.findWorkspacePackages)(this.#dirPath, {
|
|
109
|
-
patterns
|
|
110
|
-
});
|
|
111
|
-
const excludeRoot = (projects2) => {
|
|
112
|
-
return projects2.filter((project) => project.rootDir !== this.#dirPath);
|
|
113
|
-
};
|
|
114
|
-
return excludeRoot(projects);
|
|
115
|
-
}
|
|
116
|
-
#hasPnpmWorkspace() {
|
|
117
|
-
return this.hasFile("pnpm-workspace.yaml");
|
|
118
|
-
}
|
|
119
|
-
#fromApp(...args) {
|
|
120
|
-
return import_node_path.default.join(this.#dirPath, ...args);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
async function createPkgService(cwd2) {
|
|
124
|
-
const searchResult = await (0, import_read_package_up.readPackageUp)({ cwd: cwd2 });
|
|
125
|
-
if (!searchResult) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const { packageJson, path: path3 } = searchResult;
|
|
129
|
-
return new PkgService(packageJson, path3);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// src/services/shell/create.ts
|
|
133
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
134
|
-
|
|
135
|
-
// src/services/shell/shell.ts
|
|
136
|
-
var import_zx2 = require("zx");
|
|
137
|
-
|
|
138
|
-
// src/services/shell/utils.ts
|
|
139
|
-
var import_node_path2 = __toESM(require("path"), 1);
|
|
140
|
-
var import_zx = require("zx");
|
|
141
|
-
function isProcessOutput(value) {
|
|
142
|
-
return value instanceof import_zx.ProcessOutput;
|
|
143
|
-
}
|
|
144
|
-
var getLocalBinPath = (dirPath) => import_node_path2.default.join(dirPath, "node_modules", ".bin");
|
|
145
|
-
function getPreferLocal(localBaseBinPath) {
|
|
146
|
-
return !localBaseBinPath ? void 0 : Array.isArray(localBaseBinPath) ? localBaseBinPath.map(getLocalBinPath) : [localBaseBinPath].map(getLocalBinPath);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// src/services/shell/shell.ts
|
|
150
|
-
var ShellService = class _ShellService {
|
|
151
|
-
#shell;
|
|
152
|
-
#options;
|
|
153
|
-
constructor(options) {
|
|
154
|
-
this.#options = Object.freeze(options);
|
|
155
|
-
this.#shell = (0, import_zx2.$)(options);
|
|
156
|
-
}
|
|
157
|
-
get options() {
|
|
158
|
-
return this.#options;
|
|
159
|
-
}
|
|
160
|
-
get $() {
|
|
161
|
-
return this.#shell;
|
|
162
|
-
}
|
|
163
|
-
child(options) {
|
|
164
|
-
return new _ShellService({
|
|
165
|
-
...this.#options,
|
|
166
|
-
...options
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
quiet(options) {
|
|
170
|
-
return this.child({
|
|
171
|
-
...options,
|
|
172
|
-
verbose: false
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
at(cwd2, options) {
|
|
176
|
-
const getLocals = (locals) => (
|
|
177
|
-
// NOTE: the boolean handling is done outside when determining preferLocal
|
|
178
|
-
typeof locals === "boolean" ? [] : typeof locals === "undefined" ? [] : Array.isArray(locals) ? locals : [locals]
|
|
179
|
-
);
|
|
180
|
-
const cwdPreferLocal = getPreferLocal(cwd2);
|
|
181
|
-
const preferLocal = options?.preferLocal === false ? false : [
|
|
182
|
-
...getLocals(this.#options.preferLocal),
|
|
183
|
-
...getLocals(options?.preferLocal),
|
|
184
|
-
...cwdPreferLocal ? cwdPreferLocal : []
|
|
185
|
-
];
|
|
186
|
-
return this.child({
|
|
187
|
-
...options,
|
|
188
|
-
cwd: cwd2,
|
|
189
|
-
preferLocal
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// src/services/shell/create.ts
|
|
195
|
-
var cwd = import_node_fs2.default.realpathSync(process.cwd());
|
|
196
|
-
function quote(arg) {
|
|
197
|
-
if (/^[\w./:=@-]+$/i.test(arg) || arg === "") {
|
|
198
|
-
return arg;
|
|
199
|
-
}
|
|
200
|
-
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");
|
|
201
|
-
}
|
|
202
|
-
var isRaw = (arg) => typeof arg === "object" && arg !== null && "stdout" in arg && typeof arg.stdout === "string";
|
|
203
|
-
function defaultQuote(arg) {
|
|
204
|
-
if (typeof arg === "string") {
|
|
205
|
-
return quote(arg);
|
|
206
|
-
}
|
|
207
|
-
if (isRaw(arg)) {
|
|
208
|
-
return arg.stdout;
|
|
209
|
-
}
|
|
210
|
-
throw TypeError(`Unsupported argument type: ${typeof arg}`);
|
|
211
|
-
}
|
|
212
|
-
function createShellService(options = {}) {
|
|
213
|
-
const preferLocal = getPreferLocal(options.localBaseBinPath);
|
|
214
|
-
return new ShellService({
|
|
215
|
-
verbose: true,
|
|
216
|
-
cwd,
|
|
217
|
-
preferLocal,
|
|
218
|
-
quote: defaultQuote,
|
|
219
|
-
...options
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/version.ts
|
|
224
|
-
function getVersion(pkg) {
|
|
225
|
-
return process.env.VERSION || pkg.packageJson.version;
|
|
226
|
-
}
|
|
227
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
-
0 && (module.exports = {
|
|
229
|
-
PkgService,
|
|
230
|
-
ShellService,
|
|
231
|
-
colors,
|
|
232
|
-
createPkgService,
|
|
233
|
-
createShellService,
|
|
234
|
-
cwd,
|
|
235
|
-
getPreferLocal,
|
|
236
|
-
getVersion,
|
|
237
|
-
isProcessOutput,
|
|
238
|
-
isRaw,
|
|
239
|
-
quote
|
|
240
|
-
});
|
|
241
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/colors.ts","../src/services/pkg.ts","../src/services/shell/create.ts","../src/services/shell/shell.ts","../src/services/shell/utils.ts","../src/version.ts"],"sourcesContent":["export * from \"./colors\";\nexport * from \"./services\";\nexport * from \"./version\";\n","import chalk, { type ChalkInstance } from \"chalk\";\nimport supportsColor from \"supports-color\";\n\n// https://no-color.org/\nconst colorIsSupported = () => supportsColor.stdout && !process.env.NO_COLOR;\n\nconst identity = <T>(x: T) => x;\nconst safe = (style: ChalkInstance) => (colorIsSupported() ? style : identity);\n\nexport const colors = {\n blueBright: safe(chalk.blueBright),\n redBright: safe(chalk.redBright),\n greenBright: safe(chalk.greenBright),\n bold: safe(chalk.bold),\n muted: safe(chalk.dim),\n link: safe(chalk.underline),\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { findWorkspacePackages, type Project } from \"@pnpm/workspace.find-packages\";\nimport { readWorkspaceManifest } from \"@pnpm/workspace.read-manifest\";\nimport { type NormalizedPackageJson, readPackageUp } from \"read-package-up\";\n\nexport type { Project };\n\nexport class PkgService {\n #packageJson: NormalizedPackageJson;\n #dirPath: string;\n\n get dirPath() {\n return this.#dirPath;\n }\n\n get packageJson() {\n return this.#packageJson;\n }\n\n constructor(packageJson: NormalizedPackageJson, pkgPath: string) {\n this.#packageJson = packageJson;\n this.#dirPath = path.dirname(pkgPath);\n }\n\n info() {\n return {\n packageJson: this.#packageJson,\n dirPath: this.#dirPath,\n };\n }\n\n hasFile(name: string, dir?: string) {\n const filepath = dir ? path.join(dir, name) : this.#fromApp(name);\n return fs.existsSync(filepath);\n }\n\n isMonorepo() {\n return this.#packageJson.workspaces !== undefined || this.#hasPnpmWorkspace();\n }\n\n async getWorkspaceProjects() {\n let patterns: string[];\n\n if (this.#hasPnpmWorkspace()) {\n const manifest = await readWorkspaceManifest(this.#dirPath);\n\n if (!manifest) {\n throw new Error(\"Can't read pnpm workspace manifest\");\n }\n\n patterns = manifest.packages;\n } else {\n patterns = Array.isArray(this.#packageJson.workspaces)\n ? this.#packageJson.workspaces\n : (this.#packageJson.workspaces?.packages ?? []);\n }\n\n if (!Array.isArray(patterns) || patterns.some((p) => typeof p !== \"string\")) {\n throw new Error(\"Invalid workspace patterns\");\n }\n\n const projects = await findWorkspacePackages(this.#dirPath, {\n patterns,\n });\n\n const excludeRoot = (projects: Project[]) => {\n return projects.filter((project) => project.rootDir !== this.#dirPath);\n };\n\n return excludeRoot(projects);\n }\n\n #hasPnpmWorkspace() {\n return this.hasFile(\"pnpm-workspace.yaml\");\n }\n\n #fromApp(...args: string[]) {\n return path.join(this.#dirPath, ...args);\n }\n}\n\nexport async function createPkgService(cwd: string): Promise<PkgService | null> {\n const searchResult = await readPackageUp({ cwd });\n\n if (!searchResult) {\n return null;\n }\n\n const { packageJson, path } = searchResult;\n\n return new PkgService(packageJson, path);\n}\n","import fs from \"node:fs\";\nimport { ShellService } from \"./shell\";\nimport type { CreateOptions } from \"./types\";\nimport { getPreferLocal } from \"./utils\";\n\nexport const cwd = fs.realpathSync(process.cwd());\n\n// Inspired by https://dub.sh/6tiHVgn\nexport function quote(arg: string) {\n if (/^[\\w./:=@-]+$/i.test(arg) || arg === \"\") {\n return arg;\n }\n\n return arg\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/'/g, \"\\\\'\")\n .replace(/\\f/g, \"\\\\f\")\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\")\n .replace(/\\v/g, \"\\\\v\")\n .replace(/\\0/g, \"\\\\0\");\n}\n\nexport const isRaw = (arg: unknown): arg is { stdout: string } =>\n typeof arg === \"object\" && arg !== null && \"stdout\" in arg && typeof arg.stdout === \"string\";\n\nfunction defaultQuote(arg: unknown) {\n if (typeof arg === \"string\") {\n return quote(arg);\n }\n\n if (isRaw(arg)) {\n return arg.stdout;\n }\n\n throw TypeError(`Unsupported argument type: ${typeof arg}`);\n}\n\nexport function createShellService(options: CreateOptions = {}) {\n const preferLocal = getPreferLocal(options.localBaseBinPath);\n\n return new ShellService({\n verbose: true,\n cwd,\n preferLocal,\n quote: defaultQuote,\n ...options,\n });\n}\n","import { $ as make$ } from \"zx\";\nimport type { Shell, ShellOptions } from \"./types\";\nimport { getPreferLocal } from \"./utils\";\n\nexport class ShellService {\n #shell: Shell;\n #options: ShellOptions;\n\n constructor(options: ShellOptions) {\n this.#options = Object.freeze(options);\n this.#shell = make$(options);\n }\n\n get options() {\n return this.#options;\n }\n\n get $() {\n return this.#shell;\n }\n\n child(options: ShellOptions) {\n return new ShellService({\n ...this.#options,\n ...options,\n });\n }\n\n quiet(options?: ShellOptions) {\n return this.child({\n ...options,\n verbose: false,\n });\n }\n\n at(cwd: string, options?: ShellOptions) {\n const getLocals = (locals: boolean | string | string[] | undefined) =>\n // NOTE: the boolean handling is done outside when determining preferLocal\n typeof locals === \"boolean\" ? [] : typeof locals === \"undefined\" ? [] : Array.isArray(locals) ? locals : [locals];\n\n const cwdPreferLocal = getPreferLocal(cwd);\n\n const preferLocal =\n options?.preferLocal === false\n ? false\n : [\n ...getLocals(this.#options.preferLocal),\n ...getLocals(options?.preferLocal),\n ...(cwdPreferLocal ? cwdPreferLocal : []),\n ];\n\n return this.child({\n ...options,\n cwd,\n preferLocal,\n });\n }\n}\n","import path from \"node:path\";\nimport { ProcessOutput } from \"zx\";\n\nexport function isProcessOutput(value: unknown): value is ProcessOutput {\n return value instanceof ProcessOutput;\n}\n\nconst getLocalBinPath = (dirPath: string) => path.join(dirPath, \"node_modules\", \".bin\");\n\nexport function getPreferLocal(localBaseBinPath: string | Array<string> | undefined) {\n return !localBaseBinPath\n ? undefined\n : Array.isArray(localBaseBinPath)\n ? localBaseBinPath.map(getLocalBinPath)\n : [localBaseBinPath].map(getLocalBinPath);\n}\n","import type { PkgService } from \"./services\";\n\nexport function getVersion(pkg: PkgService) {\n return process.env.VERSION || pkg.packageJson.version;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0C;AAC1C,4BAA0B;AAG1B,IAAM,mBAAmB,MAAM,sBAAAA,QAAc,UAAU,CAAC,QAAQ,IAAI;AAEpE,IA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OAAO,MAAM,EACrB,QAAQ,MAAM,KAAK,EACnB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK;AACzB;AAEO,IAAM,QAAQ,CAAC,QACpB,OAAO,QAAQ,YAAY,QAAQ,QAAQ,YAAY,OAAO,OAAO,IAAI,WAAW;AAEtF,SAAS,aAAa,KAAc;AAClC,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,MAAM,GAAG;AAAA,EAClB;AAEA,MAAI,MAAM,GAAG,GAAG;AACd,WAAO,IAAI;AAAA,EACb;AAEA,QAAM,UAAU,8BAA8B,OAAO,GAAG,EAAE;AAC5D;AAEO,SAAS,mBAAmB,UAAyB,CAAC,GAAG;AAC9D,QAAM,cAAc,eAAe,QAAQ,gBAAgB;AAE3D,SAAO,IAAI,aAAa;AAAA,IACtB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,GAAG;AAAA,EACL,CAAC;AACH;;;AG/CO,SAAS,WAAW,KAAiB;AAC1C,SAAO,QAAQ,IAAI,WAAW,IAAI,YAAY;AAChD;","names":["supportsColor","chalk","import_workspace","path","fs","projects","cwd","import_node_fs","import_zx","import_node_path","path","make$","cwd","fs"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ChalkInstance } from 'chalk';
|
|
2
|
-
import { Project } from '@pnpm/workspace.find-packages';
|
|
3
|
-
export { Project } from '@pnpm/workspace.find-packages';
|
|
4
|
-
import { NormalizedPackageJson } from 'read-package-up';
|
|
5
|
-
import * as zx from 'zx';
|
|
6
|
-
import { Options, Shell as Shell$1, ProcessOutput } from 'zx';
|
|
7
|
-
|
|
8
|
-
declare const colors: {
|
|
9
|
-
blueBright: (<T>(x: T) => T) | ChalkInstance;
|
|
10
|
-
redBright: (<T>(x: T) => T) | ChalkInstance;
|
|
11
|
-
greenBright: (<T>(x: T) => T) | ChalkInstance;
|
|
12
|
-
bold: (<T>(x: T) => T) | ChalkInstance;
|
|
13
|
-
muted: (<T>(x: T) => T) | ChalkInstance;
|
|
14
|
-
link: (<T>(x: T) => T) | ChalkInstance;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
declare class PkgService {
|
|
18
|
-
#private;
|
|
19
|
-
get dirPath(): string;
|
|
20
|
-
get packageJson(): NormalizedPackageJson;
|
|
21
|
-
constructor(packageJson: NormalizedPackageJson, pkgPath: string);
|
|
22
|
-
info(): {
|
|
23
|
-
packageJson: NormalizedPackageJson;
|
|
24
|
-
dirPath: string;
|
|
25
|
-
};
|
|
26
|
-
hasFile(name: string, dir?: string): boolean;
|
|
27
|
-
isMonorepo(): boolean;
|
|
28
|
-
getWorkspaceProjects(): Promise<Project[]>;
|
|
29
|
-
}
|
|
30
|
-
declare function createPkgService(cwd: string): Promise<PkgService | null>;
|
|
31
|
-
|
|
32
|
-
type Shell = Shell$1;
|
|
33
|
-
type ShellOptions = Partial<Options>;
|
|
34
|
-
type CreateOptions = ShellOptions & {
|
|
35
|
-
localBaseBinPath?: string | Array<string>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
declare class ShellService {
|
|
39
|
-
#private;
|
|
40
|
-
constructor(options: ShellOptions);
|
|
41
|
-
get options(): Partial<zx.Options>;
|
|
42
|
-
get $(): Shell;
|
|
43
|
-
child(options: ShellOptions): ShellService;
|
|
44
|
-
quiet(options?: ShellOptions): ShellService;
|
|
45
|
-
at(cwd: string, options?: ShellOptions): ShellService;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare const cwd: string;
|
|
49
|
-
declare function quote(arg: string): string;
|
|
50
|
-
declare const isRaw: (arg: unknown) => arg is {
|
|
51
|
-
stdout: string;
|
|
52
|
-
};
|
|
53
|
-
declare function createShellService(options?: CreateOptions): ShellService;
|
|
54
|
-
|
|
55
|
-
declare function isProcessOutput(value: unknown): value is ProcessOutput;
|
|
56
|
-
declare function getPreferLocal(localBaseBinPath: string | Array<string> | undefined): string[] | undefined;
|
|
57
|
-
|
|
58
|
-
declare function getVersion(pkg: PkgService): string;
|
|
59
|
-
|
|
60
|
-
export { type CreateOptions, PkgService, type Shell, type ShellOptions, ShellService, colors, createPkgService, createShellService, cwd, getPreferLocal, getVersion, isProcessOutput, isRaw, quote };
|
package/dist/index.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ChalkInstance } from 'chalk';
|
|
2
|
-
import { Project } from '@pnpm/workspace.find-packages';
|
|
3
|
-
export { Project } from '@pnpm/workspace.find-packages';
|
|
4
|
-
import { NormalizedPackageJson } from 'read-package-up';
|
|
5
|
-
import * as zx from 'zx';
|
|
6
|
-
import { Options, Shell as Shell$1, ProcessOutput } from 'zx';
|
|
7
|
-
|
|
8
|
-
declare const colors: {
|
|
9
|
-
blueBright: (<T>(x: T) => T) | ChalkInstance;
|
|
10
|
-
redBright: (<T>(x: T) => T) | ChalkInstance;
|
|
11
|
-
greenBright: (<T>(x: T) => T) | ChalkInstance;
|
|
12
|
-
bold: (<T>(x: T) => T) | ChalkInstance;
|
|
13
|
-
muted: (<T>(x: T) => T) | ChalkInstance;
|
|
14
|
-
link: (<T>(x: T) => T) | ChalkInstance;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
declare class PkgService {
|
|
18
|
-
#private;
|
|
19
|
-
get dirPath(): string;
|
|
20
|
-
get packageJson(): NormalizedPackageJson;
|
|
21
|
-
constructor(packageJson: NormalizedPackageJson, pkgPath: string);
|
|
22
|
-
info(): {
|
|
23
|
-
packageJson: NormalizedPackageJson;
|
|
24
|
-
dirPath: string;
|
|
25
|
-
};
|
|
26
|
-
hasFile(name: string, dir?: string): boolean;
|
|
27
|
-
isMonorepo(): boolean;
|
|
28
|
-
getWorkspaceProjects(): Promise<Project[]>;
|
|
29
|
-
}
|
|
30
|
-
declare function createPkgService(cwd: string): Promise<PkgService | null>;
|
|
31
|
-
|
|
32
|
-
type Shell = Shell$1;
|
|
33
|
-
type ShellOptions = Partial<Options>;
|
|
34
|
-
type CreateOptions = ShellOptions & {
|
|
35
|
-
localBaseBinPath?: string | Array<string>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
declare class ShellService {
|
|
39
|
-
#private;
|
|
40
|
-
constructor(options: ShellOptions);
|
|
41
|
-
get options(): Partial<zx.Options>;
|
|
42
|
-
get $(): Shell;
|
|
43
|
-
child(options: ShellOptions): ShellService;
|
|
44
|
-
quiet(options?: ShellOptions): ShellService;
|
|
45
|
-
at(cwd: string, options?: ShellOptions): ShellService;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare const cwd: string;
|
|
49
|
-
declare function quote(arg: string): string;
|
|
50
|
-
declare const isRaw: (arg: unknown) => arg is {
|
|
51
|
-
stdout: string;
|
|
52
|
-
};
|
|
53
|
-
declare function createShellService(options?: CreateOptions): ShellService;
|
|
54
|
-
|
|
55
|
-
declare function isProcessOutput(value: unknown): value is ProcessOutput;
|
|
56
|
-
declare function getPreferLocal(localBaseBinPath: string | Array<string> | undefined): string[] | undefined;
|
|
57
|
-
|
|
58
|
-
declare function getVersion(pkg: PkgService): string;
|
|
59
|
-
|
|
60
|
-
export { type CreateOptions, PkgService, type Shell, type ShellOptions, ShellService, colors, createPkgService, createShellService, cwd, getPreferLocal, getVersion, isProcessOutput, isRaw, quote };
|
package/dist/index.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// src/colors.ts
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import supportsColor from "supports-color";
|
|
4
|
-
var colorIsSupported = () => supportsColor.stdout && !process.env.NO_COLOR;
|
|
5
|
-
var identity = (x) => x;
|
|
6
|
-
var safe = (style) => colorIsSupported() ? style : identity;
|
|
7
|
-
var colors = {
|
|
8
|
-
blueBright: safe(chalk.blueBright),
|
|
9
|
-
redBright: safe(chalk.redBright),
|
|
10
|
-
greenBright: safe(chalk.greenBright),
|
|
11
|
-
bold: safe(chalk.bold),
|
|
12
|
-
muted: safe(chalk.dim),
|
|
13
|
-
link: safe(chalk.underline)
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/services/pkg.ts
|
|
17
|
-
import fs from "fs";
|
|
18
|
-
import path from "path";
|
|
19
|
-
import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
|
|
20
|
-
import { readWorkspaceManifest } from "@pnpm/workspace.read-manifest";
|
|
21
|
-
import { readPackageUp } from "read-package-up";
|
|
22
|
-
var PkgService = class {
|
|
23
|
-
#packageJson;
|
|
24
|
-
#dirPath;
|
|
25
|
-
get dirPath() {
|
|
26
|
-
return this.#dirPath;
|
|
27
|
-
}
|
|
28
|
-
get packageJson() {
|
|
29
|
-
return this.#packageJson;
|
|
30
|
-
}
|
|
31
|
-
constructor(packageJson, pkgPath) {
|
|
32
|
-
this.#packageJson = packageJson;
|
|
33
|
-
this.#dirPath = path.dirname(pkgPath);
|
|
34
|
-
}
|
|
35
|
-
info() {
|
|
36
|
-
return {
|
|
37
|
-
packageJson: this.#packageJson,
|
|
38
|
-
dirPath: this.#dirPath
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
hasFile(name, dir) {
|
|
42
|
-
const filepath = dir ? path.join(dir, name) : this.#fromApp(name);
|
|
43
|
-
return fs.existsSync(filepath);
|
|
44
|
-
}
|
|
45
|
-
isMonorepo() {
|
|
46
|
-
return this.#packageJson.workspaces !== void 0 || this.#hasPnpmWorkspace();
|
|
47
|
-
}
|
|
48
|
-
async getWorkspaceProjects() {
|
|
49
|
-
let patterns;
|
|
50
|
-
if (this.#hasPnpmWorkspace()) {
|
|
51
|
-
const manifest = await readWorkspaceManifest(this.#dirPath);
|
|
52
|
-
if (!manifest) {
|
|
53
|
-
throw new Error("Can't read pnpm workspace manifest");
|
|
54
|
-
}
|
|
55
|
-
patterns = manifest.packages;
|
|
56
|
-
} else {
|
|
57
|
-
patterns = Array.isArray(this.#packageJson.workspaces) ? this.#packageJson.workspaces : this.#packageJson.workspaces?.packages ?? [];
|
|
58
|
-
}
|
|
59
|
-
if (!Array.isArray(patterns) || patterns.some((p) => typeof p !== "string")) {
|
|
60
|
-
throw new Error("Invalid workspace patterns");
|
|
61
|
-
}
|
|
62
|
-
const projects = await findWorkspacePackages(this.#dirPath, {
|
|
63
|
-
patterns
|
|
64
|
-
});
|
|
65
|
-
const excludeRoot = (projects2) => {
|
|
66
|
-
return projects2.filter((project) => project.rootDir !== this.#dirPath);
|
|
67
|
-
};
|
|
68
|
-
return excludeRoot(projects);
|
|
69
|
-
}
|
|
70
|
-
#hasPnpmWorkspace() {
|
|
71
|
-
return this.hasFile("pnpm-workspace.yaml");
|
|
72
|
-
}
|
|
73
|
-
#fromApp(...args) {
|
|
74
|
-
return path.join(this.#dirPath, ...args);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
async function createPkgService(cwd2) {
|
|
78
|
-
const searchResult = await readPackageUp({ cwd: cwd2 });
|
|
79
|
-
if (!searchResult) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const { packageJson, path: path3 } = searchResult;
|
|
83
|
-
return new PkgService(packageJson, path3);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// src/services/shell/create.ts
|
|
87
|
-
import fs2 from "fs";
|
|
88
|
-
|
|
89
|
-
// src/services/shell/shell.ts
|
|
90
|
-
import { $ as make$ } from "zx";
|
|
91
|
-
|
|
92
|
-
// src/services/shell/utils.ts
|
|
93
|
-
import path2 from "path";
|
|
94
|
-
import { ProcessOutput } from "zx";
|
|
95
|
-
function isProcessOutput(value) {
|
|
96
|
-
return value instanceof ProcessOutput;
|
|
97
|
-
}
|
|
98
|
-
var getLocalBinPath = (dirPath) => path2.join(dirPath, "node_modules", ".bin");
|
|
99
|
-
function getPreferLocal(localBaseBinPath) {
|
|
100
|
-
return !localBaseBinPath ? void 0 : Array.isArray(localBaseBinPath) ? localBaseBinPath.map(getLocalBinPath) : [localBaseBinPath].map(getLocalBinPath);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/services/shell/shell.ts
|
|
104
|
-
var ShellService = class _ShellService {
|
|
105
|
-
#shell;
|
|
106
|
-
#options;
|
|
107
|
-
constructor(options) {
|
|
108
|
-
this.#options = Object.freeze(options);
|
|
109
|
-
this.#shell = make$(options);
|
|
110
|
-
}
|
|
111
|
-
get options() {
|
|
112
|
-
return this.#options;
|
|
113
|
-
}
|
|
114
|
-
get $() {
|
|
115
|
-
return this.#shell;
|
|
116
|
-
}
|
|
117
|
-
child(options) {
|
|
118
|
-
return new _ShellService({
|
|
119
|
-
...this.#options,
|
|
120
|
-
...options
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
quiet(options) {
|
|
124
|
-
return this.child({
|
|
125
|
-
...options,
|
|
126
|
-
verbose: false
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
at(cwd2, options) {
|
|
130
|
-
const getLocals = (locals) => (
|
|
131
|
-
// NOTE: the boolean handling is done outside when determining preferLocal
|
|
132
|
-
typeof locals === "boolean" ? [] : typeof locals === "undefined" ? [] : Array.isArray(locals) ? locals : [locals]
|
|
133
|
-
);
|
|
134
|
-
const cwdPreferLocal = getPreferLocal(cwd2);
|
|
135
|
-
const preferLocal = options?.preferLocal === false ? false : [
|
|
136
|
-
...getLocals(this.#options.preferLocal),
|
|
137
|
-
...getLocals(options?.preferLocal),
|
|
138
|
-
...cwdPreferLocal ? cwdPreferLocal : []
|
|
139
|
-
];
|
|
140
|
-
return this.child({
|
|
141
|
-
...options,
|
|
142
|
-
cwd: cwd2,
|
|
143
|
-
preferLocal
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// src/services/shell/create.ts
|
|
149
|
-
var cwd = fs2.realpathSync(process.cwd());
|
|
150
|
-
function quote(arg) {
|
|
151
|
-
if (/^[\w./:=@-]+$/i.test(arg) || arg === "") {
|
|
152
|
-
return arg;
|
|
153
|
-
}
|
|
154
|
-
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");
|
|
155
|
-
}
|
|
156
|
-
var isRaw = (arg) => typeof arg === "object" && arg !== null && "stdout" in arg && typeof arg.stdout === "string";
|
|
157
|
-
function defaultQuote(arg) {
|
|
158
|
-
if (typeof arg === "string") {
|
|
159
|
-
return quote(arg);
|
|
160
|
-
}
|
|
161
|
-
if (isRaw(arg)) {
|
|
162
|
-
return arg.stdout;
|
|
163
|
-
}
|
|
164
|
-
throw TypeError(`Unsupported argument type: ${typeof arg}`);
|
|
165
|
-
}
|
|
166
|
-
function createShellService(options = {}) {
|
|
167
|
-
const preferLocal = getPreferLocal(options.localBaseBinPath);
|
|
168
|
-
return new ShellService({
|
|
169
|
-
verbose: true,
|
|
170
|
-
cwd,
|
|
171
|
-
preferLocal,
|
|
172
|
-
quote: defaultQuote,
|
|
173
|
-
...options
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// src/version.ts
|
|
178
|
-
function getVersion(pkg) {
|
|
179
|
-
return process.env.VERSION || pkg.packageJson.version;
|
|
180
|
-
}
|
|
181
|
-
export {
|
|
182
|
-
PkgService,
|
|
183
|
-
ShellService,
|
|
184
|
-
colors,
|
|
185
|
-
createPkgService,
|
|
186
|
-
createShellService,
|
|
187
|
-
cwd,
|
|
188
|
-
getPreferLocal,
|
|
189
|
-
getVersion,
|
|
190
|
-
isProcessOutput,
|
|
191
|
-
isRaw,
|
|
192
|
-
quote
|
|
193
|
-
};
|
|
194
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/colors.ts","../src/services/pkg.ts","../src/services/shell/create.ts","../src/services/shell/shell.ts","../src/services/shell/utils.ts","../src/version.ts"],"sourcesContent":["import chalk, { type ChalkInstance } from \"chalk\";\nimport supportsColor from \"supports-color\";\n\n// https://no-color.org/\nconst colorIsSupported = () => supportsColor.stdout && !process.env.NO_COLOR;\n\nconst identity = <T>(x: T) => x;\nconst safe = (style: ChalkInstance) => (colorIsSupported() ? style : identity);\n\nexport const colors = {\n blueBright: safe(chalk.blueBright),\n redBright: safe(chalk.redBright),\n greenBright: safe(chalk.greenBright),\n bold: safe(chalk.bold),\n muted: safe(chalk.dim),\n link: safe(chalk.underline),\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { findWorkspacePackages, type Project } from \"@pnpm/workspace.find-packages\";\nimport { readWorkspaceManifest } from \"@pnpm/workspace.read-manifest\";\nimport { type NormalizedPackageJson, readPackageUp } from \"read-package-up\";\n\nexport type { Project };\n\nexport class PkgService {\n #packageJson: NormalizedPackageJson;\n #dirPath: string;\n\n get dirPath() {\n return this.#dirPath;\n }\n\n get packageJson() {\n return this.#packageJson;\n }\n\n constructor(packageJson: NormalizedPackageJson, pkgPath: string) {\n this.#packageJson = packageJson;\n this.#dirPath = path.dirname(pkgPath);\n }\n\n info() {\n return {\n packageJson: this.#packageJson,\n dirPath: this.#dirPath,\n };\n }\n\n hasFile(name: string, dir?: string) {\n const filepath = dir ? path.join(dir, name) : this.#fromApp(name);\n return fs.existsSync(filepath);\n }\n\n isMonorepo() {\n return this.#packageJson.workspaces !== undefined || this.#hasPnpmWorkspace();\n }\n\n async getWorkspaceProjects() {\n let patterns: string[];\n\n if (this.#hasPnpmWorkspace()) {\n const manifest = await readWorkspaceManifest(this.#dirPath);\n\n if (!manifest) {\n throw new Error(\"Can't read pnpm workspace manifest\");\n }\n\n patterns = manifest.packages;\n } else {\n patterns = Array.isArray(this.#packageJson.workspaces)\n ? this.#packageJson.workspaces\n : (this.#packageJson.workspaces?.packages ?? []);\n }\n\n if (!Array.isArray(patterns) || patterns.some((p) => typeof p !== \"string\")) {\n throw new Error(\"Invalid workspace patterns\");\n }\n\n const projects = await findWorkspacePackages(this.#dirPath, {\n patterns,\n });\n\n const excludeRoot = (projects: Project[]) => {\n return projects.filter((project) => project.rootDir !== this.#dirPath);\n };\n\n return excludeRoot(projects);\n }\n\n #hasPnpmWorkspace() {\n return this.hasFile(\"pnpm-workspace.yaml\");\n }\n\n #fromApp(...args: string[]) {\n return path.join(this.#dirPath, ...args);\n }\n}\n\nexport async function createPkgService(cwd: string): Promise<PkgService | null> {\n const searchResult = await readPackageUp({ cwd });\n\n if (!searchResult) {\n return null;\n }\n\n const { packageJson, path } = searchResult;\n\n return new PkgService(packageJson, path);\n}\n","import fs from \"node:fs\";\nimport { ShellService } from \"./shell\";\nimport type { CreateOptions } from \"./types\";\nimport { getPreferLocal } from \"./utils\";\n\nexport const cwd = fs.realpathSync(process.cwd());\n\n// Inspired by https://dub.sh/6tiHVgn\nexport function quote(arg: string) {\n if (/^[\\w./:=@-]+$/i.test(arg) || arg === \"\") {\n return arg;\n }\n\n return arg\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/'/g, \"\\\\'\")\n .replace(/\\f/g, \"\\\\f\")\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\")\n .replace(/\\v/g, \"\\\\v\")\n .replace(/\\0/g, \"\\\\0\");\n}\n\nexport const isRaw = (arg: unknown): arg is { stdout: string } =>\n typeof arg === \"object\" && arg !== null && \"stdout\" in arg && typeof arg.stdout === \"string\";\n\nfunction defaultQuote(arg: unknown) {\n if (typeof arg === \"string\") {\n return quote(arg);\n }\n\n if (isRaw(arg)) {\n return arg.stdout;\n }\n\n throw TypeError(`Unsupported argument type: ${typeof arg}`);\n}\n\nexport function createShellService(options: CreateOptions = {}) {\n const preferLocal = getPreferLocal(options.localBaseBinPath);\n\n return new ShellService({\n verbose: true,\n cwd,\n preferLocal,\n quote: defaultQuote,\n ...options,\n });\n}\n","import { $ as make$ } from \"zx\";\nimport type { Shell, ShellOptions } from \"./types\";\nimport { getPreferLocal } from \"./utils\";\n\nexport class ShellService {\n #shell: Shell;\n #options: ShellOptions;\n\n constructor(options: ShellOptions) {\n this.#options = Object.freeze(options);\n this.#shell = make$(options);\n }\n\n get options() {\n return this.#options;\n }\n\n get $() {\n return this.#shell;\n }\n\n child(options: ShellOptions) {\n return new ShellService({\n ...this.#options,\n ...options,\n });\n }\n\n quiet(options?: ShellOptions) {\n return this.child({\n ...options,\n verbose: false,\n });\n }\n\n at(cwd: string, options?: ShellOptions) {\n const getLocals = (locals: boolean | string | string[] | undefined) =>\n // NOTE: the boolean handling is done outside when determining preferLocal\n typeof locals === \"boolean\" ? [] : typeof locals === \"undefined\" ? [] : Array.isArray(locals) ? locals : [locals];\n\n const cwdPreferLocal = getPreferLocal(cwd);\n\n const preferLocal =\n options?.preferLocal === false\n ? false\n : [\n ...getLocals(this.#options.preferLocal),\n ...getLocals(options?.preferLocal),\n ...(cwdPreferLocal ? cwdPreferLocal : []),\n ];\n\n return this.child({\n ...options,\n cwd,\n preferLocal,\n });\n }\n}\n","import path from \"node:path\";\nimport { ProcessOutput } from \"zx\";\n\nexport function isProcessOutput(value: unknown): value is ProcessOutput {\n return value instanceof ProcessOutput;\n}\n\nconst getLocalBinPath = (dirPath: string) => path.join(dirPath, \"node_modules\", \".bin\");\n\nexport function getPreferLocal(localBaseBinPath: string | Array<string> | undefined) {\n return !localBaseBinPath\n ? undefined\n : Array.isArray(localBaseBinPath)\n ? localBaseBinPath.map(getLocalBinPath)\n : [localBaseBinPath].map(getLocalBinPath);\n}\n","import type { PkgService } from \"./services\";\n\nexport function getVersion(pkg: PkgService) {\n return process.env.VERSION || pkg.packageJson.version;\n}\n"],"mappings":";AAAA,OAAO,WAAmC;AAC1C,OAAO,mBAAmB;AAG1B,IAAM,mBAAmB,MAAM,cAAc,UAAU,CAAC,QAAQ,IAAI;AAEpE,IAAM,WAAW,CAAI,MAAS;AAC9B,IAAM,OAAO,CAAC,UAA0B,iBAAiB,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