UNPKG

3.41 kBTypeScriptView Raw
1import { PackageJson, PackageJsonWithDepsAndDevDeps } from './PackageJson';
2/**
3 * Extract package name and version from input
4 *
5 * @param pkg A string like `@storybook/cli`, `react` or `react@^16`
6 * @return A tuple of 2 elements: [packageName, packageVersion]
7 */
8export declare function getPackageDetails(pkg: string): [
9 string,
10 string?
11];
12export declare abstract class JsPackageManager {
13 abstract readonly type: 'npm' | 'yarn1' | 'yarn2';
14 abstract initPackageJson(): void;
15 abstract getRunStorybookCommand(): string;
16 abstract getRunCommand(command: string): string;
17 /**
18 * Install dependencies listed in `package.json`
19 */
20 installDependencies(): void;
21 retrievePackageJson(): PackageJsonWithDepsAndDevDeps;
22 /**
23 * Add dependencies to a project using `yarn add` or `npm install`.
24 *
25 * @param {Object} options contains `skipInstall`, `packageJson` and `installAsDevDependencies` which we use to determine how we install packages.
26 * @param {Array} dependencies contains a list of packages to add.
27 * @example
28 * addDependencies(options, [
29 * `@storybook/react@${storybookVersion}`,
30 * `@storybook/addon-actions@${actionsVersion}`,
31 * `@storybook/addon-links@${linksVersion}`,
32 * `@storybook/addons@${addonsVersion}`,
33 * ]);
34 */
35 addDependencies(options: {
36 skipInstall?: boolean;
37 installAsDevDependencies?: boolean;
38 packageJson?: PackageJson;
39 }, dependencies: string[]): void;
40 /**
41 * Return an array of strings matching following format: `<package_name>@<package_latest_version>`
42 *
43 * @param packages
44 */
45 getVersionedPackages(...packages: string[]): Promise<string[]>;
46 /**
47 * Return an array of string standing for the latest version of the input packages.
48 * To be able to identify which version goes with which package the order of the input array is keep.
49 *
50 * @param packageNames
51 */
52 getVersions(...packageNames: string[]): Promise<string[]>;
53 getVersion(packageName: string, constraint?: string): Promise<string>;
54 /**
55 * Get the latest version of the package available on npmjs.com.
56 * If constraint is set then it returns a version satisfying it, otherwise the latest version available is returned.
57 *
58 * @param packageName Name of the package
59 * @param constraint Version range to use to constraint the returned version
60 */
61 latestVersion(packageName: string, constraint?: string): Promise<string>;
62 addStorybookCommandInScripts(options?: {
63 port: number;
64 staticFolder?: string;
65 preCommand?: string;
66 }): void;
67 addESLintConfig(): void;
68 addScripts(scripts: Record<string, string>): void;
69 protected abstract runInstall(): void;
70 protected abstract runAddDeps(dependencies: string[], installAsDevDependencies: boolean): void;
71 /**
72 * Get the latest or all versions of the input package available on npmjs.com
73 *
74 * @param packageName Name of the package
75 * @param fetchAllVersions Should return
76 */
77 protected abstract runGetVersions<T extends boolean>(packageName: string, fetchAllVersions: T): Promise<T extends true ? string[] : string>;
78 executeCommand(command: string, args: string[], stdio?: 'pipe' | 'inherit'): string;
79}