politty 0.11.3 → 0.11.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.
- package/README.md +20 -4
- package/dist/{arg-registry-D558cYkD.d.ts → arg-registry-SrNIsq-d.d.ts} +41 -10
- package/dist/augment.d.ts +1 -2
- package/dist/cli-main.d.ts +1 -0
- package/dist/cli-main.js +86 -0
- package/dist/cli.js +10 -49
- package/dist/compile-cache-NnTkjJMV.js +101 -0
- package/dist/compile-cache.d.ts +79 -0
- package/dist/compile-cache.js +3 -0
- package/dist/completion/index.d.ts +2 -2
- package/dist/completion/index.js +1 -1
- package/dist/{completion-BEGiVJST.js → completion-D9SKGJad.js} +3 -3
- package/dist/docs/index.d.ts +26 -13
- package/dist/docs/index.js +2 -2
- package/dist/{index-CeZ1yI46.d.ts → index-qqwo5WZT.d.ts} +29 -18
- package/dist/index.d.ts +76 -5
- package/dist/index.js +4 -3
- package/dist/prompt/clack/index.d.ts +1 -2
- package/dist/prompt/index.d.ts +1 -2
- package/dist/prompt/inquirer/index.d.ts +1 -2
- package/dist/runner-BGs_QMJM.js +3 -0
- package/dist/{runner-cEPqI3qs.js → runner-xN7248Ph.js} +24 -30
- package/dist/skill/index.d.ts +13 -7
- package/dist/skill/index.js +1 -1
- package/dist/src-BiCtSNrn.js +193 -0
- package/package.json +14 -10
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { S as Command, Y as ResolvedFieldMeta, _ as AnyCommand, d as ResolvedExpandCandidate, h as DynamicCompletionResolver, u as ExpandCompletion, y as ArgsSchema } from "./arg-registry-
|
|
1
|
+
import { S as Command, Y as ResolvedFieldMeta, _ as AnyCommand, d as ResolvedExpandCandidate, h as DynamicCompletionResolver, u as ExpandCompletion, y as ArgsSchema } from "./arg-registry-SrNIsq-d.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/completion/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* A single resolved entry in an "expand" lookup table.
|
|
@@ -99,8 +98,11 @@ interface CompletionOptions {
|
|
|
99
98
|
* without narrowing first.
|
|
100
99
|
*/
|
|
101
100
|
type ValueCompletion = ({
|
|
102
|
-
/** Completion type */
|
|
103
|
-
choices
|
|
101
|
+
/** Completion type */
|
|
102
|
+
type: "choices" | "file" | "directory" | "command" | "none";
|
|
103
|
+
/** List of valid choices (for "choices" type) */
|
|
104
|
+
choices?: string[];
|
|
105
|
+
/** Shell command for dynamic completion (for "command" type) */
|
|
104
106
|
shellCommand?: string;
|
|
105
107
|
resolve?: never;
|
|
106
108
|
dependsOn?: never;
|
|
@@ -109,10 +111,11 @@ type ValueCompletion = ({
|
|
|
109
111
|
extensions?: string[];
|
|
110
112
|
matcher?: never;
|
|
111
113
|
} | {
|
|
112
|
-
/** Glob patterns for file matching (for "file" type) */matcher?: string[];
|
|
114
|
+
/** Glob patterns for file matching (for "file" type) */ matcher?: string[];
|
|
113
115
|
extensions?: never;
|
|
114
116
|
})) | {
|
|
115
|
-
/** In-process dynamic completion via JS callback. */
|
|
117
|
+
/** In-process dynamic completion via JS callback. */
|
|
118
|
+
type: "dynamic";
|
|
116
119
|
resolve: DynamicCompletionResolver;
|
|
117
120
|
choices?: never;
|
|
118
121
|
shellCommand?: never;
|
|
@@ -329,13 +332,21 @@ declare function parseCompletionContext(argv: string[], rootCommand: AnyCommand,
|
|
|
329
332
|
* Completion directive flags (bitwise)
|
|
330
333
|
*/
|
|
331
334
|
declare const CompletionDirective: {
|
|
332
|
-
/** Default completion behavior */
|
|
333
|
-
readonly
|
|
334
|
-
|
|
335
|
-
readonly
|
|
336
|
-
|
|
337
|
-
readonly
|
|
338
|
-
|
|
335
|
+
/** Default completion behavior */
|
|
336
|
+
readonly Default: 0;
|
|
337
|
+
/** Don't add space after completion */
|
|
338
|
+
readonly NoSpace: 1;
|
|
339
|
+
/** Don't offer file completion (even if no other completions) */
|
|
340
|
+
readonly NoFileCompletion: 2;
|
|
341
|
+
/** Filter completions using current word as prefix */
|
|
342
|
+
readonly FilterPrefix: 4;
|
|
343
|
+
/** Keep the order of completions */
|
|
344
|
+
readonly KeepOrder: 8;
|
|
345
|
+
/** Trigger file completion */
|
|
346
|
+
readonly FileCompletion: 16;
|
|
347
|
+
/** Trigger directory completion */
|
|
348
|
+
readonly DirectoryCompletion: 32;
|
|
349
|
+
/** Error occurred during completion */
|
|
339
350
|
readonly Error: 64;
|
|
340
351
|
};
|
|
341
352
|
/**
|
|
@@ -392,8 +403,8 @@ declare function generateCandidates(context: CompletionContext, options: Generat
|
|
|
392
403
|
declare const completeArgsSchema: z.ZodObject<{
|
|
393
404
|
shell: z.ZodEnum<{
|
|
394
405
|
bash: "bash";
|
|
395
|
-
zsh: "zsh";
|
|
396
406
|
fish: "fish";
|
|
407
|
+
zsh: "zsh";
|
|
397
408
|
}>;
|
|
398
409
|
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
399
410
|
}, z.core.$strip>;
|
|
@@ -551,8 +562,8 @@ declare function detectShell(): ShellType | null;
|
|
|
551
562
|
declare const completionArgsSchema: z.ZodObject<{
|
|
552
563
|
shell: z.ZodOptional<z.ZodEnum<{
|
|
553
564
|
bash: "bash";
|
|
554
|
-
zsh: "zsh";
|
|
555
565
|
fish: "fish";
|
|
566
|
+
zsh: "zsh";
|
|
556
567
|
}>>;
|
|
557
568
|
instructions: z.ZodDefault<z.ZodBoolean>;
|
|
558
569
|
loader: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -565,8 +576,8 @@ type CompletionArgs = z.infer<typeof completionArgsSchema>;
|
|
|
565
576
|
declare const refreshArgsSchema: z.ZodObject<{
|
|
566
577
|
shell: z.ZodEnum<{
|
|
567
578
|
bash: "bash";
|
|
568
|
-
zsh: "zsh";
|
|
569
579
|
fish: "fish";
|
|
580
|
+
zsh: "zsh";
|
|
570
581
|
}>;
|
|
571
582
|
target: z.ZodOptional<z.ZodString>;
|
|
572
583
|
static: z.ZodDefault<z.ZodBoolean>;
|
|
@@ -576,8 +587,8 @@ type RefreshArgs = z.infer<typeof refreshArgsSchema>;
|
|
|
576
587
|
declare const workerPathArgsSchema: z.ZodObject<{
|
|
577
588
|
shell: z.ZodEnum<{
|
|
578
589
|
bash: "bash";
|
|
579
|
-
zsh: "zsh";
|
|
580
590
|
fish: "fish";
|
|
591
|
+
zsh: "zsh";
|
|
581
592
|
}>;
|
|
582
593
|
}, z.core.$strip>;
|
|
583
594
|
type WorkerPathArgs = z.infer<typeof workerPathArgsSchema>;
|
|
@@ -659,4 +670,4 @@ interface WithCompletionOptions {
|
|
|
659
670
|
declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
|
|
660
671
|
//#endregion
|
|
661
672
|
export { BundledWorkerOptions as A, CandidateResult as C, CompletionContext as D, generateCandidates as E, CompletionMode as F, CompletionOptions as I, CompletionResult as L, CompletableSubcommand as M, CompletionData as N, CompletionType as O, CompletionGenerator as P, ShellType as R, hasCompleteCommand as S, CompletionDirective as T, extractCompletionData as _, detectShell as a, formatForShell as b, withCompletionCommand as c, GenerateBundledCompletionWorkerOptions as d, GenerateBundledCompletionWorkerResult as f, validateBundledWorkerFile as g, generateBundledCompletionWorker as h, createRefreshCompletionCommand as i, CompletableOption as j, parseCompletionContext as k, ValueCompletionField as l, defaultBundledWorkerOutputPath as m, createCompletionCommand as n, generateCompletion as o, bundledWorkerShellExtension as p, createCompletionWorkerPathCommand as r, getSupportedShells as s, WithCompletionOptions as t, resolveValueCompletion as u, extractPositionals as v, CompletionCandidate as w, createDynamicCompleteCommand as x, ShellFormatOptions as y };
|
|
662
|
-
//# sourceMappingURL=index-
|
|
673
|
+
//# sourceMappingURL=index-qqwo5WZT.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
|
-
import { $ as toCamelCase, A as LogLevel, B as RunnableCommand, C as CommandBase, D as GlobalSetupContext, E as GlobalCleanupContext, F as PromptResolver, G as LazyCommand, H as SubCommandValue, I as RunCommandOptions, J as ExtractedFields, K as isLazyCommand, L as RunResult, M as Logger, N as MainOptions, O as IsEmpty, P as NonRunnableCommand, Q as getUnknownKeysMode, R as RunResultFailure, S as Command, T as GlobalArgs, U as SubCommandsRecord, V as SetupContext, W as UnknownSubcommandHandler, X as UnknownKeysMode, Y as ResolvedFieldMeta, Z as extractFields, _ as AnyCommand, a as EffectContext, b as CleanupContext, c as arg, d as ResolvedExpandCandidate, et as toKebabCase, f as CompletionDirectiveMask, g as DynamicCompletionResult, h as DynamicCompletionResolver, i as CustomCompletion, j as LogStream, k as LogEntry, l as ExpandCandidate, m as DynamicCompletionContext, n as CompletionMeta, o as PromptMeta, p as DynamicCompletionCandidate, q as lazy, r as CompletionType, s as PromptType, t as ArgMeta, u as ExpandCompletion, v as ArgSource, w as Example, x as CollectedLogs, y as ArgsSchema, z as RunResultSuccess } from "./arg-registry-
|
|
2
|
-
import { I as CompletionOptions, L as CompletionResult, c as withCompletionCommand, d as GenerateBundledCompletionWorkerOptions, f as GenerateBundledCompletionWorkerResult, h as generateBundledCompletionWorker, o as generateCompletion, t as WithCompletionOptions } from "./index-
|
|
1
|
+
import { $ as toCamelCase, A as LogLevel, B as RunnableCommand, C as CommandBase, D as GlobalSetupContext, E as GlobalCleanupContext, F as PromptResolver, G as LazyCommand, H as SubCommandValue, I as RunCommandOptions, J as ExtractedFields, K as isLazyCommand, L as RunResult, M as Logger, N as MainOptions, O as IsEmpty, P as NonRunnableCommand, Q as getUnknownKeysMode, R as RunResultFailure, S as Command, T as GlobalArgs, U as SubCommandsRecord, V as SetupContext, W as UnknownSubcommandHandler, X as UnknownKeysMode, Y as ResolvedFieldMeta, Z as extractFields, _ as AnyCommand, a as EffectContext, b as CleanupContext, c as arg, d as ResolvedExpandCandidate, et as toKebabCase, f as CompletionDirectiveMask, g as DynamicCompletionResult, h as DynamicCompletionResolver, i as CustomCompletion, j as LogStream, k as LogEntry, l as ExpandCandidate, m as DynamicCompletionContext, n as CompletionMeta, o as PromptMeta, p as DynamicCompletionCandidate, q as lazy, r as CompletionType, s as PromptType, t as ArgMeta, u as ExpandCompletion, v as ArgSource, w as Example, x as CollectedLogs, y as ArgsSchema, z as RunResultSuccess } from "./arg-registry-SrNIsq-d.js";
|
|
2
|
+
import { I as CompletionOptions, L as CompletionResult, c as withCompletionCommand, d as GenerateBundledCompletionWorkerOptions, f as GenerateBundledCompletionWorkerResult, h as generateBundledCompletionWorker, o as generateCompletion, t as WithCompletionOptions } from "./index-qqwo5WZT.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
|
|
4
|
+
//#region src/compile-cache-shim.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generator for compile-cache bin shims.
|
|
7
|
+
*
|
|
8
|
+
* Emits the minimal entry file described in docs/recipes.md ("Faster
|
|
9
|
+
* Startup"): a shim that enables the Node.js on-disk compile cache via
|
|
10
|
+
* `politty/compile-cache` and then loads the real CLI with a dynamic
|
|
11
|
+
* import. Meant to be wired into a `postbuild` or `prepack` script via
|
|
12
|
+
* `politty generate-shim` so the shim never has to live in source.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Options for {@link generateCompileCacheShim}.
|
|
16
|
+
*/
|
|
17
|
+
interface GenerateCompileCacheShimOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Module specifier(s) the shim imports to start the CLI, relative to the
|
|
20
|
+
* generated shim file (e.g. `./cli.js`). Pass one per shim; when `out` is
|
|
21
|
+
* omitted the count must match the package's `bin` entries (paired in
|
|
22
|
+
* order). Defaults to the first of `./cli.js`, `./cli.mjs`, `./index.js`,
|
|
23
|
+
* `./index.mjs` that exists next to each shim.
|
|
24
|
+
*/
|
|
25
|
+
entry?: string | string[];
|
|
26
|
+
/**
|
|
27
|
+
* Output path(s) for the generated shim(s) (e.g. `dist/bin.js`). When
|
|
28
|
+
* given, the count must match `entry` (paired in order). Defaults to all
|
|
29
|
+
* `bin` paths in the nearest `package.json` — the places the executables
|
|
30
|
+
* must live.
|
|
31
|
+
*/
|
|
32
|
+
out?: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* Program name used to derive the cache directory, applied to every
|
|
35
|
+
* generated shim. Defaults per shim to the `bin` name whose path is the
|
|
36
|
+
* shim's output, falling back to the first `bin` name and then the
|
|
37
|
+
* package name without its scope. The fallback never happens silently: a
|
|
38
|
+
* warning is printed when an explicit `out` path cannot be matched to a
|
|
39
|
+
* `bin` entry.
|
|
40
|
+
*/
|
|
41
|
+
program?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Base directory for resolving paths and locating the nearest
|
|
44
|
+
* `package.json` (default: `process.cwd()`).
|
|
45
|
+
*/
|
|
46
|
+
cwd?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* One generated shim from {@link generateCompileCacheShim}.
|
|
50
|
+
*/
|
|
51
|
+
interface GenerateCompileCacheShimResult {
|
|
52
|
+
/** Absolute path of the generated shim. */
|
|
53
|
+
outputPath: string;
|
|
54
|
+
/** Program name baked into the shim. */
|
|
55
|
+
program: string;
|
|
56
|
+
/** Entry specifier baked into the shim. */
|
|
57
|
+
entry: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate executable compile-cache bin shims.
|
|
61
|
+
*
|
|
62
|
+
* With no explicit paths, one shim is generated per `bin` entry of the
|
|
63
|
+
* nearest `package.json`, each importing a conventional built module next
|
|
64
|
+
* to it — so a bare `politty generate-shim` in a `postbuild` script is
|
|
65
|
+
* usually enough. Explicit `entry` values are paired in order with the
|
|
66
|
+
* `bin` entries (or with explicit `out` values of the same count).
|
|
67
|
+
*
|
|
68
|
+
* The generated files are ESM (they use top-level `await import`), so `.js`
|
|
69
|
+
* output requires `"type": "module"` in the package; use a `.mjs` extension
|
|
70
|
+
* otherwise. Refuses to overwrite an existing file it did not generate, so
|
|
71
|
+
* a `bin` path still pointing at the real CLI entry fails loudly instead of
|
|
72
|
+
* clobbering the build output.
|
|
73
|
+
*/
|
|
74
|
+
declare function generateCompileCacheShim(options?: GenerateCompileCacheShimOptions): GenerateCompileCacheShimResult[];
|
|
75
|
+
//#endregion
|
|
5
76
|
//#region src/core/case-types.d.ts
|
|
6
77
|
/**
|
|
7
78
|
* TypeScript utility types for case conversion between camelCase and kebab-case.
|
|
@@ -56,7 +127,7 @@ type KebabCase<S extends string> = StripLeadingHyphen<KebabCaseInner<S>>;
|
|
|
56
127
|
* Keys that are identical in both cases (e.g. single-word keys) are not duplicated.
|
|
57
128
|
* Uses a distributive conditional type so it works correctly with discriminated unions.
|
|
58
129
|
*/
|
|
59
|
-
type WithCaseVariants<T> = T extends unknown ? T & { [K in keyof T as CamelCase<K & string>]: T[K] } & { [K in keyof T as KebabCase<K & string>]: T[K] } : never;
|
|
130
|
+
type WithCaseVariants<T> = T extends unknown ? T & { [K in keyof T as CamelCase<K & string>]: T[K]; } & { [K in keyof T as KebabCase<K & string>]: T[K]; } : never;
|
|
60
131
|
//#endregion
|
|
61
132
|
//#region src/core/case-proxy.d.ts
|
|
62
133
|
/**
|
|
@@ -743,5 +814,5 @@ type ValidationResult<T> = {
|
|
|
743
814
|
*/
|
|
744
815
|
declare function formatValidationErrors(errors: ValidationError[]): string;
|
|
745
816
|
//#endregion
|
|
746
|
-
export { type AnyCommand, type ArgMeta, type ArgSource, type ArgsSchema, type BuiltinOptionDescriptions, type CamelCase, CaseVariantCollisionError, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CustomCompletion, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, FieldTypeConflictError, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpOptions, type KebabCase, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type ParsedArgv, type ParserOptions, PositionalConfigError, type PromptMeta, type PromptResolver, type PromptType, ReservedAliasError, ReservedFieldNameError, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, validateReservedFieldNames, withCompletionCommand };
|
|
817
|
+
export { type AnyCommand, type ArgMeta, type ArgSource, type ArgsSchema, type BuiltinOptionDescriptions, type CamelCase, CaseVariantCollisionError, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CustomCompletion, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, FieldTypeConflictError, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpOptions, type KebabCase, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type ParsedArgv, type ParserOptions, PositionalConfigError, type PromptMeta, type PromptResolver, type PromptType, ReservedAliasError, ReservedFieldNameError, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompileCacheShim, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, validateReservedFieldNames, withCompletionCommand };
|
|
747
818
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as generateCompileCacheShim } from "./src-BiCtSNrn.js";
|
|
2
2
|
import { a as toCamelCase, i as getUnknownKeysMode, o as toKebabCase, s as arg, t as extractFields } from "./schema-extractor-wzJ1cGon.js";
|
|
3
3
|
import { n as defineCommand, t as createDefineCommand } from "./command-B4yA4LXX.js";
|
|
4
4
|
import { o as isLazyCommand, s as lazy } from "./subcommand-router-CTzHPGzF.js";
|
|
5
|
-
import { a as generateCompletion, p as generateBundledCompletionWorker, s as withCompletionCommand } from "./completion-
|
|
5
|
+
import { a as generateCompletion, p as generateBundledCompletionWorker, s as withCompletionCommand } from "./completion-D9SKGJad.js";
|
|
6
|
+
import { C as generateHelp, E as createDualCaseProxy, S as ReservedFieldNameError, T as renderMarkdown, _ as DuplicateFieldError, a as formatCommandValidationErrors, b as PositionalConfigError, c as validateCrossSchemaCollisions, d as validateDuplicateNegations, f as validatePositionalConfig, g as DuplicateAliasError, h as CaseVariantCollisionError, i as parseArgv, l as validateDuplicateAliases, m as validateReservedFieldNames, n as runMain, o as validateCaseVariantCollisions, p as validateReservedAliases, r as formatValidationErrors, s as validateCommand, t as runCommand, u as validateDuplicateFields, v as DuplicateNegationError, w as renderInline, x as ReservedAliasError, y as FieldTypeConflictError } from "./runner-xN7248Ph.js";
|
|
6
7
|
import { a as symbols, i as styles, n as logger, r as setColorEnabled, t as isColorEnabled } from "./logger-DbDkjdfO.js";
|
|
7
8
|
|
|
8
|
-
export { CaseVariantCollisionError, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, FieldTypeConflictError, PositionalConfigError, ReservedAliasError, ReservedFieldNameError, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, validateReservedFieldNames, withCompletionCommand };
|
|
9
|
+
export { CaseVariantCollisionError, DuplicateAliasError, DuplicateFieldError, DuplicateNegationError, FieldTypeConflictError, PositionalConfigError, ReservedAliasError, ReservedFieldNameError, arg, createDefineCommand, createDualCaseProxy, defineCommand, extractFields, formatCommandValidationErrors, formatValidationErrors, generateBundledCompletionWorker, generateCompileCacheShim, generateCompletion, generateHelp, getUnknownKeysMode, isColorEnabled, isLazyCommand, lazy, logger, parseArgv, renderInline, renderMarkdown, runCommand, runMain, setColorEnabled, styles, symbols, toCamelCase, toKebabCase, validateCaseVariantCollisions, validateCommand, validateCrossSchemaCollisions, validateDuplicateAliases, validateDuplicateFields, validateDuplicateNegations, validatePositionalConfig, validateReservedAliases, validateReservedFieldNames, withCompletionCommand };
|
package/dist/prompt/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { J as ExtractedFields, Y as ResolvedFieldMeta } from "../arg-registry-
|
|
2
|
-
|
|
1
|
+
import { J as ExtractedFields, Y as ResolvedFieldMeta } from "../arg-registry-SrNIsq-d.js";
|
|
3
2
|
//#region src/prompt/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Resolved prompt configuration for a single field
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { a as toCamelCase, n as getAllAliases, o as toKebabCase, r as getExtractedFields, t as extractFields } from "./schema-extractor-wzJ1cGon.js";
|
|
2
2
|
import { a as resolveSubcommandWithAlias, c as resolveSubCommandMeta, n as listSubCommands, o as isLazyCommand, r as resolveLazyCommand, t as listSubCommandNamesWithAliases } from "./subcommand-router-CTzHPGzF.js";
|
|
3
|
+
import { n as enableCompileCache } from "./compile-cache-NnTkjJMV.js";
|
|
3
4
|
import { n as emptyLogs, r as mergeLogs, t as createLogCollector } from "./log-collector-DK32-73m.js";
|
|
4
5
|
import { a as symbols, i as styles } from "./logger-DbDkjdfO.js";
|
|
5
6
|
import { stripVTControlCharacters } from "node:util";
|
|
6
7
|
|
|
7
|
-
//#region \0rolldown/runtime.js
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __exportAll = (all, no_symbols) => {
|
|
10
|
-
let target = {};
|
|
11
|
-
for (var name in all) {
|
|
12
|
-
__defProp(target, name, {
|
|
13
|
-
get: all[name],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (!no_symbols) {
|
|
18
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
19
|
-
}
|
|
20
|
-
return target;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
8
|
//#region src/core/case-proxy.ts
|
|
25
9
|
/**
|
|
26
10
|
* Wrap an args object with a Proxy that allows dual-case access.
|
|
@@ -1555,8 +1539,13 @@ function formatCommandValidationErrors(errors) {
|
|
|
1555
1539
|
|
|
1556
1540
|
//#endregion
|
|
1557
1541
|
//#region src/parser/long-option-resolver.ts
|
|
1542
|
+
/** Return a long option's name without leading dashes or an inline value. */
|
|
1543
|
+
function getLongOptionName(arg) {
|
|
1544
|
+
const equalsIndex = arg.indexOf("=");
|
|
1545
|
+
return equalsIndex >= 0 ? arg.slice(2, equalsIndex) : arg.slice(2);
|
|
1546
|
+
}
|
|
1558
1547
|
function resolveLongOption(arg, lookup) {
|
|
1559
|
-
const withoutDashes =
|
|
1548
|
+
const withoutDashes = getLongOptionName(arg);
|
|
1560
1549
|
if (!arg.includes("=")) {
|
|
1561
1550
|
const negatedField = lookup.negationMap.get(withoutDashes);
|
|
1562
1551
|
if (negatedField && lookup.booleanFlags.has(negatedField)) return {
|
|
@@ -1951,13 +1940,13 @@ function scanForSubcommand(argv, subCommandNames, globalExtracted) {
|
|
|
1951
1940
|
suppressedTokens
|
|
1952
1941
|
};
|
|
1953
1942
|
if (arg.startsWith("--")) {
|
|
1954
|
-
const { resolvedName, isNegated, isGlobal, isSuppressedNegation } = resolveGlobalLongOption(arg, lookup);
|
|
1943
|
+
const { resolvedName, withoutDashes, isNegated, isGlobal, isSuppressedNegation } = resolveGlobalLongOption(arg, lookup);
|
|
1955
1944
|
if (isGlobal) {
|
|
1956
1945
|
i += collectGlobalFlag(argv, i, resolvedName, isNegated, lookup.booleanFlags, globalTokensBefore);
|
|
1957
1946
|
continue;
|
|
1958
1947
|
}
|
|
1959
1948
|
if (isSuppressedNegation) {
|
|
1960
|
-
suppressedTokens.push(
|
|
1949
|
+
suppressedTokens.push(withoutDashes);
|
|
1961
1950
|
i++;
|
|
1962
1951
|
continue;
|
|
1963
1952
|
}
|
|
@@ -2253,7 +2242,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
|
|
|
2253
2242
|
continue;
|
|
2254
2243
|
}
|
|
2255
2244
|
if (isSuppressedNegation && !isLocalCollision) {
|
|
2256
|
-
suppressedTokens.push(
|
|
2245
|
+
suppressedTokens.push(withoutDashes);
|
|
2257
2246
|
continue;
|
|
2258
2247
|
}
|
|
2259
2248
|
} else if (arg.startsWith("-") && arg.length > 1) {
|
|
@@ -2392,10 +2381,6 @@ async function runEffects(validatedArgs, extracted, globalArgs) {
|
|
|
2392
2381
|
|
|
2393
2382
|
//#endregion
|
|
2394
2383
|
//#region src/core/runner.ts
|
|
2395
|
-
var runner_exports = /* @__PURE__ */ __exportAll({
|
|
2396
|
-
runCommand: () => runCommand,
|
|
2397
|
-
runMain: () => runMain
|
|
2398
|
-
});
|
|
2399
2384
|
/**
|
|
2400
2385
|
* Default logger using console
|
|
2401
2386
|
*/
|
|
@@ -2547,6 +2532,7 @@ function isInternalSubcommandInvocation(command, argv, globalExtracted) {
|
|
|
2547
2532
|
* ```
|
|
2548
2533
|
*/
|
|
2549
2534
|
async function runMain(command, options = {}) {
|
|
2535
|
+
if (options.compileCache !== false) enableCompileCache(typeof options.compileCache === "string" ? { cacheDir: options.compileCache } : { programName: command.name });
|
|
2550
2536
|
if (command.runMainHook) try {
|
|
2551
2537
|
command.runMainHook(process.argv.slice(2));
|
|
2552
2538
|
} catch {}
|
|
@@ -2571,7 +2557,8 @@ async function runMain(command, options = {}) {
|
|
|
2571
2557
|
const exitCode = await effectiveOptions.onUnknownSubcommand({
|
|
2572
2558
|
commandPath: [],
|
|
2573
2559
|
name,
|
|
2574
|
-
args: forwardArgs
|
|
2560
|
+
args: forwardArgs,
|
|
2561
|
+
precedingArgs: argv.slice(0, positionalIndex)
|
|
2575
2562
|
});
|
|
2576
2563
|
if (typeof exitCode === "number") {
|
|
2577
2564
|
await flushStandardStreams();
|
|
@@ -2664,7 +2651,8 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2664
2651
|
const exitCode = await options.onUnknownSubcommand({
|
|
2665
2652
|
commandPath: nestedCommandPath,
|
|
2666
2653
|
name,
|
|
2667
|
-
args: forwardArgs
|
|
2654
|
+
args: forwardArgs,
|
|
2655
|
+
precedingArgs: [...options._precedingArgs ?? [], ...argv.slice(0, positionalIndex)]
|
|
2668
2656
|
});
|
|
2669
2657
|
if (typeof exitCode === "number") {
|
|
2670
2658
|
collector?.stop();
|
|
@@ -2761,11 +2749,17 @@ async function runCommandInternal(command, argv, options = {}) {
|
|
|
2761
2749
|
aliasFor: resolved.aliasFor
|
|
2762
2750
|
};
|
|
2763
2751
|
collector?.stop();
|
|
2752
|
+
const suppressedNames = new Set(options._globalExtracted?.unknownKeysMode === "passthrough" ? [] : parseResult.unknownGlobalFlags ?? []);
|
|
2753
|
+
const isSuppressedFlag = (token) => {
|
|
2754
|
+
return token.startsWith("--") && suppressedNames.has(getLongOptionName(token));
|
|
2755
|
+
};
|
|
2756
|
+
const levelPrecedingArgs = argv.slice(0, argv.length - parseResult.remainingArgs.length - 1).filter((token) => !isSuppressedFlag(token));
|
|
2764
2757
|
return runCommandInternal(resolved.command, parseResult.remainingArgs, {
|
|
2765
2758
|
...options,
|
|
2766
2759
|
_context: subContext,
|
|
2767
2760
|
_existingLogs: getCurrentLogs(),
|
|
2768
|
-
_parsedGlobalArgs: accumulatedGlobalArgs
|
|
2761
|
+
_parsedGlobalArgs: accumulatedGlobalArgs,
|
|
2762
|
+
_precedingArgs: [...options._precedingArgs ?? [], ...levelPrecedingArgs]
|
|
2769
2763
|
});
|
|
2770
2764
|
}
|
|
2771
2765
|
}
|
|
@@ -2968,5 +2962,5 @@ function extractAndValidateGlobal(options) {
|
|
|
2968
2962
|
}
|
|
2969
2963
|
|
|
2970
2964
|
//#endregion
|
|
2971
|
-
export {
|
|
2972
|
-
//# sourceMappingURL=runner-
|
|
2965
|
+
export { generateHelp as C, createDualCaseProxy as E, ReservedFieldNameError as S, renderMarkdown as T, DuplicateFieldError as _, formatCommandValidationErrors as a, PositionalConfigError as b, validateCrossSchemaCollisions as c, validateDuplicateNegations as d, validatePositionalConfig as f, DuplicateAliasError as g, CaseVariantCollisionError as h, parseArgv as i, validateDuplicateAliases as l, validateReservedFieldNames as m, runMain as n, validateCaseVariantCollisions as o, validateReservedAliases as p, formatValidationErrors as r, validateCommand as s, runCommand as t, validateDuplicateFields as u, DuplicateNegationError as v, renderInline as w, ReservedAliasError as x, FieldTypeConflictError as y };
|
|
2966
|
+
//# sourceMappingURL=runner-xN7248Ph.js.map
|
package/dist/skill/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { X as UnknownKeysMode, _ as AnyCommand, y as ArgsSchema } from "../arg-registry-
|
|
1
|
+
import { X as UnknownKeysMode, _ as AnyCommand, y as ArgsSchema } from "../arg-registry-SrNIsq-d.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/skill/frontmatter.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Zod schema for SKILL.md frontmatter.
|
|
@@ -357,7 +356,9 @@ interface SkillCommandOptions {
|
|
|
357
356
|
* ```
|
|
358
357
|
*/
|
|
359
358
|
commandMap?: {
|
|
360
|
-
/** Primary name + aliases for `skills add`. Default: `["add", "install"]`. */
|
|
359
|
+
/** Primary name + aliases for `skills add`. Default: `["add", "install"]`. */
|
|
360
|
+
add?: string[];
|
|
361
|
+
/** Primary name + aliases for `skills remove`. Default: `["remove", "uninstall"]`. */
|
|
361
362
|
remove?: string[];
|
|
362
363
|
};
|
|
363
364
|
/**
|
|
@@ -382,10 +383,15 @@ interface SkillCommandOptions {
|
|
|
382
383
|
* ```
|
|
383
384
|
*/
|
|
384
385
|
descriptions?: {
|
|
385
|
-
/** Description for the top-level `skills` command. Default: `"Manage agent skills"`. */
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
/** Description for the top-level `skills` command. Default: `"Manage agent skills"`. */
|
|
387
|
+
skills?: string;
|
|
388
|
+
/** Description for `skills sync`. Default: `"Remove and reinstall all skills from source"`. */
|
|
389
|
+
sync?: string;
|
|
390
|
+
/** Description for `skills add`. Default: `"Install skills from source"`. */
|
|
391
|
+
add?: string;
|
|
392
|
+
/** Description for `skills remove`. Default: `"Remove installed skills"`. */
|
|
393
|
+
remove?: string;
|
|
394
|
+
/** Description for `skills list`. Default: `"List available skills from source"`. */
|
|
389
395
|
list?: string;
|
|
390
396
|
};
|
|
391
397
|
}
|
package/dist/skill/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { s as arg, t as extractFields } from "../schema-extractor-wzJ1cGon.js";
|
|
2
2
|
import { n as defineCommand } from "../command-B4yA4LXX.js";
|
|
3
3
|
import { a as symbols, n as logger } from "../logger-DbDkjdfO.js";
|
|
4
|
-
import { z } from "zod";
|
|
5
4
|
import { copyFileSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, symlinkSync, unlinkSync } from "node:fs";
|
|
6
5
|
import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { z } from "zod";
|
|
7
7
|
import { parse as parse$1 } from "yaml";
|
|
8
8
|
|
|
9
9
|
//#region src/skill/frontmatter.ts
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import "./schema-extractor-wzJ1cGon.js";
|
|
2
|
+
import "./completion-D9SKGJad.js";
|
|
3
|
+
import "./runner-xN7248Ph.js";
|
|
4
|
+
import "./logger-DbDkjdfO.js";
|
|
5
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
//#region src/compile-cache-shim.ts
|
|
10
|
+
/**
|
|
11
|
+
* Generator for compile-cache bin shims.
|
|
12
|
+
*
|
|
13
|
+
* Emits the minimal entry file described in docs/recipes.md ("Faster
|
|
14
|
+
* Startup"): a shim that enables the Node.js on-disk compile cache via
|
|
15
|
+
* `politty/compile-cache` and then loads the real CLI with a dynamic
|
|
16
|
+
* import. Meant to be wired into a `postbuild` or `prepack` script via
|
|
17
|
+
* `politty generate-shim` so the shim never has to live in source.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Marker identifying files this generator wrote (overwrite guard). Must be
|
|
21
|
+
* shim-specific: other politty artifacts (e.g. completion scripts) also say
|
|
22
|
+
* "Generated by politty", and those must never be treated as overwritable.
|
|
23
|
+
*/
|
|
24
|
+
const SHIM_MARKER = "Generated by politty: compile-cache bin shim";
|
|
25
|
+
/** Entry candidates tried, in order, when `entry` is omitted. */
|
|
26
|
+
const DEFAULT_ENTRY_CANDIDATES = [
|
|
27
|
+
"./cli.js",
|
|
28
|
+
"./cli.mjs",
|
|
29
|
+
"./index.js",
|
|
30
|
+
"./index.mjs"
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Read the nearest `package.json`, walking up from `startDir` to the
|
|
34
|
+
* filesystem root. A malformed file is a real error and propagates.
|
|
35
|
+
*/
|
|
36
|
+
function readNearestPackageJson(startDir) {
|
|
37
|
+
let dir = resolve(startDir);
|
|
38
|
+
for (;;) {
|
|
39
|
+
const candidate = join(dir, "package.json");
|
|
40
|
+
if (existsSync(candidate)) return {
|
|
41
|
+
pkg: JSON.parse(readFileSync(candidate, "utf8")),
|
|
42
|
+
dir
|
|
43
|
+
};
|
|
44
|
+
const parent = dirname(dir);
|
|
45
|
+
if (parent === dir) return void 0;
|
|
46
|
+
dir = parent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `bin` entries as `[name, path]` pairs: the object form's entries in
|
|
51
|
+
* declaration order, or the string form as a single pair named after the
|
|
52
|
+
* package (npm's own convention for `"bin": "path"`).
|
|
53
|
+
*/
|
|
54
|
+
function binEntries(pkg) {
|
|
55
|
+
if (!pkg) return [];
|
|
56
|
+
if (typeof pkg.bin === "string" && pkg.bin) {
|
|
57
|
+
const name = defaultProgramName(pkg);
|
|
58
|
+
return name ? [[name, pkg.bin]] : [];
|
|
59
|
+
}
|
|
60
|
+
if (typeof pkg.bin === "object" && pkg.bin !== null) return Object.entries(pkg.bin).filter((pair) => typeof pair[1] === "string" && pair[1] !== "");
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Derive the fallback program name from a package.json: the first `bin`
|
|
65
|
+
* command name when present (that is the name users type in their shell),
|
|
66
|
+
* else the package name without its scope.
|
|
67
|
+
*/
|
|
68
|
+
function defaultProgramName(pkg) {
|
|
69
|
+
if (!pkg) return void 0;
|
|
70
|
+
if (typeof pkg.bin === "object" && pkg.bin !== null) {
|
|
71
|
+
const [first] = Object.keys(pkg.bin);
|
|
72
|
+
if (first) return first;
|
|
73
|
+
}
|
|
74
|
+
if (typeof pkg.name === "string" && pkg.name) {
|
|
75
|
+
const name = pkg.name;
|
|
76
|
+
return name.startsWith("@") ? name.split("/")[1] ?? name : name;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Pick the default entry: the first {@link DEFAULT_ENTRY_CANDIDATES} that
|
|
81
|
+
* exists next to the shim (never the shim itself).
|
|
82
|
+
*/
|
|
83
|
+
function defaultEntry(outputPath) {
|
|
84
|
+
const dir = dirname(outputPath);
|
|
85
|
+
const self = basename(outputPath);
|
|
86
|
+
for (const candidate of DEFAULT_ENTRY_CANDIDATES) {
|
|
87
|
+
if (basename(candidate) === self) continue;
|
|
88
|
+
if (existsSync(join(dir, candidate))) return candidate;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function shimContent(program, entry) {
|
|
92
|
+
return [
|
|
93
|
+
"#!/usr/bin/env node",
|
|
94
|
+
"",
|
|
95
|
+
`// ${SHIM_MARKER}.`,
|
|
96
|
+
"// Enables the Node.js on-disk compile cache (V8 code cache) before the",
|
|
97
|
+
"// CLI module graph is compiled, so warm starts skip recompilation",
|
|
98
|
+
"// (Node >= 22.8.0; silent no-op otherwise).",
|
|
99
|
+
"try {",
|
|
100
|
+
" const { enableCompileCache } = await import(\"politty/compile-cache\");",
|
|
101
|
+
` enableCompileCache(${JSON.stringify(program)});`,
|
|
102
|
+
"} catch {",
|
|
103
|
+
" // politty is not resolvable from here (e.g. a fully bundled CLI) —",
|
|
104
|
+
" // start without the compile cache rather than failing the CLI.",
|
|
105
|
+
"}",
|
|
106
|
+
`await import(${JSON.stringify(entry)});`,
|
|
107
|
+
""
|
|
108
|
+
].join("\n");
|
|
109
|
+
}
|
|
110
|
+
function toArray(value) {
|
|
111
|
+
if (value === void 0) return [];
|
|
112
|
+
return Array.isArray(value) ? value : [value];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generate executable compile-cache bin shims.
|
|
116
|
+
*
|
|
117
|
+
* With no explicit paths, one shim is generated per `bin` entry of the
|
|
118
|
+
* nearest `package.json`, each importing a conventional built module next
|
|
119
|
+
* to it — so a bare `politty generate-shim` in a `postbuild` script is
|
|
120
|
+
* usually enough. Explicit `entry` values are paired in order with the
|
|
121
|
+
* `bin` entries (or with explicit `out` values of the same count).
|
|
122
|
+
*
|
|
123
|
+
* The generated files are ESM (they use top-level `await import`), so `.js`
|
|
124
|
+
* output requires `"type": "module"` in the package; use a `.mjs` extension
|
|
125
|
+
* otherwise. Refuses to overwrite an existing file it did not generate, so
|
|
126
|
+
* a `bin` path still pointing at the real CLI entry fails loudly instead of
|
|
127
|
+
* clobbering the build output.
|
|
128
|
+
*/
|
|
129
|
+
function generateCompileCacheShim(options = {}) {
|
|
130
|
+
const cwd = options.cwd ?? process.cwd();
|
|
131
|
+
const found = readNearestPackageJson(cwd);
|
|
132
|
+
const pkg = found?.pkg;
|
|
133
|
+
const entries = toArray(options.entry);
|
|
134
|
+
const outs = toArray(options.out);
|
|
135
|
+
const bins = binEntries(pkg);
|
|
136
|
+
let outputPaths;
|
|
137
|
+
if (outs.length > 0) {
|
|
138
|
+
if (entries.length > 0 && entries.length !== outs.length) throw new Error(`--entry count (${entries.length}) does not match --out count (${outs.length}); pass one --out per --entry or omit --out entirely.`);
|
|
139
|
+
outputPaths = outs.map((out) => isAbsolute(out) ? out : resolve(cwd, out));
|
|
140
|
+
} else {
|
|
141
|
+
if (bins.length === 0 || found === void 0) throw new Error("Cannot derive the output path: no bin entry in package.json. Pass --out explicitly.");
|
|
142
|
+
if (entries.length > 0 && entries.length !== bins.length) throw new Error(`--entry count (${entries.length}) does not match the package's bin entries (${bins.length}); pass one --entry per bin (in declaration order) or matching --out paths.`);
|
|
143
|
+
outputPaths = bins.map(([, path]) => resolve(found.dir, path));
|
|
144
|
+
}
|
|
145
|
+
if (new Set(outputPaths).size !== outputPaths.length) throw new Error("Duplicate output paths; each shim needs a distinct output file. Check the --out values (or the bin paths in package.json when --out is omitted).");
|
|
146
|
+
const binNameByPath = /* @__PURE__ */ new Map();
|
|
147
|
+
if (found) for (const [name, path] of bins) binNameByPath.set(resolve(found.dir, path), name);
|
|
148
|
+
const warnings = [];
|
|
149
|
+
const plans = outputPaths.map((outputPath, index) => {
|
|
150
|
+
const matchedBinName = binNameByPath.get(outputPath);
|
|
151
|
+
const program = options.program ?? matchedBinName ?? defaultProgramName(pkg);
|
|
152
|
+
if (!program) throw new Error("Cannot derive a program name: no bin or name in package.json. Pass --program explicitly.");
|
|
153
|
+
if (options.program === void 0 && matchedBinName === void 0 && outs.length > 0) warnings.push(`Warning: ${formatShimPath(outputPath, cwd)} does not match any bin path in package.json, so its cache directory uses the program name ${JSON.stringify(program)}. Pass --program to override.`);
|
|
154
|
+
if (outputPath.endsWith(".cjs")) throw new Error("The generated shim is an ES module and cannot be written to a .cjs file. Use a .mjs (or .js in a \"type\": \"module\" package) output path.");
|
|
155
|
+
if (extname(outputPath) === "") throw new Error("The generated shim is an ES module and cannot be written to an extensionless file (it would not load on every supported Node.js version). Use a .mjs (or .js in a \"type\": \"module\" package) output path.");
|
|
156
|
+
if (outputPath.endsWith(".js") && pkg?.type !== "module") throw new Error(pkg === void 0 ? "The generated shim is an ES module, and no package.json was found to confirm .js files are treated as ESM. Write it to a .mjs file instead (e.g. --out dist/bin.mjs)." : "The generated shim is an ES module, but the package is not \"type\": \"module\". Write it to a .mjs file instead (e.g. --out dist/bin.mjs).");
|
|
157
|
+
const entry = entries[index] ?? defaultEntry(outputPath);
|
|
158
|
+
if (entry === void 0) throw new Error(`Cannot derive an entry: none of ${DEFAULT_ENTRY_CANDIDATES.join(", ")} exist next to ${outputPath}. Pass --entry explicitly.`);
|
|
159
|
+
if (!entry.startsWith("./") && !entry.startsWith("../") && !entry.startsWith("file:")) throw new Error(`Invalid entry ${entry}: pass a specifier relative to the shim file ("./..." or "../...") or a file: URL.`);
|
|
160
|
+
let entryPath;
|
|
161
|
+
if (entry.startsWith("file:")) try {
|
|
162
|
+
entryPath = fileURLToPath(entry);
|
|
163
|
+
} catch {
|
|
164
|
+
entryPath = void 0;
|
|
165
|
+
}
|
|
166
|
+
else entryPath = resolve(dirname(outputPath), entry);
|
|
167
|
+
if (entryPath === outputPath) throw new Error(`The shim at ${outputPath} would import itself (entry ${entry}). Point bin at a separate shim path (e.g. dist/bin.js) or pass a different --entry.`);
|
|
168
|
+
if (existsSync(outputPath) && !readFileSync(outputPath, "utf8").includes(SHIM_MARKER)) throw new Error(`Refusing to overwrite ${outputPath}: it exists and was not generated by politty. If bin currently points at your real CLI entry, point it at a separate shim path (e.g. dist/bin.js) or pass --out explicitly.`);
|
|
169
|
+
return {
|
|
170
|
+
outputPath,
|
|
171
|
+
program,
|
|
172
|
+
entry
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
for (const warning of warnings) console.warn(warning);
|
|
176
|
+
for (const { outputPath, program, entry } of plans) {
|
|
177
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
178
|
+
writeFileSync(outputPath, shimContent(program, entry));
|
|
179
|
+
chmodSync(outputPath, 493);
|
|
180
|
+
}
|
|
181
|
+
return plans;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Format a generated path for CLI output: relative to `cwd` when inside it.
|
|
185
|
+
*/
|
|
186
|
+
function formatShimPath(outputPath, cwd) {
|
|
187
|
+
const rel = relative(cwd, outputPath);
|
|
188
|
+
return rel && !rel.startsWith("..") ? rel : outputPath;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
export { generateCompileCacheShim as n, formatShimPath as t };
|
|
193
|
+
//# sourceMappingURL=src-BiCtSNrn.js.map
|