@darkobits/re-pack
Version:
Utility for managing NPM package contents.
55 lines (54 loc) • 1.95 kB
TypeScript
import { type NormalizedPackageJson } from 'read-package-up';
export interface PackageInfo {
/**
* Normalized package.json for the resolved package.
*/
json: NormalizedPackageJson;
/**
* Root directory for the resolved package.
*/
root: string;
}
/**
* Reads the package.json for the host package by walking up the directory tree
* from the current working directory. An optional `cwd` param may be provided
* to override the default.
*/
export declare function getPackageInfo(cwd?: string): Promise<PackageInfo>;
/**
* Determines the "emptiness" of various data structures.
*/
export declare function isEmpty(value: any): boolean;
/**
* Creates the directory to which the host package will be re-packed.
*/
export declare function createPackDir(workspacePath?: string): Promise<string>;
/**
* Modifies and writes to the publish workspace a new package.json with correct
* paths based on the files hoisted from `hoistDir`.
*
* Note. This function assumes the publish workspace has already been created
* and can be written to.
*/
export interface RewritePackageJsonOptions {
/**
* Normalized package.json data to re-write.
*/
pkgJson: NormalizedPackageJson;
/**
* Sub-directory in the local project that will become the root directory in
* the re-packed project. Usually 'dist' or 'lib'.
*/
hoistDir: string;
/**
* Directory to which re-written package.json will be written.
*/
packDir: string;
}
export declare function rewritePackageJson({ pkgJson, hoistDir, packDir }: RewritePackageJsonOptions): Promise<void>;
/**
* Provided a valid semver string, determines if it contains a prerelease
* component (ex: 'beta') and returns it.
*/
export declare function inferPublishTag(pkgVersion: string): string | undefined;
export declare function temporarilyRemoveProblematicPackageScripts(pkgInfo: PackageInfo): Promise<() => Promise<void>>;