@w5s/managed-script 1.0.0-alpha.2 → 1.0.0-alpha.5

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/dist/ManagedScript-B8d632d3.js +321 -0
  4. package/dist/ManagedScript-B8d632d3.js.map +1 -0
  5. package/dist/cli.js +27 -43
  6. package/dist/cli.js.map +1 -1
  7. package/dist/defaultContext-Xl2iA7UM.js +91 -0
  8. package/dist/defaultContext-Xl2iA7UM.js.map +1 -0
  9. package/dist/index.d.ts +27 -54
  10. package/dist/index.js +27 -12
  11. package/dist/index.js.map +1 -1
  12. package/dist/type-hvsy_R0f.d.ts +103 -0
  13. package/dist/zx.d.ts +45 -14
  14. package/dist/zx.js +67 -26
  15. package/dist/zx.js.map +1 -1
  16. package/package.json +4 -2
  17. package/src/ManagedScript/defaultContext.ts +2 -4
  18. package/src/ManagedScript/execute.ts +48 -25
  19. package/src/ManagedScript/resolveScripts.ts +52 -5
  20. package/src/cli/RootCommand.ts +2 -3
  21. package/src/internal/Executor.ts +27 -10
  22. package/src/internal/Logger.ts +25 -7
  23. package/src/internal/PackageScriptOverride.ts +43 -0
  24. package/src/internal/ScriptInvocation.ts +55 -0
  25. package/src/internal/ScriptNameResolver.ts +5 -4
  26. package/src/internal/Stdio.ts +41 -0
  27. package/src/internal/lazy.ts +7 -0
  28. package/src/mergeConfig.ts +28 -0
  29. package/src/type/CommandContext.ts +6 -7
  30. package/src/type/ResolvedConfig.ts +27 -8
  31. package/src/type/StdOptions.ts +1 -0
  32. package/src/type/UserConfig.ts +38 -1
  33. package/src/type.ts +1 -0
  34. package/src/zx/ZXOptions.ts +73 -1
  35. package/src/zx/ZXShell.ts +18 -1
  36. package/src/zx/defaults.ts +6 -0
  37. package/src/zx/isCI.ts +26 -0
  38. package/src/zx/zx.ts +7 -13
  39. package/src/zx.ts +2 -0
  40. package/dist/ManagedScript-DIacNHCc.js +0 -149
  41. package/dist/ManagedScript-DIacNHCc.js.map +0 -1
  42. package/dist/defaultContext-D_QWP9aF.js +0 -98
  43. package/dist/defaultContext-D_QWP9aF.js.map +0 -1
  44. package/dist/type-DQiyX1q_.d.ts +0 -53
  45. package/src/zx/defaultZXOptions.ts +0 -37
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Julien Polo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -48,6 +48,28 @@ When you want to use the managed-script configuration simply execute the cli to
48
48
  }
49
49
  ```
50
50
 
51
+ ### Direct runner
52
+
53
+ A string script is a shell command (shorthand for `{ "run": "..." }`, like a lefthook `run`). To run a program directly, set `runner` and `args`, the same idea as a lefthook script runner. Arguments passed on the CLI are appended after `args`.
54
+
55
+ ```jsonc
56
+ // package.json
57
+ {
58
+ "managed-script": {
59
+ "scripts": {
60
+ "lint": {
61
+ "runner": "node",
62
+ "args": ["./scripts/lint.js"]
63
+ }
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ `managed-script lint --fix` runs `node ./scripts/lint.js --fix`.
70
+
71
+ Keep a shell command string when the script uses pipes, `&&`, or other shell syntax. A program name that contains spaces is still one `runner`; put the remaining words in `args`, for example `{ "runner": "go", "args": ["run", "main.go"] }`.
72
+
51
73
  ### Global shared configuration (npm)
52
74
 
53
75
  ```jsonc
@@ -64,6 +86,21 @@ When you want to use the managed-script configuration simply execute the cli to
64
86
 
65
87
  ## Miscellaneous
66
88
 
89
+ ### Overriding a managed script
90
+
91
+ Define a script named like the managed one with a trailing `!` in the local `package.json` to replace its implementation:
92
+
93
+ ```jsonc
94
+ {
95
+ "scripts": {
96
+ "build": "managed-script",
97
+ "build!": "tsc -p tsconfig.custom.json" // used instead of the managed "build"
98
+ }
99
+ }
100
+ ```
101
+
102
+ The override is executed with `npm run "build!"` (arguments are forwarded after `--`), so it behaves like any native npm script.
103
+
67
104
  ### Working directory and config origins
68
105
 
69
106
  Use `--cwd` to choose the directory used to resolve configuration and run the selected script. The equivalent environment variable is `MANAGED_SCRIPT_CWD`; the CLI option takes precedence over the environment variable, which takes precedence over the current process directory.
@@ -0,0 +1,321 @@
1
+ import path from "node:path";
2
+ import { loadConfig } from "c12";
3
+ import { spawn } from "node:child_process";
4
+ import { n as ManagedScriptEnv, r as Stdio, t as defaultContext } from "./defaultContext-Xl2iA7UM.js";
5
+ import { readFile } from "node:fs/promises";
6
+ import path$1 from "node:path/win32";
7
+ // src/meta.ts
8
+ const meta = Object.freeze({
9
+ binaryLabel: "W5S Managed Script",
10
+ binaryName: "managed-script",
11
+ binaryVersion: "1.0.0-alpha.5",
12
+ buildNumber: 1,
13
+ name: "@w5s/managed-script",
14
+ version: "1.0.0-alpha.5"
15
+ });
16
+ // src/internal/ConfigLoader.ts
17
+ const ConfigLoader = { async load(options) {
18
+ const result = await loadConfig({
19
+ cwd: options.cwd,
20
+ name: meta.binaryName,
21
+ packageJson: [meta.binaryName]
22
+ });
23
+ return {
24
+ config: result.config,
25
+ configFile: result.configFile ?? void 0,
26
+ layers: result.layers ?? []
27
+ };
28
+ } };
29
+ // src/internal/Executor.ts
30
+ /**
31
+ * Runs a shell command (`run`), or a program spawned directly without a shell (`runner`).
32
+ * Stdio is inherited and the exit code is forwarded.
33
+ */
34
+ const Executor = { async run(request) {
35
+ const env = request.env == null ? process.env : {
36
+ ...process.env,
37
+ ...request.env
38
+ };
39
+ const options = {
40
+ cwd: request.cwd,
41
+ env,
42
+ stdio: "inherit"
43
+ };
44
+ const child = request.runner == null ? spawn(request.run, {
45
+ ...options,
46
+ shell: true
47
+ }) : spawn(request.runner, request.args ?? [], {
48
+ ...options,
49
+ shell: false
50
+ });
51
+ return new Promise((resolve, reject) => {
52
+ child.on("error", reject);
53
+ child.on("close", (code, signal) => {
54
+ resolve(code ?? (signal == null ? 1 : 128));
55
+ });
56
+ });
57
+ } };
58
+ // src/internal/Logger.ts
59
+ /**
60
+ * Rank order used to compare log levels, higher means more verbose.
61
+ */
62
+ const logLevelRank = {
63
+ debug: 4,
64
+ error: 1,
65
+ info: 3,
66
+ silent: 0,
67
+ warn: 2
68
+ };
69
+ /**
70
+ * Creates a logger writing to `stream`, filtering out messages above the configured `level`.
71
+ */
72
+ const Logger = { create({ color = "auto", level, name = meta.binaryName, stdio }) {
73
+ const { stderr } = Stdio.resolve(stdio);
74
+ const write = (messageLevel, message) => {
75
+ if (!(logLevelRank[messageLevel] <= logLevelRank[level])) return;
76
+ const outputStream = stderr;
77
+ const shouldColor = color === "always" || color === "auto" && "isTTY" in outputStream && outputStream.isTTY === true;
78
+ const colorCode = {
79
+ debug: "\x1B[36m",
80
+ error: "\x1B[31m",
81
+ info: "",
82
+ silent: "",
83
+ warn: "\x1B[33m"
84
+ }[messageLevel];
85
+ const label = {
86
+ debug: "debug",
87
+ error: "error",
88
+ info: "",
89
+ silent: "",
90
+ warn: "warning"
91
+ }[messageLevel];
92
+ const coloredLabel = shouldColor && colorCode !== "" ? `${colorCode}${label}\u{1B}[0m` : label;
93
+ const prefix = label === "" ? `${name}: ` : `${name}: ${coloredLabel}: `;
94
+ outputStream.write(`${prefix}${message}\n`);
95
+ };
96
+ return {
97
+ debug: (message) => write("debug", message),
98
+ error: (message) => write("error", message),
99
+ info: (message) => write("info", message),
100
+ warn: (message) => write("warn", message)
101
+ };
102
+ } };
103
+ // src/internal/PackageScriptOverride.ts
104
+ /**
105
+ * Suffix marking a package.json script as an override of the managed script with the same name.
106
+ */
107
+ const OVERRIDE_MARKER = "!";
108
+ /**
109
+ * @namespace
110
+ */
111
+ const PackageScriptOverride = {
112
+ /**
113
+ * Returns the name of the override script (`<name>!`) if it is defined in `<cwd>/package.json`.
114
+ *
115
+ * @param options
116
+ * @param options.cwd
117
+ * @param options.name
118
+ */
119
+ async find({ cwd, name }) {
120
+ const overrideName = `${name}${OVERRIDE_MARKER}`;
121
+ try {
122
+ const scripts = JSON.parse(await readFile(path.join(cwd, "package.json"), "utf8"))?.scripts;
123
+ return scripts != null && typeof scripts === "object" && Object.hasOwn(scripts, overrideName) && typeof scripts[overrideName] === "string" ? overrideName : void 0;
124
+ } catch {
125
+ return;
126
+ }
127
+ },
128
+ /**
129
+ * The marker used to identify override scripts in `package.json`.
130
+ */
131
+ marker: OVERRIDE_MARKER
132
+ };
133
+ // src/internal/ScriptInvocation.ts
134
+ const shellSafe = /^[\w@%+=:,./-]+$/;
135
+ /**
136
+ * @namespace
137
+ */
138
+ const ScriptInvocation = {
139
+ /**
140
+ * Builds the command line shown to the user and the target passed to the executor.
141
+ * A `run` script stays one command string. A `runner` script receives real arguments.
142
+ *
143
+ * @param script
144
+ * @param scriptArgs
145
+ */
146
+ create(script, scriptArgs) {
147
+ if (script.runner != null) return { target: {
148
+ args: [...script.args, ...scriptArgs],
149
+ runner: script.runner
150
+ } };
151
+ return { target: { run: [script.run, ...scriptArgs.map((argument) => quoteShell(argument))].join(" ") } };
152
+ },
153
+ /**
154
+ * Returns the command line as a string suitable for display.
155
+ *
156
+ * @param self
157
+ */
158
+ format(self) {
159
+ const { args, run, runner } = self.target;
160
+ return runner == null ? run : formatArgv([runner, ...args ?? []]);
161
+ }
162
+ };
163
+ function formatArgv(argv) {
164
+ return argv.map((part) => shellSafe.test(part) ? part : quoteShell(part)).join(" ");
165
+ }
166
+ function quoteShell(value) {
167
+ return `'${value.replaceAll("'", String.raw`'\''`)}'`;
168
+ }
169
+ // src/internal/ScriptNameResolver.ts
170
+ /**
171
+ * Resolves the script name to run.
172
+ *
173
+ * Priority: first positional CLI argument > `npm_lifecycle_event` env var.
174
+ *
175
+ * `MANAGED_SCRIPT_NAME` is deliberately not read: it is only provided to the spawned script, so that
176
+ * an inherited value can never shadow the name of a nested invocation.
177
+ */
178
+ const ScriptNameResolver = { resolve({ env, scriptName }) {
179
+ return scriptName ?? env["npm_lifecycle_event"];
180
+ } };
181
+ // src/ManagedScript/resolveScripts.ts
182
+ function resolveScripts(loaded) {
183
+ const scripts = {};
184
+ const layers = loaded.layers.length > 0 ? loaded.layers : [{ config: loaded.config }];
185
+ for (const layer of layers) for (const [name, command] of Object.entries(layer.config?.scripts ?? {})) {
186
+ const configFile = layer.configFile ?? loaded.configFile;
187
+ const configDir = configFile == null ? void 0 : path$1.dirname(configFile);
188
+ scripts[name] ??= {
189
+ ...normalizeScript(name, command),
190
+ configDir,
191
+ configFile
192
+ };
193
+ }
194
+ return { scripts };
195
+ }
196
+ function isPlainObject(value) {
197
+ return Object.prototype.toString.call(value) === "[object Object]";
198
+ }
199
+ function isStringArray(value) {
200
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
201
+ }
202
+ const allowedKeys = /* @__PURE__ */ new Set([
203
+ "args",
204
+ "run",
205
+ "runner"
206
+ ]);
207
+ function normalizeScript(name, definition) {
208
+ if (typeof definition === "string") return requireRun(name, definition);
209
+ if (!isPlainObject(definition)) throw new TypeError(`Script "${name}" must be a shell command string or an object with "run", or "runner" and "args".`);
210
+ const unknownKeys = Object.keys(definition).filter((key) => !allowedKeys.has(key));
211
+ if (unknownKeys.length > 0) throw new TypeError(`Script "${name}" has unknown option(s): ${unknownKeys.join(", ")}.`);
212
+ const { args, run, runner } = definition;
213
+ if (run !== void 0) {
214
+ if (runner !== void 0 || args !== void 0) throw new TypeError(`Script "${name}" cannot mix "run" with "runner" or "args".`);
215
+ return requireRun(name, run);
216
+ }
217
+ if (typeof runner !== "string" || runner.trim().length === 0) throw new TypeError(`Script "${name}" runner must be a non-empty string.`);
218
+ if (args !== void 0 && !isStringArray(args)) throw new TypeError(`Script "${name}" args must be an array of strings.`);
219
+ return {
220
+ args: [...args ?? []],
221
+ runner
222
+ };
223
+ }
224
+ function requireRun(name, run) {
225
+ if (typeof run !== "string" || run.trim().length === 0) throw new TypeError(`Script "${name}" run must be a non-empty string.`);
226
+ return { run };
227
+ }
228
+ // src/ManagedScript/execute.ts
229
+ const handlers = { RunScript: async (command) => {
230
+ const { context: { color, cwd, dryRun, env, logLevel, stdio }, parameters: { scriptArgs = [], scriptName } } = command;
231
+ const { stdout } = Stdio.resolve(stdio);
232
+ const logger = Logger.create({
233
+ color,
234
+ level: logLevel,
235
+ stdio
236
+ });
237
+ const loaded = await ConfigLoader.load({ cwd });
238
+ logger.debug(`Resolved configuration from ${loaded.configFile ?? "defaults (no config file found)"}`);
239
+ const { scripts } = resolveScripts(loaded);
240
+ const name = ScriptNameResolver.resolve({
241
+ env,
242
+ scriptName
243
+ });
244
+ if (name == null) throw new Error("Unable to resolve the script name. Pass it as the first argument or run through an npm/pnpm script (npm_lifecycle_event).");
245
+ const overrideName = await PackageScriptOverride.find({
246
+ cwd,
247
+ name
248
+ });
249
+ let invocation;
250
+ let scriptLabel;
251
+ let origin;
252
+ if (overrideName == null) {
253
+ const script = scripts[name];
254
+ if (script == null) {
255
+ const available = Object.keys(scripts);
256
+ throw new Error(`No script named "${name}" found in the configuration.${available.length > 0 ? ` Available scripts: ${available.join(", ")}.` : " No scripts are configured."}`);
257
+ }
258
+ invocation = ScriptInvocation.create(script, scriptArgs);
259
+ scriptLabel = name;
260
+ origin = script;
261
+ logger.debug(`Script found in configuration: ${path.relative(cwd, script.configFile)}`);
262
+ } else {
263
+ origin = {
264
+ args: [
265
+ "run",
266
+ overrideName,
267
+ ...scriptArgs.length > 0 ? ["--"] : []
268
+ ],
269
+ configDir: void 0,
270
+ configFile: void 0,
271
+ runner: "npm"
272
+ };
273
+ invocation = ScriptInvocation.create(origin, scriptArgs);
274
+ scriptLabel = overrideName;
275
+ logger.debug(`Script "${name}" overridden by package.json script "${overrideName}"`);
276
+ }
277
+ stdout.write(`$ ${ScriptInvocation.format(invocation)}\n`);
278
+ if (dryRun) return 0;
279
+ const scriptEnv = {
280
+ [ManagedScriptEnv.Color]: color,
281
+ [ManagedScriptEnv.ConfigDir]: origin.configDir,
282
+ [ManagedScriptEnv.ConfigFile]: origin.configFile,
283
+ [ManagedScriptEnv.Cwd]: cwd,
284
+ [ManagedScriptEnv.LogLevel]: logLevel,
285
+ [ManagedScriptEnv.Name]: name
286
+ };
287
+ const exitCode = await Executor.run({
288
+ ...invocation.target,
289
+ cwd,
290
+ env: scriptEnv
291
+ });
292
+ if (exitCode !== 0) throw new Error(`Script "${scriptLabel}" exited with code ${exitCode}.`);
293
+ return exitCode;
294
+ } };
295
+ /**
296
+ * Dispatch the command to the appropriate handler based on its type.
297
+ *
298
+ * @param command
299
+ */
300
+ async function execute(command) {
301
+ const context = defaultContext(command.context);
302
+ return handlers[command._]({
303
+ ...command,
304
+ context
305
+ });
306
+ }
307
+ // src/ManagedScript/runScript.ts
308
+ async function runScript(options) {
309
+ return execute({
310
+ _: "RunScript",
311
+ ...options
312
+ });
313
+ }
314
+ // src/ManagedScript.ts
315
+ /**
316
+ * @namespace
317
+ */
318
+ const ManagedScript = Object.freeze({ runScript });
319
+ export { meta as n, ManagedScript as t };
320
+
321
+ //# sourceMappingURL=ManagedScript-B8d632d3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ManagedScript-B8d632d3.js","names":["path"],"sources":["../src/meta.ts","../src/internal/ConfigLoader.ts","../src/internal/Executor.ts","../src/internal/Logger.ts","../src/internal/PackageScriptOverride.ts","../src/internal/ScriptInvocation.ts","../src/internal/ScriptNameResolver.ts","../src/ManagedScript/resolveScripts.ts","../src/ManagedScript/execute.ts","../src/ManagedScript/runScript.ts","../src/ManagedScript.ts"],"sourcesContent":["export const meta = Object.freeze({\n binaryLabel: 'W5S Managed Script',\n binaryName: 'managed-script',\n // @ts-ignore - these variables are injected at build time\n binaryVersion: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n // @ts-ignore - these variables are injected at build time\n buildNumber: 1, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import type { ConfigLayer } from 'c12';\n\nimport { loadConfig } from 'c12';\n\nimport type { UserConfig } from '../type/UserConfig.js';\n\nimport { meta } from '../meta.js';\n\nexport interface ConfigLoaderOptions {\n readonly cwd: string;\n}\n\nexport interface ConfigLoaderResult {\n readonly config: UserConfig;\n readonly configFile: string | undefined;\n readonly layers: Array<ConfigLayer<UserConfig>>;\n}\n\nexport const ConfigLoader = {\n async load(options: ConfigLoaderOptions): Promise<ConfigLoaderResult> {\n const result = await loadConfig<UserConfig>({\n cwd: options.cwd,\n name: meta.binaryName,\n packageJson: [meta.binaryName],\n });\n\n return {\n config: result.config,\n configFile: result.configFile ?? undefined,\n layers: result.layers ?? [],\n };\n },\n};\n","import { spawn } from 'node:child_process';\n\nexport type ExecutorRequest = ExecutorTarget & {\n readonly cwd?: string | undefined;\n readonly env?: NodeJS.ProcessEnv | undefined;\n};\n\nexport interface ExecutorRun {\n readonly args?: undefined;\n readonly run: string;\n readonly runner?: undefined;\n}\n\nexport interface ExecutorRunner {\n readonly args?: ReadonlyArray<string> | undefined;\n readonly run?: undefined;\n readonly runner: string;\n}\n\n/**\n * Same shape as a lefthook job: either a shell command (`run`) or a program with arguments (`runner` + `args`).\n */\nexport type ExecutorTarget = ExecutorRun | ExecutorRunner;\n\n/**\n * Runs a shell command (`run`), or a program spawned directly without a shell (`runner`).\n * Stdio is inherited and the exit code is forwarded.\n */\nexport const Executor = {\n async run(request: ExecutorRequest): Promise<number> {\n const env = request.env == null ? process.env : { ...process.env, ...request.env };\n const options = { cwd: request.cwd, env, stdio: 'inherit' } as const;\n const child = request.runner == null\n ? spawn(request.run, { ...options, shell: true })\n : spawn(request.runner, request.args ?? [], { ...options, shell: false });\n\n return new Promise((resolve, reject) => {\n child.on('error', reject);\n child.on('close', (code, signal) => {\n resolve(code ?? (signal == null ? 1 : 128));\n });\n });\n },\n};\n","import type { StdioOptions } from '../type.js';\n\nimport { meta } from '../meta.js';\nimport { Stdio } from './Stdio.js';\n\nexport type ColorMode = 'always' | 'auto' | 'never';\nexport type LogLevel = 'debug' | 'error' | 'info' | 'silent' | 'warn';\n\n/**\n * Rank order used to compare log levels, higher means more verbose.\n */\nconst logLevelRank: Record<LogLevel, number> = {\n debug: 4,\n error: 1,\n info: 3,\n silent: 0,\n warn: 2,\n};\n\nexport interface CreateLoggerOptions {\n readonly color?: ColorMode;\n readonly level: LogLevel;\n\n /**\n * Program name used as message prefix (default: binary name)\n */\n readonly name?: string;\n\n /**\n * Standard I/O, messages are written to index `2` (stderr)\n */\n readonly stdio: StdioOptions;\n}\n\nexport interface Logger {\n debug(message: string): void;\n error(message: string): void;\n info(message: string): void;\n warn(message: string): void;\n}\n\n/**\n * Creates a logger writing to `stream`, filtering out messages above the configured `level`.\n */\nexport const Logger = {\n create({ color = 'auto', level, name = meta.binaryName, stdio }: CreateLoggerOptions): Logger {\n const { stderr } = Stdio.resolve(stdio);\n const write = (messageLevel: LogLevel, message: string) => {\n if (!(logLevelRank[messageLevel] <= logLevelRank[level])) {\n return;\n }\n // Keep stdout free for command output that may be consumed by another process.\n const outputStream = stderr;\n const shouldColor = color === 'always' || (color === 'auto' && 'isTTY' in outputStream && outputStream.isTTY === true);\n const colorCode = {\n debug: '\\u{1B}[36m',\n error: '\\u{1B}[31m',\n info: '',\n silent: '',\n warn: '\\u{1B}[33m',\n }[messageLevel];\n // Unix convention: `program: [level: ]message`, info has no level label\n const label = { debug: 'debug', error: 'error', info: '', silent: '', warn: 'warning' }[messageLevel];\n const coloredLabel = shouldColor && colorCode !== '' ? `${colorCode}${label}\\u{1B}[0m` : label;\n const prefix = label === '' ? `${name}: ` : `${name}: ${coloredLabel}: `;\n outputStream.write(`${prefix}${message}\\n`);\n };\n\n return {\n debug: (message) => write('debug', message),\n error: (message) => write('error', message),\n info: (message) => write('info', message),\n warn: (message) => write('warn', message),\n };\n },\n};\n","import { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\n/**\n * Suffix marking a package.json script as an override of the managed script with the same name.\n */\nconst OVERRIDE_MARKER = '!';\n\n/**\n * @namespace\n */\nexport const PackageScriptOverride = {\n /**\n * Returns the name of the override script (`<name>!`) if it is defined in `<cwd>/package.json`.\n *\n * @param options\n * @param options.cwd\n * @param options.name\n */\n async find({ cwd, name }: { readonly cwd: string; readonly name: string }): Promise<string | undefined> {\n const overrideName = `${name}${OVERRIDE_MARKER}`;\n try {\n const content = JSON.parse(await readFile(path.join(cwd, 'package.json'), 'utf8')) as null | {\n scripts?: Record<string, unknown>;\n };\n const scripts = content?.scripts;\n return scripts != null &&\n typeof scripts === 'object' &&\n Object.hasOwn(scripts, overrideName) &&\n typeof scripts[overrideName] === 'string'\n ? overrideName\n : undefined;\n } catch {\n // missing or invalid package.json: no override\n return undefined;\n }\n },\n\n /**\n * The marker used to identify override scripts in `package.json`.\n */\n marker: OVERRIDE_MARKER,\n};\n","import type { ResolvedConfig } from '../type/ResolvedConfig.js';\nimport type { ExecutorTarget } from './Executor.js';\n\nconst shellSafe = /^[\\w@%+=:,./-]+$/;\n\nexport interface ScriptInvocation {\n /**\n * What the executor runs\n */\n readonly target: ExecutorTarget;\n}\n\n/**\n * @namespace\n */\nexport const ScriptInvocation = {\n /**\n * Builds the command line shown to the user and the target passed to the executor.\n * A `run` script stays one command string. A `runner` script receives real arguments.\n *\n * @param script\n * @param scriptArgs\n */\n create(script: ResolvedConfig.Script, scriptArgs: ReadonlyArray<string>): ScriptInvocation {\n if (script.runner != null) {\n const args = [...script.args, ...scriptArgs];\n return {\n target: { args, runner: script.runner },\n };\n }\n\n const run = [script.run, ...scriptArgs.map((argument) => quoteShell(argument))].join(' ');\n return {\n target: { run },\n };\n },\n\n /**\n * Returns the command line as a string suitable for display.\n *\n * @param self\n */\n format(self: ScriptInvocation): string {\n const { args, run, runner } = self.target;\n return runner == null ? run : formatArgv([runner, ...args ?? []]);\n },\n};\n\nfunction formatArgv(argv: ReadonlyArray<string>): string {\n return argv.map((part) => shellSafe.test(part) ? part : quoteShell(part)).join(' ');\n}\n\nfunction quoteShell(value: string): string {\n return `'${value.replaceAll(\"'\", String.raw`'\\''`)}'`;\n}\n","export interface ScriptNameResolverOptions {\n readonly env: NodeJS.ProcessEnv;\n readonly scriptName: string | undefined;\n}\n\n/**\n * Resolves the script name to run.\n *\n * Priority: first positional CLI argument > `npm_lifecycle_event` env var.\n *\n * `MANAGED_SCRIPT_NAME` is deliberately not read: it is only provided to the spawned script, so that\n * an inherited value can never shadow the name of a nested invocation.\n */\nexport const ScriptNameResolver = {\n resolve({ env, scriptName }: ScriptNameResolverOptions): string | undefined {\n return scriptName ?? env['npm_lifecycle_event'];\n },\n};\n","import path from 'node:path/win32';\n\nimport type { ConfigLoaderResult } from '../internal/ConfigLoader.js';\nimport type { ResolvedConfig } from '../type/ResolvedConfig.js';\n\ntype NormalizedScript = Pick<ResolvedConfig.RunnerScript, 'args' | 'run' | 'runner'> | Pick<ResolvedConfig.ShellScript, 'args' | 'run' | 'runner'>;\n\nexport function resolveScripts(loaded: ConfigLoaderResult): ResolvedConfig {\n const scripts: ResolvedConfig['scripts'] = {};\n const layers = loaded.layers.length > 0 ? loaded.layers : [{ config: loaded.config }];\n\n for (const layer of layers) {\n for (const [name, command] of Object.entries(layer.config?.scripts ?? {})) {\n const configFile = layer.configFile ?? loaded.configFile;\n const configDir = configFile == null ? undefined : path.dirname(configFile);\n scripts[name] ??= { ...normalizeScript(name, command), configDir, configFile };\n }\n }\n\n return {\n scripts,\n };\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nfunction isStringArray(value: unknown): value is ReadonlyArray<string> {\n return Array.isArray(value) && value.every((item) => typeof item === 'string');\n}\n\nconst allowedKeys = new Set(['args', 'run', 'runner']);\n\nfunction normalizeScript(name: string, definition: unknown): NormalizedScript {\n if (typeof definition === 'string') {\n return requireRun(name, definition);\n }\n\n if (!isPlainObject(definition)) {\n throw new TypeError(`Script \"${name}\" must be a shell command string or an object with \"run\", or \"runner\" and \"args\".`);\n }\n\n const unknownKeys = Object.keys(definition).filter((key) => !allowedKeys.has(key));\n if (unknownKeys.length > 0) {\n throw new TypeError(`Script \"${name}\" has unknown option(s): ${unknownKeys.join(', ')}.`);\n }\n\n const { args, run, runner } = definition;\n if (run !== undefined) {\n if (runner !== undefined || args !== undefined) {\n throw new TypeError(`Script \"${name}\" cannot mix \"run\" with \"runner\" or \"args\".`);\n }\n return requireRun(name, run);\n }\n\n if (typeof runner !== 'string' || runner.trim().length === 0) {\n throw new TypeError(`Script \"${name}\" runner must be a non-empty string.`);\n }\n if (args !== undefined && !isStringArray(args)) {\n throw new TypeError(`Script \"${name}\" args must be an array of strings.`);\n }\n\n return { args: [...(args ?? [])], runner };\n}\n\nfunction requireRun(name: string, run: unknown): NormalizedScript {\n if (typeof run !== 'string' || run.trim().length === 0) {\n throw new TypeError(`Script \"${name}\" run must be a non-empty string.`);\n }\n return { run };\n}\n","import path from 'node:path';\n\nimport type { ManagedScriptCommand } from '../type.js';\nimport type { ResolvedConfig } from '../type/ResolvedConfig.js';\n\nimport { ConfigLoader } from '../internal/ConfigLoader.js';\nimport { Executor } from '../internal/Executor.js';\nimport { Logger } from '../internal/Logger.js';\nimport { PackageScriptOverride } from '../internal/PackageScriptOverride.js';\nimport { ScriptInvocation } from '../internal/ScriptInvocation.js';\nimport { ScriptNameResolver } from '../internal/ScriptNameResolver.js';\nimport { Stdio } from '../internal/Stdio.js';\nimport { ManagedScriptEnv } from '../ManagedScriptEnv.js';\nimport { defaultContext } from './defaultContext.js';\nimport { resolveScripts } from './resolveScripts.js';\n\nconst handlers = {\n RunScript: async (command: ManagedScriptCommand.RunScript): Promise<number> => {\n const {\n context: { color, cwd, dryRun, env, logLevel, stdio },\n parameters: { scriptArgs = [], scriptName },\n } = command;\n const { stdout } = Stdio.resolve(stdio);\n const logger = Logger.create({ color, level: logLevel, stdio });\n const loaded = await ConfigLoader.load({ cwd });\n logger.debug(`Resolved configuration from ${loaded.configFile ?? 'defaults (no config file found)'}`);\n const resolved = resolveScripts(loaded);\n const { scripts } = resolved;\n\n const name = ScriptNameResolver.resolve({ env, scriptName: scriptName });\n if (name == null) {\n throw new Error(\n 'Unable to resolve the script name. Pass it as the first argument or run through an npm/pnpm script (npm_lifecycle_event).',\n );\n }\n\n const overrideName = await PackageScriptOverride.find({ cwd, name });\n let invocation: ScriptInvocation;\n let scriptLabel: string;\n let origin: ResolvedConfig.Script;\n if (overrideName == null) {\n const script = scripts[name];\n if (script == null) {\n const available = Object.keys(scripts);\n throw new Error(\n `No script named \"${name}\" found in the configuration.${\n available.length > 0 ? ` Available scripts: ${available.join(', ')}.` : ' No scripts are configured.'\n }`,\n );\n }\n\n invocation = ScriptInvocation.create(script, scriptArgs);\n scriptLabel = name;\n origin = script;\n // relative to cwd\n // eslint-disable-next-line ts/no-non-null-assertion\n logger.debug(`Script found in configuration: ${path.relative(cwd, script.configFile!)}`);\n } else {\n // Run through npm so the override behaves exactly like a regular package.json script\n origin = {\n args: ['run', overrideName, ...(scriptArgs.length > 0 ? ['--'] : [])],\n configDir: undefined,\n configFile: undefined,\n runner: 'npm',\n };\n invocation = ScriptInvocation.create(origin, scriptArgs);\n scriptLabel = overrideName;\n logger.debug(`Script \"${name}\" overridden by package.json script \"${overrideName}\"`);\n }\n\n stdout.write(`$ ${ScriptInvocation.format(invocation)}\\n`);\n if (dryRun) {\n return 0;\n }\n\n // Prepare the environment variables for the script execution.\n const scriptEnv = {\n [ManagedScriptEnv.Color]: color,\n [ManagedScriptEnv.ConfigDir]: origin.configDir,\n [ManagedScriptEnv.ConfigFile]: origin.configFile,\n [ManagedScriptEnv.Cwd]: cwd,\n [ManagedScriptEnv.LogLevel]: logLevel,\n [ManagedScriptEnv.Name]: name,\n };\n const exitCode = await Executor.run({ ...invocation.target, cwd, env: scriptEnv });\n\n if (exitCode !== 0) {\n throw new Error(`Script \"${scriptLabel}\" exited with code ${exitCode}.`);\n }\n\n return exitCode;\n },\n} satisfies {\n [K in ManagedScriptCommand['_']]: (command: Extract<ManagedScriptCommand, { _: K }>) => Promise<any>;\n};\n\nexport type ExecuteCommand<T extends ManagedScriptCommand> = Omit<T, 'context'> & {\n /**\n * Context is optional\n */\n context?: Partial<ManagedScriptCommand['context']>;\n};\n\n/**\n * Extract command parameter from execute handler\n */\nexport type ExecuteCommandParameters<T extends ManagedScriptCommand> = Omit<Parameters<typeof execute<T>>[0], '_'>;\n\n/**\n * Dispatch the command to the appropriate handler based on its type.\n *\n * @param command\n */\nexport async function execute<T extends ManagedScriptCommand>(command: ExecuteCommand<T>): Promise<Awaited<ReturnType<typeof handlers[T['_']]>>> {\n const context = defaultContext(command.context);\n // @ts-ignore we know this works\n return handlers[command._]({\n ...command,\n context,\n });\n}\n","import { ManagedScriptCommand } from '../type.js';\nimport { execute, type ExecuteCommandParameters } from './execute.js';\n\nexport async function runScript(options: ExecuteCommandParameters<ManagedScriptCommand.RunScript>) {\n return execute({\n _: 'RunScript',\n ...options,\n });\n}\n","import { runScript } from './ManagedScript/runScript.js';\n\n/**\n * @namespace\n */\nexport const ManagedScript = Object.freeze({\n runScript,\n});\n"],"mappings":";;;;;;;AAAA,MAAa,OAAO,OAAO,OAAO;CAChC,aAAa;CACb,YAAY;CAEZ,eAAA;CAEA,aAAa;CAEb,MAAA;CAEA,SAAA;AACF,CAAC;;ACOD,MAAa,eAAe,EAC1B,MAAM,KAAK,SAA2D;CACpE,MAAM,SAAS,MAAM,WAAuB;EAC1C,KAAK,QAAQ;EACb,MAAM,KAAK;EACX,aAAa,CAAC,KAAK,UAAU;CAC/B,CAAC;CAED,OAAO;EACL,QAAQ,OAAO;EACf,YAAY,OAAO,cAAc,KAAA;EACjC,QAAQ,OAAO,UAAU,CAAC;CAC5B;AACF,EACF;;;;;;ACJA,MAAa,WAAW,EACtB,MAAM,IAAI,SAA2C;CACnD,MAAM,MAAM,QAAQ,OAAO,OAAO,QAAQ,MAAM;EAAE,GAAG,QAAQ;EAAK,GAAG,QAAQ;CAAI;CACjF,MAAM,UAAU;EAAE,KAAK,QAAQ;EAAK;EAAK,OAAO;CAAU;CAC1D,MAAM,QAAQ,QAAQ,UAAU,OAC5B,MAAM,QAAQ,KAAK;EAAE,GAAG;EAAS,OAAO;CAAK,CAAC,IAC9C,MAAM,QAAQ,QAAQ,QAAQ,QAAQ,CAAC,GAAG;EAAE,GAAG;EAAS,OAAO;CAAM,CAAC;CAE1E,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,GAAG,SAAS,MAAM;EACxB,MAAM,GAAG,UAAU,MAAM,WAAW;GAClC,QAAQ,SAAS,UAAU,OAAO,IAAI,IAAI;EAC5C,CAAC;CACH,CAAC;AACH,EACF;;;;;AChCA,MAAM,eAAyC;CAC7C,OAAO;CACP,OAAO;CACP,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;;;AA2BA,MAAa,SAAS,EACpB,OAAO,E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,MAAM,WAAW,KAAK,uCAAuC,aAAa,EAAE;CACrF;CAEA,OAAO,MAAM,KAAK,iBAAiB,OAAO,UAAU,EAAE,GAAG;CACzD,IAAI,QACF,OAAO;CAIT,MAAM,YAAY;GACf,iBAAiB,QAAQ;GACzB,iBAAiB,YAAY,OAAO;GACpC,iBAAiB,aAAa,OAAO;GACrC,iBAAiB,MAAM;GACvB,iBAAiB,WAAW;GAC5B,iBAAiB,OAAO;CAC3B;CACA,MAAM,WAAW,MAAM,SAAS,IAAI;EAAE,GAAG,WAAW;EAAQ;EAAK,KAAK;CAAU,CAAC;CAEjF,IAAI,aAAa,GACf,MAAM,IAAI,MAAM,WAAW,YAAY,qBAAqB,SAAS,EAAE;CAGzE,OAAO;AACT,EACF;;;;;;AAqBA,eAAsB,QAAwC,SAAmF;CAC/I,MAAM,UAAU,eAAe,QAAQ,OAAO;CAE9C,OAAO,SAAS,QAAQ,EAAE,CAAC;EACzB,GAAG;EACH;CACF,CAAC;AACH;;ACrHA,eAAsB,UAAU,SAAmE;CACjG,OAAO,QAAQ;EACb,GAAG;EACH,GAAG;CACL,CAAC;AACH;;;;;ACHA,MAAa,gBAAgB,OAAO,OAAO,EACzC,UACF,CAAC"}
package/dist/cli.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import { n as meta, t as ManagedScript } from "./ManagedScript-DIacNHCc.js";
3
2
  import { createRequire } from "node:module";
4
3
  import tty from "tty";
5
- //#region \0rolldown/runtime.js
4
+ import { n as meta, t as ManagedScript } from "./ManagedScript-B8d632d3.js";
5
+ // \0rolldown/runtime.js
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
8
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
9
  var __getOwnPropNames = Object.getOwnPropertyNames;
10
10
  var __getProtoOf = Object.getPrototypeOf;
11
11
  var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
12
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
13
13
  var __copyProps = (to, from, except, desc) => {
14
14
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
15
  key = keys[i];
@@ -25,8 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  enumerable: true
26
26
  }) : target, mod));
27
27
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
28
- //#endregion
29
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/constants.mjs
28
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/constants.mjs
30
29
  var SpecialToken;
31
30
  (function(SpecialToken) {
32
31
  SpecialToken["StartOfInput"] = "\0";
@@ -45,8 +44,7 @@ const OPTION_REGEX = /^(--[a-z]+(?:-[a-z]+)*|-[a-zA-Z]+)$/;
45
44
  const BATCH_REGEX = /^-[a-zA-Z]{2,}$/;
46
45
  const BINDING_REGEX = /^([^=]+)=([\s\S]*)$/;
47
46
  const IS_DEBUG = process.env.DEBUG_CLI === `1`;
48
- //#endregion
49
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/errors.mjs
47
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/errors.mjs
50
48
  /**
51
49
  * A generic usage error with the name `UsageError`.
52
50
  *
@@ -97,8 +95,7 @@ const whileRunning = (input) => `While running ${input.filter((token) => {
97
95
  if (token.match(/\s/) || token.length === 0 || json !== `"${token}"`) return json;
98
96
  else return token;
99
97
  }).join(` `)}`;
100
- //#endregion
101
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/utils.mjs
98
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/utils.mjs
102
99
  const isOptionSymbol = Symbol(`clipanion/isOption`);
103
100
  function makeCommandOption(spec) {
104
101
  return {
@@ -140,8 +137,7 @@ function applyValidator(name, value, validator) {
140
137
  for (const [, op] of coercions) op();
141
138
  return value;
142
139
  }
143
- //#endregion
144
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/Command.mjs
140
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/Command.mjs
145
141
  /**
146
142
  * Base abstract class for CLI commands. The main thing to remember is to
147
143
  * declare an async `execute` member function that will be called when the
@@ -202,8 +198,7 @@ Command.isOption = isOptionSymbol;
202
198
  * }
203
199
  */
204
200
  Command.Default = [];
205
- //#endregion
206
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/platform/node.mjs
201
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/platform/node.mjs
207
202
  function getDefaultColorDepth() {
208
203
  if (tty && `getColorDepth` in tty.WriteStream.prototype) return tty.WriteStream.prototype.getColorDepth();
209
204
  if (process.env.FORCE_COLOR === `0`) return 1;
@@ -235,8 +230,7 @@ function getCaptureActivator(context) {
235
230
  return contextStorage.run(context, fn);
236
231
  };
237
232
  }
238
- //#endregion
239
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/core.mjs
233
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/core.mjs
240
234
  function debug(str) {
241
235
  if (IS_DEBUG) console.log(str);
242
236
  }
@@ -1060,8 +1054,7 @@ var CliBuilder = class CliBuilder {
1060
1054
  };
1061
1055
  }
1062
1056
  };
1063
- //#endregion
1064
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/format.mjs
1057
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/format.mjs
1065
1058
  const richLine = Array(80).fill(`━`);
1066
1059
  for (let t = 0; t <= 24; ++t) richLine[richLine.length - t] = `\x1b[38;5;${232 + t}m━`;
1067
1060
  const richFormat = {
@@ -1111,8 +1104,7 @@ function formatMarkdownish(text, { format, paragraphs }) {
1111
1104
  });
1112
1105
  return text ? `${text}\n` : ``;
1113
1106
  }
1114
- //#endregion
1115
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/HelpCommand.mjs
1107
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/HelpCommand.mjs
1116
1108
  var HelpCommand$1 = class HelpCommand$1 extends Command {
1117
1109
  static from(state, contexts) {
1118
1110
  const command = new HelpCommand$1(contexts);
@@ -1145,8 +1137,7 @@ var HelpCommand$1 = class HelpCommand$1 extends Command {
1145
1137
  }
1146
1138
  }
1147
1139
  };
1148
- //#endregion
1149
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/Cli.mjs
1140
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/Cli.mjs
1150
1141
  const errorCommandSymbol = Symbol(`clipanion/errorCommand`);
1151
1142
  /**
1152
1143
  * @template Context The context shared by all commands. Contexts are a set of values, defined when calling the `run`/`runExit` functions from the CLI instance, that will be made available to the commands via `this.context`.
@@ -1506,8 +1497,7 @@ Cli.defaultContext = {
1506
1497
  function noopCaptureActivator(fn) {
1507
1498
  return fn();
1508
1499
  }
1509
- //#endregion
1510
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/builtins/help.mjs
1500
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/builtins/help.mjs
1511
1501
  /**
1512
1502
  * A command that prints the usage of all commands.
1513
1503
  *
@@ -1519,8 +1509,7 @@ var HelpCommand = class extends Command {
1519
1509
  }
1520
1510
  };
1521
1511
  HelpCommand.paths = [[`-h`], [`--help`]];
1522
- //#endregion
1523
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/builtins/version.mjs
1512
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/builtins/version.mjs
1524
1513
  /**
1525
1514
  * A command that prints the version of the binary (`cli.binaryVersion`).
1526
1515
  *
@@ -1533,8 +1522,7 @@ var VersionCommand = class extends Command {
1533
1522
  }
1534
1523
  };
1535
1524
  VersionCommand.paths = [[`-v`], [`--version`]];
1536
- //#endregion
1537
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/Boolean.mjs
1525
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/Boolean.mjs
1538
1526
  function Boolean(descriptor, initialValueBase, optsBase) {
1539
1527
  const [initialValue, opts] = rerouteArguments(initialValueBase, optsBase !== null && optsBase !== void 0 ? optsBase : {});
1540
1528
  const optNames = descriptor.split(`,`);
@@ -1560,8 +1548,7 @@ function Boolean(descriptor, initialValueBase, optsBase) {
1560
1548
  }
1561
1549
  });
1562
1550
  }
1563
- //#endregion
1564
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/Rest.mjs
1551
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/Rest.mjs
1565
1552
  /**
1566
1553
  * Used to annotate that the command supports any number of positional
1567
1554
  * arguments.
@@ -1597,8 +1584,7 @@ function Rest(opts = {}) {
1597
1584
  }
1598
1585
  });
1599
1586
  }
1600
- //#endregion
1601
- //#region ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/String.mjs
1587
+ // ../../node_modules/.pnpm/clipanion@4.0.0-rc.4_typanion@3.14.0/node_modules/clipanion/lib/advanced/options/String.mjs
1602
1588
  function StringOption(descriptor, initialValueBase, optsBase) {
1603
1589
  const [initialValue, opts] = rerouteArguments(initialValueBase, optsBase !== null && optsBase !== void 0 ? optsBase : {});
1604
1590
  const { arity = 1 } = opts;
@@ -1657,8 +1643,7 @@ function String$1(descriptor, ...args) {
1657
1643
  if (typeof descriptor === `string`) return StringOption(descriptor, ...args);
1658
1644
  else return StringPositional(descriptor);
1659
1645
  }
1660
- //#endregion
1661
- //#region ../../node_modules/.pnpm/typanion@3.14.0/node_modules/typanion/lib/index.js
1646
+ // ../../node_modules/.pnpm/typanion@3.14.0/node_modules/typanion/lib/index.js
1662
1647
  var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
1663
1648
  Object.defineProperty(exports, "__esModule", { value: true });
1664
1649
  const simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
@@ -2703,8 +2688,7 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
2703
2688
  exports.matchesRegExp = matchesRegExp;
2704
2689
  exports.softAssert = softAssert;
2705
2690
  }));
2706
- //#endregion
2707
- //#region src/cli/RootCommand.ts
2691
+ // src/cli/RootCommand.ts
2708
2692
  var import_lib = require_lib();
2709
2693
  const isLogLevel = (0, import_lib.isEnum)([
2710
2694
  "debug",
@@ -2722,7 +2706,7 @@ var RootCommand = class extends Command {
2722
2706
  static paths = [Command.Default];
2723
2707
  static usage = Command.Usage({
2724
2708
  description: "Run a script from the managed-script configuration.",
2725
- details: "Resolves the script name from the first positional argument, MANAGED_SCRIPT_NAME or npm_lifecycle_event, then executes it. Use --dry-run,-n to print the resolved command without executing it. Use --loglevel, --silent,-s or --verbose,-v to control status messages, forwarded to the script as MANAGED_SCRIPT_LOGLEVEL. Use --color[=WHEN] or --no-color to control ANSI colors (WHEN: auto, always, never)."
2709
+ details: "Resolves the script name from the first positional argument or npm_lifecycle_event, then executes it. Use --dry-run,-n to print the resolved command without executing it. Use --loglevel, --silent,-s or --verbose,-v to control status messages, forwarded to the script as MANAGED_SCRIPT_LOGLEVEL. Use --color[=WHEN] or --no-color to control ANSI colors (WHEN: auto, always, never)."
2726
2710
  });
2727
2711
  color = String$1("--color", {
2728
2712
  description: "Control ANSI colors (auto, always, never). Bare --color means always.",
@@ -2762,8 +2746,11 @@ var RootCommand = class extends Command {
2762
2746
  dryRun: this.dryRun,
2763
2747
  logLevel
2764
2748
  },
2765
- stderr: this.context.stderr,
2766
- stdout: this.context.stdout
2749
+ stdio: [
2750
+ "inherit",
2751
+ this.context.stdout,
2752
+ this.context.stderr
2753
+ ]
2767
2754
  },
2768
2755
  parameters: {
2769
2756
  scriptArgs,
@@ -2777,8 +2764,7 @@ var RootCommand = class extends Command {
2777
2764
  }
2778
2765
  }
2779
2766
  };
2780
- //#endregion
2781
- //#region src/cli/runCLI.ts
2767
+ // src/cli/runCLI.ts
2782
2768
  async function runCLI() {
2783
2769
  const cli = new Cli({
2784
2770
  binaryLabel: meta.binaryLabel,
@@ -2799,10 +2785,8 @@ async function runCLI() {
2799
2785
  process.exitCode = 1;
2800
2786
  }
2801
2787
  }
2802
- //#endregion
2803
- //#region src/cli.ts
2788
+ // src/cli.ts
2804
2789
  runCLI();
2805
- //#endregion
2806
2790
  export {};
2807
2791
 
2808
2792
  //# sourceMappingURL=cli.js.map