import type { BundleMode } from './BundleMode.js'; import type { PackageSettings } from './PackageSettings.js'; /** * Types for the `package.json` file, derived from [`type-fest`](https://github.com/sindresorhus/type-fest/blob/main/source/package-json.d.ts). * * This version intentionally does not permit arbitrary keys, and only includes properties that are * used by Cloudpack. Additional properties can be added as needed. */ export interface PackageJson { /** * The name of the package. This is always set when reading via `PackageDefinitions`, but might be * missing if reading package.json directly. */ name: string; /** A description of the package. */ description?: string; /** * Package semantic version. This is always set when reading via `PackageDefinitions`, but might be * missing if reading package.json directly. */ version: string; /** Resolution algorithm for importing ".js" files from the package's scope. https://nodejs.org/api/esm.html#esm_package_json_type_field */ type?: 'module' | 'commonjs'; /** The module ID that is the primary entry point to the package. */ main?: string; /** An ECMAScript module ID that is the primary entry point to the package. */ module?: string; /** A hint to JavaScript bundlers or component tools when packaging modules for client side use. */ browser?: string | Partial>; /** * Subpath exports to define entry points of the package. https://nodejs.org/api/packages.html#subpath-exports * * In most of Cloudpack, this will be the computed exports map from `createPackageSettingsTransform`. * This may incorporate user settings, generated settings, and either the original exports * (if present) or exports calculated from other entry points. * * (Exception: this will be the original exports when running tests within `package-utilities` * or with manually-constructed `PackageDefinitions`, instead of `createPackageDefinitions`.) */ exports?: PackageJsonExports; /** * Dependencies that will be installed when the package is consumed. * * When read via `PackageDefinitions`, any `@types` will be removed from this list. * In most of Cloudpack, this is also updated by `createPackageSettingsTransform` to incorporate * included and excluded dependencies from the user and generated configs. */ dependencies?: PackageJsonDependencies; /** * Dependencies that must be installed alongside this package when consumed. * * When read via `PackageDefinitions`, any `@types` will be removed from this list. * In most of Cloudpack, this is also updated by `createPackageSettingsTransform` to incorporate * excluded dependencies from the user and generated configs. */ peerDependencies?: PackageJsonDependencies; /** Indicates which peer dependencies are optional. */ peerDependenciesMeta?: Partial>; /** * Dependencies for local development only. * * When read via `PackageDefinitions`, any `@types` will be removed from this list. * In most of Cloudpack, this may also be updated by `createPackageSettingsTransform`. */ devDependencies?: PackageJsonDependencies; /** * Optional dependencies. * When read via `PackageDefinitions`, any `@types` will be removed from this list. */ optionalDependencies?: PackageJsonDependencies; bundledDependencies?: PackageJsonDependencies | string[]; bundleDependencies?: PackageJsonDependencies | string[]; resolutions?: PackageJsonDependencies; /** Required engine versions for running this package. */ engines?: { [engine in LiteralOrString<'node'>]?: string; }; /** * Cached merged package settings (user and generated) for this package (excluding properties * that are fully handled by `createPackageSettingsTransform`), plus other info. * * This can be used while bundling for cached access to package settings. * It's also used for calculating the hash in `getPackageHashEntries`. * * The package settings properties cached here should NOT be used during init's analysis of the * bundle result, since they might be outdated due to pending generated settings updates. * (If a package is re-enqueued after analysis due to generated settings updates, we refresh the * definition, which updates these cached setting. So it's safe to use on the next bundle attempt.) */ cloudpack?: PackageJsonCloudpackMeta; } /** * Cached merged package settings (user and generated) for this package (excluding properties * that are fully handled by `createPackageSettingsTransform`), plus other info. * * See `PackageJson.cloudpack` for details of how this is set and when it's safe to use. */ export interface PackageJsonCloudpackMeta extends Omit { /** Controls how the package is bundled. */ mode: BundleMode; /** * If the package manager is yarn berry (v2+) and the package has been patched with `yarn patch`, * this is the path to the patch file relative to the project root (set by `getNonSemverTransform`). */ patchFilePath?: string; } /** * Union type which has intellisense for specific keys but also allows arbitrary strings. * This is a workaround for a [TypeScript issue](https://github.com/Microsoft/TypeScript/issues/29729) */ export type LiteralOrString = LiteralType | (string & Record); /** Conditions which provide a way to resolve a package entry point based on the environment. */ export type PackageJsonExportCondition = LiteralOrString<'browser' | 'default' | 'deno' | 'electron' | 'import' | 'module' | 'node-addons' | 'node' | 'react-native' | 'require'>; /** * The value of an `PackageJson.exports` object key. Note at the root of the object, keys can be represented * either by a condition, or a `string` to provide import paths (such as "./foo"). At subsequent levels * within the object, only conditions (string which don't start with ".") can be used as keys. */ export type PackageJsonExportsValue = null | string | { [condition in PackageJsonExportCondition]?: PackageJsonExportsValue; } | Array; /** * Definition of the root exports object. Keys can be either conditions or import paths. */ export type PackageJsonExportsObject = { [pathOrCondition: string]: PackageJsonExportsValue; }; /** Entry points of a package, optionally with conditions and subpath exports. Used as `PackageJson.exports`. */ export type PackageJsonExports = PackageJsonExportsValue | PackageJsonExportsObject | PackageJsonExports[]; /** * Mapping from import path to either file path, or a nested object of conditions to file paths * (occasionally with two levels of conditions). This is the format used for generated exports maps. */ export type GeneratedExports = { [path: string]: string | null | { [condition: string]: string | { [condition2: string]: string; }; }; }; /** Mapping from dependency name to semver spec. */ export type PackageJsonDependencies = Partial>; //# sourceMappingURL=PackageJson.d.ts.map