fork-version 1.4.14 → 1.4.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -3,26 +3,18 @@ import { ReleaseType } from 'semver';
3
3
 
4
4
  declare const ForkConfigSchema: z.ZodObject<{
5
5
  /**
6
- * The path where the changes should be calculated from.
6
+ * The path fork-version will run from.
7
7
  * @default
8
8
  * ```js
9
9
  * process.cwd()
10
10
  * ```
11
11
  */
12
- changePath: z.ZodString;
12
+ path: z.ZodString;
13
13
  /**
14
- * The name of the changelog file.
14
+ * Name of the changelog file.
15
15
  * @default "CHANGELOG.md"
16
16
  */
17
17
  changelog: z.ZodString;
18
- /**
19
- * Files to be updated.
20
- * @default
21
- * ```js
22
- * ["bower.json", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]
23
- * ```
24
- */
25
- outFiles: z.ZodArray<z.ZodString, "many">;
26
18
  /**
27
19
  * The header to be used in the changelog.
28
20
  * @default
@@ -34,16 +26,44 @@ declare const ForkConfigSchema: z.ZodObject<{
34
26
  */
35
27
  header: z.ZodString;
36
28
  /**
37
- * Specify a prefix for the git tag that will be taken into account during the comparison.
29
+ * Files to be updated.
30
+ * @default
31
+ * ```js
32
+ * ["bower.json", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]
33
+ * ```
34
+ */
35
+ files: z.ZodArray<z.ZodString, "many">;
36
+ /**
37
+ * Specify a prefix for the git tag fork-version will create.
38
+ *
39
+ * For instance if your version tag is prefixed by "version/" instead of "v" you have to specify
40
+ * `tagPrefix: "version/"`.
41
+ *
42
+ * `tagPrefix` can also be used for a monorepo environment where you might want to deploy
43
+ * multiple package from the same repository. In this case you can specify a prefix for
44
+ * each package:
38
45
  *
39
- * For instance if your version tag is prefixed by `version/` instead of `v` you would
40
- * have to specify `tagPrefix: "version/"`.
41
- * @default `v`
46
+ * | Value | Tag Created |
47
+ * |:-------------------------|:------------------------------|
48
+ * | "" | `1.2.3` |
49
+ * | "version/" | `version/1.2.3` |
50
+ * | "@eglavin/fork-version-" | `@eglavin/fork-version-1.2.3` |
51
+ *
52
+ * @example "", "version/", "@eglavin/fork-version-"
53
+ * @default "v"
42
54
  */
43
55
  tagPrefix: z.ZodString;
44
56
  /**
45
- * Make a pre-release with optional label to specify a tag id.
46
- * @example true, "alpha", "beta", "rc", etc.
57
+ * Make a pre-release with optional label, if value is a string it will be used as the
58
+ * pre-release tag.
59
+ *
60
+ * | Value | Version |
61
+ * |:----------|:----------------|
62
+ * | true | "1.2.3-0" |
63
+ * | "alpha" | "1.2.3-alpha-0" |
64
+ * | "beta" | "1.2.3-beta-0" |
65
+ *
66
+ * @example true, "alpha", "beta", "rc"
47
67
  * @default undefined
48
68
  */
49
69
  preReleaseTag: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>;
@@ -52,17 +72,27 @@ declare const ForkConfigSchema: z.ZodObject<{
52
72
  * @default false
53
73
  */
54
74
  commitAll: z.ZodBoolean;
75
+ /**
76
+ * If set we'll log debug information.
77
+ * @default false
78
+ */
79
+ debug: z.ZodBoolean;
55
80
  /**
56
81
  * If true, no output will be written to disk or committed.
57
82
  * @default false
58
83
  */
59
84
  dryRun: z.ZodBoolean;
60
85
  /**
61
- * If true and we cant find a version in an `outFiles`, we'll fallback and attempt
62
- * to use the latest git tag for the current version.
86
+ * If true and we cant find a version in the list of `files`, we'll fallback
87
+ * and attempt to use the latest git tag to get the current version.
63
88
  * @default true
64
89
  */
65
90
  gitTagFallback: z.ZodBoolean;
91
+ /**
92
+ * If set, we'll gather information about the current version and exit.
93
+ * @default false
94
+ */
95
+ inspectVersion: z.ZodBoolean;
66
96
  /**
67
97
  * Should we sign the git commit using GPG?
68
98
  * @see {@link https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--Sltkeyidgt GPG Sign Commits}
@@ -80,13 +110,14 @@ declare const ForkConfigSchema: z.ZodObject<{
80
110
  */
81
111
  verify: z.ZodBoolean;
82
112
  /**
83
- * If set, we'll use this version number instead of trying to find it in an `outFiles`.
113
+ * If set, we'll use this version number instead of trying to find a version from the list of `files`.
84
114
  * @example "1.0.0"
85
115
  * @default undefined
86
116
  */
87
117
  currentVersion: z.ZodOptional<z.ZodString>;
88
118
  /**
89
- * If set, we'll attempt to update the version number to this version.
119
+ * If set, we'll attempt to update the version number to this version, instead of incrementing
120
+ * using "conventional-commit".
90
121
  * @example "2.0.0"
91
122
  * @default undefined
92
123
  */
@@ -95,9 +126,6 @@ declare const ForkConfigSchema: z.ZodObject<{
95
126
  * Override the default conventional-changelog preset configuration.
96
127
  */
97
128
  changelogPresetConfig: z.ZodObject<{
98
- /**
99
- * An array of `type` objects representing the explicitly supported commit message types, and whether they should show up in generated `CHANGELOG`s.
100
- */
101
129
  types: z.ZodOptional<z.ZodArray<z.ZodObject<{
102
130
  type: z.ZodString;
103
131
  section: z.ZodOptional<z.ZodString>;
@@ -111,29 +139,11 @@ declare const ForkConfigSchema: z.ZodObject<{
111
139
  section?: string | undefined;
112
140
  hidden?: boolean | undefined;
113
141
  }>, "many">>;
114
- /**
115
- * A URL representing a specific commit at a hash.
116
- */
117
142
  commitUrlFormat: z.ZodOptional<z.ZodString>;
118
- /**
119
- * A URL representing the comparison between two git SHAs.
120
- */
121
143
  compareUrlFormat: z.ZodOptional<z.ZodString>;
122
- /**
123
- * A URL representing the issue format (allowing a different URL format to be swapped in for Gitlab, Bitbucket, etc).
124
- */
125
144
  issueUrlFormat: z.ZodOptional<z.ZodString>;
126
- /**
127
- * A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for substituting @bcoe with https://github.com/bcoe in commit messages.
128
- */
129
145
  userUrlFormat: z.ZodOptional<z.ZodString>;
130
- /**
131
- * A string to be used to format the auto-generated release commit message.
132
- */
133
146
  releaseCommitMessageFormat: z.ZodOptional<z.ZodString>;
134
- /**
135
- * An array of prefixes used to detect references to issues
136
- */
137
147
  issuePrefixes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
138
148
  }, "strip", z.ZodTypeAny, {
139
149
  types?: {
@@ -160,34 +170,17 @@ declare const ForkConfigSchema: z.ZodObject<{
160
170
  releaseCommitMessageFormat?: string | undefined;
161
171
  issuePrefixes?: string[] | undefined;
162
172
  }>;
163
- /**
164
- * Log function, can be used to override the default `console.log` function
165
- * to log to a file or another service.
166
- * @default console.log
167
- */
168
- log: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodVoid>;
169
- /**
170
- * Error logger function, can be used to override the default `console.error`
171
- * function to log to a file or another service.
172
- * @default console.error
173
- */
174
- error: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodVoid>;
175
- /**
176
- * Debug logger function, by default this is a noop function, but can be replaced
177
- * with a custom logger function or `console.info` to print output.
178
- * @default () => {}
179
- */
180
- debug: z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodVoid>;
181
173
  }, "strip", z.ZodTypeAny, {
182
- changePath: string;
174
+ path: string;
183
175
  changelog: string;
184
- outFiles: string[];
185
- error: (args_0: string, ...args_1: unknown[]) => void;
186
176
  header: string;
177
+ files: string[];
187
178
  tagPrefix: string;
188
179
  commitAll: boolean;
180
+ debug: boolean;
189
181
  dryRun: boolean;
190
182
  gitTagFallback: boolean;
183
+ inspectVersion: boolean;
191
184
  sign: boolean;
192
185
  silent: boolean;
193
186
  verify: boolean;
@@ -204,21 +197,20 @@ declare const ForkConfigSchema: z.ZodObject<{
204
197
  releaseCommitMessageFormat?: string | undefined;
205
198
  issuePrefixes?: string[] | undefined;
206
199
  };
207
- log: (args_0: string, ...args_1: unknown[]) => void;
208
- debug: (args_0: string, ...args_1: unknown[]) => void;
209
200
  preReleaseTag?: string | boolean | undefined;
210
201
  currentVersion?: string | undefined;
211
202
  nextVersion?: string | undefined;
212
203
  }, {
213
- changePath: string;
204
+ path: string;
214
205
  changelog: string;
215
- outFiles: string[];
216
- error: (args_0: string, ...args_1: unknown[]) => void;
217
206
  header: string;
207
+ files: string[];
218
208
  tagPrefix: string;
219
209
  commitAll: boolean;
210
+ debug: boolean;
220
211
  dryRun: boolean;
221
212
  gitTagFallback: boolean;
213
+ inspectVersion: boolean;
222
214
  sign: boolean;
223
215
  silent: boolean;
224
216
  verify: boolean;
@@ -235,8 +227,6 @@ declare const ForkConfigSchema: z.ZodObject<{
235
227
  releaseCommitMessageFormat?: string | undefined;
236
228
  issuePrefixes?: string[] | undefined;
237
229
  };
238
- log: (args_0: string, ...args_1: unknown[]) => void;
239
- debug: (args_0: string, ...args_1: unknown[]) => void;
240
230
  preReleaseTag?: string | boolean | undefined;
241
231
  currentVersion?: string | undefined;
242
232
  nextVersion?: string | undefined;
@@ -244,52 +234,90 @@ declare const ForkConfigSchema: z.ZodObject<{
244
234
  type ForkConfig = z.infer<typeof ForkConfigSchema>;
245
235
  declare function defineConfig(config: Partial<ForkConfig>): Partial<ForkConfig>;
246
236
 
247
- type FileState = {
237
+ declare function getUserConfig(): Promise<ForkConfig>;
238
+
239
+ declare class Logger {
240
+ private config;
241
+ disableLogs: boolean;
242
+ constructor(config: Pick<ForkConfig, "silent" | "debug" | "inspectVersion">);
243
+ log(...messages: any[]): void;
244
+ warn(...messages: any[]): void;
245
+ error(...messages: any[]): void;
246
+ debug(...messages: any[]): void;
247
+ }
248
+
249
+ interface FileState {
248
250
  name: string;
249
251
  path: string;
250
- type: "package-file" | ({} & string);
251
252
  version: string;
252
- isPrivate: boolean;
253
- };
254
- type CurrentVersion = {
255
- currentVersion: string;
253
+ [other: string]: unknown;
254
+ }
255
+ interface IFileManager {
256
+ read(fileName: string): FileState | undefined;
257
+ write(filePath: string, newVersion: string): void;
258
+ }
259
+ declare class FileManager implements IFileManager {
260
+ private config;
261
+ private logger;
262
+ private JSONPackage;
263
+ private PlainText;
264
+ constructor(config: ForkConfig, logger: Logger);
265
+ /**
266
+ * Get the state from the given file name.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * fileManager.read("package.json");
271
+ * ```
272
+ *
273
+ * @returns
274
+ * ```json
275
+ * { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
276
+ * ```
277
+ */
278
+ read(fileName: string): FileState | undefined;
279
+ /**
280
+ * Write the new version to the given file path.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * fileManager.write("/path/to/package.json", "1.2.3");
285
+ * ```
286
+ */
287
+ write(filePath: string, newVersion: string): void;
288
+ }
289
+
290
+ interface CurrentVersion {
291
+ version: string;
256
292
  files: FileState[];
257
- };
258
- type NextVersion = {
259
- nextVersion: string;
293
+ }
294
+ declare function getCurrentVersion(config: ForkConfig, logger: Logger, fileManager: IFileManager): Promise<CurrentVersion>;
295
+ interface NextVersion {
296
+ version: string;
260
297
  level?: number;
261
298
  preMajor?: boolean;
262
299
  reason?: string;
263
300
  releaseType?: ReleaseType;
264
- };
265
- type BumpVersion = CurrentVersion & NextVersion;
266
- declare function bumpVersion(options: ForkConfig): Promise<BumpVersion>;
301
+ }
302
+ declare function getNextVersion(config: ForkConfig, logger: Logger, currentVersion: string): Promise<NextVersion>;
267
303
 
268
- type CreateChangelog = {
269
- path: string;
270
- exists: boolean;
271
- };
272
- type UpdateChangelog = {
273
- changelog: CreateChangelog;
304
+ interface UpdateChangelog {
305
+ changelogPath: string;
274
306
  oldContent: string;
275
307
  newContent: string;
276
- };
277
- declare function updateChangelog(options: ForkConfig, bumpResult: BumpVersion): Promise<UpdateChangelog>;
308
+ }
309
+ declare function updateChangelog(config: ForkConfig, logger: Logger, nextVersion: string): Promise<UpdateChangelog>;
278
310
 
279
- type CommitChanges = {
311
+ interface CommitChanges {
280
312
  filesToCommit: string[];
281
313
  gitAddOutput?: string;
282
314
  gitCommitOutput?: string;
283
- };
284
- declare function commitChanges(options: ForkConfig, bumpResult: BumpVersion): Promise<CommitChanges>;
315
+ }
316
+ declare function commitChanges(config: ForkConfig, logger: Logger, files: FileState[], nextVersion: string): Promise<CommitChanges>;
285
317
 
286
- type TagChanges = {
318
+ interface TagChanges {
287
319
  gitTagOutput: string;
288
- currentBranchName: string;
289
- hasPublicPackageFile: boolean;
290
- pushMessage: string;
291
- publishMessage: string;
292
- };
293
- declare function tagChanges(options: ForkConfig, bumpResult: BumpVersion): Promise<TagChanges>;
320
+ }
321
+ declare function tagChanges(config: ForkConfig, logger: Logger, nextVersion: string): Promise<TagChanges>;
294
322
 
295
- export { BumpVersion, ForkConfig, bumpVersion, commitChanges, defineConfig, tagChanges, updateChangelog };
323
+ export { type CurrentVersion, FileManager, type FileState, type ForkConfig, ForkConfigSchema, type IFileManager, type NextVersion, commitChanges, defineConfig, getCurrentVersion, getNextVersion, getUserConfig, tagChanges, updateChangelog };