@expo/eas-json 0.36.0 → 0.38.3

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.
Files changed (42) hide show
  1. package/build/build/resolver.d.ts +8 -0
  2. package/build/build/resolver.js +67 -0
  3. package/build/build/schema.d.ts +2 -0
  4. package/build/{EasJsonSchema.js → build/schema.js} +18 -55
  5. package/build/{EasBuild.types.d.ts → build/types.d.ts} +6 -1
  6. package/build/{EasJson.types.js → build/types.js} +0 -0
  7. package/build/errors.d.ts +6 -0
  8. package/build/errors.js +10 -1
  9. package/build/index.d.ts +5 -4
  10. package/build/index.js +10 -8
  11. package/build/reader.d.ts +15 -0
  12. package/build/reader.js +75 -0
  13. package/build/schema.d.ts +2 -0
  14. package/build/schema.js +15 -0
  15. package/build/submit/resolver.d.ts +9 -0
  16. package/build/submit/resolver.js +72 -0
  17. package/build/submit/schema.d.ts +4 -0
  18. package/build/submit/schema.js +35 -0
  19. package/build/{EasSubmit.types.d.ts → submit/types.d.ts} +8 -1
  20. package/build/{EasSubmit.types.js → submit/types.js} +1 -0
  21. package/build/types.d.ts +20 -0
  22. package/build/{EasBuild.types.js → types.js} +0 -0
  23. package/package.json +4 -3
  24. package/src/__tests__/{EasJsonReader-build-test.ts → reader-build-test.ts} +60 -48
  25. package/src/__tests__/{EasJsonReader-submit-test.ts → reader-submit-test.ts} +49 -7
  26. package/src/build/resolver.ts +97 -0
  27. package/src/{EasJsonSchema.ts → build/schema.ts} +16 -60
  28. package/src/{EasBuild.types.ts → build/types.ts} +7 -5
  29. package/src/errors.ts +6 -0
  30. package/src/index.ts +6 -13
  31. package/src/reader.ts +87 -0
  32. package/src/schema.ts +13 -0
  33. package/src/submit/resolver.ts +114 -0
  34. package/src/submit/schema.ts +35 -0
  35. package/src/{EasSubmit.types.ts → submit/types.ts} +9 -7
  36. package/src/types.ts +21 -0
  37. package/build/EasJson.types.d.ts +0 -29
  38. package/build/EasJsonReader.d.ts +0 -39
  39. package/build/EasJsonReader.js +0 -204
  40. package/build/EasJsonSchema.d.ts +0 -6
  41. package/src/EasJson.types.ts +0 -31
  42. package/src/EasJsonReader.ts +0 -259
@@ -1,259 +0,0 @@
1
- import { Platform } from '@expo/eas-build-job';
2
- import JsonFile from '@expo/json-file';
3
- import envString from 'env-string';
4
- import path from 'path';
5
-
6
- import { BuildProfile } from './EasBuild.types';
7
- import { CliConfig, CredentialsSource, EasJson, RawBuildProfile } from './EasJson.types';
8
- import {
9
- AndroidSubmitProfileSchema,
10
- CliConfigSchema,
11
- EasJsonSchema,
12
- IosSubmitProfileSchema,
13
- MinimalEasJsonSchema,
14
- } from './EasJsonSchema';
15
- import {
16
- AndroidSubmitProfileFieldsToEvaluate,
17
- IosSubmitProfileFieldsToEvaluate,
18
- SubmitProfile,
19
- } from './EasSubmit.types';
20
- import { InvalidEasJsonError } from './errors';
21
-
22
- interface EasJsonPreValidation {
23
- cli?: object;
24
- build: { [profile: string]: object };
25
- submit?: { [profile: string]: object };
26
- }
27
-
28
- const defaults = {
29
- distribution: 'store',
30
- credentialsSource: CredentialsSource.REMOTE,
31
- } as const;
32
-
33
- type LoggerFn = (...args: any[]) => void;
34
-
35
- interface Logger {
36
- log: LoggerFn;
37
- warn: LoggerFn;
38
- }
39
-
40
- export class EasJsonReader {
41
- private static log?: Logger;
42
-
43
- public static formatEasJsonPath(projectDir: string): string {
44
- return path.join(projectDir, 'eas.json');
45
- }
46
-
47
- public static setLog(log: Logger): void {
48
- this.log = log;
49
- }
50
-
51
- constructor(private projectDir: string) {}
52
-
53
- public async getBuildProfileNamesAsync(): Promise<string[]> {
54
- const easJson = await this.readRawAsync();
55
- return Object.keys(easJson?.build ?? {});
56
- }
57
-
58
- public async getCliConfigAsync(): Promise<CliConfig | null> {
59
- try {
60
- const easJson = await this.readRawAsync();
61
- if (!easJson.cli) {
62
- return null;
63
- }
64
- const { value, error } = CliConfigSchema.validate(easJson.cli, {
65
- allowUnknown: false,
66
- convert: true,
67
- abortEarly: false,
68
- });
69
- if (error) {
70
- throw new Error(`"cli" field in eas.json is not valid [${error.toString()}]`);
71
- }
72
- return value as CliConfig;
73
- } catch (err: any) {
74
- if (err.code === 'ENOENT') {
75
- return null;
76
- }
77
- throw err;
78
- }
79
- }
80
-
81
- public async getSubmitProfileNamesAsync({ throwIfEasJsonDoesNotExist = true } = {}): Promise<
82
- string[]
83
- > {
84
- try {
85
- const easJson = await this.readRawAsync();
86
- return Object.keys(easJson?.submit ?? {});
87
- } catch (err: any) {
88
- if (!throwIfEasJsonDoesNotExist && err.code === 'ENOENT') {
89
- return [];
90
- } else {
91
- throw err;
92
- }
93
- }
94
- }
95
-
96
- public async readBuildProfileAsync<T extends Platform>(
97
- platform: T,
98
- profileName: string
99
- ): Promise<BuildProfile<T>> {
100
- const easJson = await this.readAndValidateAsync();
101
- this.ensureBuildProfileExists(easJson, profileName);
102
- const {
103
- android: resolvedAndroidSpecificValues,
104
- ios: resolvedIosSpecificValues,
105
- ...resolvedProfile
106
- } = this.resolveBuildProfile(easJson, profileName);
107
- if (platform === Platform.ANDROID) {
108
- const profileWithoutDefaults = profileMerge(
109
- resolvedProfile,
110
- resolvedAndroidSpecificValues ?? {}
111
- );
112
- return profileMerge(defaults, profileWithoutDefaults) as BuildProfile<T>;
113
- } else if (platform === Platform.IOS) {
114
- const profileWithoutDefaults = profileMerge(resolvedProfile, resolvedIosSpecificValues ?? {});
115
- return profileMerge(defaults, profileWithoutDefaults) as BuildProfile<T>;
116
- } else {
117
- throw new Error(`Unknown platform ${platform}`);
118
- }
119
- }
120
-
121
- public async readSubmitProfileAsync<T extends Platform>(
122
- platform: T,
123
- profileNameArg?: string
124
- ): Promise<SubmitProfile<T>> {
125
- let profileName = profileNameArg;
126
-
127
- if (!profileName) {
128
- const profileNames = await this.getSubmitProfileNamesAsync({
129
- throwIfEasJsonDoesNotExist: false,
130
- });
131
-
132
- if (profileNames.includes('production')) {
133
- profileName = 'production';
134
- } else if (profileNames.includes('release')) {
135
- profileName = 'release';
136
- } else {
137
- return getDefaultSubmitProfile(platform);
138
- }
139
- }
140
-
141
- const easJson = await this.readAndValidateAsync();
142
- const profile = easJson?.submit?.[profileName];
143
- if (!profile) {
144
- throw new Error(`There is no profile named ${profileName} in eas.json`);
145
- }
146
- const platformProfile = profile[platform];
147
- if (platformProfile) {
148
- return this.evaluateFields(platform, platformProfile as SubmitProfile<T>);
149
- } else {
150
- return getDefaultSubmitProfile(platform);
151
- }
152
- }
153
-
154
- public async readAndValidateAsync(): Promise<EasJson> {
155
- const easJson = await this.readRawAsync();
156
- const { value, error } = EasJsonSchema.validate(easJson, {
157
- allowUnknown: false,
158
- convert: true,
159
- abortEarly: false,
160
- });
161
-
162
- if (error) {
163
- throw new InvalidEasJsonError(`eas.json is not valid [${error.toString()}]`);
164
- }
165
- return value as EasJson;
166
- }
167
-
168
- public async readRawAsync(): Promise<EasJsonPreValidation> {
169
- try {
170
- const easJsonPath = EasJsonReader.formatEasJsonPath(this.projectDir);
171
- const rawEasJson = JsonFile.read(easJsonPath);
172
- const { value, error } = MinimalEasJsonSchema.validate(rawEasJson, { abortEarly: false });
173
- if (error) {
174
- throw new InvalidEasJsonError(`eas.json is not valid [${error.toString()}]`);
175
- }
176
- return value;
177
- } catch (err: any) {
178
- if (err.code === 'EJSONPARSE') {
179
- err.message = `Found invalid JSON in eas.json. ${err.message}`;
180
- }
181
- throw err;
182
- }
183
- }
184
-
185
- private resolveBuildProfile(
186
- easJson: EasJson,
187
- profileName: string,
188
- depth: number = 0
189
- ): RawBuildProfile {
190
- if (depth >= 2) {
191
- throw new Error(
192
- 'Too long chain of build profile extensions, make sure "extends" keys do not make a cycle'
193
- );
194
- }
195
- const buildProfile = easJson.build[profileName];
196
- if (!buildProfile) {
197
- throw new Error(`There is no profile named ${profileName} in eas.json`);
198
- }
199
- const { extends: baseProfileName, ...buildProfileRest } = buildProfile;
200
- if (baseProfileName) {
201
- return profileMerge(
202
- this.resolveBuildProfile(easJson, baseProfileName, depth + 1),
203
- buildProfileRest
204
- );
205
- } else {
206
- return buildProfileRest;
207
- }
208
- }
209
-
210
- private ensureBuildProfileExists(easJson: EasJson, profileName: string): void {
211
- if (!easJson.build || !easJson.build[profileName]) {
212
- throw new Error(`There is no profile named ${profileName} in eas.json`);
213
- }
214
- }
215
-
216
- private evaluateFields<T extends Platform>(
217
- platform: T,
218
- profile: SubmitProfile<T>
219
- ): SubmitProfile<T> {
220
- const fields =
221
- platform === Platform.ANDROID
222
- ? AndroidSubmitProfileFieldsToEvaluate
223
- : IosSubmitProfileFieldsToEvaluate;
224
- const evaluatedProfile = { ...profile };
225
- for (const field of fields) {
226
- if (field in evaluatedProfile) {
227
- // @ts-ignore
228
- evaluatedProfile[field] = envString(evaluatedProfile[field], process.env);
229
- }
230
- }
231
- return evaluatedProfile;
232
- }
233
- }
234
-
235
- export function profileMerge(base: RawBuildProfile, update: RawBuildProfile): RawBuildProfile {
236
- const result = {
237
- ...base,
238
- ...update,
239
- };
240
- if (base.env && update.env) {
241
- result.env = {
242
- ...base.env,
243
- ...update.env,
244
- };
245
- }
246
- if (base.android && update.android) {
247
- result.android = profileMerge(base.android, update.android);
248
- }
249
- if (base.ios && update.ios) {
250
- result.ios = profileMerge(base.ios, update.ios);
251
- }
252
- return result;
253
- }
254
-
255
- function getDefaultSubmitProfile<T extends Platform>(platform: T): SubmitProfile<T> {
256
- const Schema =
257
- platform === Platform.ANDROID ? AndroidSubmitProfileSchema : IosSubmitProfileSchema;
258
- return Schema.validate({}, { convert: true }).value;
259
- }