package-management 0.0.16 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,15 +1,26 @@
1
- import { Split } from 'string-ts';
2
1
  import * as async_cache_fn from 'async-cache-fn';
3
2
  import { AsyncCacheFn as AsyncCacheFn$1 } from 'async-cache-fn';
3
+ import { WriteFileOptions } from 'node:fs';
4
4
  import { Options } from 'execa';
5
- import { InstallPackageOptions as InstallPackageOptions$1 } from '@antfu/install-pkg';
6
5
  import { ResolveOptions } from 'mlly';
7
6
  import * as parse_gitignore from 'parse-gitignore';
8
- import * as WST from 'workspace-tools';
9
7
  import { ModificationOptions } from 'jsonc-parser';
8
+ import { parseJSONC, stringifyJSONC, parseJSON5, stringifyJSON5, parseYAML, stringifyYAML, parseTOML, stringifyTOML } from 'confbox';
10
9
  import { StorageValue, TransactionOptions, Snapshot, Storage } from 'unstorage';
11
10
  import { FSStorageOptions } from 'unstorage/drivers/fs-lite';
12
11
 
12
+ /**
13
+ * Returns true if string input type is a literal
14
+ */
15
+ type IsStringLiteral<T extends string> = [T] extends [string] ? [string] extends [T] ? false : Uppercase<T> extends Uppercase<Lowercase<T>> ? Lowercase<T> extends Lowercase<Uppercase<T>> ? true : false : false : false;
16
+
17
+ /**
18
+ * Splits a string into an array of substrings.
19
+ * T: The string to split.
20
+ * delimiter: The delimiter.
21
+ */
22
+ type Split<T extends string, delimiter extends string = ''> = IsStringLiteral<T | delimiter> extends true ? T extends `${infer first}${delimiter}${infer rest}` ? [first, ...Split<rest, delimiter>] : T extends '' ? [] : [T] : string[];
23
+
13
24
  type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? 1 : 0) extends <A>() => A extends A1 ? 1 : 0 ? 1 : 0;
14
25
  type Cast<A1 extends any, A2 extends any> = A1 extends A2 ? A1 : A2;
15
26
  type __<T> = {
@@ -21,6 +32,7 @@ type Prettify<T> = {
21
32
  type ValueOf<T> = T[keyof T];
22
33
  type EnumToLiteral<T extends string | number> = T extends string ? `${T}` : `${T}` extends `${infer N extends number}` ? N : never;
23
34
  type IsUnknown<t> = unknown extends t ? [t] extends [{}] ? false : true : false;
35
+ type IsNever<T> = [T] extends [never] ? true : false;
24
36
  type AnyFunction = (...args: any[]) => any;
25
37
  type StringLiteral<T extends string> = T | (string & {});
26
38
  type Awaitable<T> = T | Promise<T>;
@@ -74,11 +86,55 @@ interface PathOptions {
74
86
  type AsyncCacheFn<TReturn = unknown, TOption extends object | undefined = undefined, C extends "required" | "optional" = "optional"> = AsyncCacheFn$1<TReturn, C extends "optional" ? [TOption | undefined] | [] : [TOption]>;
75
87
  type CheckResult<$data, $error = Error, $data_key extends string = "data", $error_key extends string = "error"> = Prettify<RequireExactlyOne<SingleProp<$data_key, $data> & SingleProp<$error_key, $error>>>;
76
88
 
77
- interface StackFrameOptions {
78
- rootFunctionName?: string;
89
+ interface CallerLocationOptions {
90
+ /**
91
+ * The calling module's own URL — pass `import.meta.url`.
92
+ *
93
+ * This is the reliable answer and skips stack inspection entirely. A module
94
+ * can always name itself; nothing can ask the runtime who called it, which is
95
+ * why the fallback below has to exist at all.
96
+ */
97
+ from?: string | URL;
98
+ /**
99
+ * Name of the public entry point whose caller is wanted, used only when
100
+ * `from` is absent.
101
+ */
102
+ boundaryFunctionName?: string;
103
+ /**
104
+ * Module URLs to treat as this library's own when walking the stack.
105
+ *
106
+ * In a published bundle every internal frame shares one script, so this is
107
+ * redundant there; unbundled, each internal module is its own script and has
108
+ * to say so.
109
+ */
110
+ internalScripts?: string[];
111
+ }
112
+
113
+ /**
114
+ * The calling file's absolute path.
115
+ *
116
+ * Pass `from: import.meta.url` wherever the caller can — that is exact in every
117
+ * runtime, while the stack fallback is Node-only.
118
+ */
119
+ declare const _filename: (options?: CallerLocationOptions) => string | undefined;
120
+ /** The directory of the calling file. */
121
+ declare const _dirname: (options?: CallerLocationOptions) => string | undefined;
122
+
123
+ declare function createFile(filePath: string, data: string, options?: WriteFileOptions): void;
124
+
125
+ interface ReadFileOptions {
126
+ /** @default "utf-8" */
127
+ encoding?: BufferEncoding;
79
128
  }
80
- declare const _filename: (options?: StackFrameOptions) => string | undefined;
81
- declare const _dirname: (options?: StackFrameOptions) => string | undefined;
129
+ declare function readFile(filePath: string, options?: ReadFileOptions): string;
130
+ /**
131
+ * `undefined` is a real answer: a config a tool has never written yet is
132
+ * absent rather than empty, and callers seeding one say so themselves
133
+ * instead of catching a throw to find out.
134
+ */
135
+ declare function readFileSafely(filePath: string, options?: ReadFileOptions): string | undefined;
136
+
137
+ declare function isWritable(filename: string): boolean;
82
138
 
83
139
  interface PackageManagerConfig<ID extends string = string> {
84
140
  id: ID;
@@ -86,6 +142,14 @@ interface PackageManagerConfig<ID extends string = string> {
86
142
  name: string;
87
143
  meta: {
88
144
  lockfile: string | string[];
145
+ /**
146
+ * Distinguishes package managers that share both a command and a lockfile
147
+ * name, where the lockfile alone cannot identify which one a project uses —
148
+ * Yarn Classic and Yarn Berry being the case this exists for.
149
+ *
150
+ * Omit when the lockfile is already unambiguous.
151
+ */
152
+ matchesVersion?: (version: string) => boolean;
89
153
  };
90
154
  runner: string;
91
155
  args: {
@@ -138,9 +202,12 @@ interface ImportPackageData<T = any> extends ImportModuleData<T> {
138
202
  */
139
203
  dev?: boolean;
140
204
  /**
141
- * Additional installation options
205
+ * When enabled, a package already declared as a dependency is not installed
206
+ * again, so a satisfied import map costs no package manager invocations.
207
+ *
208
+ * @default true
142
209
  */
143
- installOptions?: Omit<InstallPackageOptions$1, "dev">;
210
+ checkExists?: boolean;
144
211
  }
145
212
  type ImportOption<T = any> = Module | ImportCallback<T> | ImportModuleData<T> | ImportPackageData<T>;
146
213
  type Module<T = any> = Promise<T>;
@@ -259,6 +326,11 @@ interface PackageManager<ID extends string = PackageManagerId> {
259
326
  cwd?: string;
260
327
  }>;
261
328
  globalVersion: AsyncCacheFn<string | undefined, PackageManagerScriptOptions>;
329
+ /**
330
+ * Whether the installed version is the one this config describes. Always
331
+ * true for managers whose lockfile already identifies them unambiguously.
332
+ */
333
+ matchesVersion: AsyncCacheFn<boolean, PackageManagerScriptOptions>;
262
334
  definePackage: DefinePackageFn;
263
335
  defineImportMap: <T extends ImportMap>(importMap: T, options?: {
264
336
  /**
@@ -270,6 +342,9 @@ interface PackageManager<ID extends string = PackageManagerId> {
270
342
  uninstallPackage: (packageNames: string | string[], options?: UninstallPackageOptions) => Promise<void>;
271
343
  installPackage: (packageNames: string | string[], options?: PackageManagerScriptOptions<"install">) => Promise<void>;
272
344
  }
345
+ declare function definePackageManager<ID extends string>(config: PackageManagerConfig<ID>, options?: {
346
+ cwd?: string;
347
+ }): PackageManager<ID>;
273
348
 
274
349
  interface DetectPackageManagerOptions<$id extends string = PackageManagerId> {
275
350
  /**
@@ -312,20 +387,24 @@ declare function mapPackageManagers<$result, $id extends string = PackageManager
312
387
  declare function filterPackageManagers<$id extends string = PackageManagerId>(packageManagers: PackageManagers<$id>, filterFn: (packageManager: PackageManager<$id>) => Awaitable<boolean>, options?: DetectPackageManagerOptions<$id>): Promise<PackageManager<$id>[]>;
313
388
 
314
389
  type PackageManagerId = (typeof packageManagerConfigs)[number]["id"];
315
- declare const packageManagerConfigs: (PackageManagerConfig<"pnpm"> | PackageManagerConfig<"yarn"> | PackageManagerConfig<"bun"> | PackageManagerConfig<"npm">)[];
390
+ declare const packageManagerConfigs: (PackageManagerConfig<"pnpm"> | PackageManagerConfig<"yarn"> | PackageManagerConfig<"yarn-berry"> | PackageManagerConfig<"bun"> | PackageManagerConfig<"npm">)[];
316
391
  declare function definePackageManagerClient(options: DetectPackageManagerOptions): {
317
- configs: PackageManager<"pnpm" | "yarn" | "bun" | "npm">[];
318
- findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
319
- findPackageManagerSafely: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm"> | undefined, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
320
- detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
321
- detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
322
- detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
323
- globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
324
- filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[]>;
392
+ configs: PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[];
393
+ findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
394
+ findPackageManagerSafely: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
395
+ detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
396
+ detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
397
+ detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
398
+ globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
399
+ filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[]>;
325
400
  mapPackageManagers: <$result>(mapFn: (packageManager: PackageManager) => Awaitable<$result>, options?: DetectPackageManagerOptions) => Promise<Awaited<$result>[]>;
326
401
  };
327
402
 
328
- declare function isPackageDependency(packageName: string | string[]): boolean;
403
+ /**
404
+ * Whether every named package is declared in the nearest package.json,
405
+ * searching up from `cwd`.
406
+ */
407
+ declare function isPackageDependency(packageName: string | string[], options?: PathOptions): boolean;
329
408
 
330
409
  interface AliasDefinition {
331
410
  resolve: ResolvePathAliasFn;
@@ -341,9 +420,20 @@ type AliasMap<TAliases extends AliasDefinitionMap = AliasDefinitionMap> = {
341
420
  } & {
342
421
  [K in keyof TAliases as `${Extract<K, string>}/${NonNullable<TAliases[K]["subpaths"]>[number]["to"]}`]: TAliases[K]["resolve"];
343
422
  };
344
- type ResolvePathAliasFn = (opts?: {
423
+ interface PathAliasResolveOptions {
345
424
  cwd?: string;
346
- }) => string;
425
+ /**
426
+ * The calling module's own URL — `import.meta.url`. Only the caller-relative
427
+ * aliases read it, and only they need it.
428
+ */
429
+ from?: string | URL;
430
+ }
431
+ /**
432
+ * `undefined` is a real answer: an alias can name a location that does not
433
+ * exist in this context, and callers assert on it rather than receiving a
434
+ * path assembled from nothing.
435
+ */
436
+ type ResolvePathAliasFn = (opts?: PathAliasResolveOptions) => string | undefined;
347
437
  type StringKeyOf<T> = Extract<keyof T, string>;
348
438
  declare function definePathAliases<const T extends AliasDefinitionMap>(aliasDefinitions: T): {
349
439
  aliasDefinitions: T;
@@ -355,6 +445,14 @@ interface GetPathOptions<TAlias extends string, TValidate extends boolean = fals
355
445
  to: PathTo<TAlias>;
356
446
  startingFrom?: PathTo<TAlias>;
357
447
  cwd?: string;
448
+ /**
449
+ * The calling module's own URL — `import.meta.url`.
450
+ *
451
+ * Required in any runtime without `node:util`'s call sites, and worth
452
+ * passing regardless: a module naming itself is exact, whereas inferring the
453
+ * caller from the stack is a best effort.
454
+ */
455
+ from?: string | URL;
358
456
  checkExistence?: TValidate;
359
457
  glob?: TGlob;
360
458
  }
@@ -415,9 +513,7 @@ type PickPathAlias<K extends PathAlias> = K;
415
513
  type PredefinedPathAliases = typeof predefinedPathAliases;
416
514
  declare const predefinedPathAliases: {
417
515
  readonly "<workspace_folder>": {
418
- readonly resolve: (opts: {
419
- cwd?: string;
420
- } | undefined) => string;
516
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string;
421
517
  readonly subpaths: [{
422
518
  readonly to: "node_modules";
423
519
  }, {
@@ -425,9 +521,7 @@ declare const predefinedPathAliases: {
425
521
  }];
426
522
  };
427
523
  readonly "<workspace_folder?>": {
428
- readonly resolve: (opts: {
429
- cwd?: string;
430
- } | undefined) => string;
524
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string;
431
525
  readonly subpaths: [{
432
526
  readonly to: "node_modules";
433
527
  }, {
@@ -435,9 +529,7 @@ declare const predefinedPathAliases: {
435
529
  }];
436
530
  };
437
531
  readonly "<package_folder>": {
438
- readonly resolve: (opts: {
439
- cwd?: string;
440
- } | undefined) => string;
532
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string | undefined;
441
533
  readonly subpaths: [{
442
534
  readonly to: "node_modules";
443
535
  }, {
@@ -447,9 +539,7 @@ declare const predefinedPathAliases: {
447
539
  }];
448
540
  };
449
541
  readonly "<gitroot_folder>": {
450
- readonly resolve: (opts: {
451
- cwd?: string;
452
- } | undefined) => string;
542
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string;
453
543
  readonly subpaths: [{
454
544
  readonly to: "node_modules";
455
545
  }, {
@@ -471,11 +561,11 @@ declare const predefinedPathAliases: {
471
561
  readonly subpaths: any[];
472
562
  };
473
563
  readonly "<current_file>": {
474
- readonly resolve: () => string;
564
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string | undefined;
475
565
  readonly subpaths: any[];
476
566
  };
477
567
  readonly "<current_folder>": {
478
- readonly resolve: () => string;
568
+ readonly resolve: (opts: PathAliasResolveOptions | undefined) => string | undefined;
479
569
  readonly subpaths: any[];
480
570
  };
481
571
  };
@@ -679,11 +769,11 @@ declare const project: (...args: ProjectParams) => {
679
769
  packageJsonPath: string | undefined;
680
770
  packageName: string | undefined;
681
771
  projectDir: string | undefined;
682
- findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
683
- detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
684
- detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
685
- detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
686
- globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
772
+ findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
773
+ detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
774
+ detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
775
+ detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
776
+ globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
687
777
  mapPackageManagers: <$result>(mapFn: (packageManager: PackageManager) => Awaitable<$result>, options?: DetectPackageManagerOptions) => Promise<Awaited<$result>[]>;
688
778
  tsconfig: {
689
779
  readonly paths: string[];
@@ -692,8 +782,8 @@ declare const project: (...args: ProjectParams) => {
692
782
  readonly data: parse_gitignore.ParsedGitignoreObject;
693
783
  readonly patterns: string[];
694
784
  };
695
- filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[]>;
696
- getPackageJson: () => PackageJson;
785
+ filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[]>;
786
+ getPackageJson: () => PackageJson | undefined;
697
787
  findDependencyInPackageJson: (options: string | FindDependencyInPackageJsonOptions) => {
698
788
  firstMatch: PackageDependencyItem | undefined;
699
789
  matches: PackageDependencyItem[];
@@ -719,7 +809,7 @@ declare function getGitRootFolder<$ThrowIfNotFound extends boolean = true>(optio
719
809
  */
720
810
  declare function getPackageFolder(options?: {
721
811
  cwd?: string;
722
- }): string;
812
+ }): string | undefined;
723
813
 
724
814
  interface GetWorkspaceFolderOptions<$Validate extends boolean = true> extends PathOptions {
725
815
  /** @default true */
@@ -741,7 +831,7 @@ interface GetPackageInfoListOptions {
741
831
  cwd?: string;
742
832
  includeRoot?: boolean;
743
833
  }
744
- declare function getWorkspacePackageInfoList(options?: GetPackageInfoListOptions): (PackageInfo | WST.WorkspacePackageInfo)[];
834
+ declare function getWorkspacePackageInfoList(options?: GetPackageInfoListOptions): PackageInfo[];
745
835
 
746
836
  declare function getWorkspacePackageNames(options?: GetPackageInfoListOptions): string[];
747
837
 
@@ -755,11 +845,11 @@ declare const workspace: {
755
845
  packageJsonPath: string | undefined;
756
846
  packageName: string | undefined;
757
847
  projectDir: string | undefined;
758
- findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
759
- detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
760
- detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
761
- detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
762
- globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "bun" | "npm"> | undefined]>;
848
+ findPackageManager: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
849
+ detectPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
850
+ detectGlobalPackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
851
+ detectLockfilePackageManagers: async_cache_fn.AsyncCacheFn<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[], [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
852
+ globalVersions: async_cache_fn.AsyncCacheFn<Record<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm", string | undefined>, [options?: DetectPackageManagerOptions<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm"> | undefined]>;
763
853
  mapPackageManagers: <$result>(mapFn: (packageManager: PackageManager) => Awaitable<$result>, options?: DetectPackageManagerOptions) => Promise<Awaited<$result>[]>;
764
854
  tsconfig: {
765
855
  readonly paths: string[];
@@ -768,8 +858,8 @@ declare const workspace: {
768
858
  readonly data: parse_gitignore.ParsedGitignoreObject;
769
859
  readonly patterns: string[];
770
860
  };
771
- filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "bun" | "npm">[]>;
772
- getPackageJson: () => PackageJson;
861
+ filterPackageManagers: (filterFn: (packageManager: PackageManager) => Awaitable<boolean>, options?: DetectPackageManagerOptions) => Promise<PackageManager<"pnpm" | "yarn" | "yarn-berry" | "bun" | "npm">[]>;
862
+ getPackageJson: () => PackageJson | undefined;
773
863
  findDependencyInPackageJson: (options: string | FindDependencyInPackageJsonOptions) => {
774
864
  firstMatch: PackageDependencyItem | undefined;
775
865
  matches: PackageDependencyItem[];
@@ -818,21 +908,104 @@ type ModifyJSONFileResult<$auto_commit extends boolean = true> = $auto_commit ex
818
908
  }>;
819
909
  declare function modifyJSONFile<$auto_commit extends boolean = true>(filepath: string, edits: JSONEdits, options?: MoodifyJSONFileOptions<$auto_commit>): ModifyJSONFileResult<$auto_commit>;
820
910
 
821
- declare const storage: Storage<StorageValue>;
822
- declare const tempFileSystem: {
823
- definition: {
824
- readonly base: string;
911
+ /**
912
+ * The configuration languages a project actually ships: `package.json` and
913
+ * `tsconfig.json`, `.prettierrc.json5`, CI and Compose YAML, and the TOML
914
+ * that Cargo, Codex, and Ruff read.
915
+ */
916
+ type ConfigFormat = "json" | "jsonc" | "json5" | "yaml" | "toml";
917
+ type ConfigSourceInputType = keyof ConfigSourceInput;
918
+ interface ConfigSourceData<$config extends object = object> {
919
+ text: string;
920
+ data: $config;
921
+ }
922
+ type ConfigSourceInput<data extends object = object> = Prettify<RequireExactlyOne<{
923
+ data?: data;
924
+ filepath?: string;
925
+ text?: string;
926
+ }> & {
927
+ /**
928
+ * Inferred from a `filepath`'s extension. Required for `text` and `data`,
929
+ * which carry no extension to read it from.
930
+ */
931
+ format?: ConfigFormat;
932
+ }>;
933
+
934
+ /**
935
+ * One edit vocabulary across every language. A dot path addresses nesting,
936
+ * an array spells segments out literally, and both are what `modifyJSON`
937
+ * already accepts — so an edit written for `package.json` reads the same
938
+ * written for `config.toml`.
939
+ */
940
+ type ConfigEdits = JSONEdits;
941
+ type ConfigEditData = JSONEditData;
942
+ type ConfigEditOptions = JSONEditOptions;
943
+ interface ModifyConfigOptions<$config extends object = object> {
944
+ config: ConfigSourceInput<$config>;
945
+ edits: ConfigEdits;
946
+ defaultEditOptions?: ConfigEditOptions;
947
+ }
948
+ declare function modifyConfig({ config, edits, defaultEditOptions, }: ModifyConfigOptions): CheckResult<ConfigSourceData>;
949
+ interface ModifyConfigFileOptions<$auto_commit extends boolean = boolean> {
950
+ autoCommit?: $auto_commit;
951
+ defaultEditOptions?: ConfigEditOptions;
952
+ /** Overrides the format the file's extension implies. */
953
+ format?: ConfigFormat;
954
+ }
955
+ type ModifyConfigFileResult<$auto_commit extends boolean = true> = $auto_commit extends true ? CheckResult<ConfigSourceData> : CheckResult<{
956
+ config: ConfigSourceData;
957
+ commit: () => void;
958
+ }>;
959
+ declare function modifyConfigFile<$auto_commit extends boolean = true>(filepath: string, edits: ConfigEdits, options?: ModifyConfigFileOptions<$auto_commit>): ModifyConfigFileResult<$auto_commit>;
960
+
961
+ declare const configLanguages: {
962
+ readonly json: {
963
+ readonly parse: typeof parseJSONC;
964
+ readonly stringify: typeof stringifyJSONC;
965
+ readonly surgical: true;
966
+ };
967
+ readonly jsonc: {
968
+ readonly parse: typeof parseJSONC;
969
+ readonly stringify: typeof stringifyJSONC;
970
+ readonly surgical: true;
971
+ };
972
+ readonly json5: {
973
+ readonly parse: typeof parseJSON5;
974
+ readonly stringify: typeof stringifyJSON5;
975
+ readonly surgical: false;
976
+ };
977
+ readonly yaml: {
978
+ readonly parse: typeof parseYAML;
979
+ readonly stringify: typeof stringifyYAML;
980
+ readonly surgical: false;
981
+ };
982
+ readonly toml: {
983
+ readonly parse: typeof parseTOML;
984
+ readonly stringify: typeof stringifyTOML;
985
+ readonly surgical: false;
825
986
  };
826
- initialize: () => Promise<FileSystemStorage<unknown, string & {}>>;
827
987
  };
988
+ declare function isConfigFormat(value: string): value is ConfigFormat;
989
+ /**
990
+ * `undefined` is a real answer: a path can name an extension this module has
991
+ * no language for, and callers say what to do about it rather than receiving
992
+ * a format picked at random.
993
+ */
994
+ declare function getConfigFormat(filepath: string): ConfigFormat | undefined;
995
+
996
+ type InferConfig<$source extends ConfigSourceInput> = $source extends ConfigSourceInput<infer $config> ? $config : object;
997
+ type ResolvedConfigSourceData<$as extends "data" | "text" = never, $config extends object = object> = IsNever<$as> extends false ? $as extends string ? ConfigSourceData<$config>[$as] : ConfigSourceData<$config> : ConfigSourceData<$config>;
998
+ declare function resolveConfigSource<$source extends ConfigSourceInput, $as extends "data" | "text" = never>(source: $source, as?: $as): ResolvedConfigSourceData<$as, InferConfig<$source>>;
999
+
1000
+ declare const storage: Storage<StorageValue>;
1001
+ declare const tempFileSystem: FileSystemStorage<FileSystemEntriesDefinition<string>, FileSystemPathCompletion<FileSystemEntriesDefinition<string>>>;
828
1002
  type FileSystemEntriesDefinition<$filepath extends string = string> = {
829
- [K in $filepath]: StorageValue | (<$file_data extends StorageValue>() => {
830
- file: $file_data;
831
- options?: TransactionOptions;
832
- serialize?: (file_data: $file_data) => string;
833
- deserialize?: (file_content: string) => $file_data;
834
- });
1003
+ [K in $filepath]: StorageValue | (() => FileSystemEntryDefinition);
835
1004
  };
1005
+ interface FileSystemEntryDefinition<$file_data extends StorageValue = StorageValue> {
1006
+ file: $file_data;
1007
+ options?: TransactionOptions;
1008
+ }
836
1009
  interface FileSystemEntry<$key extends string = string> {
837
1010
  key: $key;
838
1011
  value: string;
@@ -858,15 +1031,21 @@ $path_completion extends FileSystemPathCompletion<$fs_def> = FileSystemPathCompl
858
1031
  getFile: (filepath: $path_completion) => Promise<{
859
1032
  key: string;
860
1033
  filepath: string;
861
- data: any;
862
- read: () => Promise<any>;
1034
+ data: StorageValue;
1035
+ read: () => Promise<string | undefined>;
863
1036
  }>;
864
- readFile: (filepath: $path_completion) => Promise<string>;
865
- getFilePath: <$filepath extends $path_completion>(key: $filepath) => Promise<string>;
1037
+ /** Resolves to `undefined` when the file does not exist. */
1038
+ readFile: (filepath: $path_completion) => Promise<string | undefined>;
1039
+ /** The location a key maps to on disk, whether or not anything is there. */
1040
+ getFilePath: (key: $path_completion) => string;
1041
+ /** `base` is a storage key prefix, not a filesystem path. */
866
1042
  restoreFs(snapshot: Snapshot, base?: string): Promise<void>;
1043
+ /** `base` is a storage key prefix, not a filesystem path. */
867
1044
  snapshotFs: (base?: string) => Promise<Snapshot<string>>;
1045
+ /** Replaces the entries this storage owns, leaving other files in place. */
868
1046
  initializeFs: (newInitial?: FileSystemEntriesDefinition) => Promise<void>;
869
- removeAllFiles(base?: string, opts?: TransactionOptions): Promise<void>;
1047
+ removeAllFiles(): Promise<void>;
1048
+ /** Removes the base directory and everything under it. */
870
1049
  deleteFileSystem(): Promise<void>;
871
1050
  defineFileSystemEntries: typeof defineFileSystemEntries;
872
1051
  storage: Storage;
@@ -878,10 +1057,7 @@ interface FileSystemEntriesData<T extends FileSystemEntriesDefinition | undefine
878
1057
  declare function defineFileSystemEntries<const $fs_def extends FileSystemEntriesDefinition>(definition: $fs_def): FileSystemEntriesData<$fs_def>;
879
1058
  type ExtractFsEntriesDef<$fs_def> = Cast<$fs_def, FileSystemEntriesDefinition>;
880
1059
  declare function defineFileSystemStorage<const $fs_storage_def extends DefineFileSystemOptions = DefineFileSystemOptions, // prettier-ignore
881
- $fs_def extends $fs_storage_def['initial'] = $fs_storage_def['initial']>(options: $fs_storage_def): $fs_storage_def["initial"] extends undefined ? FileSystemStorage : {
882
- definition: $fs_storage_def;
883
- initialize: () => Promise<FileSystemStorage<$fs_def>>;
884
- };
1060
+ $fs_def extends $fs_storage_def['initial'] = $fs_storage_def['initial']>(options: $fs_storage_def): FileSystemStorage<ExtractFsEntriesDef<$fs_def>>;
885
1061
 
886
- export { _dirname, _filename, defineFileSystemEntries, defineFileSystemStorage, definePackage, definePackageManagerClient, definePathAliases, dependencyTypeMap, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getFolderByPackageName, getGitRootFolder, getGlobalVersions, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, mapPackageManagers, modifyJSON, modifyJSONFile, packageManagerConfigs, predefinedPathAliases, project, resolveModule, resolveModulePath, resolvePackageModulePath, storage, tempFileSystem, workspace };
887
- export type { AliasDefinition, AliasDefinitionMap, AliasMap, AnyFunction, AsyncCacheFn, Awaitable, Cast, CheckResult, DefinePackageFn, DetectPackageManagerOptions, Entry, EntryOf, EnumToLiteral, Equals, ExtractImportOptionModule, FileSystemEntriesDefinition, FindDependencyInPackageJsonOptions, FromEntries, GetGitRootFolderOptions, GetPathOptions, GetWorkspaceFolderOptions, ImportCallback, ImportList, ImportMap, ImportMapFn, ImportMapOptions, ImportModuleData, ImportModuleFn, ImportOption, ImportOptionData, ImportPackageData, ImporterOptions, InstallPackageOptions, InstallerFn, IsExactBoolean, IsUnion, IsUnknown, JSONEditData, JSONEditMap, JSONEditOptions, JSONEdits, KeyOf, KnownPackageJson, MergeObject, ModifyJSONCDataOptions, Module, MoodifyJSONFileOptions, NoInfer, OmitByValue, OmitIndexSignature, OmitNever, PackageDependencyItem, PackageDependencyType, PackageInfo, PackageInfoList, PackageInfoMap, PackageJson, PackageJsonPerson, PackageManagerCommandName, PackageManagerCommandSpec, PackageManagerCommands, PackageManagerConfig, PackageManagerId, PackageManagerScriptOptions, PackageName, PathAlias, PathOptions, PathTo, PickByValue, PickKeyOf, PickPathAlias, PredefinedPathAliases, Prettify, ProjectParams, RequireExactlyOne, ResolveModulePathOptions, ResolvedImportList, ResolvedImportListPromise, ResolvedImportMap, ResolvedImportMapPromise, ResolvedImportOption, ResolvedPromise, Select, SelectionMap, SingleProp, StringLiteral, UninstallPackageOptions, ValueAtPath, ValueKeyOf, ValueKeyOfDeep, ValueOf, __ };
1062
+ export { _dirname, _filename, configLanguages, createFile, defineFileSystemEntries, defineFileSystemStorage, definePackage, definePackageManager, definePackageManagerClient, definePathAliases, dependencyTypeMap, detectGlobalPackageManagers, detectLockfilePackageManagers, detectPackageManagers, filterPackageManagers, findDependencyInPackageJson, findPackageManager, findPackageManagerSafely, findResolvedModulePath, getAliasMap, getConfigFormat, getFolderByPackageName, getGitRootFolder, getGlobalVersions, getPackageFolder, getPath, getWorkspaceFolder, importMap, importer, isConfigFormat, isDependencyInPackageJson, isPackageDependency, isPackageModuleFound, isWritable, mapPackageManagers, modifyConfig, modifyConfigFile, modifyJSON, modifyJSONFile, packageManagerConfigs, predefinedPathAliases, project, readFile, readFileSafely, resolveConfigSource, resolveModule, resolveModulePath, resolvePackageModulePath, storage, tempFileSystem, workspace };
1063
+ export type { AliasDefinition, AliasDefinitionMap, AliasMap, AnyFunction, AsyncCacheFn, Awaitable, CallerLocationOptions, Cast, CheckResult, ConfigEditData, ConfigEditOptions, ConfigEdits, ConfigFormat, ConfigSourceData, ConfigSourceInput, ConfigSourceInputType, DefinePackageFn, DetectPackageManagerOptions, Entry, EntryOf, EnumToLiteral, Equals, ExtractImportOptionModule, FileSystemEntriesDefinition, FindDependencyInPackageJsonOptions, FromEntries, GetGitRootFolderOptions, GetPathOptions, GetWorkspaceFolderOptions, ImportCallback, ImportList, ImportMap, ImportMapFn, ImportMapOptions, ImportModuleData, ImportModuleFn, ImportOption, ImportOptionData, ImportPackageData, ImporterOptions, InstallPackageOptions, InstallerFn, IsExactBoolean, IsNever, IsUnion, IsUnknown, JSONEditData, JSONEditMap, JSONEditOptions, JSONEdits, KeyOf, KnownPackageJson, MergeObject, ModifyConfigFileOptions, ModifyConfigOptions, ModifyJSONCDataOptions, Module, MoodifyJSONFileOptions, NoInfer, OmitByValue, OmitIndexSignature, OmitNever, PackageDependencyItem, PackageDependencyType, PackageInfo, PackageInfoList, PackageInfoMap, PackageJson, PackageJsonPerson, PackageManager, PackageManagerCommandName, PackageManagerCommandSpec, PackageManagerCommands, PackageManagerConfig, PackageManagerId, PackageManagerScriptOptions, PackageManagers, PackageName, PathAlias, PathAliasResolveOptions, PathOptions, PathTo, PickByValue, PickKeyOf, PickPathAlias, PredefinedPathAliases, Prettify, ProjectParams, ReadFileOptions, RequireExactlyOne, ResolveModulePathOptions, ResolvedImportList, ResolvedImportListPromise, ResolvedImportMap, ResolvedImportMapPromise, ResolvedImportOption, ResolvedPromise, Select, SelectionMap, SingleProp, StringLiteral, UninstallPackageOptions, ValueAtPath, ValueKeyOf, ValueKeyOfDeep, ValueOf, __ };