react-native-platform-override 0.4.7 → 0.81.0-preview.10
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/bin.js +1 -2
- package/lib-commonjs/Api.d.ts +57 -56
- package/lib-commonjs/Api.js +187 -167
- package/lib-commonjs/Api.js.map +1 -1
- package/lib-commonjs/BatchingQueue.d.ts +15 -15
- package/lib-commonjs/BatchingQueue.js +57 -57
- package/lib-commonjs/BatchingQueue.js.map +1 -1
- package/lib-commonjs/Cli.d.ts +7 -7
- package/lib-commonjs/Cli.js +323 -291
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/CrossProcessLock.d.ts +44 -44
- package/lib-commonjs/CrossProcessLock.js +147 -144
- package/lib-commonjs/CrossProcessLock.js.map +1 -1
- package/lib-commonjs/DiffStrategy.d.ts +24 -24
- package/lib-commonjs/DiffStrategy.js +34 -34
- package/lib-commonjs/DiffStrategy.js.map +1 -1
- package/lib-commonjs/FileRepository.d.ts +63 -62
- package/lib-commonjs/FileRepository.js +21 -21
- package/lib-commonjs/FileRepository.js.map +1 -1
- package/lib-commonjs/FileSearch.d.ts +21 -21
- package/lib-commonjs/FileSearch.js +77 -91
- package/lib-commonjs/FileSearch.js.map +1 -1
- package/lib-commonjs/FileSystemRepository.d.ts +21 -20
- package/lib-commonjs/FileSystemRepository.js +62 -59
- package/lib-commonjs/FileSystemRepository.js.map +1 -1
- package/lib-commonjs/GitReactFileRepository.d.ts +57 -58
- package/lib-commonjs/GitReactFileRepository.js +202 -208
- package/lib-commonjs/GitReactFileRepository.js.map +1 -1
- package/lib-commonjs/Hash.d.ts +34 -33
- package/lib-commonjs/Hash.js +81 -81
- package/lib-commonjs/Hash.js.map +1 -1
- package/lib-commonjs/Manifest.d.ts +80 -80
- package/lib-commonjs/Manifest.js +157 -154
- package/lib-commonjs/Manifest.js.map +1 -1
- package/lib-commonjs/Override.d.ts +182 -182
- package/lib-commonjs/Override.js +248 -245
- package/lib-commonjs/Override.js.map +1 -1
- package/lib-commonjs/OverrideFactory.d.ts +33 -33
- package/lib-commonjs/OverrideFactory.js +85 -70
- package/lib-commonjs/OverrideFactory.js.map +1 -1
- package/lib-commonjs/OverridePrompt.d.ts +30 -30
- package/lib-commonjs/OverridePrompt.js +130 -104
- package/lib-commonjs/OverridePrompt.js.map +1 -1
- package/lib-commonjs/PackageUtils.d.ts +15 -15
- package/lib-commonjs/PackageUtils.js +40 -38
- package/lib-commonjs/PackageUtils.js.map +1 -1
- package/lib-commonjs/PathUtils.d.ts +14 -14
- package/lib-commonjs/PathUtils.js +31 -28
- package/lib-commonjs/PathUtils.js.map +1 -1
- package/lib-commonjs/Serialized.d.ts +158 -158
- package/lib-commonjs/Serialized.js +145 -119
- package/lib-commonjs/Serialized.js.map +1 -1
- package/lib-commonjs/UpgradeStrategy.d.ts +39 -39
- package/lib-commonjs/UpgradeStrategy.js +102 -99
- package/lib-commonjs/UpgradeStrategy.js.map +1 -1
- package/lib-commonjs/ValidationStrategy.d.ts +57 -57
- package/lib-commonjs/ValidationStrategy.js +124 -124
- package/lib-commonjs/ValidationStrategy.js.map +1 -1
- package/lib-commonjs/refFromVersion.d.ts +10 -0
- package/lib-commonjs/refFromVersion.js +99 -0
- package/lib-commonjs/refFromVersion.js.map +1 -0
- package/lib-commonjs/scripts/generateManifest.d.ts +7 -7
- package/lib-commonjs/scripts/generateManifest.js +196 -170
- package/lib-commonjs/scripts/generateManifest.js.map +1 -1
- package/lib-commonjs/scripts/hashFile.d.ts +7 -7
- package/lib-commonjs/scripts/hashFile.js +17 -14
- package/lib-commonjs/scripts/hashFile.js.map +1 -1
- package/lib-commonjs/scripts/testLocks.d.ts +1 -1
- package/lib-commonjs/scripts/testLocks.js +29 -26
- package/lib-commonjs/scripts/testLocks.js.map +1 -1
- package/package.json +53 -43
- package/CHANGELOG.json +0 -554
- package/CHANGELOG.md +0 -238
|
@@ -1,120 +1,146 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
Object.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
exports.
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.writeManifestToFile = exports.parseManifest = exports.readManifestFromFile = void 0;
|
|
36
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
37
|
+
const path_1 = __importDefault(require("path"));
|
|
38
|
+
const t = __importStar(require("io-ts"));
|
|
39
|
+
const ThrowReporter_1 = require("io-ts/lib/ThrowReporter");
|
|
40
|
+
/**
|
|
41
|
+
* Serialized form of {@see PlatformOverride}
|
|
42
|
+
*/
|
|
43
|
+
const PlatformOverrideType = t.type({
|
|
44
|
+
type: t.literal('platform'),
|
|
45
|
+
file: t.string,
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Serialized form of {@see PatchOverride}
|
|
49
|
+
*/
|
|
50
|
+
const PatchOverrideType = t.type({
|
|
51
|
+
type: t.literal('patch'),
|
|
52
|
+
file: t.string,
|
|
53
|
+
baseFile: t.string,
|
|
54
|
+
baseVersion: t.union([t.undefined, t.string]),
|
|
55
|
+
baseHash: t.string,
|
|
56
|
+
issue: t.union([t.undefined, t.number]),
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Serialized form of {@see DerivedOverride}
|
|
60
|
+
*/
|
|
61
|
+
const DerivedOverrideType = t.type({
|
|
62
|
+
type: t.literal('derived'),
|
|
63
|
+
file: t.string,
|
|
64
|
+
baseFile: t.string,
|
|
65
|
+
baseVersion: t.union([t.undefined, t.string]),
|
|
66
|
+
baseHash: t.string,
|
|
67
|
+
issue: t.union([t.undefined, t.number]),
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Serialized form of {@see CopyOverride}
|
|
71
|
+
*/
|
|
72
|
+
const CopyOverrideType = t.type({
|
|
73
|
+
type: t.literal('copy'),
|
|
74
|
+
file: t.string,
|
|
75
|
+
baseFile: t.string,
|
|
76
|
+
baseVersion: t.union([t.undefined, t.string]),
|
|
77
|
+
baseHash: t.string,
|
|
78
|
+
issue: t.union([t.undefined, t.number]),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Serialized form of {@see DirectoryCopyOverride}
|
|
82
|
+
*/
|
|
83
|
+
const DirectoryCopyOverrideType = t.type({
|
|
84
|
+
type: t.literal('copy'),
|
|
85
|
+
directory: t.string,
|
|
86
|
+
baseDirectory: t.string,
|
|
87
|
+
baseVersion: t.union([t.undefined, t.string]),
|
|
88
|
+
baseHash: t.string,
|
|
89
|
+
issue: t.union([t.undefined, t.number]),
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Union of all serialized override types
|
|
93
|
+
*/
|
|
94
|
+
const OverrideType = t.union([
|
|
95
|
+
PlatformOverrideType,
|
|
96
|
+
PatchOverrideType,
|
|
97
|
+
DerivedOverrideType,
|
|
98
|
+
CopyOverrideType,
|
|
99
|
+
DirectoryCopyOverrideType,
|
|
100
|
+
]);
|
|
101
|
+
/**
|
|
102
|
+
* Schema for the "overrides.json" manifest
|
|
103
|
+
*/
|
|
104
|
+
const ManifestType = t.type({
|
|
105
|
+
includePatterns: t.union([t.undefined, t.array(t.string)]),
|
|
106
|
+
excludePatterns: t.union([t.undefined, t.array(t.string)]),
|
|
107
|
+
baseVersion: t.union([t.undefined, t.string]),
|
|
108
|
+
overrides: t.array(OverrideType),
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Read an override manifest from a file.
|
|
112
|
+
*
|
|
113
|
+
* @throws if the file is invalid or cannot be found
|
|
114
|
+
*/
|
|
115
|
+
async function readManifestFromFile(filePath) {
|
|
116
|
+
const json = (await fs_1.default.readFile(filePath)).toString();
|
|
117
|
+
return parseManifest(json);
|
|
118
|
+
}
|
|
119
|
+
exports.readManifestFromFile = readManifestFromFile;
|
|
120
|
+
/**
|
|
121
|
+
* Parse a string with JSON for the override manifest into one.
|
|
122
|
+
*
|
|
123
|
+
* @throws if the JSON doesn't describe a valid manifest
|
|
124
|
+
*/
|
|
125
|
+
function parseManifest(json) {
|
|
126
|
+
const parsed = JSON.parse(json);
|
|
127
|
+
try {
|
|
128
|
+
ThrowReporter_1.ThrowReporter.report(ManifestType.decode(parsed));
|
|
129
|
+
}
|
|
130
|
+
catch (ex) {
|
|
131
|
+
throw new Error('Could not parse manifest. Is it valid?');
|
|
132
|
+
}
|
|
133
|
+
return parsed;
|
|
134
|
+
}
|
|
135
|
+
exports.parseManifest = parseManifest;
|
|
136
|
+
/**
|
|
137
|
+
* Writes the manifest to a JSON file. Does not validate correctness of the
|
|
138
|
+
* manifest.
|
|
139
|
+
*/
|
|
140
|
+
async function writeManifestToFile(manifest, filePath) {
|
|
141
|
+
const json = JSON.stringify(manifest, null /*replacer*/, 2 /*space*/);
|
|
142
|
+
await fs_1.default.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
143
|
+
await fs_1.default.writeFile(filePath, json);
|
|
144
|
+
}
|
|
145
|
+
exports.writeManifestToFile = writeManifestToFile;
|
|
120
146
|
//# sourceMappingURL=Serialized.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serialized.js","sourceRoot":"","sources":["../src/Serialized.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"Serialized.js","sourceRoot":"","sources":["../src/Serialized.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAA0C;AAC1C,gDAAwB;AACxB,yCAA2B;AAE3B,2DAAsD;AAEtD;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,MAAM;CACf,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC/B,IAAI,EAAE,CAAC,CAA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E,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACtD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AALD,oDAKC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEhC,IAAI;QACF,6BAAa,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;KACnD;IAAC,OAAO,EAAE,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAVD,sCAUC;AAED;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CACvC,QAAkB,EAClB,QAAgB;IAEhB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IACtE,MAAM,YAAE,CAAC,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;IAC1D,MAAM,YAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAPD,kDAOC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\nimport * as t from 'io-ts';\n\nimport {ThrowReporter} from 'io-ts/lib/ThrowReporter';\n\n/**\n * Serialized form of {@see PlatformOverride}\n */\nconst PlatformOverrideType = t.type({\n type: t.literal('platform'),\n file: t.string,\n});\n\n/**\n * Serialized form of {@see PatchOverride}\n */\nconst PatchOverrideType = t.type({\n type: t.literal('patch'),\n file: t.string,\n baseFile: t.string,\n baseVersion: t.union([t.undefined, t.string]),\n baseHash: t.string,\n issue: t.union([t.undefined, t.number]),\n});\n\n/**\n * Serialized form of {@see DerivedOverride}\n */\nconst DerivedOverrideType = t.type({\n type: t.literal('derived'),\n file: t.string,\n baseFile: t.string,\n baseVersion: t.union([t.undefined, t.string]),\n baseHash: t.string,\n issue: t.union([t.undefined, t.number]),\n});\n\n/**\n * Serialized form of {@see CopyOverride}\n */\nconst CopyOverrideType = t.type({\n type: t.literal('copy'),\n file: t.string,\n baseFile: t.string,\n baseVersion: t.union([t.undefined, t.string]),\n baseHash: t.string,\n issue: t.union([t.undefined, t.number]),\n});\n\n/**\n * Serialized form of {@see DirectoryCopyOverride}\n */\nconst DirectoryCopyOverrideType = t.type({\n type: t.literal('copy'),\n directory: t.string,\n baseDirectory: t.string,\n baseVersion: t.union([t.undefined, t.string]),\n baseHash: t.string,\n issue: t.union([t.undefined, t.number]),\n});\n\n/**\n * Union of all serialized override types\n */\nconst OverrideType = t.union([\n PlatformOverrideType,\n PatchOverrideType,\n DerivedOverrideType,\n CopyOverrideType,\n DirectoryCopyOverrideType,\n]);\n\n/**\n * Schema for the \"overrides.json\" manifest\n */\nconst ManifestType = t.type({\n includePatterns: t.union([t.undefined, t.array(t.string)]),\n excludePatterns: t.union([t.undefined, t.array(t.string)]),\n baseVersion: t.union([t.undefined, t.string]),\n overrides: t.array(OverrideType),\n});\n\nexport type PlatformOverride = t.TypeOf<typeof PlatformOverrideType>;\nexport type PatchOverride = t.TypeOf<typeof PatchOverrideType>;\nexport type DerivedOverride = t.TypeOf<typeof DerivedOverrideType>;\nexport type CopyOverride = t.TypeOf<typeof CopyOverrideType>;\nexport type DirectoryCopyOverride = t.TypeOf<typeof DirectoryCopyOverrideType>;\nexport type Override = t.TypeOf<typeof OverrideType>;\nexport type Manifest = t.TypeOf<typeof ManifestType>;\n\n/**\n * Read an override manifest from a file.\n *\n * @throws if the file is invalid or cannot be found\n */\nexport async function readManifestFromFile(\n filePath: string,\n): Promise<Manifest> {\n const json = (await fs.readFile(filePath)).toString();\n return parseManifest(json);\n}\n\n/**\n * Parse a string with JSON for the override manifest into one.\n *\n * @throws if the JSON doesn't describe a valid manifest\n */\nexport function parseManifest(json: string): Manifest {\n const parsed = JSON.parse(json);\n\n try {\n ThrowReporter.report(ManifestType.decode(parsed));\n } catch (ex) {\n throw new Error('Could not parse manifest. Is it valid?');\n }\n\n return parsed;\n}\n\n/**\n * Writes the manifest to a JSON file. Does not validate correctness of the\n * manifest.\n */\nexport async function writeManifestToFile(\n manifest: Manifest,\n filePath: string,\n) {\n const json = JSON.stringify(manifest, null /*replacer*/, 2 /*space*/);\n await fs.mkdir(path.dirname(filePath), {recursive: true});\n await fs.writeFile(filePath, json);\n}\n"]}
|
|
@@ -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
|
|
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,100 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*
|
|
6
|
-
* @format
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
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
|
+
};
|
|
100
103
|
//# sourceMappingURL=UpgradeStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpgradeStrategy.js","sourceRoot":"","sources":["../src/UpgradeStrategy.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"UpgradeStrategy.js","sourceRoot":"","sources":["../src/UpgradeStrategy.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,oDAAuB;AACvB,gDAAwB;AACxB,qDAAqE;AAErE,iCAA2C;AAC3C,oDAA4B;AAqBf,QAAA,iBAAiB,GAAG;IAC/B;;OAEG;IACH,cAAc,EAAE,CAAC,YAAoB,EAAmB,EAAE,CAAC,CAAC;QAC1D,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACpB,YAAY;YACZ,YAAY,EAAE,KAAK;YACnB,YAAY,EAAE,KAAK;SACpB,CAAC;KACH,CAAC;IAEF;;;OAGG;IACH,aAAa,EAAE,CACb,YAAoB,EACpB,QAAgB,EAChB,WAAmB,EACF,EAAE,CAAC,CAAC;QACrB,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE;YACxE,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC7D,IAAI,UAAU,KAAK,IAAI,EAAE;gBACvB,MAAM,IAAI,KAAK,CAAC,kBAAkB,YAAY,EAAE,CAAC,CAAC;aACnD;YAED,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,aAAa,CACjD,QAAQ,EACR,WAAW,EACX,UAAU,CACX,CAAC;YAEF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,YAAY,CAAC,CAAC;aAClE;YAED,MAAM,EAAC,WAAW,EAAE,YAAY,EAAC,GAAG,MAAM,YAAY,CAAC,cAAc,CACnE,QAAQ,EACR,UAAU,EACV,UAAU,CACX,CAAC;YAEF,IAAI,CAAC,WAAW,EAAE;gBAChB,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE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Q,CAAC,CAAC;oBAClD,MAAM,YAAY,CAAC,SAAS,CAAC,YAAY,EAAE,OAAQ,CAAC,CAAC;iBACtD;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;YAElD,OAAO;gBACL,YAAY,EAAE,iBAAiB;gBAC/B,YAAY,EAAE,IAAI;gBAClB,YAAY,EAAE,KAAK;aACpB,CAAC;QACJ,CAAC;KACF,CAAC;CACH,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport _ from 'lodash';\nimport path from 'path';\nimport {WritableFileRepository, bindVersion} from './FileRepository';\nimport GitReactFileRepository from './GitReactFileRepository';\nimport {hashFileOrDirectory} from './Hash';\nimport isUtf8 from 'isutf8';\n\nexport interface UpgradeResult {\n overrideName: string;\n filesWritten: boolean;\n hasConflicts: boolean;\n}\n\n/**\n * An UpgradeStrategy describes the process to upgrade an individual override\n * to a new version of the React Native source tree.\n */\nexport default interface UpgradeStrategy {\n upgrade(\n gitReactRepo: GitReactFileRepository,\n overrideRepo: WritableFileRepository,\n newVersion: string,\n allowConflicts: boolean,\n ): Promise<UpgradeResult>;\n}\n\nexport const UpgradeStrategies = {\n /**\n * No work needed to upgrade\n */\n assumeUpToDate: (overrideName: string): UpgradeStrategy => ({\n upgrade: async () => ({\n overrideName,\n filesWritten: false,\n hasConflicts: false,\n }),\n }),\n\n /**\n * Perform a three way merge of the original base file, the overridden version\n * of it, and the base file from a newwer version of React Native.\n */\n threeWayMerge: (\n overrideName: string,\n baseFile: string,\n baseVersion: string,\n ): UpgradeStrategy => ({\n upgrade: async (gitReactRepo, overrideRepo, newVersion, allowConflicts) => {\n const ovrContent = await overrideRepo.readFile(overrideName);\n if (ovrContent === null) {\n throw new Error(`Could not read ${overrideName}`);\n }\n\n const ovrAsPatch = await gitReactRepo.generatePatch(\n baseFile,\n baseVersion,\n ovrContent,\n );\n\n if (ovrAsPatch.length === 0) {\n throw new Error(`Generated patch for ${overrideName} was empty`);\n }\n\n const {patchedFile, hasConflicts} = await gitReactRepo.getPatchedFile(\n baseFile,\n newVersion,\n ovrAsPatch,\n );\n\n if (!patchedFile) {\n return {overrideName, filesWritten: false, hasConflicts};\n }\n\n const prettyPatched =\n hasConflicts && isUtf8(patchedFile)\n ? patchedFile\n .toString('utf8')\n .replace(/<<<<<<< ours/g, '<<<<<<< Upstream')\n .replace(/>>>>>>> theirs/g, '>>>>>>> Override')\n : patchedFile;\n\n if (!hasConflicts || allowConflicts) {\n await overrideRepo.writeFile(overrideName, prettyPatched);\n return {overrideName, filesWritten: true, hasConflicts};\n }\n\n return {overrideName, filesWritten: false, hasConflicts};\n },\n }),\n\n /**\n * Overwrite our override with base file contents\n */\n copyFile: (overrideName: string, baseFile: string): UpgradeStrategy => ({\n upgrade: async (gitReactRepo, overrideRepo, newVersion) => {\n const newContent = await gitReactRepo.readFile(baseFile, newVersion);\n if (newContent === null) {\n throw new Error(`Could not read ${baseFile}@${newVersion}`);\n }\n\n await overrideRepo.writeFile(overrideName, newContent);\n return {overrideName, filesWritten: true, hasConflicts: false};\n },\n }),\n\n /**\n * Overwrite our override with base file contents\n */\n copyDirectory: (\n overrideDirectory: string,\n baseDirectory: string,\n ): UpgradeStrategy => ({\n upgrade: async (gitReactRepo, overrideRepo, newVersion) => {\n const baseFiles = (\n await gitReactRepo.listFiles([`${baseDirectory}/**`], newVersion)\n ).map(f => path.relative(baseDirectory, f));\n\n const overrideFiles = (\n await overrideRepo.listFiles([`${overrideDirectory}/**`])\n ).map(f => path.relative(overrideDirectory, f));\n\n // Note that this logic can leave empty directories. This shouldn't\n // matter in practice as Git won't track them.\n const deleteTasks = _.difference(overrideFiles, baseFiles).map(f =>\n overrideRepo.deleteFile(path.join(overrideDirectory, f)),\n );\n\n const baseRepo = bindVersion(gitReactRepo, newVersion);\n const copyTasks = baseFiles.map(async f => {\n const basePath = path.join(baseDirectory, f);\n const overridePath = path.join(overrideDirectory, f);\n\n // Con't replace files of the same content but different line endings\n if (\n (await hashFileOrDirectory(basePath, baseRepo)) !==\n (await hashFileOrDirectory(overridePath, overrideRepo))\n ) {\n const content = await baseRepo.readFile(basePath);\n await overrideRepo.writeFile(overridePath, content!);\n }\n });\n\n await Promise.all([...deleteTasks, ...copyTasks]);\n\n return {\n overrideName: overrideDirectory,\n filesWritten: true,\n hasConflicts: false,\n };\n },\n }),\n};\n"]}
|