xref: /expo/tools/src/publish-packages/types.ts (revision 5dab530b)
1import { Changelog, ChangelogChanges } from '../Changelogs';
2import { GitLog, GitFileLog, GitDirectory } from '../Git';
3import { PackageViewType } from '../Npm';
4import { Package } from '../Packages';
5import { PackagesGraphNode } from '../packages-graph';
6import { BACKUPABLE_OPTIONS_FIELDS } from './constants';
7
8/**
9 * Command's options.
10 */
11export type CommandOptions = {
12  packageNames: string[];
13  prerelease: boolean | string;
14  tag: string;
15  retry: boolean;
16  commitMessage: string;
17  skipRepoChecks: boolean;
18  dry: boolean;
19  force: boolean;
20  deps: boolean;
21
22  /* exclusive options that affect what the command does */
23  listUnpublished: boolean;
24  grantAccess: boolean;
25  checkIntegrity: boolean;
26};
27
28/**
29 * CommandOptions without options that aren't backupable or just don't matter when restoring a backup.
30 */
31export type BackupableOptions = Pick<CommandOptions, typeof BACKUPABLE_OPTIONS_FIELDS[number]>;
32
33/**
34 * Represents command's backup data.
35 */
36export type PublishBackupData = {
37  head: string;
38  options: BackupableOptions;
39  state: {
40    [key: string]: PublishState;
41  };
42};
43
44export type PublishState = {
45  /**
46   * The final release type that also takes into account release types of the dependencies.
47   *
48   * Example: Package A depends only on package B and package B has no dependencies.
49   * If `minReleaseType` of package A is `patch` and `minor` in package B, then `releaseType` of A is `minor`
50   * because it's higher than `patch`.
51   */
52  releaseType?: ReleaseType;
53
54  /**
55   * The final suggested version to publish. Resolved based on `releaseType`.
56   */
57  releaseVersion?: string | null;
58
59  /**
60   * Property that is set to `true` once the parcel finishes publishing to NPM registry.
61   */
62  published?: boolean;
63
64  /**
65   * Whether the package was requested to be published (was listed in command's arguments).
66   */
67  isRequested?: boolean;
68};
69
70export type BaseParcel<State> = {
71  /**
72   * Package instance that stores `package.json` object and some other useful data.
73   */
74  pkg: Package;
75
76  /**
77   * JSON object representing the result of `npm view` command run for the package.
78   * Can be `null` if package is not published yet.
79   */
80  pkgView: PackageViewType | null;
81
82  /**
83   * Changelog instance that can read and modify package changelog.
84   */
85  changelog: Changelog;
86
87  /**
88   * Instance of GitDirectory that runs all git commands from package root directory.
89   */
90  gitDir: GitDirectory;
91
92  /**
93   * Command's tasks should put their results in this object.
94   * It's being serialized and saved in the backup after each task.
95   */
96  state: State;
97};
98
99/**
100 * Type of objects that are being passed through command's tasks.
101 * It's kind of a wrapper for all data related to the package.
102 */
103export type Parcel = BaseParcel<PublishState> & {
104  /**
105   * A node in the graph of monorepo packages and their dependencies.
106   */
107  graphNode: PackagesGraphNode;
108
109  /**
110   * Provides informations about changelog changes that have been added since last publish.
111   */
112  changelogChanges: ChangelogChanges;
113
114  /**
115   * Object that contains a list of commits and changed files since last publish.
116   */
117  logs: PackageGitLogs;
118
119  /**
120   * This is the smallest possible release type that we can use.
121   * It depends only on changes within this package.
122   */
123  minReleaseType?: ReleaseType;
124
125  /**
126   * Set of parcels whose package depends on this one.
127   */
128  dependents: Set<Parcel>;
129
130  /**
131   * Set of parcels on which this parcel depends on.
132   */
133  dependencies: Set<Parcel>;
134};
135
136/**
137 * Array type representing arguments passed to the tasks.
138 */
139export type TaskArgs = [Parcel[], CommandOptions];
140
141/**
142 * Enum of possible release types. It must be in sync with `semver.ReleaseType` union options.
143 */
144export enum ReleaseType {
145  MAJOR = 'major',
146  MINOR = 'minor',
147  PATCH = 'patch',
148  PREMAJOR = 'premajor',
149  PREMINOR = 'preminor',
150  PREPATCH = 'prepatch',
151  PRERELEASE = 'prerelease',
152}
153
154/**
155 * Object containing git logs. `null` if logs couldn't be resolved due to corrupted package data.
156 */
157export type PackageGitLogs = null | {
158  commits: GitLog[];
159  files: GitFileLog[];
160};
161