@expo/eas-json 2.1.0 → 2.6.0

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.
@@ -0,0 +1,16 @@
1
+ import { EasJson } from './types';
2
+ export declare class EasJsonAccessor {
3
+ private easJsonPath;
4
+ private isJson5;
5
+ private easJson;
6
+ private easJsonRawContents;
7
+ private easJsonRawObject;
8
+ private easJsonPatched;
9
+ constructor(projectDir: string);
10
+ static formatEasJsonPath(projectDir: string): string;
11
+ readAsync(): Promise<EasJson>;
12
+ writeAsync(): Promise<void>;
13
+ patch(fn: (easJsonRawObject: any) => any): void;
14
+ readRawJsonAsync(): Promise<any>;
15
+ private resetState;
16
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EasJsonAccessor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const code_frame_1 = require("@babel/code-frame");
6
+ const assert_1 = tslib_1.__importDefault(require("assert"));
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
9
+ const fleece = tslib_1.__importStar(require("golden-fleece"));
10
+ const path_1 = tslib_1.__importDefault(require("path"));
11
+ const errors_1 = require("./errors");
12
+ const schema_1 = require("./schema");
13
+ class EasJsonAccessor {
14
+ constructor(projectDir) {
15
+ this.isJson5 = false;
16
+ this.easJsonPatched = false;
17
+ this.easJsonPath = EasJsonAccessor.formatEasJsonPath(projectDir);
18
+ }
19
+ static formatEasJsonPath(projectDir) {
20
+ return path_1.default.join(projectDir, 'eas.json');
21
+ }
22
+ async readAsync() {
23
+ if (this.easJson) {
24
+ return this.easJson;
25
+ }
26
+ const rawJSON = await this.readRawJsonAsync();
27
+ const { value, error } = schema_1.EasJsonSchema.validate(rawJSON, {
28
+ allowUnknown: false,
29
+ abortEarly: false,
30
+ convert: true,
31
+ noDefaults: true,
32
+ });
33
+ if (error) {
34
+ const errorMessages = error.message.split('. ');
35
+ throw new errors_1.InvalidEasJsonError(`${chalk_1.default.bold('eas.json')} is not valid.\n- ${errorMessages.join('\n- ')}`);
36
+ }
37
+ this.easJson = value;
38
+ return value;
39
+ }
40
+ async writeAsync() {
41
+ if (!this.easJsonPatched) {
42
+ return;
43
+ }
44
+ await fs_extra_1.default.writeFile(this.easJsonPath, this.easJsonRawContents);
45
+ this.resetState();
46
+ }
47
+ patch(fn) {
48
+ (0, assert_1.default)(this.easJsonRawContents && this.easJsonRawObject, 'call readAsync/readRawJsonAsync first');
49
+ this.easJsonRawObject = fn(this.easJsonRawObject);
50
+ if (this.isJson5) {
51
+ this.easJsonRawContents = fleece.patch(this.easJsonRawContents, this.easJsonRawObject);
52
+ }
53
+ else {
54
+ this.easJsonRawContents = `${JSON.stringify(this.easJsonRawObject, null, 2)}\n`;
55
+ }
56
+ this.easJsonPatched = true;
57
+ }
58
+ async readRawJsonAsync() {
59
+ if (!(await fs_extra_1.default.pathExists(this.easJsonPath))) {
60
+ throw new errors_1.MissingEasJsonError(`${chalk_1.default.bold('eas.json')} could not be found at ${this.easJsonPath}. Learn more at https://expo.fyi/eas-json`);
61
+ }
62
+ this.easJsonRawContents = await fs_extra_1.default.readFile(this.easJsonPath, 'utf-8');
63
+ if (this.easJsonRawContents.trim().length === 0) {
64
+ throw new errors_1.InvalidEasJsonError(`${chalk_1.default.bold('eas.json')} is empty.`);
65
+ }
66
+ try {
67
+ const rawJSON = JSON.parse(this.easJsonRawContents);
68
+ this.easJsonRawObject = rawJSON;
69
+ return rawJSON;
70
+ }
71
+ catch {
72
+ // ignore error, try reading as JSON5
73
+ }
74
+ try {
75
+ const rawJSON = fleece.evaluate(this.easJsonRawContents);
76
+ this.easJsonRawObject = rawJSON;
77
+ this.isJson5 = true;
78
+ return rawJSON;
79
+ }
80
+ catch (originalError) {
81
+ if (originalError.loc) {
82
+ const err = new errors_1.InvalidEasJsonError(`Found invalid character in ${chalk_1.default.bold('eas.json')}.`);
83
+ const codeFrame = (0, code_frame_1.codeFrameColumns)(this.easJsonRawContents, { start: originalError.loc });
84
+ err.message += `\n${codeFrame}`;
85
+ throw err;
86
+ }
87
+ else {
88
+ throw new errors_1.InvalidEasJsonError(`Found invalid JSON in ${chalk_1.default.bold('eas.json')}.`);
89
+ }
90
+ }
91
+ }
92
+ resetState() {
93
+ this.isJson5 = false;
94
+ this.easJson = undefined;
95
+ this.easJsonRawContents = undefined;
96
+ this.easJsonRawObject = undefined;
97
+ this.easJsonPatched = false;
98
+ }
99
+ }
100
+ exports.EasJsonAccessor = EasJsonAccessor;
package/build/errors.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- export declare class InvalidEasJsonError extends Error {
1
+ declare class NamedError extends Error {
2
+ constructor(message?: string);
2
3
  }
3
- export declare class MissingEasJsonError extends Error {
4
+ export declare class InvalidEasJsonError extends NamedError {
4
5
  }
5
- export declare class MissingProfileError extends Error {
6
+ export declare class MissingEasJsonError extends NamedError {
6
7
  }
7
- export declare class MissingParentProfileError extends Error {
8
+ export declare class MissingProfileError extends NamedError {
8
9
  }
10
+ export declare class MissingParentProfileError extends NamedError {
11
+ }
12
+ export {};
package/build/errors.js CHANGED
@@ -1,15 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MissingParentProfileError = exports.MissingProfileError = exports.MissingEasJsonError = exports.InvalidEasJsonError = void 0;
4
- class InvalidEasJsonError extends Error {
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ class NamedError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = chalk_1.default.red(this.constructor.name);
10
+ }
11
+ }
12
+ class InvalidEasJsonError extends NamedError {
5
13
  }
6
14
  exports.InvalidEasJsonError = InvalidEasJsonError;
7
- class MissingEasJsonError extends Error {
15
+ class MissingEasJsonError extends NamedError {
8
16
  }
9
17
  exports.MissingEasJsonError = MissingEasJsonError;
10
- class MissingProfileError extends Error {
18
+ class MissingProfileError extends NamedError {
11
19
  }
12
20
  exports.MissingProfileError = MissingProfileError;
13
- class MissingParentProfileError extends Error {
21
+ class MissingParentProfileError extends NamedError {
14
22
  }
15
23
  exports.MissingParentProfileError = MissingParentProfileError;
package/build/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { AndroidReleaseStatus, AndroidReleaseTrack, SubmitProfile } from './subm
2
2
  export { getDefaultProfile as getDefaultSubmitProfile } from './submit/resolver';
3
3
  export { EasJson, ProfileType, AppVersionSource } from './types';
4
4
  export { AndroidVersionAutoIncrement, BuildProfile, CredentialsSource, DistributionType, IosEnterpriseProvisioning, IosVersionAutoIncrement, } from './build/types';
5
- export { EasJsonReader } from './reader';
5
+ export { EasJsonAccessor } from './accessor';
6
+ export { EasJsonUtils } from './utils';
6
7
  export * as errors from './errors';
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errors = exports.EasJsonReader = exports.CredentialsSource = exports.AppVersionSource = exports.getDefaultSubmitProfile = exports.AndroidReleaseTrack = exports.AndroidReleaseStatus = void 0;
3
+ exports.errors = exports.EasJsonUtils = exports.EasJsonAccessor = exports.CredentialsSource = exports.AppVersionSource = exports.getDefaultSubmitProfile = exports.AndroidReleaseTrack = exports.AndroidReleaseStatus = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var types_1 = require("./submit/types");
6
6
  Object.defineProperty(exports, "AndroidReleaseStatus", { enumerable: true, get: function () { return types_1.AndroidReleaseStatus; } });
@@ -11,6 +11,8 @@ var types_2 = require("./types");
11
11
  Object.defineProperty(exports, "AppVersionSource", { enumerable: true, get: function () { return types_2.AppVersionSource; } });
12
12
  var types_3 = require("./build/types");
13
13
  Object.defineProperty(exports, "CredentialsSource", { enumerable: true, get: function () { return types_3.CredentialsSource; } });
14
- var reader_1 = require("./reader");
15
- Object.defineProperty(exports, "EasJsonReader", { enumerable: true, get: function () { return reader_1.EasJsonReader; } });
14
+ var accessor_1 = require("./accessor");
15
+ Object.defineProperty(exports, "EasJsonAccessor", { enumerable: true, get: function () { return accessor_1.EasJsonAccessor; } });
16
+ var utils_1 = require("./utils");
17
+ Object.defineProperty(exports, "EasJsonUtils", { enumerable: true, get: function () { return utils_1.EasJsonUtils; } });
16
18
  exports.errors = tslib_1.__importStar(require("./errors"));
@@ -0,0 +1,12 @@
1
+ import { Platform } from '@expo/eas-build-job';
2
+ import { EasJsonAccessor } from './accessor';
3
+ import { BuildProfile } from './build/types';
4
+ import { SubmitProfile } from './submit/types';
5
+ import { EasJson } from './types';
6
+ export declare class EasJsonUtils {
7
+ static getBuildProfileNamesAsync(accessor: EasJsonAccessor): Promise<string[]>;
8
+ static getBuildProfileAsync<T extends Platform>(accessor: EasJsonAccessor, platform: T, profileName?: string): Promise<BuildProfile<T>>;
9
+ static getCliConfigAsync(accessor: EasJsonAccessor): Promise<EasJson['cli'] | null>;
10
+ static getSubmitProfileNamesAsync(accessor: EasJsonAccessor): Promise<string[]>;
11
+ static getSubmitProfileAsync<T extends Platform>(accessor: EasJsonAccessor, platform: T, profileName?: string): Promise<SubmitProfile<T>>;
12
+ }
package/build/utils.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EasJsonUtils = void 0;
4
+ const resolver_1 = require("./build/resolver");
5
+ const errors_1 = require("./errors");
6
+ const resolver_2 = require("./submit/resolver");
7
+ class EasJsonUtils {
8
+ static async getBuildProfileNamesAsync(accessor) {
9
+ var _a;
10
+ const easJson = await accessor.readAsync();
11
+ return Object.keys((_a = easJson === null || easJson === void 0 ? void 0 : easJson.build) !== null && _a !== void 0 ? _a : {});
12
+ }
13
+ static async getBuildProfileAsync(accessor, platform, profileName) {
14
+ const easJson = await accessor.readAsync();
15
+ return (0, resolver_1.resolveBuildProfile)({ easJson, platform, profileName });
16
+ }
17
+ static async getCliConfigAsync(accessor) {
18
+ var _a;
19
+ try {
20
+ const easJson = await accessor.readAsync();
21
+ return (_a = easJson.cli) !== null && _a !== void 0 ? _a : null;
22
+ }
23
+ catch (err) {
24
+ if (err instanceof errors_1.MissingEasJsonError) {
25
+ return null;
26
+ }
27
+ throw err;
28
+ }
29
+ }
30
+ static async getSubmitProfileNamesAsync(accessor) {
31
+ var _a;
32
+ const easJson = await accessor.readAsync();
33
+ return Object.keys((_a = easJson === null || easJson === void 0 ? void 0 : easJson.submit) !== null && _a !== void 0 ? _a : {});
34
+ }
35
+ static async getSubmitProfileAsync(accessor, platform, profileName) {
36
+ const easJson = await accessor.readAsync();
37
+ return (0, resolver_2.resolveSubmitProfile)({ easJson, platform, profileName });
38
+ }
39
+ }
40
+ exports.EasJsonUtils = EasJsonUtils;
package/package.json CHANGED
@@ -1,25 +1,27 @@
1
1
  {
2
2
  "name": "@expo/eas-json",
3
3
  "description": "A library for interacting with eas.json",
4
- "version": "2.1.0",
4
+ "version": "2.6.0",
5
5
  "author": "Expo <support@expo.dev>",
6
6
  "bugs": "https://github.com/expo/eas-cli/issues",
7
7
  "dependencies": {
8
- "@expo/eas-build-job": "0.2.90",
9
- "@expo/json-file": "8.2.36",
8
+ "@babel/code-frame": "7.18.6",
9
+ "@expo/eas-build-job": "0.2.96",
10
10
  "chalk": "4.1.2",
11
11
  "env-string": "1.0.1",
12
12
  "fs-extra": "10.1.0",
13
- "joi": "17.6.0",
13
+ "golden-fleece": "1.0.9",
14
+ "joi": "17.6.4",
14
15
  "log-symbols": "4.1.0",
15
- "semver": "7.3.7",
16
+ "semver": "7.3.8",
16
17
  "tslib": "2.4.0"
17
18
  },
18
19
  "devDependencies": {
20
+ "@types/babel__code-frame": "7.0.3",
19
21
  "@types/fs-extra": "9.0.13",
20
22
  "memfs": "3.4.7",
21
23
  "rimraf": "3.0.2",
22
- "typescript": "4.7.4"
24
+ "typescript": "4.8.4"
23
25
  },
24
26
  "engines": {
25
27
  "node": ">=14.0.0"
@@ -47,5 +49,5 @@
47
49
  "node": "18.6.0",
48
50
  "yarn": "1.22.19"
49
51
  },
50
- "gitHead": "0cc5b74081452735e74c39667de5f8a774f34555"
52
+ "gitHead": "20ebf24a20afe513cdc4cdc227f1a3ec0a30baab"
51
53
  }
package/build/reader.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Platform } from '@expo/eas-build-job';
2
- import { BuildProfile } from './build/types';
3
- import { SubmitProfile } from './submit/types';
4
- import { EasJson } from './types';
5
- export declare class EasJsonReader {
6
- private projectDir;
7
- private easJson;
8
- constructor(projectDir: string);
9
- static formatEasJsonPath(projectDir: string): string;
10
- readAsync(): Promise<EasJson>;
11
- getBuildProfileNamesAsync(): Promise<string[]>;
12
- getBuildProfileAsync<T extends Platform>(platform: T, profileName?: string): Promise<BuildProfile<T>>;
13
- getCliConfigAsync(): Promise<EasJson['cli'] | null>;
14
- getSubmitProfileNamesAsync(): Promise<string[]>;
15
- getSubmitProfileAsync<T extends Platform>(platform: T, profileName?: string): Promise<SubmitProfile<T>>;
16
- }
package/build/reader.js DELETED
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EasJsonReader = void 0;
4
- const tslib_1 = require("tslib");
5
- const json_file_1 = tslib_1.__importDefault(require("@expo/json-file"));
6
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const resolver_1 = require("./build/resolver");
9
- const errors_1 = require("./errors");
10
- const schema_1 = require("./schema");
11
- const resolver_2 = require("./submit/resolver");
12
- class EasJsonReader {
13
- constructor(projectDir) {
14
- this.projectDir = projectDir;
15
- }
16
- static formatEasJsonPath(projectDir) {
17
- return path_1.default.join(projectDir, 'eas.json');
18
- }
19
- async readAsync() {
20
- if (this.easJson) {
21
- return this.easJson;
22
- }
23
- try {
24
- const easJsonPath = EasJsonReader.formatEasJsonPath(this.projectDir);
25
- if (!(await fs_extra_1.default.pathExists(easJsonPath))) {
26
- throw new errors_1.MissingEasJsonError(`eas.json could not be found at ${easJsonPath}. Learn more at https://expo.fyi/eas-json`);
27
- }
28
- const contents = json_file_1.default.read(easJsonPath);
29
- const { value, error } = schema_1.EasJsonSchema.validate(contents, {
30
- allowUnknown: false,
31
- abortEarly: false,
32
- convert: true,
33
- noDefaults: true,
34
- });
35
- if (error) {
36
- throw new errors_1.InvalidEasJsonError(`eas.json is not valid [${error.toString()}]`);
37
- }
38
- this.easJson = value;
39
- return value;
40
- }
41
- catch (err) {
42
- if (err.code === 'EJSONPARSE') {
43
- err.message = `Found invalid JSON in eas.json. ${err.message}`;
44
- }
45
- throw err;
46
- }
47
- }
48
- async getBuildProfileNamesAsync() {
49
- var _a;
50
- const easJson = await this.readAsync();
51
- return Object.keys((_a = easJson === null || easJson === void 0 ? void 0 : easJson.build) !== null && _a !== void 0 ? _a : {});
52
- }
53
- async getBuildProfileAsync(platform, profileName) {
54
- const easJson = await this.readAsync();
55
- return (0, resolver_1.resolveBuildProfile)({ easJson, platform, profileName });
56
- }
57
- async getCliConfigAsync() {
58
- var _a;
59
- try {
60
- const easJson = await this.readAsync();
61
- return (_a = easJson.cli) !== null && _a !== void 0 ? _a : null;
62
- }
63
- catch (err) {
64
- if (err instanceof errors_1.MissingEasJsonError) {
65
- return null;
66
- }
67
- throw err;
68
- }
69
- }
70
- async getSubmitProfileNamesAsync() {
71
- var _a;
72
- const easJson = await this.readAsync();
73
- return Object.keys((_a = easJson === null || easJson === void 0 ? void 0 : easJson.submit) !== null && _a !== void 0 ? _a : {});
74
- }
75
- async getSubmitProfileAsync(platform, profileName) {
76
- const easJson = await this.readAsync();
77
- return (0, resolver_2.resolveSubmitProfile)({ easJson, platform, profileName });
78
- }
79
- }
80
- exports.EasJsonReader = EasJsonReader;