/** * @file Editable package.json manipulation utilities. Convenience wrappers * around the `EditablePackageJson` class. Both the in-memory and path-backed * flows funnel through the same two entry points — pass `path` to persist, * omit it to stay in memory: * * - `EditablePackageJsonInstance` — public interface for instances * - `toEditablePackageJson` — async (in-memory if no `path`, loads from disk if * `path` set) * - `toEditablePackageJsonSync` — sync version of the above The class factory * lives in a sibling leaf and is re-exported here so existing * `packages/edit` importers keep working unchanged: * - `getEditablePackageJsonClass` — `./edit-class` Lazy `node:fs` / `node:path` * / `node:util` loaders use the canonical `getNodeFs` / `getNodePath` / * `getNodeUtil` helpers from `@socketsecurity/lib/node/{fs,path,util}`. */ import type { EditablePackageJsonOptions, NormalizeOptions, PackageJson, SaveOptions } from './types.js'; /** * EditablePackageJson instance interface extending NPMCliPackageJson * functionality. Provides enhanced package.json manipulation with * Socket-specific features. * * @extends NPMCliPackageJson (from @npmcli/package-json) */ export interface EditablePackageJsonInstance { /** * The parsed package.json content as a readonly object. * * @readonly */ content: Readonly; /** * Create a new package.json file at the specified path. * * @param path - The directory path where package.json will be created. */ create(path: string): this; /** * Apply automatic fixes to the package.json based on npm standards. * * @param opts - Optional fix configuration. */ fix(opts?: unknown | undefined): Promise; /** * Initialize the instance from a content object. * * @param content - The package.json content object. */ fromContent(content: unknown): this; /** * Initialize the instance from a JSON string. * * @param json - The package.json content as a JSON string. */ fromJSON(json: string): this; /** * Load a package.json file from the specified path. * * @param path - The directory containing the package.json. * @param create - Whether to create the file if it doesn't exist. */ load(path: string, create?: boolean | undefined): Promise; /** * Normalize the package.json content according to npm standards. * * @param opts - Normalization options. */ normalize(opts?: NormalizeOptions | undefined): Promise; /** * Prepare the package.json for publishing. * * @param opts - Preparation options. */ prepare(opts?: unknown | undefined): Promise; /** * Update the package.json content with new values. * * @param content - Partial package.json object with fields to update. * * @override from NPMCliPackageJson */ update(content: Partial): this; /** * Save the package.json file to disk. * * @param options - Save options for formatting and sorting. * * @override from NPMCliPackageJson */ save(options?: SaveOptions | undefined): Promise; /** * Synchronously save the package.json file to disk. * * @param options - Save options for formatting and sorting. */ saveSync(options?: SaveOptions | undefined): boolean; /** * Check if the package.json will be saved based on current changes. * * @param options - Save options to evaluate. */ willSave(options?: SaveOptions | undefined): boolean; } /** * Convert package.json to editable instance with file persistence. * * @example * ;```typescript * const editable = await toEditablePackageJson( * { name: 'my-pkg', version: '1.0.0' }, * { path: '/tmp/my-project' }, * ) * ``` */ export declare function toEditablePackageJson(pkgJson: PackageJson, options?: EditablePackageJsonOptions | undefined): Promise; /** * Convert package.json to editable instance with file persistence * synchronously. * * @example * ;```typescript * const editable = toEditablePackageJsonSync( * { name: 'my-pkg', version: '1.0.0' }, * { path: '/tmp/my-project' }, * ) * ``` */ export declare function toEditablePackageJsonSync(pkgJson: PackageJson, options?: EditablePackageJsonOptions | undefined): unknown; export { getEditablePackageJsonClass } from './edit-class.js';