import type { CloudpackConfig } from './CloudpackConfig.js'; import type { PackageJson } from './PackageJson.js'; /** Provides context about how a parent package imports/depends on another package. */ export interface PackageImporterContext { /** Actual name of the package that requested this package. */ parentName: string; /** Actual version of the package that requested this package. */ parentVersion: string; /** Name under which this package is imported by the parent. */ importedName: string; /** Version spec the parent requested for this package. */ versionRequirement: string; } /** * Transform applied to a `package.json` file after it's read. * `PackageDefinitions` clones the original object, so it's okay for transforms to mutate properties. * @returns The transformed definition, or undefined if there were no changes. */ export type PackageDefinitionTransform = (params: { definition: PackageJson; packagePath: string; packages: PackageDefinitionsCache; importerContext?: PackageImporterContext; }) => PackageJson | undefined | Promise; export type PackageDefinitionTransformFactory = (config?: CloudpackConfig) => PackageDefinitionTransform; export interface GetPackageDefinitionOptions { /** If true, the package definition will be re-read from disk. */ refresh?: boolean; /** If true, transforms will not be applied. */ disableTransforms?: boolean; /** Info about the package that is importing this package, if known. */ importerContext?: PackageImporterContext; } /** Serializable representation of the package definitions cache. */ export interface SerializablePackageDefinitionsCache { definitions: Record; transformedDefinitions: Record; } /** * Utility class for reading and caching package definition (`package.json`) objects, * and optionally applying transforms. */ export interface PackageDefinitionsCache { /** * Get a `package.json` (either from cache or disk) and apply transforms. * Throws an error if the file isn't found or there's an error parsing it. * (Use `tryGet` to avoid throwing.) */ get(packagePath: string, options?: GetPackageDefinitionOptions): Promise; /** * Get a `package.json` (either from cache or disk) and apply transforms. * Returns undefined if the file isn't found or there's an error parsing it. */ tryGet(packagePath: string, options?: GetPackageDefinitionOptions): Promise; /** * Registers a transform factory function, which will be called on initialization, and when reset, * to re-generate the transform function. Transform functions are called only when the package * definition hasn't been loaded before, and the result will be cached. * Calling `reset` will reset the cache. */ registerTransform(factory: PackageDefinitionTransformFactory): void; /** * Resets the cache. If a `newConfig` value is provided, the transform factories will be called with the new value * to give them an opportunity to reflect changes to the config. It is `unknown` because the config type is * application-specific. */ reset(options?: { newConfig?: CloudpackConfig; }): void; /** * Sets the definition for a given package path. * If called with `disableTransforms`, it will also delete the transformed definition from the cache, * so that the next call to `get` will apply the transforms, else it will only update the transformed definition. * This is useful when a package received through a serializable representation of the cache * needs to be updated (e.g. automatically adding new exports during remote link). */ set(packagePath: string, definition: PackageJson, options?: Pick): void; /** * Extends the cache with a serializable representation of the cache. * This is useful for merging caches from different sources (e.g. link). */ extend(input: SerializablePackageDefinitionsCache): void; /** * Creates a serializable representation of the cache. */ toSerializable(): SerializablePackageDefinitionsCache; } //# sourceMappingURL=PackageDefinitionsCache.d.ts.map