react-native-platform-override 1.9.21 → 1.9.22
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/lib-commonjs/Api.d.ts +57 -57
- package/lib-commonjs/Api.js +187 -187
- package/lib-commonjs/BatchingQueue.d.ts +15 -15
- package/lib-commonjs/BatchingQueue.js +57 -57
- package/lib-commonjs/Cli.d.ts +7 -7
- package/lib-commonjs/Cli.js +323 -323
- package/lib-commonjs/CrossProcessLock.d.ts +44 -44
- package/lib-commonjs/CrossProcessLock.js +147 -147
- package/lib-commonjs/DiffStrategy.d.ts +24 -24
- package/lib-commonjs/DiffStrategy.js +34 -34
- package/lib-commonjs/FileRepository.d.ts +62 -62
- package/lib-commonjs/FileRepository.js +21 -21
- package/lib-commonjs/FileSearch.d.ts +21 -21
- package/lib-commonjs/FileSearch.js +77 -77
- package/lib-commonjs/FileSystemRepository.d.ts +20 -20
- package/lib-commonjs/FileSystemRepository.js +62 -62
- package/lib-commonjs/GitReactFileRepository.d.ts +56 -56
- package/lib-commonjs/GitReactFileRepository.js +202 -202
- package/lib-commonjs/Hash.d.ts +33 -33
- package/lib-commonjs/Hash.js +81 -81
- package/lib-commonjs/Manifest.d.ts +80 -80
- package/lib-commonjs/Manifest.js +157 -157
- package/lib-commonjs/Override.d.ts +182 -182
- package/lib-commonjs/Override.js +248 -248
- package/lib-commonjs/OverrideFactory.d.ts +33 -33
- package/lib-commonjs/OverrideFactory.js +85 -85
- package/lib-commonjs/OverridePrompt.d.ts +30 -30
- package/lib-commonjs/OverridePrompt.js +130 -130
- package/lib-commonjs/PackageUtils.d.ts +15 -15
- package/lib-commonjs/PackageUtils.js +40 -40
- package/lib-commonjs/PathUtils.d.ts +14 -14
- package/lib-commonjs/PathUtils.js +31 -31
- package/lib-commonjs/Serialized.d.ts +158 -158
- package/lib-commonjs/Serialized.js +145 -145
- package/lib-commonjs/UpgradeStrategy.d.ts +39 -39
- package/lib-commonjs/UpgradeStrategy.js +102 -102
- package/lib-commonjs/ValidationStrategy.d.ts +57 -57
- package/lib-commonjs/ValidationStrategy.js +124 -124
- package/lib-commonjs/refFromVersion.d.ts +10 -10
- package/lib-commonjs/refFromVersion.js +98 -98
- package/lib-commonjs/refFromVersion.js.map +1 -1
- package/lib-commonjs/scripts/generateManifest.d.ts +7 -7
- package/lib-commonjs/scripts/generateManifest.js +196 -196
- package/lib-commonjs/scripts/hashFile.d.ts +7 -7
- package/lib-commonjs/scripts/hashFile.js +17 -17
- package/lib-commonjs/scripts/testLocks.d.ts +1 -1
- package/lib-commonjs/scripts/testLocks.js +29 -29
- package/package.json +10 -10
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
import * as Serialized from './Serialized';
|
|
8
|
-
import Override from './Override';
|
|
9
|
-
import { ReactFileRepository, WritableFileRepository } from './FileRepository';
|
|
10
|
-
import OverrideFactory from './OverrideFactory';
|
|
11
|
-
import { ValidationError } from './ValidationStrategy';
|
|
12
|
-
/**
|
|
13
|
-
* Represents a collection of overrides listed in an on-disk manifest. Allows
|
|
14
|
-
* performing aggregate operations on the overrides.
|
|
15
|
-
*/
|
|
16
|
-
export default class Manifest {
|
|
17
|
-
private readonly includePatterns?;
|
|
18
|
-
private readonly excludePatterns?;
|
|
19
|
-
private baseVersion?;
|
|
20
|
-
private readonly overrides;
|
|
21
|
-
/**
|
|
22
|
-
* Construct the manifest
|
|
23
|
-
*
|
|
24
|
-
* @param overrides List of overrides to evaluate
|
|
25
|
-
* @param opts Allows specifying globs to include or exclude paths to enforce
|
|
26
|
-
* exist in the manifest
|
|
27
|
-
*/
|
|
28
|
-
constructor(overrides: Override[], opts?: {
|
|
29
|
-
includePatterns?: string[];
|
|
30
|
-
excludePatterns?: string[];
|
|
31
|
-
baseVersion?: string;
|
|
32
|
-
});
|
|
33
|
-
static fromSerialized(man: Serialized.Manifest): Manifest;
|
|
34
|
-
/**
|
|
35
|
-
* Check that overrides are accurately accounted for in the manifest. E.g.
|
|
36
|
-
* all files should be accounted for, and base files should be up to date
|
|
37
|
-
* with upstream.
|
|
38
|
-
*/
|
|
39
|
-
validate(overrideRepo: WritableFileRepository, reactRepo: ReactFileRepository): Promise<ValidationError[]>;
|
|
40
|
-
/**
|
|
41
|
-
* Add an override to the manifest
|
|
42
|
-
*/
|
|
43
|
-
addOverride(override: Override): void;
|
|
44
|
-
/**
|
|
45
|
-
* Whether the manifest contains a given override
|
|
46
|
-
*/
|
|
47
|
-
hasOverride(overrideName: string): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Try to remove an override.
|
|
50
|
-
* @returns false if none is found with the given name
|
|
51
|
-
*/
|
|
52
|
-
removeOverride(overrideName: string): boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Returns the entry corresponding to the given override path, or null if none
|
|
55
|
-
* exists.
|
|
56
|
-
*/
|
|
57
|
-
findOverride(overrideName: string): Override | null;
|
|
58
|
-
/**
|
|
59
|
-
* Updates an override entry to mark it as up-to-date in regards to its
|
|
60
|
-
* current base file.
|
|
61
|
-
*/
|
|
62
|
-
markUpToDate(overrideName: string, overrideFactory: OverrideFactory): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Return a serialized representation of the manifest
|
|
65
|
-
*/
|
|
66
|
-
serialize(): Serialized.Manifest;
|
|
67
|
-
/**
|
|
68
|
-
* Returns the overrides in the manifest
|
|
69
|
-
*/
|
|
70
|
-
listOverrides(): Override[];
|
|
71
|
-
/**
|
|
72
|
-
* Set the default baseVersion for the manifest
|
|
73
|
-
*/
|
|
74
|
-
setBaseVersion(baseVersion?: string): void;
|
|
75
|
-
/**
|
|
76
|
-
* Find the index to a given override.
|
|
77
|
-
* @returns -1 if it cannot be found
|
|
78
|
-
*/
|
|
79
|
-
private findOverrideIndex;
|
|
80
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import * as Serialized from './Serialized';
|
|
8
|
+
import Override from './Override';
|
|
9
|
+
import { ReactFileRepository, WritableFileRepository } from './FileRepository';
|
|
10
|
+
import OverrideFactory from './OverrideFactory';
|
|
11
|
+
import { ValidationError } from './ValidationStrategy';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a collection of overrides listed in an on-disk manifest. Allows
|
|
14
|
+
* performing aggregate operations on the overrides.
|
|
15
|
+
*/
|
|
16
|
+
export default class Manifest {
|
|
17
|
+
private readonly includePatterns?;
|
|
18
|
+
private readonly excludePatterns?;
|
|
19
|
+
private baseVersion?;
|
|
20
|
+
private readonly overrides;
|
|
21
|
+
/**
|
|
22
|
+
* Construct the manifest
|
|
23
|
+
*
|
|
24
|
+
* @param overrides List of overrides to evaluate
|
|
25
|
+
* @param opts Allows specifying globs to include or exclude paths to enforce
|
|
26
|
+
* exist in the manifest
|
|
27
|
+
*/
|
|
28
|
+
constructor(overrides: Override[], opts?: {
|
|
29
|
+
includePatterns?: string[];
|
|
30
|
+
excludePatterns?: string[];
|
|
31
|
+
baseVersion?: string;
|
|
32
|
+
});
|
|
33
|
+
static fromSerialized(man: Serialized.Manifest): Manifest;
|
|
34
|
+
/**
|
|
35
|
+
* Check that overrides are accurately accounted for in the manifest. E.g.
|
|
36
|
+
* all files should be accounted for, and base files should be up to date
|
|
37
|
+
* with upstream.
|
|
38
|
+
*/
|
|
39
|
+
validate(overrideRepo: WritableFileRepository, reactRepo: ReactFileRepository): Promise<ValidationError[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Add an override to the manifest
|
|
42
|
+
*/
|
|
43
|
+
addOverride(override: Override): void;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the manifest contains a given override
|
|
46
|
+
*/
|
|
47
|
+
hasOverride(overrideName: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Try to remove an override.
|
|
50
|
+
* @returns false if none is found with the given name
|
|
51
|
+
*/
|
|
52
|
+
removeOverride(overrideName: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the entry corresponding to the given override path, or null if none
|
|
55
|
+
* exists.
|
|
56
|
+
*/
|
|
57
|
+
findOverride(overrideName: string): Override | null;
|
|
58
|
+
/**
|
|
59
|
+
* Updates an override entry to mark it as up-to-date in regards to its
|
|
60
|
+
* current base file.
|
|
61
|
+
*/
|
|
62
|
+
markUpToDate(overrideName: string, overrideFactory: OverrideFactory): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Return a serialized representation of the manifest
|
|
65
|
+
*/
|
|
66
|
+
serialize(): Serialized.Manifest;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the overrides in the manifest
|
|
69
|
+
*/
|
|
70
|
+
listOverrides(): Override[];
|
|
71
|
+
/**
|
|
72
|
+
* Set the default baseVersion for the manifest
|
|
73
|
+
*/
|
|
74
|
+
setBaseVersion(baseVersion?: string): void;
|
|
75
|
+
/**
|
|
76
|
+
* Find the index to a given override.
|
|
77
|
+
* @returns -1 if it cannot be found
|
|
78
|
+
*/
|
|
79
|
+
private findOverrideIndex;
|
|
80
|
+
}
|
package/lib-commonjs/Manifest.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
|
-
const Override_1 = require("./Override");
|
|
15
|
-
const async_1 = require("async");
|
|
16
|
-
const PathUtils_1 = require("./PathUtils");
|
|
17
|
-
/**
|
|
18
|
-
* Represents a collection of overrides listed in an on-disk manifest. Allows
|
|
19
|
-
* performing aggregate operations on the overrides.
|
|
20
|
-
*/
|
|
21
|
-
class Manifest {
|
|
22
|
-
/**
|
|
23
|
-
* Construct the manifest
|
|
24
|
-
*
|
|
25
|
-
* @param overrides List of overrides to evaluate
|
|
26
|
-
* @param opts Allows specifying globs to include or exclude paths to enforce
|
|
27
|
-
* exist in the manifest
|
|
28
|
-
*/
|
|
29
|
-
constructor(overrides, opts = {}) {
|
|
30
|
-
const uniquelyNamed = lodash_1.default.uniqBy(overrides, ovr => ovr.name());
|
|
31
|
-
if (uniquelyNamed.length !== overrides.length) {
|
|
32
|
-
throw new Error('Cannot construct a manifest with duplicate overrides');
|
|
33
|
-
}
|
|
34
|
-
this.includePatterns = opts.includePatterns;
|
|
35
|
-
this.excludePatterns = opts.excludePatterns;
|
|
36
|
-
this.baseVersion = opts.baseVersion;
|
|
37
|
-
this.overrides = lodash_1.default.clone(overrides);
|
|
38
|
-
}
|
|
39
|
-
static fromSerialized(man) {
|
|
40
|
-
const overrides = man.overrides.map(ovr => (0, Override_1.deserializeOverride)(ovr, { defaultBaseVersion: man.baseVersion }));
|
|
41
|
-
return new Manifest(overrides, {
|
|
42
|
-
includePatterns: man.includePatterns,
|
|
43
|
-
excludePatterns: man.excludePatterns,
|
|
44
|
-
baseVersion: man.baseVersion,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Check that overrides are accurately accounted for in the manifest. E.g.
|
|
49
|
-
* all files should be accounted for, and base files should be up to date
|
|
50
|
-
* with upstream.
|
|
51
|
-
*/
|
|
52
|
-
async validate(overrideRepo, reactRepo) {
|
|
53
|
-
const errors = [];
|
|
54
|
-
const globs = [
|
|
55
|
-
...(this.includePatterns || ['**']),
|
|
56
|
-
...(this.excludePatterns || []).map(p => '!' + p),
|
|
57
|
-
];
|
|
58
|
-
const overrideFiles = await overrideRepo.listFiles(globs);
|
|
59
|
-
const missingFromManifest = overrideFiles.filter(file => file !== 'overrides.json' &&
|
|
60
|
-
path_1.default.relative('node_modules', file).startsWith('..') &&
|
|
61
|
-
!this.overrides.some(override => override.includesFile(file)));
|
|
62
|
-
for (const missingFile of missingFromManifest) {
|
|
63
|
-
errors.push({ type: 'missingFromManifest', overrideName: missingFile });
|
|
64
|
-
}
|
|
65
|
-
const validationTasks = lodash_1.default.flatMap(this.overrides, ovr => ovr.validationStrategies());
|
|
66
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
67
|
-
await (0, async_1.eachLimit)(validationTasks, 30, async (task) => {
|
|
68
|
-
errors.push(...(await task.validate(overrideRepo, reactRepo)));
|
|
69
|
-
});
|
|
70
|
-
return errors.sort((a, b) => a.overrideName.localeCompare(b.overrideName, 'en'));
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Add an override to the manifest
|
|
74
|
-
*/
|
|
75
|
-
addOverride(override) {
|
|
76
|
-
if (this.hasOverride(override.name())) {
|
|
77
|
-
throw new Error(`Trying to add duplicate override '${override.name()}'`);
|
|
78
|
-
}
|
|
79
|
-
this.overrides.push(override);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Whether the manifest contains a given override
|
|
83
|
-
*/
|
|
84
|
-
hasOverride(overrideName) {
|
|
85
|
-
return this.overrides.some(ovr => ovr.name() === (0, PathUtils_1.normalizePath)(overrideName));
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Try to remove an override.
|
|
89
|
-
* @returns false if none is found with the given name
|
|
90
|
-
*/
|
|
91
|
-
removeOverride(overrideName) {
|
|
92
|
-
const idx = this.findOverrideIndex(overrideName);
|
|
93
|
-
if (idx === -1) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
this.overrides.splice(idx, 1);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Returns the entry corresponding to the given override path, or null if none
|
|
101
|
-
* exists.
|
|
102
|
-
*/
|
|
103
|
-
findOverride(overrideName) {
|
|
104
|
-
const idx = this.findOverrideIndex(overrideName);
|
|
105
|
-
if (idx === -1) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
return this.overrides[idx];
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Updates an override entry to mark it as up-to-date in regards to its
|
|
112
|
-
* current base file.
|
|
113
|
-
*/
|
|
114
|
-
async markUpToDate(overrideName, overrideFactory) {
|
|
115
|
-
const override = this.findOverride(overrideName);
|
|
116
|
-
if (override === null) {
|
|
117
|
-
throw new Error(`Override '${overrideName}' does not exist`);
|
|
118
|
-
}
|
|
119
|
-
// Mutate the object instead of replacing by index because the index may no
|
|
120
|
-
// longer be the same after awaiting.
|
|
121
|
-
const upToDateOverride = await override.createUpdated(overrideFactory);
|
|
122
|
-
Object.assign(override, upToDateOverride);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Return a serialized representation of the manifest
|
|
126
|
-
*/
|
|
127
|
-
serialize() {
|
|
128
|
-
return {
|
|
129
|
-
includePatterns: this.includePatterns,
|
|
130
|
-
excludePatterns: this.excludePatterns,
|
|
131
|
-
baseVersion: this.baseVersion,
|
|
132
|
-
overrides: this.overrides
|
|
133
|
-
.sort((a, b) => a.name().localeCompare(b.name(), 'en'))
|
|
134
|
-
.map(override => override.serialize({ defaultBaseVersion: this.baseVersion })),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Returns the overrides in the manifest
|
|
139
|
-
*/
|
|
140
|
-
listOverrides() {
|
|
141
|
-
return lodash_1.default.clone(this.overrides);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Set the default baseVersion for the manifest
|
|
145
|
-
*/
|
|
146
|
-
setBaseVersion(baseVersion) {
|
|
147
|
-
this.baseVersion = baseVersion;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Find the index to a given override.
|
|
151
|
-
* @returns -1 if it cannot be found
|
|
152
|
-
*/
|
|
153
|
-
findOverrideIndex(overrideName) {
|
|
154
|
-
return this.overrides.findIndex(ovr => ovr.name() === (0, PathUtils_1.normalizePath)(overrideName));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.default = Manifest;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const Override_1 = require("./Override");
|
|
15
|
+
const async_1 = require("async");
|
|
16
|
+
const PathUtils_1 = require("./PathUtils");
|
|
17
|
+
/**
|
|
18
|
+
* Represents a collection of overrides listed in an on-disk manifest. Allows
|
|
19
|
+
* performing aggregate operations on the overrides.
|
|
20
|
+
*/
|
|
21
|
+
class Manifest {
|
|
22
|
+
/**
|
|
23
|
+
* Construct the manifest
|
|
24
|
+
*
|
|
25
|
+
* @param overrides List of overrides to evaluate
|
|
26
|
+
* @param opts Allows specifying globs to include or exclude paths to enforce
|
|
27
|
+
* exist in the manifest
|
|
28
|
+
*/
|
|
29
|
+
constructor(overrides, opts = {}) {
|
|
30
|
+
const uniquelyNamed = lodash_1.default.uniqBy(overrides, ovr => ovr.name());
|
|
31
|
+
if (uniquelyNamed.length !== overrides.length) {
|
|
32
|
+
throw new Error('Cannot construct a manifest with duplicate overrides');
|
|
33
|
+
}
|
|
34
|
+
this.includePatterns = opts.includePatterns;
|
|
35
|
+
this.excludePatterns = opts.excludePatterns;
|
|
36
|
+
this.baseVersion = opts.baseVersion;
|
|
37
|
+
this.overrides = lodash_1.default.clone(overrides);
|
|
38
|
+
}
|
|
39
|
+
static fromSerialized(man) {
|
|
40
|
+
const overrides = man.overrides.map(ovr => (0, Override_1.deserializeOverride)(ovr, { defaultBaseVersion: man.baseVersion }));
|
|
41
|
+
return new Manifest(overrides, {
|
|
42
|
+
includePatterns: man.includePatterns,
|
|
43
|
+
excludePatterns: man.excludePatterns,
|
|
44
|
+
baseVersion: man.baseVersion,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check that overrides are accurately accounted for in the manifest. E.g.
|
|
49
|
+
* all files should be accounted for, and base files should be up to date
|
|
50
|
+
* with upstream.
|
|
51
|
+
*/
|
|
52
|
+
async validate(overrideRepo, reactRepo) {
|
|
53
|
+
const errors = [];
|
|
54
|
+
const globs = [
|
|
55
|
+
...(this.includePatterns || ['**']),
|
|
56
|
+
...(this.excludePatterns || []).map(p => '!' + p),
|
|
57
|
+
];
|
|
58
|
+
const overrideFiles = await overrideRepo.listFiles(globs);
|
|
59
|
+
const missingFromManifest = overrideFiles.filter(file => file !== 'overrides.json' &&
|
|
60
|
+
path_1.default.relative('node_modules', file).startsWith('..') &&
|
|
61
|
+
!this.overrides.some(override => override.includesFile(file)));
|
|
62
|
+
for (const missingFile of missingFromManifest) {
|
|
63
|
+
errors.push({ type: 'missingFromManifest', overrideName: missingFile });
|
|
64
|
+
}
|
|
65
|
+
const validationTasks = lodash_1.default.flatMap(this.overrides, ovr => ovr.validationStrategies());
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
67
|
+
await (0, async_1.eachLimit)(validationTasks, 30, async (task) => {
|
|
68
|
+
errors.push(...(await task.validate(overrideRepo, reactRepo)));
|
|
69
|
+
});
|
|
70
|
+
return errors.sort((a, b) => a.overrideName.localeCompare(b.overrideName, 'en'));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Add an override to the manifest
|
|
74
|
+
*/
|
|
75
|
+
addOverride(override) {
|
|
76
|
+
if (this.hasOverride(override.name())) {
|
|
77
|
+
throw new Error(`Trying to add duplicate override '${override.name()}'`);
|
|
78
|
+
}
|
|
79
|
+
this.overrides.push(override);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether the manifest contains a given override
|
|
83
|
+
*/
|
|
84
|
+
hasOverride(overrideName) {
|
|
85
|
+
return this.overrides.some(ovr => ovr.name() === (0, PathUtils_1.normalizePath)(overrideName));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Try to remove an override.
|
|
89
|
+
* @returns false if none is found with the given name
|
|
90
|
+
*/
|
|
91
|
+
removeOverride(overrideName) {
|
|
92
|
+
const idx = this.findOverrideIndex(overrideName);
|
|
93
|
+
if (idx === -1) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
this.overrides.splice(idx, 1);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the entry corresponding to the given override path, or null if none
|
|
101
|
+
* exists.
|
|
102
|
+
*/
|
|
103
|
+
findOverride(overrideName) {
|
|
104
|
+
const idx = this.findOverrideIndex(overrideName);
|
|
105
|
+
if (idx === -1) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return this.overrides[idx];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Updates an override entry to mark it as up-to-date in regards to its
|
|
112
|
+
* current base file.
|
|
113
|
+
*/
|
|
114
|
+
async markUpToDate(overrideName, overrideFactory) {
|
|
115
|
+
const override = this.findOverride(overrideName);
|
|
116
|
+
if (override === null) {
|
|
117
|
+
throw new Error(`Override '${overrideName}' does not exist`);
|
|
118
|
+
}
|
|
119
|
+
// Mutate the object instead of replacing by index because the index may no
|
|
120
|
+
// longer be the same after awaiting.
|
|
121
|
+
const upToDateOverride = await override.createUpdated(overrideFactory);
|
|
122
|
+
Object.assign(override, upToDateOverride);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Return a serialized representation of the manifest
|
|
126
|
+
*/
|
|
127
|
+
serialize() {
|
|
128
|
+
return {
|
|
129
|
+
includePatterns: this.includePatterns,
|
|
130
|
+
excludePatterns: this.excludePatterns,
|
|
131
|
+
baseVersion: this.baseVersion,
|
|
132
|
+
overrides: this.overrides
|
|
133
|
+
.sort((a, b) => a.name().localeCompare(b.name(), 'en'))
|
|
134
|
+
.map(override => override.serialize({ defaultBaseVersion: this.baseVersion })),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Returns the overrides in the manifest
|
|
139
|
+
*/
|
|
140
|
+
listOverrides() {
|
|
141
|
+
return lodash_1.default.clone(this.overrides);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Set the default baseVersion for the manifest
|
|
145
|
+
*/
|
|
146
|
+
setBaseVersion(baseVersion) {
|
|
147
|
+
this.baseVersion = baseVersion;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Find the index to a given override.
|
|
151
|
+
* @returns -1 if it cannot be found
|
|
152
|
+
*/
|
|
153
|
+
findOverrideIndex(overrideName) {
|
|
154
|
+
return this.overrides.findIndex(ovr => ovr.name() === (0, PathUtils_1.normalizePath)(overrideName));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.default = Manifest;
|
|
158
158
|
//# sourceMappingURL=Manifest.js.map
|