@somewhatabstract/x 0.1.1 → 0.2.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/dist/x.mjs +13 -20
- package/package.json +3 -3
package/dist/x.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import * as fs from "node:fs/promises";
|
|
|
7
7
|
import * as path$1 from "node:path";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import { findRoot } from "@manypkg/find-root";
|
|
10
|
-
|
|
11
10
|
//#region src/errors.ts
|
|
12
11
|
/**
|
|
13
12
|
* Error class for known/expected errors that should be displayed to the user
|
|
@@ -19,7 +18,6 @@ var HandledError = class extends Error {
|
|
|
19
18
|
this.name = "HandledError";
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
22
|
//#region src/discover-packages.ts
|
|
25
23
|
/**
|
|
@@ -42,7 +40,6 @@ async function discoverPackages(workspaceRoot) {
|
|
|
42
40
|
throw new HandledError(`Failed to discover packages`, { cause: error });
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
//#endregion
|
|
47
44
|
//#region src/build-environment.ts
|
|
48
45
|
/**
|
|
@@ -93,7 +90,6 @@ async function buildEnvironment(workspaceRoot, currentEnv) {
|
|
|
93
90
|
}
|
|
94
91
|
return env;
|
|
95
92
|
}
|
|
96
|
-
|
|
97
93
|
//#endregion
|
|
98
94
|
//#region src/is-node-executable.ts
|
|
99
95
|
/**
|
|
@@ -108,7 +104,6 @@ function isNodeExecutable(binPath) {
|
|
|
108
104
|
const lower = binPath.toLowerCase();
|
|
109
105
|
return lower.endsWith(".js") || lower.endsWith(".mjs") || lower.endsWith(".cjs");
|
|
110
106
|
}
|
|
111
|
-
|
|
112
107
|
//#endregion
|
|
113
108
|
//#region src/execute-script.ts
|
|
114
109
|
/**
|
|
@@ -138,7 +133,6 @@ async function executeScript(bin, args, workspaceRoot) {
|
|
|
138
133
|
});
|
|
139
134
|
});
|
|
140
135
|
}
|
|
141
|
-
|
|
142
136
|
//#endregion
|
|
143
137
|
//#region src/resolve-bin-path.ts
|
|
144
138
|
/**
|
|
@@ -162,7 +156,6 @@ function resolveBinPath(pkg, bin, binName) {
|
|
|
162
156
|
if (resolvedBinPath !== packageDir && !resolvedBinPath.startsWith(packageDir + path.sep)) return null;
|
|
163
157
|
return resolvedBinPath;
|
|
164
158
|
}
|
|
165
|
-
|
|
166
159
|
//#endregion
|
|
167
160
|
//#region src/find-matching-bins.ts
|
|
168
161
|
/**
|
|
@@ -192,7 +185,6 @@ async function findMatchingBins(packages, binName) {
|
|
|
192
185
|
}
|
|
193
186
|
return matches;
|
|
194
187
|
}
|
|
195
|
-
|
|
196
188
|
//#endregion
|
|
197
189
|
//#region src/find-workspace-root.ts
|
|
198
190
|
/**
|
|
@@ -210,7 +202,6 @@ async function findWorkspaceRoot(startDir = process.cwd()) {
|
|
|
210
202
|
throw new HandledError("Could not find workspace root. Make sure you're in a monorepo workspace.", { cause: error });
|
|
211
203
|
}
|
|
212
204
|
}
|
|
213
|
-
|
|
214
205
|
//#endregion
|
|
215
206
|
//#region src/x-impl.ts
|
|
216
207
|
/**
|
|
@@ -255,33 +246,35 @@ async function xImpl(scriptName, args = [], options = {}) {
|
|
|
255
246
|
throw error;
|
|
256
247
|
}
|
|
257
248
|
}
|
|
258
|
-
|
|
259
249
|
//#endregion
|
|
260
250
|
//#region src/bin/x.ts
|
|
261
|
-
const
|
|
251
|
+
const rawArgs = hideBin(process.argv);
|
|
252
|
+
const argv = yargs(rawArgs).usage("Usage: $0 <script-name> [...args]").command("$0 <script-name>", "Execute a bin script from any package in the workspace", (yargs) => {
|
|
262
253
|
return yargs.positional("script-name", {
|
|
263
254
|
describe: "Name of the bin script to execute",
|
|
264
255
|
type: "string",
|
|
265
256
|
demandOption: true
|
|
266
|
-
}).positional("args", {
|
|
267
|
-
describe: "Arguments to pass to the script",
|
|
268
|
-
type: "string",
|
|
269
|
-
array: true,
|
|
270
|
-
default: []
|
|
271
257
|
});
|
|
272
258
|
}).option("dry-run", {
|
|
273
259
|
alias: "d",
|
|
274
260
|
describe: "Show what would be executed without running it",
|
|
275
261
|
type: "boolean",
|
|
276
262
|
default: false
|
|
277
|
-
}).help().alias("help", "h").version().alias("version", "v").example("$0 tsc --noEmit", "Run TypeScript compiler from any package").example("$0 eslint src/", "Run ESLint from any package that provides it").example("$0 --dry-run jest", "Preview which jest would be executed").
|
|
263
|
+
}).help().alias("help", "h").version().alias("version", "v").example("$0 tsc --noEmit", "Run TypeScript compiler from any package").example("$0 eslint src/", "Run ESLint from any package that provides it").example("$0 --dry-run jest", "Preview which jest would be executed").parserConfiguration({ "unknown-options-as-args": true }).parseSync();
|
|
278
264
|
const scriptName = argv["script-name"];
|
|
279
|
-
|
|
265
|
+
const args = argv._ || [];
|
|
266
|
+
const options = { dryRun: argv["dry-run"] };
|
|
267
|
+
if (!rawArgs.includes("--")) {
|
|
268
|
+
if (args.filter((arg) => typeof arg === "string" && arg.startsWith("-")).length > 0) {
|
|
269
|
+
console.warn(`Tip: To pass flags to "${scriptName}", use '--' to separate them:`);
|
|
270
|
+
console.warn(` x ${scriptName} -- ${args.join(" ")}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
xImpl(scriptName, args, options).then((result) => {
|
|
280
274
|
process.exit(result.exitCode);
|
|
281
275
|
}).catch((error) => {
|
|
282
276
|
console.error("Unexpected error:", error);
|
|
283
277
|
process.exit(1);
|
|
284
278
|
});
|
|
285
|
-
|
|
286
279
|
//#endregion
|
|
287
|
-
export {
|
|
280
|
+
export {};
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"type": "module",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.2.0",
|
|
16
16
|
"description": "Execute any bin defined by any package in a monorepo without needing to install that package",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/somewhatabstract/x/issues"
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"yarn": "please-use-pnpm"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^2.4.
|
|
30
|
+
"@biomejs/biome": "^2.4.6",
|
|
31
31
|
"@changesets/cli": "^2.29.8",
|
|
32
32
|
"@codecov/rollup-plugin": "^1.9.1",
|
|
33
33
|
"@types/node": "^20.19.29",
|
|
34
34
|
"@types/yargs": "^17.0.35",
|
|
35
35
|
"@vitest/coverage-v8": "^4.0.17",
|
|
36
|
-
"tsdown": "0.
|
|
36
|
+
"tsdown": "0.21.6",
|
|
37
37
|
"typescript": "^5.9.3",
|
|
38
38
|
"vitest": "^4.0.17"
|
|
39
39
|
},
|