react-native-platform-override 1.9.20 → 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,39 +1,39 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
import { WritableFileRepository } from './FileRepository';
|
|
8
|
-
import GitReactFileRepository from './GitReactFileRepository';
|
|
9
|
-
export interface UpgradeResult {
|
|
10
|
-
overrideName: string;
|
|
11
|
-
filesWritten: boolean;
|
|
12
|
-
hasConflicts: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* An UpgradeStrategy describes the process to upgrade an individual override
|
|
16
|
-
* to a new version of the React Native source tree.
|
|
17
|
-
*/
|
|
18
|
-
export default interface UpgradeStrategy {
|
|
19
|
-
upgrade(gitReactRepo: GitReactFileRepository, overrideRepo: WritableFileRepository, newVersion: string, allowConflicts: boolean): Promise<UpgradeResult>;
|
|
20
|
-
}
|
|
21
|
-
export declare const UpgradeStrategies: {
|
|
22
|
-
/**
|
|
23
|
-
* No work needed to upgrade
|
|
24
|
-
*/
|
|
25
|
-
assumeUpToDate: (overrideName: string) => UpgradeStrategy;
|
|
26
|
-
/**
|
|
27
|
-
* Perform a three way merge of the original base file, the overridden version
|
|
28
|
-
* of it, and the base file from a newwer version of React Native.
|
|
29
|
-
*/
|
|
30
|
-
threeWayMerge: (overrideName: string, baseFile: string, baseVersion: string) => UpgradeStrategy;
|
|
31
|
-
/**
|
|
32
|
-
* Overwrite our override with base file contents
|
|
33
|
-
*/
|
|
34
|
-
copyFile: (overrideName: string, baseFile: string) => UpgradeStrategy;
|
|
35
|
-
/**
|
|
36
|
-
* Overwrite our override with base file contents
|
|
37
|
-
*/
|
|
38
|
-
copyDirectory: (overrideDirectory: string, baseDirectory: string) => UpgradeStrategy;
|
|
39
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import { WritableFileRepository } from './FileRepository';
|
|
8
|
+
import GitReactFileRepository from './GitReactFileRepository';
|
|
9
|
+
export interface UpgradeResult {
|
|
10
|
+
overrideName: string;
|
|
11
|
+
filesWritten: boolean;
|
|
12
|
+
hasConflicts: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* An UpgradeStrategy describes the process to upgrade an individual override
|
|
16
|
+
* to a new version of the React Native source tree.
|
|
17
|
+
*/
|
|
18
|
+
export default interface UpgradeStrategy {
|
|
19
|
+
upgrade(gitReactRepo: GitReactFileRepository, overrideRepo: WritableFileRepository, newVersion: string, allowConflicts: boolean): Promise<UpgradeResult>;
|
|
20
|
+
}
|
|
21
|
+
export declare const UpgradeStrategies: {
|
|
22
|
+
/**
|
|
23
|
+
* No work needed to upgrade
|
|
24
|
+
*/
|
|
25
|
+
assumeUpToDate: (overrideName: string) => UpgradeStrategy;
|
|
26
|
+
/**
|
|
27
|
+
* Perform a three way merge of the original base file, the overridden version
|
|
28
|
+
* of it, and the base file from a newwer version of React Native.
|
|
29
|
+
*/
|
|
30
|
+
threeWayMerge: (overrideName: string, baseFile: string, baseVersion: string) => UpgradeStrategy;
|
|
31
|
+
/**
|
|
32
|
+
* Overwrite our override with base file contents
|
|
33
|
+
*/
|
|
34
|
+
copyFile: (overrideName: string, baseFile: string) => UpgradeStrategy;
|
|
35
|
+
/**
|
|
36
|
+
* Overwrite our override with base file contents
|
|
37
|
+
*/
|
|
38
|
+
copyDirectory: (overrideDirectory: string, baseDirectory: string) => UpgradeStrategy;
|
|
39
|
+
};
|
|
@@ -1,103 +1,103 @@
|
|
|
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
|
-
exports.UpgradeStrategies = void 0;
|
|
13
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
-
const path_1 = __importDefault(require("path"));
|
|
15
|
-
const FileRepository_1 = require("./FileRepository");
|
|
16
|
-
const Hash_1 = require("./Hash");
|
|
17
|
-
const isutf8_1 = __importDefault(require("isutf8"));
|
|
18
|
-
exports.UpgradeStrategies = {
|
|
19
|
-
/**
|
|
20
|
-
* No work needed to upgrade
|
|
21
|
-
*/
|
|
22
|
-
assumeUpToDate: (overrideName) => ({
|
|
23
|
-
upgrade: async () => ({
|
|
24
|
-
overrideName,
|
|
25
|
-
filesWritten: false,
|
|
26
|
-
hasConflicts: false,
|
|
27
|
-
}),
|
|
28
|
-
}),
|
|
29
|
-
/**
|
|
30
|
-
* Perform a three way merge of the original base file, the overridden version
|
|
31
|
-
* of it, and the base file from a newwer version of React Native.
|
|
32
|
-
*/
|
|
33
|
-
threeWayMerge: (overrideName, baseFile, baseVersion) => ({
|
|
34
|
-
upgrade: async (gitReactRepo, overrideRepo, newVersion, allowConflicts) => {
|
|
35
|
-
const ovrContent = await overrideRepo.readFile(overrideName);
|
|
36
|
-
if (ovrContent === null) {
|
|
37
|
-
throw new Error(`Could not read ${overrideName}`);
|
|
38
|
-
}
|
|
39
|
-
const ovrAsPatch = await gitReactRepo.generatePatch(baseFile, baseVersion, ovrContent);
|
|
40
|
-
if (ovrAsPatch.length === 0) {
|
|
41
|
-
throw new Error(`Generated patch for ${overrideName} was empty`);
|
|
42
|
-
}
|
|
43
|
-
const { patchedFile, hasConflicts } = await gitReactRepo.getPatchedFile(baseFile, newVersion, ovrAsPatch);
|
|
44
|
-
if (!patchedFile) {
|
|
45
|
-
return { overrideName, filesWritten: false, hasConflicts };
|
|
46
|
-
}
|
|
47
|
-
const prettyPatched = hasConflicts && (0, isutf8_1.default)(patchedFile)
|
|
48
|
-
? patchedFile
|
|
49
|
-
.toString('utf8')
|
|
50
|
-
.replace(/<<<<<<< ours/g, '<<<<<<< Upstream')
|
|
51
|
-
.replace(/>>>>>>> theirs/g, '>>>>>>> Override')
|
|
52
|
-
: patchedFile;
|
|
53
|
-
if (!hasConflicts || allowConflicts) {
|
|
54
|
-
await overrideRepo.writeFile(overrideName, prettyPatched);
|
|
55
|
-
return { overrideName, filesWritten: true, hasConflicts };
|
|
56
|
-
}
|
|
57
|
-
return { overrideName, filesWritten: false, hasConflicts };
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
/**
|
|
61
|
-
* Overwrite our override with base file contents
|
|
62
|
-
*/
|
|
63
|
-
copyFile: (overrideName, baseFile) => ({
|
|
64
|
-
upgrade: async (gitReactRepo, overrideRepo, newVersion) => {
|
|
65
|
-
const newContent = await gitReactRepo.readFile(baseFile, newVersion);
|
|
66
|
-
if (newContent === null) {
|
|
67
|
-
throw new Error(`Could not read ${baseFile}@${newVersion}`);
|
|
68
|
-
}
|
|
69
|
-
await overrideRepo.writeFile(overrideName, newContent);
|
|
70
|
-
return { overrideName, filesWritten: true, hasConflicts: false };
|
|
71
|
-
},
|
|
72
|
-
}),
|
|
73
|
-
/**
|
|
74
|
-
* Overwrite our override with base file contents
|
|
75
|
-
*/
|
|
76
|
-
copyDirectory: (overrideDirectory, baseDirectory) => ({
|
|
77
|
-
upgrade: async (gitReactRepo, overrideRepo, newVersion) => {
|
|
78
|
-
const baseFiles = (await gitReactRepo.listFiles([`${baseDirectory}/**`], newVersion)).map(f => path_1.default.relative(baseDirectory, f));
|
|
79
|
-
const overrideFiles = (await overrideRepo.listFiles([`${overrideDirectory}/**`])).map(f => path_1.default.relative(overrideDirectory, f));
|
|
80
|
-
// Note that this logic can leave empty directories. This shouldn't
|
|
81
|
-
// matter in practice as Git won't track them.
|
|
82
|
-
const deleteTasks = lodash_1.default.difference(overrideFiles, baseFiles).map(f => overrideRepo.deleteFile(path_1.default.join(overrideDirectory, f)));
|
|
83
|
-
const baseRepo = (0, FileRepository_1.bindVersion)(gitReactRepo, newVersion);
|
|
84
|
-
const copyTasks = baseFiles.map(async (f) => {
|
|
85
|
-
const basePath = path_1.default.join(baseDirectory, f);
|
|
86
|
-
const overridePath = path_1.default.join(overrideDirectory, f);
|
|
87
|
-
// Con't replace files of the same content but different line endings
|
|
88
|
-
if ((await (0, Hash_1.hashFileOrDirectory)(basePath, baseRepo)) !==
|
|
89
|
-
(await (0, Hash_1.hashFileOrDirectory)(overridePath, overrideRepo))) {
|
|
90
|
-
const content = await baseRepo.readFile(basePath);
|
|
91
|
-
await overrideRepo.writeFile(overridePath, content);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
await Promise.all([...deleteTasks, ...copyTasks]);
|
|
95
|
-
return {
|
|
96
|
-
overrideName: overrideDirectory,
|
|
97
|
-
filesWritten: true,
|
|
98
|
-
hasConflicts: false,
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
}),
|
|
102
|
-
};
|
|
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
|
+
exports.UpgradeStrategies = void 0;
|
|
13
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const FileRepository_1 = require("./FileRepository");
|
|
16
|
+
const Hash_1 = require("./Hash");
|
|
17
|
+
const isutf8_1 = __importDefault(require("isutf8"));
|
|
18
|
+
exports.UpgradeStrategies = {
|
|
19
|
+
/**
|
|
20
|
+
* No work needed to upgrade
|
|
21
|
+
*/
|
|
22
|
+
assumeUpToDate: (overrideName) => ({
|
|
23
|
+
upgrade: async () => ({
|
|
24
|
+
overrideName,
|
|
25
|
+
filesWritten: false,
|
|
26
|
+
hasConflicts: false,
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
/**
|
|
30
|
+
* Perform a three way merge of the original base file, the overridden version
|
|
31
|
+
* of it, and the base file from a newwer version of React Native.
|
|
32
|
+
*/
|
|
33
|
+
threeWayMerge: (overrideName, baseFile, baseVersion) => ({
|
|
34
|
+
upgrade: async (gitReactRepo, overrideRepo, newVersion, allowConflicts) => {
|
|
35
|
+
const ovrContent = await overrideRepo.readFile(overrideName);
|
|
36
|
+
if (ovrContent === null) {
|
|
37
|
+
throw new Error(`Could not read ${overrideName}`);
|
|
38
|
+
}
|
|
39
|
+
const ovrAsPatch = await gitReactRepo.generatePatch(baseFile, baseVersion, ovrContent);
|
|
40
|
+
if (ovrAsPatch.length === 0) {
|
|
41
|
+
throw new Error(`Generated patch for ${overrideName} was empty`);
|
|
42
|
+
}
|
|
43
|
+
const { patchedFile, hasConflicts } = await gitReactRepo.getPatchedFile(baseFile, newVersion, ovrAsPatch);
|
|
44
|
+
if (!patchedFile) {
|
|
45
|
+
return { overrideName, filesWritten: false, hasConflicts };
|
|
46
|
+
}
|
|
47
|
+
const prettyPatched = hasConflicts && (0, isutf8_1.default)(patchedFile)
|
|
48
|
+
? patchedFile
|
|
49
|
+
.toString('utf8')
|
|
50
|
+
.replace(/<<<<<<< ours/g, '<<<<<<< Upstream')
|
|
51
|
+
.replace(/>>>>>>> theirs/g, '>>>>>>> Override')
|
|
52
|
+
: patchedFile;
|
|
53
|
+
if (!hasConflicts || allowConflicts) {
|
|
54
|
+
await overrideRepo.writeFile(overrideName, prettyPatched);
|
|
55
|
+
return { overrideName, filesWritten: true, hasConflicts };
|
|
56
|
+
}
|
|
57
|
+
return { overrideName, filesWritten: false, hasConflicts };
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
/**
|
|
61
|
+
* Overwrite our override with base file contents
|
|
62
|
+
*/
|
|
63
|
+
copyFile: (overrideName, baseFile) => ({
|
|
64
|
+
upgrade: async (gitReactRepo, overrideRepo, newVersion) => {
|
|
65
|
+
const newContent = await gitReactRepo.readFile(baseFile, newVersion);
|
|
66
|
+
if (newContent === null) {
|
|
67
|
+
throw new Error(`Could not read ${baseFile}@${newVersion}`);
|
|
68
|
+
}
|
|
69
|
+
await overrideRepo.writeFile(overrideName, newContent);
|
|
70
|
+
return { overrideName, filesWritten: true, hasConflicts: false };
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
/**
|
|
74
|
+
* Overwrite our override with base file contents
|
|
75
|
+
*/
|
|
76
|
+
copyDirectory: (overrideDirectory, baseDirectory) => ({
|
|
77
|
+
upgrade: async (gitReactRepo, overrideRepo, newVersion) => {
|
|
78
|
+
const baseFiles = (await gitReactRepo.listFiles([`${baseDirectory}/**`], newVersion)).map(f => path_1.default.relative(baseDirectory, f));
|
|
79
|
+
const overrideFiles = (await overrideRepo.listFiles([`${overrideDirectory}/**`])).map(f => path_1.default.relative(overrideDirectory, f));
|
|
80
|
+
// Note that this logic can leave empty directories. This shouldn't
|
|
81
|
+
// matter in practice as Git won't track them.
|
|
82
|
+
const deleteTasks = lodash_1.default.difference(overrideFiles, baseFiles).map(f => overrideRepo.deleteFile(path_1.default.join(overrideDirectory, f)));
|
|
83
|
+
const baseRepo = (0, FileRepository_1.bindVersion)(gitReactRepo, newVersion);
|
|
84
|
+
const copyTasks = baseFiles.map(async (f) => {
|
|
85
|
+
const basePath = path_1.default.join(baseDirectory, f);
|
|
86
|
+
const overridePath = path_1.default.join(overrideDirectory, f);
|
|
87
|
+
// Con't replace files of the same content but different line endings
|
|
88
|
+
if ((await (0, Hash_1.hashFileOrDirectory)(basePath, baseRepo)) !==
|
|
89
|
+
(await (0, Hash_1.hashFileOrDirectory)(overridePath, overrideRepo))) {
|
|
90
|
+
const content = await baseRepo.readFile(basePath);
|
|
91
|
+
await overrideRepo.writeFile(overridePath, content);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
await Promise.all([...deleteTasks, ...copyTasks]);
|
|
95
|
+
return {
|
|
96
|
+
overrideName: overrideDirectory,
|
|
97
|
+
filesWritten: true,
|
|
98
|
+
hasConflicts: false,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
103
|
//# sourceMappingURL=UpgradeStrategy.js.map
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
import { ReactFileRepository, WritableFileRepository } from './FileRepository';
|
|
8
|
-
export interface ValidationError {
|
|
9
|
-
/**
|
|
10
|
-
* Why did validation fail?
|
|
11
|
-
*/
|
|
12
|
-
type: 'missingFromManifest' | 'overrideNotFound' | 'baseNotFound' | 'expectedFile' | 'expectedDirectory' | 'outOfDate' | 'overrideDifferentFromBase' | 'overrideSameAsBase';
|
|
13
|
-
/**
|
|
14
|
-
* What override failed validation
|
|
15
|
-
*/
|
|
16
|
-
overrideName: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A ValidationStrategy allows describing a process to ensure a specific
|
|
20
|
-
* override meets constraints such as ensuring file existence, preventing
|
|
21
|
-
* content modification, or being up to date.
|
|
22
|
-
*/
|
|
23
|
-
export default interface ValidationStrategy {
|
|
24
|
-
validate(overrideRepo: WritableFileRepository, reactRepo: ReactFileRepository): Promise<ValidationError[]>;
|
|
25
|
-
}
|
|
26
|
-
export declare const ValidationStrategies: {
|
|
27
|
-
/**
|
|
28
|
-
* Validate that an override file exists
|
|
29
|
-
*/
|
|
30
|
-
overrideFileExists: (overrideName: string) => ValidationStrategy;
|
|
31
|
-
/**
|
|
32
|
-
* Validate that a base file exists
|
|
33
|
-
*/
|
|
34
|
-
baseFileExists: (overrideName: string, baseFile: string) => ValidationStrategy;
|
|
35
|
-
/**
|
|
36
|
-
* Validate that an override directory exists
|
|
37
|
-
*/
|
|
38
|
-
overrideDirectoryExists: (overrideName: string) => ValidationStrategy;
|
|
39
|
-
/**
|
|
40
|
-
* Validate that a base directory exists
|
|
41
|
-
*/
|
|
42
|
-
baseDirectoryExists: (overrideName: string, baseDirectory: string) => ValidationStrategy;
|
|
43
|
-
/**
|
|
44
|
-
* Validate that a base file/folder matches an expected hash if it exists
|
|
45
|
-
*/
|
|
46
|
-
baseUpToDate: (overrideName: string, base: string, expectedBaseHash: string) => ValidationStrategy;
|
|
47
|
-
/**
|
|
48
|
-
* Validate that an override meant to be a copy of a base file/folder has not
|
|
49
|
-
* been tampered with
|
|
50
|
-
*/
|
|
51
|
-
overrideCopyOfBase: (overrideName: string, base: string) => ValidationStrategy;
|
|
52
|
-
/**
|
|
53
|
-
* Validate that an override assumed to be different from its base is not
|
|
54
|
-
* identical.
|
|
55
|
-
*/
|
|
56
|
-
overrideDifferentFromBase: (overrideName: string, base: string) => ValidationStrategy;
|
|
57
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import { ReactFileRepository, WritableFileRepository } from './FileRepository';
|
|
8
|
+
export interface ValidationError {
|
|
9
|
+
/**
|
|
10
|
+
* Why did validation fail?
|
|
11
|
+
*/
|
|
12
|
+
type: 'missingFromManifest' | 'overrideNotFound' | 'baseNotFound' | 'expectedFile' | 'expectedDirectory' | 'outOfDate' | 'overrideDifferentFromBase' | 'overrideSameAsBase';
|
|
13
|
+
/**
|
|
14
|
+
* What override failed validation
|
|
15
|
+
*/
|
|
16
|
+
overrideName: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A ValidationStrategy allows describing a process to ensure a specific
|
|
20
|
+
* override meets constraints such as ensuring file existence, preventing
|
|
21
|
+
* content modification, or being up to date.
|
|
22
|
+
*/
|
|
23
|
+
export default interface ValidationStrategy {
|
|
24
|
+
validate(overrideRepo: WritableFileRepository, reactRepo: ReactFileRepository): Promise<ValidationError[]>;
|
|
25
|
+
}
|
|
26
|
+
export declare const ValidationStrategies: {
|
|
27
|
+
/**
|
|
28
|
+
* Validate that an override file exists
|
|
29
|
+
*/
|
|
30
|
+
overrideFileExists: (overrideName: string) => ValidationStrategy;
|
|
31
|
+
/**
|
|
32
|
+
* Validate that a base file exists
|
|
33
|
+
*/
|
|
34
|
+
baseFileExists: (overrideName: string, baseFile: string) => ValidationStrategy;
|
|
35
|
+
/**
|
|
36
|
+
* Validate that an override directory exists
|
|
37
|
+
*/
|
|
38
|
+
overrideDirectoryExists: (overrideName: string) => ValidationStrategy;
|
|
39
|
+
/**
|
|
40
|
+
* Validate that a base directory exists
|
|
41
|
+
*/
|
|
42
|
+
baseDirectoryExists: (overrideName: string, baseDirectory: string) => ValidationStrategy;
|
|
43
|
+
/**
|
|
44
|
+
* Validate that a base file/folder matches an expected hash if it exists
|
|
45
|
+
*/
|
|
46
|
+
baseUpToDate: (overrideName: string, base: string, expectedBaseHash: string) => ValidationStrategy;
|
|
47
|
+
/**
|
|
48
|
+
* Validate that an override meant to be a copy of a base file/folder has not
|
|
49
|
+
* been tampered with
|
|
50
|
+
*/
|
|
51
|
+
overrideCopyOfBase: (overrideName: string, base: string) => ValidationStrategy;
|
|
52
|
+
/**
|
|
53
|
+
* Validate that an override assumed to be different from its base is not
|
|
54
|
+
* identical.
|
|
55
|
+
*/
|
|
56
|
+
overrideDifferentFromBase: (overrideName: string, base: string) => ValidationStrategy;
|
|
57
|
+
};
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ValidationStrategies = void 0;
|
|
10
|
-
const Hash_1 = require("./Hash");
|
|
11
|
-
exports.ValidationStrategies = {
|
|
12
|
-
/**
|
|
13
|
-
* Validate that an override file exists
|
|
14
|
-
*/
|
|
15
|
-
overrideFileExists: (overrideName) => ({
|
|
16
|
-
validate: async (overrideRepo) => {
|
|
17
|
-
switch (await overrideRepo.stat(overrideName)) {
|
|
18
|
-
case 'file':
|
|
19
|
-
return [];
|
|
20
|
-
case 'directory':
|
|
21
|
-
return [{ type: 'expectedFile', overrideName }];
|
|
22
|
-
case 'none':
|
|
23
|
-
return [{ type: 'overrideNotFound', overrideName }];
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
/**
|
|
28
|
-
* Validate that a base file exists
|
|
29
|
-
*/
|
|
30
|
-
baseFileExists: (overrideName, baseFile) => ({
|
|
31
|
-
validate: async (_, reactRepo) => {
|
|
32
|
-
switch (await reactRepo.stat(baseFile)) {
|
|
33
|
-
case 'file':
|
|
34
|
-
return [];
|
|
35
|
-
case 'directory':
|
|
36
|
-
return [{ type: 'expectedFile', overrideName }];
|
|
37
|
-
case 'none':
|
|
38
|
-
return [{ type: 'baseNotFound', overrideName }];
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
}),
|
|
42
|
-
/**
|
|
43
|
-
* Validate that an override directory exists
|
|
44
|
-
*/
|
|
45
|
-
overrideDirectoryExists: (overrideName) => ({
|
|
46
|
-
validate: async (overrideRepo) => {
|
|
47
|
-
switch (await overrideRepo.stat(overrideName)) {
|
|
48
|
-
case 'file':
|
|
49
|
-
return [{ type: 'expectedDirectory', overrideName }];
|
|
50
|
-
case 'directory':
|
|
51
|
-
return [];
|
|
52
|
-
case 'none':
|
|
53
|
-
return [{ type: 'overrideNotFound', overrideName }];
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
/**
|
|
58
|
-
* Validate that a base directory exists
|
|
59
|
-
*/
|
|
60
|
-
baseDirectoryExists: (overrideName, baseDirectory) => ({
|
|
61
|
-
validate: async (_, reactRepo) => {
|
|
62
|
-
switch (await reactRepo.stat(baseDirectory)) {
|
|
63
|
-
case 'file':
|
|
64
|
-
return [{ type: 'expectedDirectory', overrideName }];
|
|
65
|
-
case 'directory':
|
|
66
|
-
return [];
|
|
67
|
-
case 'none':
|
|
68
|
-
return [{ type: 'baseNotFound', overrideName }];
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
/**
|
|
73
|
-
* Validate that a base file/folder matches an expected hash if it exists
|
|
74
|
-
*/
|
|
75
|
-
baseUpToDate: (overrideName, base, expectedBaseHash) => ({
|
|
76
|
-
validate: async (_, reactRepo) => {
|
|
77
|
-
const hash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo);
|
|
78
|
-
if (!hash) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
return hash === expectedBaseHash
|
|
82
|
-
? []
|
|
83
|
-
: [{ type: 'outOfDate', overrideName }];
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
/**
|
|
87
|
-
* Validate that an override meant to be a copy of a base file/folder has not
|
|
88
|
-
* been tampered with
|
|
89
|
-
*/
|
|
90
|
-
overrideCopyOfBase: (overrideName, base) => ({
|
|
91
|
-
validate: async (overrideRepo, reactRepo) => {
|
|
92
|
-
if ((await overrideRepo.stat(overrideName)) === 'none' ||
|
|
93
|
-
(await reactRepo.stat(base)) === 'none') {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
const overrideHash = await (0, Hash_1.hashFileOrDirectory)(overrideName, overrideRepo);
|
|
97
|
-
const baseHash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo);
|
|
98
|
-
return overrideHash === baseHash
|
|
99
|
-
? []
|
|
100
|
-
: [{ type: 'overrideDifferentFromBase', overrideName }];
|
|
101
|
-
},
|
|
102
|
-
}),
|
|
103
|
-
/**
|
|
104
|
-
* Validate that an override assumed to be different from its base is not
|
|
105
|
-
* identical.
|
|
106
|
-
*/
|
|
107
|
-
overrideDifferentFromBase: (overrideName, base) => ({
|
|
108
|
-
validate: async (overrideRepo, reactRepo) => {
|
|
109
|
-
if ((await overrideRepo.stat(overrideName)) === 'none' ||
|
|
110
|
-
(await reactRepo.stat(base)) === 'none') {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
// There can be whitespace differences from merges that lead to
|
|
114
|
-
// semantically identical files. Do a whitespace insensitive compare to
|
|
115
|
-
// determine if there is a difference.
|
|
116
|
-
const hashOpts = { insensitivity: 'whitespace' };
|
|
117
|
-
const overrideHash = await (0, Hash_1.hashFileOrDirectory)(overrideName, overrideRepo, hashOpts);
|
|
118
|
-
const baseHash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo, hashOpts);
|
|
119
|
-
return overrideHash === baseHash
|
|
120
|
-
? [{ type: 'overrideSameAsBase', overrideName }]
|
|
121
|
-
: [];
|
|
122
|
-
},
|
|
123
|
-
}),
|
|
124
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ValidationStrategies = void 0;
|
|
10
|
+
const Hash_1 = require("./Hash");
|
|
11
|
+
exports.ValidationStrategies = {
|
|
12
|
+
/**
|
|
13
|
+
* Validate that an override file exists
|
|
14
|
+
*/
|
|
15
|
+
overrideFileExists: (overrideName) => ({
|
|
16
|
+
validate: async (overrideRepo) => {
|
|
17
|
+
switch (await overrideRepo.stat(overrideName)) {
|
|
18
|
+
case 'file':
|
|
19
|
+
return [];
|
|
20
|
+
case 'directory':
|
|
21
|
+
return [{ type: 'expectedFile', overrideName }];
|
|
22
|
+
case 'none':
|
|
23
|
+
return [{ type: 'overrideNotFound', overrideName }];
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
/**
|
|
28
|
+
* Validate that a base file exists
|
|
29
|
+
*/
|
|
30
|
+
baseFileExists: (overrideName, baseFile) => ({
|
|
31
|
+
validate: async (_, reactRepo) => {
|
|
32
|
+
switch (await reactRepo.stat(baseFile)) {
|
|
33
|
+
case 'file':
|
|
34
|
+
return [];
|
|
35
|
+
case 'directory':
|
|
36
|
+
return [{ type: 'expectedFile', overrideName }];
|
|
37
|
+
case 'none':
|
|
38
|
+
return [{ type: 'baseNotFound', overrideName }];
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
/**
|
|
43
|
+
* Validate that an override directory exists
|
|
44
|
+
*/
|
|
45
|
+
overrideDirectoryExists: (overrideName) => ({
|
|
46
|
+
validate: async (overrideRepo) => {
|
|
47
|
+
switch (await overrideRepo.stat(overrideName)) {
|
|
48
|
+
case 'file':
|
|
49
|
+
return [{ type: 'expectedDirectory', overrideName }];
|
|
50
|
+
case 'directory':
|
|
51
|
+
return [];
|
|
52
|
+
case 'none':
|
|
53
|
+
return [{ type: 'overrideNotFound', overrideName }];
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
/**
|
|
58
|
+
* Validate that a base directory exists
|
|
59
|
+
*/
|
|
60
|
+
baseDirectoryExists: (overrideName, baseDirectory) => ({
|
|
61
|
+
validate: async (_, reactRepo) => {
|
|
62
|
+
switch (await reactRepo.stat(baseDirectory)) {
|
|
63
|
+
case 'file':
|
|
64
|
+
return [{ type: 'expectedDirectory', overrideName }];
|
|
65
|
+
case 'directory':
|
|
66
|
+
return [];
|
|
67
|
+
case 'none':
|
|
68
|
+
return [{ type: 'baseNotFound', overrideName }];
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
/**
|
|
73
|
+
* Validate that a base file/folder matches an expected hash if it exists
|
|
74
|
+
*/
|
|
75
|
+
baseUpToDate: (overrideName, base, expectedBaseHash) => ({
|
|
76
|
+
validate: async (_, reactRepo) => {
|
|
77
|
+
const hash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo);
|
|
78
|
+
if (!hash) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
return hash === expectedBaseHash
|
|
82
|
+
? []
|
|
83
|
+
: [{ type: 'outOfDate', overrideName }];
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
/**
|
|
87
|
+
* Validate that an override meant to be a copy of a base file/folder has not
|
|
88
|
+
* been tampered with
|
|
89
|
+
*/
|
|
90
|
+
overrideCopyOfBase: (overrideName, base) => ({
|
|
91
|
+
validate: async (overrideRepo, reactRepo) => {
|
|
92
|
+
if ((await overrideRepo.stat(overrideName)) === 'none' ||
|
|
93
|
+
(await reactRepo.stat(base)) === 'none') {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
const overrideHash = await (0, Hash_1.hashFileOrDirectory)(overrideName, overrideRepo);
|
|
97
|
+
const baseHash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo);
|
|
98
|
+
return overrideHash === baseHash
|
|
99
|
+
? []
|
|
100
|
+
: [{ type: 'overrideDifferentFromBase', overrideName }];
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
/**
|
|
104
|
+
* Validate that an override assumed to be different from its base is not
|
|
105
|
+
* identical.
|
|
106
|
+
*/
|
|
107
|
+
overrideDifferentFromBase: (overrideName, base) => ({
|
|
108
|
+
validate: async (overrideRepo, reactRepo) => {
|
|
109
|
+
if ((await overrideRepo.stat(overrideName)) === 'none' ||
|
|
110
|
+
(await reactRepo.stat(base)) === 'none') {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
// There can be whitespace differences from merges that lead to
|
|
114
|
+
// semantically identical files. Do a whitespace insensitive compare to
|
|
115
|
+
// determine if there is a difference.
|
|
116
|
+
const hashOpts = { insensitivity: 'whitespace' };
|
|
117
|
+
const overrideHash = await (0, Hash_1.hashFileOrDirectory)(overrideName, overrideRepo, hashOpts);
|
|
118
|
+
const baseHash = await (0, Hash_1.hashFileOrDirectory)(base, reactRepo, hashOpts);
|
|
119
|
+
return overrideHash === baseHash
|
|
120
|
+
? [{ type: 'overrideSameAsBase', overrideName }]
|
|
121
|
+
: [];
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
125
|
//# sourceMappingURL=ValidationStrategy.js.map
|