1 |
|
2 |
|
3 | import { packageJson } from 'mrm-core';
|
4 | import { SpawnSyncReturns, StdioOptions } from 'child_process';
|
5 | import { File } from '../Base/File';
|
6 | declare type InstallerNotifier = (list: string[], dev: boolean) => void;
|
7 | declare type Dependencies = {
|
8 | list: string[];
|
9 | versions?: any;
|
10 | dev: boolean;
|
11 | };
|
12 | declare type SupportedPackageManager = 'yarn' | 'pnpm' | 'npm';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export declare class PackageJsonFile extends File {
|
19 | private installerOutput;
|
20 | filePointer: ReturnType<typeof packageJson>;
|
21 | |
22 |
|
23 |
|
24 | protected actions: never[];
|
25 | |
26 |
|
27 |
|
28 | protected packages: {
|
29 | install: {
|
30 | dependency: string;
|
31 | version: string;
|
32 | dev: boolean;
|
33 | }[];
|
34 | uninstall: {
|
35 | dependency: string;
|
36 | dev: boolean;
|
37 | }[];
|
38 | };
|
39 | |
40 |
|
41 |
|
42 | private packageManager;
|
43 | |
44 |
|
45 |
|
46 | private beforeInstallHooks?;
|
47 | |
48 |
|
49 |
|
50 | private beforeUninstallHooks?;
|
51 | constructor(basePath: string, installerOutput?: StdioOptions);
|
52 | /**
|
53 | * Run hooks for action or uninstall action
|
54 | */
|
55 | private runHooks;
|
56 | /**
|
57 | * Sets installation client
|
58 | */
|
59 | private setClient;
|
60 | /**
|
61 | * Executes the installer `install` or `uninstall` action. Use
|
62 | * `this.installerFnAsync` for async version
|
63 | */
|
64 | private installerFn;
|
65 | /**
|
66 | * Executes the installer `install` or `uninstall` action. Use
|
67 | * `this.installerFn` for sync version
|
68 | */
|
69 | private installerFnAsync;
|
70 | /**
|
71 | * Install and uninstall packages defined via `this.install`
|
72 | * and `this.uninstall`
|
73 | */
|
74 | private commitDependencies;
|
75 | /**
|
76 | * Performing uninstalling as a rollback step. Which means, this method
|
77 | * will remove packages marked for installation.
|
78 | */
|
79 | private rollbackDependencies;
|
80 | /**
|
81 | * Same as `commitInstalls` but async
|
82 | */
|
83 | private commitDependenciesAsync;
|
84 | /**
|
85 | * Same as `rollbackInstalls` but async.
|
86 | */
|
87 | private rollbackDependenciesAsync;
|
88 | /**
|
89 | * Commits actions defined on the given file
|
90 | */
|
91 | private commitActions;
|
92 | /**
|
93 | * Rollsback actions defined on the package file
|
94 | */
|
95 | private rollbackActions;
|
96 | /**
|
97 | * Set key/value pair in the package.json file
|
98 | */
|
99 | set(key: string, value: any): this;
|
100 | /**
|
101 | * Set a specific client to be used
|
102 | */
|
103 | useClient(client: SupportedPackageManager): this;
|
104 | /**
|
105 | * Enable/disable use of yarn
|
106 | * @deprecated The "yarn" method is deprecated. Please use "useClient('yarn')" instead.
|
107 | */
|
108 | yarn(_useYarn: boolean): this;
|
109 | /**
|
110 | * Unset key/value pair from the package.json file
|
111 | */
|
112 | unset(key: string): this;
|
113 | /**
|
114 | * Set package.json script
|
115 | */
|
116 | setScript(name: string, script: string): this;
|
117 | /**
|
118 | * Append to existing package.json script
|
119 | */
|
120 | appendScript(name: string, script: string): this;
|
121 | /**
|
122 | * Prepend to existing package.json script
|
123 | */
|
124 | prependScript(name: string, script: string): this;
|
125 | /**
|
126 | * Remove existing script or remove a given action from an
|
127 | * existing script
|
128 | */
|
129 | removeScript(name: string, script?: string | RegExp): this;
|
130 | /**
|
131 | * Install dependencies
|
132 | */
|
133 | install(dependency: string, version?: string, dev?: boolean): this;
|
134 | /**
|
135 | * Uninstall dependencies
|
136 | */
|
137 | uninstall(dependency: string, dev?: boolean): this;
|
138 | /**
|
139 | * Remove file
|
140 | */
|
141 | delete(): this;
|
142 | /**
|
143 | * Returns value for a given key from the file
|
144 | */
|
145 | get(): any;
|
146 | get(address: string | string[], defaultValue?: any): any;
|
147 | /**
|
148 | * A boolean telling if the file already exists
|
149 | */
|
150 | exists(): boolean;
|
151 | /**
|
152 | * Returns a list of dependencies along with specific versions (if any)
|
153 | */
|
154 | getInstalls(dev?: boolean): Dependencies;
|
155 | /**
|
156 | * Returns uninstalls list for prod or development
|
157 | * dependencies.
|
158 | */
|
159 | getUninstalls(dev: boolean): Dependencies;
|
160 | /**
|
161 | * Define a function to be called before installing dependencies
|
162 | */
|
163 | beforeInstall(callback: InstallerNotifier): this;
|
164 | /**
|
165 | * Define a function to be called before uninstalling dependencies
|
166 | */
|
167 | beforeUninstall(callback: InstallerNotifier): this;
|
168 | /**
|
169 | * Commit mutations
|
170 | */
|
171 | commit(): SpawnSyncReturns<Buffer> | undefined;
|
172 | /**
|
173 | * Commits async. The files are still written using synchronous
|
174 | * API. However, the install and uninstall becomes async.
|
175 | */
|
176 | commitAsync(): Promise<SpawnSyncReturns<Buffer> | undefined>;
|
177 | /**
|
178 | * Rollback mutations
|
179 | */
|
180 | rollback(): SpawnSyncReturns<Buffer> | undefined;
|
181 | /**
|
182 | * Rollsback async. The files are still written using synchronous
|
183 | * API. However, the uninstall becomes async.
|
184 | */
|
185 | rollbackAsync(): Promise<SpawnSyncReturns<Buffer> | undefined>;
|
186 | }
|
187 | export {};
|